Skip to content

Commit

Permalink
Merge pull request #9841 from hmislk/update_the_pharmacy_income_repor…
Browse files Browse the repository at this point in the history
…t_with_new_bill_type_atomics_#9838

Update the pharmacy income report with new bill type atomics #9838  Closes #9838
  • Loading branch information
Irani96 authored Dec 24, 2024
2 parents ba17786 + ca9044c commit 0184d03
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 22 deletions.
145 changes: 140 additions & 5 deletions src/main/java/com/divudi/bean/common/ReportsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ public void setDischargedStatus(String dischargedStatus) {
this.dischargedStatus = dischargedStatus;
}


public PaymentMethod getPaymentMethod() {
return paymentMethod;
}
Expand Down Expand Up @@ -1652,7 +1651,6 @@ public void generateSampleCarrierReport() {
private ReportTemplateRowBundle generateSampleCarrierBillItems(List<BillTypeAtomic> bts) {
Map<String, Object> parameters = new HashMap<>();


String jpql = "SELECT new com.divudi.data.ReportTemplateRow(pi) "
+ "FROM PatientInvestigation pi "
+ "JOIN pi.billItem billItem "
Expand All @@ -1661,7 +1659,6 @@ private ReportTemplateRowBundle generateSampleCarrierBillItems(List<BillTypeAtom
+ " and billItem.retired=false "
+ " and bill.retired=false ";


jpql += "AND bill.billTypeAtomic in :bts ";
parameters.put("bts", bts);

Expand Down Expand Up @@ -2617,7 +2614,7 @@ public void generateDebtorBalanceReport(final boolean onlyDueBills) {
}

public ReportTemplateRowBundle generateDebtorBalanceReportBills(List<BillTypeAtomic> bts, List<PaymentMethod> billPaymentMethods,
boolean onlyDueBills) {
boolean onlyDueBills) {
Map<String, Object> parameters = new HashMap<>();
String jpql = "SELECT new com.divudi.data.ReportTemplateRow(bill) "
+ "FROM Bill bill "
Expand Down Expand Up @@ -3140,7 +3137,6 @@ private ReportTemplateRowBundle generateExternalLaboratoryWorkloadBillItems(List
// + "LEFT JOIN PatientInvestigation pi ON pi.billItem = billItem "
// + "WHERE bill.billTypeAtomic IN :bts "
// + "AND bill.createdAt BETWEEN :fd AND :td ";

String jpql = "SELECT new com.divudi.data.ReportTemplateRow(billItem) "
+ "FROM PatientInvestigation pi "
+ "JOIN pi.billItem billItem "
Expand Down Expand Up @@ -3644,6 +3640,144 @@ public Double calculateSponsorShareNetTotal() {
return subTotal;
}

public Double calculateNetAmountNetTotal() {
double netAmountNetTotal = 0.0;
Map<Institution, List<Bill>> billMap = bundle.getGroupedBillItemsByInstitution();

for (Map.Entry<Institution, List<Bill>> entry : billMap.entrySet()) {
List<Bill> bills = entry.getValue();

netAmountNetTotal += calculateNetAmountSubTotalByBills(bills);
}

return netAmountNetTotal;
}

public Double calculateNetAmountSubTotalByBills(List<Bill> bills) {
Double netTotal = 0.0;

for (Bill bill : bills) {
netTotal += bill.getNetTotal();
}

return netTotal;
}

public Double calculateGrossAmountSubTotalByBills(List<Bill> bills) {
Double billTotal = 0.0;

for (Bill bill : bills) {
billTotal += bill.getBillTotal();
}

return billTotal;
}

public Double calculatePatientShareSubTotalByBills(List<Bill> bills) {
Double settledAmountByPatient = 0.0;

for (Bill bill : bills) {
settledAmountByPatient += bill.getSettledAmountByPatient();
}

return settledAmountByPatient;
}

public Double calculateSponsorShareSubTotalByBills(List<Bill> bills) {
Double settledAmountBySponsor = 0.0;

for (Bill bill : bills) {
settledAmountBySponsor += bill.getSettledAmountBySponsor();
}

return settledAmountBySponsor;
}

public Double calculateDueAmountSubTotalByBills(List<Bill> bills) {
Double balance = 0.0;

for (Bill bill : bills) {
balance += bill.getBalance();
}

return balance;
}

public Double calculateGrossAmountNetTotal() {
double grossAmountNetTotal = 0.0;
Map<Institution, List<Bill>> billMap = bundle.getGroupedBillItemsByInstitution();

for (Map.Entry<Institution, List<Bill>> entry : billMap.entrySet()) {
List<Bill> bills = entry.getValue();

grossAmountNetTotal += calculateGrossAmountSubTotalByBills(bills);
}

return grossAmountNetTotal;
}

public Double calculateDiscountNetTotal() {
double discountNetTotal = 0.0;
Map<Institution, List<Bill>> billMap = bundle.getGroupedBillItemsByInstitution();

for (Map.Entry<Institution, List<Bill>> entry : billMap.entrySet()) {
List<Bill> bills = entry.getValue();

discountNetTotal += calculateDiscountSubTotalByBills(bills);
}

return discountNetTotal;
}

public Double calculateDiscountSubTotalByBills(List<Bill> bills) {
Double discount = 0.0;

for (Bill bill : bills) {
discount += bill.getDiscount();
}

return discount;
}

public Double calculatePatientShareNetTotal() {
double patientShareNetTotal = 0.0;
Map<Institution, List<Bill>> billMap = bundle.getGroupedBillItemsByInstitution();

for (Map.Entry<Institution, List<Bill>> entry : billMap.entrySet()) {
List<Bill> bills = entry.getValue();

patientShareNetTotal += calculatePatientShareSubTotalByBills(bills);
}

return patientShareNetTotal;
}

public Double calculateDueAmountNetTotal() {
double dueAmountNetTotal = 0.0;
Map<Institution, List<Bill>> billMap = bundle.getGroupedBillItemsByInstitution();

for (Map.Entry<Institution, List<Bill>> entry : billMap.entrySet()) {
List<Bill> bills = entry.getValue();

dueAmountNetTotal += calculateDueAmountSubTotalByBills(bills);
}

return dueAmountNetTotal;
}

public Double calculateSponsorShareNetTotal() {
double sponsorShareNetTotal = 0.0;
Map<Institution, List<Bill>> billMap = bundle.getGroupedBillItemsByInstitution();

for (Map.Entry<Institution, List<Bill>> entry : billMap.entrySet()) {
List<Bill> bills = entry.getValue();

sponsorShareNetTotal += calculateSponsorShareSubTotalByBills(bills);
}

return sponsorShareNetTotal;
}

public void generateDiscountReport() {
if (visitType == null || visitType.trim().isEmpty()) {
JsfUtil.addErrorMessage("Please select a visit type");
Expand Down Expand Up @@ -3984,6 +4118,7 @@ public void exportCollectionCenterBillWiseDetailReportToExcel() {
try (XSSFWorkbook workbook = new XSSFWorkbook();
OutputStream out = response.getOutputStream()) {


XSSFSheet sheet = workbook.createSheet("Report");
int rowIndex = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public void resetAllFilters() {
}

public void processPharmacyIncomeReport() {
System.out.println("processPharmacyIncomeReport");
List<BillTypeAtomic> billTypeAtomics = new ArrayList<>();
billTypeAtomics.add(BillTypeAtomic.PHARMACY_RETAIL_SALE);
billTypeAtomics.add(BillTypeAtomic.PHARMACY_RETAIL_SALE_CANCELLED);
Expand All @@ -242,6 +243,18 @@ public void processPharmacyIncomeReport() {
billTypeAtomics.add(BillTypeAtomic.PHARMACY_WHOLESALE_CANCELLED);
billTypeAtomics.add(BillTypeAtomic.PHARMACY_WHOLESALE_PRE);
billTypeAtomics.add(BillTypeAtomic.PHARMACY_WHOLESALE_REFUND);
billTypeAtomics.add(BillTypeAtomic.DIRECT_ISSUE_INWARD_MEDICINE);
billTypeAtomics.add(BillTypeAtomic.DIRECT_ISSUE_INWARD_MEDICINE_CANCELLATION);
billTypeAtomics.add(BillTypeAtomic.DIRECT_ISSUE_INWARD_MEDICINE_RETURN);
billTypeAtomics.add(BillTypeAtomic.DIRECT_ISSUE_THEATRE_MEDICINE);
billTypeAtomics.add(BillTypeAtomic.DIRECT_ISSUE_THEATRE_MEDICINE_CANCELLATION);
billTypeAtomics.add(BillTypeAtomic.DIRECT_ISSUE_THEATRE_MEDICINE_RETURN);
billTypeAtomics.add(BillTypeAtomic.ISSUE_MEDICINE_ON_REQUEST_INWARD);
billTypeAtomics.add(BillTypeAtomic.ISSUE_MEDICINE_ON_REQUEST_INWARD_CANCELLATION);
billTypeAtomics.add(BillTypeAtomic.ISSUE_MEDICINE_ON_REQUEST_THEATRE);
billTypeAtomics.add(BillTypeAtomic.ISSUE_MEDICINE_ON_REQUEST_THEATRE_CANCELLATION);
billTypeAtomics.add(BillTypeAtomic.ACCEPT_RETURN_MEDICINE_INWARD);
billTypeAtomics.add(BillTypeAtomic.ACCEPT_RETURN_MEDICINE_THEATRE);

List<Bill> bills = billService.fetchBills(fromDate, toDate, institution, site, department, webUser, billTypeAtomics);
bundle = new IncomeBundle(bills);
Expand All @@ -252,7 +265,7 @@ public void processPharmacyIncomeReport() {
if (r.getBill().getPaymentMethod() == null) {
continue;
}
if(r.getBill().getPaymentMethod().equals(PaymentMethod.MultiplePaymentMethods)){
if (r.getBill().getPaymentMethod().equals(PaymentMethod.MultiplePaymentMethods)) {
r.setPayments(billService.fetchBillPayments(r.getBill()));
}
}
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/com/divudi/data/IncomeBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,18 @@ public void generatePaymentDetailsForBills() {
r.setNetTotal(b.getNetTotal());
r.setDiscount(b.getDiscount());
r.setActualTotal(b.getNetTotal() - b.getServiceCharge());

if (b.getPaymentMethod() == null) {
r.setNoneValue(b.getNetTotal());
r.setCreditValue(b.getNetTotal());
if (r.getBill().getPatientEncounter() != null) {
r.setOpdCreditValue(0);
r.setInpatientCreditValue(b.getNetTotal());
} else {
r.setOpdCreditValue(0);
r.setInpatientCreditValue(0);
r.setNoneValue(b.getNetTotal());
}

} else {
switch (b.getPaymentMethod()) {
case Agent:
Expand All @@ -261,7 +270,7 @@ public void generatePaymentDetailsForBills() {
break;
case Credit:
r.setCreditValue(b.getNetTotal());
if (r.getBill().getPatientEncounter() == null) {
if (r.getBill().getPatientEncounter() != null) {
r.setOpdCreditValue(0);
r.setInpatientCreditValue(b.getNetTotal());
} else {
Expand Down Expand Up @@ -301,7 +310,7 @@ public void generatePaymentDetailsForBills() {
}

}

}
populateSummaryRow();
}
Expand Down Expand Up @@ -336,10 +345,10 @@ private void calculateBillPaymentValuesFromPayments(IncomeRow r) {
break;
case Credit:
r.setCreditValue(r.getCreditValue() + p.getPaidValue());
if (r.getBill().getPatientEncounter() == null) {
r.setOpdCreditValue(r.getOpdCreditValue() + p.getPaidValue());
} else {
if (r.getBill().getPatientEncounter() != null) {
r.setInpatientCreditValue(r.getInpatientCreditValue() + p.getPaidValue());
} else {
r.setOpdCreditValue(r.getOpdCreditValue() + p.getPaidValue());
}
break;
case IOU:
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/divudi/service/BillService.java
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,10 @@ public List<Bill> fetchBills(Date fromDate,
}

jpql += " order by b.createdAt desc ";

return billFacade.findByJpql(jpql, params, TemporalType.TIMESTAMP);
System.out.println("params = " + params);
System.out.println("jpql = " + jpql);
List<Bill> fetchedBills = billFacade.findByJpql(jpql, params, TemporalType.TIMESTAMP);
System.out.println("fetchedBills = " + fetchedBills);
return fetchedBills;
}
}
4 changes: 2 additions & 2 deletions src/main/webapp/pharmacy/pharmacy_analytics.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<p:panel header="Pharmacy Analytics" >
<div class="row">
<div class="col-md-3">
<div class="col-md-2">
<h:form>
<p:accordionPanel activeIndex="#{pharmacyController.managePharamcyReportIndex}">
<p:ajax process="@this"></p:ajax>
Expand Down Expand Up @@ -297,7 +297,7 @@
</p:accordionPanel>
</h:form>
</div>
<div class="col-md-9">
<div class="col-md-10">
<ui:insert name="subcontent">

</ui:insert>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@
<p:printer target="tbl" />
</p:commandButton>



<p:dataTable
id="tbl"
styleClass="ui-datatable-borderless ui-datatable-sm compact-datatable"
value="#{pharmacySummaryReportController.bundle.rows}" var="row"
paginator="true" rows="10" rowsPerPageTemplate="5,10,15,50,100,500,1000,2000,5000,10000"
paginatorPosition="bottom">
Expand Down Expand Up @@ -232,7 +233,7 @@
</f:facet>

</p:column>
<p:column headerText="Inpatient Credit" class="text-end bg-secondary text-white">
<p:column headerText="Inpatient Credit" class="text-end light-grey-background">
<h:outputText value="#{row.inpatientCreditValue}">
<f:convertNumber pattern="#,##0.00" />
</h:outputText>
Expand All @@ -243,7 +244,7 @@
</f:facet>

</p:column>
<p:column headerText="Outpatient Credit" class="text-end bg-secondary text-white">
<p:column headerText="Outpatient Credit" class="text-end light-grey-background">
<h:outputText value="#{row.opdCreditValue}">
<f:convertNumber pattern="#,##0.00" />
</h:outputText>
Expand All @@ -254,7 +255,7 @@
</f:facet>

</p:column>
<p:column headerText="Staff Credit" class="text-end bg-secondary text-white" >
<p:column headerText="Staff Credit" class="text-end light-grey-background" >
<h:outputText value="#{row.staffValue}">
<f:convertNumber pattern="#,##0.00" />
</h:outputText>
Expand All @@ -265,7 +266,7 @@
</f:facet>

</p:column>
<p:column headerText="Agent Credit" class="text-end bg-secondary text-white" >
<p:column headerText="Agent Credit" class="text-end light-grey-background" >
<h:outputText value="#{row.agentValue}">
<f:convertNumber pattern="#,##0.00" />
</h:outputText>
Expand Down
Loading

0 comments on commit 0184d03

Please sign in to comment.