Skip to content

Commit

Permalink
Merge pull request #8753 from hmislk/Issue#8507
Browse files Browse the repository at this point in the history
Issue#8507  Closes #8507
  • Loading branch information
Irani96 authored Nov 14, 2024
2 parents 0424dbf + 423f70a commit 4adf9f9
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 84 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.divudi</groupId>
<artifactId>rh</artifactId>
<artifactId>ruhunu</artifactId>
<version>3.0.0</version>
<packaging>war</packaging>
<name>rh</name>
<name>ruhunu</name>

<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.divudi.data.Title;
import com.divudi.data.dataStructure.DateRange;
import com.divudi.data.dataStructure.YearMonthDay;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
import javax.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -59,6 +61,13 @@ public String capitalizeFirstLetter(String str) {
}
return result.toString().trim();
}

public static String getDateTimeFormat(Date date) {
String s = "";
DateFormat d = new SimpleDateFormat("YYYY-MM-dd hh:mm:ss a");
s = d.format(date);
return s;
}

public DateRange getDateRangeForOT(Date date) {
DateRange dateRange = new DateRange();
Expand Down
71 changes: 62 additions & 9 deletions src/main/java/com/divudi/bean/common/PdfController.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public class PdfController {
CommonReportItemController commonReportItemController;
@Inject
PatientInvestigationController patientInvestigationController;
@Inject
SearchController searchController;

/**
* Creates a new instance of PdfController
Expand Down Expand Up @@ -760,7 +762,7 @@ public StreamedContent createPdfForBundle(ReportTemplateRowBundle rootBundle) th

// Set the downloading file
return DefaultStreamedContent.builder()
.name("bundle_report.pdf")
.name("Bundle_Report.pdf")
.contentType("application/pdf")
.stream(() -> inputStream)
.build();
Expand All @@ -772,7 +774,7 @@ private void addDataToPdf(Document document, ReportTemplateRowBundle addingBundl
}

// Create a new Table for each call
Table table = new Table(new float[]{10, 40, 15, 15, 10, 10});
Table table = new Table(new float[]{10, 40, 15, 15, 10, 10});
table.setWidth(200);

switch (type) {
Expand Down Expand Up @@ -818,8 +820,11 @@ private void addDataToPdf(Document document, ReportTemplateRowBundle addingBundl
case "netCash":
populateTitleBundleForPdf(document, addingBundle);
break;
case "income_breakdown_by_category":
populateTableForIncomeByCategory(document, addingBundle);
case "income_breakdown_by_category_with_professional_fee":
populateTableForIncomeByCategoryWithProfessionalFee(document, addingBundle);
break;
case "income_breakdown_by_category_with_out_professional_fee":
populateTableForIncomeByCategoryWithoutProfessionalFee(document, addingBundle);
break;
default:
table.addCell(new Cell().add(new Paragraph("Data for unknown type"))); // Default handling for unknown types
Expand Down Expand Up @@ -1160,12 +1165,15 @@ private void populateTableForItemSummaryGroupedByCategory(Document document, Rep
document.add(noDataParagraph);
}
}

private void populateTableForIncomeByCategory(Document document, ReportTemplateRowBundle addingBundle) {
@Inject
CommonFunctionsController commonFunctionsController;

private void populateTableForIncomeByCategoryWithProfessionalFee(Document document, ReportTemplateRowBundle addingBundle) {
if (addingBundle.getReportTemplateRows() != null && !addingBundle.getReportTemplateRows().isEmpty()) {

document.add(new Paragraph(addingBundle.getName()));

document.add(new Paragraph(commonFunctionsController.getDateTimeFormat(searchController.getFromDate()) + " to " + commonFunctionsController.getDateTimeFormat(searchController.getToDate())));

Table table = new Table(new float[]{55, 20, 25, 25, 25, 25, 25});
table.setWidth(UnitValue.createPercentValue(100));

Expand All @@ -1174,7 +1182,8 @@ private void populateTableForIncomeByCategory(Document document, ReportTemplateR
for (String header : headers) {
table.addHeaderCell(new com.itextpdf.layout.element.Cell().add(new Paragraph(header)));
}


table.addFooterCell(new com.itextpdf.layout.element.Cell(1, 6).add(new Paragraph("Total")));
table.addFooterCell(new Paragraph(String.format("%.2f", addingBundle.getTotal())));

// Populate table with data rows
Expand Down Expand Up @@ -1204,6 +1213,50 @@ private void populateTableForIncomeByCategory(Document document, ReportTemplateR
}
}


private void populateTableForIncomeByCategoryWithoutProfessionalFee(Document document, ReportTemplateRowBundle addingBundle) {
if (addingBundle.getReportTemplateRows() != null && !addingBundle.getReportTemplateRows().isEmpty()) {

document.add(new Paragraph(addingBundle.getName()));
document.add(new Paragraph(commonFunctionsController.getDateTimeFormat(searchController.getFromDate()) + " to " + commonFunctionsController.getDateTimeFormat(searchController.getToDate())));

Table table = new Table(new float[]{55, 20, 25, 25, 25, 25});
table.setWidth(UnitValue.createPercentValue(100));

// Add headers
String[] headers = {"Category", "Count", "Gross Value", "Hospital Fee", "Discount", "Net Amount"};
for (String header : headers) {
table.addHeaderCell(new com.itextpdf.layout.element.Cell().add(new Paragraph(header)));
}

table.addFooterCell(new com.itextpdf.layout.element.Cell(1, 5).add(new Paragraph("Total")));
table.addFooterCell(new Paragraph(String.format("%.2f", addingBundle.getTotal())));

// Populate table with data rows
for (ReportTemplateRow row : addingBundle.getReportTemplateRows()) {
table.addCell(new com.itextpdf.layout.element.Cell().add(new Paragraph(
row.getCategory() != null ? row.getCategory().getName() : "")));
table.addCell(new com.itextpdf.layout.element.Cell().add(new Paragraph(
String.valueOf(row.getItemCount()))));
table.addCell(new com.itextpdf.layout.element.Cell().add(new Paragraph(
String.format("%.2f", row.getItemTotal())))); // Format as string
table.addCell(new com.itextpdf.layout.element.Cell().add(new Paragraph(
String.format("%.2f", row.getItemHospitalFee())))); // Format as string
table.addCell(new com.itextpdf.layout.element.Cell().add(new Paragraph(
String.format("%.2f", row.getItemDiscountAmount())))); // Format as string
table.addCell(new com.itextpdf.layout.element.Cell().add(new Paragraph(
String.format("%.2f", row.getItemNetTotal())))); // Format as string
}

// Add the table to the document
document.add(table);
} else {
// Add a paragraph for no data
Paragraph noDataParagraph = new Paragraph("No Data for " + addingBundle.getName());
document.add(noDataParagraph);
}
}

private void populateTableForDepartmentCollection(Document document, ReportTemplateRowBundle addingBundle) {
if (addingBundle.getReportTemplateRows() == null || addingBundle.getReportTemplateRows().isEmpty()) {
// If no data, add a paragraph stating this
Expand Down
136 changes: 75 additions & 61 deletions src/main/java/com/divudi/bean/common/SearchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12853,7 +12853,11 @@ public void createItemizedSalesReportOpd() {
}

public void createIncomeBreakdownByCategory() {
bundle = generateIncomeBreakdownByCategory();
if(withProfessionalFee){
bundle = generateIncomeBreakdownByCategoryWithProfessionalFee();
}else{
bundle = generateIncomeBreakdownByCategoryWithOutProfessionalFee();
}
}

public void generateDailyReturn() {
Expand Down Expand Up @@ -14070,7 +14074,7 @@ public void billItemsToItamizedSaleSummary(ReportTemplateRowBundle rtrb, List<Bi
@Inject
EnumController enumController;

public ReportTemplateRowBundle generateIncomeBreakdownByCategory() {
public ReportTemplateRowBundle generateIncomeBreakdownByCategoryWithProfessionalFee() {
ReportTemplateRowBundle oiBundle = new ReportTemplateRowBundle();
String jpql = "select bi "
+ " from BillItem bi "
Expand Down Expand Up @@ -14209,8 +14213,8 @@ public ReportTemplateRowBundle generateIncomeBreakdownByCategory() {

summarizeBillItemsToIncomeByCategory(oiBundle, bis);

oiBundle.setName("Income Breakdown By Category");
oiBundle.setBundleType("income_breakdown_by_category");
oiBundle.setName("Income Breakdown By Category - With Professional Fee");
oiBundle.setBundleType("income_breakdown_by_category_with_professional_fee");

oiBundle.getReportTemplateRows().stream()
.forEach(rtr -> {
Expand All @@ -14224,33 +14228,35 @@ public ReportTemplateRowBundle generateIncomeBreakdownByCategory() {
return oiBundle;
}

@Deprecated
public ReportTemplateRowBundle generateIncomeBreakdownByCategoryOpdWithoutProfessionalFee() {
public ReportTemplateRowBundle generateIncomeBreakdownByCategoryWithOutProfessionalFee() {
ReportTemplateRowBundle oiBundle = new ReportTemplateRowBundle();
String jpql = "select bi "
+ " from BillItem bi "
+ " where bi.bill.retired=:br "
+ " and bi.bill.createdAt between :fd and :td ";
Map<String, Object> m = new HashMap<>();
Map m = new HashMap();
m.put("br", false);
m.put("fd", fromDate);
m.put("td", toDate);

List<BillTypeAtomic> btas = new ArrayList<>();
List<BillTypeAtomic> btas = new ArrayList();

List<BillTypeAtomic> obtas = BillTypeAtomic.findByServiceType(ServiceType.OPD);
List<BillTypeAtomic> ibtas = BillTypeAtomic.findByServiceType(ServiceType.INWARD);

if (visitType != null) {
if (null != visitType) {
switch (visitType) {
case "Any":
System.out.println("Any");
btas.addAll(obtas);
btas.addAll(ibtas);
break;
case "OP":
System.out.println("OPD");
btas.addAll(obtas);
break;
case "IP":
System.out.println("IP");
btas.addAll(ibtas);
break;
default:
Expand All @@ -14264,58 +14270,66 @@ public ReportTemplateRowBundle generateIncomeBreakdownByCategoryOpdWithoutProfes
m.put("bts", btas);
}

// Define credit and non-credit payment methods
List<PaymentMethod> creditPaymentMethods = Arrays.asList(
PaymentMethod.Credit,
PaymentMethod.Staff
// Add any other credit payment methods used in your system
);
List<PaymentMethod> creditPaymentMethods = enumController.getPaymentTypeOfPaymentMethods(PaymentType.CREDIT);
List<PaymentMethod> nonCreditPaymentMethods = enumController.getPaymentTypeOfPaymentMethods(PaymentType.NON_CREDIT);

List<PaymentMethod> nonCreditPaymentMethods = Arrays.asList(
PaymentMethod.Cash,
PaymentMethod.Card,
PaymentMethod.Cheque,
PaymentMethod.Slip,
PaymentMethod.ewallet,
PaymentMethod.Voucher,
PaymentMethod.Agent,
PaymentMethod.PatientDeposit,
PaymentMethod.PatientPoints,
PaymentMethod.OnlineSettlement,
PaymentMethod.YouOweMe
// Add any other non-credit payment methods
);

System.out.println("methodType = " + methodType);
System.out.println("visitType = " + visitType);

if (methodType != null) {
switch (methodType) {
case "Any":
// No additional conditions needed
break;
case "Credit":
// jpql += " AND ("
// + " (bi.bill.paymentMethod in :cpm) "
// + " OR "
// + " (bi.bill.patientEncounter is not null AND bi.bill.patientEncounter.paymentMethod in :cpm) "
// + ")";
List<PaymentMethod> allMethods = new ArrayDeque();
allMethods.addAll(creditPaymentMethods);
allMethods.addAll(nonCreditPaymentMethods);

jpql += " AND bi.bill.paymentMethod in :cpm ";
if ("Any".equals(methodType)) {
System.out.println("Any");
} else if ("Credit".equals(methodType)) {
System.out.println("Credit");

m.put("cpm", creditPaymentMethods);
break;
case "NonCredit":
jpql += " AND ("
+ " (bi.bill.paymentMethod in :ncpm) "
+ " OR "
+ " (bi.bill.patientEncounter is not null AND bi.bill.patientEncounter.paymentMethod in :ncpm) "
+ ")";
m.put("ncpm", nonCreditPaymentMethods);
break;
default:
break;
if (null != visitType) {
switch (visitType) {
case "Any":
System.out.println("Credit Any");
jpql += " AND (bi.bill.paymentMethod in :apm OR bi.bill.patientEncounter.paymentMethod in :apm)";
m.put("apm", allMethods);
break;
case "OP":
System.out.println("Credit OP");
jpql += " AND bi.bill.paymentMethod in :cpm ";
m.put("cpm", creditPaymentMethods);
break;
case "IP":
System.out.println("Credit IP");
jpql += " AND bi.bill.patientEncounter.paymentMethod in :cpm ";
m.put("cpm", creditPaymentMethods);
break;
default:
break;
}
}

} else if ("NonCredit".equals(methodType)) {
System.out.println("Non Credit");

if (null != visitType) {
switch (visitType) {
case "Any":
System.out.println("Credit Any");
System.out.println("Credit Any");
jpql += " AND (bi.bill.paymentMethod in :apm OR bi.bill.patientEncounter.paymentMethod in :apm)";
m.put("apm", allMethods);
break;
case "OP":
System.out.println("Credit OP");
jpql += " AND bi.bill.paymentMethod in :ncpm ";
m.put("ncpm", nonCreditPaymentMethods);
break;
case "IP":
System.out.println("Credit IP");
jpql += " AND bi.bill.patientEncounter.paymentMethod in :ncpm ";
m.put("ncpm", nonCreditPaymentMethods);
break;
default:
break;
}
}

}

if (department != null) {
Expand All @@ -14334,7 +14348,6 @@ public ReportTemplateRowBundle generateIncomeBreakdownByCategoryOpdWithoutProfes
jpql += " and bi.item.category=:cat ";
m.put("cat", category);
}

System.out.println("jpql = " + jpql);
System.out.println("m = " + m);

Expand All @@ -14352,10 +14365,10 @@ public ReportTemplateRowBundle generateIncomeBreakdownByCategoryOpdWithoutProfes
}
}

summarizeBillItemsToIncomeByCategoryWithoutProfessionalFee(oiBundle, bis);
summarizeBillItemsToIncomeByCategory(oiBundle, bis);

oiBundle.setName("Income Breakdown By Category Without Professional Fee");
oiBundle.setBundleType("income_breakdown_by_category");
oiBundle.setName("Income Breakdown By Category - Without Professional Fee");
oiBundle.setBundleType("income_breakdown_by_category_with_out_professional_fee");

oiBundle.getReportTemplateRows().stream()
.forEach(rtr -> {
Expand All @@ -14369,6 +14382,7 @@ public ReportTemplateRowBundle generateIncomeBreakdownByCategoryOpdWithoutProfes
return oiBundle;
}


public ReportTemplateRowBundle generateOpdProfessionalFees(String paymentStatusStr) {
PaymentStatus paymentStatus = PaymentStatus.ALL;
if (paymentStatusStr != null) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/divudi/ws/common/ApplicationConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public Set<Class<?>> getClasses() {
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(com.divudi.ws.channel.ChannelApi.class);
resources.add(com.divudi.ws.channel.CorsResponseFilter.class);
resources.add(com.divudi.ws.common.ApiMembership.class);
resources.add(com.divudi.ws.common.ConfigResource.class);
resources.add(com.divudi.ws.fhir.Fhir.class);
resources.add(com.divudi.ws.finance.Finance.class);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/.LCKpersistence.xml~
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
D:\CC\hmis\src\main\resources\META-INF\persistence.xml
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</properties>
</persistence-unit>
<persistence-unit name="hmisAuditPU" transaction-type="JTA">
<jta-data-source>jdbc/ruhunuaudit</jta-data-source>
<jta-data-source>jdbc/ruhunuAudit</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.level.sql" value="SEVERE"/>
Expand Down
Loading

0 comments on commit 4adf9f9

Please sign in to comment.