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

BS-14 | Trigger CDSS on the Drug Order Sets #765

Merged
merged 2 commits into from
Nov 1, 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
30 changes: 28 additions & 2 deletions ui/app/clinical/common/services/cdssService.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('bahmni.clinical')
.service('cdssService', ['drugService', function (drugService) {
.service('cdssService', ['drugService', '$rootScope', function (drugService, $rootScope) {
var createMedicationRequest = function (medication, patientUuid, conceptSource) {
return extractCodeInfo(medication, conceptSource).then(function (coding) {
var medicationRequest = {
Expand Down Expand Up @@ -180,6 +180,10 @@ angular.module('bahmni.clinical')
return createConditionResource(condition, patient.uuid, true);
}));

medications = medications.filter(function (medication) {
return angular.isDefined(medication.include) && medication.include || medication.include === undefined;
});

return Promise.all(medications.map(function (medication) {
return createMedicationRequest(medication, patient.uuid, conceptSource).then(function (medicationResource) {
return medicationResource;
Expand All @@ -200,6 +204,27 @@ angular.module('bahmni.clinical')
});
};

var getAlerts = function (cdssEnabled, consultation, patient) {
if (cdssEnabled) {
var consultationData = angular.copy(consultation);
consultationData.patient = patient;

var orderSetTreatments = consultationData.newlyAddedTabTreatments ? consultationData.newlyAddedTabTreatments.allMedicationTabConfig.orderSetTreatments : [];
var drafts = consultationData.newlyAddedTabTreatments ? consultationData.newlyAddedTabTreatments.allMedicationTabConfig.treatments : [];
consultationData.draftDrug = drafts.concat(orderSetTreatments);
var params = createParams(consultationData);
createFhirBundle(params.patient, params.conditions, params.medications, params.diagnosis)
.then(function (bundle) {
var cdssAlerts = drugService.sendDiagnosisDrugBundle(bundle);
cdssAlerts.then(function (response) {
var alerts = response.data;
var existingAlerts = $rootScope.cdssAlerts || [];
$rootScope.cdssAlerts = addNewAlerts(alerts, existingAlerts, bundle);
});
});
}
};

var createParams = function (consultationData) {
var patient = consultationData.patient;
var conditions = consultationData.condition && consultationData.condition.concept.uuid ? consultationData.conditions.concat(consultationData.condition) : consultationData.conditions;
Expand Down Expand Up @@ -309,6 +334,7 @@ angular.module('bahmni.clinical')
createFhirBundle: createFhirBundle,
createParams: createParams,
addNewAlerts: addNewAlerts,
sortInteractionsByStatus: sortInteractionsByStatus
sortInteractionsByStatus: sortInteractionsByStatus,
getAlerts: getAlerts
};
}]);
21 changes: 4 additions & 17 deletions ui/app/clinical/consultation/controllers/addTreatmentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,7 @@ angular.module('bahmni.clinical')
};

var getAlerts = function () {
if ($scope.cdssEnabled) {
var consultationData = angular.copy($scope.consultation);
consultationData.patient = $scope.patient;

consultationData.draftDrug = consultationData.newlyAddedTabTreatments ? consultationData.newlyAddedTabTreatments.allMedicationTabConfig.treatments : [];
var params = cdssService.createParams(consultationData);
cdssService.createFhirBundle(params.patient, params.conditions, params.medications, params.diagnosis)
.then(function (bundle) {
var cdssAlerts = drugService.sendDiagnosisDrugBundle(bundle);
cdssAlerts.then(function (response) {
var alerts = response.data;
var existingAlerts = $rootScope.cdssAlerts || [];
$rootScope.cdssAlerts = cdssService.addNewAlerts(alerts, existingAlerts, bundle);
});
});
}
return cdssService.getAlerts($scope.cdssEnabled, $scope.consultation, $scope.patient);
};

var getConflictingDrugOrder = function (newDrugOrder) {
Expand Down Expand Up @@ -787,7 +772,8 @@ angular.module('bahmni.clinical')
calculateDoseForTemplatesIn(orderSet)
.then(createDrugOrdersAndGetConflicts)
.then(showConflictMessageIfAny)
.then(setUpNewOrderSet);
.then(setUpNewOrderSet)
.then(getAlerts);
};

$scope.removeOrderSet = function () {
Expand All @@ -807,6 +793,7 @@ angular.module('bahmni.clinical')
});
$scope.popupActive = true;
}
getAlerts();
});

$scope.consultation.preSaveHandler.register("drugOrderSaveHandlerKey", saveTreatment);
Expand Down
22 changes: 1 addition & 21 deletions ui/app/clinical/consultation/controllers/diagnosisController.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,7 @@ angular.module('bahmni.clinical')
};

