From c8b312edf86318cc6b097067d5b2bc14ed1b5fb6 Mon Sep 17 00:00:00 2001 From: PawanTheGod Date: Fri, 27 Mar 2026 23:53:20 +0530 Subject: [PATCH] Add initial skeleton for Visit Summary report generation --- api/pom.xml | 6 ++ .../common/PatientDocumentsConstants.java | 6 ++ .../VisitSummaryDataSetDefinition.java | 32 +++++++ .../renderer/VisitSummaryPdfRenderer.java | 77 ++++++++++++++++ .../reports/VisitSummaryReportManager.java | 91 +++++++++++++++++++ api/src/main/resources/messages.properties | 2 + omod/pom.xml | 6 -- 7 files changed, 214 insertions(+), 6 deletions(-) create mode 100644 api/src/main/java/org/openmrs/module/patientdocuments/library/VisitSummaryDataSetDefinition.java create mode 100644 api/src/main/java/org/openmrs/module/patientdocuments/renderer/VisitSummaryPdfRenderer.java create mode 100644 api/src/main/java/org/openmrs/module/patientdocuments/reports/VisitSummaryReportManager.java diff --git a/api/pom.xml b/api/pom.xml index 14a78f7..42d6996 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -100,6 +100,12 @@ + + com.github.librepdf + openpdf + ${openpdfVersion} + + net.sf.barcode4j barcode4j-fop-ext diff --git a/api/src/main/java/org/openmrs/module/patientdocuments/common/PatientDocumentsConstants.java b/api/src/main/java/org/openmrs/module/patientdocuments/common/PatientDocumentsConstants.java index 2ad9878..da7299c 100644 --- a/api/src/main/java/org/openmrs/module/patientdocuments/common/PatientDocumentsConstants.java +++ b/api/src/main/java/org/openmrs/module/patientdocuments/common/PatientDocumentsConstants.java @@ -27,6 +27,12 @@ public class PatientDocumentsConstants { public static final String COMPONENT_REPORTMANAGER_PATIENT_ID_STICKER = MODULE_ARTIFACT_ID + "." + PATIENT_ID_STICKER_ID; + public static final String VISIT_SUMMARY_REPORT_ID = "visitSummary"; + + public static final String COMPONENT_REPORTMANAGER_VISIT_SUMMARY = MODULE_ARTIFACT_ID + "." + VISIT_SUMMARY_REPORT_ID; + + public static final String VISIT_SUMMARY_REPORT_UUID = "4fb1f692-7ead-4257-bbe1-97fac0295171"; + /** * The path to the style sheet for Patient History reports. */ diff --git a/api/src/main/java/org/openmrs/module/patientdocuments/library/VisitSummaryDataSetDefinition.java b/api/src/main/java/org/openmrs/module/patientdocuments/library/VisitSummaryDataSetDefinition.java new file mode 100644 index 0000000..9585770 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/patientdocuments/library/VisitSummaryDataSetDefinition.java @@ -0,0 +1,32 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.patientdocuments.library; + +import org.openmrs.module.reporting.common.Localized; +import org.openmrs.module.reporting.dataset.definition.BaseDataSetDefinition; +import org.openmrs.module.reporting.evaluation.parameter.Parameter; + +/** + * A dataset definition for the Visit Summary Report. + * This class serves as a placeholder for visit-related data such as vitals, diagnoses, and medications. + */ +@Localized("patientdocuments.visitSummaryDataSetDefinition") +public class VisitSummaryDataSetDefinition extends BaseDataSetDefinition { + + private static final long serialVersionUID = 1L; + + /** + * Default Constructor + */ + public VisitSummaryDataSetDefinition() { + super(); + addParameter(new Parameter("visitUuid", "Visit UUID", String.class)); + } +} diff --git a/api/src/main/java/org/openmrs/module/patientdocuments/renderer/VisitSummaryPdfRenderer.java b/api/src/main/java/org/openmrs/module/patientdocuments/renderer/VisitSummaryPdfRenderer.java new file mode 100644 index 0000000..cfef4ab --- /dev/null +++ b/api/src/main/java/org/openmrs/module/patientdocuments/renderer/VisitSummaryPdfRenderer.java @@ -0,0 +1,77 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.patientdocuments.renderer; + +import java.io.IOException; +import java.io.OutputStream; + +import org.openmrs.annotation.Handler; +import org.openmrs.module.reporting.common.Localized; +import org.openmrs.module.reporting.report.ReportData; +import org.openmrs.module.reporting.report.ReportRequest; +import org.openmrs.module.reporting.report.renderer.RenderingException; +import org.openmrs.module.reporting.report.renderer.ReportDesignRenderer; +import org.springframework.stereotype.Component; + +import com.lowagie.text.Document; +import com.lowagie.text.DocumentException; +import com.lowagie.text.Paragraph; +import com.lowagie.text.pdf.PdfWriter; + +/** + * ReportRenderer that renders the Visit Summary Report to a PDF format using OpenPDF. + * This skeleton generates a simple PDF and is designed to allow future section-based rendering. + */ +@Component +@Handler +@Localized("patientdocuments.visitSummaryPdfRenderer") +public class VisitSummaryPdfRenderer extends ReportDesignRenderer { + + @Override + public String getFilename(ReportRequest request) { + return getFilenameBase(request) + ".pdf"; + } + + @Override + public String getRenderedContentType(ReportRequest request) { + return "application/pdf"; + } + + @Override + public void render(ReportData results, String argument, OutputStream out) throws IOException, RenderingException { + + // Attempt to extract the visitUuid from parameters + String visitUuid = (String) results.getContext().getParameterValue("visitUuid"); + if (visitUuid == null) { + visitUuid = "N/A"; + } + + Document document = new Document(); + try { + PdfWriter.getInstance(document, out); + document.open(); + + // Initial skeleton output + document.add(new Paragraph("Visit Summary Report")); + document.add(new Paragraph("Visit UUID: " + visitUuid)); + + // TODO: Future logic for rendering sections (Vitals, Diagnoses, Medications, etc.) + // Section: Vitals + // Section: Diagnoses + // Section: Medications + // Section: Lab Results + + document.close(); + } + catch (DocumentException e) { + throw new RenderingException("Error generating Visit Summary PDF", e); + } + } +} diff --git a/api/src/main/java/org/openmrs/module/patientdocuments/reports/VisitSummaryReportManager.java b/api/src/main/java/org/openmrs/module/patientdocuments/reports/VisitSummaryReportManager.java new file mode 100644 index 0000000..f5285bf --- /dev/null +++ b/api/src/main/java/org/openmrs/module/patientdocuments/reports/VisitSummaryReportManager.java @@ -0,0 +1,91 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.patientdocuments.reports; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.openmrs.module.patientdocuments.common.PatientDocumentsConstants; +import org.openmrs.module.patientdocuments.library.VisitSummaryDataSetDefinition; +import org.openmrs.module.patientdocuments.renderer.VisitSummaryPdfRenderer; +import org.openmrs.module.reporting.evaluation.parameter.Parameter; +import org.openmrs.module.reporting.report.ReportDesign; +import org.openmrs.module.reporting.report.definition.ReportDefinition; +import org.openmrs.module.reporting.report.manager.BaseReportManager; +import org.springframework.stereotype.Component; + +/** + * Manager class for the Visit Summary Report. + * Defines the report structure, parameters, and links it to the appropriate dataset and renderer. + */ +@Component(PatientDocumentsConstants.COMPONENT_REPORTMANAGER_VISIT_SUMMARY) +public class VisitSummaryReportManager extends BaseReportManager { + + public static final String REPORT_DEFINITION_NAME = "Visit Summary Report"; + + public static final String DATASET_KEY_VISIT_SUMMARY = "visitSummaryFields"; + + @Override + public String getVersion() { + return "1.1.0-SNAPSHOT"; + } + + @Override + public String getUuid() { + return PatientDocumentsConstants.VISIT_SUMMARY_REPORT_UUID; + } + + @Override + public String getName() { + return REPORT_DEFINITION_NAME; + } + + @Override + public String getDescription() { + return "A report summarizing a patient visit, including vitals, diagnoses, and medications."; + } + + @Override + public List getParameters() { + List params = new ArrayList<>(); + params.add(new Parameter("visitUuid", "Visit UUID", String.class)); + return params; + } + + @Override + public ReportDefinition constructReportDefinition() { + ReportDefinition reportDef = new ReportDefinition(); + reportDef.setUuid(this.getUuid()); + reportDef.setName(this.getName()); + reportDef.setDescription(this.getDescription()); + reportDef.setParameters(this.getParameters()); + + // Link the VisitSummaryDataSetDefinition + VisitSummaryDataSetDefinition dsd = new VisitSummaryDataSetDefinition(); + Map parameterMappings = new HashMap<>(); + parameterMappings.put("visitUuid", "${visitUuid}"); + reportDef.addDataSetDefinition(DATASET_KEY_VISIT_SUMMARY, dsd, parameterMappings); + + return reportDef; + } + + @Override + public List constructReportDesigns(ReportDefinition reportDefinition) { + ReportDesign reportDesign = new ReportDesign(); + reportDesign.setName("Visit Summary PDF"); + reportDesign.setUuid("d3b07384-8f1d-4f1e-9e7c-87dcb46a5b98"); + reportDesign.setReportDefinition(reportDefinition); + reportDesign.setRendererType(VisitSummaryPdfRenderer.class); + return Arrays.asList(reportDesign); + } +} diff --git a/api/src/main/resources/messages.properties b/api/src/main/resources/messages.properties index 30b2fdc..d7f88ed 100644 --- a/api/src/main/resources/messages.properties +++ b/api/src/main/resources/messages.properties @@ -28,3 +28,5 @@ ${project.parent.artifactId}.patientIdSticker.fields.gender=Gender ${project.parent.artifactId}.patientIdSticker.fields.fulladdress=Address ${project.parent.artifactId}.patientIdStickerDataSetDefinition=Patient Identifier Sticker Data Set Definition ${project.parent.artifactId}.patientIdStickerXmlReportRenderer=Patient Identifier Sticker XML Report Renderer +${project.parent.artifactId}.visitSummaryDataSetDefinition=Visit Summary Data Set Definition +${project.parent.artifactId}.visitSummaryPdfRenderer=Visit Summary PDF Renderer diff --git a/omod/pom.xml b/omod/pom.xml index 09c42c9..e73d248 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -43,12 +43,6 @@ test-jar test - - com.github.librepdf - openpdf - ${openpdfVersion} - test - org.apache.pdfbox pdfbox