Skip to content

Implement three-tier discharge system: clinical, room, and hospital discharge#19658

Merged
buddhika75 merged 3 commits intodevelopmentfrom
19657-three-tier-discharge-system
Apr 2, 2026
Merged

Implement three-tier discharge system: clinical, room, and hospital discharge#19658
buddhika75 merged 3 commits intodevelopmentfrom
19657-three-tier-discharge-system

Conversation

@buddhika75
Copy link
Copy Markdown
Member

@buddhika75 buddhika75 commented Apr 2, 2026

Summary

  • Introduces a Clinical Discharge concept — a doctor-confirmed sign-off captured on a new inward_clinical_discharge.xhtml page, linked from the inpatient dashboard
  • Mirrors Room Discharge timestamp to PatientEncounter when the last room is vacated
  • Adds a warning on Hospital Discharge (interim bill) if clinical discharge has not been confirmed
  • Adds a configurable Discharge Condition admin list (emr/admin/discharge_conditions.xhtml) using the existing ClinicalEntity / SymanticType pattern (mirrors plans.xhtml)

Changes

Area Detail
Entity 9 new fields on PatientEncounter for clinical/room discharge tracking and clinical discharge content
Enum PatientEncounterType.ClinicalDischarge, SymanticType.Discharge_Condition
Privilege InpatientClinicalDischarge
New files DischargeConditionController.java, discharge_conditions.xhtml, inward_clinical_discharge.xhtml
Controller 6 new methods in InpatientClinicalDataController
Integration Room discharge → encounter sync in RoomChangeController; warning in BhtSummeryController
UI Clinical Discharge button on admission_profile.xhtml (green = confirmed, orange = pending)

Test plan

  • Update persistence to pick up new PatientEncounter columns
  • Seed discharge condition values via missing_database_fields.xhtml
  • Assign InpatientClinicalDischarge privilege to doctor roles
  • Link discharge_conditions.xhtml in the EMR admin navigation menu
  • Navigate to inpatient dashboard → Clinical Discharge button visible and orange
  • Enter discharge condition, diagnoses, summary, follow-up, activity/diet → Save Draft
  • Confirm Clinical Discharge → banner turns green, fields become read-only
  • Cancel Clinical Discharge → fields reopen for editing
  • Discharge a room → verify roomDischargeDateTime set on the encounter
  • Attempt hospital discharge without clinical discharge → warning message shown
  • Attempt hospital discharge after clinical discharge → no warning

Closes #19657

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Full clinical discharge workflow for inpatient care with draft, confirm and cancel flows, discharge documentation, diagnoses, and timestamps.
    • Admin UI to manage discharge conditions, including list/edit/delete and Excel export.
    • New “Clinical Discharge” action on admission profile and a dedicated clinical discharge page with guided inputs and state-aware controls.
    • Pre-discharge validation preventing discharge until clinical discharge is confirmed; room discharge times now update encounter records.

…ischarge

- Add PatientEncounterType.ClinicalDischarge and SymanticType.Discharge_Condition
- Add InpatientClinicalDischarge privilege
- Add clinical discharge fields to PatientEncounter (clinicallyDischarged,
  clinicalDischargeDateTime, clinicalDischargedBy, roomDischargeDateTime,
  roomDischargedBy, dischargeCondition, followUpPlan, activityInstructions,
  dietInstructions)
- Add DischargeConditionController and discharge_conditions.xhtml admin page
  for configurable discharge condition values (Stable, DAMA, Referred, etc.)
- Add inward_clinical_discharge.xhtml page with condition, diagnoses, summary,
  follow-up, activity/diet sections and confirm/cancel actions
- Add navigateToClinicalDischargeFromAdmission, saveClinicalDischarge,
  confirmClinicalDischarge, cancelClinicalDischarge to InpatientClinicalDataController
- Sync roomDischargeDateTime to PatientEncounter when last room is discharged
- Warn on hospital discharge if clinical discharge not yet confirmed
- Add Clinical Discharge button to admission_profile.xhtml (green/orange status)

Closes #19657

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

Walkthrough

