Skip to content

Commit

Permalink
Arjun | BAH-3157 | Ability to switch IPD to non-IPD medication (#668)
Browse files Browse the repository at this point in the history
* add. ability to update ipd to non ipd and bring it to new treatment section

* refactor. IPD buttons to be enabled or disabled based on schedules

* refactor. disable IPD button for stopped orders

* add. disable IPD button when encounter is passed

* refactor. switch IPD to non-IPD medication in same encounter with strike-through

* refactor. remove rootScope variables for passing encounter Ids
  • Loading branch information
Arjun-Go authored Aug 18, 2023
1 parent a5f3524 commit 9e68996
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 45 deletions.
17 changes: 14 additions & 3 deletions ui/app/clinical/common/services/treatmentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
};

Expand All @@ -204,6 +214,7 @@ angular.module('bahmni.clinical')
getConfig: getConfig,
getPrescribedDrugOrders: getPrescribedDrugOrders,
getPrescribedAndActiveDrugOrders: getPrescribedAndActiveDrugOrders,
getMedicationSchedulesForOrders: getMedicationSchedulesForOrders,
getNonCodedDrugConcept: getNonCodedDrugConcept,
getAllDrugOrdersFor: getAllDrugOrdersFor,
voidDrugOrder: voidDrugOrder,
Expand Down
48 changes: 26 additions & 22 deletions ui/app/clinical/consultation/controllers/addTreatmentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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();
});
}
});

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
}
Expand All @@ -762,15 +766,15 @@ 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);
});
};

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
};
}

Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions ui/app/clinical/consultation/directives/newDrugOrders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ui/app/clinical/consultation/views/newDrugOrders.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h2 class="section-title fl">{{ ::'MEDICATION_NEW_PRESCRIPTION' | translate}}</h
</div>
<div class="button-group-wrapper">
<div class="button-group">
<button ng-show="enableIPDFeature" class="ipd-btn" ng-click="toggleCareSetting(newTreatment)" ng-disabled="newTreatment.action === 'REVISE'">
<button ng-show="enableIPDFeature" class="ipd-btn" ng-click="toggleCareSetting(newTreatment)" ng-disabled="shouldDisableIPDButton(newTreatment)">
<i class="fa fa-check" ng-show="newTreatment.careSetting === 'INPATIENT'"></i>
{{ ::'IPD_BUTTON' | translate}}
</button>
Expand Down
Loading

0 comments on commit 9e68996

Please sign in to comment.