diff --git a/src/main/java/com/divudi/bean/common/NotificationController.java b/src/main/java/com/divudi/bean/common/NotificationController.java index 62d6eab775..69cbe025cd 100644 --- a/src/main/java/com/divudi/bean/common/NotificationController.java +++ b/src/main/java/com/divudi/bean/common/NotificationController.java @@ -157,7 +157,8 @@ private void createInwardRoomDischargeNotifications(PatientRoom pr) { nn.setPatientRoom(pr); nn.setTriggerType(tt); nn.setCreater(sessionController.getLoggedUser()); - String msg = "You Have a Discharge Notification From " + pr.getRoomFacilityCharge().getName(); + String roomName = pr.getRoomFacilityCharge() != null ? pr.getRoomFacilityCharge().getName() : "Unknown Room"; + String msg = "You Have a Discharge Notification From " + roomName; nn.setMessage(msg); getFacade().create(nn); userNotificationController.createUserNotifications(nn); diff --git a/src/main/java/com/divudi/bean/common/UserNotificationController.java b/src/main/java/com/divudi/bean/common/UserNotificationController.java index 947a2b500d..74f2dcd2c0 100644 --- a/src/main/java/com/divudi/bean/common/UserNotificationController.java +++ b/src/main/java/com/divudi/bean/common/UserNotificationController.java @@ -20,6 +20,8 @@ import com.divudi.core.entity.Department; import com.divudi.core.entity.UserNotification; import com.divudi.core.entity.Notification; +import com.divudi.bean.inward.BhtSummeryController; +import com.divudi.core.entity.inward.PatientRoom; import com.divudi.core.entity.PatientEncounter; import com.divudi.core.entity.Sms; import com.divudi.core.entity.WebUser; @@ -30,7 +32,6 @@ import java.io.Serializable; import java.util.Date; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import javax.ejb.EJB; @@ -82,18 +83,30 @@ public class UserNotificationController implements Serializable { SmsManagerEjb smsManager; @Inject NotificationPushService notificationPushService; + @Inject + BhtSummeryController bhtSummeryController; private Date date; + // Notification list filters private boolean todayNotification; - private boolean seenedNotifiaction; - private boolean completedNotification; - private boolean notCompeletedNotifiaction; + private String seenFilter = "ALL"; // ALL | SEEN | UNSEEN + private String completionFilter = "ALL"; // ALL | COMPLETED | PENDING private boolean canceldRequests; + private boolean showCleared; // list previously cleared (retired) notifications for restoring public String navigateToRecivedNotification() { + resetFilters(); fillLoggedUserNotifications(); return "/Notification/user_notifications?faces-redirect=true"; } + public void resetFilters() { + todayNotification = false; + canceldRequests = false; + showCleared = false; + seenFilter = "ALL"; + completionFilter = "ALL"; + } + public int getUnseenCount() { if (sessionController == null || sessionController.getLoggedUser() == null) { return 0; @@ -119,153 +132,103 @@ public String navigateToSentNotification() { return "/Notification/sent_notifications"; } + /** + * Retires (clears) every notification currently listed. The user filters + * first, then clears, so what is removed is exactly what is on screen. + * Cleared notifications remain in the database and can be viewed and + * restored through the "Show Cleared" filter. + */ public void clearNotificationsByCriteria() { - if (seenedNotifiaction) { - if (items == null) { - return; - } - for (UserNotification un : items) { - if (un.isSeen()) { - un.setRetired(true); - un.setRetiredAt(new Date()); - getFacade().edit(un); - } - } - fillLoggedUserNotifications(); + if (showCleared) { + JsfUtil.addErrorMessage("These notifications are already cleared. Use Restore to bring one back."); + return; } - - if (completedNotification) { - if (items == null) { - return; - } - for (UserNotification un : items) { - if (un.getNotification().isCompleted()) { - un.setRetired(true); - un.setRetiredAt(new Date()); - getFacade().edit(un); - } - } - fillLoggedUserNotifications(); + if (items == null || items.isEmpty()) { + JsfUtil.addErrorMessage("No notifications listed to clear"); + return; } - - if (canceldRequests) { - if (items == null) { - return; - } - for (UserNotification un : items) { - if (un.getNotification().getBill().isCancelled()) { - un.setRetired(true); - un.setRetiredAt(new Date()); - getFacade().edit(un); - } - } - fillLoggedUserNotifications(); + int clearedCount = 0; + for (UserNotification un : items) { + un.setRetired(true); + un.setRetiredAt(new Date()); + un.setRetirer(sessionController.getLoggedUser()); + getFacade().edit(un); + clearedCount++; } + JsfUtil.addSuccessMessage(clearedCount + " notification(s) cleared"); + filterNotificationsByCriteria(); + } - if (notCompeletedNotifiaction) { - if (items == null) { - return; - } - for (UserNotification un : items) { - if (!un.getNotification().isCompleted()) { - un.setRetired(true); - un.setRetiredAt(new Date()); - getFacade().edit(un); - } - } - fillLoggedUserNotifications(); - + /** + * Brings back a previously cleared (retired) notification so it appears + * in the normal list again. + */ + public void restoreUserNotification(UserNotification un) { + if (un == null || un.getId() == null) { + JsfUtil.addErrorMessage("Nothing to restore !"); + return; } - + un.setRetired(false); + un.setRetiredAt(null); + un.setRetirer(null); + un.setRetireComments(null); + getFacade().edit(un); + JsfUtil.addSuccessMessage("Notification restored"); + filterNotificationsByCriteria(); } + /** + * Reloads the notification list from the database applying the selected + * filter criteria. Always queries fresh so changing or removing criteria + * works as expected. + */ public void filterNotificationsByCriteria() { - if (seenedNotifiaction) { - if (items == null) { - return; - } - Iterator iterator = items.iterator(); - while (iterator.hasNext()) { - UserNotification notification = iterator.next(); - if (notification.getNotification() == null) { - continue; - } - - if (!notification.isSeen()) { - iterator.remove(); - } - } - } - - if (completedNotification) { - if (items == null) { - return; - } - - Iterator iterator = items.iterator(); - while (iterator.hasNext()) { - UserNotification notification = iterator.next(); - if (notification.getNotification() == null) { - continue; - } - - if (!notification.getNotification().isCompleted()) { - iterator.remove(); - } - } - + if (sessionController == null || sessionController.getLoggedUser() == null) { + items = null; + return; } + StringBuilder jpql = new StringBuilder("select un " + + " from UserNotification un " + + " where un.webUser=:wu " + + " and un.retired=:ret "); + Map m = new HashMap<>(); + m.put("wu", sessionController.getLoggedUser()); + m.put("ret", showCleared); if (todayNotification) { - if (items == null) { - return; - } - Iterator iterator = items.iterator(); - while (iterator.hasNext()) { - UserNotification notification = iterator.next(); - if (notification.getNotification() == null) { - continue; - } - - if (!notification.getNotification().getCreatedAt().equals(getDate())) { - iterator.remove(); - } - } + java.util.Calendar todayCal = java.util.Calendar.getInstance(); + todayCal.set(java.util.Calendar.HOUR_OF_DAY, 0); + todayCal.set(java.util.Calendar.MINUTE, 0); + todayCal.set(java.util.Calendar.SECOND, 0); + todayCal.set(java.util.Calendar.MILLISECOND, 0); + jpql.append(" and un.notification.createdAt >= :fromDate "); + m.put("fromDate", todayCal.getTime()); + } + + if ("SEEN".equals(seenFilter)) { + jpql.append(" and un.seen=:seen "); + m.put("seen", true); + } else if ("UNSEEN".equals(seenFilter)) { + jpql.append(" and un.seen=:seen "); + m.put("seen", false); } - if (notCompeletedNotifiaction) { - if (items == null) { - return; - } - Iterator iterator = items.iterator(); - while (iterator.hasNext()) { - UserNotification notification = iterator.next(); - if (notification.getNotification() == null) { - continue; - } - - if (notification.getNotification().isCompleted()) { - iterator.remove(); - } - } + if ("COMPLETED".equals(completionFilter)) { + jpql.append(" and un.notification.completed=:com "); + m.put("com", true); + } else if ("PENDING".equals(completionFilter)) { + jpql.append(" and un.notification.completed=:com "); + m.put("com", false); } if (canceldRequests) { - if (items == null) { - return; - } - Iterator iterator = items.iterator(); - while (iterator.hasNext()) { - UserNotification notification = iterator.next(); - if (notification.getNotification() == null) { - continue; - } - - if (!notification.getNotification().getBill().isCancelled()) { - iterator.remove(); - } - } + jpql.append(" and un.notification.bill is not null " + + " and un.notification.bill.cancelled=:can "); + m.put("can", true); } + + jpql.append(" order by un.id desc"); + items = getFacade().findByJpql(jpql.toString(), m, 100); } public void save(UserNotification userNotification) { @@ -318,6 +281,10 @@ public void userNotificationRequestComplete() { } public void removeUserNotification(UserNotification un) { + if (un == null || un.getNotification() == null) { + JsfUtil.addErrorMessage("Nothing to remove !"); + return; + } Department todept = null; Notification n = un.getNotification(); if (n.getBill() != null) { @@ -339,21 +306,24 @@ public void removeUserNotification(UserNotification un) { break; } } else if (n.getPatientRoom() != null) { - todept = n.getPatientRoom().getRoomFacilityCharge().getDepartment(); - } else { + if (n.getPatientRoom().getRoomFacilityCharge() != null) { + todept = n.getPatientRoom().getRoomFacilityCharge().getDepartment(); + } + } else if (n.getPatientEncounter() == null) { + // Not a bill, room or encounter based notification - nothing we know how to remove return; } - - if (!todept.equals(sessionController.getLoggedUser().getDepartment())) { + // PatientEncounter-based (clinical/final discharge) notifications have no + // owning department; the notification already belongs to the logged user. + if (todept != null && !todept.equals(sessionController.getLoggedUser().getDepartment())) { JsfUtil.addErrorMessage("You can't Access On Current Department !"); return; } - if (un.getNotification().getBill() == null) { - return; - } un.setRetired(true); + un.setRetiredAt(new Date()); + un.setRetirer(sessionController.getLoggedUser()); getFacade().edit(un); - fillLoggedUserNotifications(); + filterNotificationsByCriteria(); } private UserNotificationFacade getEjbFacade() { @@ -413,9 +383,33 @@ public void onPushRefreshNotifications() { } public String navigateToCurrentNotificationRequest(UserNotification un) { + if (un == null || un.getNotification() == null) { + JsfUtil.addErrorMessage("Invalid notification"); + return ""; + } un.setSeen(true); + un.setRetired(true); + un.setRetiredAt(new Date()); + un.setRetirer(sessionController.getLoggedUser()); + un.setRetireComments("Viewed"); getFacade().edit(un); + // Handle PatientRoom-based (discharge) notifications + if (un.getNotification().getPatientRoom() != null) { + PatientRoom pr = un.getNotification().getPatientRoom(); + if (pr.getPatientEncounter() != null) { + bhtSummeryController.setPatientEncounter(pr.getPatientEncounter()); + return bhtSummeryController.navigateToInpatientProfile(); + } + return ""; + } + + // Handle PatientEncounter-based notifications + if (un.getNotification().getPatientEncounter() != null) { + bhtSummeryController.setPatientEncounter(un.getNotification().getPatientEncounter()); + return bhtSummeryController.navigateToInpatientProfile(); + } + if (un.getNotification().getBill() == null) { return ""; } @@ -444,9 +438,6 @@ public String navigateToCurrentNotificationRequest(UserNotification un) { JsfUtil.addErrorMessage("You can't Access On Current Department !"); return ""; } - if (un.getNotification().getBill() == null) { - return ""; - } Bill bill = un.getNotification().getBill(); BillTypeAtomic type = bill.getBillTypeAtomic(); switch (type) { @@ -660,28 +651,28 @@ public void setTodayNotification(boolean todayNotification) { this.todayNotification = todayNotification; } - public boolean isSeenedNotifiaction() { - return seenedNotifiaction; + public String getSeenFilter() { + return seenFilter; } - public void setSeenedNotifiaction(boolean seenedNotifiaction) { - this.seenedNotifiaction = seenedNotifiaction; + public void setSeenFilter(String seenFilter) { + this.seenFilter = seenFilter; } - public boolean isCompletedNotification() { - return completedNotification; + public String getCompletionFilter() { + return completionFilter; } - public void setCompletedNotification(boolean completedNotification) { - this.completedNotification = completedNotification; + public void setCompletionFilter(String completionFilter) { + this.completionFilter = completionFilter; } - public boolean isNotCompeletedNotifiaction() { - return notCompeletedNotifiaction; + public boolean isShowCleared() { + return showCleared; } - public void setNotCompeletedNotifiaction(boolean notCompeletedNotifiaction) { - this.notCompeletedNotifiaction = notCompeletedNotifiaction; + public void setShowCleared(boolean showCleared) { + this.showCleared = showCleared; } public Date getDate() { diff --git a/src/main/webapp/Notification/user_notifications.xhtml b/src/main/webapp/Notification/user_notifications.xhtml index f6be7656ec..caa71c3b5e 100644 --- a/src/main/webapp/Notification/user_notifications.xhtml +++ b/src/main/webapp/Notification/user_notifications.xhtml @@ -4,11 +4,25 @@ xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:p="http://primefaces.org/ui" xmlns:h="http://xmlns.jcp.org/jsf/html" - xmlns:f="http://xmlns.jcp.org/jsf/core"> + xmlns:f="http://xmlns.jcp.org/jsf/core" + xmlns:o="http://omnifaces.org/ui"> + + + + @@ -23,12 +37,15 @@ -

Are you sure you want to clear the selected notifications?

+

This will remove ALL notifications currently listed below. + To clear only some, filter the list first. Continue?

- - +
@@ -37,11 +54,33 @@
- Today : - Seen : - Completed : - Not Completed : - Canceled : + + + + + + + + + + + + + + + + + + + + + + -
@@ -108,6 +148,27 @@ + + +
+
+ +
Room Discharge
+
#{un.notification.patientRoom.roomFacilityCharge.name}
+
+
+
+ + +
+
+ +
Patient Discharge
+
#{un.notification.patientEncounter.bhtNo}
+
+
+
+
@@ -122,7 +183,7 @@ style="border-left:1px solid black;border-right:1px solid black;"> - +
@@ -135,9 +196,16 @@ + +