gt: 		if (fromDate != null)
context: //#############################################################################
  //#                                                                           #
  //#  Copyright (C) <2014>  <IMS MAXIMS>                                       #
  //#                                                                           #
  //#  This program is free software: you can redistribute it and/or modify     #
  //#  it under the terms of the GNU Affero General Public License as           #
  //#  published by the Free Software Foundation, either version 3 of the       #
  //#  License, or (at your option) any later version.                          # 
  //#                                                                           #
  //#  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 Affero General Public License for more details.                      #
  //#                                                                           #
  //#  You should have received a copy of the GNU Affero General Public License #
  //#  along with this program.  If not, see <http://www.gnu.org/licenses/>.    #
  //#                                                                           #
  //#############################################################################
  //#EOH
  // This code was generated by Alexie Ursache using IMS Development Environment (version 1.53 build 2656.22861)
  // Copyright (C) 1995-2007 IMS MAXIMS plc. All rights reserved.
  
  package ims.ocrr.domain.impl;
  import ims.RefMan.vo.CatsReferralListVo;
  import ims.core.clinical.vo.ServiceRefVo;
  import ims.core.domain.Reports;
  import ims.core.domain.impl.ReportsImpl;
  import ims.core.resource.place.vo.LocationRefVo;
  import ims.core.vo.LocationLiteVoCollection;
  import ims.core.vo.ServiceLiteVoCollection;
  import ims.core.vo.domain.LocationLiteVoAssembler;
  import ims.core.vo.domain.ServiceLiteVoAssembler;
  import ims.core.vo.lookups.LocationType;
  import ims.core.vo.lookups.ServiceCategory;
  import ims.domain.DomainFactory;
  import ims.framework.enumerations.SortOrder;
  import ims.framework.interfaces.IAppRole;
  import ims.framework.utils.Date;
  import ims.framework.utils.Time;
  import ims.ocrr.domain.ClinicalImagingResults;
  import ims.ocrr.domain.SelectandOrder;
  import ims.ocrr.domain.base.impl.BaseRadiologyOrdersImpl;
  import ims.ocrr.orderingresults.vo.OcsOrderSessionRefVo;
  import ims.ocrr.vo.OrdInvXOStatusHistoryLiteVoCollection;
  import ims.ocrr.vo.PathologyOrderVoCollection;
  import ims.ocrr.vo.RadiologyOrderVo;
  import ims.ocrr.vo.RadiologyOrderVoCollection;
  import ims.ocrr.vo.RoleDisciplineSecurityLevelLiteGCVo;
  import ims.ocrr.vo.domain.PathologyOrderVoAssembler;
  import ims.ocrr.vo.domain.RadiologyOrderVoAssembler;
  import ims.ocrr.vo.lookups.Category;
  import ims.ocrr.vo.lookups.OrderInvStatus;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  
  public class RadiologyOrdersImpl  extends BaseRadiologyOrdersImpl
  {
  
  	private static final long serialVersionUID = 1L;
  
  	public LocationLiteVoCollection listLocation(LocationType type, Boolean active)
  	{
  		StringBuffer query = new StringBuffer("from Location as l1_1");
  		String operator = " where";
  		ArrayList paramValues = new ArrayList(3); 
  		ArrayList<String> paramNames = new ArrayList<String>(3);
  		
  		if(type != null)
  		{
  			query.append(operator);
  			query.append(" l1_1.type = :TYPE");
  			paramValues.add(getDomLookup(type));
  			paramNames.add("TYPE");
  			operator = " and ";
  		}
  		
  		if(active != null)
  		{
  			query.append(operator);
  			query.append(" l1_1.isActive = :STATUS");
  			paramValues.add(active);
  			paramNames.add("STATUS");
  			operator = " and ";
  		}
  		
  		//WDEV-2821
  		if(type != null && type.equals(LocationType.CLINICALIMAGINGDEPARTMENT))
  		{
  			//wdev-2730
  			query.append(operator);
  			query.append(" l1_1.isVirtual = :VIRTUAL");
  			paramValues.add(Boolean.FALSE);
  			paramNames.add("VIRTUAL");
  		}
  		
  		// WDEV-10539, WDEV-10540
  		query.append(" order by l1_1.name");
  		
  		List list = getDomainFactory().find(query.toString(), paramNames, paramValues);
  		
  		return LocationLiteVoAssembler.createLocationLiteVoCollectionFromLocation(list);
  	}
  	
  	public ServiceLiteVoCollection listService(LocationRefVo locationRefVo, ServiceCategory serviceCategory)
  	{
  		StringBuffer query = new StringBuffer("select s1_1 from LocationService as l1_1 left join l1_1.service as s1_1");
  		String clause = " where";
  		ArrayList<String> paramNames = new ArrayList<String>(2);
  		ArrayList paramValues = new ArrayList(2);
  
  		if (locationRefVo != null)
  		{
  			query.append(clause);
  
  			String locationID = "LOCATION_ID";
  			query.append(" l1_1.location.id = :" + locationID);
  			paramNames.add(locationID);
  			paramValues.add(locationRefVo.getID_Location());
  
  			clause = " and";
  		}
  
  		query.append(clause);
  
  		String activeParam = "ACTIVE";
  		query.append(" l1_1.isActive = :" + activeParam);
  		paramNames.add(activeParam);
  		paramValues.add(Boolean.TRUE);
  		clause = " and";
  
  		if (serviceCategory != null)
  		{
  			query.append(clause);
  
  			activeParam = "SERVICE_CATEGORY";
  			query.append(" l1_1.service.serviceCategory = :" + activeParam);
  			paramNames.add(activeParam);
  			paramValues.add(getDomLookup(serviceCategory));
  
  			clause = " and";
  		}
  		
  		// WDEV-10539, WDEV-10540
  		query.append(" order by l1_1.service.serviceName");
  		
  		List list = getDomainFactory().find(query.toString(), paramNames, paramValues);
  		return ServiceLiteVoAssembler.createServiceLiteVoCollectionFromService(list);
  	}
  
  	/**
  	 * getReportAndTemplate
  	 */
  	public String[] getReportAndTemplate(Integer reportId, Integer templateId)
  	{
  		String[] result = null;
  		
  		DomainFactory factory = getDomainFactory();
  		
  		List lst = factory.find("select r1_1.reportXml, t1_1.templateXml, r1_1.reportName, r1_1.reportDescription, t1_1.name, t1_1.description from ReportBo as r1_1 left join r1_1.templates as t1_1 where (r1_1.id = :rid  and t1_1.id = :tid)", new String[] {"rid", "tid"}, new Object[] {reportId, templateId});
  		
  		if(lst.iterator().hasNext())
  		{
  			Object[] obj = (Object[])lst.iterator().next();
  			
  			result = new String[] {(String)obj[0], (String)obj[1], (String)obj[2], (String)obj[3], (String)obj[4], (String)obj[5]};
  		}
  		
  		return result;
  	}
  
  	/**
  	* listAssignedReports
  	*/
  	public ims.admin.vo.ReportVoCollection listAssignedReports(Integer formId)
  	{
  		Reports impl = (Reports)getDomainImpl(ReportsImpl.class);
  		
  		return impl.listAssignedReports(formId);
  	}
  
  	// WDEV-11643
  	private List listOrderInvestigation(ServiceRefVo serviceRefVo, LocationRefVo locationRefVo, OrderInvStatus[] orderInvStatus, Category category, Date fromDate, Date toDate)
  	{
  		StringBuffer query = new StringBuffer("from OrderInvestigation as o1_1");
  		String clause = " where";
  
  		ArrayList<String> paramNames = new ArrayList<String>(4);
  		ArrayList paramValues = new ArrayList(4);
  
  		if (orderInvStatus != null && orderInvStatus.length > 0)
  		{
  			query.append(clause);
  			if (orderInvStatus.length == 1)
  			{
  				OrderInvStatus stat = orderInvStatus[0];
  				query.append(" o1_1.ordInvCurrentStatus.ordInvStatus = " +  orderInvStatus[0].getId());
  			}
  			else
  			{
  				query.append(" o1_1.ordInvCurrentStatus.ordInvStatus in ( ");
  				String comma = " ";
  				for (int i = 0; i < orderInvStatus.length; i++)
  				{
  					query.append(comma + orderInvStatus[i].getId());
  					comma = ", ";					
  				}
  				query.append(")");
  			}
  			clause = " and";
  		}
  
  		if (serviceRefVo != null)
  		{
  			query.append(clause);
  			String paramName = "SERVICE_ID";
  			query.append(" o1_1.investigation.providerService.locationService.service.id = :" + paramName);
  			paramNames.add(paramName);
  			paramValues.add(serviceRefVo.getID_Service());
  			clause = " and";
  		}
  		
  		//WDEV-2821
  		if(locationRefVo != null && category != null && category.equals(Category.CLINICALIMAGING))
  		{
  			query.append(clause);
  			String paramName = "LOCATION_ID";
  			query.append(" o1_1.requestedLocation.id = :" + paramName);
  			paramNames.add(paramName);
  			paramValues.add(locationRefVo.getID_Location());
  			clause = " and";
  		}
  
  		if (category != null)
  		{
  			query.append(clause);
  			String paramName = "CATEGORY";
  			query.append(" o1_1.investigation.investigationIndex.category = :" + paramName);
  			paramNames.add(paramName);
  			paramValues.add(getDomLookup(category));
  			clause = " and";
  		}
  		
  		// WDEV-11643
  