Skip to content

Commit

Permalink
Merge pull request #14 from open-osp/bugfix/pathnet-results-data-cast
Browse files Browse the repository at this point in the history
Fix ClassCastException using TypedQuery
  • Loading branch information
warrendennis authored Feb 14, 2025
2 parents 492a023 + d7571ba commit 241de08
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 25 deletions.
38 changes: 26 additions & 12 deletions src/main/java/org/oscarehr/billing/CA/BC/dao/Hl7MshDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import java.util.List;

import javax.persistence.Query;
import javax.persistence.TypedQuery;

import org.oscarehr.billing.CA.BC.model.Hl7Msh;
import org.oscarehr.billing.CA.BC.util.PathNetLabResults;
import org.oscarehr.common.dao.AbstractDaoImpl;
import org.springframework.stereotype.Repository;

Expand All @@ -40,8 +42,12 @@ public Hl7MshDao() {
super(Hl7Msh.class);
}

public List<Object[]> findPathnetResultsDataByPatientNameHinStatusAndProvider(String patientName, String patientHealthNumber, String status, String providerNo, String labType) {
String sql = "SELECT msh, pid, orc, obr, providerLabRouting, MIN(obr.resultStatus) " +
public List<PathNetLabResults> findPathnetResultsDataByPatientNameHinStatusAndProvider(String patientName, String patientHealthNumber, String status, String providerNo, String labType) {
/*
* Below query use a constructor expression (SELECT new org.oscarehr.billing.CA.BC.model.PathNetLabResults(Hl7Msh, Hl7Pid, Hl7Orc, Hl7Obr, ProviderLabRoutingModel, String))
* and TypedQuery<PathNetLabResults> to directly create instances of PathNetLabResults from the database results
* */
String sql = "SELECT new org.oscarehr.billing.CA.BC.util.PathNetLabResults( msh, pid, orc, obr, providerLabRouting, MIN(obr.resultStatus) )" +
"FROM Hl7Msh msh, Hl7Pid pid, Hl7Orc orc, Hl7Obr obr, ProviderLabRoutingModel providerLabRouting " +
"WHERE providerLabRouting.labNo = pid.messageId " +
"AND pid.messageId = msh.messageId " +
Expand All @@ -53,8 +59,8 @@ public List<Object[]> findPathnetResultsDataByPatientNameHinStatusAndProvider(St
"AND pid.patientName like :patientName " +
"AND pid.externalId like :patientHealthNumber " +
"GROUP BY pid.id";
Query query = entityManager.createQuery(sql);

TypedQuery<PathNetLabResults> query = entityManager.createQuery(sql, PathNetLabResults.class);
query.setParameter("status", status);
query.setParameter("providerNo", providerNo);
query.setParameter("labType", labType);
Expand All @@ -63,23 +69,31 @@ public List<Object[]> findPathnetResultsDataByPatientNameHinStatusAndProvider(St
return query.getResultList();
}

public List<Object[]> findPathnetResultsByLabNo(Integer labNo) {
String sql = "SELECT msh, pid, orc, obr, providerLabRouting, MIN(obr.resultStatus) " +
public List<PathNetLabResults> findPathnetResultsByLabNo(Integer labNo) {
/*
* Below query use a constructor expression (SELECT new org.oscarehr.billing.CA.BC.model.PathNetLabResults(Hl7Msh, Hl7Pid, Hl7Orc, Hl7Obr, ProviderLabRoutingModel, String))
* and TypedQuery<PathNetLabResults> to directly create instances of PathNetLabResults from the database results
* */
String sql = "SELECT new org.oscarehr.billing.CA.BC.util.PathNetLabResults( msh, pid, orc, obr, providerLabRouting, MIN(obr.resultStatus) )" +
"FROM Hl7Msh msh, Hl7Pid pid, Hl7Orc orc, Hl7Obr obr, ProviderLabRoutingModel providerLabRouting " +
"WHERE providerLabRouting.labNo = pid.messageId " +
"AND pid.messageId = msh.messageId " +
"AND pid.id = orc.pidId " +
"AND pid.id = obr.pidId "+
"AND pid.messageId= :labNo " +
"GROUP BY pid.id";
Query query = entityManager.createQuery(sql);

TypedQuery<PathNetLabResults> query = entityManager.createQuery(sql, PathNetLabResults.class);
query.setParameter("labNo", labNo);
return query.getResultList();
}

public List<Object[]> findPathnetResultsDeomgraphicNo(Integer demographicNo, String labType) {
String sql = "SELECT msh, pid, orc, obr, patientLabRouting, MIN(obr.resultStatus) " +

public List<PathNetLabResults> findPathnetResultsDeomgraphicNo(Integer demographicNo, String labType) {
/*
* Below query use a constructor expression (SELECT new org.oscarehr.billing.CA.BC.model.PathNetLabResults(Hl7Msh, Hl7Pid, Hl7Orc, Hl7Obr, PatientLabRouting, String))
* and TypedQuery<PathNetLabResults> to directly create instances of PathNetLabResults from the database results
* */
String sql = "SELECT new org.oscarehr.billing.CA.BC.util.PathNetLabResults( msh, pid, orc, obr, patientLabRouting, MIN(obr.resultStatus) )" +
"FROM Hl7Msh msh, Hl7Pid pid, Hl7Orc orc, Hl7Obr obr, PatientLabRouting patientLabRouting " +
"WHERE patientLabRouting.labNo = pid.id " +
"AND pid.id = orc.pidId " +
Expand All @@ -89,7 +103,7 @@ public List<Object[]> findPathnetResultsDeomgraphicNo(Integer demographicNo, Str
"AND patientLabRouting.demographicNo = :demographicNo " +
"GROUP BY pid.id";

Query query = entityManager.createQuery(sql);
TypedQuery<PathNetLabResults> query = entityManager.createQuery(sql, PathNetLabResults.class);
query.setParameter("demographicNo", demographicNo);
query.setParameter("labType", labType);
return query.getResultList();
Expand Down
114 changes: 114 additions & 0 deletions src/main/java/org/oscarehr/billing/CA/BC/util/PathNetLabResults.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/**
* Copyright (c) 2005-2012. Centre for Research on Inner City Health, St. Michael's Hospital, Toronto. All Rights Reserved.
* This software is published under the GPL GNU General Public License.
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* <p>
* This software was written for
* Centre for Research on Inner City Health, St. Michael's Hospital,
* Toronto, Ontario, Canada
*/

package org.oscarehr.billing.CA.BC.util;

import org.oscarehr.billing.CA.BC.model.Hl7Msh;
import org.oscarehr.billing.CA.BC.model.Hl7Obr;
import org.oscarehr.billing.CA.BC.model.Hl7Orc;
import org.oscarehr.billing.CA.BC.model.Hl7Pid;
import org.oscarehr.common.model.PatientLabRouting;
import org.oscarehr.common.model.ProviderLabRoutingModel;

public class PathNetLabResults {
private Hl7Msh hl7Msh;
private Hl7Pid hl7Pid;
private Hl7Orc hl7Orc;
private Hl7Obr hl7Obr;
private ProviderLabRoutingModel providerLabRouting;
private PatientLabRouting patientLabRouting;
private Long minResultStatus;

public PathNetLabResults(Hl7Msh hl7Msh, Hl7Pid hl7Pid, Hl7Orc hl7Orc, Hl7Obr hl7Obr, ProviderLabRoutingModel providerLabRouting, String minResultStatus) {
this.hl7Msh = hl7Msh;
this.hl7Pid = hl7Pid;
this.hl7Orc = hl7Orc;
this.hl7Obr = hl7Obr;
this.providerLabRouting = providerLabRouting;
this.minResultStatus = Long.valueOf(minResultStatus);
}

public PathNetLabResults(Hl7Msh hl7Msh, Hl7Pid hl7Pid, Hl7Orc hl7Orc, Hl7Obr hl7Obr, PatientLabRouting patientLabRouting, String minResultStatus) {
this.hl7Msh = hl7Msh;
this.hl7Pid = hl7Pid;
this.hl7Orc = hl7Orc;
this.hl7Obr = hl7Obr;
this.patientLabRouting = patientLabRouting;
this.minResultStatus = Long.valueOf(minResultStatus);
}

public Hl7Msh getHl7Msh() {
return hl7Msh;
}

public void setHl7Msh(Hl7Msh hl7Msh) {
this.hl7Msh = hl7Msh;
}

public Hl7Pid getHl7Pid() {
return hl7Pid;
}

public void setHl7Pid(Hl7Pid hl7Pid) {
this.hl7Pid = hl7Pid;
}

public Hl7Orc getHl7Orc() {
return hl7Orc;
}

public void setHl7Orc(Hl7Orc hl7Orc) {
this.hl7Orc = hl7Orc;
}

public Hl7Obr getHl7Obr() {
return hl7Obr;
}

public void setHl7Obr(Hl7Obr hl7Obr) {
this.hl7Obr = hl7Obr;
}

public ProviderLabRoutingModel getProviderLabRouting() {
return providerLabRouting;
}

public void setProviderLabRouting(ProviderLabRoutingModel providerLabRouting) {
this.providerLabRouting = providerLabRouting;
}

public PatientLabRouting getPatientLabRouting() {
return patientLabRouting;
}

public void setPatientLabRouting(PatientLabRouting patientLabRouting) {
this.patientLabRouting = patientLabRouting;
}

public Long getMinResultStatus() {
return minResultStatus;
}

public void setMinResultStatus(Long minResultStatus) {
this.minResultStatus = minResultStatus;
}
}
30 changes: 17 additions & 13 deletions src/main/java/oscar/oscarLab/ca/bc/PathNet/PathnetResultsData.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
import org.apache.logging.log4j.Logger;
import org.oscarehr.billing.CA.BC.dao.*;
import org.oscarehr.billing.CA.BC.model.*;
import org.oscarehr.billing.CA.BC.util.PathNetLabResults;
import org.oscarehr.common.dao.ConsultDocsDao;
import org.oscarehr.common.dao.ConsultResponseDocDao;
import org.oscarehr.common.dao.EFormDocsDao;
import org.oscarehr.common.dao.PatientLabRoutingDao;
import org.oscarehr.common.model.ConsultDocs;
import org.oscarehr.common.model.EFormDocs;
import org.oscarehr.common.model.PatientLabRouting;
import org.oscarehr.common.model.ProviderLabRoutingModel;
import org.oscarehr.util.SpringUtils;
import oscar.oscarLab.ca.on.LabResultData;
import oscar.util.ConversionUtils;
Expand Down Expand Up @@ -152,31 +152,35 @@ public ArrayList<LabResultData> populatePathnetResultsData(String providerNo, St

ArrayList<LabResultData> labResults = new ArrayList<LabResultData>();
try {
List<Object[]> pathnetResultsData = null;
List<PathNetLabResults> pathNetLabResultsList = null;

if(labNo != null && labNo.intValue()>0) {
pathnetResultsData = hl7MshDao.findPathnetResultsByLabNo(labNo);
pathNetLabResultsList = hl7MshDao.findPathnetResultsByLabNo(labNo);
} else {
if (demographicNo == null) {
pathnetResultsData = hl7MshDao.findPathnetResultsDataByPatientNameHinStatusAndProvider(patientLastName + "%^" + patientFirstName + "%", "%" + patientHealthNumber + "%", "%" + status + "%", providerNo.equals("") ? "%" : providerNo, "BCP");
pathNetLabResultsList = hl7MshDao.findPathnetResultsDataByPatientNameHinStatusAndProvider(patientLastName + "%^" + patientFirstName + "%", "%" + patientHealthNumber + "%", "%" + status + "%", providerNo.equals("") ? "%" : providerNo, "BCP");
} else {
pathnetResultsData = hl7MshDao.findPathnetResultsDeomgraphicNo(ConversionUtils.fromIntString(demographicNo), "BCP");
pathNetLabResultsList = hl7MshDao.findPathnetResultsDeomgraphicNo(ConversionUtils.fromIntString(demographicNo), "BCP");
}
}

for (Object[] o : pathnetResultsData) {
Hl7Msh msh = (Hl7Msh) o[0];
Hl7Pid pid = (Hl7Pid) o[1];
Hl7Orc orc = (Hl7Orc) o[2];
ProviderLabRoutingModel p = (ProviderLabRoutingModel) o[4];
Long stat = (Long) o[5];
for (PathNetLabResults o : pathNetLabResultsList) {
Hl7Msh msh = o.getHl7Msh();
Hl7Pid pid = o.getHl7Pid();
Hl7Orc orc = o.getHl7Orc();
Long stat = o.getMinResultStatus();

String providerLabRoutingStatus = null;
if (Objects.nonNull(o.getProviderLabRouting())) {
providerLabRoutingStatus = o.getProviderLabRouting().getStatus();
}

LabResultData lbData = new LabResultData(LabResultData.EXCELLERIS);
lbData.labType = LabResultData.EXCELLERIS;
lbData.segmentID = "" + pid.getMessageId();

if (demographicNo == null && !providerNo.equals("0")) {
lbData.acknowledgedStatus = p.getStatus();
if (demographicNo == null && !providerNo.equals("0") && providerLabRoutingStatus != null) {
lbData.acknowledgedStatus = providerLabRoutingStatus;
} else {
lbData.acknowledgedStatus = "U";
}
Expand Down

0 comments on commit 241de08

Please sign in to comment.