public FluidBalanceInstanceVoCollection getFluidBalanceInstancesForContextAndDate(CareContextRefVo contextVo, DateTime datetimeStartShift, DateTime datetimeEndShift) { DomainFactory factory = getDomainFactory(); ArrayList<String> markers = new ArrayList<String>(); ArrayList<Object> values = new ArrayList<Object>(); final String andStr = " and "; String query = "select distinct dfb.fluidBalanceInstances from DailyFluidBalance as dfb left join dfb.fluidBalanceInstances as fbi where dfb.isRIE is null"; StringBuffer hql = new StringBuffer(""); if (contextVo != null) { hql.append(andStr + " dfb.careContext.id = :cc"); markers.add("cc"); values.add(contextVo.getID_CareContext()); } if (datetimeStartShift != null) { hql.append(andStr + " dfb.shiftDetails.startDateTime >= :sdate "); markers.add("sdate"); values.add(datetimeStartShift.getJavaDate()); } if (datetimeEndShift != null) { hql.append(andStr + " ( dfb.shiftDetails.endDateTime <= :edate ) "); markers.add("edate"); values.add(datetimeEndShift.getJavaDate()); } query += hql.toString(); List<?> fluidList = factory.find(query, markers, values); return FluidBalanceInstanceVoAssembler.createFluidBalanceInstanceVoCollectionFromFluidBalanceInstance(fluidList).sort(SortOrder.DESCENDING); }