From 506f199ce3df59834adab7e334fe049f97f0e64f Mon Sep 17 00:00:00 2001 From: thiwanka570 Date: Wed, 14 Aug 2024 10:25:28 +0530 Subject: [PATCH 1/5] Signed-off-by: thiwanka570 --- .../divudi/bean/common/ItemFeeManager.java | 4 + .../divudi/bean/emr/DataUploadController.java | 137 +++++++++++++++++- src/main/resources/META-INF/persistence.xml | 4 +- .../pricing/feelist_item_fees_upload.xhtml | 74 ++++++++++ src/main/webapp/admin/pricing/index.xhtml | 14 ++ 5 files changed, 230 insertions(+), 3 deletions(-) create mode 100644 src/main/webapp/admin/pricing/feelist_item_fees_upload.xhtml diff --git a/src/main/java/com/divudi/bean/common/ItemFeeManager.java b/src/main/java/com/divudi/bean/common/ItemFeeManager.java index c4b57c2824..ccd1856f3c 100644 --- a/src/main/java/com/divudi/bean/common/ItemFeeManager.java +++ b/src/main/java/com/divudi/bean/common/ItemFeeManager.java @@ -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"; } diff --git a/src/main/java/com/divudi/bean/emr/DataUploadController.java b/src/main/java/com/divudi/bean/emr/DataUploadController.java index db602643e4..865d1f25d7 100644 --- a/src/main/java/com/divudi/bean/emr/DataUploadController.java +++ b/src/main/java/com/divudi/bean/emr/DataUploadController.java @@ -246,6 +246,7 @@ public class DataUploadController implements Serializable { private List surgeriesToSave; private List surgeriesToSkiped; + public String navigateToRouteUpload(){ return "/admin/institutions/route_upload?faces-redirect=true"; } @@ -609,6 +610,18 @@ public void uploadStaff() { pollActive = false; } + public void uploadFeeListItemFees() { + itemFees = new ArrayList<>(); + if (file != null) { + try ( InputStream inputStream = file.getInputStream()) { + itemFees = readFeeListItemFeesFromExcel(inputStream); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + public List readFeeListTypesFromExcel(InputStream inputStream)throws IOException { List feeListTypes = new ArrayList<>(); Workbook workbook = new XSSFWorkbook(inputStream); @@ -619,7 +632,7 @@ public List readFeeListTypesFromExcel(InputStream inputStream)throws I rowIterator.next(); } - Category category; + Category category = null; while (rowIterator.hasNext()) { Row row = rowIterator.next(); @@ -636,6 +649,9 @@ public List readFeeListTypesFromExcel(InputStream inputStream)throws I if (feeListName != null || !feeListName.trim().equals("")) { category=categoryController.findCategoryByName(feeListName); + } + + if (category == null) { category= new Category(); category.setName(feeListName); category.setSymanticType(SymanticHyrachi.Fee_List_Type); @@ -649,6 +665,125 @@ public List readFeeListTypesFromExcel(InputStream inputStream)throws I JsfUtil.addSuccessMessage("FeeList Types Uploaded"); return feeListTypes; } + + private List readFeeListItemFeesFromExcel(InputStream inputStream) throws IOException{ + List itemFees = new ArrayList<>(); + Workbook workbook = new XSSFWorkbook(inputStream); + Sheet sheet = workbook.getSheetAt(0); + Iterator rowIterator = sheet.rowIterator(); + + // Assuming the first row contains headers, skip it + if (rowIterator.hasNext()) { + rowIterator.next(); + } + + while (rowIterator.hasNext()) { + Row row = rowIterator.next(); + String itemCode=null; + String itemName = null; + String forCategoryName=null; + String institutionName=null; + String discountAllowed=null; + String ffeeValue=null; + String fffeeValue=null; + + boolean disAllowd; + double fee=0.0; + double ffee=0.0; + + Item item; + Category category; + Institution institution; + + Cell itemCodeCell = row.getCell(0); + if (itemCodeCell != null && itemCodeCell.getCellType() == CellType.STRING) { + itemCode = itemCodeCell.getStringCellValue(); + } + + Cell itemNameCell = row.getCell(1); + if (itemNameCell != null && itemNameCell.getCellType() == CellType.STRING) { + itemName = itemNameCell.getStringCellValue(); + } + + Cell forCategoryCell = row.getCell(2); + if (forCategoryCell != null && forCategoryCell.getCellType() == CellType.STRING) { + forCategoryName = forCategoryCell.getStringCellValue(); + } + + Cell institutionCell = row.getCell(3); + if (institutionCell != null && institutionCell.getCellType() == CellType.STRING) { + institutionName = forCategoryCell.getStringCellValue(); + } + + Cell feeCell = row.getCell(4); + if (feeCell != null && feeCell.getCellType() == CellType.NUMERIC) { + fee = feeCell.getNumericCellValue(); + } + + Cell ffeeCell = row.getCell(5); + if (ffeeCell != null && ffeeCell.getCellType() == CellType.NUMERIC) { + ffee = ffeeCell.getNumericCellValue(); + } + + + Cell discountAllowedCell = row.getCell(6); + if (discountAllowedCell != null && discountAllowedCell.getCellType() == CellType.STRING) { + discountAllowed = discountAllowedCell.getStringCellValue(); + } + if (discountAllowed!= null || !discountAllowed.trim().equals("")) { + disAllowd=true; + }else{ + disAllowd=false; + } + + if (institutionName==null || institutionName.trim().equals("")) { + institution=sessionController.getInstitution(); + }else{ + institution=institutionController.findAndSaveInstitutionByName(institutionName); + } + + + if (itemName == null || itemCode==null) { + JsfUtil.addErrorMessage("Item Name and Item Code cannot be null."); + return itemFees; + } + + if (forCategoryName == null || forCategoryName.trim().equals("")) { + JsfUtil.addErrorMessage("Fee List types cannot be null."); + return itemFees; + } + + category=categoryController.findCategoryByName(forCategoryName); + if (category==null) { + JsfUtil.addErrorMessage("Fee List type Not found."); + return itemFees; + } + + item= itemController.findItemByNameAndCode(itemName, itemCode); + if (item==null) { + JsfUtil.addErrorMessage("Item cannot be null."); + return itemFees; + } + ItemFee Itemfee= new ItemFee(); + Itemfee.setCreatedAt(new Date()); + Itemfee.setName(forCategoryName); + Itemfee.setCreater(sessionController.getLoggedUser()); + Itemfee.setForInstitution(null); + Itemfee.setForCategory(category); + Itemfee.setItem(item); + Itemfee.setFeeType(FeeType.OwnInstitution); + Itemfee.setInstitution(institution); + Itemfee.setFee(fee); + Itemfee.setFfee(ffee); + Itemfee.setDiscountAllowed(disAllowd); + itemFeeFacade.create(Itemfee); + + + } + JsfUtil.addSuccessMessage("Upload Success"); + return itemFees; + + } private List readConsultantsFromExcel(InputStream inputStream) throws IOException { List cons = new ArrayList<>(); diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml index 755636ee5e..61eb84e771 100644 --- a/src/main/resources/META-INF/persistence.xml +++ b/src/main/resources/META-INF/persistence.xml @@ -2,7 +2,7 @@ org.eclipse.persistence.jpa.PersistenceProvider - jdbc/ruhunu + jdbc/arogya false @@ -13,7 +13,7 @@ - jdbc/ruhunuaudit + jdbc/arogyaAudit false diff --git a/src/main/webapp/admin/pricing/feelist_item_fees_upload.xhtml b/src/main/webapp/admin/pricing/feelist_item_fees_upload.xhtml new file mode 100644 index 0000000000..17a6b0c1dd --- /dev/null +++ b/src/main/webapp/admin/pricing/feelist_item_fees_upload.xhtml @@ -0,0 +1,74 @@ + + + + + + +
+
+
+

