Skip to content

Commit

Permalink
Kavitha | BAH-3140 | add print selected medication feature (#659)
Browse files Browse the repository at this point in the history
* BAH-3140 | add print selected medication feature

* BAH-3140 | fix anonymous function error
  • Loading branch information
kavitha-sundararajan authored Aug 4, 2023
1 parent ef5639b commit f479b9a
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 11 deletions.
38 changes: 36 additions & 2 deletions ui/app/clinical/common/services/treatmentService.js
Original file line number Diff line number Diff line change
@@ -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);
};
Expand Down Expand Up @@ -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,
Expand All @@ -175,6 +207,8 @@ angular.module('bahmni.clinical')
getNonCodedDrugConcept: getNonCodedDrugConcept,
getAllDrugOrdersFor: getAllDrugOrdersFor,
voidDrugOrder: voidDrugOrder,
sharePrescriptions: sharePrescriptions
sharePrescriptions: sharePrescriptions,
printSelectedPrescriptions: printSelectedPrescriptions,
getOrderedProviderAttributesForPrint: getOrderedProviderAttributesForPrint
};
}]);
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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 [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +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" 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 All @@ -19,6 +20,7 @@
<div class="inpage-tab-content">
<p ng-if="!drugOrderGroup.drugOrders.length" class="placeholder-text">{{ ::'MEDICATION_NO_RECENT_TREATMENT' | translate }}</p>
<ul class="table-mimic">
<form id="prescribedDrugs" name="prescribedDrugs" ng-submit="printSelectedDrugs()">
<li id="ordered-drug-orders" ng-repeat="drugOrder in drugOrderGroup.drugOrders" ng-class="{'active-drug' : drugOrder.isActive(), 'highlight' : drugOrder.isBeingEdited, 'scheduled-drug': drugOrder.isScheduled()}">
<div class="drug-details" ng-class="{'strike-through': drugOrder.isDiscontinuedOrStopped()}">
<div class="drug-dosage">
Expand Down Expand Up @@ -54,6 +56,8 @@
<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"
ng-model="selectedDrugs[$parent.$index + '/' + drugOrder.uuid]"/>
</div>
</div>
<div class="start-date fr">
Expand Down Expand Up @@ -105,6 +109,7 @@
</div>
</div>
</li>
</form>
</ul>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions ui/app/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 12 additions & 2 deletions ui/app/common/domain/services/providerService.js
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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
};
}]);
5 changes: 4 additions & 1 deletion ui/app/common/patient/mappers/patientMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : ""
} : {};
};

Expand Down
6 changes: 5 additions & 1 deletion ui/app/common/ui-helper/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ 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;
var printScope = $rootScope.$new();
angular.extend(printScope, data);
var element = $compile($('<div>' + template + '</div>'))(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);
Expand All @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions ui/app/i18n/clinical/locale_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 9 additions & 3 deletions ui/app/styles/clinical/treatment/_treatment.scss
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@

@media screen and (min-width:769px) {
float: right;
width: 215px;
width: 255px;
}

button.toggle.has-notes {
Expand Down Expand Up @@ -283,7 +283,8 @@
}

.refill-drugs-btn,
.dispense-all-btn {
.dispense-all-btn,
.print-drugs-btn {
font-size: 14px;
margin-right: 0;
display: none;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f479b9a

Please sign in to comment.