Introduces clinical discharge as a new discharge tier: data model additions to PatientEncounter, enums and privilege, a DischargeCondition management controller and admin page, inpatient clinical discharge UI and controller flows, and synchronization of room/hospital discharge operations with clinical discharge state.

Changes

Cohort / File(s) Summary
Data Model & Enums
src/main/java/com/divudi/core/entity/PatientEncounter.java, src/main/java/com/divudi/core/data/SymanticType.java, src/main/java/com/divudi/core/data/PatientEncounterType.java, src/main/java/com/divudi/core/data/Privileges.java
Added clinical and room discharge fields and clinical-discharge content fields to PatientEncounter. Added Discharge_Condition to SymanticType, ClinicalDischarge to PatientEncounterType, and InpatientClinicalDischarge privilege.
Discharge Conditions Management
src/main/java/com/divudi/bean/clinical/DischargeConditionController.java, src/main/webapp/emr/admin/discharge_conditions.xhtml
New session-scoped JSF controller for CRUD, autocomplete and Excel export of discharge conditions; companion admin Facelets page with list/detail UI and controls (Add, Delete, Save, Download).
Clinical Discharge Workflow UI & Controller
src/main/java/com/divudi/bean/inward/InpatientClinicalDataController.java, src/main/webapp/inward/inward_clinical_discharge.xhtml
New navigation to clinical discharge, find-or-create clinical discharge record, save/confirm/cancel workflows, and a clinical discharge form with condition, diagnoses, summary, follow-up, activity and diet fields; UI becomes read-only after confirmation.
Room & Hospital Discharge Integration
src/main/java/com/divudi/bean/inward/RoomChangeController.java, src/main/java/com/divudi/bean/inward/BhtSummeryController.java, src/main/webapp/inward/admission_profile.xhtml
Room discharge now mirrors room discharge timestamp/user to parent PatientEncounter when applicable. Hospital discharge emits a non-blocking warning if clinical discharge not confirmed. Admission profile gains a privilege-gated “Clinical Discharge” navigation button with status styling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Admission
    participant InpatientController
    participant PatientEncounter
    participant RoomChange
    participant Hospital

    User->>Admission: Open admission profile
    Admission-->>User: Show "Clinical Discharge" button

    rect rgba(100,150,200,0.5)
    Note over User,InpatientController: Clinical Discharge Workflow
    User->>InpatientController: navigateToClinicalDischargeFromAdmission(admission)
    InpatientController->>PatientEncounter: findOrCreate ClinicalDischarge record
    InpatientController-->>User: Navigate to clinical discharge form
    User->>InpatientController: saveClinicalDischarge()
    InpatientController->>PatientEncounter: Persist clinical discharge (draft)
    User->>InpatientController: confirmClinicalDischarge()
    InpatientController->>Admission: Set clinicallyDischarged=true, timestamp, user
    InpatientController->>PatientEncounter: Persist parent admission
    InpatientController-->>User: Show confirmation banner / disable form
    end

    rect rgba(150,100,150,0.5)
    Note over User,RoomChange: Room Discharge Sync
    User->>RoomChange: discharge patient from room
    RoomChange->>PatientEncounter: Set roomDischargeDateTime, roomDischargedBy
    RoomChange->>PatientEncounter: Persist sync
    RoomChange-->>User: Room discharged
    end

    rect rgba(200,100,100,0.5)
    Note over User,Hospital: Hospital Discharge
    User->>Hospital: Complete billing → invoke hospital discharge
    Hospital->>Admission: Check isClinicallyDischarged()
    alt Not clinically discharged
        Hospital-->>User: Warning message (non-blocking)
    end
    Hospital->>Admission: Set discharged=true, dateOfDischarge
    Hospital-->>User: Discharge complete
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately and concisely summarizes the primary change: implementing a three-tier discharge system (clinical, room, hospital).
Linked Issues check ✅ Passed All major objectives from issue #19657 are addressed: clinical discharge workflow, room discharge sync, hospital discharge warning, discharge conditions admin, privilege system, and controller modifications.
Out of Scope Changes check ✅ Passed All changes directly support the three-tier discharge system implementation specified in #19657; no unrelated modifications detected.

✏️ 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 19657-three-tier-discharge-system

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

Caution

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

⚠️ Outside diff range comments (1)
src/main/java/com/divudi/bean/inward/RoomChangeController.java (1)

296-306: ⚠️ Potential issue | 🟠 Major

Add room discharge sync logic to discharge() or use dischargeWithCurrentTime() instead.

The discharge(PatientRoom pR) method lacks the room discharge synchronization that dischargeWithCurrentTime() provides. When discharge() is called on the last room (as it is in BhtSummeryController line 1634), the PatientEncounter is not updated with roomDischargeDateTime and roomDischargedBy, leaving inconsistent state. Either add the sync logic (lines 28–32 from dischargeWithCurrentTime()) to discharge(), or replace the call in BhtSummeryController with dischargeWithCurrentTime().

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

In `@src/main/java/com/divudi/bean/inward/RoomChangeController.java` around lines
296 - 306, The discharge(PatientRoom pR) method currently sets discharged flags
and persists the PatientRoom but omits the room-discharge synchronization
present in dischargeWithCurrentTime(); update discharge(PatientRoom) to also set
the PatientEncounter.roomDischargeDateTime and PatientEncounter.roomDischargedBy
(the same logic found in dischargeWithCurrentTime(), lines that update
encounter's roomDischargeDateTime and roomDischargedBy and persist via
getPatientEncounterFacade().edit(encounter)), or alternatively replace the call
site in BhtSummeryController to invoke dischargeWithCurrentTime(pR) instead so
the encounter is updated; ensure you reference and persist the PatientEncounter
via getPatientEncounterFacade() and maintain
notificationController.createNotification(pR, "Discharge").
🧹 Nitpick comments (3)
src/main/webapp/inward/admission_profile.xhtml (1)

425-432: LGTM!

The Clinical Discharge button is well-implemented:

  • Privilege check via webUserController.hasPrivilege('InpatientClinicalDischarge') follows coding guidelines.
  • PrimeFaces button classes (ui-button-success, ui-button-warning) are correctly used per guidelines.
  • Conditional styling based on clinicallyDischarged provides clear visual status indication.

Consider adding a title attribute for accessibility (e.g., title="Navigate to Clinical Discharge") to align with the accessibility guideline for tooltips and labeling. 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/inward/admission_profile.xhtml` around lines 425 - 432, Add
an accessible tooltip/title to the Clinical Discharge button by adding a title
attribute on the p:commandButton that describes its action (e.g.,
title="Navigate to Clinical Discharge"); update the element where
action="#{inpatientClinicalDataController.navigateToClinicalDischargeFromAdmission(admissionController.current)}"
and rendered="#{webUserController.hasPrivilege('InpatientClinicalDischarge')}"
so the title is present regardless of the conditional style that uses
admissionController.current.clinicallyDischarged.
src/main/java/com/divudi/bean/clinical/DischargeConditionController.java (2)

198-206: Handle invalid numeric input gracefully.

Long.valueOf(value) throws NumberFormatException if the value is not a valid number. While JSF will catch this, explicit handling provides a clearer error.

🛡️ Proposed improvement
 `@Override`
 public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
     if (value == null || value.length() == 0) {
         return null;
     }
+    try {
         DischargeConditionController controller = (DischargeConditionController) facesContext.getApplication()
                 .getELResolver().getValue(facesContext.getELContext(), null, "dischargeConditionController");
         return controller.getEjbFacade().find(Long.valueOf(value));
+    } catch (NumberFormatException e) {
+        return null;
+    }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/divudi/bean/clinical/DischargeConditionController.java`
around lines 198 - 206, In getAsObject of DischargeConditionController,
currently Long.valueOf(value) can throw NumberFormatException for non-numeric
input; update getAsObject to validate/parse the incoming String safely (e.g.,
try/catch NumberFormatException or use a numeric check) and handle invalid input
by returning null and optionally adding a FacesMessage or logging the invalid
value before returning, then only call
controller.getEjbFacade().find(parsedLong) when parsing succeeds; ensure you
reference the getAsObject method and controller.getEjbFacade().find(...) when
implementing the fix.

147-149: Silently swallowing exception provides no feedback to user.

If the download fails, the user sees nothing. Add an error message and consider using try-with-resources for the workbook.

♻️ Proposed improvement
-    try {
-        Workbook workbook = new XSSFWorkbook();
+    try (Workbook workbook = new XSSFWorkbook()) {
         Sheet sheet = workbook.createSheet("Discharge Conditions");
         // ... rest of method ...
         context.responseComplete();
     } catch (Exception e) {
-        e.printStackTrace();
+        JsfUtil.addErrorMessage("Error generating Excel file: " + e.getMessage());
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/divudi/bean/clinical/DischargeConditionController.java`
around lines 147 - 149, The catch block in DischargeConditionController
currently swallows exceptions (catch(Exception e) { e.printStackTrace(); }) so
users get no feedback and resources may leak; replace this with
try-with-resources for the Workbook/stream creation and handle the exception by
logging the error (use your logger) and adding a user-facing error message
(e.g., FacesContext/PrimeFaces/UILayer message) so the UI informs the user of
the download failure; update the catch to log e and add the message, and ensure
any OutputStream/Workbook objects are opened in a try-with-resources block
within the method that performs the export/download.
🤖 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/clinical/DischargeConditionController.java`:
- Around line 64-77: In saveSelected(), the success messages are reversed: when
getCurrent().getId() != null the code edits the entity via
getFacade().edit(current) but calls JsfUtil.addSuccessMessage("Saved"), and the
else branch that creates the entity calls JsfUtil.addSuccessMessage("Updated");
swap these two messages so the edit branch calls
JsfUtil.addSuccessMessage("Updated") and the create branch calls
JsfUtil.addSuccessMessage("Saved") (references: saveSelected(), current,
getFacade(), JsfUtil.addSuccessMessage).
- Around line 105-116: The method completeDischargeConditions currently calls
qry.toUpperCase() which throws NPE when qry is null or may produce useless SQL
for empty strings; update completeDischargeConditions(String qry) to first check
if qry is null or blank and if so return an empty List (or set qry = "" and
search all names), otherwise proceed with m.put("n", "%" + qry.toUpperCase() +
"%"); ensure the null/blank check occurs before creating the parameter map and
building the JPQL query so getFacade().findByJpql is never called with a null
parameter.
- Around line 130-137: The row-numbering bug is caused by using post-increment
rowNum++ when creating the row and then writing rowNum into the cell (so the
first written value becomes 2); change the loop to createRow using the current
index (e.g., use sheet.createRow(rowNum) or increment after writing) and write
the display index as (rowNum) or (rowNum - 1) appropriately so the first row
shows 1; update the loop that iterates over ClinicalEntity items (the rowNum
variable and calls to sheet.createRow(...) and setCellValue(...)) to ensure
consistent indexing, and also open the Workbook (and any streams) with
try-with-resources to guarantee closure on exceptions (adjust code around
Workbook creation and any OutputStream usage accordingly).

In `@src/main/webapp/emr/admin/discharge_conditions.xhtml`:
- Around line 60-80: Replace the raw HTML <label> elements for txtName, txtCode
and txtDes with JSF/PrimeFaces label components (e.g., p:outputLabel or
h:outputLabel) so the labels bind to the JSF client IDs and improve
accessibility; locate the label currently paired with the input components
having ids txtName, txtCode and txtDes and swap each raw label for a
p:outputLabel (or h:outputLabel) using the same
for="txtName"/for="txtCode"/for="txtDes" and include an accessible tooltip/title
if required, leaving the input components and their value bindings
(#{dischargeConditionController.current.name}, .code, .descreption) unchanged.
- Around line 10-97: The page renders admin actions without view-level privilege
checks; wrap the form and destructive controls with
webUserController.hasPrivilege() checks so only authorized users see them. Add a
rendered attribute on the main h:form (or surrounding p:panel) using EL
webUserController.hasPrivilege('<appropriate-privilege>') and also add rendered
or disabled attributes to command buttons btnAdd, btnDelete, btnSave (and the
Excel download) to call webUserController.hasPrivilege(...) so the
p:commandButton elements (ids btnAdd, btnDelete, btnSave and the download
button) and the detail/select panels (gpDetail, gpSelect) are hidden/disabled
when the user lacks the privilege. Ensure you use the canonical privilege string
used elsewhere in the app when calling webUserController.hasPrivilege().

In `@src/main/webapp/inward/inward_clinical_discharge.xhtml`:
- Around line 99-105: The outputLabel and input/textarea lack explicit label-for
associations which harms accessibility; add matching id attributes to the input
components and reference them from the labels using for (e.g., set an id on the
p:inputText bound to
inpatientClinicalDataController.clinicalDischargeRecord.encounterDateTime and
change the p:outputLabel to for="<that-id>"), and do the same for the textarea
referenced in lines ~208-215 (identify the textarea bound to
inpatientClinicalDataController.clinicalDischargeRecord.<fieldName> and add id,
then update its p:outputLabel for attribute); also include an appropriate
tooltip/title on the labels if required by the coding guidelines.

---

Outside diff comments:
In `@src/main/java/com/divudi/bean/inward/RoomChangeController.java`:
- Around line 296-306: The discharge(PatientRoom pR) method currently sets
discharged flags and persists the PatientRoom but omits the room-discharge
synchronization present in dischargeWithCurrentTime(); update
discharge(PatientRoom) to also set the PatientEncounter.roomDischargeDateTime
and PatientEncounter.roomDischargedBy (the same logic found in
dischargeWithCurrentTime(), lines that update encounter's roomDischargeDateTime
and roomDischargedBy and persist via
getPatientEncounterFacade().edit(encounter)), or alternatively replace the call
site in BhtSummeryController to invoke dischargeWithCurrentTime(pR) instead so
the encounter is updated; ensure you reference and persist the PatientEncounter
via getPatientEncounterFacade() and maintain
notificationController.createNotification(pR, "Discharge").

---

Nitpick comments:
In `@src/main/java/com/divudi/bean/clinical/DischargeConditionController.java`:
- Around line 198-206: In getAsObject of DischargeConditionController, currently
Long.valueOf(value) can throw NumberFormatException for non-numeric input;
update getAsObject to validate/parse the incoming String safely (e.g., try/catch
NumberFormatException or use a numeric check) and handle invalid input by
returning null and optionally adding a FacesMessage or logging the invalid value
before returning, then only call controller.getEjbFacade().find(parsedLong) when
parsing succeeds; ensure you reference the getAsObject method and
controller.getEjbFacade().find(...) when implementing the fix.
- Around line 147-149: The catch block in DischargeConditionController currently
swallows exceptions (catch(Exception e) { e.printStackTrace(); }) so users get
no feedback and resources may leak; replace this with try-with-resources for the
Workbook/stream creation and handle the exception by logging the error (use your
logger) and adding a user-facing error message (e.g.,
FacesContext/PrimeFaces/UILayer message) so the UI informs the user of the
download failure; update the catch to log e and add the message, and ensure any
OutputStream/Workbook objects are opened in a try-with-resources block within
the method that performs the export/download.

In `@src/main/webapp/inward/admission_profile.xhtml`:
- Around line 425-432: Add an accessible tooltip/title to the Clinical Discharge
button by adding a title attribute on the p:commandButton that describes its
action (e.g., title="Navigate to Clinical Discharge"); update the element where
action="#{inpatientClinicalDataController.navigateToClinicalDischargeFromAdmission(admissionController.current)}"
and rendered="#{webUserController.hasPrivilege('InpatientClinicalDischarge')}"
so the title is present regardless of the conditional style that uses
admissionController.current.clinicallyDischarged.
🪄 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: c3152b11-37fc-41e4-98dc-915972ced80c

📥 Commits

Reviewing files that changed from the base of the PR and between 6ce1cd4 and 11cda0d.

📒 Files selected for processing (11)
  • src/main/java/com/divudi/bean/clinical/DischargeConditionController.java
  • src/main/java/com/divudi/bean/inward/BhtSummeryController.java
  • src/main/java/com/divudi/bean/inward/InpatientClinicalDataController.java
  • src/main/java/com/divudi/bean/inward/RoomChangeController.java
  • src/main/java/com/divudi/core/data/Privileges.java
  • src/main/java/com/divudi/core/data/SymanticType.java
  • src/main/java/com/divudi/core/data/inward/PatientEncounterType.java
  • src/main/java/com/divudi/core/entity/PatientEncounter.java
  • src/main/webapp/emr/admin/discharge_conditions.xhtml
  • src/main/webapp/inward/admission_profile.xhtml
  • src/main/webapp/inward/inward_clinical_discharge.xhtml

buddhika75 and others added 2 commits April 2, 2026 09:31
…e in RoomChangeController

AdmissionFacade cannot accept PatientEncounter directly; inject and use
PatientEncounterFacade for the roomDischargeDateTime sync.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Fix swapped success messages in DischargeConditionController.saveSelected()
- Add null/empty guard in completeDischargeConditions() to prevent NPE
- Fix row numbering bug in downloadAsExcel() (first row showed 2 instead of 1)
- Use try-with-resources for Workbook and show user-facing error on failure
- Wrap NumberFormatException in converter getAsObject()
- Add privilege guard (InpatientClinicalDischarge) to discharge_conditions.xhtml form
- Replace raw HTML labels with p:outputLabel in discharge_conditions.xhtml
- Add for/id associations on labels in inward_clinical_discharge.xhtml
- Add title tooltip to Clinical Discharge button in admission_profile.xhtml
- Add room discharge sync logic to discharge() in RoomChangeController
  (was only in dischargeWithCurrentTime(), leaving inconsistent state
  when discharge() is called from BhtSummeryController)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.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.

♻️ Duplicate comments (1)
src/main/webapp/inward/inward_clinical_discharge.xhtml (1)

207-217: ⚠️ Potential issue | 🟡 Minor

Add accessible label for Follow-up Plan textarea.

The txtFollowUp textarea is missing an associated p:outputLabel. While the panel header provides visual context, screen readers need an explicit label association for accessibility.

♿ Proposed fix
 <div class="col-12">
+    <p:outputLabel for="txtFollowUp" value="Follow-up Plan:" styleClass="font-weight-bold" />
     <p:inputTextarea
         id="txtFollowUp"
         value="#{inpatientClinicalDataController.clinicalDischargeRecord.followUpPlan}"

As per coding guidelines: **/*.{xhtml,java}: 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/inward/inward_clinical_discharge.xhtml` around lines 207 -
217, The txtFollowUp textarea lacks an accessible label; add a p:outputLabel
associated with id="txtFollowUp" (for="txtFollowUp") with visible text like
"Follow-up Plan" (and optional tooltip/title) immediately before the
p:inputTextarea so screen readers can associate the label with
inpatientClinicalDataController.clinicalDischargeRecord.followUpPlan; ensure the
label respects disabled state and matches styling/translation conventions used
elsewhere.
🧹 Nitpick comments (1)
src/main/java/com/divudi/bean/clinical/DischargeConditionController.java (1)

121-152: Consider buffering Excel output for atomic downloads.

The current implementation writes directly to response.getOutputStream(). If an error occurs mid-write, the client may receive a partial/corrupted file. For robustness, consider writing to a ByteArrayOutputStream first, then setting Content-Length and writing the complete bytes.

♻️ Suggested improvement
 public void downloadAsExcel() {
     getItems();
     FacesContext context = FacesContext.getCurrentInstance();
     try (Workbook workbook = new XSSFWorkbook()) {
         Sheet sheet = workbook.createSheet("Discharge Conditions");
         // ... populate sheet ...

+        // Buffer to byte array first for atomic download
+        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
+        workbook.write(baos);
+        byte[] bytes = baos.toByteArray();
+
         HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
         response.setHeader("Content-Disposition", "attachment; filename=\"discharge_conditions.xlsx\"");
-        workbook.write(response.getOutputStream());
+        response.setContentLength(bytes.length);
+        response.getOutputStream().write(bytes);
         context.responseComplete();
     } catch (Exception e) {
         JsfUtil.addErrorMessage("Error generating Excel file: " + e.getMessage());
     }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/divudi/bean/clinical/DischargeConditionController.java`
around lines 121 - 152, The downloadAsExcel method currently streams the
Workbook directly to response.getOutputStream(), risking partial/corrupt files
on errors; change it to write the workbook to a ByteArrayOutputStream first
(call workbook.write(baos)), then set response.setContentLength(baos.size()) and
response.getOutputStream().write(baos.toByteArray()), flush and close the
output, and then call context.responseComplete(); keep the existing
try-with-resources for Workbook and preserve the exception handling in the catch
block to report failures; update references in this method (downloadAsExcel,
workbook, response, context) only.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/main/webapp/inward/inward_clinical_discharge.xhtml`:
- Around line 207-217: The txtFollowUp textarea lacks an accessible label; add a
p:outputLabel associated with id="txtFollowUp" (for="txtFollowUp") with visible
text like "Follow-up Plan" (and optional tooltip/title) immediately before the
p:inputTextarea so screen readers can associate the label with
inpatientClinicalDataController.clinicalDischargeRecord.followUpPlan; ensure the
label respects disabled state and matches styling/translation conventions used
elsewhere.

---

Nitpick comments:
In `@src/main/java/com/divudi/bean/clinical/DischargeConditionController.java`:
- Around line 121-152: The downloadAsExcel method currently streams the Workbook
directly to response.getOutputStream(), risking partial/corrupt files on errors;
change it to write the workbook to a ByteArrayOutputStream first (call
workbook.write(baos)), then set response.setContentLength(baos.size()) and
response.getOutputStream().write(baos.toByteArray()), flush and close the
output, and then call context.responseComplete(); keep the existing
try-with-resources for Workbook and preserve the exception handling in the catch
block to report failures; update references in this method (downloadAsExcel,
workbook, response, context) only.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7d694104-6710-406b-9b60-55b26e96aff9

📥 Commits

Reviewing files that changed from the base of the PR and between 11cda0d and fd9a04d.

📒 Files selected for processing (5)
  • src/main/java/com/divudi/bean/clinical/DischargeConditionController.java
  • src/main/java/com/divudi/bean/inward/RoomChangeController.java
  • src/main/webapp/emr/admin/discharge_conditions.xhtml
  • src/main/webapp/inward/admission_profile.xhtml
  • src/main/webapp/inward/inward_clinical_discharge.xhtml
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/webapp/inward/admission_profile.xhtml

@buddhika75
Copy link
Copy Markdown
Member Author

Re: RoomChangeController.discharge() missing room discharge sync (outside-diff comment)

Fixed in fd9a04d — added the same roomDischargeDateTime / roomDischargedBy sync block to discharge(PatientRoom pR) that was already present in dischargeWithCurrentTime(). Both paths now update the parent PatientEncounter via patientEncounterFacade when the discharged room is the last room (nextRoom == null).

@buddhika75 buddhika75 merged commit 39b8169 into development Apr 2, 2026
3 checks passed
@buddhika75 buddhika75 deleted the 19657-three-tier-discharge-system branch April 2, 2026 23:27
buddhika75 added a commit that referenced this pull request Apr 3, 2026
…process

The InpatientClinicalDischarge privilege was added to Privileges.java in
PR #19658 but was not registered in UserPrivilageController.java, making
it invisible in the admin privilege management UI. Administrators had no
way to grant this privilege through the UI.

Changes:
- Register InpatientClinicalDischarge as a DefaultTreeNode under the
  "Clinical" branch of the Inward section in UserPrivilageController.java
- Update developer_docs/security/privilege-system.md with an explicit
  3-step checklist and warning that enum-only addition is not sufficient
- Update CLAUDE.md with a "When Adding a New Privilege" section linking
  to the privilege system guide

Closes #19677

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Three-Tier Discharge System: Clinical, Room, and Hospital Discharge

1 participant