diff --git a/ui/app/clinical/app.js b/ui/app/clinical/app.js index a8d54105dc..9ce34d4c52 100644 --- a/ui/app/clinical/app.js +++ b/ui/app/clinical/app.js @@ -104,7 +104,7 @@ angular.module('consultation') abstract: true, views: { 'content': { - template: '
' + + template: '
' + '', controller: function ($scope, visitHistory, consultationContext, followUpConditionConcept) { $scope.visitHistory = visitHistory; diff --git a/ui/app/clinical/consultation/controllers/addTreatmentController.js b/ui/app/clinical/consultation/controllers/addTreatmentController.js index 0b63395f8d..eb2b852558 100644 --- a/ui/app/clinical/consultation/controllers/addTreatmentController.js +++ b/ui/app/clinical/consultation/controllers/addTreatmentController.js @@ -3,10 +3,10 @@ angular.module('bahmni.clinical') .controller('AddTreatmentController', ['$scope', '$rootScope', 'contextChangeHandler', 'treatmentConfig', 'drugService', '$timeout', 'clinicalAppConfigService', 'ngDialog', '$window', 'messagingService', 'appService', 'activeDrugOrders', - 'orderSetService', '$q', 'locationService', 'spinner', '$translate', + 'orderSetService', '$q', 'locationService', 'spinner', '$translate', '$state', function ($scope, $rootScope, contextChangeHandler, treatmentConfig, drugService, $timeout, clinicalAppConfigService, ngDialog, $window, messagingService, appService, activeDrugOrders, - orderSetService, $q, locationService, spinner, $translate) { + orderSetService, $q, locationService, spinner, $translate, $state) { var DateUtil = Bahmni.Common.Util.DateUtil; var DrugOrderViewModel = Bahmni.Clinical.DrugOrderViewModel; var scrollTop = _.partial($window.scrollTo, 0, 0); @@ -88,6 +88,16 @@ angular.module('bahmni.clinical') }); }; + $scope.$on('$stateChangeStart', function () { + if ($scope.addForm.$dirty) { + $state.dirtyConsultationForm = true; + } + }); + + $scope.$on("event:changes-saved", function () { + $scope.addForm.$dirty = false; + }); + var markVariable = function (variable) { $scope[variable] = true; $timeout(function () { diff --git a/ui/app/clinical/consultation/controllers/bacteriologyController.js b/ui/app/clinical/consultation/controllers/bacteriologyController.js index dc7ccf8305..40f3184e98 100644 --- a/ui/app/clinical/consultation/controllers/bacteriologyController.js +++ b/ui/app/clinical/consultation/controllers/bacteriologyController.js @@ -1,9 +1,9 @@ 'use strict'; angular.module('bahmni.clinical') - .controller('BacteriologyController', ['$scope', '$rootScope', 'contextChangeHandler', 'spinner', 'conceptSetService', + .controller('BacteriologyController', ['$scope', '$state', '$rootScope', 'contextChangeHandler', 'spinner', 'conceptSetService', 'messagingService', 'bacteriologyConceptSet', 'appService', 'retrospectiveEntryService', - function ($scope, $rootScope, contextChangeHandler, spinner, conceptSetService, messagingService, bacteriologyConceptSet, + function ($scope, $state, $rootScope, contextChangeHandler, spinner, conceptSetService, messagingService, bacteriologyConceptSet, appService, retrospectiveEntryService) { $scope.consultation.extensions = $scope.consultation.extensions ? $scope.consultation.extensions : {mdrtbSpecimen: []}; var initializeBacteriologyScope = function () { @@ -54,6 +54,11 @@ angular.module('bahmni.clinical') $scope.newSpecimens.push(newSpecimen); }; + $scope.$on('$stateChangeStart', function () { + const newlyAddedSpecimens = $scope.consultation.newlyAddedSpecimens; + $state.dirtyConsultationForm = newlyAddedSpecimens.length !== 0 && newlyAddedSpecimens[0].dateCollected !== null; + }); + var contextChange = function () { $scope.consultation.newlyAddedSpecimens = $scope.newSpecimens; $scope.consultation.deletedSpecimens = $scope.deletedSpecimens; diff --git a/ui/app/clinical/consultation/controllers/consultationController.js b/ui/app/clinical/consultation/controllers/consultationController.js index 42dfc95435..eb9761d35d 100644 --- a/ui/app/clinical/consultation/controllers/consultationController.js +++ b/ui/app/clinical/consultation/controllers/consultationController.js @@ -524,6 +524,8 @@ angular.module('bahmni.clinical').controller('ConsultationController', params.cachebuster = Math.random(); return encounterService.create(encounterData) .then(function (saveResponse) { + $state.dirtyConsultationForm = false; + $scope.$parent.$broadcast("event:changes-saved"); var messageParams = { encounterUuid: saveResponse.data.encounterUuid, encounterType: saveResponse.data.encounterType diff --git a/ui/app/clinical/consultation/controllers/consultationSummaryController.js b/ui/app/clinical/consultation/controllers/consultationSummaryController.js index ed666e0498..cb228d06b7 100644 --- a/ui/app/clinical/consultation/controllers/consultationSummaryController.js +++ b/ui/app/clinical/consultation/controllers/consultationSummaryController.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('bahmni.clinical') - .controller('ConsultationSummaryController', ['$scope', '$translate', 'conceptSetUiConfigService', function ($scope, $translate, conceptSetUiConfigService) { + .controller('ConsultationSummaryController', ['$scope', '$state', '$translate', 'conceptSetUiConfigService', function ($scope, $state, $translate, conceptSetUiConfigService) { var geEditedDiagnosesFromPastEncounters = function () { var editedDiagnosesFromPastEncounters = []; $scope.consultation.pastDiagnoses.forEach(function (pastDiagnosis) { @@ -18,6 +18,16 @@ angular.module('bahmni.clinical') $scope.consultation.consultationNote.observationDateTime = null; }; + $scope.$on('$stateChangeStart', function () { + if ($scope.consultationForm.$dirty) { + $state.dirtyConsultationForm = true; + } + }); + + $scope.$on("event:changes-saved", function (event) { + $scope.consultationForm.$dirty = false; + }); + var groupObservations = function () { var allObservations = $scope.consultation.observations; allObservations = _.filter(allObservations, function (obs) { diff --git a/ui/app/clinical/consultation/controllers/diagnosisController.js b/ui/app/clinical/consultation/controllers/diagnosisController.js index 2fda0d49dd..6f65cebdb4 100644 --- a/ui/app/clinical/consultation/controllers/diagnosisController.js +++ b/ui/app/clinical/consultation/controllers/diagnosisController.js @@ -1,8 +1,8 @@ 'use strict'; angular.module('bahmni.clinical') - .controller('DiagnosisController', ['$scope', '$rootScope', 'diagnosisService', 'messagingService', 'contextChangeHandler', 'spinner', 'appService', '$translate', 'retrospectiveEntryService', - function ($scope, $rootScope, diagnosisService, messagingService, contextChangeHandler, spinner, appService, $translate, retrospectiveEntryService) { + .controller('DiagnosisController', ['$scope', '$rootScope', 'diagnosisService', 'messagingService', 'contextChangeHandler', 'spinner', 'appService', '$translate', 'retrospectiveEntryService', '$state', + function ($scope, $rootScope, diagnosisService, messagingService, contextChangeHandler, spinner, appService, $translate, retrospectiveEntryService, $state) { var DateUtil = Bahmni.Common.Util.DateUtil; $scope.todayWithoutTime = DateUtil.getDateWithoutTime(DateUtil.today()); $scope.toggles = { @@ -56,6 +56,16 @@ angular.module('bahmni.clinical') return canAdd; }; + $scope.$on('$stateChangeStart', function () { + if ($scope.diagnosisForm.$dirty) { + $state.dirtyConsultationForm = true; + } + }); + + $scope.$on("event:changes-saved", function () { + $scope.diagnosisForm.$dirty = false; + }); + $scope.getAddNewDiagnosisMethod = function (diagnosisAtIndex) { return function (item) { var concept = item.lookup; diff --git a/ui/app/clinical/consultation/controllers/dispositionController.js b/ui/app/clinical/consultation/controllers/dispositionController.js index fb823f43f9..d4b06ec3d6 100644 --- a/ui/app/clinical/consultation/controllers/dispositionController.js +++ b/ui/app/clinical/consultation/controllers/dispositionController.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('bahmni.clinical') - .controller('DispositionController', ['$scope', '$q', 'dispositionService', 'appService', 'retrospectiveEntryService', 'spinner', '$rootScope', '$translate', function ($scope, $q, dispositionService, appService, retrospectiveEntryService, spinner, $rootScope, $translate) { + .controller('DispositionController', ['$scope', '$state', '$q', 'dispositionService', 'appService', 'retrospectiveEntryService', 'spinner', '$rootScope', '$translate', function ($scope, $state, $q, dispositionService, appService, retrospectiveEntryService, spinner, $rootScope, $translate) { var consultation = $scope.consultation; var allDispositions = []; var getPreviousDispositionNote = function () { @@ -120,6 +120,16 @@ angular.module('bahmni.clinical') } }; + $scope.$on('$stateChangeStart', function () { + if ($scope.dispositionForm.$dirty) { + $state.dirtyConsultationForm = true; + } + }); + + $scope.$on("event:changes-saved", function () { + $scope.dispositionForm.$dirty = false; + }); + $scope.consultation.preSaveHandler.register("dispositionSaveHandlerKey", saveDispositions); $scope.$on('$destroy', saveDispositions); }]); diff --git a/ui/app/clinical/consultation/controllers/orderController.js b/ui/app/clinical/consultation/controllers/orderController.js index 7bc1cdf9c6..ad26db0500 100644 --- a/ui/app/clinical/consultation/controllers/orderController.js +++ b/ui/app/clinical/consultation/controllers/orderController.js @@ -1,8 +1,8 @@ 'use strict'; angular.module('bahmni.clinical') - .controller('OrderController', ['$scope', 'allOrderables', 'ngDialog', 'retrospectiveEntryService', 'appService', '$translate', - function ($scope, allOrderables, ngDialog, retrospectiveEntryService, appService, $translate) { + .controller('OrderController', ['$scope', '$state', 'allOrderables', 'ngDialog', 'retrospectiveEntryService', 'appService', '$translate', + function ($scope, $state, allOrderables, ngDialog, retrospectiveEntryService, appService, $translate) { $scope.consultation.orders = $scope.consultation.orders || []; $scope.consultation.childOrders = $scope.consultation.childOrders || []; $scope.allOrdersTemplates = allOrderables; @@ -132,6 +132,12 @@ angular.module('bahmni.clinical') }); }; + $scope.$on('$stateChangeStart', function () { + if ($scope.consultation.orders.length !== $scope.consultation.investigations.length) { + $state.dirtyConsultationForm = true; + } + }); + $scope.getOrderTemplate = function (templateName) { var key = '\'' + templateName + '\''; return $scope.allOrdersTemplates[key]; diff --git a/ui/app/clinical/consultation/directives/alertOnExit.js b/ui/app/clinical/consultation/directives/alertOnExit.js new file mode 100644 index 0000000000..738ab92fac --- /dev/null +++ b/ui/app/clinical/consultation/directives/alertOnExit.js @@ -0,0 +1,18 @@ +"use strict"; + +angular.module('bahmni.clinical') + .directive('alertOnExit', ['exitAlertService', '$state', + function (exitAlertService, $state) { + return { + link: function ($scope) { + $scope.$on('$stateChangeStart', function (event, next, current) { + var uuid = $state.params.patientUuid; + var currentUuid = current.patientUuid; + var isNavigating = exitAlertService.setIsNavigating(next, uuid, currentUuid); + $state.dirtyConsultationForm = $state.discardChanges ? false : $state.dirtyConsultationForm; + exitAlertService.showExitAlert(isNavigating, $state.dirtyConsultationForm, event, next.spinnerToken); + }); + } + }; + } + ]); diff --git a/ui/app/clinical/consultation/services/exitAlertService.js b/ui/app/clinical/consultation/services/exitAlertService.js new file mode 100644 index 0000000000..bd3f9a30d8 --- /dev/null +++ b/ui/app/clinical/consultation/services/exitAlertService.js @@ -0,0 +1,23 @@ +angular.module('bahmni.clinical') + .factory('exitAlertService', ['messagingService', 'spinner', '$state', '$location', + function (messagingService, spinner, $state, $location) { + return { + showExitAlert: function (isNavigating, dirtyConsultationForm, event, spinnerToken) { + if (isNavigating && dirtyConsultationForm) { + messagingService.showMessage('alert', "{{'ALERT_MESSAGE_ON_EXIT' | translate }}"); + $state.reviewButtonFocused = true; + event.preventDefault(); + spinner.hide(spinnerToken); + } + }, + setIsNavigating: function (next, uuid, currentUuid) { + $state.newPatientUuid = currentUuid; + next.url.includes("/patient/search") ? $state.isPatientSearch = true : $state.isPatientSearch = false; + return (next.url.includes("/patient/search") || (uuid !== currentUuid)); + }, + redirectUrl: function () { + return $state.isPatientSearch ? $location.path('/default/patient/search') : $location.path('/default/patient/' + $state.newPatientUuid + "/dashboard"); + } + }; + } + ]); diff --git a/ui/app/clinical/consultation/views/bacteriology.html b/ui/app/clinical/consultation/views/bacteriology.html index 94e06c76ab..b69cbb9560 100644 --- a/ui/app/clinical/consultation/views/bacteriology.html +++ b/ui/app/clinical/consultation/views/bacteriology.html @@ -5,7 +5,7 @@
-
+

{{'BACTERIOLOGY_TAB_TITLE_KEY' | translate}}

diff --git a/ui/app/clinical/consultation/views/consultation.html b/ui/app/clinical/consultation/views/consultation.html index 246f1c2cfe..884b12b479 100644 --- a/ui/app/clinical/consultation/views/consultation.html +++ b/ui/app/clinical/consultation/views/consultation.html @@ -260,9 +260,11 @@

{{ 'CONSULTATION_TAB_DISPOSITION_HEADER_LABEL'|transla

-

{{ 'CONSULTATION_TAB_CONSULTATION_NOTES_LABEL'|translate }}

- +
diff --git a/ui/app/clinical/consultation/views/diagnosis.html b/ui/app/clinical/consultation/views/diagnosis.html index a727b4ea10..ab4b03403d 100644 --- a/ui/app/clinical/consultation/views/diagnosis.html +++ b/ui/app/clinical/consultation/views/diagnosis.html @@ -1,4 +1,4 @@ -
+
diff --git a/ui/app/clinical/consultation/views/disposition.html b/ui/app/clinical/consultation/views/disposition.html index 69fb40f6b6..37b2cbdf16 100644 --- a/ui/app/clinical/consultation/views/disposition.html +++ b/ui/app/clinical/consultation/views/disposition.html @@ -4,7 +4,7 @@
- +