function getAlerts () {
if ($scope.cdssEnabled) {
var consultationData = angular.copy($scope.consultation);
consultationData.patient = $scope.patient;

consultationData.draftDrug = consultationData.newlyAddedTabTreatments ? consultationData.newlyAddedTabTreatments.allMedicationTabConfig.treatments : [];
var params = cdssService.createParams(consultationData);
cdssService.createFhirBundle(params.patient, params.conditions, params.medications, params.diagnosis)
.then(function (bundle) {
var cdssAlerts = drugService.sendDiagnosisDrugBundle(bundle);
cdssAlerts.then(function (response) {
var alerts = response.data;
var existingAlerts = $rootScope.cdssAlerts || [];
$rootScope.cdssAlerts = cdssService.addNewAlerts(alerts, existingAlerts, bundle);
isPastDiagnosisFlagged();
getFlaggedSavedDiagnosisAlert();
getAlertForCurrentDiagnosis();
getConditionAlerts();
getConditionsAlerts();
});
});
}
return cdssService.getAlerts($scope.cdssEnabled, $scope.consultation, $scope.patient);
}

$scope.hasActiveAlerts = function (alerts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,59 @@ angular.module('bahmni.common.displaycontrol.drugOrdersSection')
if (promise) {
spinner.forPromise(promise);
}

var sortInteractionsByStatus = function (arr) {
var order = { "critical": 0, "warning": 1, "info": 2 };
return arr.sort(function (a, b) {
return order[a.indicator] - order[b.indicator];
});
};

$scope.hasActiveAlerts = function (alerts) {
return alerts.some(function (alert) {
return alert.isActive;
});
};

var alertsPresent = function (orders) {
return orders.some(function (drugOrder) {
return drugOrder.alerts && drugOrder.alerts.length > 0 && !$scope.hasActiveAlerts(drugOrder.alerts);
});
};

var filterDrugAlerts = function () {
var drugOrders = $scope.drugOrders;
if (!drugOrders || (drugOrders && !drugOrders.length > 0)) return;

drugOrders.forEach(function (drugOrder) {
var drug = drugOrder.drug;
var cdssAlerts = angular.copy($rootScope.cdssAlerts);
if (cdssAlerts) {
drugOrder.alerts = cdssAlerts.filter(function (cdssAlert) {
return cdssAlert.referenceMedications.some(function (referenceMedication) {
return referenceMedication.coding.some(function (coding) {
return (
drug.uuid === coding.code || drug.name === coding.display
);
}
);
}
);
});

drugOrder.alerts = sortInteractionsByStatus(drugOrder.alerts);
}
});

$scope.alertsPresent = alertsPresent(drugOrders);
};

var watchAlerts = $rootScope.$watch('cdssAlerts', function () {
if (!$rootScope.cdssAlerts) return;
filterDrugAlerts();
}, true);

$scope.$on('$destroy', function () { watchAlerts(); });
};
return {
restrict: 'E',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,53 @@ <h2 class="has-toggle section-title" ng-if="config | titleTranslate" ng-click="t
<table class="drug-order-table treatments-details-table" ng-class="{'drug-order-table-discontinue' : drugOrder.isMarkedForDiscontinue }">
<thead>
<tr>
<th class="empty-header header-alerts" ng-if="alertsPresent"></th>
<th ng-repeat="columnName in columns" ng-class="{ 'active-drugs' : columns.length ===5 ,
'{{::columnName}}':true }"><span>{{columnHeaders[columnName] | translate}}</span></th>
<th class="empty-header noOfActions-{{::config.actions.length}}-width">{{ 'MEDICATIONS_ACTIONS_LABEL'|translate }}</th>
</tr>
</thead>
<tbody ng-repeat="drugOrder in drugOrders">
<tr ng-class="{'highlight' : drugOrder.isBeingEdited, 'edited' : drugOrder.isMarkedForDiscontinue}">
<td ng-repeat="columnName in columns" class="{{columnName}}" ng-class="{'drugNameStopForm' : drugOrder.isMarkedForDiscontinue && columnName === 'drugName' ,'drugNameAddNote': drugOrder.showAdditionalInstructions && columnName === 'drugName' ,'drugNameStopFormAddNote': drugOrder.isMarkedForDiscontinue && drugOrder.showAdditionalInstructions && columnName === 'drugName'}">
<td class="order-alert-row" ng-if="alertsPresent" bm-pop-over autoclose="true">
<button ng-if="drugOrder.alerts && drugOrder.alerts.length > 0 && !hasActiveAlerts(drugOrder.alerts)" class="cdss-alert-icon fl" bm-pop-over-trigger>
<i class="fa fa-exclamation-circle cdss-icon-medication"></i>
</button>
<div class="tooltip cdss-tooltip" bm-pop-over-target>
<cdss-popover alerts="drugOrder.alerts"></cdss-popover>
</div>
</td>
<td ng-repeat="columnName in columns" class="{{columnName}}" ng-class="{'drugNameStopForm' : drugOrder.isMarkedForDiscontinue && columnName === 'drugName' ,'drugNameAddNote': drugOrder.showAdditionalInstructions && columnName === 'drugName' ,'drugNameStopFormAddNote': drugOrder.isMarkedForDiscontinue && drugOrder.showAdditionalInstructions && columnName === 'drugName', 'drugName-alert': alertsPresent}">
<span ng-if="columnName === 'dosage'">{{::drugOrder.getDoseAndUnits()}}</span>
<span ng-if="columnName === 'drugName' && !isDrugOrderSet" title="{{::drugOrder.getDrugOrderName(false)}}">
{{::drugOrder.getDrugOrderName(false)}}
</span>
<span ng-if="columnName === 'drugName' && isDrugOrderSet" title="{{::drugOrder.drugNameDisplay}}">
<input type="checkbox" ng-model="drugOrder.include" ng-click="checkConflictingDrug(drugOrder)" class="fl orderSetStagingAreaCheckbox"/>
{{::drugOrder.drugNameDisplay}}
<span class="order-set-name" ng-if="columnName === 'drugName' && isDrugOrderSet" title="{{::drugOrder.drugNameDisplay}}">
<span class="medication-name">
<!-- <button ng-if="drugOrder.alerts && drugOrder.alerts.length > 0 && !hasActiveAlerts(drugOrder.alerts)" class="cdss-alert-icon fl" bm-pop-over-trigger>
<i class="fa fa-exclamation-circle cdss-icon-medication"></i>
</button> -->
<input type="checkbox" ng-model="drugOrder.include" ng-click="checkConflictingDrug(drugOrder)" class="fl orderSetStagingAreaCheckbox"/>
{{::drugOrder.drugNameDisplay}}
</span>
</span>
<span ng-if="columnName === 'route'">{{::drugOrder.route}}</span>
<span ng-if="columnName === 'duration'">{{::drugOrder.getDurationAndDurationUnits()}}</span>
<span ng-if="columnName === 'frequency'">
{{::drugOrder.getFrequency()}}
<span ng-if="drugOrder.asNeeded">
, {{::'MEDICATION_AS_NEEDED' | translate}}
<span ng-if="columnName === 'frequency'">
{{::drugOrder.getFrequency()}}
<span ng-if="drugOrder.asNeeded">
, {{::'MEDICATION_AS_NEEDED' | translate}}
</span>
</span>
</span>
<span ng-if="columnName === 'startDate'">{{::drugOrder.effectiveStartDate | bahmniDate}}</span>
<span ng-if="columnName === 'stopDate' && drugOrder.isDiscontinuedOrStopped()">{{::drugOrder.effectiveStopDate | bahmniDate}}</span>
<span ng-if="columnName === 'stopReason' && drugOrder.orderReasonConcept && drugOrder.isDiscontinuedOrStopped()">
{{::drugOrder.orderReasonConcept.display || drugOrder.orderReasonConcept.name}}
<span ng-if="drugOrder.orderReasonText"> - {{::drugOrder.orderReasonText}}</span>
</span>
<span ng-if="columnName === 'stopReason' && drugOrder.orderReasonConcept && drugOrder.isDiscontinuedOrStopped()">
{{::drugOrder.orderReasonConcept.display || drugOrder.orderReasonConcept.name}}
<span ng-if="drugOrder.orderReasonText"> - {{::drugOrder.orderReasonText}}</span>
</span>
<span ng-if="columnName === 'instructions'">{{::drugOrder.instructions}}</span>
<span ng-if="columnName === 'quantity'">{{::drugOrder.getQuantityWithUnit()}}</span>

