public ReferralAppointmentDetailsOcsOrderVoCollection getRefAppDetOcsOrder(String listId, PatientRefVo patientRef, OrderInvestigationRefVo orderInvRef) { if (patientRef==null || patientRef.getID_Patient()==null) throw new CodingRuntimeException("Patient parameter cannot be null !"); ArrayList<String> markers = new ArrayList<String>(); ArrayList<Object> values = new ArrayList<Object>(); StringBuffer hql = new StringBuffer(); hql.append("select ocsOrd from OcsOrderSession as ocsOrd left join ocsOrd.investigations as investigations left join investigations.investigation as inv left join ocsOrd.patient as patient "); hql.append("where inv.id in " + listId ) ; hql.append(" and patient.id=:PatID "); markers.add("PatID"); values.add(patientRef.getID_Patient()); if (orderInvRef!=null && orderInvRef.getID_OrderInvestigationIsNotNull()) { hql.append(" and investigations.id=:OrderInvId "); markers.add("OrderInvId"); values.add(orderInvRef.getID_OrderInvestigation()); } List<?> ListReffApp = getDomainFactory().find(hql.toString(), markers, values); return ReferralAppointmentDetailsOcsOrderVoAssembler.createReferralAppointmentDetailsOcsOrderVoCollectionFromOcsOrderSession(ListReffApp); }