diff --git a/src/main/java/com/divudi/bean/common/NotificationController.java b/src/main/java/com/divudi/bean/common/NotificationController.java index 270ce7956e..d5959316bc 100644 --- a/src/main/java/com/divudi/bean/common/NotificationController.java +++ b/src/main/java/com/divudi/bean/common/NotificationController.java @@ -11,6 +11,7 @@ import com.divudi.bean.common.util.JsfUtil; import com.divudi.data.BillTypeAtomic; import static com.divudi.data.BillTypeAtomic.PHARMACY_TRANSFER_REQUEST; +import com.divudi.data.OptionScope; import com.divudi.data.TriggerType; import com.divudi.data.TriggerTypeParent; import com.divudi.entity.AppEmail; @@ -53,6 +54,8 @@ public class NotificationController implements Serializable { SecurityController securityController; @Inject CommonController commonController; + @Inject + ConfigOptionController configOptionController; @EJB private NotificationFacade ejbFacade; private Notification current; @@ -102,6 +105,9 @@ public void createNotification(Bill bill) { case OPD_BILL_CANCELLATION_DURING_BATCH_BILL_CANCELLATION: //No Notification is necessary break; + case PHARMACY_DIRECT_ISSUE: + createPharmacyDirectIssueNotifications(bill); + break; default: throw new AssertionError(); } @@ -115,12 +121,59 @@ private void createPharmacyTransferRequestNotifications(Bill bill) { nn.setBill(bill); nn.setTriggerType(tt); nn.setCreater(sessionController.getLoggedUser()); - nn.setMessage("New Request for Medicines from "); + nn.setMessage(createTemplateForNotificationMessage(bill.getBillTypeAtomic())); + getFacade().create(nn); + userNotificationController.createUserNotifications(nn); + } + } + + private void createPharmacyDirectIssueNotifications(Bill bill) { + Date date = new Date(); + for (TriggerType tt : TriggerType.getTriggersByParent(TriggerTypeParent.TRANSFER_ISSUE)) { + Notification nn = new Notification(); + nn.setCreatedAt(date); + nn.setBill(bill); + nn.setTriggerType(tt); + nn.setCreater(sessionController.getLoggedUser()); + nn.setMessage(createTemplateForNotificationMessage(bill.getBillTypeAtomic())); getFacade().create(nn); userNotificationController.createUserNotifications(nn); } } + private String createTemplateForNotificationMessage(BillTypeAtomic bt) { + String message = null; + if (bt == null) { + return null; + } + + if (bt == BillTypeAtomic.PHARMACY_TRANSFER_REQUEST) { + message = configOptionController.getLongTextValueByKey("Message Template for Pharmacy Transfer Request Notification", OptionScope.APPLICATION, null, null, null); + } + + if (bt == BillTypeAtomic.PHARMACY_ORDER) { + message = configOptionController.getLongTextValueByKey("Message Template for Pharmacy Order Request Notification", OptionScope.APPLICATION, null, null, null); + } + + if (bt == BillTypeAtomic.OPD_BILL_CANCELLATION) { + message = configOptionController.getLongTextValueByKey("Message Template for OPD Bill Cancellation Notification", OptionScope.APPLICATION, null, null, null); + } + + if (bt == BillTypeAtomic.OPD_BATCH_BILL_CANCELLATION) { + message = configOptionController.getLongTextValueByKey("Message Template for OPD Batch Bill Notification", OptionScope.APPLICATION, null, null, null); + } + + if (bt == BillTypeAtomic.OPD_BILL_CANCELLATION_DURING_BATCH_BILL_CANCELLATION) { + message = configOptionController.getLongTextValueByKey("Message Template for OPD Bill Cancellation During Batch Bill Cancellation Notification", OptionScope.APPLICATION, null, null, null); + } + + if (message == null || message == "" || message.isEmpty()) { + message = "New Request from "; + } + + return message; + } + private void createOpdBillCancellationNotification(Bill bill) { String messageBody = ""; @@ -280,7 +333,7 @@ private void createPharmacyReuestForInpatients(Bill bill) { nn.setBill(bill); nn.setTriggerType(tt); nn.setCreater(sessionController.getLoggedUser()); - nn.setMessage("New Request for Medicines for inpatient "); + nn.setMessage(createTemplateForNotificationMessage(bill.getBillTypeAtomic())); getFacade().create(nn); userNotificationController.createUserNotifications(nn); } diff --git a/src/main/java/com/divudi/bean/common/TriggerSubscriptionController.java b/src/main/java/com/divudi/bean/common/TriggerSubscriptionController.java index f7bc950a49..f984f4157a 100644 --- a/src/main/java/com/divudi/bean/common/TriggerSubscriptionController.java +++ b/src/main/java/com/divudi/bean/common/TriggerSubscriptionController.java @@ -49,6 +49,25 @@ public class TriggerSubscriptionController implements Serializable { private List departments; private WebUser user; + public List fillSubscribedUsersByDepartment(TriggerType tt,Department dept) { + List us = new ArrayList<>(); + if (tt == null) { + return us; + } + Map m = new HashMap(); + String jpql = "SELECT i.webUser " + + " FROM TriggerSubscription i " + + " where i.triggerType=:tt " + + " and i.retired=:ret " + + " and i.department=:dep"; + + m.put("tt", tt); + m.put("ret", false); + m.put("dep", dept); + us = webUserFacade.findByJpql(jpql, m); + return us; + } + public void addUserSubscription() { if (triggerType == null) { JsfUtil.addErrorMessage("Select Subscription"); @@ -116,7 +135,7 @@ public List fillWebUsers(TriggerType tt) { m.put("tt", tt); m.put("ret", false); - us= webUserFacade.findByJpql(jpql, m); + us = webUserFacade.findByJpql(jpql, m); return us; } @@ -322,7 +341,6 @@ public List getTriggerTypes() { return triggerTypes; } - @FacesConverter(forClass = TriggerSubscription.class) public static class UserSubscriptionConverter implements Converter { diff --git a/src/main/java/com/divudi/bean/common/UserNotificationController.java b/src/main/java/com/divudi/bean/common/UserNotificationController.java index 61a2b29fd1..3bd2a5f193 100644 --- a/src/main/java/com/divudi/bean/common/UserNotificationController.java +++ b/src/main/java/com/divudi/bean/common/UserNotificationController.java @@ -10,6 +10,7 @@ import com.divudi.bean.common.util.JsfUtil; import com.divudi.bean.pharmacy.PharmacySaleBhtController; +import com.divudi.bean.pharmacy.TransferIssueController; import com.divudi.data.BillTypeAtomic; import static com.divudi.data.BillTypeAtomic.PHARMACY_ORDER; import static com.divudi.data.BillTypeAtomic.PHARMACY_TRANSFER_REQUEST; @@ -19,10 +20,12 @@ import com.divudi.data.TriggerType; import com.divudi.ejb.SmsManagerEjb; import com.divudi.entity.Bill; +import com.divudi.entity.Department; import com.divudi.entity.UserNotification; import com.divudi.entity.Institution; import com.divudi.entity.Notification; import com.divudi.entity.Sms; +import com.divudi.entity.TriggerSubscription; import com.divudi.entity.WebUser; import com.divudi.facade.NotificationFacade; import com.divudi.facade.SmsFacade; @@ -61,6 +64,8 @@ public class UserNotificationController implements Serializable { SmsController smsController; @Inject ConfigOptionController configOptionController; + @Inject + TransferIssueController transferIssueController; @EJB private UserNotificationFacade ejbFacade; @EJB @@ -72,16 +77,34 @@ public class UserNotificationController implements Serializable { @Inject PharmacySaleBhtController pharmacySaleBhtController; - @Inject + @Inject SmsManagerEjb smsManager; + public String navigateToRecivedNotification() { return "/Notification/user_notifications"; } - + public String navigateToSentNotification() { return "/Notification/sent_notifications"; } + + public void clearCanceledRequestsNotification(){ + fillLoggedUserNotifications(); + if (items==null) { + return; + } + + for (UserNotification item : items) { + if (item.getNotification()==null) { + return; + } + if (item.getNotification().getBill().isCancelled()) { + items.remove(item); + } + } + + } public void save(UserNotification userNotification) { if (userNotification == null) { @@ -157,20 +180,25 @@ public List fillLoggedUserNotifications() { return items; } - public String navigateToCurrentNotificationRequest(UserNotification cu) { - if (cu.getNotification().getBill() == null) { + public String navigateToCurrentNotificationRequest(UserNotification un) { + Department toDepartmentFromNotification=un.getNotification().getBill().getToDepartment(); + if (!toDepartmentFromNotification.equals(sessionController.getLoggedUser().getDepartment())) { + JsfUtil.addErrorMessage("You can't Access On Current Department !"); + return ""; + } + if (un.getNotification().getBill() == null) { return ""; } - Bill bill = cu.getNotification().getBill(); + Bill bill = un.getNotification().getBill(); BillTypeAtomic type = bill.getBillTypeAtomic(); switch (type) { case PHARMACY_ORDER: - pharmacySaleBhtController.generateIssueBillComponentsForBhtRequest(bill); - return "/ward/ward_pharmacy_bht_issue"; + pharmacySaleBhtController.setBhtRequestBill(bill); + return pharmacySaleBhtController.navigateToIssueMedicinesDirectlyForBhtRequest(); case PHARMACY_TRANSFER_REQUEST: - pharmacySaleBhtController.generateIssueBillComponentsForBhtRequest(bill); - return "/ward/ward_pharmacy_bht_issue"; + transferIssueController.setRequestedBill(bill); + return transferIssueController.navigateToPharmacyIssueForRequests(); default: return ""; @@ -192,12 +220,16 @@ public void createUserNotifications(Notification notification) { } private void createUserNotificationsForMedium(Notification n) { - List notificationUsers = triggerSubscriptionController.fillWebUsers(n.getTriggerType()); + Department department = n.getBill().getToDepartment(); + if (n.getBill() == null) { + return; + } + List notificationUsers = triggerSubscriptionController.fillSubscribedUsersByDepartment(n.getTriggerType(), department); + System.out.println("notificationUsers = " + notificationUsers.size()); switch (n.getTriggerType().getMedium()) { case EMAIL: for (WebUser u : notificationUsers) { String number = u.getWebUserPerson().getMobile(); - System.out.println("number = " + number); //TODo } break; @@ -206,7 +238,7 @@ private void createUserNotificationsForMedium(Notification n) { String number = u.getWebUserPerson().getMobile(); sendSmsForUserSubscriptions(number); } - break; + break; case SYSTEM_NOTIFICATION: for (WebUser u : notificationUsers) { UserNotification nun = new UserNotification(); @@ -218,28 +250,28 @@ private void createUserNotificationsForMedium(Notification n) { } } - - public void sendSmsForUserSubscriptions(String userMobNumber){ + + public void sendSmsForUserSubscriptions(String userMobNumber) { Sms e = new Sms(); - e.setCreatedAt(new Date()); - e.setCreater(sessionController.getLoggedUser()); - e.setReceipientNumber(userMobNumber); - e.setSendingMessage(createSmsForUserNotification()); - e.setDepartment(getSessionController().getLoggedUser().getDepartment()); - e.setInstitution(getSessionController().getLoggedUser().getInstitution()); - e.setPending(false); - //e.setSmsType(MessageType.ChannelDoctorArrival); - smsFacade.create(e); - SmsSentResponse sent = smsManager.sendSmsByApplicationPreference(e.getReceipientNumber(), e.getSendingMessage(), sessionController.getApplicationPreference()); - e.setSentSuccessfully(sent.isSentSuccefully()); - e.setReceivedMessage(sent.getReceivedMessage()); - smsFacade.edit(e); + e.setCreatedAt(new Date()); + e.setCreater(sessionController.getLoggedUser()); + e.setReceipientNumber(userMobNumber); + e.setSendingMessage(createSmsForUserNotification()); + e.setDepartment(getSessionController().getLoggedUser().getDepartment()); + e.setInstitution(getSessionController().getLoggedUser().getInstitution()); + e.setPending(false); + //e.setSmsType(MessageType.ChannelDoctorArrival); + smsFacade.create(e); + SmsSentResponse sent = smsManager.sendSmsByApplicationPreference(e.getReceipientNumber(), e.getSendingMessage(), sessionController.getApplicationPreference()); + e.setSentSuccessfully(sent.isSentSuccefully()); + e.setReceivedMessage(sent.getReceivedMessage()); + smsFacade.edit(e); } - - public String createSmsForUserNotification(){ + + public String createSmsForUserNotification() { String template = configOptionController.getLongTextValueByKey("SMS Template for User Notification", OptionScope.APPLICATION, null, null, null); - if(template==null||template.isEmpty()){ - template= "{patient_name} {appointment_time}"; + if (template == null || template.isEmpty()) { + template = "{patient_name} {appointment_time}"; } //TODO: Replace placeholders with actual values template = template.replace("{patient_name}", "") diff --git a/src/main/java/com/divudi/bean/pharmacy/TransferIssueController.java b/src/main/java/com/divudi/bean/pharmacy/TransferIssueController.java index 29ebd751c5..d6b95dea4a 100644 --- a/src/main/java/com/divudi/bean/pharmacy/TransferIssueController.java +++ b/src/main/java/com/divudi/bean/pharmacy/TransferIssueController.java @@ -6,11 +6,14 @@ import com.divudi.bean.common.BillController; import com.divudi.bean.common.CommonController; +import com.divudi.bean.common.NotificationController; import com.divudi.bean.common.SessionController; +import com.divudi.bean.common.UserNotificationController; import com.divudi.bean.common.util.JsfUtil; import com.divudi.data.BillClassType; import com.divudi.data.BillNumberSuffix; import com.divudi.data.BillType; +import com.divudi.data.BillTypeAtomic; import com.divudi.data.StockQty; import com.divudi.data.inward.InwardChargeType; import com.divudi.ejb.BillNumberGenerator; @@ -63,6 +66,8 @@ public class TransferIssueController implements Serializable { BillController billController; @Inject CommonController commonController; + @Inject + NotificationController notificationController; //// @EJB private BillFacade billFacade; @@ -458,7 +463,7 @@ public void settleDirectIssue() { getIssuedBill().setNetTotal(calTotal()); getIssuedBill().setBackwardReferenceBill(getRequestedBill()); - + getIssuedBill().setBillTypeAtomic(BillTypeAtomic.PHARMACY_DIRECT_ISSUE); getBillFacade().edit(getIssuedBill()); //Update ReferenceBill @@ -468,10 +473,10 @@ public void settleDirectIssue() { Bill b = getBillFacade().find(getIssuedBill().getId()); userStockController.retiredAllUserStockContainer(getSessionController().getLoggedUser()); - issuedBill = null; issuedBill = b; - + + notificationController.createNotification(issuedBill); printPreview = true; } diff --git a/src/main/java/com/divudi/bean/pharmacy/TransferRequestController.java b/src/main/java/com/divudi/bean/pharmacy/TransferRequestController.java index df2411da0a..7020ccba5e 100644 --- a/src/main/java/com/divudi/bean/pharmacy/TransferRequestController.java +++ b/src/main/java/com/divudi/bean/pharmacy/TransferRequestController.java @@ -288,15 +288,10 @@ public void request() { getBill().getBillItems().add(b); } - getBill().setBillTypeAtomic(BillTypeAtomic.PHARMACY_TRANSFER_REQUEST); - getBillFacade().edit(getBill()); - JsfUtil.addSuccessMessage("Transfer Request Succesfully Created"); - printPreview = true; - notificationController.createNotification(bill); diff --git a/src/main/java/com/divudi/data/BillTypeAtomic.java b/src/main/java/com/divudi/data/BillTypeAtomic.java index bfa31d9fa3..494f14f555 100644 --- a/src/main/java/com/divudi/data/BillTypeAtomic.java +++ b/src/main/java/com/divudi/data/BillTypeAtomic.java @@ -54,6 +54,8 @@ public enum BillTypeAtomic { PHARMACY_TRANSFER_REQUEST_CANCELLED("Pharmacy Transfer Request Cancelled", BillCategory.CANCELLATION, ServiceType.PHARMACY, BillFinanceType.NO_FINANCE_TRANSACTIONS), PHARMACY_ISSUE("Pharmacy Issue", BillCategory.BILL, ServiceType.PHARMACY, BillFinanceType.NO_FINANCE_TRANSACTIONS), PHARMACY_ISSUE_CANCELLED("Pharmacy Issue Cancelled", BillCategory.CANCELLATION, ServiceType.PHARMACY, BillFinanceType.NO_FINANCE_TRANSACTIONS), + PHARMACY_DIRECT_ISSUE("Pharmacy Direct Issue", BillCategory.BILL, ServiceType.PHARMACY, BillFinanceType.NO_FINANCE_TRANSACTIONS), + PHARMACY_DIRECT_ISSUE_CANCELLED("Pharmacy Direct Issue Cancelled", BillCategory.CANCELLATION, ServiceType.PHARMACY, BillFinanceType.NO_FINANCE_TRANSACTIONS), PHARMACY_RECEIVE("Pharmacy Receive", BillCategory.BILL, ServiceType.PHARMACY, BillFinanceType.NO_FINANCE_TRANSACTIONS), PHARMACY_RECEIVE_CANCELLED("Pharmacy Receive Cancelled", BillCategory.CANCELLATION, ServiceType.PHARMACY, BillFinanceType.NO_FINANCE_TRANSACTIONS), // CHANNELLING diff --git a/src/main/java/com/divudi/entity/Notification.java b/src/main/java/com/divudi/entity/Notification.java index 1b391d55c3..c546f203b3 100644 --- a/src/main/java/com/divudi/entity/Notification.java +++ b/src/main/java/com/divudi/entity/Notification.java @@ -47,6 +47,7 @@ public class Notification implements Serializable { @Temporal(javax.persistence.TemporalType.TIMESTAMP) private Date retiredAt; private String retireComments; + public Long getId() { return id; diff --git a/src/main/java/com/divudi/entity/UserNotification.java b/src/main/java/com/divudi/entity/UserNotification.java index 9aabca5098..4daa33586d 100644 --- a/src/main/java/com/divudi/entity/UserNotification.java +++ b/src/main/java/com/divudi/entity/UserNotification.java @@ -44,6 +44,7 @@ public class UserNotification implements Serializable { @Temporal(javax.persistence.TemporalType.TIMESTAMP) private Date retiredAt; private String retireComments; + private Department toDepartment; public Long getId() { @@ -152,5 +153,14 @@ public String getRetireComments() { public void setRetireComments(String retireComments) { this.retireComments = retireComments; } + + public Department getToDepartment() { + return toDepartment; + } + + public void setToDepartment(Department toDepartment) { + this.toDepartment = toDepartment; + } + } diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml index a84bb3ce8f..501b1ca603 100644 --- a/src/main/resources/META-INF/persistence.xml +++ b/src/main/resources/META-INF/persistence.xml @@ -1,19 +1,32 @@ - - - jdbc/arogyaNew - false - - - - - - - - jdbc/arogyaAudit - false - - - - - \ No newline at end of file + + + org.eclipse.persistence.jpa.PersistenceProvider + jdbc/arogya + false + + + + + + + + + jdbc/arogyaAudit + + com.divudi.entity.AuditEvent + true + + + + + + + + diff --git a/src/main/resources/VERSION.txt b/src/main/resources/VERSION.txt index 041265944c..23b593ca7d 100644 --- a/src/main/resources/VERSION.txt +++ b/src/main/resources/VERSION.txt @@ -1 +1 @@ -3.0.0.20240417.12 +3.0.0.20240417.7 diff --git a/src/main/webapp/Notification/index.xhtml b/src/main/webapp/Notification/index.xhtml index 3b1f986da0..ac8f021899 100644 --- a/src/main/webapp/Notification/index.xhtml +++ b/src/main/webapp/Notification/index.xhtml @@ -24,10 +24,7 @@ ajax="false" value="Received Messages" action="#{userNotificationController.navigateToRecivedNotification}"/> - + diff --git a/src/main/webapp/Notification/sent_notifications.xhtml b/src/main/webapp/Notification/sent_notifications.xhtml deleted file mode 100644 index 5c67f2c74f..0000000000 --- a/src/main/webapp/Notification/sent_notifications.xhtml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - -
- -
- -

New Request for Medicines

-
- - - - - - -
-
- - - -
-
- -
- - -
- - -
- -
-
-
-
-
-
-
-
-
-
-
- \ No newline at end of file diff --git a/src/main/webapp/Notification/user_notifications.xhtml b/src/main/webapp/Notification/user_notifications.xhtml index 227b3ec71f..233df24791 100644 --- a/src/main/webapp/Notification/user_notifications.xhtml +++ b/src/main/webapp/Notification/user_notifications.xhtml @@ -6,35 +6,62 @@ xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://xmlns.jcp.org/jsf/core"> - - + + +
+ +
-
-
- +
+ +
-
New Request from
-
#{un.notification.bill.department.name}
+
New Notification from
+
#{un.notification.bill.department.name}
- -
-
+
+
+ +
+
+ +
New Notification from
+
#{un.notification.bill.department.name}
+
+
+
+ +
+
+ +
New Notification from
+
#{un.notification.bill.department.name}
+
+
+
+
- - + + +
-
+