Skip to content

Commit

Permalink
Kavitha | BAH-3244 | adds printing based on custom templates and conf…
Browse files Browse the repository at this point in the history
…igs (#930)

* Kavitha | BAH-3244 | adds printing based on custom templates and configs

* add check for non coded diagnosis

---------

Co-authored-by: Kavitha S <kavitha.s@thoughtworks.com>
  • Loading branch information
binduak and kavitha-sundararajan committed May 17, 2024
1 parent bd36c65 commit 6a49e18
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 6 deletions.
51 changes: 50 additions & 1 deletion ui/app/clinical/common/controllers/visitController.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,56 @@ angular.module('bahmni.clinical')
};

$scope.$on("event:printVisitTab", function () {
printer.printFromScope("common/views/visitTabPrint.html", $scope);
var printConfig = $scope.visitTabConfig.currentTab.printing;
var templateUrl = printConfig.templateUrl;
if (templateUrl) {
var promises = [];
$scope.diagnosesCodes = "";
$scope.observationsEntries = [];

if (printConfig.observationsConcepts !== undefined) {
var promise = $q.all([diagnosisService.getPatientDiagnosis($stateParams.patientUuid), observationsService.fetch($stateParams.patientUuid, printConfig.observationsConcepts, "latest", null, null, null, null, null)]).then(function (response) {
const diagnoses = response[0].data;
$scope.observationsEntries = response[1].data;
angular.forEach(diagnoses, function (diagnosis) {
if (diagnosis.order === printConfig.printDiagnosis.order &&
diagnosis.certainty === printConfig.printDiagnosis.certainity) {
if ($scope.diagnosesCodes.length > 0) {
$scope.diagnosesCodes += ", ";
}
if (diagnosis.codedAnswer !== null && diagnosis.codedAnswer.mappings.length !== 0) {
$scope.diagnosesCodes += diagnosis.codedAnswer.mappings[0].code + " - " + diagnosis.codedAnswer.name;
}
else if (diagnosis.codedAnswer !== null && diagnosis.codedAnswer.mappings.length == 0) {
$scope.diagnosesCodes += diagnosis.codedAnswer.name;
}
else if (diagnosis.codedAnswer == null && diagnosis.freeTextAnswer !== null) {
$scope.diagnosesCodes += diagnosis.freeTextAnswer;
}
}
});
});
promises.push(promise);
}

Promise.all(promises).then(function () {
$scope.additionalInfo = {};
$scope.additionalInfo.visitSummary = $scope.visitSummary;
$scope.additionalInfo.currentDate = new Date();
$scope.additionalInfo.facilityLocation = $rootScope.facilityLocation;
var tabName = printConfig.header.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, function (match, chr) {
return chr.toUpperCase();
}).replace(/^[a-z]/, function (match) {
return match.toUpperCase();
});
$scope.pageTitle = $scope.patient.givenName + $scope.patient.familyName + "_" + $scope.patient.identifier + "_" + tabName;
printer.printFromScope(templateUrl, $scope);
}).catch(function (error) {
console.error("Error fetching details for print: ", error);
});
} else {
printer.printFromScope("common/views/visitTabPrint.html", $scope);
}
});

$scope.$on("event:clearVisitBoard", function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ angular.module('bahmni.common.displaycontrol.admissiondetails')
return {
restrict: 'E',
controller: controller,
templateUrl: "../common/displaycontrols/admissiondetails/views/admissionDetails.html",
templateUrl: function (element, attrs) {
if (attrs.templateUrl) {
return attrs.templateUrl;
} else {
return "../common/displaycontrols/admissiondetails/views/admissionDetails.html";
}
},
scope: {
params: "=",
patientUuid: "=",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ angular.module('bahmni.common.displaycontrol.diagnosis')
restrict: 'E',
controller: controller,
link: link,
templateUrl: "../common/displaycontrols/diagnosis/views/diagnosisDisplayControl.html",
templateUrl: function (element, attrs) {
if (attrs.templateUrl) {
return attrs.templateUrl;
} else {
return "../common/displaycontrols/diagnosis/views/diagnosisDisplayControl.html";
}
},
scope: {
patientUuid: "=",
config: "=",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ angular.module('bahmni.common.displaycontrol.observation')
return _.toLower(conceptName) === _.toLower(_.get(observation, comparableAttr));
});
});
if ($scope.config.customSortNeeded && $scope.config.conceptNames) {
observations.sort(function (a, b) {
const indexOfA = $scope.config.conceptNames.indexOf(a.concept.name);
const indexOfB = $scope.config.conceptNames.indexOf(b.concept.name);
return indexOfA - indexOfB;
});
}
}

if ($scope.config.persistOrderOfConcepts) {
Expand Down Expand Up @@ -132,7 +139,13 @@ angular.module('bahmni.common.displaycontrol.observation')
restrict: 'E',
controller: controller,
link: link,
templateUrl: "../common/displaycontrols/observation/views/observationDisplayControl.html",
templateUrl: function (element, attrs) {
if (attrs.templateUrl) {
return attrs.templateUrl;
} else {
return "../common/displaycontrols/observation/views/observationDisplayControl.html";
}
},
scope: {
patient: "=",
visitUuid: "@",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ angular.module('bahmni.common.displaycontrol.prescription')
return {
restrict: 'EA',
controller: controller,
templateUrl: "../common/displaycontrols/prescription/views/prescription.html",
templateUrl: function (element, attrs) {
if (attrs.templateUrl) {
return attrs.templateUrl;
} else {
return "../common/displaycontrols/prescription/views/prescription.html";
}
},
scope: {
patient: "=",
visitDate: "=",
Expand Down
8 changes: 7 additions & 1 deletion ui/app/common/obs/directives/showObservation.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ angular.module('bahmni.common.obs')
displayNameType: "=?"
},
controller: controller,
template: '<ng-include src="\'../common/obs/views/showObservation.html\'" />'
template: function (element, attrs) {
if (attrs.templateURL) {
return '<ng-include src="' + attrs.templateURL + '" />';
} else {
return '<ng-include src="\'../common/obs/views/showObservation.html\'" />';
}
}
};
}]);
3 changes: 3 additions & 0 deletions ui/app/common/ui-helper/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ angular.module('bahmni.common.uiHelper')
var printScope = scope;
var element = $compile($('<div>' + template + '</div>'))(printScope);
var renderAndPrintPromise = $q.defer();
var originalTitle = angular.element(document).prop('title');
printScope.pageTitle ? angular.element(document).prop('title', printScope.pageTitle) : angular.element(document).prop('title', originalTitle);
var waitForRenderAndPrint = function () {
if (printScope.$$phase || $http.pendingRequests.length) {
$timeout(waitForRenderAndPrint);
Expand All @@ -72,6 +74,7 @@ angular.module('bahmni.common.uiHelper')
afterPrint();
}
renderAndPrintPromise.resolve();
angular.element(document).prop('title', originalTitle);
});
}
return renderAndPrintPromise.promise;
Expand Down

0 comments on commit 6a49e18

Please sign in to comment.