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

BAH-2359 | Add. Alert for unsaved observation under consultation #652

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e4cec6c
Parvathy | BAH-2359 | Add. Alert for unsaved observation under consul…
parvathy00 Jul 20, 2023
c9c4d9e
Parvathy | BAH-2359 | Add. Alert box with review and discard button
parvathy00 Jul 20, 2023
8975915
Parvathy | BAH-2359 | Fix. Separated alert message from error messages
parvathy00 Jul 20, 2023
4462cb1
Parvathy | BAH-2359 | Refactor. Removed unwanted lines of code
parvathy00 Jul 21, 2023
f72727b
Parvathy | BAH-2359 | Fix. New variable to record state of changes wh…
parvathy00 Jul 21, 2023
3af6b24
Parvathy | BAH-2359 | Refactor. Improvements to code
parvathy00 Jul 25, 2023
967ae57
Parvathy | BAH-2359 | Refactor. Removed code duplicacy by extracting …
parvathy00 Jul 25, 2023
cd2e72f
Parvathy | BAH-2359 | Add. Alert when trying to navigate to new patie…
parvathy00 Jul 25, 2023
3a39ed3
Parvathy | BAH-2359 | Fix. eslint issues
parvathy00 Jul 25, 2023
7eec18a
Parvathy | BAH-2359 | Fix. failing tests
parvathy00 Jul 25, 2023
dd8b4ba
Parvathy | BAH-2359 | Add. Tests for showing alert
parvathy00 Jul 26, 2023
66d4249
Parvathy | BAH-2359 | Fix. Check for unsaved observations
parvathy00 Jul 28, 2023
95d10ad
Parvathy | BAH-2359 | Fix. Eslint issues and test cases
parvathy00 Jul 28, 2023
b87a605
Parvathy | BAH-2359 | Fix. checking for group members
parvathy00 Aug 1, 2023
337b19b
Parvathy | BAH-2359 | Add. Handle unsaved observations in bahmni stan…
parvathy00 Aug 3, 2023
739ad54
Parvathy | BAH-2359 | Refactor. Changed alert message and button alig…
parvathy00 Aug 4, 2023
88b27c0
Parvathy | BAH-2359 | Refactor. Alignment of text message and buttons
parvathy00 Aug 8, 2023
d231a2e
Parvathy | BAH-2359 | Fix. failing test
parvathy00 Aug 8, 2023
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
2 changes: 1 addition & 1 deletion ui/app/clinical/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ angular.module('consultation')
abstract: true,
views: {
'content': {
template: '<div ui-view="dashboard-header"></div> <div ui-view="dashboard-content"></div>' +
template: '<div ui-view="dashboard-header"></div> <div ui-view="dashboard-content" alert-on-exit></div>' +
'<patient-control-panel patient="patient" visit-history="visitHistory" visit="visit" show="showControlPanel" consultation="consultation"/>',
controller: function ($scope, visitHistory, consultationContext, followUpConditionConcept) {
$scope.visitHistory = visitHistory;
Expand Down
14 changes: 12 additions & 2 deletions ui/app/clinical/consultation/controllers/addTreatmentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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) {
Expand Down
14 changes: 12 additions & 2 deletions ui/app/clinical/consultation/controllers/diagnosisController.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down Expand Up @@ -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);
}]);
10 changes: 8 additions & 2 deletions ui/app/clinical/consultation/controllers/orderController.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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];
Expand Down
18 changes: 18 additions & 0 deletions ui/app/clinical/consultation/directives/alertOnExit.js
Original file line number Diff line number Diff line change
@@ -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);
});
}
};
}
]);
23 changes: 23 additions & 0 deletions ui/app/clinical/consultation/services/exitAlertService.js
Original file line number Diff line number Diff line change
@@ -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");
}
};
}
]);
2 changes: 1 addition & 1 deletion ui/app/clinical/consultation/views/bacteriology.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<span ng-bind-html="'BACTERIOLOGY_NOT_ALLOWED_IN_RETROSPECTIVE_MESSAGE'|translate"></span>
</div>
<div ng-repeat="newSpecimen in newSpecimens track by $id(newSpecimen)" class="sample-container">
<form class="form">
<form class="form" alert-on-exit>
<section class="section-grid">
<div class="section-title-wrapper clearfix">
<h2 class="section-title fl">{{'BACTERIOLOGY_TAB_TITLE_KEY' | translate}}</h2>
Expand Down
6 changes: 4 additions & 2 deletions ui/app/clinical/consultation/views/consultation.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,11 @@ <h2 class="section-title">{{ 'CONSULTATION_TAB_DISPOSITION_HEADER_LABEL'|transla
</section>
</div>
<section class="block consultation-notes section-grid">
<h2 class="section-title">{{ 'CONSULTATION_TAB_CONSULTATION_NOTES_LABEL'|translate }}</h2>
<textarea ng-model="consultation.consultationNote.value" ng-change="onNoteChanged()"
<form name="consultationForm" alert-on-exit>
<h2 class="section-title">{{ 'CONSULTATION_TAB_CONSULTATION_NOTES_LABEL'|translate }}</h2>
<textarea ng-model="consultation.consultationNote.value" ng-change="onNoteChanged()"
placeholder="{{ 'CLINICAL_ENTER_NOTES_PLACEHOLDER'|translate }} " rows="6" msd-elastic></textarea>
</form>
</section>

</article>
Expand Down
2 changes: 1 addition & 1 deletion ui/app/clinical/consultation/views/diagnosis.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form>
<form name="diagnosisForm" alert-on-exit>
<fieldset>
<div class="diagnosis" focus-on-input-errors>
<div id="selectedNodesArea">
Expand Down
2 changes: 1 addition & 1 deletion ui/app/clinical/consultation/views/disposition.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<span ng-bind-html="'DISPOSITION_NOT_ALLOWED_IN_RETROSPECTIVE_MESSAGE'|translate"></span>
</div>
<div class="box disposition-tab">
<form ng-submit="submit()">
<form name="dispositionForm" ng-submit="submit()" alert-on-exit>
<label for="dispositionAction">{{ 'DISPOSITION_TYPE_LABEL'|translate }}: </label>
<select id="dispositionAction" ng-model="dispositionCode" ng-options="d.code as ::getTranslatedDisposition(d.name) for d in dispositionActions" ng-change="clearDispositionNote();" ng-disabled="isRetrospectiveMode()">
<option value=""></option>
Expand Down
2 changes: 1 addition & 1 deletion ui/app/clinical/consultation/views/orders.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="order-list">
<div class="order-list" alert-on-exit>
<div ng-class="{'disableOrdersInRetroMode':isRetrospectiveMode()}">
<div class="infoMsgRetrospectiveModeEnabled" ng-if="isRetrospectiveMode()">
<i class="fa fa-info-circle"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h2 class="section-title has-toggle" toggle="addTreatment">
</h2>
<div class="order-section-container" ng-show="addTreatment">
<div class="Order-section-orderDrug clearfix">
<form name="addForm" ng-class="{ 'show-invalid': formInvalid}" ng-submit="add()" bm-form class="edit-drug-order-container">
<form name="addForm" ng-class="{ 'show-invalid': formInvalid}" ng-submit="add()" bm-form class="edit-drug-order-container" alert-on-exit>
<article class="form-field">
<div class="field-attribute">
<label>{{ ::treatmentConfig.translate('drugName', 'MEDICATION_DRUG_NAME_TITLE') }} </label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ angular.module('bahmni.clinical')
$scope.enrollment = $stateParams.enrollment;
$scope.isDashboardPrinting = false;
var programConfig = appService.getAppDescriptor().getConfigValue("program") || {};
$state.discardChanges = false;

$scope.stateChange = function () {
return $state.current.name === 'patient.dashboard.show';
Expand Down
2 changes: 2 additions & 0 deletions ui/app/clinical/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,12 @@ <h3 class="close" ng-click="closeTeleConsultation()">
<script src="consultation/services/otherTestsProvider.js"></script>
<script src="consultation/services/Notifier.js"></script>
<script src="consultation/services/adhocTeleconsultationService.js"></script>
<script src="consultation/services/exitAlertService.js"></script>

<script src="consultation/services/treatmentConfig.js"></script>
<script src="consultation/filters/observationValue.js"></script>
<script src="consultation/directives/buttonsRadio.js"></script>
<script src="consultation/directives/alertOnExit.js"></script>
<script src="consultation/directives/orderSelector.js"></script>
<script src="consultation/directives/diagnosisAutoComplete.js"></script>
<script src="consultation/directives/newDrugOrders.js"></script>
Expand Down
16 changes: 14 additions & 2 deletions ui/app/common/concept-set/directives/conceptSet.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

angular.module('bahmni.common.conceptSet')
.directive('conceptSet', ['contextChangeHandler', 'appService', 'observationsService', 'messagingService', 'conceptSetService', 'conceptSetUiConfigService', 'spinner',
function (contextChangeHandler, appService, observationsService, messagingService, conceptSetService, conceptSetUiConfigService, spinner) {
.directive('conceptSet', ['contextChangeHandler', 'appService', 'observationsService', 'messagingService', 'conceptSetService', 'conceptSetUiConfigService', 'spinner', '$state',
function (contextChangeHandler, appService, observationsService, messagingService, conceptSetService, conceptSetUiConfigService, spinner, $state) {
var controller = function ($scope) {
var conceptSetName = $scope.conceptSetName;
var ObservationUtil = Bahmni.Common.Obs.ObservationUtil;
Expand Down Expand Up @@ -407,6 +407,18 @@ angular.module('bahmni.common.conceptSet')
}
});

$scope.$on('$stateChangeStart', function () {
if ($scope.obsForm && $scope.obsForm.$dirty) {
$state.dirtyConsultationForm = true;
}
});

$scope.$on("event:changes-saved", function () {
if ($scope.obsForm) {
$scope.obsForm.$dirty = false;
}
});

$scope.$on('$destroy', function () {
deregisterObservationUpdated();
deregisterAddMore();
Expand Down
Loading
Loading