Skip to content

Collection center report print pdf excel improvements#19634

Open
denuwanhendalage wants to merge 7 commits intodevelopmentfrom
collection-center-report-print-pdf-excel-improvements
Open

Collection center report print pdf excel improvements#19634
denuwanhendalage wants to merge 7 commits intodevelopmentfrom
collection-center-report-print-pdf-excel-improvements

Conversation

@denuwanhendalage
Copy link
Copy Markdown
Collaborator

@denuwanhendalage denuwanhendalage commented Mar 31, 2026

Improved collection center report print PDF, Excel, and Print Preview
Changed files

  1. reportController (pdf generation method, postProcessor for excel)
  2. collection_center_reports_print.xhtml
  3. collection_center_reports_print_view.xhtml (created for clear print preview)

Summary by CodeRabbit

  • New Features

    • PDF exports now include styled filter summaries and a dedicated printable view for collection center reports.
    • Excel exports embed filter metadata and produce dynamic date-range filenames.
  • Improvements

    • Print action opens a print-focused view with A4 landscape styling and printable footer.
    • Report date/time formatting now follows application-wide preferences.
    • Added exports for collection-center balance, summary, and detailed print reports.
  • Bug Fixes

    • Corrected typo in “Last Printing Time” column header.

Signed-off-by: denuwanhendalage <shashankadenuwanb@gmail.com>
Signed-off-by: denuwanhendalage <shashankadenuwanb@gmail.com>
Signed-off-by: denuwanhendalage <shashankadenuwanb@gmail.com>
Signed-off-by: denuwanhendalage <shashankadenuwanb@gmail.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

Walkthrough

Adds multi-report export and print support for Collection Center reports: new filter builders, Excel post-processors, PDF preprocessors/exporter in ReportController; updated JSF views to use dynamic filenames and processor hooks; and a new print-only Facelets view rendering printable report and filter summary.

Changes

Cohort / File(s) Summary
Backend: ReportController
src/main/java/com/divudi/bean/report/ReportController.java
Added multiple public methods: filter builders (getFiltersForCollectionCenterWiseSummaryReport, getFiltersForCollectionCenterBalanceReport, getFiltersForCollectionCenterReportPrint), Excel post-processors (postProcessCollectionCenterWiseSummaryReportExcel, postProcessCollectionCenterBalanceReportExcel, postProcessCollectionCenterReportPrintExcel), PDF preprocessors (preProcessCollectionCenterWiseSummaryReportPDF, preProcessCollectionCenterBalanceReportPDF) and a PDF exporter (exportCollectionCenterReportPrintToPDF) that build/validate documents, inject metadata via pharmacyController, and render/export PDF/Excel outputs.
View: Print entry & exporter integration
src/main/webapp/reports/collectionCenterReports/collection_center_report_print.xhtml
Replaced inline client-side printing with navigation to a print view; switched PDF export to controller-driven export; Excel exporter now uses dynamic filename (fromDateFormatted/toDateFormatted) and calls postProcessCollectionCenterReportPrintExcel; adjusted table cells to use p:outputLabel/exportValue and standardized date formatting to application preference.
View: New print-only Facelets page
src/main/webapp/reports/collectionCenterReports/collection_center_report_print_view.xhtml
Added new print view that embeds A4-landscape print CSS, renders institution/title/optional-department header, prints filter summary (with formatted dates and fallback “All …” labels), and outputs a printable table via ui:repeat over reportController.patientInvestigations including status markers and printing metadata.
View: Balance report exporter hooks
src/main/webapp/reports/collectionCenterReports/collection_center_balance_report.xhtml
Excel exporter filename made dynamic and postProcessor added; PDF exporter filename made dynamic and preProcessor added to attach filter summary metadata.
View: Wise summary exporter hooks
src/main/webapp/reports/collectionCenterReports/collection_center_wise_summary_report.xhtml
Excel and PDF exporters updated to use dynamic date-range filenames and to call the new postProcess...Excel and preProcess...PDF processor methods respectively.

Sequence Diagram(s)

