Skip to content

19690 - Improve Lab Report Patient Details Panel with Privilege-Controlled Editing#19691

Merged
damithdeshan98 merged 7 commits intodevelopmentfrom
19690-improve-patient-details-panel-in-lab-report-with-privilege-based-editing-and-reload
Apr 3, 2026
Merged

19690 - Improve Lab Report Patient Details Panel with Privilege-Controlled Editing#19691
damithdeshan98 merged 7 commits intodevelopmentfrom
19690-improve-patient-details-panel-in-lab-report-with-privilege-based-editing-and-reload

Conversation

@damithdeshan98
Copy link
Copy Markdown
Collaborator

@damithdeshan98 damithdeshan98 commented Apr 3, 2026

Summary:

  • Replaced the old single patient details panel with a two-column layout: system patient info (col-md-5) + editable
    report header fields (col-md-7).
  • Patient Name, Age, and Gender fields are now readonly unless the user has LabDeAutherizing privilege (and the report
    is not yet approved).
  • Added a "Reload Patient Details" button (requires LabDeAutherizing) that calls
    patientReportController.reloadPatientDetailsInReport() to sync report header from the current patient record.
  • Added a warning alert in the panel footer reminding users to verify reference ranges and flags after updating
    patient age/gender.
  • Applied identically to both patient_report.xhtml and patient_report_without_sample_sending_process.xhtml.

Summary by CodeRabbit

  • New Features

    • Added a "Reload Patient Details" button and a two-column patient details panel allowing inline edit of report-header name/age/gender with appropriate permission checks.
    • History logging now records patient-details edits and dynamic-label recalculations.
  • Bug Fixes

    • Age-based reference-range filtering made inclusive to ensure correct dynamic label/flag matching.

Signed-off-by: damithdeshan98 <hkddrajapaksha@gmail.com>
Signed-off-by: damithdeshan98 <hkddrajapaksha@gmail.com>
Signed-off-by: damithdeshan98 <hkddrajapaksha@gmail.com>
Signed-off-by: damithdeshan98 <hkddrajapaksha@gmail.com>
…olled Editing

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

coderabbitai bot commented Apr 3, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9b7f200c-7a27-43c6-a316-d39c4a38b871

📥 Commits

Reviewing files that changed from the base of the PR and between 7184de7 and b3dd6d0.

📒 Files selected for processing (2)
  • src/main/java/com/divudi/bean/lab/LabTestHistoryController.java
  • src/main/java/com/divudi/bean/lab/PatientReportController.java

Walkthrough

Adds UI controls and a controller action to reload patient name/age/gender into a patient report, optionally re-evaluate dynamic-label item values, and record two new lab-test history types for patient-detail edits and dynamic-label recalculation.

Changes

Cohort / File(s) Summary
Enum: History Types
src/main/java/com/divudi/core/data/lab/TestHistoryType.java
Added PATIENT_DETAILS_CHANGE and RECALCULATE_DYNAMICLABEL enum values and labels in getLabel().
Service: History Persistence
src/main/java/com/divudi/ejb/LabTestHistoryService.java
Added addParientDetailsEditHistory(...) and addReCalculateDynamicLabelHistory(...) to create history entries with corresponding types.
Controller: History Delegation
src/main/java/com/divudi/bean/lab/LabTestHistoryController.java
Added delegation methods that call service methods with current session institution, department, and loggedUser.
Controller: Report Reload
src/main/java/com/divudi/bean/lab/PatientReportController.java
Added reloadPatientDetailsInReport() to refresh report header fields (name, age, gender), persist report and item values, optionally recalculate dynamic-label values, and record history entries. Minor whitespace tweaks in sendSmsForPatientReport().
Bean: Dynamic Label Query
src/main/java/com/divudi/ejb/PatientReportBean.java
Changed JPQL age-range comparisons in getPatientDynamicLabel(...) from exclusive (< / >) to inclusive (<= / >=) bounds.
UI: patient_report view
src/main/webapp/lab/patient_report.xhtml
Replaced single-column patient panel with two-column layout; added editable report-header fields (name/age/gender) gated by approval/LabDeAutherizing privilege and a "Reload Patient Details" button; added warning footer.
UI: patient_report without sample sending
src/main/webapp/lab/patient_report_without_sample_sending_process.xhtml
Added two-column layout with report-header editable fields and a non-AJAX "Reload Patient Details" button; added warning footer.

Sequence Diagram

sequenceDiagram
    participant User as User
    participant UI as JSF View
    participant PRC as PatientReportController
    participant PRB as PatientReportBean
    participant LTHS as LabTestHistoryService
    participant DB as Database

    User->>UI: Click "Reload Patient Details"
    UI->>PRC: reloadPatientDetailsInReport()
    PRC->>PRB: load patient & data
    PRB->>DB: Query Patient / Flags
    DB-->>PRB: Return Patient / Flags
    PRC->>PRC: Update report (name, age, gender)
    PRC->>PRB: edit(currentPatientReport)
    PRB->>DB: Persist report
    DB-->>PRB: Confirm
    PRC->>LTHS: addParientDetailsEditHistory(...)
    LTHS->>DB: Insert history (PATIENT_DETAILS_CHANGE)
    DB-->>LTHS: Confirm

    alt Dynamic-label items present
        PRC->>PRB: getPatientDynamicLabel(...) per item
        PRB->>DB: Query InvestigationItemValueFlag (inclusive age bounds)
        DB-->>PRB: Return matching flags
        PRC->>PRC: Update report item values
        PRC->>PRB: savePatientReportItemValues()
        PRB->>DB: Persist item values
        DB-->>PRB: Confirm
        PRC->>LTHS: addReCalculateDynamicLabelHistory(...)
        LTHS->>DB: Insert history (RECALCULATE_DYNAMICLABEL)
        DB-->>LTHS: Confirm
    end

    PRC-->>UI: Show success message
    UI-->>User: Reload complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% 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
