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-58: Trigger and show CDSS Active alert alert at the diagnosis/conditions and Medications tab #728

Merged
merged 6 commits into from
Oct 25, 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
1 change: 0 additions & 1 deletion ui/app/clinical/common/models/drugOrderViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,6 @@ Bahmni.Clinical.DrugOrderViewModel.createFromContract = function (drugOrderRespo
};
}
viewModel.instructions = administrationInstructions.instructions;
viewModel.audit = drugOrderResponse.audit;
viewModel.additionalInstructions = administrationInstructions.additionalInstructions;
viewModel.quantity = drugOrderResponse.dosingInstructions.quantity;
viewModel.quantityUnit = drugOrderResponse.dosingInstructions.quantityUnits;
Expand Down
10 changes: 2 additions & 8 deletions ui/app/clinical/common/services/cdssService.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,14 @@ angular.module('bahmni.clinical')

var createConditionResource = function (condition, patientUuid, isDiagnosis) {
var conceptLimitIndex = isDiagnosis ? -1 : condition.concept.uuid.lastIndexOf('/');
var conditionStatus = condition.status || condition.certainty;
var activeConditions = ['CONFIRMED', 'PRESUMED', 'ACTIVE'];
var status = activeConditions.indexOf(conditionStatus) > -1 ? 'active' : 'inactive';
var conditionResource = {
resourceType: 'Condition',
id: condition.uuid,
clinicalStatus: {
coding: [
{
code: status,
display: status.charAt(0).toUpperCase() + status.slice(1),
code: 'active',
display: 'Active',
system: 'http://terminology.hl7.org/CodeSystem/condition-clinical'
}
]
Expand Down Expand Up @@ -188,9 +185,6 @@ angular.module('bahmni.clinical')
var activeAlerts = newAlerts.map(function (item) {
item.isActive = true;
item.detail = marked.parse(item.detail);
if (item.source && item.source.url) {
item.detail = item.detail + ' <a href="' + item.source.url + '" target="_blank" ng-show="alert.source.url" class="cdss_alert_source"><i class="fa fa-question-circle"></i></a>';
}
return item;
});
if (!currentAlerts || (currentAlerts && currentAlerts.length === 0)) {
Expand Down
35 changes: 20 additions & 15 deletions ui/app/clinical/consultation/controllers/addTreatmentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,27 +369,32 @@ angular.module('bahmni.clinical')
if ($scope.treatment.isBeingEdited) {
treatments.splice($scope.treatment.currentIndex, 1, $scope.treatment);
$scope.treatment.isBeingEdited = false;
getAlerts();
} else {
treatments.push($scope.treatment);
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;
$rootScope.cdssAlerts = cdssService.addNewAlerts(alerts);
});
});
}
getAlerts();
}
$scope.clearForm();
};

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;
$rootScope.cdssAlerts = cdssService.addNewAlerts(alerts);
});
});
}
};

var getConflictingDrugOrder = function (newDrugOrder) {
var allDrugOrders = $scope.treatments.concat($scope.orderSetTreatments);
allDrugOrders = _.reject(allDrugOrders, newDrugOrder);
Expand Down
17 changes: 17 additions & 0 deletions ui/app/clinical/consultation/controllers/consultationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,23 @@ angular.module('bahmni.clinical').controller('ConsultationController',
return $q.when({});
}
try {
var alerts = $rootScope.cdssAlerts || [];
var activeAlerts = alerts.filter(function (alert) {
return alert.indicator === 'critical' && alert.isActive;
});

if (activeAlerts && activeAlerts.length > 0) {
messagingService.showMessage("error", "{{ 'CDSS_ALERT_SAVE_ERROR' | translate }}");
return $q.when({});
}

var cdssAlerts = $rootScope.cdssAlerts;
cdssAlerts && cdssAlerts.forEach(
function (cdssAlert) {
cdssAlert.isActive = false;
}
);
$rootScope.cdssAlerts = cdssAlerts;
preSaveEvents();
return spinner.forPromise($q.all([preSavePromise(),
encounterService.getEncounterType($state.params.programUuid, sessionService.getLoginLocationUuid())]).then(function (results) {
Expand Down
60 changes: 38 additions & 22 deletions ui/app/clinical/consultation/controllers/diagnosisController.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,39 @@ angular.module('bahmni.clinical')
change to say array[index]=newObj instead array.splice(index,1,newObj);
*/
$scope.consultation.newlyAddedDiagnoses.splice(index, 1, diagnosis);
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;

$rootScope.cdssAlerts = cdssService.addNewAlerts(alerts);
isPastDiagnosisFlagged();
getFlaggedSavedDiagnosisAlert();
getAlertForCurrentDiagnosis();
});
});
}
getAlerts();
}
};
};

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;

$rootScope.cdssAlerts = cdssService.addNewAlerts(alerts);
isPastDiagnosisFlagged();
getFlaggedSavedDiagnosisAlert();
getAlertForCurrentDiagnosis();
});
});
}
}

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

var isPastDiagnosisFlagged = function () {
var pastDiagnoses = $scope.consultation.pastDiagnoses;
var alerts = $scope.cdssAlerts;
Expand Down Expand Up @@ -155,9 +165,6 @@ angular.module('bahmni.clinical')
});
});
if (diagnosis.alerts) {
diagnosis.alerts.forEach(function (item) {
item.isActive = true;
});
diagnosis.alerts = cdssService.sortInteractionsByStatus(diagnosis.alerts);
flaggedDiagnoses.push(diagnosis);
}
Expand All @@ -166,6 +173,14 @@ angular.module('bahmni.clinical')
return flaggedDiagnoses;
};