sequenceDiagram
    participant User as Browser/User
    participant View as JSF View
    participant ReportCtrl as ReportController
    participant Pharmacy as PharmacyController
    participant Response as HTTP Response

    User->>View: Click "PDF" export / "Print" navigation
    alt Print navigation
        View->>View: Navigate to print view (render HTML)
        View-->>User: Printable HTML (client-side print)
    else PDF export
        View->>ReportCtrl: exportCollectionCenterReportPrintToPDF()
        ReportCtrl->>ReportCtrl: validate patientInvestigations, build filters
        ReportCtrl->>Pharmacy: createInfoTablePdfExport(filters)
        Pharmacy-->>ReportCtrl: info table (PDF element)
        ReportCtrl->>ReportCtrl: build 13-column PDF table from patientInvestigations
        ReportCtrl->>Response: write PDF bytes, set Content-Disposition (filename)
        Response-->>User: Downloadable PDF
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main focus of the changeset: improvements to collection center report functionality for PDF, Excel, and print preview.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch collection-center-report-print-pdf-excel-improvements

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.42.0)
src/main/java/com/divudi/bean/report/ReportController.java

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/webapp/reports/collectionCenterReports/collection_center_report_print.xhtml (1)

303-310: ⚠️ Potential issue | 🟡 Minor

Remove the stray > from the print-preview button.

That extra character becomes a text node inside the component body and can leak into the rendered button markup.

