Skip to content

Commit

Permalink
Merge branch 'master' into Issue#6372
Browse files Browse the repository at this point in the history
  • Loading branch information
DamithDeshan authored Aug 21, 2024
2 parents c4d8089 + 3bb31f6 commit b7dca62
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 173 deletions.
4 changes: 1 addition & 3 deletions src/main/java/com/divudi/bean/channel/BookingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -897,9 +897,7 @@ public void listTodaysCompletedSesionInstances() {
public void listSessionInstancesByDate() {
sessionInstances = channelBean.listSessionInstancesByDate(fromDate, null, null, null);
if (configOptionApplicationController.getBooleanValueByKey("Load Past Patient Data")) {
for (SessionInstance s : sessionInstances) {
bookingControllerViewScope.fillBillSessions(s);
}
bookingControllerViewScope.fillBillSessions(sessionInstances);
}
}

Expand Down
179 changes: 63 additions & 116 deletions src/main/java/com/divudi/bean/channel/BookingControllerViewScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -1188,12 +1188,8 @@ public void listCancelled() {

public void addBillSessionData() {
if (configOptionApplicationController.getBooleanValueByKey("Calculate All Patient Count When Loading Channel Booking By Dates")) {
if (sessionInstances != null) {
if (sessionInstances.size() < 21) {
for (SessionInstance s : sessionInstances) {
fillBillSessions(s);
}
}
if (sessionInstancesFiltered != null) {
fillBillSessions(sessionInstancesFiltered);
}
}
}
Expand Down Expand Up @@ -1274,6 +1270,7 @@ public void loadSessionInstances() {
}
}

@Deprecated
public void filterSessionInstances() {
if (sessionInstanceFilter == null || sessionInstanceFilter.trim().isEmpty()) {
if (sessionInstances != null) {
Expand Down Expand Up @@ -1742,42 +1739,50 @@ public UserPreference getDepartmentPreference() {
return sessionController.getDepartmentPreference();
}

@Deprecated
public String navigateToChannelBookingByDate() {
fillBillSessions();
prepareForNewChannellingBill();
return null;
}

@Deprecated
public String navigateToChannelQueueFromMenu() {
sessionInstances = channelBean.listTodaysSesionInstances();
return "/channel/channel_queue?faces-redirect=true";
}

@Deprecated
public String navigateToChannelDisplayFromMenu() {
sessionInstances = channelBean.listTodaysSessionInstances(true, false, false);
return "/channel/channel_display?faces-redirect=true";
}

@Deprecated
public String navigateToChannelQueueFromConsultantRoom() {
sessionInstances = channelBean.listTodaysSesionInstances();
return "/channel/channel_queue?faces-redirect=true";
}

@Deprecated
public void listOngoingSesionInstances() {
sessionInstances = channelBean.listSessionInstances(fromDate, toDate, true, null, null);
filterSessionInstances();
}

@Deprecated
public void listCompletedSesionInstances() {
sessionInstances = channelBean.listSessionInstances(fromDate, toDate, null, true, null);
filterSessionInstances();
}

@Deprecated
public void listPendingSesionInstances() {
sessionInstances = channelBean.listSessionInstances(fromDate, toDate, null, null, true);
filterSessionInstances();
}

@Deprecated
public void listCancelledSesionInstances() {
sessionInstances = channelBean.listSessionInstances(fromDate, toDate, null, null, null, true);
filterSessionInstances();
Expand Down Expand Up @@ -2840,6 +2845,7 @@ public String startNewChannelBookingForSelectingSpeciality() {
return navigateBackToBookingsFromSessionInstance();
}

@Deprecated
public String startNewChannelBookingFormSelectingConsultant() {
resetToStartFromSelectingConsultant();
generateSessions();
Expand Down Expand Up @@ -4746,127 +4752,65 @@ public void fillBillSessions() {
sessionInstanceController.save(selectedSessionInstance);
}

public void fillBillSessions(SessionInstance s) {
List<BillSession> tempBillSessions;
BillType[] billTypes = {
BillType.ChannelAgent,
BillType.ChannelCash,
BillType.ChannelOnCall,
BillType.ChannelStaff,
BillType.ChannelCredit,
BillType.ChannelResheduleWithPayment,
BillType.ChannelResheduleWithOutPayment
};
List<BillType> bts = Arrays.asList(billTypes);
String sql = "Select bs "
+ " From BillSession bs "
+ " where bs.retired=false"
+ " and bs.bill.billType in :bts"
+ " and type(bs.bill)=:class "
+ " and bs.sessionInstance=:ss "
+ " order by bs.serialNo ";
HashMap<String, Object> hh = new HashMap<>();
hh.put("bts", bts);
hh.put("class", BilledBill.class);
hh.put("ss", s);
tempBillSessions = getBillSessionFacade().findByJpql(sql, hh, TemporalType.DATE);

// Initialize counts
long bookedPatientCount = 0;
long paidPatientCount = 0;
long completedPatientCount = 0;
long cancelPatientCount = 0;
long refundedPatientCount = 0;
long onCallPatientCount = 0;
long reservedBookingCount = 0;

if (tempBillSessions == null) {
s.setBookedPatientCount(0l);
s.setPaidPatientCount(0l);
s.setCompletedPatientCount(0l);
s.setRemainingPatientCount(0l);
sessionInstanceController.save(s);
public void fillBillSessions(List<SessionInstance> sessionInstances) {
if (sessionInstances == null || sessionInstances.isEmpty()) {
return;
}

// Loop through billSessions to calculate counts
for (BillSession bs : tempBillSessions) {
if (bs != null) {
bookedPatientCount++; // Always increment if bs is not null

// Additional check for reserved status
try {
if (bs.isReservedBooking()) {
reservedBookingCount++;
}
} catch (NullPointerException npe) {
// Log or handle the fact that there was an NPE checking completion status

}

// Additional check for completion status
try {
if (bs.isCompleted()) {
completedPatientCount++;
}
} catch (NullPointerException npe) {
// Log or handle the fact that there was an NPE checking completion status

}
// Prepare the SQL query
String sql = "SELECT bs.SESSIONINSTANCE_ID, " +
"COUNT(bs.ID) AS bookedPatientCount, " +
"SUM(CASE WHEN bs.PAIDBILLSESSION_ID IS NOT NULL THEN 1 ELSE 0 END) AS paidPatientCount, " +
"SUM(CASE WHEN bs.COMPLETED = TRUE THEN 1 ELSE 0 END) AS completedPatientCount, " +
"SUM(CASE WHEN b.CANCELLED = TRUE THEN 1 ELSE 0 END) AS cancelPatientCount, " +
"SUM(CASE WHEN b.REFUNDED = TRUE THEN 1 ELSE 0 END) AS refundedPatientCount, " +
"SUM(CASE WHEN bs.PAIDBILLSESSION_ID IS NULL AND b.CANCELLED = FALSE THEN 1 ELSE 0 END) AS onCallPatientCount, " +
"SUM(CASE WHEN bs.RESERVEDBOOKING = TRUE THEN 1 ELSE 0 END) AS reservedBookingCount " +
"FROM billsession bs " +
"JOIN bill b ON bs.BILL_ID = b.ID " +
"WHERE bs.RETIRED = FALSE " +
"AND b.BILLTYPE IN ('ChannelAgent', 'ChannelCash', 'ChannelOnCall', 'ChannelStaff', 'ChannelCredit', 'ChannelResheduleWithPayment', 'ChannelResheduleWithOutPayment') " +
"AND b.DTYPE = 'BilledBill' " +
"AND bs.SESSIONINSTANCE_ID IN (:ids) " +
"GROUP BY bs.SESSIONINSTANCE_ID";

// Additional check for paid status
try {
if (bs.getPaidBillSession() != null) {
paidPatientCount++;
}
} catch (NullPointerException npe) {
// Log or handle the fact that there was an NPE checking paid status

}
// Additional check for cancel status
try {
if (bs.getBill().isCancelled()) {
cancelPatientCount++;
}
} catch (NullPointerException npe) {
// Log or handle the fact that there was an NPE checking paid status
// Prepare the parameters
List<Long> sessionInstanceIds = sessionInstances.stream()
.map(SessionInstance::getId)
.collect(Collectors.toList());
Map<String, Object> parameters = new HashMap<>();

}
// Execute the query
List<Object[]> results = billSessionFacade.findObjectsArrayByNativeQuery(sql, parameters, sessionInstanceIds);

// Additional check for refund status
try {
if (bs.getBill().isRefunded()) {
refundedPatientCount++;
}
} catch (NullPointerException npe) {
// Log or handle the fact that there was an NPE checking paid status
// Process the results
Map<Long, SessionInstance> sessionInstanceMap = sessionInstances.stream()
.collect(Collectors.toMap(SessionInstance::getId, si -> si));

}
for (Object[] result : results) {
Long sessionInstanceId = ((Number) result[0]).longValue();
long bookedPatientCount = ((Number) result[1]).longValue();
long paidPatientCount = ((Number) result[2]).longValue();
long completedPatientCount = ((Number) result[3]).longValue();
long cancelPatientCount = ((Number) result[4]).longValue();
long refundedPatientCount = ((Number) result[5]).longValue();
long onCallPatientCount = ((Number) result[6]).longValue();
long reservedBookingCount = ((Number) result[7]).longValue();

// Additional check for Oncall status
try {
if (bs.getPaidBillSession() == null && !bs.getBill().isCancelled()) {
onCallPatientCount++;
}
} catch (NullPointerException npe) {
// Log or handle the fact that there was an NPE checking paid status
SessionInstance sessionInstance = sessionInstanceMap.get(sessionInstanceId);
if (sessionInstance != null) {
sessionInstance.setBookedPatientCount(bookedPatientCount);
sessionInstance.setPaidPatientCount(paidPatientCount);
sessionInstance.setCompletedPatientCount(completedPatientCount);
sessionInstance.setCancelPatientCount(cancelPatientCount);
sessionInstance.setRefundedPatientCount(refundedPatientCount);
sessionInstance.setOnCallPatientCount(onCallPatientCount);
sessionInstance.setReservedBookingCount(reservedBookingCount);
sessionInstance.setRemainingPatientCount(bookedPatientCount - completedPatientCount);

}
sessionInstanceController.save(sessionInstance);
}
}

// Set calculated counts to selectedSessionInstance
s.setBookedPatientCount(bookedPatientCount);
s.setPaidPatientCount(paidPatientCount);
s.setCompletedPatientCount(completedPatientCount);
s.setCancelPatientCount(cancelPatientCount);
s.setRefundedPatientCount(refundedPatientCount);
s.setOnCallPatientCount(onCallPatientCount);
s.setReservedBookingCount(reservedBookingCount);

// Assuming remainingPatientCount is calculated as booked - completed
s.setRemainingPatientCount(bookedPatientCount - completedPatientCount);
sessionInstanceController.save(s);
}

private boolean errorCheckForAddingNewBooking() {
Expand Down Expand Up @@ -6089,13 +6033,15 @@ public void listnerStaffListForRowSelect() {
selectedBillSession = null;
}

@Deprecated
public void listnerStaffRowSelect() {
getSelectedConsultants();
setSelectedServiceSession(null);
serviceSessionLeaveController.setSelectedServiceSession(null);
serviceSessionLeaveController.setCurrentStaff(staff);
}

@Deprecated
public void listnerSessionRowSelect() {
if (sessionInstances == null) {
selectedServiceSession = null;
Expand Down Expand Up @@ -7725,6 +7671,7 @@ public List<SessionInstance> getSessionInstancesFiltered() {
return sessionInstancesFiltered;
}

@Deprecated
public List<SessionInstance> getSortedSessionInstances() {

if (oldSessionInstancesFiltered == null) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/divudi/bean/common/ItemFeeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public String navigateToUploadFeeListType(){
return "/admin/pricing/feelist_type_upload?faces-redirect=true";
}

public String navigateToUploadFeeListItemFees(){
return "/admin/pricing/feelist_item_fees_upload?faces-redirect=true";
}

public String navigateToUploadCollectingCentreFeeList() {
return "/admin/pricing/collecting_centre_price_list_upload?faces-redirect=true";
}
Expand Down
Loading

0 comments on commit b7dca62

Please sign in to comment.