Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Able to navigate through form 1 forms with mandatory errors #732

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ angular.module('bahmni.clinical')
};

$scope.$on('$stateChangeStart', function () {
if ($scope.bacteriologyForm.$dirty) {
if ($scope.bacteriologyForm && $scope.bacteriologyForm.$dirty) {
$state.dirtyConsultationForm = true;
}
});
Expand Down
31 changes: 29 additions & 2 deletions ui/app/clinical/consultation/controllers/consultationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ angular.module('bahmni.clinical').controller('ConsultationController',
};
$scope.showComment = true;
$scope.showSaveAndContinueButton = true;

$scope.visitHistory = visitHistory;
$scope.consultationBoardLink = clinicalAppConfigService.getConsultationBoardLink();
$scope.showControlPanel = false;
Expand Down Expand Up @@ -351,6 +350,11 @@ angular.module('bahmni.clinical').controller('ConsultationController',
if ($scope.currentBoard === board) {
return;
}
$scope.isObservationPage = board.id == "bahmni.clinical.consultation.observations" ? true : false;
$scope.isSave = false;
if ($scope.currentBoard) {
$scope.isSwitchedFromObservationToOtherPage = $scope.currentBoard.id == "bahmni.clinical.consultation.observations" ? true : false;
}
if (!isFormValid()) {
$scope.$parent.$broadcast("event:errorsOnForm");
return;
Expand Down Expand Up @@ -489,10 +493,32 @@ angular.module('bahmni.clinical').controller('ConsultationController',
return valid;
};

var checkForObservationPageError = function (shouldAllow, contxChange) {
if (!$scope.isSave) {
if ($scope.isSwitchedFromObservationToOtherPage && !shouldAllow) {
$scope.isErrorPresentInObsTab = true;
shouldAllow = $scope.isErrorPresentInObsTab;
} else if ($scope.isSwitchedFromObservationToOtherPage && shouldAllow) {
$scope.isErrorPresentInObsTab = false;
}
} else if ($scope.isSave) {
if ($scope.isErrorPresentInObsTab) {
if (!$scope.isObservationPage) {
var errorMessage = contxChange["errorMessage"] ? contxChange["errorMessage"] : "{{'CLINICAL_FORM_ERRORS_MESSAGE_KEY' | translate }}";
messagingService.showMessage('error', errorMessage);
} else if ($scope.isObservationPage) {
$scope.isErrorPresentInObsTab = false;
}
}
}
return shouldAllow;
};

var isFormValid = function () {
var contxChange = contextChange();
var shouldAllow = contxChange["allow"];
var discontinuedDrugOrderValidationMessage = discontinuedDrugOrderValidation($scope.consultation.discontinuedDrugs);
shouldAllow = checkForObservationPageError(shouldAllow, contxChange);
if (!shouldAllow) {
var errorMessage = contxChange["errorMessage"] ? contxChange["errorMessage"] : "{{'CLINICAL_FORM_ERRORS_MESSAGE_KEY' | translate }}";
messagingService.showMessage('error', errorMessage);
Expand All @@ -517,7 +543,8 @@ angular.module('bahmni.clinical').controller('ConsultationController',
});

$scope.save = function (toStateConfig) {
if (isFormValid() && !isObservationFormValid()) {
$scope.isSave = true;
if (!isFormValid() || !isObservationFormValid() || $scope.isErrorPresentInObsTab) {
$scope.$parent.$parent.$broadcast("event:errorsOnForm");
return $q.when({});
}
Expand Down
111 changes: 111 additions & 0 deletions ui/test/unit/clinical/controllers/consultationController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,117 @@ describe("ConsultationController", function () {
scope.showBoard(1);
expect(scope.currentBoard.label).toBe('Treatment');
});

it("should allow the observation tab with mandatory error fields to navigate to other tabs", function () {
scope.consultation = { observations: [{
conceptNameToDisplay: "Cleft Lip/Palate -Operative Report",
groupMembers : [{
conceptNameToDisplay: "Anesthesia Start Time",
valueAsString : "2023-10-01 15:07:00"
},
{
conceptNameToDisplay: "Surgical Finish Time",
valueAsString : "2023-10-10 15:06:00"
}]
}]};
location = {
path: function () {
}, url: function (url) {
return "/default/patient/somePatientUuid/dashboard/concept-set-group/observations";
}
};
var observationTab = {
"default": true,
"extensionPointId": "org.bahmni.clinical.consultation.board",
"icon": "fa-user-md",
"id": "bahmni.clinical.consultation.observations",
"isSelectedTab": true,
"label": "Observations",
"order": 1,
"requiredPrivilege": "app:clinical:observationTab",
"translationKey": "OBSERVATIONS_BOARD_LABEL_KEY",
"type": "link",
"url": "concept-set-group/observations"
};
boards.push(observationTab);

createController();

var expectedCurrentBoard = observationTab;
expectedCurrentBoard.isSelectedTab = true;
expect(scope.currentBoard.id).toBe('bahmni.clinical.consultation.observations');
scope.isErrorPresentInObsTab = true
scope.showBoard(2);
spyOn(scope.$parent, '$broadcast');
expect(scope.$parent.$broadcast).not.toHaveBeenCalledWith('event:errorsOnForm');
expect(messagingService.showMessage).not.toHaveBeenCalledWith('error');
});
it("should throw error for mandatory fields for observation tab while saving from any other tab", function () {
scope.consultation = { observations: [{
conceptNameToDisplay: "Cleft Lip/Palate -Operative Report",
groupMembers : [{
conceptNameToDisplay: "Anesthesia Start Time",
valueAsString : "2023-10-01 15:07:00"
},
{
conceptNameToDisplay: "Surgical Finish Time",
valueAsString : "2023-10-10 15:06:00"
}]
}]};
scope.$parent = {
$parent: {
$broadcast: function () {
return {};
}
}
};
scope.isErrorPresentInObsTab = true
scope.save();
spyOn(scope.$parent.$parent, '$broadcast');
expect(scope.isSave).toBe(true);
expect(scope.isErrorPresentInObsTab).toBe(true);
expect(messagingService.showMessage).toHaveBeenCalled();
});
it("should be able to save the consultation after the mandatory issue fix", function () {
scope.consultation = { observations: [{
conceptNameToDisplay: "Cleft Lip/Palate -Operative Report",
groupMembers : [{
conceptNameToDisplay: "Anesthesia Start Time",
valueAsString : "2023-10-01 15:07:00"
},
{
conceptNameToDisplay: "Surgical Finish Time",
valueAsString : "2023-10-10 15:06:00"
}]
}]};
location = {
path: function () {
}, url: function (url) {
return "/default/patient/somePatientUuid/dashboard/concept-set-group/observations";
}
};
var observationTab = {
"default": true,
"extensionPointId": "org.bahmni.clinical.consultation.board",
"icon": "fa-user-md",
"id": "bahmni.clinical.consultation.observations",
"isSelectedTab": true,
"label": "Observations",
"order": 1,
"requiredPrivilege": "app:clinical:observationTab",
"translationKey": "OBSERVATIONS_BOARD_LABEL_KEY",
"type": "link",
"url": "concept-set-group/observations"
};
boards.push(observationTab);

createController();
scope.isErrorPresentInObsTab = true
scope.isObservationPage = true
scope.save();
expect(scope.isSave).toBe(true);
expect(scope.isErrorPresentInObsTab).toBe(false);
});
});

describe("showSaveConfirmDialogConfig", function () {
Expand Down