diff --git a/ui/app/clinical/common/services/treatmentService.js b/ui/app/clinical/common/services/treatmentService.js index dc867bc140..85797e9fa1 100644 --- a/ui/app/clinical/common/services/treatmentService.js +++ b/ui/app/clinical/common/services/treatmentService.js @@ -36,6 +36,16 @@ angular.module('bahmni.clinical') }); }; + var getMedicationSchedulesForOrders = function (patientUuid, orderUuids) { + return $http.get(Bahmni.Common.Constants.medicationSchedulesForOrders, { + params: { + patientUuid: patientUuid, + orderUuids: orderUuids + }, + withCredentials: true + }); + }; + var getConfig = function () { return $http.get(Bahmni.Common.Constants.drugOrderConfigurationUrl, { withCredentials: true @@ -102,7 +112,7 @@ angular.module('bahmni.clinical') var getAllDrugOrdersFor = function (patientUuid, conceptSetToBeIncluded, conceptSetToBeExcluded, isActive, patientProgramUuid) { var deferred = $q.defer(); - var params = {patientUuid: patientUuid}; + var params = { patientUuid: patientUuid }; if (conceptSetToBeIncluded) { params.includeConceptSet = conceptSetToBeIncluded; } @@ -155,7 +165,7 @@ angular.module('bahmni.clinical') }]; var subject = "Prescription for consultation at " + $rootScope.facilityLocation.name + " on " + $filter("bahmniDate")(prescriptionDetails.visitDate); var body = transmissionService.getSharePrescriptionMailContent(prescriptionDetails); - var emailUrl = appService.getAppDescriptor().formatUrl(Bahmni.Common.Constants.sendViaEmailUrl, {'patientUuid': prescriptionDetails.patient.uuid}); + var emailUrl = appService.getAppDescriptor().formatUrl(Bahmni.Common.Constants.sendViaEmailUrl, { 'patientUuid': prescriptionDetails.patient.uuid }); transmissionService.sendEmail(attachments, subject, body, emailUrl, [], []); }); renderAndSendPromise.resolve(); @@ -195,7 +205,7 @@ angular.module('bahmni.clinical') var printParams = appService.getAppDescriptor().getConfigValue("prescriptionPrint") || {}; var templateUrl = appService.getAppDescriptor().getConfigValue("prescriptionPrintTemplateUrl") || '../common/displaycontrols/prescription/views/prescription.html'; var fileName = patient.givenName + patient.familyName + "_" + patient.identifier + "_Prescription"; - printer.print(templateUrl, {patient: patient, encounterDrugOrderMap: encounterDrugOrderMap, printParams: printParams, additionalInfo: additionalInfo }, fileName); + printer.print(templateUrl, { patient: patient, encounterDrugOrderMap: encounterDrugOrderMap, printParams: printParams, additionalInfo: additionalInfo }, fileName); } }; @@ -204,6 +214,7 @@ angular.module('bahmni.clinical') getConfig: getConfig, getPrescribedDrugOrders: getPrescribedDrugOrders, getPrescribedAndActiveDrugOrders: getPrescribedAndActiveDrugOrders, + getMedicationSchedulesForOrders: getMedicationSchedulesForOrders, getNonCodedDrugConcept: getNonCodedDrugConcept, getAllDrugOrdersFor: getAllDrugOrdersFor, voidDrugOrder: voidDrugOrder, diff --git a/ui/app/clinical/consultation/controllers/addTreatmentController.js b/ui/app/clinical/consultation/controllers/addTreatmentController.js index ddaf74d53e..8dee1bcf66 100644 --- a/ui/app/clinical/consultation/controllers/addTreatmentController.js +++ b/ui/app/clinical/consultation/controllers/addTreatmentController.js @@ -5,8 +5,8 @@ angular.module('bahmni.clinical') '$timeout', 'clinicalAppConfigService', 'ngDialog', '$window', 'messagingService', 'appService', 'activeDrugOrders', 'orderSetService', '$q', 'locationService', 'spinner', '$translate', function ($scope, $rootScope, contextChangeHandler, treatmentConfig, drugService, $timeout, - clinicalAppConfigService, ngDialog, $window, messagingService, appService, activeDrugOrders, - orderSetService, $q, locationService, spinner, $translate) { + clinicalAppConfigService, ngDialog, $window, messagingService, appService, activeDrugOrders, + orderSetService, $q, locationService, spinner, $translate) { var DateUtil = Bahmni.Common.Util.DateUtil; var DrugOrderViewModel = Bahmni.Clinical.DrugOrderViewModel; var scrollTop = _.partial($window.scrollTo, 0, 0); @@ -139,7 +139,7 @@ angular.module('bahmni.clinical') var existingTreatment = false; angular.forEach($scope.consultation.discontinuedDrugs, function (drugOrder) { existingTreatment = _.some($scope.treatments, function (treatment) { - return treatment.getDisplayName() === drugOrder.getDisplayName(); + return treatment.getDisplayName() === drugOrder.getDisplayName() && treatment.careSetting === drugOrder.careSetting; }) && drugOrder.isMarkedForDiscontinue; }); return existingTreatment; @@ -186,7 +186,7 @@ angular.module('bahmni.clinical') setSortWeightForOrderSetDrugs(refilledOrderGroupOrders); // Fetch the orderSet for the drugOrder - var matchedOrderSet = _.find(orderSets, {uuid: drugOrder.orderSetUuid}); + var matchedOrderSet = _.find(orderSets, { uuid: drugOrder.orderSetUuid }); // Find the drugs in ordered DrugOrderSet which matches with the matchedOrderSet SetMembers var orderSetMembersOfMatchedOrderSet = matchedOrderSet.orderSetMembers; @@ -208,11 +208,11 @@ angular.module('bahmni.clinical') var baseDose = eachMember.orderTemplate.dosingInstructions.dose; var drugName = eachMember.orderTemplate.concept.name; return orderSetService.getCalculatedDose($scope.patient.uuid, drugName, baseDose, doseUnits, $scope.newOrderSet.name) - .then(function (calculatedDosage) { - refilledOrderGroupOrders[index].uniformDosingType.dose = calculatedDosage.dose; - refilledOrderGroupOrders[index].uniformDosingType.doseUnits = calculatedDosage.doseUnit; - refilledOrderGroupOrders[index].calculateQuantityAndUnit(); - }); + .then(function (calculatedDosage) { + refilledOrderGroupOrders[index].uniformDosingType.dose = calculatedDosage.dose; + refilledOrderGroupOrders[index].uniformDosingType.doseUnits = calculatedDosage.doseUnit; + refilledOrderGroupOrders[index].calculateQuantityAndUnit(); + }); } }); @@ -261,6 +261,10 @@ angular.module('bahmni.clinical') refillDrugOrders(drugOrders); }); + $scope.$on("event:updateDrugOrderType", function (event, drugOrder) { + $scope.treatments.push(drugOrder); + }); + $scope.$on("event:discontinueDrugOrder", function (event, drugOrder) { drugOrder.isMarkedForDiscontinue = true; drugOrder.isEditAllowed = false; @@ -370,23 +374,23 @@ angular.module('bahmni.clinical') var getConflictingDrugOrder = function (newDrugOrder) { var allDrugOrders = $scope.treatments.concat($scope.orderSetTreatments); allDrugOrders = _.reject(allDrugOrders, newDrugOrder); - var unsavedNotBeingEditedOrders = _.filter(allDrugOrders, {isBeingEdited: false}); + var unsavedNotBeingEditedOrders = _.filter(allDrugOrders, { isBeingEdited: false }); var existingDrugOrders; if (newDrugOrder.isBeingEdited) { - existingDrugOrders = _.reject($scope.consultation.activeAndScheduledDrugOrders, {uuid: newDrugOrder.previousOrderUuid}); + existingDrugOrders = _.reject($scope.consultation.activeAndScheduledDrugOrders, { uuid: newDrugOrder.previousOrderUuid }); } else { existingDrugOrders = $scope.consultation.activeAndScheduledDrugOrders; } existingDrugOrders = existingDrugOrders.concat(unsavedNotBeingEditedOrders); var potentiallyOverlappingOrders = existingDrugOrders.filter(function (drugOrder) { - return (drugOrder.getDisplayName() === newDrugOrder.getDisplayName() && drugOrder.overlappingScheduledWith(newDrugOrder)); + return (drugOrder.getDisplayName() === newDrugOrder.getDisplayName() && drugOrder.overlappingScheduledWith(newDrugOrder) && newDrugOrder.careSetting === drugOrder.careSetting); }); setEffectiveDates(newDrugOrder, potentiallyOverlappingOrders); var alreadyActiveSimilarOrders = existingDrugOrders.filter(function (drugOrder) { - return (drugOrder.getDisplayName() === newDrugOrder.getDisplayName() && drugOrder.overlappingScheduledWith(newDrugOrder)); + return (drugOrder.getDisplayName() === newDrugOrder.getDisplayName() && drugOrder.overlappingScheduledWith(newDrugOrder) && newDrugOrder.careSetting === drugOrder.careSetting); }); if (alreadyActiveSimilarOrders.length > 0) { @@ -488,16 +492,16 @@ angular.module('bahmni.clinical') var contextChange = function () { var errorMessages = Bahmni.Clinical.Constants.errorMessages; if (isSameDrugBeingDiscontinuedAndOrdered()) { - return {allow: false, errorMessage: $translate.instant(errorMessages.discontinuingAndOrderingSameDrug)}; + return { allow: false, errorMessage: $translate.instant(errorMessages.discontinuingAndOrderingSameDrug) }; } if ($scope.incompleteDrugOrders()) { $scope.formInvalid = true; - return {allow: false}; + return { allow: false }; } if ($scope.unaddedDrugOrders()) { - return {allow: false, errorMessage: $translate.instant(errorMessages.incompleteForm)}; + return { allow: false, errorMessage: $translate.instant(errorMessages.incompleteForm) }; } - return {allow: true}; + return { allow: true }; }; var setIsNotBeingEdited = function (treatment) { @@ -607,7 +611,7 @@ angular.module('bahmni.clinical') $scope.consultation.newlyAddedTreatments = allTreatmentsAcrossTabs.concat(includedOrderSetTreatments); if ($scope.consultation.discontinuedDrugs) { $scope.consultation.discontinuedDrugs.forEach(function (discontinuedDrug) { - var removableOrder = _.find(activeDrugOrders, {uuid: discontinuedDrug.uuid}); + var removableOrder = _.find(activeDrugOrders, { uuid: discontinuedDrug.uuid }); if (discontinuedDrug) { removableOrder.orderReasonText = discontinuedDrug.orderReasonText; removableOrder.dateActivated = null; @@ -721,7 +725,7 @@ angular.module('bahmni.clinical') }); ngDialog.open({ template: 'consultation/views/treatmentSections/conflictingOrderSet.html', - data: {'conflictingDrugOrders': conflictingDrugOrders} + data: { 'conflictingDrugOrders': conflictingDrugOrders } }); $scope.popupActive = true; }; @@ -752,7 +756,7 @@ angular.module('bahmni.clinical') drugOrder.include = false; ngDialog.open({ template: 'consultation/views/treatmentSections/conflictingOrderSet.html', - data: {'conflictingDrugOrders': [conflictingDrugOrder]} + data: { 'conflictingDrugOrders': [conflictingDrugOrder] } }); $scope.popupActive = true; } @@ -762,7 +766,7 @@ angular.module('bahmni.clinical') var mergeActiveAndScheduledWithDiscontinuedOrders = function () { _.each($scope.consultation.discontinuedDrugs, function (discontinuedDrug) { - _.remove($scope.consultation.activeAndScheduledDrugOrders, {'uuid': discontinuedDrug.uuid}); + _.remove($scope.consultation.activeAndScheduledDrugOrders, { 'uuid': discontinuedDrug.uuid }); $scope.consultation.activeAndScheduledDrugOrders.push(discontinuedDrug); }); }; @@ -770,7 +774,7 @@ angular.module('bahmni.clinical') var showRulesInMedication = function (medicationConfig) { $scope.showRulesInMedication = false; if (medicationConfig !== 'undefined' && medicationConfig.tabConfig !== 'undefined' && medicationConfig.tabConfig.allMedicationTabConfig - !== 'undefined' && medicationConfig.tabConfig.allMedicationTabConfig.orderSet !== 'undefined') { + !== 'undefined' && medicationConfig.tabConfig.allMedicationTabConfig.orderSet !== 'undefined') { if (medicationConfig.tabConfig.allMedicationTabConfig.orderSet.showRulesInMedication) { $scope.showRulesInMedication = true; } diff --git a/ui/app/clinical/consultation/controllers/drugOrderHistoryController.js b/ui/app/clinical/consultation/controllers/drugOrderHistoryController.js index 27ba7e7948..3e3f9f45f6 100644 --- a/ui/app/clinical/consultation/controllers/drugOrderHistoryController.js +++ b/ui/app/clinical/consultation/controllers/drugOrderHistoryController.js @@ -4,7 +4,7 @@ angular.module('bahmni.clinical') .controller('DrugOrderHistoryController', ['$scope', '$filter', '$stateParams', 'activeDrugOrders', 'appService', 'treatmentConfig', 'treatmentService', 'spinner', 'drugOrderHistoryHelper', 'visitHistory', '$translate', '$rootScope', 'providerService', function ($scope, $filter, $stateParams, activeDrugOrders, appService, treatmentConfig, treatmentService, spinner, - drugOrderHistoryHelper, visitHistory, $translate, $rootScope, providerService) { + drugOrderHistoryHelper, visitHistory, $translate, $rootScope, providerService) { var DrugOrderViewModel = Bahmni.Clinical.DrugOrderViewModel; var DateUtil = Bahmni.Common.Util.DateUtil; var currentVisit = visitHistory.activeVisit; @@ -17,8 +17,24 @@ angular.module('bahmni.clinical') $scope.selectedDrugs = {}; if ($scope.enableIPDFeature) { - $scope.toggleCareSetting = function (drugOrder) { - drugOrder.careSetting = drugOrder.careSetting === Bahmni.Clinical.Constants.careSetting.inPatient ? Bahmni.Clinical.Constants.careSetting.outPatient : Bahmni.Clinical.Constants.careSetting.inPatient; + $scope.updateOrderType = function (drugOrder) { + var updatedDrugOrder = angular.copy(drugOrder); + updatedDrugOrder.careSetting = updatedDrugOrder.careSetting === Bahmni.Clinical.Constants.careSetting.outPatient ? Bahmni.Clinical.Constants.careSetting.inPatient : Bahmni.Clinical.Constants.careSetting.outPatient; + if (updatedDrugOrder.previousOrderUuid !== undefined) { + updatedDrugOrder.previousOrderUuid = null; + updatedDrugOrder.scheduledDate = null; + } + $rootScope.$broadcast("event:updateDrugOrderType", updatedDrugOrder); + $rootScope.$broadcast("event:discontinueDrugOrder", drugOrder); + }; + + $scope.disableIPDButton = function (drugOrder) { + return ($scope.medicationSchedules && + $scope.medicationSchedules.some(function (schedule) { + return schedule.order.uuid === drugOrder.uuid; + })) || + !drugOrder.isActive() || !drugOrder.isDiscontinuedAllowed || + $scope.consultation.encounterUuid !== drugOrder.encounterUuid; }; } @@ -64,6 +80,7 @@ angular.module('bahmni.clinical') if (treatmentConfig.drugOrderHistoryConfig.numberOfVisits !== undefined && treatmentConfig.drugOrderHistoryConfig.numberOfVisits !== null && treatmentConfig.drugOrderHistoryConfig.numberOfVisits === 0) { $scope.consultation.drugOrderGroups = [$scope.consultation.drugOrderGroups[0]]; } + $rootScope.$broadcast("event:setEncounterId", $scope.consultation.encounterUuid); }; $scope.isAnyDrugSelected = function () { @@ -144,6 +161,17 @@ angular.module('bahmni.clinical') createPrescriptionGroups($scope.consultation.activeAndScheduledDrugOrders); })); }; + + const getActiveAndPrescribedDrugOrdersUuids = function () { + return $scope.consultation.activeAndScheduledDrugOrders.map(function (drugOrder) { + return drugOrder.uuid; + }); + }; + + $scope.enableIPDFeature && spinner.forPromise(treatmentService.getMedicationSchedulesForOrders($stateParams.patientUuid, getActiveAndPrescribedDrugOrdersUuids()).then(function (response) { + $scope.medicationSchedules = response.data; + })); + $scope.getOrderReasonConcept = function (drugOrder) { if (drugOrder.orderReasonConcept) { return drugOrder.orderReasonConcept.display || drugOrder.orderReasonConcept.name; @@ -280,7 +308,7 @@ angular.module('bahmni.clinical') }; var getAttribute = function (drugOrder, attributeName) { - return _.find(drugOrder.orderAttributes, {name: attributeName}); + return _.find(drugOrder.orderAttributes, { name: attributeName }); }; init(); diff --git a/ui/app/clinical/consultation/directives/newDrugOrders.js b/ui/app/clinical/consultation/directives/newDrugOrders.js index 1e6122b417..a8071f603b 100644 --- a/ui/app/clinical/consultation/directives/newDrugOrders.js +++ b/ui/app/clinical/consultation/directives/newDrugOrders.js @@ -5,9 +5,17 @@ angular.module('bahmni.clinical') var controller = function ($scope, $rootScope, appService) { $scope.enableIPDFeature = appService.getAppDescriptor().getConfigValue("enableIPDFeature"); if ($scope.enableIPDFeature) { + $rootScope.$on("event:setEncounterId", function (event, encounterId) { + $scope.encounterId = encounterId; + }); + $scope.toggleCareSetting = function (newTreatment) { newTreatment.careSetting = newTreatment.careSetting === Bahmni.Clinical.Constants.careSetting.inPatient ? Bahmni.Clinical.Constants.careSetting.outPatient : Bahmni.Clinical.Constants.careSetting.inPatient; }; + + $scope.shouldDisableIPDButton = function (treatment) { + return $scope.encounterId !== treatment.encounterUuid && treatment.encounterUuid !== undefined; + }; } $scope.edit = function (drugOrder, index) { $rootScope.$broadcast("event:editDrugOrder", drugOrder, index); diff --git a/ui/app/clinical/consultation/views/newDrugOrders.html b/ui/app/clinical/consultation/views/newDrugOrders.html index 03451659d4..df78304f6b 100644 --- a/ui/app/clinical/consultation/views/newDrugOrders.html +++ b/ui/app/clinical/consultation/views/newDrugOrders.html @@ -41,7 +41,7 @@