Skip to content

Commit

Permalink
add. logic to add observations and dispenser info in prescription
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjun-Go committed Aug 30, 2023
1 parent e6b39b6 commit d01c2e7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
28 changes: 16 additions & 12 deletions ui/app/clinical/common/services/treatmentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,18 @@ angular.module('bahmni.clinical')
});
};

var getOrderedProviderAttributesForPrint = function (providerAttributeData) {
const providerAttributeTypesToFilter = appService.getAppDescriptor().getConfigValue("providerAttributesForPrint") || [];
var filteredProviderAttributes = providerAttributeData.filter(function (attribute) {
return providerAttributeTypesToFilter.includes(attribute.attributeType.display);
var getProviderAttributesForPrint = function (attributeData, attributeTypesToFilter) {
if (!attributeTypesToFilter) return;
var filteredAttributes = attributeData.filter(function (attribute) {
return attributeTypesToFilter.includes(attribute.attributeType.display);
});
filteredProviderAttributes.sort(function (a, b) {
return providerAttributeTypesToFilter.indexOf(a.attributeType.display) - providerAttributeTypesToFilter.indexOf(b.attributeType.display);
filteredAttributes.sort(function (a, b) {
return attributeTypesToFilter.indexOf(a.attributeType.display) - attributeTypesToFilter.indexOf(b.attributeType.display);
});
return filteredProviderAttributes;
return filteredAttributes;
};

var printSelectedPrescriptions = function (drugOrdersForPrint, patient, additionalInfo, diagnosesCodes) {
var printSelectedPrescriptions = function (printPrescriptionFeatureConfig, drugOrdersForPrint, patient, additionalInfo, diagnosesCodes, dispenserInfo, observationsEntries) {
if (drugOrdersForPrint.length > 0) {
var encounterDrugOrderMap = Object.values(drugOrdersForPrint.reduce(function (orderMap, item) {
const providerUuid = item.provider.uuid;
Expand All @@ -202,10 +202,14 @@ angular.module('bahmni.clinical')
return orderMap;
}, {}));

var printParams = appService.getAppDescriptor().getConfigValue("prescriptionPrint") || {};
var templateUrl = appService.getAppDescriptor().getConfigValue("prescriptionPrintTemplateUrl") || '../common/displaycontrols/prescription/views/prescription.html';
var printParams = {
title: printPrescriptionFeatureConfig.title || "",
header: printPrescriptionFeatureConfig.header || "",
logo: printPrescriptionFeatureConfig.logo || ""
};
var templateUrl = printPrescriptionFeatureConfig.templateUrl || '../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, diagnosesCodes: diagnosesCodes }, fileName);
printer.print(templateUrl, { patient: patient, encounterDrugOrderMap: encounterDrugOrderMap, printParams: printParams, additionalInfo: additionalInfo, diagnosesCodes: diagnosesCodes, dispenserInfo: dispenserInfo, observationsEntries: observationsEntries }, fileName);
}
};

Expand All @@ -220,6 +224,6 @@ angular.module('bahmni.clinical')
voidDrugOrder: voidDrugOrder,
sharePrescriptions: sharePrescriptions,
printSelectedPrescriptions: printSelectedPrescriptions,
getOrderedProviderAttributesForPrint: getOrderedProviderAttributesForPrint
getProviderAttributesForPrint: getProviderAttributesForPrint
};
}]);
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

angular.module('bahmni.clinical')
.controller('DrugOrderHistoryController', ['$scope', '$filter', '$stateParams', 'activeDrugOrders', 'appService',
.controller('DrugOrderHistoryController', ['$q', '$scope', '$filter', '$stateParams', 'activeDrugOrders', 'appService',
'treatmentConfig', 'treatmentService', 'spinner', 'drugOrderHistoryHelper', 'visitHistory', '$translate', '$rootScope', 'providerService', 'observationsService', 'diagnosisService',
function ($scope, $filter, $stateParams, activeDrugOrders, appService, treatmentConfig, treatmentService, spinner,
function ($q, $scope, $filter, $stateParams, activeDrugOrders, appService, treatmentConfig, treatmentService, spinner,
drugOrderHistoryHelper, visitHistory, $translate, $rootScope, providerService, observationsService, diagnosisService) {
var DrugOrderViewModel = Bahmni.Clinical.DrugOrderViewModel;
var DateUtil = Bahmni.Common.Util.DateUtil;
Expand All @@ -13,7 +13,7 @@ angular.module('bahmni.clinical')
$scope.dispensePrivilege = Bahmni.Clinical.Constants.dispensePrivilege;
$scope.scheduledDate = DateUtil.getDateWithoutTime(DateUtil.addDays(DateUtil.now(), 1));
$scope.enableIPDFeature = appService.getAppDescriptor().getConfigValue("enableIPDFeature");
$scope.enablePrintSelectedDrugs = appService.getAppDescriptor().getConfigValue("enablePrintSelectedDrugs");
$scope.printPrescriptionFeature = appService.getAppDescriptor().getConfigValue("printPrescriptionFeature");
$scope.selectedDrugs = {};

if ($scope.enableIPDFeature) {
Expand Down Expand Up @@ -93,6 +93,8 @@ angular.module('bahmni.clinical')
var drugOrdersForPrint = [];
var promises = [];
var diagnosesCodes = "";
var dispenserInfo = [];
var observationsEntries = [];

angular.forEach($scope.selectedDrugs, function (selected, drugOrderIndex) {
var selectedDrugOrder = drugOrderIndex.split("/");
Expand All @@ -106,7 +108,7 @@ angular.module('bahmni.clinical')
promises.push(promise);

promise.then(function (response) {
drugOrder.provider.attributes = treatmentService.getOrderedProviderAttributesForPrint(response.data.results);
drugOrder.provider.attributes = treatmentService.getProviderAttributesForPrint(response.data.results, $scope.printPrescriptionFeature.providerAttributesForPrint);
}).catch(function (error) {
console.error("Error fetching provider attributes: ", error);
});
Expand All @@ -115,32 +117,29 @@ angular.module('bahmni.clinical')
}
});

var diagnosesPromise = diagnosisService.getPatientDiagnosis($stateParams.patientUuid);
promises.push(diagnosesPromise);

diagnosesPromise.then(function (response) {
var diagnoses = response.data;
console.log(diagnoses);
var promise = $q.all([diagnosisService.getPatientDiagnosis($stateParams.patientUuid), providerService.getAttributesForProvider($rootScope.currentProvider.uuid), observationsService.fetch($stateParams.patientUuid, $scope.printPrescriptionFeature.observationsConcepts, "latest", null, null, null, null, null)]).then(function (response) {
const diagnoses = response[0].data;
const dispenserAttributes = response[1].data.results;
observationsEntries = response[2].data;
dispenserInfo = treatmentService.getProviderAttributesForPrint(dispenserAttributes, $scope.printPrescriptionFeature.providerAttributesForPrint);
angular.forEach(diagnoses, function (diagnosis) {
console.log("g = ", diagnosis);
if (diagnosis.order === "PRIMARY" && diagnosis.certainty === "CONFIRMED") {
if (diagnosis.order === $scope.printPrescriptionFeature.printDiagnosis.order &&
diagnosis.certainty === $scope.printPrescriptionFeature.printDiagnosis.certainity) {
if (diagnosesCodes.length > 0) {
diagnosesCodes += ", ";
}
diagnosesCodes += diagnosis.codedAnswer.mappings[0].code;
}
});
}).catch(function (error) {
console.error("Error fetching diagnosis: ", error);
});
promises.push(promise);

Promise.all(promises).then(function () {
var additionalInfo = {};
additionalInfo.visitType = currentVisit ? currentVisit.visitType.display : "";
additionalInfo.currentDate = new Date();
additionalInfo.facilityLocation = $rootScope.facilityLocation;
treatmentService.printSelectedPrescriptions(drugOrdersForPrint, $scope.patient, additionalInfo, diagnosesCodes);
console.log(diagnosesCodes);
treatmentService.printSelectedPrescriptions($scope.printPrescriptionFeature, drugOrdersForPrint, $scope.patient, additionalInfo, diagnosesCodes, dispenserInfo, observationsEntries);
$scope.selectedDrugs = {};
}).catch(function (error) {
console.error("Error fetching details for print: ", error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<span>{{drugOrderGroup.label | bahmniDate}}</span>
<i class="fa fa-star current-visit-icon" title="Current visit" ng-if="drugOrderGroup.isCurrentVisit"></i>
</label>
<button ng-show="enablePrintSelectedDrugs.enabled" ng-disabled="!isAnyDrugSelected()" type="submit" class="secondary-button print-drugs-btn fr" form="prescribedDrugs">{{ ::'MEDICATION_PRINT' | translate }}</button>
<button ng-show="printPrescriptionFeature" ng-disabled="!isAnyDrugSelected()" type="submit" class="secondary-button print-drugs-btn fr" form="prescribedDrugs">{{ ::'MEDICATION_PRINT' | translate }}</button>
<button class="secondary-button refill-drugs-btn fr" ng-click="refillAll(drugOrderGroup.drugOrders)" ng-if="!drugOrderGroupsEmpty()">{{ ::'MEDICATION_REFILL_ALL' | translate }}</button>
<button ng-repeat="orderAttribute in getOrderAttributes()" class="secondary-button dispense-all-btn fr" show-if-privilege="{{dispensePrivilege}}" ng-if="!drugOrderGroupsEmpty()" ng-click="updateAllOrderAttributesByName(orderAttribute,drugOrderGroup)" ng-disabled="!canUpdateAtLeastOneOrderAttributeOfName(drugOrderGroup,orderAttribute.name)">
<i ng-init="allOrderAttributesOfNameSet(drugOrderGroup,orderAttribute.name)" class="fa fa-check" ng-show="drugOrderGroup[orderAttribute.name].selected" ></i>
Expand Down Expand Up @@ -56,7 +56,7 @@
<button class="refill-btn" ng-disabled="!drugOrder.effectiveStopDate || drugOrder.isDrugRetired" ng-click="refill(drugOrder)">
{{ ::'MEDICATION_REFILL' | translate }}
</button>
<input ng-show="enablePrintSelectedDrugs" type="checkbox" id="{{$parent.$index + '/' + drugOrder.uuid}}" name="selectedDrug"
<input ng-show="printPrescriptionFeature" type="checkbox" id="{{$parent.$index + '/' + drugOrder.uuid}}" name="selectedDrug"
ng-model="selectedDrugs[$parent.$index + '/' + drugOrder.uuid]"/>
</div>
</div>
Expand Down

0 comments on commit d01c2e7

Please sign in to comment.