Upload Collecting Centre Price List

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ColumnTitle
AItem Code
BItem Name
CCategory
DInstitution
EFee
Fforeign fee
GDiscount Allowed
+
+
+
+ + + +
+
diff --git a/src/main/webapp/admin/pricing/index.xhtml b/src/main/webapp/admin/pricing/index.xhtml index 8b8c2ddbaa..5305e683f9 100644 --- a/src/main/webapp/admin/pricing/index.xhtml +++ b/src/main/webapp/admin/pricing/index.xhtml @@ -86,6 +86,20 @@ action="#{itemFeeManager.navigateToUploadFeeListType()}"> + + + + + + Date: Wed, 14 Aug 2024 11:52:38 +0530 Subject: [PATCH 2/5] Signed-off-by: thiwanka570 --- src/main/webapp/admin/institutions/route_upload.xhtml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/webapp/admin/institutions/route_upload.xhtml b/src/main/webapp/admin/institutions/route_upload.xhtml index 0dced545c4..99c2578b9c 100644 --- a/src/main/webapp/admin/institutions/route_upload.xhtml +++ b/src/main/webapp/admin/institutions/route_upload.xhtml @@ -25,13 +25,7 @@ class="ui-button-success" action="#{dataUploadController.uploadRoutes()}" ajax="false"/> - - - + From 8670f46a5fb611a6aae45e831bfae38320dfa5be Mon Sep 17 00:00:00 2001 From: Piyankara N W M G P Date: Wed, 14 Aug 2024 13:34:29 +0530 Subject: [PATCH 3/5] Signed-off-by: Piyankara N W M G P --- .../divudi/bean/report/ReportController.java | 19 ++++---- src/main/resources/META-INF/persistence.xml | 4 +- .../financialReports/petty_cash_payment.xhtml | 43 ++++++++++--------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/divudi/bean/report/ReportController.java b/src/main/java/com/divudi/bean/report/ReportController.java index aa2390fd33..937f3575fa 100644 --- a/src/main/java/com/divudi/bean/report/ReportController.java +++ b/src/main/java/com/divudi/bean/report/ReportController.java @@ -70,7 +70,6 @@ public class ReportController implements Serializable { BillFacade billFacade; @EJB InstitutionFacade institutionFacade; - @Inject private InstitutionController institutionController; @@ -157,22 +156,26 @@ public void processCollectionCenterBalance() { collectionCenters = institutionFacade.findByJpql(jpql, m); } - - public void processPettyCashPayment(){ + + public void processPettyCashPayment() { String jpql = "SELECT pc " - +"FROM Bill pc " - +"WHERE pc.retired=:ret " - +"and pc.createdAt between :fromDate and :toDate"; + + "FROM Bill pc " + + "WHERE pc.retired = :ret " + + "AND pc.billType = :bt " + + "AND pc.createdAt BETWEEN :fromDate AND :toDate"; + Map m = new HashMap<>(); m.put("ret", false); + m.put("bt", BillType.PettyCash); m.put("fromDate", getFromDate()); m.put("toDate", getToDate()); + System.out.println(m); System.err.println(jpql); + bills = billFacade.findByJpql(jpql, m); - } - + public String navigatetoOPDLabReportByMenu() { return "/lab/report_for_opd_print?faces-redirect=true"; } diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml index 755636ee5e..393a6cba67 100644 --- a/src/main/resources/META-INF/persistence.xml +++ b/src/main/resources/META-INF/persistence.xml @@ -2,7 +2,7 @@ org.eclipse.persistence.jpa.PersistenceProvider - jdbc/ruhunu + jdbc/hims false @@ -13,7 +13,7 @@ - jdbc/ruhunuaudit + jdbc/himsAduit false diff --git a/src/main/webapp/reports/financialReports/petty_cash_payment.xhtml b/src/main/webapp/reports/financialReports/petty_cash_payment.xhtml index 86a71f4979..dae0edec91 100644 --- a/src/main/webapp/reports/financialReports/petty_cash_payment.xhtml +++ b/src/main/webapp/reports/financialReports/petty_cash_payment.xhtml @@ -17,17 +17,17 @@
- - - + + +
@@ -83,23 +83,26 @@ - + - + + - + - + + + - + @@ -108,14 +111,14 @@ - + - - - + + + From fc80ec55a1d9c092930ecafef01d2a530629d482 Mon Sep 17 00:00:00 2001 From: Lahiru Jayakody Date: Wed, 14 Aug 2024 15:25:35 +0530 Subject: [PATCH 4/5] remove unnecessary size check since now using the filtered results. marked all methods which uses `sessionInstances` as deprecated since those should use sessionInstancesFiltered --- .../channel/BookingControllerViewScope.java | 21 ++++++++++++++----- .../channel/channel_booking_by_date.xhtml | 2 +- .../channel/manage_booking_by_date.xhtml | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/divudi/bean/channel/BookingControllerViewScope.java b/src/main/java/com/divudi/bean/channel/BookingControllerViewScope.java index a73f241223..c248842f78 100644 --- a/src/main/java/com/divudi/bean/channel/BookingControllerViewScope.java +++ b/src/main/java/com/divudi/bean/channel/BookingControllerViewScope.java @@ -1188,11 +1188,9 @@ 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) { + for (SessionInstance s : sessionInstances) { + fillBillSessions(s); } } } @@ -1274,6 +1272,7 @@ public void loadSessionInstances() { } } + @Deprecated public void filterSessionInstances() { if (sessionInstanceFilter == null || sessionInstanceFilter.trim().isEmpty()) { if (sessionInstances != null) { @@ -1742,42 +1741,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(); @@ -2840,6 +2847,7 @@ public String startNewChannelBookingForSelectingSpeciality() { return navigateBackToBookingsFromSessionInstance(); } + @Deprecated public String startNewChannelBookingFormSelectingConsultant() { resetToStartFromSelectingConsultant(); generateSessions(); @@ -6089,6 +6097,7 @@ public void listnerStaffListForRowSelect() { selectedBillSession = null; } + @Deprecated public void listnerStaffRowSelect() { getSelectedConsultants(); setSelectedServiceSession(null); @@ -6096,6 +6105,7 @@ public void listnerStaffRowSelect() { serviceSessionLeaveController.setCurrentStaff(staff); } + @Deprecated public void listnerSessionRowSelect() { if (sessionInstances == null) { selectedServiceSession = null; @@ -7725,6 +7735,7 @@ public List getSessionInstancesFiltered() { return sessionInstancesFiltered; } + @Deprecated public List getSortedSessionInstances() { if (oldSessionInstancesFiltered == null) { diff --git a/src/main/webapp/channel/channel_booking_by_date.xhtml b/src/main/webapp/channel/channel_booking_by_date.xhtml index 30bacabbcd..77f1ad7bd5 100644 --- a/src/main/webapp/channel/channel_booking_by_date.xhtml +++ b/src/main/webapp/channel/channel_booking_by_date.xhtml @@ -50,7 +50,7 @@
+ listener="#{bookingControllerViewScope.listAndFilterSessionInstances()}">
diff --git a/src/main/webapp/channel/manage_booking_by_date.xhtml b/src/main/webapp/channel/manage_booking_by_date.xhtml index 682a4032ed..e52132909d 100644 --- a/src/main/webapp/channel/manage_booking_by_date.xhtml +++ b/src/main/webapp/channel/manage_booking_by_date.xhtml @@ -662,7 +662,7 @@ From 22258a2d215a9adec9ae04bb0415dbbbdb7d6e82 Mon Sep 17 00:00:00 2001 From: Lahiru Jayakody Date: Wed, 14 Aug 2024 17:39:27 +0530 Subject: [PATCH 5/5] fix for N+1 problem in fillBillSessions --- .../bean/channel/BookingController.java | 4 +- .../channel/BookingControllerViewScope.java | 172 ++++++------------ .../data/channel/PatientPortalController.java | 17 +- .../com/divudi/facade/AbstractFacade.java | 19 ++ 4 files changed, 78 insertions(+), 134 deletions(-) diff --git a/src/main/java/com/divudi/bean/channel/BookingController.java b/src/main/java/com/divudi/bean/channel/BookingController.java index a150f004c5..379c260081 100644 --- a/src/main/java/com/divudi/bean/channel/BookingController.java +++ b/src/main/java/com/divudi/bean/channel/BookingController.java @@ -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); } } diff --git a/src/main/java/com/divudi/bean/channel/BookingControllerViewScope.java b/src/main/java/com/divudi/bean/channel/BookingControllerViewScope.java index c248842f78..1e30a114df 100644 --- a/src/main/java/com/divudi/bean/channel/BookingControllerViewScope.java +++ b/src/main/java/com/divudi/bean/channel/BookingControllerViewScope.java @@ -1189,9 +1189,7 @@ public void listCancelled() { public void addBillSessionData() { if (configOptionApplicationController.getBooleanValueByKey("Calculate All Patient Count When Loading Channel Booking By Dates")) { if (sessionInstancesFiltered != null) { - for (SessionInstance s : sessionInstances) { - fillBillSessions(s); - } + fillBillSessions(sessionInstancesFiltered); } } } @@ -4754,127 +4752,65 @@ public void fillBillSessions() { sessionInstanceController.save(selectedSessionInstance); } - public void fillBillSessions(SessionInstance s) { - List tempBillSessions; - BillType[] billTypes = { - BillType.ChannelAgent, - BillType.ChannelCash, - BillType.ChannelOnCall, - BillType.ChannelStaff, - BillType.ChannelCredit, - BillType.ChannelResheduleWithPayment, - BillType.ChannelResheduleWithOutPayment - }; - List 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 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 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 - - } + // 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 completion status - try { - if (bs.isCompleted()) { - completedPatientCount++; - } - } catch (NullPointerException npe) { - // Log or handle the fact that there was an NPE checking completion status - - } - - // 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 - - } - - // 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 - - } - - // 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 - - } + // Prepare the parameters + List sessionInstanceIds = sessionInstances.stream() + .map(SessionInstance::getId) + .collect(Collectors.toList()); + Map parameters = new HashMap<>(); + + // Execute the query + List results = billSessionFacade.findObjectsArrayByNativeQuery(sql, parameters, sessionInstanceIds); + + // Process the results + Map 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(); + + 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() { diff --git a/src/main/java/com/divudi/data/channel/PatientPortalController.java b/src/main/java/com/divudi/data/channel/PatientPortalController.java index 244a553406..d24a85f63f 100644 --- a/src/main/java/com/divudi/data/channel/PatientPortalController.java +++ b/src/main/java/com/divudi/data/channel/PatientPortalController.java @@ -36,13 +36,7 @@ import com.divudi.facade.SmsFacade; import com.divudi.facade.StaffFacade; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; +import java.util.*; import javax.ejb.EJB; import javax.inject.Named; import javax.enterprise.context.SessionScoped; @@ -142,7 +136,7 @@ public class PatientPortalController implements Serializable { private ChannelBean channelBean; public String navigateBookingMenue() { - bookingControllerViewScope.fillBillSessions(selectedSessionInstance); + bookingControllerViewScope.fillBillSessions(Collections.singletonList(selectedSessionInstance)); sessionInstances = null; selectedConsultant = null; selectedSpeciality = null; @@ -281,11 +275,8 @@ public void fillSessionInstance() { m.put("nextTwoDays", calendar.getTime()); sessionInstances = sessionInstanceFacade.findByJpql(jpql.toString(), m, TemporalType.DATE); - - for(SessionInstance s : sessionInstances){ - bookingControllerViewScope.fillBillSessions(s); - } - + + bookingControllerViewScope.fillBillSessions(sessionInstances); } public void otpCodeConverter() { diff --git a/src/main/java/com/divudi/facade/AbstractFacade.java b/src/main/java/com/divudi/facade/AbstractFacade.java index f1093bc4c3..8eb15793fd 100644 --- a/src/main/java/com/divudi/facade/AbstractFacade.java +++ b/src/main/java/com/divudi/facade/AbstractFacade.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import javax.persistence.EntityManager; import javax.persistence.NoResultException; import javax.persistence.NonUniqueResultException; @@ -447,6 +448,24 @@ public List findByJpql(String jpql, Map parameters, TemporalT return qry.getResultList(); } + public List findObjectsArrayByNativeQuery(String sql, Map parameters, List ids) { + // Construct the IN clause dynamically + String inClause = ids.stream() + .map(id -> "?") + .collect(Collectors.joining(", ")); + sql = sql.replace(":ids", inClause); + + Query query = getEntityManager().createNativeQuery(sql); + int index = 1; + for (Map.Entry entry : parameters.entrySet()) { + query.setParameter(index++, entry.getValue()); + } + for (Long id : ids) { + query.setParameter(index++, id); + } + return query.getResultList(); + } + public List findObjectsArrayByJpql(String jpql, Map parameters, TemporalType tt) { TypedQuery qry = getEntityManager().createQuery(jpql, Object[].class); Set s = parameters.entrySet();