</td>
<td class="buttonColumn" ng-class="{'noActionColumn' :!config.actions ,
'noActionColumnAddNote' : !config.actions && drugOrder.showAdditionalInstructions ,
Expand Down Expand Up @@ -78,6 +93,11 @@ <h2 class="has-toggle section-title" ng-if="config | titleTranslate" ng-click="t
</div>
</td>
</tr>
<tr ng-if="drugOrder.alerts && drugOrder.alerts.length > 0" class="medicationDrugNotes order-alerts">
<td colspan="{{columns.length + 1}}" class="form drug-stop-container">
<cdss-alert-row alerts="drugOrder.alerts" drug-order="drugOrder" consultation="consultation"></cdss-alert-row>
</td>
</tr>
<tr ng-if="drugOrder.showAdditionalInstructions" class="medicationDrugNotes">
<td colspan="{{columns.length + 1}}" class="form drug-stop-container">
<div ng-show="drugOrder.showAdditionalInstructions" class="notes inline-notes">
Expand Down
2 changes: 2 additions & 0 deletions ui/app/styles/bahmni-components/_tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
.alert-detail {
display: flex !important;
align-items: baseline !important;
text-align: left !important;
> span {
display: flex !important;
flex-direction: column !important;
Expand Down Expand Up @@ -125,6 +126,7 @@
}

.tooltip-list {
text-align: left !important;
i {
position: relative !important;
}
Expand Down
Loading
Loading