diff --git a/openelis/src/us/mn/state/health/lims/referral/daoimpl/ReferralDAOImpl.java b/openelis/src/us/mn/state/health/lims/referral/daoimpl/ReferralDAOImpl.java index 99740d53b..e0593389f 100644 --- a/openelis/src/us/mn/state/health/lims/referral/daoimpl/ReferralDAOImpl.java +++ b/openelis/src/us/mn/state/health/lims/referral/daoimpl/ReferralDAOImpl.java @@ -89,9 +89,12 @@ public Referral getReferralByAnalysisId(String analysisId) throws LIMSRuntimeExc @SuppressWarnings("unchecked") public List getAllUncanceledOpenReferrals(int resultPageSize,int resultPageNumber) throws LIMSRuntimeException { - String sql = "From Referral r where" + - " r.analysis.statusId in (" + StatusOfSampleUtil.getStatusID(StatusOfSampleUtil.AnalysisStatus.ReferedOut) + "," + StatusOfSampleUtil.getStatusID(StatusOfSampleUtil.AnalysisStatus.BiologistRejectedRO) + ")" + - " and r.canceled = 'false' order by r.requestDate desc"; + String sql = "select r From Referral r, Analysis a, Test t, SampleItem si, Sample s where r.analysis.id = a.id and a.test.id = t.id " + + "and a.sampleItem.id = si.id and si.sample.id = s.id " + + "and a.statusId in (" + StatusOfSampleUtil.getStatusID(StatusOfSampleUtil.AnalysisStatus.ReferedOut) + "," + StatusOfSampleUtil.getStatusID(StatusOfSampleUtil.AnalysisStatus.BiologistRejectedRO) + ") " + + "and r.canceled = 'false' " + + "order by date(r.requestDate) DESC, s.accessionNumber DESC , t.sortOrder ASC"; + try { Query query = HibernateUtil.getSession().createQuery(sql).setMaxResults(resultPageSize).setFirstResult(resultPageSize*resultPageNumber); List referrals = query.list(); @@ -119,12 +122,13 @@ public long getAllUncanceledOpenReferralsCount() throws LIMSRuntimeException { } public List getAllUncanceledOpenReferralsByPatientSTNumber(String patientSTNumber) throws LIMSRuntimeException { - String sql = "select r From Referral r, SampleHuman sh, PatientIdentity pi"+ - " where r.analysis.sampleItem.sample.id = sh.sampleId" + + String sql = "select r From Referral r, SampleHuman sh, PatientIdentity pi, Test t, SampleItem si, Sample s"+ + " where r.analysis.sampleItem.sample.id = sh.sampleId and r.analysis.test.id = t.id and r.analysis.sampleItem.id = si.id and si.sample.id = s.id" + " and r.analysis.statusId in (" + StatusOfSampleUtil.getStatusID(StatusOfSampleUtil.AnalysisStatus.ReferedOut) + "," + StatusOfSampleUtil.getStatusID(StatusOfSampleUtil.AnalysisStatus.BiologistRejectedRO) + ")" + " and sh.patientId = pi.patientId and pi.identityTypeId = "+ PatientIdentityTypeMap.getInstance().getIDForType("ST") + " and pi.identityData in ( :patientSTNumber )" + - " and r.canceled = 'false' order by r.requestDate desc"; + " and r.canceled = 'false' " + + " order by date(r.requestDate) desc, s.accessionNumber DESC , t.sortOrder ASC"; try { Query query = HibernateUtil.getSession().createQuery(sql); query.setParameterList("patientSTNumber", getHealthPrefixedList(patientSTNumber));