Title check ✅ Passed The title clearly and specifically summarizes the main change: improving the lab report patient details panel with privilege-controlled editing capabilities.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 19690-improve-patient-details-panel-in-lab-report-with-privilege-based-editing-and-reload

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: 6

🤖 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/lab/LabTestHistoryController.java`:
- Around line 181-187: The two controller wrappers (addParientDetailsEditHistory
and addReCalculateDynamicLabelHistory) currently call
labTestHistoryService.addApprovalHistory(...) and thus log events as
REPORT_APPROVED; change each to call the dedicated history methods on
labTestHistoryService instead (e.g., replace
labTestHistoryService.addApprovalHistory(...) in addParientDetailsEditHistory
with labTestHistoryService.addPatientDetailsEditHistory(...), and replace the
call in addReCalculateDynamicLabelHistory with
labTestHistoryService.addDynamicLabelRecalculateHistory(...)), passing the same
parameters (patientInvestigation, patientReport,
sessionController.getInstitution(), sessionController.getDepartment(),
sessionController.getLoggedUser()) so the proper history types are recorded.

In `@src/main/java/com/divudi/bean/lab/PatientReportController.java`:
- Line 268: The null/empty guard in PatientReportController is using || which
calls isEmpty() when getPatientReportItemValues() is null; change the condition
to use && so it reads that patientReportItemValues is not null AND not empty
(i.e., replace the currentPatientReport.getPatientReportItemValues() != null ||
!currentPatientReport.getPatientReportItemValues().isEmpty() check with a
null-safe AND check). This ensures getPatientReportItemValues() is only
dereferenced when non-null and prevents the NPE during save/reload.
- Around line 255-262: The code unconditionally updates currentPatientReport and
logs history even when values didn't change; modify the logic in
PatientReportController so you compute the new values (patientName, patientAge,
patientGender — and any DynamicLabel-derived values) and compare them against
the existing fields on currentPatientReport, and only call
getFacade().edit(currentPatientReport) and
labTestHistoryController.addParientDetailsEditHistory(...) when at least one of
those comparisons shows a real change; apply the same change-gating pattern to
the other similar block (the code block around lines 270-281) to avoid no-op
writes and false audit entries.

In `@src/main/java/com/divudi/ejb/PatientReportBean.java`:
- Line 513: The age-bound query in PatientReportBean (the SQL string building
the InvestigationItemValueFlag lookup using "f.retired=false" and inclusive
fromAge/toAge) is now inconsistent with the exclusive lookup in
LimsMiddlewareController (lines ~1704-1717); fix by unifying the logic: extract
the lookup into a single shared helper (e.g., a new method like
findInvestigationItemValueFlagByInvestigationItemAndAge in a common EJB/utility)
and update both PatientReportBean and LimsMiddlewareController to call that
helper so they use the same retired check and inclusive-from/toAge semantics for
consistent dynamic-label matching.

In `@src/main/webapp/lab/patient_report_without_sample_sending_process.xhtml`:
- Around line 880-913: The new p:inputText components with ids PatientName,
PatientAge, PatientGender conflict with existing components of the same ids in
the Developers-only section and must be made unique; rename these input ids (and
their matching p:outputLabel for attributes) to distinct names (for example
PatientName_readonly, PatientAge_readonly, PatientGender_readonly) and ensure
the value bindings remain
#{patientReportController.currentPatientReport.patientName|patientAge|patientGender}
and the readonly logic remains unchanged so labels and AJAX behavior target the
updated ids.

In `@src/main/webapp/lab/patient_report.xhtml`:
- Around line 937-944: Add server-side privilege enforcement inside
PatientReportController.reloadPatientDetailsInReport(): before performing any
reload logic call webUserController.hasPrivilege('LabDeAutherizing') and if it
returns false use JsfUtil.addErrorMessage("Unauthorized action") and return to
stop execution; ensure this check is the first thing in
reloadPatientDetailsInReport() so crafted requests cannot bypass the
frontend-disabled button.
🪄 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: d0c9c13e-b39d-4289-993e-45300e92c20d

📥 Commits

Reviewing files that changed from the base of the PR and between 5476712 and 7184de7.

📒 Files selected for processing (7)
  • src/main/java/com/divudi/bean/lab/LabTestHistoryController.java
  • src/main/java/com/divudi/bean/lab/PatientReportController.java
  • src/main/java/com/divudi/core/data/lab/TestHistoryType.java
  • src/main/java/com/divudi/ejb/LabTestHistoryService.java
  • src/main/java/com/divudi/ejb/PatientReportBean.java
  • src/main/webapp/lab/patient_report.xhtml
  • src/main/webapp/lab/patient_report_without_sample_sending_process.xhtml

@damithdeshan98 damithdeshan98 merged commit 540b3cf into development Apr 3, 2026
3 checks passed
@damithdeshan98 damithdeshan98 deleted the 19690-improve-patient-details-panel-in-lab-report-with-privilege-based-editing-and-reload branch April 3, 2026 14:23
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