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

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

Merged
merged 2 commits into from
May 17, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -67,7 +67,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