var alertsWatch = $rootScope.$watch('cdssAlerts', function () {
getAlertForCurrentDiagnosis();
});

$scope.$on('$destroy', function () {
alertsWatch();
});

var addPlaceHolderDiagnosis = function () {
var diagnosis = new Bahmni.Common.Domain.Diagnosis('');
$scope.consultation.newlyAddedDiagnoses.push(diagnosis);
Expand Down Expand Up @@ -386,6 +401,7 @@ angular.module('bahmni.clinical')
$scope.removeObservation = function (index) {
if (index >= 0) {
$scope.consultation.newlyAddedDiagnoses.splice(index, 1);
getAlerts();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,43 +230,5 @@ angular.module('bahmni.clinical')
return _.find(drugOrder.orderAttributes, {name: attributeName});
};

var getPreviousDrugAlerts = function () {
var drugOrderGroups = $scope.consultation.drugOrderGroups;
if (!drugOrderGroups || (drugOrderGroups && !drugOrderGroups.length > 0)) return;
drugOrderGroups.forEach(function (order) {
var drugOrders = order.drugOrders;
drugOrders && drugOrders.forEach(function (drugOrder) {
var drug = drugOrder.drug;
var cdssAlerts = $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
);
}
);
}
);
});
}
});
});
};

var cdssAlertsWatcher = $rootScope.$watch('cdssAlerts', function () {
getPreviousDrugAlerts();
});

$scope.$on('$destroy', function () {
cdssAlertsWatcher();
});

init();
}]);
29 changes: 27 additions & 2 deletions ui/app/clinical/consultation/controllers/treatmentController.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

angular.module('bahmni.clinical')
.controller('TreatmentController', ['$scope', 'clinicalAppConfigService', 'treatmentConfig', '$stateParams',
function ($scope, clinicalAppConfigService, treatmentConfig, $stateParams) {
.controller('TreatmentController', ['$scope', 'clinicalAppConfigService', 'treatmentConfig', '$stateParams', '$rootScope', 'cdssService',
function ($scope, clinicalAppConfigService, treatmentConfig, $stateParams, $rootScope, cdssService) {
var init = function () {
var drugOrderHistoryConfig = treatmentConfig.drugOrderHistoryConfig || {};
$scope.drugOrderHistoryView = drugOrderHistoryConfig.view || 'default';
Expand All @@ -16,7 +16,32 @@ angular.module('bahmni.clinical')
$scope.newOrderSet = $scope.consultation.newlyAddedTabTreatments[$scope.tabConfigName].newOrderSet;
};

var getPreviousDrugAlerts = function () {
var treatments = $scope.treatments;
treatments && treatments.forEach(function (drugOrder) {
var drug = drugOrder.drug;
var cdssAlerts = $rootScope.cdssAlerts;
if (!cdssAlerts) return;
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 = cdssService.sortInteractionsByStatus(drugOrder.alerts);
});
};

$scope.$watch('consultation.newlyAddedTabTreatments', initializeTreatments);
$rootScope.$watch('cdssAlerts', getPreviousDrugAlerts);

$scope.enrollment = $stateParams.enrollment;
$scope.treatmentConfig = treatmentConfig;
Expand Down
101 changes: 101 additions & 0 deletions ui/app/clinical/consultation/directives/cdssAlertRow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict';

angular.module('bahmni.clinical')
.controller('cdssAlertRowController', ['$scope', '$rootScope', '$stateParams', 'appService', 'drugService', function ($scope, $rootScope, $stateParams, appService, drugService) {
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];
});
};

var getPreviousDrugAlerts = function () {
var drugOrderGroups = $scope.consultation ? $scope.consultation.drugOrderGroups : [];
if (!drugOrderGroups || (drugOrderGroups && !drugOrderGroups.length > 0)) return;

drugOrderGroups.forEach(function (order) {
var drugOrders = order.drugOrders;
drugOrders && drugOrders.forEach(function (drugOrder) {
var drug = drugOrder.drug;
var cdssAlerts = $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 = drugOrder.alerts.map(function (item) {
item.isActive = false;
return item;
});

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

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

$scope.closeAlert = function (alert) {
var alertItem = $rootScope.cdssAlerts.find(function (item) {
return item.uuid === alert.uuid;
});
if (alertItem) {
alertItem.isActive = false;
}
};

$scope.toggleDetails = function (alert) {
var cdssAlerts = $rootScope.cdssAlerts;
var cdssAlert = cdssAlerts.find(function (cdssAlert) {
return cdssAlert.uuid === alert.uuid;
});
if (cdssAlert) {
cdssAlert.showDetails = !cdssAlert.showDetails;
}
};

$scope.auditOptions = function () {
return appService
.getAppDescriptor()
.getConfigValue('cdssDismissalOptionsToDisplay');
};

$scope.auditForm = {};

$scope.submitAudit = function (alert) {
var patientUuid = $stateParams.patientUuid;
var message = alert.summary.replace(/"/g, '');
var eventType = 'Dismissed: ' + $scope.auditForm.audit;

$scope.closeAlert(alert);
return drugService.cdssAudit(patientUuid, eventType, message, 'CDSS');
};

var cdssAlertsWatcher = $rootScope.$watch('cdssAlerts', getPreviousDrugAlerts);

$scope.$on('$destroy', cdssAlertsWatcher);
}])
.directive('cdssAlertRow', function () {
return {
restrict: 'E',
controller: 'cdssAlertRowController',
templateUrl: './consultation/views/cdssAlertRow.html',
scope: {
alerts: '=',
consultation: '='
}
};
});
Loading
Loading