From f479b9abf416fce01f2dfb8ae2ac48789bcb28b4 Mon Sep 17 00:00:00 2001 From: kavitha-sundararajan <90255023+kavitha-sundararajan@users.noreply.github.com> Date: Fri, 4 Aug 2023 14:06:40 +0530 Subject: [PATCH] Kavitha | BAH-3140 | add print selected medication feature (#659) * BAH-3140 | add print selected medication feature * BAH-3140 | fix anonymous function error --- .../common/services/treatmentService.js | 38 +++++++++++++- .../controllers/drugOrderHistoryController.js | 50 ++++++++++++++++++- .../treatmentSections/drugOrderHistory.html | 5 ++ ui/app/common/constants.js | 1 + .../common/domain/services/providerService.js | 14 +++++- .../common/patient/mappers/patientMapper.js | 5 +- ui/app/common/ui-helper/printer.js | 6 ++- ui/app/i18n/clinical/locale_en.json | 1 + .../styles/clinical/treatment/_treatment.scss | 12 +++-- 9 files changed, 121 insertions(+), 11 deletions(-) diff --git a/ui/app/clinical/common/services/treatmentService.js b/ui/app/clinical/common/services/treatmentService.js index bc836e311e..dc867bc140 100644 --- a/ui/app/clinical/common/services/treatmentService.js +++ b/ui/app/clinical/common/services/treatmentService.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('bahmni.clinical') - .factory('treatmentService', ['$http', '$q', '$compile', '$timeout', 'spinner', 'appService', '$rootScope', 'transmissionService', '$filter', function ($http, $q, $compile, $timeout, spinner, appService, $rootScope, transmissionService, $filter) { + .factory('treatmentService', ['$http', '$q', '$compile', '$timeout', 'spinner', 'appService', '$rootScope', 'transmissionService', '$filter', 'printer', function ($http, $q, $compile, $timeout, spinner, appService, $rootScope, transmissionService, $filter, printer) { var createDrugOrder = function (drugOrder) { return Bahmni.Clinical.DrugOrder.create(drugOrder); }; @@ -167,6 +167,38 @@ 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); + }); + filteredProviderAttributes.sort(function (a, b) { + return providerAttributeTypesToFilter.indexOf(a.attributeType.display) - providerAttributeTypesToFilter.indexOf(b.attributeType.display); + }); + return filteredProviderAttributes; + }; + + var printSelectedPrescriptions = function (drugOrdersForPrint, patient, additionalInfo) { + if (drugOrdersForPrint.length > 0) { + var encounterDrugOrderMap = Object.values(drugOrdersForPrint.reduce(function (orderMap, item) { + const providerUuid = item.provider.uuid; + if (!orderMap[providerUuid]) { + orderMap[providerUuid] = { + providerUuid: providerUuid, + drugOrders: [] + }; + } + orderMap[providerUuid].drugOrders.push(item); + return orderMap; + }, {})); + + 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); + } + }; + return { getActiveDrugOrders: getActiveDrugOrders, getConfig: getConfig, @@ -175,6 +207,8 @@ angular.module('bahmni.clinical') getNonCodedDrugConcept: getNonCodedDrugConcept, getAllDrugOrdersFor: getAllDrugOrdersFor, voidDrugOrder: voidDrugOrder, - sharePrescriptions: sharePrescriptions + sharePrescriptions: sharePrescriptions, + printSelectedPrescriptions: printSelectedPrescriptions, + getOrderedProviderAttributesForPrint: getOrderedProviderAttributesForPrint }; }]); diff --git a/ui/app/clinical/consultation/controllers/drugOrderHistoryController.js b/ui/app/clinical/consultation/controllers/drugOrderHistoryController.js index 8762d65de8..689c01619a 100644 --- a/ui/app/clinical/consultation/controllers/drugOrderHistoryController.js +++ b/ui/app/clinical/consultation/controllers/drugOrderHistoryController.js @@ -2,9 +2,9 @@ angular.module('bahmni.clinical') .controller('DrugOrderHistoryController', ['$scope', '$filter', '$stateParams', 'activeDrugOrders', 'appService', - 'treatmentConfig', 'treatmentService', 'spinner', 'drugOrderHistoryHelper', 'visitHistory', '$translate', '$rootScope', + 'treatmentConfig', 'treatmentService', 'spinner', 'drugOrderHistoryHelper', 'visitHistory', '$translate', '$rootScope', 'providerService', function ($scope, $filter, $stateParams, activeDrugOrders, appService, treatmentConfig, treatmentService, spinner, - drugOrderHistoryHelper, visitHistory, $translate, $rootScope) { + drugOrderHistoryHelper, visitHistory, $translate, $rootScope, providerService) { var DrugOrderViewModel = Bahmni.Clinical.DrugOrderViewModel; var DateUtil = Bahmni.Common.Util.DateUtil; var currentVisit = visitHistory.activeVisit; @@ -13,6 +13,8 @@ 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.selectedDrugs = {}; if ($scope.enableIPDFeature) { $scope.toggleCareSetting = function (drugOrder) { @@ -64,6 +66,50 @@ angular.module('bahmni.clinical') } }; + $scope.isAnyDrugSelected = function () { + return Object.values($scope.selectedDrugs).some(function (selected) { + return selected === true; + }); + }; + + $scope.printSelectedDrugs = function () { + var drugOrdersForPrint = []; + var promises = []; + + angular.forEach($scope.selectedDrugs, function (selected, drugOrderIndex) { + var selectedDrugOrder = drugOrderIndex.split("/"); + if (selected) { + var drugOrder = $scope.consultation.drugOrderGroups[selectedDrugOrder[0]].drugOrders.find(function (drugOrder) { + return drugOrder.uuid == selectedDrugOrder[1]; + }); + if (drugOrder) { + drugOrder.provider.attributes = {}; + var promise = providerService.getAttributesForProvider(drugOrder.provider.uuid); + promises.push(promise); + + promise.then(function (response) { + drugOrder.provider.attributes = treatmentService.getOrderedProviderAttributesForPrint(response.data.results); + }).catch(function (error) { + console.error("Error fetching provider attributes: ", error); + }); + + drugOrdersForPrint.push(drugOrder); + } + } + }); + + Promise.all(promises).then(function () { + var additionalInfo = {}; + additionalInfo.visitType = currentVisit.visitType.display; + additionalInfo.currentDate = new Date(); + additionalInfo.facilityLocation = $rootScope.facilityLocation; + treatmentService.printSelectedPrescriptions(drugOrdersForPrint, $scope.patient, additionalInfo); + $scope.selectedDrugs = {}; + }).catch(function (error) { + console.error("Error fetching details for print: ", error); + }); + }; + var createPrescribedDrugOrderGroups = function () { if (prescribedDrugOrders.length === 0) { return []; diff --git a/ui/app/clinical/consultation/views/treatmentSections/drugOrderHistory.html b/ui/app/clinical/consultation/views/treatmentSections/drugOrderHistory.html index 17600f085c..8bccebff0b 100644 --- a/ui/app/clinical/consultation/views/treatmentSections/drugOrderHistory.html +++ b/ui/app/clinical/consultation/views/treatmentSections/drugOrderHistory.html @@ -10,6 +10,7 @@ {{drugOrderGroup.label | bahmniDate}} + +
@@ -105,6 +109,7 @@
+ diff --git a/ui/app/common/constants.js b/ui/app/common/constants.js index 9fee2e0da5..d79aa3ee33 100644 --- a/ui/app/common/constants.js +++ b/ui/app/common/constants.js @@ -218,6 +218,7 @@ Bahmni.Common = Bahmni.Common || {}; ordersUrl: RESTWS_V1 + "/order", formDataUrl: RESTWS_V1 + "/obs", providerUrl: RESTWS_V1 + "/provider", + providerAttributeUrl: RESTWS_V1 + "/provider/{{providerUuid}}/attribute", drugUrl: RESTWS_V1 + "/drug", orderTypeUrl: RESTWS_V1 + "/ordertype", userUrl: RESTWS_V1 + "/user", diff --git a/ui/app/common/domain/services/providerService.js b/ui/app/common/domain/services/providerService.js index d1fd1875a1..526a48487e 100644 --- a/ui/app/common/domain/services/providerService.js +++ b/ui/app/common/domain/services/providerService.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('bahmni.common.domain') - .factory('providerService', ['$http', function ($http) { + .factory('providerService', ['$http', 'appService', function ($http, appService) { var search = function (fieldValue) { return $http.get(Bahmni.Common.Constants.providerUrl, { method: "GET", @@ -28,9 +28,19 @@ angular.module('bahmni.common.domain') }); }; + var getAttributesForProvider = function (providerUuid) { + var providerAttributeUrl = appService.getAppDescriptor().formatUrl(Bahmni.Common.Constants.providerAttributeUrl, {'providerUuid': providerUuid}); + return $http.get(providerAttributeUrl, { + method: "GET", + withCredentials: true, + cache: false + }); + }; + return { search: search, searchByUuid: searchByUuid, - list: list + list: list, + getAttributesForProvider: getAttributesForProvider }; }]); diff --git a/ui/app/common/patient/mappers/patientMapper.js b/ui/app/common/patient/mappers/patientMapper.js index b9f3fb229c..6d2e5206a0 100644 --- a/ui/app/common/patient/mappers/patientMapper.js +++ b/ui/app/common/patient/mappers/patientMapper.js @@ -81,10 +81,13 @@ Bahmni.PatientMapper = function (patientConfig, $rootScope, $translate) { "address1": preferredAddress.address1, "address2": preferredAddress.address2, "address3": preferredAddress.address3, + "address4": preferredAddress.address4, + "address5": preferredAddress.address5, "cityVillage": preferredAddress.cityVillage, "countyDistrict": preferredAddress.countyDistrict === null ? '' : preferredAddress.countyDistrict, "stateProvince": preferredAddress.stateProvince, - "postalCode": preferredAddress.postalCode ? preferredAddress.postalCode : "" + "postalCode": preferredAddress.postalCode ? preferredAddress.postalCode : "", + "country": preferredAddress.country ? preferredAddress.country : "" } : {}; }; diff --git a/ui/app/common/ui-helper/printer.js b/ui/app/common/ui-helper/printer.js index 10177822e5..54e045cbd8 100644 --- a/ui/app/common/ui-helper/printer.js +++ b/ui/app/common/ui-helper/printer.js @@ -30,7 +30,8 @@ angular.module('bahmni.common.uiHelper') }, false); }; - var print = function (templateUrl, data) { + var print = function (templateUrl, data, pageTitle) { + pageTitle = pageTitle || null; $rootScope.isBeingPrinted = true; $http.get(templateUrl).then(function (templateData) { var template = templateData.data; @@ -38,6 +39,8 @@ angular.module('bahmni.common.uiHelper') angular.extend(printScope, data); var element = $compile($('
' + template + '
'))(printScope); var renderAndPrintPromise = $q.defer(); + var originalTitle = angular.element(document).prop('title'); + pageTitle ? angular.element(document).prop('title', pageTitle) : angular.element(document).prop('title', originalTitle); var waitForRenderAndPrint = function () { if (printScope.$$phase || $http.pendingRequests.length) { $timeout(waitForRenderAndPrint, 1000); @@ -46,6 +49,7 @@ angular.module('bahmni.common.uiHelper') printHtml(element.html()).then(function () { $rootScope.isBeingPrinted = false; renderAndPrintPromise.resolve(); + angular.element(document).prop('title', originalTitle); }); printScope.$destroy(); } diff --git a/ui/app/i18n/clinical/locale_en.json b/ui/app/i18n/clinical/locale_en.json index c948204895..27e71c3ee9 100644 --- a/ui/app/i18n/clinical/locale_en.json +++ b/ui/app/i18n/clinical/locale_en.json @@ -157,6 +157,7 @@ "MEDICATION_CLEAR": "Clear", "MEDICATION_ADD_ACCESS_KEY": "a", "MEDICATION_REFILL_ALL": "Refill All", + "MEDICATION_PRINT": "Print", "MEDICATION_NO_RECENT_TREATMENT": "No Recent Treatments", "MEDICATION_STOP": "Stop", "MEDICATION_REFILL": "Refill", diff --git a/ui/app/styles/clinical/treatment/_treatment.scss b/ui/app/styles/clinical/treatment/_treatment.scss index 94e0eca09a..e83484d791 100644 --- a/ui/app/styles/clinical/treatment/_treatment.scss +++ b/ui/app/styles/clinical/treatment/_treatment.scss @@ -131,7 +131,7 @@ @media screen and (min-width:769px) { float: right; - width: 215px; + width: 255px; } button.toggle.has-notes { @@ -283,7 +283,8 @@ } .refill-drugs-btn, - .dispense-all-btn { + .dispense-all-btn, + .print-drugs-btn { font-size: 14px; margin-right: 0; display: none; @@ -302,6 +303,10 @@ margin-right: 5px; } + .print-drugs-btn { + margin-left: 5px; + } + .bulk-edit-options-container { padding: 10px 10px 10px 10px; background-color: $lightestGray; @@ -339,7 +344,8 @@ } .tabs .tab [type=radio]:checked~.dispense-all-btn, - .tabs .tab [type=radio]:checked~.refill-drugs-btn { + .tabs .tab [type=radio]:checked~.refill-drugs-btn, + .tabs .tab [type=radio]:checked~.print-drugs-btn { display: inline-block; line-height: 14px; }