diff --git a/src/main/java/com/divudi/ws/lims/LimsMiddlewareController.java b/src/main/java/com/divudi/ws/lims/LimsMiddlewareController.java index 8a81c18d62d..12d85c35cf4 100644 --- a/src/main/java/com/divudi/ws/lims/LimsMiddlewareController.java +++ b/src/main/java/com/divudi/ws/lims/LimsMiddlewareController.java @@ -100,7 +100,7 @@ public class LimsMiddlewareController { @EJB PatientInvestigationFacade patientInvestigationFacade; @EJB - private BillFacade billFacade; + BillFacade billFacade; @EJB PatientReportFacade prFacade; @EJB @@ -1022,6 +1022,10 @@ public boolean addResultToReport(String sampleId, String testCodeFromUploadedDat if (ptixs == null || ptixs.isEmpty()) { return temFlag; } + + List valuesToCreate = new ArrayList<>(); + List valuesToEdit = new ArrayList<>(); + for (PatientInvestigation pi : ptixs) { // // System.out.println("Patient Investigation = " + pi.getInvestigation()); @@ -1104,9 +1108,9 @@ public boolean addResultToReport(String sampleId, String testCodeFromUploadedDat priv.setFileName(fileName); if (priv.getId() == null) { - patientReportItemValueFacade.create(priv); + valuesToCreate.add(priv); } else { - patientReportItemValueFacade.edit(priv); + valuesToEdit.add(priv); } temFlag = true; valueToSave = true; @@ -1152,10 +1156,10 @@ public boolean addResultToReport(String sampleId, String testCodeFromUploadedDat // // System.out.println("0 priv.getDoubleValue() = " + priv.getDoubleValue()); if (priv.getId() == null) { // // System.out.println("0 new priv created = " + dbl); - patientReportItemValueFacade.create(priv); + valuesToCreate.add(priv); } else { // // System.out.println("0 new priv Updates = " + dbl); - patientReportItemValueFacade.edit(priv); + valuesToEdit.add(priv); } temFlag = true; valueToSave = true; @@ -1178,11 +1182,11 @@ public boolean addResultToReport(String sampleId, String testCodeFromUploadedDat // // System.out.println("priv double value " + priv.getDoubleValue()); // // System.out.println("priv Str value = " + priv.getStrValue()); if (priv.getId() == null) { - patientReportItemValueFacade.create(priv); + valuesToCreate.add(priv); // // System.out.println("1 new priv created = " + dbl); } else { // // System.out.println("1 new priv Updates = " + dbl); - patientReportItemValueFacade.edit(priv); + valuesToEdit.add(priv); } valueToSave = true; temFlag = true; @@ -1200,10 +1204,10 @@ public boolean addResultToReport(String sampleId, String testCodeFromUploadedDat // // System.out.println("2 priv.getDoubleValue() = " + priv.getDoubleValue()); if (priv.getId() == null) { // // System.out.println("2 new priv created = " + dbl); - patientReportItemValueFacade.create(priv); + valuesToCreate.add(priv); } else { // // System.out.println("2 new priv Updates = " + dbl); - patientReportItemValueFacade.edit(priv); + valuesToEdit.add(priv); } temFlag = true; valueToSave = true; @@ -1245,6 +1249,13 @@ public boolean addResultToReport(String sampleId, String testCodeFromUploadedDat billFacade.edit(b); } + if (!valuesToCreate.isEmpty()) { + patientReportItemValueFacade.batchCreate(valuesToCreate); + } + if (!valuesToEdit.isEmpty()) { + patientReportItemValueFacade.batchEdit(valuesToEdit); + } + return temFlag; } @@ -1752,7 +1763,7 @@ public PatientReport getUnsavedPatientReport(PatientInvestigation pi) { return r; } - private List getPatientInvestigations(List pscs) { + public List getPatientInvestigations(List pscs) { Set ptixhs = new HashSet<>(); for (PatientSampleComponant psc : pscs) { ptixhs.add(psc.getPatientInvestigation()); diff --git a/src/test/java/com/divudi/ws/lims/LimsBenchmark.java b/src/test/java/com/divudi/ws/lims/LimsBenchmark.java new file mode 100644 index 00000000000..6ab8e691095 --- /dev/null +++ b/src/test/java/com/divudi/ws/lims/LimsBenchmark.java @@ -0,0 +1,160 @@ +package com.divudi.ws.lims; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.Date; + +import com.divudi.core.entity.Patient; +import com.divudi.core.entity.lab.Investigation; +import com.divudi.core.entity.lab.InvestigationItem; +import com.divudi.core.entity.lab.PatientInvestigation; +import com.divudi.core.entity.lab.PatientReport; +import com.divudi.core.entity.lab.PatientReportItemValue; +import com.divudi.core.entity.lab.PatientSample; +import com.divudi.core.entity.lab.PatientSampleComponant; +import com.divudi.core.data.InvestigationItemType; +import com.divudi.core.entity.Item; +import com.divudi.core.entity.Bill; +import com.divudi.core.entity.BillItem; +import com.divudi.core.data.lab.PatientInvestigationStatus; + +import com.divudi.core.facade.PatientReportItemValueFacade; +import com.divudi.core.facade.PatientReportFacade; +import com.divudi.core.facade.PatientInvestigationFacade; +import com.divudi.core.facade.BillFacade; + +public class LimsBenchmark { + + @Test + public void testAddResultToReportPerformance() { + LimsMiddlewareController controller = new LimsMiddlewareController() { + + public PatientSample patientSampleFromId(Long id) { + PatientSample ps = new PatientSample(); + ps.setId(id); + return ps; + } + + + public List getPatientSampleComponents(PatientSample ps) { + List pscs = new ArrayList<>(); + PatientSampleComponant psc = new PatientSampleComponant(); + + Item ic = new Item() { + + public boolean equals(Object o) { return true; } + }; + psc.setInvestigationComponant(ic); + pscs.add(psc); + return pscs; + } + + + public List getPatientInvestigations(List pscs) { + List ptixs = new ArrayList<>(); + PatientInvestigation pi = new PatientInvestigation(); + Investigation ix = new Investigation(); + + List items = new ArrayList<>(); + for (int i = 0; i < 1000; i++) { + InvestigationItem ii = new InvestigationItem(); + ii.setIxItemType(InvestigationItemType.Value); + Item ti = new Item(); + ti.setCode("TEST_CODE"); + ii.setTest(ti); + ii.setResultCode("TEST_CODE"); + + Item sampleComp = new Item() { + + public boolean equals(Object o) { return true; } + }; + ii.setSampleComponent(sampleComp); + + items.add(ii); + } + ix.getReportItems().addAll(items); + pi.setInvestigation(ix); + + BillItem bi = new BillItem(); + Bill b = new Bill(); + bi.setBill(b); + pi.setBillItem(bi); + + ptixs.add(pi); + return ptixs; + } + + + public PatientReport getUnapprovedPatientReport(PatientInvestigation pi) { + PatientReport pr = new PatientReport(); + List privs = new ArrayList<>(); + + for (int i = 0; i < 1000; i++) { + PatientReportItemValue priv = new PatientReportItemValue(); + priv.setId((long) i); + InvestigationItem ii = new InvestigationItem(); + ii.setIxItemType(InvestigationItemType.Value); + Item ti = new Item(); + ti.setCode("TEST_CODE"); + ii.setTest(ti); + ii.setResultCode("TEST_CODE"); + + Item sampleComp = new Item() { + + public boolean equals(Object o) { return true; } + }; + ii.setSampleComponent(sampleComp); + + priv.setInvestigationItem(ii); + privs.add(priv); + } + + pr.setPatientReportItemValues(privs); + return pr; + } + }; + + controller.patientReportItemValueFacade = new PatientReportItemValueFacade() { + + public void create(PatientReportItemValue priv) { } + + public void edit(PatientReportItemValue priv) { } + + public void batchCreate(List privs) { } + + public void batchEdit(List privs) { } + }; + + controller.prFacade = new PatientReportFacade() { + + public void edit(PatientReport pr) { } + }; + + controller.patientInvestigationFacade = new PatientInvestigationFacade() { + + public void edit(PatientInvestigation pi) { } + }; + + controller.billFacade = new BillFacade() { + + public void edit(Bill b) { } + }; + + + long startTime = System.currentTimeMillis(); + + // Run test iterations + for (int i = 0; i < 100; i++) { + controller.addResultToReport("123", "TEST_CODE", "5.5", "unit", "error"); + } + + long endTime = System.currentTimeMillis(); + + System.out.println("================================================="); + System.out.println("BASELINE TIME: " + (endTime - startTime) + " ms"); + System.out.println("================================================="); + } +} \ No newline at end of file