public QryOrderMsgVoCollection listOrdersByDateTimeRange(PatientId patIdVo, DateTime dtFrom, DateTime dtTo) { Patient domPatient = null; if (patIdVo != null) { domPatient = findPatientById(patIdVo); if (null==domPatient) return null; } ArrayList markers = new ArrayList(); ArrayList values = new ArrayList(); StringBuffer sb = new StringBuffer("select om from OrderMessage om, OcsOrderSession ord, " + "OrderInvestigation oi where om.orderDetails.id = ord.id " + "and oi.orderDetails = ord.id "); if (domPatient != null) { sb.append(" and ord.patient = :domPatient"); markers.add("domPatient"); values.add(domPatient); } if (dtFrom != null && dtTo != null && dtFrom.isLessOrEqualThan(dtTo)) { sb.append(" and ( (ord.systemInformation.creationDateTime >= :fromDate and ord.systemInformation.creationDateTime <= :toDate)"); sb.append(" or (om.systemInformation.lastUpdateDateTime >= :fromDate and om.systemInformation.lastUpdateDateTime <= :toDate))"); markers.add("fromDate"); values.add(dtFrom.getJavaDate()); markers.add("toDate"); values.add(dtTo.addDays(1).getJavaDate()); } sb.append(" order by ord.systemInformation.creationDateTime desc"); List messages = getDomainFactory().find(sb.toString(), markers, values); return QryOrderMsgVoAssembler.createQryOrderMsgVoCollectionFromOrderMessage(messages); }