Skip to content

Commit

Permalink
Merge pull request #4637 from hmislk/issue#4595
Browse files Browse the repository at this point in the history
Issue#4595
  • Loading branch information
Thiwanka570 authored Apr 18, 2024
2 parents f714164 + 41f54d0 commit e2389c7
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 153 deletions.
57 changes: 55 additions & 2 deletions src/main/java/com/divudi/bean/common/NotificationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,6 +54,8 @@ public class NotificationController implements Serializable {
SecurityController securityController;
@Inject
CommonController commonController;
@Inject
ConfigOptionController configOptionController;
@EJB
private NotificationFacade ejbFacade;
private Notification current;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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 = "";
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ public class TriggerSubscriptionController implements Serializable {
private List<Department> departments;
private WebUser user;

public List<WebUser> fillSubscribedUsersByDepartment(TriggerType tt,Department dept) {
List<WebUser> 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");
Expand Down Expand Up @@ -116,7 +135,7 @@ public List<WebUser> fillWebUsers(TriggerType tt) {

m.put("tt", tt);
m.put("ret", false);
us= webUserFacade.findByJpql(jpql, m);
us = webUserFacade.findByJpql(jpql, m);
return us;
}

Expand Down Expand Up @@ -322,7 +341,6 @@ public List<TriggerType> getTriggerTypes() {
return triggerTypes;
}


@FacesConverter(forClass = TriggerSubscription.class)
public static class UserSubscriptionConverter implements Converter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -61,6 +64,8 @@ public class UserNotificationController implements Serializable {
SmsController smsController;
@Inject
ConfigOptionController configOptionController;
@Inject
TransferIssueController transferIssueController;
@EJB
private UserNotificationFacade ejbFacade;
@EJB
Expand All @@ -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) {
Expand Down Expand Up @@ -157,20 +180,25 @@ public List<UserNotification> 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 "";
Expand All @@ -192,12 +220,16 @@ public void createUserNotifications(Notification notification) {
}

private void createUserNotificationsForMedium(Notification n) {
List<WebUser> notificationUsers = triggerSubscriptionController.fillWebUsers(n.getTriggerType());
Department department = n.getBill().getToDepartment();
if (n.getBill() == null) {
return;
}
List<WebUser> 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;
Expand All @@ -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();
Expand All @@ -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}", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,6 +66,8 @@ public class TransferIssueController implements Serializable {
BillController billController;
@Inject
CommonController commonController;
@Inject
NotificationController notificationController;
////
@EJB
private BillFacade billFacade;
Expand Down Expand Up @@ -458,7 +463,7 @@ public void settleDirectIssue() {
getIssuedBill().setNetTotal(calTotal());

getIssuedBill().setBackwardReferenceBill(getRequestedBill());

getIssuedBill().setBillTypeAtomic(BillTypeAtomic.PHARMACY_DIRECT_ISSUE);
getBillFacade().edit(getIssuedBill());

//Update ReferenceBill
Expand All @@ -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;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/divudi/data/BillTypeAtomic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/divudi/entity/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit e2389c7

Please sign in to comment.