From 8b5c4128930201815371f2bbfef33c39daa1a0f2 Mon Sep 17 00:00:00 2001 From: thiwanka570 Date: Mon, 5 Aug 2024 12:01:10 +0530 Subject: [PATCH 01/17] Signed-off-by: thiwanka570 --- .../com/divudi/bean/common/PettyCashBillSearch.java | 10 ++++++++++ src/main/webapp/petty_cash_bill_reprint.xhtml | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/com/divudi/bean/common/PettyCashBillSearch.java b/src/main/java/com/divudi/bean/common/PettyCashBillSearch.java index b2c6d68adf..2fa0b2fdc1 100644 --- a/src/main/java/com/divudi/bean/common/PettyCashBillSearch.java +++ b/src/main/java/com/divudi/bean/common/PettyCashBillSearch.java @@ -101,6 +101,16 @@ public class PettyCashBillSearch implements Serializable { private String comment; WebUser user; private SearchKeyword searchKeyword; + + public void sendToApprovePettyCashBillCancellation(){ + Bill b=new Bill(); + b.setCreatedAt(new Date()); + b.setCreater(webUserController.getCurrent()); + b.setReferenceBill(getBill()); + b.setBillType(BillType.PettyCashCancelApprove); + billFacade.create(b); + + } public WebUser getUser() { return user; diff --git a/src/main/webapp/petty_cash_bill_reprint.xhtml b/src/main/webapp/petty_cash_bill_reprint.xhtml index e91f2e09bc..5ae89facf2 100644 --- a/src/main/webapp/petty_cash_bill_reprint.xhtml +++ b/src/main/webapp/petty_cash_bill_reprint.xhtml @@ -20,6 +20,11 @@ + + + + + From 401c870adc282214f00f27b7435c6f923173130b Mon Sep 17 00:00:00 2001 From: buddhika75 Date: Thu, 8 Aug 2024 03:31:09 +0530 Subject: [PATCH 02/17] Signed-off-by: buddhika75 --- pom.xml | 4 ++-- src/main/resources/META-INF/persistence.xml | 4 ++-- src/main/webapp/WEB-INF/glassfish-web.xml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 7d4291e618..c80f526ea1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,10 +3,10 @@ 4.0.0 com.divudi - sethma + ruhunu-demo 3.0.0 war - sethma + ruhunu-demo ${project.build.directory}/endorsed diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml index 503e524d47..38cf08518b 100644 --- a/src/main/resources/META-INF/persistence.xml +++ b/src/main/resources/META-INF/persistence.xml @@ -1,7 +1,7 @@ - jdbc/sethma + jdbc/ruhunuDemo false @@ -9,7 +9,7 @@ - jdbc/sethmaaudit + jdbc/ruhunuDemoAudit false diff --git a/src/main/webapp/WEB-INF/glassfish-web.xml b/src/main/webapp/WEB-INF/glassfish-web.xml index 2ef047d83a..9841584308 100644 --- a/src/main/webapp/WEB-INF/glassfish-web.xml +++ b/src/main/webapp/WEB-INF/glassfish-web.xml @@ -1,7 +1,7 @@ - /sethma + /ruhunuDemo From 207f98c95d5495123190de55f053bb38ea697d1e Mon Sep 17 00:00:00 2001 From: buddhika75 Date: Thu, 8 Aug 2024 03:40:55 +0530 Subject: [PATCH 03/17] Signed-off-by: buddhika75 --- .../divudi/bean/common/EnumController.java | 7 + .../lab/PatientInvestigationController.java | 87 +++ .../data/lab/PatientInvestigationStatus.java | 42 ++ .../entity/lab/PatientInvestigation.java | 58 ++ .../com/divudi/entity/lab/PatientSample.java | 13 + src/main/webapp/lab/generate_barcode_p.xhtml | 523 +++++++++--------- src/main/webapp/logout.xhtml | 2 +- src/main/webapp/resources/ezcomp/menu.xhtml | 2 +- src/main/webapp/timeout.xhtml | 2 +- 9 files changed, 486 insertions(+), 250 deletions(-) create mode 100644 src/main/java/com/divudi/data/lab/PatientInvestigationStatus.java diff --git a/src/main/java/com/divudi/bean/common/EnumController.java b/src/main/java/com/divudi/bean/common/EnumController.java index b523415348..fa236f639b 100644 --- a/src/main/java/com/divudi/bean/common/EnumController.java +++ b/src/main/java/com/divudi/bean/common/EnumController.java @@ -44,6 +44,7 @@ import com.divudi.data.inward.AdmissionTypeEnum; import com.divudi.data.inward.InwardChargeType; import com.divudi.data.inward.PatientEncounterComponentType; +import com.divudi.data.lab.PatientInvestigationStatus; import com.divudi.data.lab.Priority; import com.divudi.entity.PaymentScheme; import com.divudi.entity.Person; @@ -78,6 +79,7 @@ public class EnumController implements Serializable { private List paymentMethodsForPatientDeposit; private List paymentMethodsForOpdBillCanceling; SessionNumberType[] sessionNumberTypes; + private List patientInvestigationStatuses; @PostConstruct public void init() { @@ -227,6 +229,11 @@ public SessionNumberType[] getSessionNumberTypes() { return sessionNumberTypes; } + public List getPatientInvestigationStatuses() { + patientInvestigationStatuses = Arrays.asList(PatientInvestigationStatus.values()); + return patientInvestigationStatuses; + } + public List getLoginPages() { return Arrays.asList(LoginPage.values()); } diff --git a/src/main/java/com/divudi/bean/lab/PatientInvestigationController.java b/src/main/java/com/divudi/bean/lab/PatientInvestigationController.java index 132540e600..641b039b13 100644 --- a/src/main/java/com/divudi/bean/lab/PatientInvestigationController.java +++ b/src/main/java/com/divudi/bean/lab/PatientInvestigationController.java @@ -1262,6 +1262,93 @@ public void listBillsToGenerateBarcodes() { List pis = getFacade().findByJpql(jpql, params, TemporalType.TIMESTAMP); billBarcodes = createBilBarcodeObjects(pis); } + + public void searchBills() { + String jpql; + Map params = new HashMap(); + jpql = "SELECT i " + + " FROM PatientInvestigation i " + + " where i.retired=:ret " + + " and i.barcodeGenerated=:bg " + + " and i.billItem.bill.billDate between :fromDate and :toDate "; + + if (orderedInstitution != null) { + jpql += " and i.billItem.bill.institution=:ins "; + params.put("ins", getOrderedInstitution()); + } + + if (orderedInstitution != null) { + jpql += " and i.billItem.bill.department=:dep "; + params.put("dep", getOrderedDepartment()); + } + + jpql += " order by i.id desc"; + params.put("fromDate", getFromDate()); + params.put("toDate", getToDate()); + params.put("ret", false); + params.put("bg", false); + billBarcodes = new ArrayList<>(); + List pis = getFacade().findByJpql(jpql, params, TemporalType.TIMESTAMP); + billBarcodes = createBilBarcodeObjects(pis); + } + + public void searchPatientInvestigations() { + String jpql; + Map params = new HashMap(); + jpql = "SELECT i " + + " FROM PatientInvestigation i " + + " where i.retired=:ret " + + " and i.barcodeGenerated=:bg " + + " and i.billItem.bill.billDate between :fromDate and :toDate "; + + if (orderedInstitution != null) { + jpql += " and i.billItem.bill.institution=:ins "; + params.put("ins", getOrderedInstitution()); + } + + if (orderedInstitution != null) { + jpql += " and i.billItem.bill.department=:dep "; + params.put("dep", getOrderedDepartment()); + } + + jpql += " order by i.id desc"; + params.put("fromDate", getFromDate()); + params.put("toDate", getToDate()); + params.put("ret", false); + params.put("bg", false); + billBarcodes = new ArrayList<>(); + List pis = getFacade().findByJpql(jpql, params, TemporalType.TIMESTAMP); + billBarcodes = createBilBarcodeObjects(pis); + } + + public void searchPatientSamples() { + String jpql; + Map params = new HashMap(); + jpql = "SELECT i " + + " FROM PatientInvestigation i " + + " where i.retired=:ret " + + " and i.barcodeGenerated=:bg " + + " and i.billItem.bill.billDate between :fromDate and :toDate "; + + if (orderedInstitution != null) { + jpql += " and i.billItem.bill.institution=:ins "; + params.put("ins", getOrderedInstitution()); + } + + if (orderedInstitution != null) { + jpql += " and i.billItem.bill.department=:dep "; + params.put("dep", getOrderedDepartment()); + } + + jpql += " order by i.id desc"; + params.put("fromDate", getFromDate()); + params.put("toDate", getToDate()); + params.put("ret", false); + params.put("bg", false); + billBarcodes = new ArrayList<>(); + List pis = getFacade().findByJpql(jpql, params, TemporalType.TIMESTAMP); + billBarcodes = createBilBarcodeObjects(pis); + } public void listBillsWithGeneratedBarcodes() { String jpql; diff --git a/src/main/java/com/divudi/data/lab/PatientInvestigationStatus.java b/src/main/java/com/divudi/data/lab/PatientInvestigationStatus.java new file mode 100644 index 0000000000..703e0506fb --- /dev/null +++ b/src/main/java/com/divudi/data/lab/PatientInvestigationStatus.java @@ -0,0 +1,42 @@ +package com.divudi.data.lab; + +/** + * Enum representing the various statuses of a patient investigation. + * + * Author: M H B Ariyaratne + */ +public enum PatientInvestigationStatus { + + ORDERED("Ordered"), + SAMPLE_GENERATED("Sample Generated (Barcode generated)"), + SAMPLE_COLLECTED("Sample Collected"), + SAMPLE_SENT("Sample Sent"), + SAMPLE_ACCEPTED("Sample Accepted"), + SAMPLE_REJECTED("Sample Rejected"), + SAMPLE_REVERTED("Sample Reverted"), + SAMPLE_RESENT("Sample Resent"), + SAMPLE_RECOLLECTED("Sample Recollected"), + SAMPLE_INTERFACED("Sample Interfaced"), + SAMPLE_APPROVED("Sample Approved"), + SAMPLE_REPEATED("Sample Repeated"), + SAMPLE_APPROVED_AND_REPEATED("Sample Approved and Repeated"), + REPORT_PRINTED("Report Printed"), + REPORT_DISTRIBUTED("Report Distributed"), + REPORT_REACHED_COLLECTING_CENTRE("Report Reached Collecting Centre"), + REPORT_HANDED_OVER("Report Handed Over"); + + private final String label; + + PatientInvestigationStatus(String label) { + this.label = label; + } + + public String getLabel() { + return label; + } + + @Override + public String toString() { + return label; + } +} diff --git a/src/main/java/com/divudi/entity/lab/PatientInvestigation.java b/src/main/java/com/divudi/entity/lab/PatientInvestigation.java index f8fc00dd50..4efe164d67 100644 --- a/src/main/java/com/divudi/entity/lab/PatientInvestigation.java +++ b/src/main/java/com/divudi/entity/lab/PatientInvestigation.java @@ -4,6 +4,7 @@ */ package com.divudi.entity.lab; +import com.divudi.data.lab.PatientInvestigationStatus; import com.divudi.entity.BillComponent; import com.divudi.entity.BillItem; import com.divudi.entity.Department; @@ -17,6 +18,7 @@ import java.util.Date; import java.util.List; import javax.persistence.Entity; +import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -73,6 +75,16 @@ public class PatientInvestigation implements Serializable { private Date sampledAt; private Boolean sampleOutside = false; private String sampleComments; + + private Boolean sampleSent = false; + @ManyToOne + private WebUser sampleSentBy; + @Temporal(javax.persistence.TemporalType.TIMESTAMP) + private Date sampleSentAt; + private String sampleSentComments; + + + @ManyToOne private Department sampleDepartment; @ManyToOne @@ -170,6 +182,9 @@ public class PatientInvestigation implements Serializable { private Institution outsourcedInstitution; @OneToMany(mappedBy="patientInvestigation",fetch = FetchType.EAGER) List patientReports; + @Enumerated + private PatientInvestigationStatus status; + public List getPatientReports() { if(patientReports == null){ @@ -185,6 +200,7 @@ public void setPatientReports(List patientReports) { + public BillComponent getBillComponent() { return billComponent; } @@ -217,6 +233,8 @@ public boolean equals(Object object) { public String toString() { return "com.divudi.entity.PatientInvestigation[ id=" + id + " ]"; } + + public Patient getPatient() { return patient; @@ -798,4 +816,44 @@ public void setBarcodeGeneratedBy(WebUser barcodeGeneratedBy) { this.barcodeGeneratedBy = barcodeGeneratedBy; } + public PatientInvestigationStatus getStatus() { + return status; + } + + public void setStatus(PatientInvestigationStatus status) { + this.status = status; + } + + public Boolean getSampleSent() { + return sampleSent; + } + + public void setSampleSent(Boolean sampleSent) { + this.sampleSent = sampleSent; + } + + public WebUser getSampleSentBy() { + return sampleSentBy; + } + + public void setSampleSentBy(WebUser sampleSentBy) { + this.sampleSentBy = sampleSentBy; + } + + public Date getSampleSentAt() { + return sampleSentAt; + } + + public void setSampleSentAt(Date sampleSentAt) { + this.sampleSentAt = sampleSentAt; + } + + public String getSampleSentComments() { + return sampleSentComments; + } + + public void setSampleSentComments(String sampleSentComments) { + this.sampleSentComments = sampleSentComments; + } + } diff --git a/src/main/java/com/divudi/entity/lab/PatientSample.java b/src/main/java/com/divudi/entity/lab/PatientSample.java index 7a249763ed..3875ab6e93 100644 --- a/src/main/java/com/divudi/entity/lab/PatientSample.java +++ b/src/main/java/com/divudi/entity/lab/PatientSample.java @@ -5,6 +5,7 @@ */ package com.divudi.entity.lab; +import com.divudi.data.lab.PatientInvestigationStatus; import com.divudi.data.lab.SampleRequestType; import com.divudi.entity.Bill; import com.divudi.entity.Department; @@ -131,6 +132,8 @@ public class PatientSample implements Serializable { @ManyToOne private Institution sampleReceivedAtLabInstitution; + @Enumerated + private PatientInvestigationStatus status; //Cancellation private Boolean cancelled = false; @@ -164,6 +167,8 @@ public String getIdStr() { return formatted; } + + @Override public int hashCode() { int hash = 0; @@ -637,4 +642,12 @@ public void setSampleReceivedAtLabInstitution(Institution sampleReceivedAtLabIns this.sampleReceivedAtLabInstitution = sampleReceivedAtLabInstitution; } + public PatientInvestigationStatus getStatus() { + return status; + } + + public void setStatus(PatientInvestigationStatus status) { + this.status = status; + } + } diff --git a/src/main/webapp/lab/generate_barcode_p.xhtml b/src/main/webapp/lab/generate_barcode_p.xhtml index df00c3b0ca..34b3bc1e3b 100644 --- a/src/main/webapp/lab/generate_barcode_p.xhtml +++ b/src/main/webapp/lab/generate_barcode_p.xhtml @@ -6,10 +6,8 @@ xmlns="http://www.w3.org/1999/xhtml" xmlns:p="http://primefaces.org/ui" xmlns:opd="http://xmlns.jcp.org/jsf/composite/ezcomp/opd"> - - - + + + + + + You are NOT authorized + + + + + +
+
+
+
+
+ + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #{apt.name} + + + #{apt.code} + + + #{apt.fullName} + + + #{apt.department.name} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Time: + + + + Institution: + + + + User: + + + + + + + + Time: + + + + Institution: + + + + User: + + + + + + + + Time: + + + + Institution: + + + + User: + + + + + + + + Time: + + + + Institution: + + + + User: + + + + + + + + Time: + + + + Institution: + + + + User: + + + + + + + + Time: + + + + Institution: + + + + User: + + + + + + + + Time: + + + + Institution: + + + + User: + + + + + + + + Time: + + + + Institution: + + + + User: + + + + + + + + Time: + + + + Institution: + + + + User: + + + + + + + + Time: + + + + Institution: + + + + User: + + + + + + + + Time: + + + + Institution: + + + + User: + + + + + + + + Time: + + + + Institution: + + + + User: + + + + + + + + Time: + + + + Institution: + + + + + + + + Time: + + + + User: + + + + + + + + Time: + + + + User: + + + + + + + + + + + + + + +
+ +
+ + +
+ + + + + + + + + +
+
+
+
+ \ No newline at end of file diff --git a/src/main/webapp/resources/ezcomp/menu.xhtml b/src/main/webapp/resources/ezcomp/menu.xhtml index 175f037e76..d454176b1d 100644 --- a/src/main/webapp/resources/ezcomp/menu.xhtml +++ b/src/main/webapp/resources/ezcomp/menu.xhtml @@ -397,14 +397,17 @@ - - - - + + + + From 2ef1caa9e27a770a41d6fc667ee7420fbf49e40a Mon Sep 17 00:00:00 2001 From: Dr M H B Ariyaratne Date: Fri, 9 Aug 2024 20:57:03 -0700 Subject: [PATCH 16/17] Signed-off-by: Dr M H B Ariyaratne --- pom.xml | 53 ++-- .../com/divudi/bean/common/BillSearch.java | 3 +- .../bean/common/DepartmentController.java | 15 +- .../common/DepartmentMachineController.java | 50 +++- .../bean/common/UserPrivilageController.java | 20 +- .../bean/lab/InvestigationItemController.java | 4 +- .../divudi/bean/lab/MachineController.java | 22 +- .../divudi/data/InvestigationItemType.java | 1 + .../com/divudi/entity/lab/PatientReport.java | 72 +++++ .../entity/lab/PatientReportItemValue.java | 20 ++ .../com/divudi/entity/lab/ReportItem.java | 39 +++ .../java/com/divudi/ws/finance/Finance.java | 17 +- .../ws/lims/LimsMiddlewareController.java | 248 +++++++++++++++++- src/main/resources/META-INF/persistence.xml | 4 +- .../admin/lims/investigation_format.xhtml | 157 +++++------ src/main/webapp/dev/depts.xhtml | 2 + 16 files changed, 575 insertions(+), 152 deletions(-) diff --git a/pom.xml b/pom.xml index 93828ee196..002cc75f62 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,32 @@
+ + + ca.uhn.hapi.fhir + hapi-fhir-base + 6.1.3 + + + ca.uhn.hapi.fhir + hapi-fhir-structures-r5 + 6.1.3 + + + ca.uhn.hapi + hapi-structures-v25 + 2.3 + + + ca.uhn.hapi + hapi-base + 2.3 + + + ca.uhn.hapi + hapi-structures-v24 + 2.3 + org.codehaus.jackson @@ -245,32 +271,7 @@ 2.0 - - - ca.uhn.hapi.fhir - hapi-fhir-base - 6.1.3 - - - ca.uhn.hapi.fhir - hapi-fhir-structures-r5 - 6.1.3 - - - ca.uhn.hapi - hapi-structures-v25 - 2.3 - - - ca.uhn.hapi - hapi-base - 2.3 - - - ca.uhn.hapi - hapi-structures-v24 - 2.3 - + diff --git a/src/main/java/com/divudi/bean/common/BillSearch.java b/src/main/java/com/divudi/bean/common/BillSearch.java index 66479f4680..f9ddd5de8d 100644 --- a/src/main/java/com/divudi/bean/common/BillSearch.java +++ b/src/main/java/com/divudi/bean/common/BillSearch.java @@ -99,7 +99,6 @@ import javax.persistence.TemporalType; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; -import kotlin.collections.ArrayDeque; import org.apache.commons.beanutils.BeanUtils; import org.primefaces.event.RowEditEvent; import org.primefaces.model.LazyDataModel; @@ -1717,7 +1716,7 @@ private boolean saveRefundBill(Bill rb) { billController.saveBillItem(bi); } - List refundBills = new ArrayDeque<>(); + List refundBills = new ArrayList<>(); refundBills.addAll(bill.getRefundBills()); refundBills.add(rb); diff --git a/src/main/java/com/divudi/bean/common/DepartmentController.java b/src/main/java/com/divudi/bean/common/DepartmentController.java index 54d7936840..9d7bc1160b 100644 --- a/src/main/java/com/divudi/bean/common/DepartmentController.java +++ b/src/main/java/com/divudi/bean/common/DepartmentController.java @@ -526,7 +526,7 @@ public List getInstitutionDepatrments(Institution ins, DepartmentTyp public List getInstitutionDepatrments(DepartmentType departmentType) { return getInstitutionDepatrments(null, true, departmentType); } - + public List getInstitutionDepatrments(Institution ins) { return getInstitutionDepatrments(ins, true, null); } @@ -696,6 +696,19 @@ public Department findDepartment(Long id) { return getFacade().find(id); } + public Department findDepartment(String strId) { + if (strId == null) { + return null; + } + Long id; + try { + id = Long.valueOf(strId); + } catch (Exception e) { + return null; + } + return getFacade().find(id); + } + public Department getSuperDepartment() { return superDepartment; } diff --git a/src/main/java/com/divudi/bean/common/DepartmentMachineController.java b/src/main/java/com/divudi/bean/common/DepartmentMachineController.java index 306c154910..bc67bf7467 100644 --- a/src/main/java/com/divudi/bean/common/DepartmentMachineController.java +++ b/src/main/java/com/divudi/bean/common/DepartmentMachineController.java @@ -87,10 +87,10 @@ public void prepareToAddNew() { current.setMachine(machine); } - + public void clearDeptAndDept() { - department=null; - institution=null; + department = null; + institution = null; } public void save(DepartmentMachine depMachine) { @@ -130,6 +130,50 @@ public DepartmentMachine getCurrent() { return current; } + public DepartmentMachine findDepartmentMachine(Long id) { + return ejbFacade.find(id); + } + + public DepartmentMachine findDepartmentMachine(String strId) { + if (strId == null) { + return null; + } + Long id; + try { + id = Long.valueOf(strId); + } catch (Exception e) { + return null; + } + return ejbFacade.find(id); + } + + public DepartmentMachine findDepartmentMachine(Department department, Machine machine, boolean createNewIfNotFound) { + if (department == null) { + return null; + } + if (machine == null) { + return null; + } + Map parameters = new HashMap(); + String jpql = "select dm " + + " from DepartmentMachine dm " + + " where dm.retired=:ret " + + " and dm.department=:dep " + + " and dm.setMachine=:ma "; + parameters.put("dep", department); + parameters.put("ma", machine); + DepartmentMachine dm = ejbFacade.findFirstByJpql(jpql, parameters); + if (dm == null) { + if (createNewIfNotFound) { + dm = new DepartmentMachine(); + dm.setDepartment(department); + dm.setMachine(machine); + ejbFacade.create(dm); + } + } + return dm; + } + public void setCurrent(DepartmentMachine current) { this.current = current; } diff --git a/src/main/java/com/divudi/bean/common/UserPrivilageController.java b/src/main/java/com/divudi/bean/common/UserPrivilageController.java index 4b4b4e7c31..ad0c374b19 100644 --- a/src/main/java/com/divudi/bean/common/UserPrivilageController.java +++ b/src/main/java/com/divudi/bean/common/UserPrivilageController.java @@ -775,8 +775,14 @@ private List extractPrivileges(TreeNode[] selectedNodes) { List privileges = new ArrayList<>(); if (selectedNodes != null) { for (TreeNode node : selectedNodes) { - PrivilegeHolder ph = (PrivilegeHolder) node.getData(); - privileges.add(ph); + Object data = node.getData(); + if (data instanceof PrivilegeHolder) { + PrivilegeHolder ph = (PrivilegeHolder) data; + privileges.add(ph); + } else { + System.out.println("Unexpected data type: " + data.getClass().getName()); + // Handle the case where the data is not of type PrivilegeHolder + } } } return privileges; @@ -903,13 +909,13 @@ public void fillUserPrivileges() { currentUserPrivilegeHolders = createPrivilegeHolders(currentWebUserPrivileges); unselectTreeNodes(rootTreeNode); checkNodes(rootTreeNode, currentUserPrivilegeHolders); - privilegesLoaded=true; + privilegesLoaded = true; } - public void makePrivilegesNeededToBeReloaded(){ - privilegesLoaded=false; + public void makePrivilegesNeededToBeReloaded() { + privilegesLoaded = false; } - + public void fillUserRolePrivileges(WebUserRole u) { webUserRole = u; fillUserRolePrivileges(); @@ -1066,8 +1072,6 @@ public boolean isPrivilegesLoaded() { public void setPrivilegesLoaded(boolean privilegesLoaded) { this.privilegesLoaded = privilegesLoaded; } - - // // diff --git a/src/main/java/com/divudi/bean/lab/InvestigationItemController.java b/src/main/java/com/divudi/bean/lab/InvestigationItemController.java index d248fc7037..55d8cdfb37 100644 --- a/src/main/java/com/divudi/bean/lab/InvestigationItemController.java +++ b/src/main/java/com/divudi/bean/lab/InvestigationItemController.java @@ -1788,7 +1788,7 @@ public String toEditInvestigationFormat() { return ""; } listInvestigationItem(); - return "/admin/lims/investigation_format"; + return "/admin/lims/investigation_format?faces-redirect=true;"; } public String toEditInvestigationFormatMultiple() { @@ -1797,7 +1797,7 @@ public String toEditInvestigationFormatMultiple() { return ""; } listInvestigationItem(); - return "/admin/lims/investigation_format_multiple"; + return "/admin/lims/investigation_format_multiple?faces-redirect=true;"; } public ReportItemFacade getRiFacade() { diff --git a/src/main/java/com/divudi/bean/lab/MachineController.java b/src/main/java/com/divudi/bean/lab/MachineController.java index 8630b81cd4..5f10c40e62 100644 --- a/src/main/java/com/divudi/bean/lab/MachineController.java +++ b/src/main/java/com/divudi/bean/lab/MachineController.java @@ -76,6 +76,23 @@ private void recreateModel() { items = null; } + public Machine findMachine(Long id) { + return ejbFacade.find(id); + } + + public Machine findMachine(String strId) { + if (strId == null) { + return null; + } + Long id; + try { + id = Long.valueOf(strId); + } catch (Exception e) { + return null; + } + return ejbFacade.find(id); + } + public void saveSelected() { if (getCurrent().getId() != null && getCurrent().getId() > 0) { @@ -103,7 +120,7 @@ public Machine findAndCreateAnalyserByName(String qry) { m.put("ret", false); m.put("name", qry); ma = ejbFacade.findFirstByJpql(jpql, m); - if(ma==null){ + if (ma == null) { ma = new Machine(); ma.setName(qry); ma.setCreatedAt(new Date()); @@ -111,6 +128,7 @@ public Machine findAndCreateAnalyserByName(String qry) { } return ma; } + public MachineFacade getEjbFacade() { return ejbFacade; } @@ -156,7 +174,7 @@ public List getInstitutionMachines() { } return institutionMachines; } - + public List fillMachines() { String j = "select m " + " from Machine m " diff --git a/src/main/java/com/divudi/data/InvestigationItemType.java b/src/main/java/com/divudi/data/InvestigationItemType.java index 8580891602..77b41e22d0 100644 --- a/src/main/java/com/divudi/data/InvestigationItemType.java +++ b/src/main/java/com/divudi/data/InvestigationItemType.java @@ -20,6 +20,7 @@ public enum InvestigationItemType { Antibiotic, Image, Html, + MeasurementUnit, @Deprecated List, @Deprecated diff --git a/src/main/java/com/divudi/entity/lab/PatientReport.java b/src/main/java/com/divudi/entity/lab/PatientReport.java index 8738ec7e80..26449aa52f 100644 --- a/src/main/java/com/divudi/entity/lab/PatientReport.java +++ b/src/main/java/com/divudi/entity/lab/PatientReport.java @@ -71,6 +71,20 @@ public class PatientReport implements Serializable { private Date retiredAt; private String retireComments; //DataEntry + private Boolean automated = false; + @ManyToOne + private WebUser automatedUser; + @Temporal(javax.persistence.TemporalType.TIMESTAMP) + private Date automatedAt; + @ManyToOne + private Department automatedDepartment; + @ManyToOne + private Institution automatedInstitution; + @ManyToOne + private Machine automatedAnalyzer; + @ManyToOne + private DepartmentMachine automatedDepartmentAnalyzer; + //DataEntry private Boolean dataEntered = false; @ManyToOne private WebUser dataEntryUser; @@ -725,6 +739,64 @@ public void setQrCodeContentsLink(String qrCodeContentsLink) { this.qrCodeContentsLink = qrCodeContentsLink; } + public Machine getAutomatedAnalyzer() { + return automatedAnalyzer; + } + + public void setAutomatedAnalyzer(Machine automatedAnalyzer) { + this.automatedAnalyzer = automatedAnalyzer; + } + + public DepartmentMachine getAutomatedDepartmentAnalyzer() { + return automatedDepartmentAnalyzer; + } + + public void setAutomatedDepartmentAnalyzer(DepartmentMachine automatedDepartmentAnalyzer) { + this.automatedDepartmentAnalyzer = automatedDepartmentAnalyzer; + } + + public Boolean getAutomated() { + return automated; + } + + public void setAutomated(Boolean automated) { + this.automated = automated; + } + + public WebUser getAutomatedUser() { + return automatedUser; + } + + public void setAutomatedUser(WebUser automatedUser) { + this.automatedUser = automatedUser; + } + + public Date getAutomatedAt() { + return automatedAt; + } + + public void setAutomatedAt(Date automatedAt) { + this.automatedAt = automatedAt; + } + + public Department getAutomatedDepartment() { + return automatedDepartment; + } + + public void setAutomatedDepartment(Department automatedDepartment) { + this.automatedDepartment = automatedDepartment; + } + + public Institution getAutomatedInstitution() { + return automatedInstitution; + } + + public void setAutomatedInstitution(Institution automatedInstitution) { + this.automatedInstitution = automatedInstitution; + } + + + static class PatientReportItemValueComparator implements Comparator { @Override diff --git a/src/main/java/com/divudi/entity/lab/PatientReportItemValue.java b/src/main/java/com/divudi/entity/lab/PatientReportItemValue.java index d6fb11053e..3520cf80f0 100644 --- a/src/main/java/com/divudi/entity/lab/PatientReportItemValue.java +++ b/src/main/java/com/divudi/entity/lab/PatientReportItemValue.java @@ -35,6 +35,8 @@ public class PatientReportItemValue implements Serializable { InvestigationItem investigationItem; @ManyToOne PatientReport patientReport; + private String codeSystem; + private String codeSystemCode; String strValue; @Lob private String lobValue; @@ -48,6 +50,8 @@ public class PatientReportItemValue implements Serializable { private String value; @Transient private String displayValue; + + public String getStrValue() { return strValue; @@ -219,4 +223,20 @@ public String getDisplayValue() { return getValue(); } + public String getCodeSystem() { + return codeSystem; + } + + public void setCodeSystem(String codeSystem) { + this.codeSystem = codeSystem; + } + + public String getCodeSystemCode() { + return codeSystemCode; + } + + public void setCodeSystemCode(String codeSystemCode) { + this.codeSystemCode = codeSystemCode; + } + } diff --git a/src/main/java/com/divudi/entity/lab/ReportItem.java b/src/main/java/com/divudi/entity/lab/ReportItem.java index b929fc193d..1784d65697 100644 --- a/src/main/java/com/divudi/entity/lab/ReportItem.java +++ b/src/main/java/com/divudi/entity/lab/ReportItem.java @@ -188,6 +188,13 @@ public class ReportItem implements Serializable { @ManyToOne private InvestigationTube tube; private String resultCode; + private String valueCodeSystem; + private String valueCode; + private String valueUnitCodeSystem; + private String valueUnitCode; + + + private boolean canNotApproveIfValueIsEmpty; private boolean canNotApproveIfValueIsBelowAbsoluteLowValue; @@ -1191,4 +1198,36 @@ public void setAboveAbsoluteWarning(String aboveAbsoluteWarning) { this.aboveAbsoluteWarning = aboveAbsoluteWarning; } + public String getValueCodeSystem() { + return valueCodeSystem; + } + + public void setValueCodeSystem(String valueCodeSystem) { + this.valueCodeSystem = valueCodeSystem; + } + + public String getValueCode() { + return valueCode; + } + + public void setValueCode(String valueCode) { + this.valueCode = valueCode; + } + + public String getValueUnitCodeSystem() { + return valueUnitCodeSystem; + } + + public void setValueUnitCodeSystem(String valueUnitCodeSystem) { + this.valueUnitCodeSystem = valueUnitCodeSystem; + } + + public String getValueUnitCode() { + return valueUnitCode; + } + + public void setValueUnitCode(String valueUnitCode) { + this.valueUnitCode = valueUnitCode; + } + } diff --git a/src/main/java/com/divudi/ws/finance/Finance.java b/src/main/java/com/divudi/ws/finance/Finance.java index 10b25c58cb..bdd09fe813 100644 --- a/src/main/java/com/divudi/ws/finance/Finance.java +++ b/src/main/java/com/divudi/ws/finance/Finance.java @@ -15,9 +15,7 @@ import com.divudi.entity.BillItem; import com.divudi.facade.BillFacade; import com.divudi.java.CommonFunctions; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; -import org.apache.commons.codec.binary.Base64; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -502,20 +500,7 @@ private JSONArray billAndBillItemsToJSONArray(List bills) { return array; } - private boolean isUserAuthenticated(String authString) { - try { - byte[] decoded = Base64.decodeBase64(authString); - String decodedAuth = new String(decoded, "UTF-8") + "\n"; - - String[] authParts = decodedAuth.split("\\s+"); - String username = authParts[0]; - String password = authParts[1]; - return authenticateController.userAuthenticated(username, password); - } catch (UnsupportedEncodingException ex) { - return false; - } - } - + private boolean isValidKey(String key) { if (key == null || key.trim().equals("")) { return false; diff --git a/src/main/java/com/divudi/ws/lims/LimsMiddlewareController.java b/src/main/java/com/divudi/ws/lims/LimsMiddlewareController.java index 265c414347..9cdbe06ace 100644 --- a/src/main/java/com/divudi/ws/lims/LimsMiddlewareController.java +++ b/src/main/java/com/divudi/ws/lims/LimsMiddlewareController.java @@ -5,6 +5,7 @@ */ package com.divudi.ws.lims; +import ca.uhn.fhir.context.FhirContext; import com.divudi.bean.common.SecurityController; import com.divudi.entity.WebUser; import com.divudi.facade.BillFacade; @@ -43,6 +44,9 @@ import java.util.HashSet; import java.util.Set; import ca.uhn.hl7v2.parser.Parser; +import com.divudi.bean.common.DepartmentController; +import com.divudi.bean.common.DepartmentMachineController; +import com.divudi.bean.lab.MachineController; import com.divudi.data.InvestigationItemValueType; import com.divudi.data.lab.SysMex; @@ -51,8 +55,10 @@ import com.divudi.entity.Institution; import com.divudi.entity.Item; import com.divudi.entity.Patient; +import com.divudi.entity.lab.DepartmentMachine; import com.divudi.entity.lab.Investigation; import com.divudi.entity.lab.InvestigationItemValueFlag; +import com.divudi.entity.lab.Machine; import com.divudi.entity.lab.PatientInvestigation; import com.divudi.entity.lab.PatientReport; import com.divudi.entity.lab.PatientReportItemValue; @@ -72,6 +78,8 @@ import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.inject.Inject; +import javax.ws.rs.GET; /** * REST Web Service @@ -104,16 +112,215 @@ public class LimsMiddlewareController { @EJB InvestigationItemValueFlagFacade iivfFacade; + @Inject + DepartmentMachineController departmentMachineController; + @Inject + DepartmentController departmentController; + @Inject + MachineController machineController; + private WebUser loggedUser; private Department loggedDepartment; private Institution loggedInstitution; + private FhirContext fhirContext = FhirContext.forR4(); + /** * Creates a new instance of LIMS */ public LimsMiddlewareController() { } + @GET + @Path("/test") + @Produces(MediaType.TEXT_PLAIN) + public Response testEndpoint() { + return Response.ok("Hello, the path is correct!").build(); + } + + @POST + @Path("/observation") + @Consumes(MediaType.APPLICATION_JSON) + public Response receiveObservation(String observationJson) { + try { + // Parse the incoming JSON string to a JSONObject + JSONObject observation = new JSONObject(observationJson); + + // Process the Observation JSON object + return processD10Observation(observation); + + } catch (Exception e) { + e.printStackTrace(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity("Failed to process Observation").build(); + } + } + + private Response processD10Observation(JSONObject observation) { + // Extract relevant fields from the JSON object using the exact names as sent by the client + String sampleId = observation.optString("sampleId"); + String analyzerName = observation.optString("analyzerName"); + String analyzerId = observation.optString("analyzerId"); + String departmentId = observation.optString("departmentId"); + String departmentAnalyzerId = observation.optString("departmentAnalyzerId"); + String observationValueCodingSystem = observation.optString("observationValueCodingSystem"); + String observationValueCode = observation.optString("observationValueCode"); + String observationUnitCodingSystem = observation.optString("observationUnitCodingSystem"); + String observationUnitCode = observation.optString("observationUnitCode"); + String observationValueStr = observation.optString("observationValue"); + Double observationValueDbl = null; + String issuedDate = observation.optString("issuedDate"); + String password = observation.optString("password"); + String username = observation.optString("username"); + + try { + observationValueDbl = Double.valueOf(observationValueStr); + } catch (NumberFormatException e) { + System.out.println("e = " + e); + } + + // Log the extracted values for debugging or further processing + System.out.println("sampleId: " + sampleId); + System.out.println("analyzerName: " + analyzerName); + System.out.println("analyzerId: " + analyzerId); + System.out.println("departmentId: " + departmentId); + System.out.println("departmentAnalyzerId: " + departmentAnalyzerId); + System.out.println("observationValueCodingSystem: " + observationValueCodingSystem); + System.out.println("observationValueCode: " + observationValueCode); + System.out.println("observationUnitCodingSystem: " + observationUnitCodingSystem); + System.out.println("observationUnitCode: " + observationUnitCode); + System.out.println("observationValue: " + observationValueStr); + System.out.println("issuedDate: " + issuedDate); + + Long sampleIdLong; + Machine analyzer; + DepartmentMachine departmentAnalyzer; + Department department; + WebUser wu; + boolean resultAdded = false; + + wu = findRequestSendingUser(username, password); + if (wu == null) { + System.out.println("Cannot find the user: " + wu); + return Response.status(Response.Status.UNAUTHORIZED) + .entity("User is not found for ID: " + username) + .build(); + } + + try { + sampleIdLong = Long.valueOf(sampleId); + } catch (Exception e) { + System.out.println("Cannot convert sample ID to Long: " + sampleId); + return Response.status(Response.Status.BAD_REQUEST) + .entity("Invalid sample ID: " + sampleId) + .build(); + } + + department = departmentController.findDepartment(departmentId); + if (department == null) { + System.out.println("Cannot find the department: " + departmentId); + return Response.status(Response.Status.NOT_FOUND) + .entity("Department not found for ID: " + departmentId) + .build(); + } + + analyzer = machineController.findMachine(analyzerId); + if (analyzer == null) { + System.out.println("Cannot find the machine (analyzer): " + analyzerId); + return Response.status(Response.Status.NOT_FOUND) + .entity("Machine (analyzer) not found for ID: " + analyzerId) + .build(); + } + + departmentAnalyzer = departmentMachineController.findDepartmentMachine(departmentAnalyzerId); + if (departmentAnalyzer == null) { + departmentAnalyzer = departmentMachineController.findDepartmentMachine(department, analyzer, true); + } + + PatientSample ps = patientSampleFromId(sampleIdLong); + if (ps == null) { + System.out.println("Cannot find the patient sample: " + sampleId); + return Response.status(Response.Status.NOT_FOUND) + .entity("Patient sample not found for ID: " + sampleId) + .build(); + } + + List pscs = getPatientSampleComponents(ps); + if (pscs == null) { + System.out.println("Invalid Sample Components. Please inform developers. Resend results for sample ID: " + sampleIdLong); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity("Invalid sample components for sample ID: " + sampleIdLong) + .build(); + } + + List ptixs = getPatientInvestigations(pscs); + if (ptixs == null || ptixs.isEmpty()) { + System.out.println("Invalid Patient Investigations. Please inform developers. Resend results for sample ID: " + sampleIdLong); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity("Invalid patient investigations for sample ID: " + sampleIdLong) + .build(); + } + + for (PatientInvestigation pi : ptixs) { + List prs = new ArrayList<>(); + if (pi.getInvestigation().getMachine().equals(analyzer)) { + PatientReport tpr; + tpr = getUnsavedPatientReport(pi); + if (tpr == null) { + tpr = createNewPatientReport(pi, pi.getInvestigation(), departmentAnalyzer, wu); + } + prs.add(tpr); + } + if (prs.isEmpty()) { + List temItems = getItemsForParentItem(pi.getInvestigation()); + for (Item ti : temItems) { + if (ti instanceof Investigation) { + Investigation tix = (Investigation) ti; + if (tix.getMachine().equals(analyzer)) { + PatientReport tprs; + tprs = getUnsavedPatientReport(pi); + if (tprs == null) { + tprs = createNewPatientReport(pi, tix); + } + prs.add(tprs); + } + } + } + } + + for (PatientReport tpr : prs) { + for (PatientReportItemValue priv : tpr.getPatientReportItemValues()) { + if (priv.getInvestigationItem() != null) { + if (priv.getCodeSystem().equals(observationValueCodingSystem)) { + if (priv.getCodeSystemCode().equals(observationValueCode)) { + priv.setStrValue(observationValueStr); + priv.setDoubleValue(observationValueDbl); + resultAdded = true; + } + } + } + } + tpr.setAutomated(true); + tpr.setAutomatedAt(new Date()); + tpr.setAutomatedAnalyzer(analyzer); + tpr.setAutomatedDepartment(department); + tpr.setAutomatedInstitution(department.getInstitution()); + tpr.setAutomatedUser(wu); + prFacade.edit(tpr); + } + } + + if (resultAdded) { + return Response.status(Response.Status.CREATED) + .entity("Results Added Successfully for Sample ID : " + sampleIdLong) + .build(); + } else { + return Response.status(Response.Status.EXPECTATION_FAILED) + .entity("Results Could NOT be Added for Sample ID : " + sampleIdLong) + .build(); + } + } + @POST @Path("/sysmex") @Consumes(MediaType.APPLICATION_JSON) @@ -256,7 +463,6 @@ private boolean authenticate(String username, String password) { @Produces(MediaType.APPLICATION_JSON) public Response limsProcessAnalyzerMessage(String requestBody, @HeaderParam("Authorization") String authorizationHeader) { - try { JSONObject requestJson = new JSONObject(requestBody); @@ -965,6 +1171,34 @@ public PatientReport createNewPatientReport(PatientInvestigation pi, Investigati return r; } + public PatientReport createNewPatientReport(PatientInvestigation pi, Investigation ix, DepartmentMachine deptAnalyzer, WebUser u) { + PatientReport r = null; + if (pi != null && pi.getId() != null && ix != null) { + r = new PatientReport(); + r.setCreatedAt(Calendar.getInstance(TimeZone.getTimeZone("IST")).getTime()); + r.setCreater(loggedUser); + r.setItem(ix); + r.setDataEntryDepartment(loggedDepartment); + r.setDataEntryInstitution(loggedInstitution); + r.setAutomated(Boolean.TRUE); + r.setAutomatedAnalyzer(deptAnalyzer.getMachine()); + r.setAutomatedAt(new Date()); + r.setAutomatedDepartment(deptAnalyzer.getDepartment()); + r.setAutomatedInstitution(deptAnalyzer.getDepartment().getInstitution()); + r.setAutomatedUser(u); + if (r.getTransInvestigation() != null) { + r.setReportFormat(r.getTransInvestigation().getReportFormat()); + } + prFacade.create(r); + r.setPatientInvestigation(pi); + addPatientReportItemValuesForReport(r); + prFacade.edit(r); + } else { + JsfUtil.addErrorMessage("No ptIx or Ix selected to add"); + } + return r; + } + public Double getDefaultDoubleValue(InvestigationItem item, Patient patient) { //TODO: Create Logic return 0.0; @@ -1109,6 +1343,18 @@ public PatientReport getUnapprovedPatientReport(PatientInvestigation pi) { return r; } + public PatientReport getUnsavedPatientReport(PatientInvestigation pi) { + String j = "select r from PatientReport r " + + " where r.patientInvestigation = :pi " + + " and (r.dataEntered = :a or r.dataEntered is null) " + + " order by r.id desc"; + Map m = new HashMap(); + m.put("pi", pi); + m.put("a", false); + PatientReport r = prFacade.findFirstByJpql(j, m); + return r; + } + private List getPatientInvestigations(List pscs) { Set ptixhs = new HashSet<>(); for (PatientSampleComponant psc : pscs) { diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml index 7dc5eaabf7..0899ba70eb 100644 --- a/src/main/resources/META-INF/persistence.xml +++ b/src/main/resources/META-INF/persistence.xml @@ -2,7 +2,7 @@ org.eclipse.persistence.jpa.PersistenceProvider - jdbc/digasiri + jdbc/ruhunu false @@ -13,7 +13,7 @@ - jdbc/digasiriAudit + jdbc/ruhunuaudit false diff --git a/src/main/webapp/admin/lims/investigation_format.xhtml b/src/main/webapp/admin/lims/investigation_format.xhtml index ba0c3550a3..5026065f3f 100644 --- a/src/main/webapp/admin/lims/investigation_format.xhtml +++ b/src/main/webapp/admin/lims/investigation_format.xhtml @@ -3,12 +3,14 @@ - + + + @@ -329,97 +331,57 @@ + - - - -
-
- -
-
- - -
-
+ + + + + + + + + + + + + + + + + + + + -
-
- -
-
- - - - - - - - - - - - -
-
+ + + + + -
-
- -
-
- - - - -
-
+ + -
-
- - - -
-
- - + + + + - - - - - - - - - - -
-
+ + + - +
-
@@ -572,6 +534,23 @@ + + + + + + + + + + + + + + + + + @@ -745,7 +724,7 @@ render="gpIi :#{p:resolveFirstComponentWithId('pDetails',view).clientId} moveFocus "/> - + - - + +

#{investigationItemController.currentInvestigation.reportFormat}

diff --git a/src/main/webapp/dev/depts.xhtml b/src/main/webapp/dev/depts.xhtml index 3cb640328e..f8d348ff01 100644 --- a/src/main/webapp/dev/depts.xhtml +++ b/src/main/webapp/dev/depts.xhtml @@ -12,6 +12,8 @@ + + From be5d220d11843783c3c91265e5f38430d866d3f5 Mon Sep 17 00:00:00 2001 From: Dr M H B Ariyaratne Date: Fri, 9 Aug 2024 23:13:10 -0700 Subject: [PATCH 17/17] Closes #6827 Signed-off-by: Dr M H B Ariyaratne --- .../divudi/bean/common/EnumController.java | 5 +- src/main/java/com/divudi/entity/Item.java | 4 +- .../ws/lims/LimsMiddlewareController.java | 269 ++++++++++-------- .../admin/lims/department_machine.xhtml | 19 +- .../admin/lims/investigation_format.xhtml | 2 +- 5 files changed, 169 insertions(+), 130 deletions(-) diff --git a/src/main/java/com/divudi/bean/common/EnumController.java b/src/main/java/com/divudi/bean/common/EnumController.java index a848de35e5..82d7c775e9 100644 --- a/src/main/java/com/divudi/bean/common/EnumController.java +++ b/src/main/java/com/divudi/bean/common/EnumController.java @@ -221,8 +221,9 @@ public > E getEnumValue(Class enumType, String enumName) { return null; // Return null if no match is found } - public Priority[] getPriorities() { - return Priority.values(); + + public List getPriorities() { + return Arrays.asList(Priority.values()); } public Dashboard[] getDashboardTypes() { diff --git a/src/main/java/com/divudi/entity/Item.java b/src/main/java/com/divudi/entity/Item.java index adcf8759c0..ac2be13c65 100644 --- a/src/main/java/com/divudi/entity/Item.java +++ b/src/main/java/com/divudi/entity/Item.java @@ -59,10 +59,10 @@ @DiscriminatorColumn(name = "DTYPE") public class Item implements Serializable, Comparable { - @OneToMany(mappedBy = "item", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "item", fetch = FetchType.EAGER) List reportItems; - @OneToMany(mappedBy = "item", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "item", fetch = FetchType.EAGER) List worksheetItems; @OneToMany(mappedBy = "item", fetch = FetchType.EAGER) diff --git a/src/main/java/com/divudi/ws/lims/LimsMiddlewareController.java b/src/main/java/com/divudi/ws/lims/LimsMiddlewareController.java index 9cdbe06ace..1c2a3e9c0c 100644 --- a/src/main/java/com/divudi/ws/lims/LimsMiddlewareController.java +++ b/src/main/java/com/divudi/ws/lims/LimsMiddlewareController.java @@ -51,6 +51,7 @@ import com.divudi.data.InvestigationItemValueType; import com.divudi.data.lab.SysMex; import com.divudi.data.lab.SysMexTypeA; +import com.divudi.ejb.PatientReportBean; import com.divudi.entity.Department; import com.divudi.entity.Institution; import com.divudi.entity.Item; @@ -118,13 +119,13 @@ public class LimsMiddlewareController { DepartmentController departmentController; @Inject MachineController machineController; + @Inject + private PatientReportBean prBean; private WebUser loggedUser; private Department loggedDepartment; private Institution loggedInstitution; - private FhirContext fhirContext = FhirContext.forR4(); - /** * Creates a new instance of LIMS */ @@ -173,10 +174,14 @@ private Response processD10Observation(JSONObject observation) { String password = observation.optString("password"); String username = observation.optString("username"); + // Convert observationValueStr to Double try { observationValueDbl = Double.valueOf(observationValueStr); } catch (NumberFormatException e) { - System.out.println("e = " + e); + System.out.println("Invalid observation value: " + observationValueStr); + return Response.status(Response.Status.BAD_REQUEST) + .entity("Invalid observation value: " + observationValueStr) + .build(); } // Log the extracted values for debugging or further processing @@ -194,19 +199,21 @@ private Response processD10Observation(JSONObject observation) { Long sampleIdLong; Machine analyzer; - DepartmentMachine departmentAnalyzer; + DepartmentMachine departmentAnalyzer = null; Department department; WebUser wu; boolean resultAdded = false; + // Find the user wu = findRequestSendingUser(username, password); if (wu == null) { - System.out.println("Cannot find the user: " + wu); + System.out.println("Cannot find the user: " + username); return Response.status(Response.Status.UNAUTHORIZED) .entity("User is not found for ID: " + username) .build(); } + // Convert sample ID to Long try { sampleIdLong = Long.valueOf(sampleId); } catch (Exception e) { @@ -216,6 +223,7 @@ private Response processD10Observation(JSONObject observation) { .build(); } + // Find the department department = departmentController.findDepartment(departmentId); if (department == null) { System.out.println("Cannot find the department: " + departmentId); @@ -224,6 +232,7 @@ private Response processD10Observation(JSONObject observation) { .build(); } + // Find the machine (analyzer) analyzer = machineController.findMachine(analyzerId); if (analyzer == null) { System.out.println("Cannot find the machine (analyzer): " + analyzerId); @@ -232,11 +241,15 @@ private Response processD10Observation(JSONObject observation) { .build(); } - departmentAnalyzer = departmentMachineController.findDepartmentMachine(departmentAnalyzerId); + // Find the department machine + if (departmentAnalyzerId != null && !departmentAnalyzerId.isEmpty()) { + departmentAnalyzer = departmentMachineController.findDepartmentMachine(departmentAnalyzerId); + } if (departmentAnalyzer == null) { departmentAnalyzer = departmentMachineController.findDepartmentMachine(department, analyzer, true); } + // Find the patient sample PatientSample ps = patientSampleFromId(sampleIdLong); if (ps == null) { System.out.println("Cannot find the patient sample: " + sampleId); @@ -245,14 +258,16 @@ private Response processD10Observation(JSONObject observation) { .build(); } + // Get patient sample components List pscs = getPatientSampleComponents(ps); - if (pscs == null) { + if (pscs == null || pscs.isEmpty()) { System.out.println("Invalid Sample Components. Please inform developers. Resend results for sample ID: " + sampleIdLong); return Response.status(Response.Status.INTERNAL_SERVER_ERROR) .entity("Invalid sample components for sample ID: " + sampleIdLong) .build(); } + // Get patient investigations List ptixs = getPatientInvestigations(pscs); if (ptixs == null || ptixs.isEmpty()) { System.out.println("Invalid Patient Investigations. Please inform developers. Resend results for sample ID: " + sampleIdLong); @@ -261,24 +276,38 @@ private Response processD10Observation(JSONObject observation) { .build(); } + // Process the patient investigations and reports + System.out.println("Process the patient investigations and reports = "); for (PatientInvestigation pi : ptixs) { + System.out.println("pi = " + pi); List prs = new ArrayList<>(); - if (pi.getInvestigation().getMachine().equals(analyzer)) { - PatientReport tpr; - tpr = getUnsavedPatientReport(pi); + + System.out.println("pi.getInvestigation() = " + pi.getInvestigation()); + if (pi.getInvestigation() == null) { + continue; + } + + System.out.println("pi.getInvestigation().getMachine() = " + pi.getInvestigation().getMachine()); + if (pi.getInvestigation().getMachine() != null && pi.getInvestigation().getMachine().equals(analyzer)) { + System.out.println("Match Machine"); + PatientReport tpr = getUnsavedPatientReport(pi); + System.out.println("tpr = " + tpr); if (tpr == null) { tpr = createNewPatientReport(pi, pi.getInvestigation(), departmentAnalyzer, wu); } + System.out.println("tpr = " + tpr); prs.add(tpr); } + System.out.println("prs = " + prs); if (prs.isEmpty()) { List temItems = getItemsForParentItem(pi.getInvestigation()); for (Item ti : temItems) { + System.out.println("ti = " + ti); if (ti instanceof Investigation) { Investigation tix = (Investigation) ti; - if (tix.getMachine().equals(analyzer)) { - PatientReport tprs; - tprs = getUnsavedPatientReport(pi); + if (tix.getMachine() != null && tix.getMachine().equals(analyzer)) { + PatientReport tprs = getUnsavedPatientReport(pi); + System.out.println("tprs = " + tprs); if (tprs == null) { tprs = createNewPatientReport(pi, tix); } @@ -288,16 +317,20 @@ private Response processD10Observation(JSONObject observation) { } } + System.out.println("prs = " + prs); for (PatientReport tpr : prs) { + System.out.println("tpr = " + tpr); for (PatientReportItemValue priv : tpr.getPatientReportItemValues()) { - if (priv.getInvestigationItem() != null) { - if (priv.getCodeSystem().equals(observationValueCodingSystem)) { - if (priv.getCodeSystemCode().equals(observationValueCode)) { - priv.setStrValue(observationValueStr); - priv.setDoubleValue(observationValueDbl); - resultAdded = true; - } - } + System.out.println("priv = " + priv); + System.out.println("priv.getInvestigationItem().getValueCodeSystem() = " + priv.getInvestigationItem()); + if (priv.getInvestigationItem() != null + && priv.getInvestigationItem().getValueCodeSystem() != null + && priv.getInvestigationItem().getValueCodeSystem().equals(observationValueCodingSystem) + && priv.getInvestigationItem().getValueCode() != null + && priv.getInvestigationItem().getValueCode().equals(observationValueCode)) { + priv.setStrValue(observationValueStr); + priv.setDoubleValue(observationValueDbl); + resultAdded = true; } } tpr.setAutomated(true); @@ -1163,7 +1196,7 @@ public PatientReport createNewPatientReport(PatientInvestigation pi, Investigati } prFacade.create(r); r.setPatientInvestigation(pi); - addPatientReportItemValuesForReport(r); + prBean.addPatientReportItemValuesForReport(r); prFacade.edit(r); } else { JsfUtil.addErrorMessage("No ptIx or Ix selected to add"); @@ -1172,6 +1205,7 @@ public PatientReport createNewPatientReport(PatientInvestigation pi, Investigati } public PatientReport createNewPatientReport(PatientInvestigation pi, Investigation ix, DepartmentMachine deptAnalyzer, WebUser u) { + System.out.println("createNewPatientReport = "); PatientReport r = null; if (pi != null && pi.getId() != null && ix != null) { r = new PatientReport(); @@ -1191,7 +1225,7 @@ public PatientReport createNewPatientReport(PatientInvestigation pi, Investigati } prFacade.create(r); r.setPatientInvestigation(pi); - addPatientReportItemValuesForReport(r); + prBean.addPatientReportItemValuesForReport(r); prFacade.edit(r); } else { JsfUtil.addErrorMessage("No ptIx or Ix selected to add"); @@ -1219,101 +1253,100 @@ public byte[] getDefaultImageValue(InvestigationItem item, Patient patient) { return null; } - public void addPatientReportItemValuesForReport(PatientReport ptReport) { - String sql = ""; - Investigation temIx = (Investigation) ptReport.getItem(); - for (ReportItem ii : temIx.getReportItems()) { - PatientReportItemValue val = null; - if ((ii.getIxItemType() == InvestigationItemType.Value || ii.getIxItemType() == InvestigationItemType.Calculation || ii.getIxItemType() == InvestigationItemType.Flag || ii.getIxItemType() == InvestigationItemType.Template) && ii.isRetired() == false) { - if (ptReport.getId() == null || ptReport.getId() == 0) { - - val = new PatientReportItemValue(); - if (ii.getIxItemValueType() == InvestigationItemValueType.Varchar) { - val.setStrValue(getDefaultVarcharValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); - } else if (ii.getIxItemValueType() == InvestigationItemValueType.Memo) { - val.setLobValue(getDefaultMemoValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); - } else if (ii.getIxItemValueType() == InvestigationItemValueType.Double) { - val.setDoubleValue(getDefaultDoubleValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); - } else if (ii.getIxItemValueType() == InvestigationItemValueType.Image) { - val.setBaImage(getDefaultImageValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); - } else { - } - val.setInvestigationItem((InvestigationItem) ii); - val.setPatient(ptReport.getPatientInvestigation().getPatient()); - val.setPatientEncounter(ptReport.getPatientInvestigation().getEncounter()); - val.setPatientReport(ptReport); - // ptReport.getPatientReportItemValues().add(val); - ////// // System.out.println("New value added to pr teport" + ptReport); - - } else { - sql = "select i from PatientReportItemValue i where i.patientReport=:ptRp" - + " and i.investigationItem=:inv "; - HashMap hm = new HashMap(); - hm.put("ptRp", ptReport); - hm.put("inv", ii); - val = ptRivFacade.findFirstByJpql(sql, hm); - if (val == null) { - ////// // System.out.println("val is null"); - val = new PatientReportItemValue(); - if (ii.getIxItemValueType() == InvestigationItemValueType.Varchar) { - val.setStrValue(getDefaultVarcharValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); - } else if (ii.getIxItemValueType() == InvestigationItemValueType.Memo) { - val.setLobValue(getDefaultMemoValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); - } else if (ii.getIxItemValueType() == InvestigationItemValueType.Double) { - val.setDoubleValue(getDefaultDoubleValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); - } else if (ii.getIxItemValueType() == InvestigationItemValueType.Image) { - val.setBaImage(getDefaultImageValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); - } else { - } - val.setInvestigationItem((InvestigationItem) ii); - val.setPatient(ptReport.getPatientInvestigation().getPatient()); - val.setPatientEncounter(ptReport.getPatientInvestigation().getEncounter()); - val.setPatientReport(ptReport); - //ptReport.getPatientReportItemValues().add(val); - ////// // System.out.println("value added to pr teport" + ptReport); - - } - - } - } else if (ii.getIxItemType() == InvestigationItemType.DynamicLabel && ii.isRetired() == false) { - if (ptReport.getId() == null || ptReport.getId() == 0) { - - val = new PatientReportItemValue(); - val.setStrValue(getPatientDynamicLabel((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); - val.setInvestigationItem((InvestigationItem) ii); - val.setPatient(ptReport.getPatientInvestigation().getPatient()); - val.setPatientEncounter(ptReport.getPatientInvestigation().getEncounter()); - val.setPatientReport(ptReport); - // ptReport.getPatientReportItemValues().add(val); - ////// // System.out.println("New value added to pr teport" + ptReport); - - } else { - sql = "select i from PatientReportItemValue i where i.patientReport.id = " + ptReport.getId() + " and i.investigationItem.id = " + ii.getId() + " and i.investigationItem.ixItemType = com.divudi.data.InvestigationItemType.Value"; - val = ptRivFacade.findFirstByJpql(sql); - if (val == null) { - val = new PatientReportItemValue(); - val.setStrValue(getPatientDynamicLabel((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); - val.setInvestigationItem((InvestigationItem) ii); - val.setPatient(ptReport.getPatientInvestigation().getPatient()); - val.setPatientEncounter(ptReport.getPatientInvestigation().getEncounter()); - val.setPatientReport(ptReport); - // ptReport.getPatientReportItemValues().add(val); - ////// // System.out.println("value added to pr teport" + ptReport); - - } - - } - } - - if (val != null) { - - ptRivFacade.create(val); - - ptReport.getPatientReportItemValues().add(val); - } - } - } - +// public void addPatientReportItemValuesForReport(PatientReport ptReport) { +// String sql = ""; +// Investigation temIx = (Investigation) ptReport.getItem(); +// for (ReportItem ii : temIx.getReportItems()) { +// PatientReportItemValue val = null; +// if ((ii.getIxItemType() == InvestigationItemType.Value || ii.getIxItemType() == InvestigationItemType.Calculation || ii.getIxItemType() == InvestigationItemType.Flag || ii.getIxItemType() == InvestigationItemType.Template) && ii.isRetired() == false) { +// if (ptReport.getId() == null || ptReport.getId() == 0) { +// +// val = new PatientReportItemValue(); +// if (ii.getIxItemValueType() == InvestigationItemValueType.Varchar) { +// val.setStrValue(getDefaultVarcharValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); +// } else if (ii.getIxItemValueType() == InvestigationItemValueType.Memo) { +// val.setLobValue(getDefaultMemoValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); +// } else if (ii.getIxItemValueType() == InvestigationItemValueType.Double) { +// val.setDoubleValue(getDefaultDoubleValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); +// } else if (ii.getIxItemValueType() == InvestigationItemValueType.Image) { +// val.setBaImage(getDefaultImageValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); +// } else { +// } +// val.setInvestigationItem((InvestigationItem) ii); +// val.setPatient(ptReport.getPatientInvestigation().getPatient()); +// val.setPatientEncounter(ptReport.getPatientInvestigation().getEncounter()); +// val.setPatientReport(ptReport); +// // ptReport.getPatientReportItemValues().add(val); +// ////// // System.out.println("New value added to pr teport" + ptReport); +// +// } else { +// sql = "select i from PatientReportItemValue i where i.patientReport=:ptRp" +// + " and i.investigationItem=:inv "; +// HashMap hm = new HashMap(); +// hm.put("ptRp", ptReport); +// hm.put("inv", ii); +// val = ptRivFacade.findFirstByJpql(sql, hm); +// if (val == null) { +// ////// // System.out.println("val is null"); +// val = new PatientReportItemValue(); +// if (ii.getIxItemValueType() == InvestigationItemValueType.Varchar) { +// val.setStrValue(getDefaultVarcharValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); +// } else if (ii.getIxItemValueType() == InvestigationItemValueType.Memo) { +// val.setLobValue(getDefaultMemoValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); +// } else if (ii.getIxItemValueType() == InvestigationItemValueType.Double) { +// val.setDoubleValue(getDefaultDoubleValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); +// } else if (ii.getIxItemValueType() == InvestigationItemValueType.Image) { +// val.setBaImage(getDefaultImageValue((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); +// } else { +// } +// val.setInvestigationItem((InvestigationItem) ii); +// val.setPatient(ptReport.getPatientInvestigation().getPatient()); +// val.setPatientEncounter(ptReport.getPatientInvestigation().getEncounter()); +// val.setPatientReport(ptReport); +// //ptReport.getPatientReportItemValues().add(val); +// ////// // System.out.println("value added to pr teport" + ptReport); +// +// } +// +// } +// } else if (ii.getIxItemType() == InvestigationItemType.DynamicLabel && ii.isRetired() == false) { +// if (ptReport.getId() == null || ptReport.getId() == 0) { +// +// val = new PatientReportItemValue(); +// val.setStrValue(getPatientDynamicLabel((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); +// val.setInvestigationItem((InvestigationItem) ii); +// val.setPatient(ptReport.getPatientInvestigation().getPatient()); +// val.setPatientEncounter(ptReport.getPatientInvestigation().getEncounter()); +// val.setPatientReport(ptReport); +// // ptReport.getPatientReportItemValues().add(val); +// ////// // System.out.println("New value added to pr teport" + ptReport); +// +// } else { +// sql = "select i from PatientReportItemValue i where i.patientReport.id = " + ptReport.getId() + " and i.investigationItem.id = " + ii.getId() + " and i.investigationItem.ixItemType = com.divudi.data.InvestigationItemType.Value"; +// val = ptRivFacade.findFirstByJpql(sql); +// if (val == null) { +// val = new PatientReportItemValue(); +// val.setStrValue(getPatientDynamicLabel((InvestigationItem) ii, ptReport.getPatientInvestigation().getPatient())); +// val.setInvestigationItem((InvestigationItem) ii); +// val.setPatient(ptReport.getPatientInvestigation().getPatient()); +// val.setPatientEncounter(ptReport.getPatientInvestigation().getEncounter()); +// val.setPatientReport(ptReport); +// // ptReport.getPatientReportItemValues().add(val); +// ////// // System.out.println("value added to pr teport" + ptReport); +// +// } +// +// } +// } +// +// if (val != null) { +// +// ptRivFacade.create(val); +// +// ptReport.getPatientReportItemValues().add(val); +// } +// } +// } public String getPatientDynamicLabel(InvestigationItem ii, Patient p) { String dl; String sql; diff --git a/src/main/webapp/admin/lims/department_machine.xhtml b/src/main/webapp/admin/lims/department_machine.xhtml index 98f110d779..10c646ecca 100644 --- a/src/main/webapp/admin/lims/department_machine.xhtml +++ b/src/main/webapp/admin/lims/department_machine.xhtml @@ -9,7 +9,7 @@ - + @@ -61,12 +61,12 @@ > + ajax="false" + rendered="#{departmentMachineController.department ne null}" + action="#{departmentMachineController.clearDeptAndDept()}" + icon="pi pi-times" styleClass="ui-button-danger" > - + + + + + - + + diff --git a/src/main/webapp/admin/lims/investigation_format.xhtml b/src/main/webapp/admin/lims/investigation_format.xhtml index 5026065f3f..5b061b5931 100644 --- a/src/main/webapp/admin/lims/investigation_format.xhtml +++ b/src/main/webapp/admin/lims/investigation_format.xhtml @@ -336,7 +336,7 @@ - +