🛠️ Proposed fix
-                            action="collection_center_report_print_view?faces-redirect=true">>
+                            action="collection_center_report_print_view?faces-redirect=true">
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/webapp/reports/collectionCenterReports/collection_center_report_print.xhtml`
around lines 303 - 310, The p:commandButton declaration for the print preview
(the element with icon="fa-solid fa-print", value="To Print" and
action="collection_center_report_print_view?faces-redirect=true") contains a
stray ">" after the start tag which creates a text node in the component body;
remove that extra ">" so the tag ends cleanly as </p:commandButton> (i.e.,
ensure there is no extraneous character between the opening tag and the closing
tag).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/com/divudi/bean/report/ReportController.java`:
- Around line 2517-2523: The current shiftRows call uses 7 rows but
pharmacyController.addMetaDataToExcelSheet(workbook, sheet, 0, "Collection
Center Report Print", filters) can write 8 rows when an institution row is
present; update the sheet.shiftRows(0, sheet.getLastRowNum(), 7) call to shift
by 8 instead so the metadata (institution row + title + filter rows + blank row)
does not overlap subsequent data when getFiltersForCollectionCenterReportPrint()
returns filters.

In
`@src/main/webapp/reports/collectionCenterReports/collection_center_report_print_view.xhtml`:
- Around line 193-195: The output text is reading
reportController.person.nameWithTitle while the filter binds to
reportController.doctor, causing a mismatch; update the summary binding to use
the same property as the filter (check empty reportController.doctor and render
reportController.doctor.nameWithTitle or fallback to 'All doctors') so both
display and filter use reportController.doctor instead of
reportController.person.

---

Outside diff comments:
In
`@src/main/webapp/reports/collectionCenterReports/collection_center_report_print.xhtml`:
- Around line 303-310: The p:commandButton declaration for the print preview
(the element with icon="fa-solid fa-print", value="To Print" and
action="collection_center_report_print_view?faces-redirect=true") contains a
stray ">" after the start tag which creates a text node in the component body;
remove that extra ">" so the tag ends cleanly as </p:commandButton> (i.e.,
ensure there is no extraneous character between the opening tag and the closing
tag).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 234218de-b7d4-4e68-b34e-3924ad416706

📥 Commits

Reviewing files that changed from the base of the PR and between 6f3aa97 and 233d508.

📒 Files selected for processing (3)
  • src/main/java/com/divudi/bean/report/ReportController.java
  • src/main/webapp/reports/collectionCenterReports/collection_center_report_print.xhtml
  • src/main/webapp/reports/collectionCenterReports/collection_center_report_print_view.xhtml

Signed-off-by: denuwanhendalage <shashankadenuwanb@gmail.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/webapp/reports/collectionCenterReports/collection_center_report_print_view.xhtml`:
- Line 230: Update the UI label in the report header where the h:outputText with
value="Reffered By" is defined by correcting the typo to value="Referred By";
locate the h:outputText element in collection_center_report_print_view.xhtml and
change the string literal to the correct spelling so the displayed column header
reads "Referred By".
- Around line 186-188: The view is binding to #{reportController.phn}, which
doesn't match the ReportController getter and can break EL resolution; change
the EL to the controller's actual MRN/PHN property (e.g., replace occurrences of
reportController.phn with reportController.phnNumber) so the outputText uses the
exact exposed property name; update both the label/value bindings in the
fragment referencing Patient MRN to use reportController.phnNumber (or the exact
getter name from ReportController) to ensure proper EL resolution at render
time.
- Around line 268-270: The report is binding "Order Date" to the investigation
master timestamp (patientInvestigation.investigation.createdAt) which is
incorrect; replace that EL with the patient order timestamp (for example
patientInvestigation.order.createdAt or
patientInvestigation.investigationOrder.createdAt — whichever model property
holds the patient’s order/request timestamp) and keep the existing
f:convertDateTime pattern; if no explicit order timestamp property exists,
fetch/populate and use the patientInvestigation.createdAt (order) field instead
of investigation.createdAt.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1741198c-387d-4a3b-ba1f-8299279d0495

📥 Commits

Reviewing files that changed from the base of the PR and between 233d508 and 2aaf77b.

📒 Files selected for processing (1)
  • src/main/webapp/reports/collectionCenterReports/collection_center_report_print_view.xhtml

Signed-off-by: denuwanhendalage <shashankadenuwanb@gmail.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/webapp/reports/collectionCenterReports/collection_center_report_print_view.xhtml (1)

202-245: Add table-level accessible labeling for assistive technologies.

The table headers are clear visually, but the table itself has no caption/explicit label. Add a caption (or aria-label) so screen-reader navigation is clearer.

♿ Proposed improvement
-                                    <table>
+                                    <table aria-label="Collection Center Report Results">
+                                        <caption style="text-align:left; font-weight:600;">
+                                            <h:outputText value="Collection Center Report Results"/>
+                                        </caption>
                                         <thead>
As per coding guidelines: "Implement accessibility with proper tooltips and labeling".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/webapp/reports/collectionCenterReports/collection_center_report_print_view.xhtml`
around lines 202 - 245, The table in the diff (the <table> containing header
cells with h:outputText values like "S. No", "CC Code", "Leaf No.", etc.) lacks
an accessible label; add a visible <caption> (e.g., "Collection Center Report -
Print View") or an aria-label/aria-labelledby on that table element so screen
readers can announce its purpose, and ensure the caption text matches the table
content; if using aria-labelledby, add a hidden heading id near the table and
reference it from the table's aria-labelledby attribute.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/webapp/reports/collectionCenterReports/collection_center_report_print_view.xhtml`:
- Around line 287-292: The template dereferences
patientInvestigation.printingUser.name (and prints printingAt) without null
checks, which can cause EL render failures if printingUser or printingAt is
null; update the JSF to guard these values — either wrap the name output in a
rendered="#{not empty patientInvestigation.printingUser}" (or render a
placeholder) or change the value to use a safe EL expression like
"#{patientInvestigation.printingUser != null ?
patientInvestigation.printingUser.name : ''}" and similarly guard
"#{patientInvestigation.printingAt}" (or only render the date converter when not
null) so the components (h:outputText) for printingUser.name and printingAt
cannot dereference null objects.

---

Nitpick comments:
In
`@src/main/webapp/reports/collectionCenterReports/collection_center_report_print_view.xhtml`:
- Around line 202-245: The table in the diff (the <table> containing header
cells with h:outputText values like "S. No", "CC Code", "Leaf No.", etc.) lacks
an accessible label; add a visible <caption> (e.g., "Collection Center Report -
Print View") or an aria-label/aria-labelledby on that table element so screen
readers can announce its purpose, and ensure the caption text matches the table
content; if using aria-labelledby, add a hidden heading id near the table and
reference it from the table's aria-labelledby attribute.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 14c708e0-445a-4111-b382-1e65d55c49ba

📥 Commits

Reviewing files that changed from the base of the PR and between 2aaf77b and e4c9e8b.

📒 Files selected for processing (1)
  • src/main/webapp/reports/collectionCenterReports/collection_center_report_print_view.xhtml

Comment on lines +287 to +292
<h:outputText value="#{patientInvestigation.printingUser.name}" style="margin-left: 1mm;"/>
</td>
<td>
<h:outputText value="#{patientInvestigation.printingAt}" style="margin-left: 1mm;">
<f:convertDateTime pattern="#{sessionController.applicationPreference.longDateTimeFormat}"/>
</h:outputText>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Handle nullable print metadata safely to avoid render-time EL failures.

Line 287 dereferences patientInvestigation.printingUser.name directly. If printingUser is null, the row/page can fail to render.

💡 Proposed fix
                                                     <td>
-                                                        <h:outputText value="#{patientInvestigation.printingUser.name}" style="margin-left: 1mm;"/>
+                                                        <h:outputText value="#{empty patientInvestigation.printingUser ? 'Not Printed' : patientInvestigation.printingUser.name}" style="margin-left: 1mm;"/>
                                                     </td>
                                                     <td>
-                                                        <h:outputText value="#{patientInvestigation.printingAt}" style="margin-left: 1mm;">
+                                                        <h:outputText value="#{patientInvestigation.printingAt}" rendered="#{not empty patientInvestigation.printingAt}" style="margin-left: 1mm;">
                                                             <f:convertDateTime pattern="#{sessionController.applicationPreference.longDateTimeFormat}"/>
                                                         </h:outputText>
+                                                        <h:outputText value="-" rendered="#{empty patientInvestigation.printingAt}" style="margin-left: 1mm;"/>
                                                     </td>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/webapp/reports/collectionCenterReports/collection_center_report_print_view.xhtml`
around lines 287 - 292, The template dereferences
patientInvestigation.printingUser.name (and prints printingAt) without null
checks, which can cause EL render failures if printingUser or printingAt is
null; update the JSF to guard these values — either wrap the name output in a
rendered="#{not empty patientInvestigation.printingUser}" (or render a
placeholder) or change the value to use a safe EL expression like
"#{patientInvestigation.printingUser != null ?
patientInvestigation.printingUser.name : ''}" and similarly guard
"#{patientInvestigation.printingAt}" (or only render the date converter when not
null) so the components (h:outputText) for printingUser.name and printingAt
cannot dereference null objects.

…ction center wise summary report

Signed-off-by: denuwanhendalage <shashankadenuwanb@gmail.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/com/divudi/bean/report/ReportController.java`:
- Around line 785-789: The PDF header is hardcoded to "Laboratory Workload
Summary Report" in ReportController (the reportTitle Paragraph created with
reportFont), but this pre-processor generates a collection-center-wise summary;
replace the hardcoded string when constructing reportTitle with the
collection-center specific title (e.g., call or build from the collection center
name or a getCollectionCenterReportTitle() method / variable such as
collectionCenter.getName() + " Collection Center Summary Report") so the header
reflects the actual report; keep using reportFont and leave alignment/spacing
and pdf.add(reportTitle) unchanged.
- Around line 2648-2666: The exported header can drift because
getFiltersForCollectionCenterReportPrint() rebuilds filters from current form
fields while patientInvestigations is populated by listCcReportPrint(); fix by
snapshotting the filters when listCcReportPrint() successfully runs and use that
snapshot for exports: add a new field (e.g., Map<String,Object>
processedCcReportFilters) set inside listCcReportPrint() after the query
completes, populate it from the same values currently used in
getFiltersForCollectionCenterReportPrint(), and then change
getFiltersForCollectionCenterReportPrint() to return the snapshot if non-null
(fallback to rebuilding only if snapshot is null) so PDF/Excel output stays
consistent with the processed result set.
- Around line 2735-2742: The PDF rendering currently always uses
bill.getFromInstitution() for CC Code and CC Route which is wrong when the query
matched bill.getCollectingCentre(); update the rendering in ReportController to
resolve a local Centre source first (e.g., Institution centre =
row.getBillItem().getBill().getCollectingCentre() != null ?
row.getBillItem().getBill().getCollectingCentre() :
row.getBillItem().getBill().getFromInstitution()) and then use centre.getCode()
and (centre.getRoute() != null ? centre.getRoute().getName() : "-") when
creating the textCell for CC Code and CC Route; ensure you null-check centre
before calling methods and keep the existing fallback "-" for missing values.
- Around line 751-752: Short sheet names must be used before calling
workbook.setSheetName to avoid POI's 31-char limit; update the calls to
workbook.setSheetName(...) that currently use "Collection Center Wise Summary
Report" and "Collection Center Balance Report" (and the identical calls at the
other location around the second occurrence) to shorter names (e.g., "Collection
Center Summary" and "Collection Center Balance") and then proceed with
sheet.shiftRows(...) as before; ensure you change both occurrences where
setSheetName is invoked so no IllegalArgumentException is thrown.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ce93cda4-0281-47cd-8c6d-1c8c7f3dae60

📥 Commits

Reviewing files that changed from the base of the PR and between e4c9e8b and a5261c8.

📒 Files selected for processing (3)
  • src/main/java/com/divudi/bean/report/ReportController.java
  • src/main/webapp/reports/collectionCenterReports/collection_center_balance_report.xhtml
  • src/main/webapp/reports/collectionCenterReports/collection_center_wise_summary_report.xhtml

Comment on lines +751 to +752
workbook.setSheetName(0, "Collection Center Wise Summary Report");
sheet.shiftRows(0, sheet.getLastRowNum(), 7);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

For Apache POI 5.2.5 / XSSFWorkbook.setSheetName, what is the maximum allowed Excel sheet name length, and what exception is thrown when the name exceeds that limit?

💡 Result:

The maximum allowed Excel sheet name length for Apache POI 5.2.5 / XSSFWorkbook.setSheetName is 31 characters. When the name exceeds this limit, an IllegalArgumentException is thrown.

Citations:


Shorten these Excel sheet names before calling setSheetName().

Excel/POI rejects sheet names longer than 31 characters. "Collection Center Wise Summary Report" is 37 characters and "Collection Center Balance Report" is 32 characters—both will throw IllegalArgumentException before the metadata rows are added.

Suggested fix
-        workbook.setSheetName(0, "Collection Center Wise Summary Report");
+        workbook.setSheetName(0, "CC Wise Summary Report");-        workbook.setSheetName(0, "Collection Center Balance Report");
+        workbook.setSheetName(0, "CC Balance Report");

Also applies to: 1788-1789

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/divudi/bean/report/ReportController.java` around lines 751
- 752, Short sheet names must be used before calling workbook.setSheetName to
avoid POI's 31-char limit; update the calls to workbook.setSheetName(...) that
currently use "Collection Center Wise Summary Report" and "Collection Center
Balance Report" (and the identical calls at the other location around the second
occurrence) to shorter names (e.g., "Collection Center Summary" and "Collection
Center Balance") and then proceed with sheet.shiftRows(...) as before; ensure
you change both occurrences where setSheetName is invoked so no
IllegalArgumentException is thrown.

Comment on lines +785 to +789
// ── Report title ──────────────────────────────────────────────
com.lowagie.text.Paragraph reportTitle = new com.lowagie.text.Paragraph("Laboratory Workload Summary Report", reportFont);
reportTitle.setAlignment(com.lowagie.text.Element.ALIGN_LEFT);
reportTitle.setSpacingAfter(2f);
pdf.add(reportTitle);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use the collection-center report title in the PDF header.

This pre-processor is for the collection center wise summary export, but the generated PDF is titled Laboratory Workload Summary Report. That makes the downloaded file look like the wrong report.

Suggested fix
-            com.lowagie.text.Paragraph reportTitle = new com.lowagie.text.Paragraph("Laboratory Workload Summary Report", reportFont);
+            com.lowagie.text.Paragraph reportTitle = new com.lowagie.text.Paragraph("Collection Center Wise Summary Report", reportFont);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/divudi/bean/report/ReportController.java` around lines 785
- 789, The PDF header is hardcoded to "Laboratory Workload Summary Report" in
ReportController (the reportTitle Paragraph created with reportFont), but this
pre-processor generates a collection-center-wise summary; replace the hardcoded
string when constructing reportTitle with the collection-center specific title
(e.g., call or build from the collection center name or a
getCollectionCenterReportTitle() method / variable such as
collectionCenter.getName() + " Collection Center Summary Report") so the header
reflects the actual report; keep using reportFont and leave alignment/spacing
and pdf.add(reportTitle) unchanged.

Comment on lines +2648 to +2666
public Map<String, Object> getFiltersForCollectionCenterReportPrint() {
SimpleDateFormat sdf = new SimpleDateFormat(sessionController.getApplicationPreference().getLongDateTimeFormat());
Map<String, Object> filters = new LinkedHashMap<>();

filters.put("From Date", sdf.format(getFromDate()));
filters.put("To Date", sdf.format(getToDate()));
filters.put("Institution", institution != null ? institution.getName() : "All");
filters.put("Site", site != null ? site.getName() : "All");
filters.put("Department", department != null ? department.getName() : "All");
filters.put("CC Route",route != null ? route.getName() : "All");
filters.put("CC Name",collectingCentre != null ? collectingCentre.getName() : "All");
filters.put("Category",category != null ? category.getName() : "All");
filters.put("Investigation",investigation != null ? investigation.getName() : "All");
filters.put("Result status",patientInvestigationStatus != null ? patientInvestigationStatus.getLabel() : "All");
filters.put("Patient MRN",phn != null && !phn.trim().isEmpty() ? phn: "All");
filters.put("Invoice No.",invoiceNumber != null && !invoiceNumber.trim().isEmpty() ? invoiceNumber : "All");
filters.put("Referring Doctor",doctor != null ? doctor.getPerson().getNameWithTitle() : "All");
return filters;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Export metadata can drift away from the processed result set.

patientInvestigations is session state populated by listCcReportPrint(), but getFiltersForCollectionCenterReportPrint() always rebuilds the header/filter block from the current form values. In src/main/webapp/reports/collectionCenterReports/collection_center_report_print.xhtml, Process and PDF/Excel are separate submits, so changing a filter and exporting without re-processing will produce old rows with a new header/filter summary. Re-run the query on export, or snapshot the processed filters when listCcReportPrint() succeeds and reuse that snapshot for PDF/Excel.

Also applies to: 2668-2710, 2778-2781

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/divudi/bean/report/ReportController.java` around lines 2648
- 2666, The exported header can drift because
getFiltersForCollectionCenterReportPrint() rebuilds filters from current form
fields while patientInvestigations is populated by listCcReportPrint(); fix by
snapshotting the filters when listCcReportPrint() successfully runs and use that
snapshot for exports: add a new field (e.g., Map<String,Object>
processedCcReportFilters) set inside listCcReportPrint() after the query
completes, populate it from the same values currently used in
getFiltersForCollectionCenterReportPrint(), and then change
getFiltersForCollectionCenterReportPrint() to return the snapshot if non-null
(fallback to rebuilding only if snapshot is null) so PDF/Excel output stays
consistent with the processed result set.

Comment on lines +2735 to +2742
table.addCell(textCell(row.getBillItem().getBill().getFromInstitution().getCode(),bodyFontSmall));
table.addCell(textCell(row.getBillItem().getBill().getReferenceNumber(),bodyFontSmall));
table.addCell(textCell(row.getBillItem().getBill().getPatient().getPhn(),bodyFontSmall));
table.addCell(textCell(row.getBillItem().getBill().getPatient().getPerson().getNameWithTitle(),bodyFontSmall));
table.addCell(textCell(row.getBillItem().getBill().getDeptId(),bodyFontSmall));
table.addCell(textCell(row.getInvestigation().getCreatedAt() != null ? sdf.format(row.getInvestigation().getCreatedAt() ) : "-",bodyFontSmall));
table.addCell(textCell(row.getBillItem().getBill().getFromInstitution().getRoute()!= null ? row.getBillItem().getBill().getFromInstitution().getRoute().getName() : "-",bodyFontSmall));
table.addCell(textCell(row.getBillItem().getBill().getReferredInstituteOrDoctor()!=null ? row.getBillItem().getBill().getReferredInstituteOrDoctor().getName() : "-",bodyFontSmall));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Resolve CC code/route from the same source combination the query uses.

The query at Line 2597 and Line 2605 accepts rows where either bill.collectingCentre or bill.fromInstitution matches the selected centre, but the PDF always renders CC Code and CC Route from bill.fromInstitution. Rows matched through bill.collectingCentre will therefore show the wrong centre, and can also hit a null dereference if fromInstitution is absent.

Suggested fix
+                Institution cc = row.getBillItem().getBill().getCollectingCentre() != null
+                        ? row.getBillItem().getBill().getCollectingCentre()
+                        : row.getBillItem().getBill().getFromInstitution();
-                table.addCell(textCell(row.getBillItem().getBill().getFromInstitution().getCode(),bodyFontSmall));
+                table.addCell(textCell(cc != null ? cc.getCode() : "-", bodyFontSmall));-                table.addCell(textCell(row.getBillItem().getBill().getFromInstitution().getRoute()!= null ? row.getBillItem().getBill().getFromInstitution().getRoute().getName() : "-",bodyFontSmall));
+                table.addCell(textCell(cc != null && cc.getRoute() != null ? cc.getRoute().getName() : "-", bodyFontSmall));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/divudi/bean/report/ReportController.java` around lines 2735
- 2742, The PDF rendering currently always uses bill.getFromInstitution() for CC
Code and CC Route which is wrong when the query matched
bill.getCollectingCentre(); update the rendering in ReportController to resolve
a local Centre source first (e.g., Institution centre =
row.getBillItem().getBill().getCollectingCentre() != null ?
row.getBillItem().getBill().getCollectingCentre() :
row.getBillItem().getBill().getFromInstitution()) and then use centre.getCode()
and (centre.getRoute() != null ? centre.getRoute().getName() : "-") when
creating the textCell for CC Code and CC Route; ensure you null-check centre
before calling methods and keep the existing fallback "-" for missing values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant