Skip to content

fix(inward): restore discharge notification fixes, room management enhancements (Closes #21257, #21389, #21390, #21391)#21456

Merged
buddhika75 merged 6 commits into
developmentfrom
restore-discharge-notification-fixes-21389-21390-21391
Jun 13, 2026
Merged

fix(inward): restore discharge notification fixes, room management enhancements (Closes #21257, #21389, #21390, #21391)#21456
buddhika75 merged 6 commits into
developmentfrom
restore-discharge-notification-fixes-21389-21390-21391

Conversation

@buddhika75

@buddhika75 buddhika75 commented Jun 13, 2026

Copy link
Copy Markdown
Member

Summary

Discharge Button Fix (#21257)

  • Fixed unresponsive "Discharge from Room" and "Cancel Room Discharge" buttons on inward_patient_room_details.xhtml by switching from ajax="false" to AJAX mode with process="@this" and update="@form"
  • Fixed patientRoom vs pR bug in RoomChangeController.dischargeWithCurrentTime() where indexOf used the List field instead of the method parameter
  • Added rendered toggle between Discharge and Cancel buttons based on room discharge state
  • Added JS confirmation dialogs (p:confirm) for discharge and cancel actions
  • Fixed cancel to properly clear dischargedAt field

Dashboard Room Listing

  • Added active room listing on admission_profile.xhtml Room Management panel showing current PatientRoom/GuardianRoom assignments with admitted time and View link
  • Added getActivePatientRooms() method to AdmissionController

Room Discharge Receipt

  • New inward_room_discharge_receipt.xhtml page with Print, Print Previous, and Inpatient Dashboard navigation

Privileges, Audit Logging & Notifications

  • Added privilege checks to all Room Management buttons (InwardRoomRoomChange, InwardRoomGurdianRoomChange, InwardRoomRoomOccupency)
  • Added "Add New Room" and "Add Guardian Room" buttons to dashboard
  • Added audit event logging to all room operations: admit, add, change, guardian change, discharge, discharge cancel, remove
  • New notification trigger types (INWARD_PATIENT_ROOM_ADDED, INWARD_PATIENT_ROOM_CHANGED) with System/SMS/Email variants
  • Extended NotificationController with notification methods for room admit, room change, and discharge cancel

Notification Fixes (#21389, #21390, #21391)

  • Previous commits on this branch already fixed: real-time push, navigation on click, filter functionality, delete/recycle bin, and timezone handling for discharge notifications

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Current room assignments shown on admission profile with facility, admit timestamp, guardian badge, and quick view.
    • New Room Discharge Receipt page with formatted receipt, print controls, and auto-print support.
  • Improvements

    • Notifications and audit logging for admissions, room changes, removals, discharges, and discharge cancellations.
    • UI/UX: privilege-gated room actions, confirmation dialogs, improved AJAX behavior for room actions, and more reliable print handling.
  • Chores

    • Updated persistence datasource configuration.

buddhika75 and others added 2 commits June 13, 2026 12:12
…pt, and audit logging (Closes #21257)

- Fix unresponsive Discharge/Cancel buttons on inward_patient_room_details.xhtml by switching from ajax=false to AJAX with process="@this" update="@Form"
- Fix patientRoom vs pR bug in RoomChangeController.dischargeWithCurrentTime() where indexOf used the List field instead of the method parameter
- Add rendered toggle between Discharge and Cancel buttons based on room discharge state
- Add success/error messages after discharge and cancel actions
- Add current room listing to admission_profile.xhtml Room Management panel showing active PatientRoom/GuardianRoom with admitted time and View link
- Add inward_room_discharge_receipt.xhtml receipt page with Print, Print Previous, and Inpatient Dashboard navigation
- Add JS confirmation dialogs (p:confirm) for discharge and cancel actions
- Add audit event logging (AuditEvent) for room discharge and cancel via AuditEventApplicationController
- Fix cancel to properly clear dischargedAt field

Co-Authored-By: Claude <noreply@anthropic.com>
…anagement actions (Closes #21257)

- Add privilege checks to all Room Management buttons on admission_profile.xhtml (InwardRoomRoomChange, InwardRoomGurdianRoomChange, InwardRoomRoomOccupency)
- Add new "Add New Room" and "Add Guardian Room" buttons to dashboard
- Add audit event logging (AuditEvent) to all room operations: admitRoom, change, addNewRoom, changeGurdianRoom, discharge, remove, removeRoom, removeGuardianRoom
- Add notification support for room admit, room change, and discharge cancel via new trigger types INWARD_PATIENT_ROOM_ADDED and INWARD_PATIENT_ROOM_CHANGED
- Extend NotificationController with createInwardRoomAdmitNotifications, createInwardRoomChangeNotifications, createInwardRoomDischargeCancelNotifications

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@buddhika75, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 15 minutes and 57 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 10ffb6ab-e4d6-44b8-9c13-b4b6b6d0ebd3

📥 Commits

Reviewing files that changed from the base of the PR and between ab55314 and fc0bc17.

📒 Files selected for processing (1)
  • src/main/java/com/divudi/bean/inward/AdmissionController.java

Walkthrough

This PR extends inward admission workflows with event tracking and discharge receipt functionality. It adds trigger types and notification handlers for room operations, integrates audit event logging into room management workflows, provides an API to query active room assignments, and adds UI to display current rooms in admission profiles and a standalone discharge receipt page.

Changes

Room Event Notifications, Audit Logging, and Discharge Receipt

Layer / File(s) Summary
Notification Trigger Type Enums
src/main/java/com/divudi/core/data/TriggerType.java, src/main/java/com/divudi/core/data/TriggerTypeParent.java
TriggerType and TriggerTypeParent enums are extended with INWARD_PATIENT_ROOM_ADDED and INWARD_PATIENT_ROOM_CHANGED constants (each with system notification, SMS, and email variants).
Notification Creation for Room Events
src/main/java/com/divudi/bean/common/NotificationController.java
createNotification now dispatches "Admit", "Change", and "CancelDischarge" actions to new private helpers that generate contextual notifications: admit messages include patient name, change messages include room and BHT context, cancel messages indicate discharge cancellation. Each notification is persisted and mirrored to users.
Active Room Query API
src/main/java/com/divudi/bean/inward/AdmissionController.java
New public method getActivePatientRooms() returns non-retired, non-discharged patient rooms for the current admission via JPQL, ordered by creation time.
Audit Event Recording Infrastructure
src/main/java/com/divudi/bean/inward/RoomChangeController.java
RoomChangeController injects AuditEventApplicationController and introduces centralized recordRoomAuditEvent(PatientRoom, String, String) helper that creates audit records with trigger type, entity info, contextual URL, and optional before/after state.
Discharge Receipt State and Navigation
src/main/java/com/divudi/bean/inward/RoomChangeController.java
Adds roomForReceipt field and public getter/setter to hold discharge record; introduces navigateToRoomDischargeReceipt(PatientRoom) to route to receipt page.
Room Workflows Integrated with Audit and Notifications
src/main/java/com/divudi/bean/inward/RoomChangeController.java
Integrates audit event logging and notification creation across room admission, removal, discharge, cancellation, and guardian room operations; captures before-state context (facility charge, admitted time, discharged flag) for audit trails; adjusts index lookup in dischargeWithCurrentTime to use the passed PatientRoom instance; each workflow now logs audit event, creates notification, and displays success message.
Admission Profile and Room Details UI Updates
src/main/webapp/inward/admission_profile.xhtml, src/main/webapp/inward/inward_patient_room_details.xhtml
Adds "Current Room Assignments" section to admission profile displaying active rooms with facility name, optional "Guardian" badge, admitted timestamp, and "View" button; gates "Room Change" and "Guardian Room Change" buttons by InwardRoomRoomChange and InwardRoomGurdianRoomChange privileges respectively. In room details, updates "Save Changes", "Discharge from Room", "Cancel Room Discharge", and "Remove Room" buttons with conditional rendering, AJAX partial updates, and confirmation dialogs.
Discharge Receipt Page
src/main/webapp/inward/inward_room_discharge_receipt.xhtml
New XHTML page that conditionally displays a formatted discharge receipt (institution, patient info, room details with guardian badge, discharge timestamps, discharged-by, printed timestamp, footer) or an error message when no record is selected; includes print/print-previous/dashboard navigation buttons, auto-print-on-load script, and print-specific CSS.
Persistence Unit DataSource Update
src/main/resources/META-INF/persistence.xml
Replaces ${JDBC_DATASOURCE}/${JDBC_AUDIT_DATASOURCE} placeholders with concrete JNDI names jdbc/coop and jdbc/ruhunuAudit for hmisPU and hmisAuditPU respectively.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • hmislk/hmis#21260: Adds removeRoom(PatientRoom) method and wires the "Remove Room" UI behavior that the main PR updates with audit logging and notifications.
  • hmislk/hmis#21454: Updates UserNotificationController and discharge-notification filters in the UI to consume the room discharge notifications that this PR creates in NotificationController.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.17% 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 summarizes the main changes: discharge notification fixes and room management enhancements including dashboard improvements, audit logging, and privilege checks across multiple related issues.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch restore-discharge-notification-fixes-21389-21390-21391

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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 7

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/com/divudi/bean/inward/AdmissionController.java`:
- Around line 785-787: In getActivePatientRooms in AdmissionController, stop
swallowing all Exceptions: log the caught Exception with full details (e.g.,
using the class logger or a Logger instance) and surface a recoverable error
signal instead of returning an empty list — either rethrow a checked or
unchecked application-level exception (or return an Optional/Result wrapper) so
callers can detect the failure; if no logger exists, add a private static final
Logger and use logger.error("Failed to fetch active patient rooms", e) before
throwing or returning the error result.

In `@src/main/java/com/divudi/bean/inward/RoomChangeController.java`:
- Around line 420-425: The code currently calls
auditEventApplicationController.logAuditEvent(auditEvent) twice which enqueues
the same AuditEvent twice; remove the first logAuditEvent call and instead set
the final state on the AuditEvent (call auditEvent.setEventStatus("Completed")
and auditEvent.setEventDuration(new Date().getTime() -
auditEvent.getEventDataTime().getTime())) before invoking
auditEventApplicationController.logAuditEvent(auditEvent) once so only the
completed event is enqueued.

In `@src/main/webapp/inward/admission_profile.xhtml`:
- Around line 541-547: Add stable id attributes to each actionable
p:commandButton in the room-management UI so JSF and automation hooks can
reliably target them; specifically, add an id to the p:commandButton that
invokes admissionController.navigateToPatientRoomDetails() (e.g.,
id="viewPatientRoomDetailsBtn") and likewise add clear, unique ids to the other
actionable buttons in the same fragment (the buttons in the other mentioned
ranges) using descriptive names (e.g., id="editRoomBtn", id="assignRoomBtn",
id="manageRoomBtn") so each button has a stable, semantic id attribute.
- Around line 536-538: The f:convertDateTime used to render #{room.admittedAt}
should pin the timezone to Asia/Colombo to prevent JVM/server timezone drift;
update the <f:convertDateTime> element (the converter attached to the
h:outputText for #{room.admittedAt}) to include timeZone="Asia/Colombo" (e.g.,
<f:convertDateTime pattern="dd MMM yyyy HH:mm" timeZone="Asia/Colombo"/>).

In `@src/main/webapp/inward/inward_room_discharge_receipt.xhtml`:
- Around line 52-58: The "Print Previous" p:commandButton is currently wired to
onclick="printReceipt()", duplicating the main Print action; either implement
the intended previous-receipt behavior by changing the onclick to a new handler
(e.g., onclick="printPreviousReceipt()") and add/implement the JavaScript
function printPreviousReceipt() to fetch and render the prior receipt, or if
you’re not implementing retrieval now, rename the button label (value="Print
Previous") to a non-misleading name like "Print Copy" (and update any
tooltip/title) so its behavior matches the existing printReceipt() handler;
update only the p:commandButton's value/onclick (and add the new JS function if
choosing the first option).
- Line 103: Add the timeZone attribute to each f:convertDateTime usage so
timestamps are rendered in Asia/Colombo; specifically update every
<f:convertDateTime pattern="dd MMM yyyy HH:mm"/> occurrence to include
timeZone="Asia/Colombo" (i.e., <f:convertDateTime pattern="dd MMM yyyy HH:mm"
timeZone="Asia/Colombo"/>), ensuring all f:convertDateTime tags in the inward
room discharge receipt are changed consistently.
- Around line 10-19: Move the print helper into the page composition head so the
function is defined inside the template-provided <h:head>: relocate the existing
printReceipt() script block from outside the <ui:composition> into the
composition's head section (so onclick handlers can find printReceipt()), add
timeZone="Asia/Colombo" to every f:convertDateTime used for Admission Date,
Admitted At, Discharged At and Printed At (i.e., update each f:convertDateTime
tag to include timeZone="Asia/Colombo"), and fix the Print Previous button so it
no longer calls the same onclick as Print — either change its onclick to a
distinct handler that loads/prints the previous receipt or remove/rename the
button if that feature is not implemented (update the button's onclick attribute
accordingly); ensure references to the print helper use the printReceipt() name
consistently.
🪄 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: 1888309b-c48c-4965-8656-1b42c7323b3c

📥 Commits

Reviewing files that changed from the base of the PR and between 2039806 and 3b48766.

📒 Files selected for processing (8)
  • src/main/java/com/divudi/bean/common/NotificationController.java
  • src/main/java/com/divudi/bean/inward/AdmissionController.java
  • src/main/java/com/divudi/bean/inward/RoomChangeController.java
  • src/main/java/com/divudi/core/data/TriggerType.java
  • src/main/java/com/divudi/core/data/TriggerTypeParent.java
  • src/main/webapp/inward/admission_profile.xhtml
  • src/main/webapp/inward/inward_patient_room_details.xhtml
  • src/main/webapp/inward/inward_room_discharge_receipt.xhtml

Comment thread src/main/java/com/divudi/bean/inward/AdmissionController.java
Comment thread src/main/java/com/divudi/bean/inward/RoomChangeController.java Outdated
Comment thread src/main/webapp/inward/admission_profile.xhtml
Comment thread src/main/webapp/inward/admission_profile.xhtml
Comment thread src/main/webapp/inward/inward_room_discharge_receipt.xhtml Outdated
Comment thread src/main/webapp/inward/inward_room_discharge_receipt.xhtml
Comment thread src/main/webapp/inward/inward_room_discharge_receipt.xhtml Outdated
…ceipt page

- Replace non-existent nameWithInitials with name() on WebUser
- Replace non-existent Person.nameOfAgeAndGender with Person.ageAsString
- Remove broken #{now} EL expression, use loggedUser.name for printed-by
- Remove redundant footer printed-by line

Co-Authored-By: Claude <noreply@anthropic.com>
@buddhika75

Copy link
Copy Markdown
Member Author

Self-review fixes pushed (3f96c88)

Fixed three runtime errors in the receipt page inward_room_discharge_receipt.xhtml:

  1. WebUser.nameWithInitialsWebUser.nameWebUser has getName() (returns String) and getWebUserPerson().getNameWithInitials(). The shorter name property is used directly. Applied to both dischargedBy and loggedUser references.

  2. Person.nameOfAgeAndGenderPerson.ageAsString — The nameOfAgeAndGender method does not exist on Person. Fixed to use the correct ageAsString property (matching the pattern used in admission_profile.xhtml).

  3. Removed #{now} EL expression — The implicit #{now} object availability depends on JSF version. Replaced the "Printed At / Printed By" dual-column layout with a single "Discharged By / Printed By" row that references only concrete controller properties.

No other issues found in review — the TriggerType enum additions preserve ordinal values, all audit paths null-guard appropriately, and privilege names match the existing Privileges enum values.

…ement, timezone, button IDs

- Fix duplicate audit event logging: set status/duration before single logAuditEvent call
- Remove h:head script block outside ui:composition (would not render); inline window.print()
- Add timeZone="Asia/Colombo" to all f:convertDateTime in receipt page and dashboard
- Rename "Print Previous" to "Print Copy" since previous retrieval not implemented
- Add stable id attributes to room-management buttons (btnAddNewRoom, btnAddGuardianRoom, btnRoomDetails, btnRoomChange, btnGuardianRoomChange)
- Add JsfUtil error message for failed active room query instead of silent swallow

Co-Authored-By: Claude <noreply@anthropic.com>
@buddhika75

Copy link
Copy Markdown
Member Author

CodeRabbit review fixes applied (ab55314)

All six findings addressed:

  1. Duplicate audit event logging ✅ Fixed — recordRoomAuditEvent now sets eventStatus="Completed" and eventDuration before a single logAuditEvent() call, matching the pattern in SearchController.

  2. Script outside <ui:composition> ✅ Fixed — Removed the <h:head> block (not rendered in Facelets composition). Replaced onclick="printReceipt()" with inline onclick="window.print();" on Print/Print Copy buttons. Auto-print script already used window.print() directly so unaffected.

  3. Missing timeZone="Asia/Colombo" ✅ Fixed — Added to all 4 f:convertDateTime converters in the receipt page (Admission Date, Admitted At, Discharged At) and the admittedAt converter in admission_profile.xhtml.

  4. "Print Previous" duplicates Print ✅ Acknowledged — Renamed to "Print Copy" since previous-receipt retrieval is not in scope for this PR. Both buttons now use window.print() directly.

  5. Button id attributes ✅ Fixed — Added stable ids to static buttons: btnAddNewRoom, btnAddGuardianRoom, btnRoomDetails, btnRoomChange, btnGuardianRoomChange. The "View" button inside <ui:repeat> cannot have a static id (would duplicate in DOM).

  6. Swallowed exception in getActivePatientRooms() ✅ Fixed — Added JsfUtil.addErrorMessage("Unable to load current room assignments.") on query failure instead of silent return.

buddhika75 and others added 2 commits June 13, 2026 15:29
…ry failure

- Use existing logger with Level.SEVERE and admission ID context
- Surface recoverable error via JsfUtil.addErrorMessage instead of silent return

Co-Authored-By: Claude <noreply@anthropic.com>
…tion

Co-Authored-By: Claude <noreply@anthropic.com>
@buddhika75 buddhika75 merged commit d91ff7c into development Jun 13, 2026
3 checks passed
@buddhika75 buddhika75 deleted the restore-discharge-notification-fixes-21389-21390-21391 branch June 13, 2026 10:03
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.

1 participant