Skip to content

Commit

Permalink
BAH-3334 | Ability to print forms
Browse files Browse the repository at this point in the history
* Kavitha | BAH-3334 | add print feature for forms display control (#783)

* Kavitha | BAH-3334 | import formPrintService script for all modules

* Kavitha | BAH-3334 | fix showing other forms data if there is no data

* Kavitha | BAH-3334 | fix failed test cases

* Kavitha | BAH-2333 | add expects in formPrintService tests

* add check for non coded diagnosis and tests

* Kavitha | fix edit form not showing data (#786)

* Kavitha | BAH-3334 | add form name null check for print (#785)

* Kavitha | BAH-3334 | add name null check for print print

* Kavitha | BAH-3334 | refactored iteration on obs

* resolve merge conflicts

* Parvathy | BAH-3334 | Refactor. Remove Duplicate Code

* Parvathy | BAH-3334 | Fix. Print Functionality of Old Forms2 Forms

---------

Co-authored-by: parvathy00 <[email protected]>
  • Loading branch information
kavitha-sundararajan and parvathy00 authored Jun 12, 2024
1 parent a91ff7e commit 490311f
Show file tree
Hide file tree
Showing 22 changed files with 637 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import "./viewObservationForm.scss";

export const ViewObservationForm = (props) => {
const { formName, formNameTranslations, closeViewObservationForm, formData, isViewFormLoading} =
const { formName, formNameTranslations, closeViewObservationForm, formData, isViewFormLoading, showPrintOption, printForm } =
props;

return (
Expand All @@ -23,6 +23,7 @@ export const ViewObservationForm = (props) => {
className="view-observation-form-modal"
onRequestClose={closeViewObservationForm}
>
{showPrintOption && <button className="confirm print-button" onClick={printForm}>Print</button> }
<section className="content-body">
<h2 className="section-title">{formNameTranslations}</h2>
{isViewFormLoading ? (
Expand Down Expand Up @@ -97,5 +98,7 @@ ViewObservationForm.propTypes = {
closeViewObservationForm: propTypes.func,
formData: propTypes.array,
isViewFormLoading: propTypes.bool,
showPrintOption: propTypes.bool,
printForm: propTypes.func
};
export default ViewObservationForm;
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
width: 80%;
height: 84%;
max-width: 1180px;
top: 96px;
}

.bx--modal-content {
Expand Down Expand Up @@ -123,4 +124,17 @@
.is-abnormal {
color: red;
}

@media (min-width: 42rem) {
.bx--modal-container {
position: fixed;
}
}

.print-button {
position: fixed;
z-index: 500;
right: 30px;
top: 40px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ export function FormDisplayControl(props) {
setEditObservationForm(false);
}

const printForm = () => {
formData.map(function(obs) {
if (obs?.groupMembers?.length > 0) {
obs.encounterDateTime = obs?.groupMembers[0].encounterDateTime;
}
})
props?.hostApi?.printForm(formData);
}

useEffect(() => {
buildResponseData();
}, []);
Expand Down Expand Up @@ -258,6 +267,8 @@ export function FormDisplayControl(props) {
formNameTranslations={formNameTranslations}
closeViewObservationForm={closeViewObservationForm}
formData={formData}
showPrintOption={props?.hostData?.showPrintOption}
printForm={printForm}
/>
) : null}
{showEditObservationForm ? (
Expand Down
2 changes: 2 additions & 0 deletions ui/app/adt/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@
<script src="../common/displaycontrols/observation/helpers/groupingFunctions.js"></script>
<script src="../common/displaycontrols/observation/services/formHierarchyBuildService.js"></script>
<script src="../common/services/formService.js"></script>
<script src="../common/services/formPrintService.js"></script>
<script src="../common/services/allergyService.js"></script>


<script src="../common/displaycontrols/disposition/init.js"></script>
Expand Down
2 changes: 2 additions & 0 deletions ui/app/bedmanagement/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@
<script src="../common/i18n/services/mergeLocaleFilesService.js"></script>
<script src="../common/ui-helper/directives/singleClick.js"></script>
<script src="../common/services/formService.js"></script>
<script src="../common/services/formPrintService.js"></script>
<script src="../common/services/allergyService.js"></script>
<script src="../common/logging/services/auditLogService.js"></script>
<script src="../clinical/consultation/mappers/consultationMapper.js"></script>

Expand Down
53 changes: 53 additions & 0 deletions ui/app/clinical/common/views/formPrint.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<link rel="stylesheet" href="../styles/clinicalPrint.css" media="print"/>
<div class="print-wrapper">
<div class="print-logo-plus-text">
<img class="print-logo" width="125px" ng-if="printConfig.logo" ng-src="{{printConfig.logo}}" alt="logo"/>
<h1 class="print-logo-text">{{printConfig.title}}</h1>
<div class="print-right"></div>
</div>
<div class="clinic-info">
<span> {{printConfig.header}}</span>
</div>
<ng-include src="patientInfoPrint.html"></ng-include>
<div class="sections-group">
<div class="section">
<section class="block observation dashboard-section" id="observationSection">
<ul bm-gallery access-impression="true">
<section class="block " ng-class="::{'hidden-print': noObsMessage}">
<h2 class="tableMargin"
ng-class="::{'section-title': !isFulfilmentDisplayControl, 'form-field': isFulfilmentDisplayControl}">{{::title |
translate}}</h2>
<div class="concept-set-container-view">
<section class="block hierarchy">
<ul class="form-field" ng-if="bahmniObservations.length > 0">
<li class="tableMargin" ng-repeat="obsGroup in ::bahmniObservations">
<span class="tree-list-item row-click toggle-container" toggle="obsGroup.isOpen">
<span class="obs-date" ng-if="obsGroup.value.length > 0">
{{::obsGroup.date | bahmniDateTime}}
</span>
</span>
<ul class="print-observations visible-print">
<li class="tableBorder" ng-repeat="observation in ::obsGroup.value track by $index">
<ul>
<show-observation show-details-button="::config.showDetailsButton" patient="::patient"
observation="::observation"
level="2">
</show-observation>
</ul>
</li>
</ul>
</li>
</ul>
<div ng-if="::noObsMessage">
<div class="placeholder-text" ng-if="::!message"><p translate="DISPLAY_CONTROL_ERROR_MESSAGE_KEY"
translate-values="::{displayControl : '{{title | translate}}'}"></p>
</div>
<div class="placeholder-text" ng-if="::message">{{::message|translate}}</div>
</div>
</section>
</div>
</section>
</ul>
</section>
</div>
</div>
2 changes: 2 additions & 0 deletions ui/app/clinical/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ <h3 class="close" ng-click="closeTeleConsultation()">
<script src="../common/services/allergyService.js"></script>
<script src="common/services/treatmentService.js"></script>
<script src="common/models/auditLogEventDetails.js"></script>
<script src="../common/services/formPrintService.js"></script>
<script src="../common/services/allergyService.js"></script>

<!-- endbuild -->

Expand Down
28 changes: 24 additions & 4 deletions ui/app/common/displaycontrols/dashboard/directives/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
'use strict';

angular.module('bahmni.common.displaycontrol.dashboard')
.directive('dashboard', ['appService', '$stateParams', '$bahmniCookieStore', 'configurations', 'encounterService', 'spinner', 'auditLogService', 'messagingService', '$state', '$translate', function (appService, $stateParams, $bahmniCookieStore, configurations, encounterService, spinner, auditLogService, messagingService, $state, $translate) {
.directive('dashboard', ['appService', '$stateParams', '$bahmniCookieStore', 'configurations', 'encounterService', 'spinner', 'auditLogService', 'messagingService', '$state', '$translate', 'formPrintService', function (appService, $stateParams, $bahmniCookieStore, configurations, encounterService, spinner, auditLogService, messagingService, $state, $translate, formPrintService) {
var controller = function ($scope, $filter, $rootScope) {
var init = function () {
$scope.dashboard = Bahmni.Common.DisplayControl.Dashboard.create($scope.config || {}, $filter);
};
$scope.tabConfigName = $stateParams.tabConfigName || 'default';

if ($scope.patient !== undefined) {
var dashboardConfig = $scope.config.sections['forms-v2-react'] ? $scope.config.sections['forms-v2-react'].dashboardConfig : null;
$scope.formData = {
patientUuid: $scope.patient.uuid,
patient: $scope.patient,
encounterUuid: $scope.activeEncounterUuid,
showEditForActiveEncounter: $scope.config.sections['forms-v2-react'] && $scope.config.sections['forms-v2-react'].dashboardConfig && $scope.config.sections['forms-v2-react'].dashboardConfig.showEditForActiveEncounter || false,
numberOfVisits: $scope.config.sections['forms-v2-react'] && $scope.config.sections['forms-v2-react'].dashboardConfig && $scope.config.sections['forms-v2-react'].dashboardConfig.maximumNoOfVisits || undefined,
showEditForActiveEncounter: dashboardConfig && dashboardConfig.showEditForActiveEncounter || false,
numberOfVisits: dashboardConfig && dashboardConfig.maximumNoOfVisits || undefined,
hasNoHierarchy: $scope.hasNoHierarchy,
currentUser: $rootScope.currentUser,
consultationMapper: new Bahmni.ConsultationMapper(configurations.dosageFrequencyConfig(), configurations.dosageInstructionConfig(),
configurations.consultationNoteConcept(), configurations.labOrderNotesConcept()),
editErrorMessage: $translate.instant('CLINICAL_FORM_ERRORS_MESSAGE_KEY')
editErrorMessage: $translate.instant('CLINICAL_FORM_ERRORS_MESSAGE_KEY'),
showPrintOption: (dashboardConfig && dashboardConfig.printing) ? true : false
};
$scope.formApi = {
handleEditSave: function (encounter) {
Expand All @@ -33,6 +35,24 @@ angular.module('bahmni.common.displaycontrol.dashboard')
$state.go($state.current, {}, {reload: true});
messagingService.showMessage('info', "{{'CLINICAL_SAVE_SUCCESS_MESSAGE_KEY' | translate}}");
}));
},
printForm: function (observations) {
var printData = {};
var mappedObservations = new Bahmni.Common.Obs.ObservationMapper().map(observations, {}, null, $translate);
printData.bahmniObservations = new Bahmni.Common.DisplayControl.Observation.GroupingFunctions().groupByEncounterDate(mappedObservations);
observations.forEach(function (obs) {
if (obs.formFieldPath) {
printData.title = obs.formFieldPath.split(".")[0];
return;
} else if (obs.groupMembers.length > 0 && obs.groupMembers[0].formFieldPath) {
printData.title = obs.groupMembers[0].formFieldPath.split(".")[0];
return;
}
});
printData.patient = $scope.patient;
printData.printConfig = dashboardConfig ? dashboardConfig.printing : {};
printData.printConfig.header = printData.title;
formPrintService.printForm(printData, observations[0].encounterUuid, $rootScope.facilityLocation);
}
};
$scope.allergyData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ angular.module('bahmni.common.displaycontrol.forms')

var init = function () {
$scope.formsNotFound = false;
var privileges = [];
return $q.all([formService.getAllPatientForms($scope.patient.uuid, $scope.section.dashboardConfig.maximumNoOfVisits, $state.params.enrollment), latestPublishedForms()]).then(function (results) {
if (!(results[0] && results[0].data.length)) {
$scope.formsNotFound = true;
Expand Down Expand Up @@ -146,10 +145,16 @@ angular.module('bahmni.common.displaycontrol.forms')
observationUuid: data.uuid,
formType: $scope.section.type,
formDisplayName: $scope.getDisplayName(data)
}
},
showPrintOption: $scope.section.dashboardConfig.printing ? true : false,
printForm: $scope.printForm
};
};

$scope.printForm = function () {
$rootScope.$broadcast("event:printForm", $scope.section.dashboardConfig);
};

$scope.getEditObsData = function (observation) {
return {
observation: observation,
Expand Down
8 changes: 7 additions & 1 deletion ui/app/common/displaycontrols/forms/directives/formsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,20 @@ angular.module('bahmni.common.displaycontrol.forms')
},
section: {
title: data.concept.displayString
}
},
showPrintOption: $scope.section.dashboardConfig.printing ? true : false,
printForm: $scope.printForm
};
};

$scope.dialogData = {
"patient": $scope.patient,
"section": $scope.section
};

$scope.printForm = function () {
$rootScope.$broadcast("event:printForm", $scope.section.dashboardConfig);
};
};

var link = function ($scope, element) {
Expand Down
7 changes: 4 additions & 3 deletions ui/app/common/displaycontrols/forms/views/formsTable.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
<span ng-hide="::showFormsDate">{{data.obsDatetime || data.encounterDateTime | bahmniDateTime}}</span>
<span ng-show="::showFormsDate">{{
data.obsDatetime || data.encounterDateTime | bahmniDate}}</span>
<span ng-show="doesUserHaveAccessToTheForm(data ,'view')"class="has-link fl formDataEdit"
<span ng-show="doesUserHaveAccessToTheForm(data, 'view')" class="has-link fl formDataEdit"
ng-dialog="../common/displaycontrols/forms/views/showObservationFormData.html"
ng-dialog-class="ngdialog-theme-default ng-dialog-all-details-page ng-dialog-view"
ng-dialog-data="{{getConfigToFetchDataAndShow(data)}}">
ng-dialog-data="{{getConfigToFetchDataAndShow(data)}}"
ng-dialog-scope="this">
<i class="fa fa-eye"></i>
</span>
<span ng-show="doesUserHaveAccessToTheForm(data ,'edit')"class="has-link fl formDataEdit"
<span ng-show="doesUserHaveAccessToTheForm(data, 'edit')" class="has-link fl formDataEdit"
ng-dialog="dashboard/views/dashboardSections/editObservationForm.html"
ng-dialog-class="ngdialog-theme-default ng-dialog-all-details-page ng-dialog-edit"
ng-dialog-data="{{getEditObsData(data)}}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="template-container">
<section class="block dashboard-section">
<button class="confirm form-print-button" ng-if="ngDialogData.showPrintOption" ng-click="printForm()">Print</button>
<bahmni-observation patient="ngDialogData.patient" config="ngDialogData.config" is-on-dashboard="false" section-title="ngDialogData.section.title"></bahmni-observation>
</section>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

angular.module('bahmni.common.displaycontrol.observation')
.directive('bahmniObservation', ['encounterService', 'observationsService', 'appService', '$q', 'spinner', '$rootScope',
'formRecordTreeBuildService', '$translate', 'providerInfoService', 'conceptGroupFormatService',
'formRecordTreeBuildService', '$translate', 'providerInfoService', 'conceptGroupFormatService', 'formPrintService',
function (encounterService, observationsService, appService, $q, spinner, $rootScope,
formRecordTreeBuildService, $translate, providerInfoService, conceptGroupFormatService) {
formRecordTreeBuildService, $translate, providerInfoService, conceptGroupFormatService, formPrintService) {
var controller = function ($scope) {
$scope.print = $rootScope.isBeingPrinted || false;

Expand Down Expand Up @@ -129,6 +129,20 @@ angular.module('bahmni.common.displaycontrol.observation')
"patient": $scope.patient,
"section": $scope.section
};

$scope.$on("event:printForm", function (event, dashboardConfig) {
var printData = {};
printData.bahmniObservations = $scope.bahmniObservations;
$scope.bahmniObservations.forEach(function (obs) {
printData.title = obs.value[0].concept.name;
});
printData.patient = $scope.patient;
printData.printConfig = dashboardConfig ? dashboardConfig.printing : {};
printData.printConfig.header = printData.title;
if ($scope.bahmniObservations && $scope.config.encounterUuid && $scope.patient) {
formPrintService.printForm(printData, $scope.config.encounterUuid, $rootScope.facilityLocation);
}
});
};

var link = function ($scope, element) {
Expand Down
Loading

0 comments on commit 490311f

Please sign in to comment.