From 68f5b357a15018afc5b64e2f01bb81526ca1c9d3 Mon Sep 17 00:00:00 2001 From: imexh Date: Thu, 19 Dec 2024 12:59:29 +0530 Subject: [PATCH] opd weekly detail report --- .../divudi/bean/common/ReportsController.java | 152 +++++++++++++- .../managementReports/opd_weekly.xhtml | 190 ++++++++---------- 2 files changed, 230 insertions(+), 112 deletions(-) diff --git a/src/main/java/com/divudi/bean/common/ReportsController.java b/src/main/java/com/divudi/bean/common/ReportsController.java index 9b6876a31a..dec2379736 100644 --- a/src/main/java/com/divudi/bean/common/ReportsController.java +++ b/src/main/java/com/divudi/bean/common/ReportsController.java @@ -309,6 +309,11 @@ public class ReportsController implements Serializable { private String settlementStatus; private String dischargedStatus; + // Map>> + Map>> weeklyDailyBillItemMap7to7; + Map>> weeklyDailyBillItemMap7to1; + Map>> weeklyDailyBillItemMap1to7; + public String getDischargedStatus() { return dischargedStatus; } @@ -322,11 +327,9 @@ public PaymentMethod getPaymentMethod() { return paymentMethod; } - public void setPaymentMethod(PaymentMethod paymentMethod) { this.paymentMethod = paymentMethod; } - public CommonController getCommonController() { return commonController; @@ -392,6 +395,30 @@ public void setAdmissionType(AdmissionType admissionType) { this.admissionType = admissionType; } + public Map>> getWeeklyDailyBillItemMap7to7() { + return weeklyDailyBillItemMap7to7; + } + + public void setWeeklyDailyBillItemMap7to7(Map>> weeklyDailyBillItemMap7to7) { + this.weeklyDailyBillItemMap7to7 = weeklyDailyBillItemMap7to7; + } + + public Map>> getWeeklyDailyBillItemMap7to1() { + return weeklyDailyBillItemMap7to1; + } + + public void setWeeklyDailyBillItemMap7to1(Map>> weeklyDailyBillItemMap7to1) { + this.weeklyDailyBillItemMap7to1 = weeklyDailyBillItemMap7to1; + } + + public Map>> getWeeklyDailyBillItemMap1to7() { + return weeklyDailyBillItemMap1to7; + } + + public void setWeeklyDailyBillItemMap1to7(Map>> weeklyDailyBillItemMap1to7) { + this.weeklyDailyBillItemMap1to7 = weeklyDailyBillItemMap1to7; + } + public PatientFacade getPatientFacade() { return patientFacade; } @@ -1747,7 +1774,120 @@ public void generateOPDWeeklyReport() { bundle = generateWeeklyBillItems(opdBts); - groupBillItemsWeekly(); + if (reportType.equalsIgnoreCase("summary")) { + groupBillItemsWeekly(); + } else if (reportType.equalsIgnoreCase("detail")) { + groupBillItemsDaily(); + } + } + + private void groupBillItemsDaily() { + // Map>> + Map>> weeklyBillItemMap7to7 = new HashMap<>(); + Map>> weeklyBillItemMap7to1 = new HashMap<>(); + Map>> weeklyBillItemMap1to7 = new HashMap<>(); + + for (ReportTemplateRow row : bundle.getReportTemplateRows()) { + final BillItem billItem = row.getBillItem(); + + final Date billItemDate = billItem.getBill().getCreatedAt(); + + if (billItemDate == null) { + continue; + } + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(billItemDate); + + final int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY); + final int weekOfMonth = getWeekOfMonth(billItemDate); + final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); + + if (hourOfDay >= 19 || hourOfDay < 7) { + // Between 7 PM to 7 AM + Map> billItemMap = weeklyBillItemMap7to7.containsKey(weekOfMonth) ? weeklyBillItemMap7to7.get(weekOfMonth) : new HashMap<>(); + + billItemMap.computeIfAbsent(billItem.getItem().getName(), k -> new HashMap<>()) + .put(dayOfMonth, billItemMap.get(billItem.getItem().getName()).getOrDefault(dayOfMonth, 0.0) + 1.0); + + weeklyBillItemMap7to7.put(weekOfMonth, billItemMap); + } else if (hourOfDay < 13) { + // Between 7 AM to 1 PM + Map> billItemMap = weeklyBillItemMap7to1.containsKey(weekOfMonth) ? weeklyBillItemMap7to1.get(weekOfMonth) : new HashMap<>(); + + billItemMap.computeIfAbsent(billItem.getItem().getName(), k -> new HashMap<>()) + .put(dayOfMonth, billItemMap.get(billItem.getItem().getName()).getOrDefault(dayOfMonth, 0.0) + 1.0); + + weeklyBillItemMap7to1.put(weekOfMonth, billItemMap); + } else { + // Between 1 PM to 7 PM + Map> billItemMap = weeklyBillItemMap1to7.containsKey(weekOfMonth) ? weeklyBillItemMap1to7.get(weekOfMonth) : new HashMap<>(); + + billItemMap.computeIfAbsent(billItem.getItem().getName(), k -> new HashMap<>()) + .put(dayOfMonth, billItemMap.get(billItem.getItem().getName()).getOrDefault(dayOfMonth, 0.0) + 1.0); + + weeklyBillItemMap1to7.put(weekOfMonth, billItemMap); + } + } + + setWeeklyDailyBillItemMap7to7(weeklyBillItemMap7to7); + setWeeklyDailyBillItemMap7to1(weeklyBillItemMap7to1); + setWeeklyDailyBillItemMap1to7(weeklyBillItemMap1to7); + } + + public List getItemListByWeek(final int week, final Map>> weeklyBillItemMap) { + if (weeklyBillItemMap == null) { + return new ArrayList<>(); + } + + List itemList = new ArrayList<>(); + + if (weeklyBillItemMap.containsKey(week)) { + itemList.addAll(weeklyBillItemMap.get(week).keySet()); + } + + return itemList; + } + + public double getCountByWeekAndDay(final int week, final int day, final String itemName, final Map>> weeklyBillItemMap) { + return Optional.ofNullable(weeklyBillItemMap) + .map(map -> map.get(week)) + .map(weekMap -> weekMap.get(itemName)) + .map(itemMap -> itemMap.get(day)) + .orElse(0.0); + } + + public double getSumByWeek(final int week, final String itemName, final Map>> weeklyBillItemMap) { + return Optional.ofNullable(weeklyBillItemMap) + .map(map -> map.get(week)) + .map(weekMap -> weekMap.get(itemName)) + .map(itemMap -> itemMap.values().stream().mapToDouble(Double::doubleValue).sum()) + .orElse(0.0); + } + + public List getDaysOfWeek(final int weekOfMonth) { + if (month == null) { + return new ArrayList<>(); + } + + final YearMonth yearMonth = YearMonth.of(LocalDate.now().getYear(), month); + + List daysOfWeek = new ArrayList<>(); + + LocalDate firstDayOfMonth = yearMonth.atDay(1); + int firstDayOfTargetWeek = (weekOfMonth - 1) * 7 + 1; + + for (int i = 0; i < 7; i++) { + LocalDate day = firstDayOfMonth.plusDays(firstDayOfTargetWeek - 1 + i); + + if (day.getMonth() != yearMonth.getMonth()) { + break; + } + + daysOfWeek.add(day.getDayOfMonth()); + } + + return daysOfWeek; } private void groupBillItemsWeekly() { @@ -2373,7 +2513,7 @@ public void generateDebtorBalanceReport(final boolean onlyDueBills) { } public ReportTemplateRowBundle generateDebtorBalanceReportBills(List bts, List billPaymentMethods, - boolean onlyDueBills) { + boolean onlyDueBills) { Map parameters = new HashMap<>(); String jpql = "SELECT new com.divudi.data.ReportTemplateRow(bill) " + "FROM Bill bill " @@ -3245,7 +3385,7 @@ private void groupBills() { bundle.setGroupedBillItemsByInstitution(billMap); } - + public Double calculateNetTotalByBills(List bills) { Double netTotal = 0.0; @@ -3266,7 +3406,7 @@ public Double calculateDiscountByBills(List bills) { return discount; } - + public Double calculateSubTotal() { double subTotal = 0.0; Map> billMap = bundle.getGroupedBillItemsByInstitution(); diff --git a/src/main/webapp/reports/managementReports/opd_weekly.xhtml b/src/main/webapp/reports/managementReports/opd_weekly.xhtml index 9544c92f4b..7e11c99fec 100644 --- a/src/main/webapp/reports/managementReports/opd_weekly.xhtml +++ b/src/main/webapp/reports/managementReports/opd_weekly.xhtml @@ -5,7 +5,7 @@ xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:p="http://primefaces.org/ui" - xmlns:f="http://xmlns.jcp.org/jsf/core"> + xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core"> @@ -267,114 +267,92 @@ - - - - -
- - -
- - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + + +
+ + +
+ +
+ + + + + + + + + +
+ - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + +