Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions src/main/java/com/divudi/ws/lims/LimsMiddlewareController.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class LimsMiddlewareController {
@EJB
PatientInvestigationFacade patientInvestigationFacade;
@EJB
private BillFacade billFacade;
BillFacade billFacade;
@EJB
PatientReportFacade prFacade;
@EJB
Expand Down Expand Up @@ -1022,6 +1022,10 @@ public boolean addResultToReport(String sampleId, String testCodeFromUploadedDat
if (ptixs == null || ptixs.isEmpty()) {
return temFlag;
}

List<PatientReportItemValue> valuesToCreate = new ArrayList<>();
List<PatientReportItemValue> valuesToEdit = new ArrayList<>();

for (PatientInvestigation pi : ptixs) {
// // System.out.println("Patient Investigation = " + pi.getInvestigation());

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1752,7 +1763,7 @@ public PatientReport getUnsavedPatientReport(PatientInvestigation pi) {
return r;
}

private List<PatientInvestigation> getPatientInvestigations(List<PatientSampleComponant> pscs) {
public List<PatientInvestigation> getPatientInvestigations(List<PatientSampleComponant> pscs) {
Set<PatientInvestigation> ptixhs = new HashSet<>();
for (PatientSampleComponant psc : pscs) {
ptixhs.add(psc.getPatientInvestigation());
Expand Down
160 changes: 160 additions & 0 deletions src/test/java/com/divudi/ws/lims/LimsBenchmark.java
Original file line number Diff line number Diff line change
@@ -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<PatientSampleComponant> getPatientSampleComponents(PatientSample ps) {
List<PatientSampleComponant> 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<PatientInvestigation> getPatientInvestigations(List<PatientSampleComponant> pscs) {
List<PatientInvestigation> ptixs = new ArrayList<>();
PatientInvestigation pi = new PatientInvestigation();
Investigation ix = new Investigation();

List<InvestigationItem> 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<PatientReportItemValue> 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<PatientReportItemValue> privs) { }

public void batchEdit(List<PatientReportItemValue> 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("=================================================");
}
}
Loading