gt: 		return (Boolean) list.get(0);
context: //#############################################################################
  //#                                                                           #
  //#  Copyright (C) <2015>  <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/>.    #
  //#                                                                           #
  //#  IMS MAXIMS provides absolutely NO GUARANTEE OF THE CLINICAL SAFTEY of    #
  //#  this program.  Users of this software do so entirely at their own risk.  #
  //#  IMS MAXIMS only ensures the Clinical Safety of unaltered run-time        #
  //#  software that it builds, deploys and maintains.                          #
  //#                                                                           #
  //#############################################################################
  //#EOH
  // This code was generated by Cristian Belciug using IMS Development Environment (version 1.71 build 3853.21665)
  // Copyright (C) 1995-2010 IMS MAXIMS. All rights reserved.
  
  package ims.core.domain.impl;
  
  import ims.admin.vo.DocumentCategoryToFormCfgVo;
  import ims.admin.vo.ReportTemplateVo;
  import ims.admin.vo.domain.ReportTemplateVoAssembler;
  import ims.clinical.vo.PatientSummaryNoteByHcpShortVoCollection;
  import ims.clinical.vo.domain.PatientSummaryNoteByHcpShortVoAssembler;
  import ims.core.admin.domain.objects.TemplateBo;
  import ims.core.admin.vo.CareContextRefVo;
  import ims.core.admin.vo.EpisodeOfCareRefVo;
  import ims.core.admin.vo.TemplateBoRefVo;
  import ims.core.documents.domain.objects.PatientDocument;
  import ims.core.documents.vo.PatientDocumentRefVo;
  import ims.core.domain.DocumentWorklist;
  import ims.core.domain.base.impl.BasePatientCorrespondenceTemplatesImpl;
  import ims.core.patient.vo.PatientRefVo;
  import ims.core.vo.CareContextForPatientDocumentVoCollection;
  import ims.core.vo.ClinicalContactShortVoCollection;
  import ims.core.vo.DocumentCategoryConfigShortVoCollection;
  import ims.core.vo.EpisodeofCareShortVoCollection;
  import ims.core.vo.PatientDocumentVo;
  import ims.core.vo.domain.CareContextForPatientDocumentVoAssembler;
  import ims.core.vo.domain.ClinicalContactShortVoAssembler;
  import ims.core.vo.domain.DocumentCategoryConfigShortVoAssembler;
  import ims.core.vo.domain.EpisodeofCareShortVoAssembler;
  import ims.core.vo.domain.PatientDocumentVoAssembler;
  import ims.core.vo.lookups.DocumentCategory;
  import ims.core.vo.lookups.Specialty;
  import ims.domain.DomainFactory;
  import ims.domain.DomainObject;
  import ims.domain.exceptions.DomainRuntimeException;
  import ims.domain.exceptions.ForeignKeyViolationException;
  import ims.domain.exceptions.StaleObjectException;
  import ims.framework.exceptions.CodingRuntimeException;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class PatientCorrespondenceTemplatesImpl extends BasePatientCorrespondenceTemplatesImpl
  {
  
  	private static final long serialVersionUID = 1L;
  
  	public PatientDocumentVo savePatientDocument(PatientDocumentVo document) throws StaleObjectException 
  	{
  		if(document == null)
  			throw new CodingRuntimeException("Can not save a null PatientDocumentVo.");
  		
  		if(!document.isValidated())
  			throw new CodingRuntimeException("PatientDocumentVo not validated");
  		
  		DomainFactory factory = getDomainFactory();
  		PatientDocument doc = PatientDocumentVoAssembler.extractPatientDocument(factory, document);
  		factory.save(doc);	
  		
  		return PatientDocumentVoAssembler.create(doc);
  	}
  
  	public ReportTemplateVo getTemplate(TemplateBoRefVo templateBoRefVo) 
  	{
  		if (templateBoRefVo == null)
  			throw new CodingRuntimeException("Cannot get ReportTemplateVo for null TemplateBoRefVo");
  
  		DomainFactory factory = getDomainFactory();
  
  		TemplateBo boTemplate = (TemplateBo) factory.getDomainObject(TemplateBo.class, templateBoRefVo.getID_TemplateBo());
  		return ReportTemplateVoAssembler.create(boTemplate);
  	}
  		
  	public EpisodeofCareShortVoCollection listEpisodesOfCare(PatientRefVo patientId) 
  	{
  		if (patientId == null || !patientId.getID_PatientIsNotNull())
  		{
  			throw new CodingRuntimeException("Supplied patient is null or doesn't have an id.");
  		}
  		
  		String hql = "select e1_1 from EpisodeOfCare as e1_1 left join e1_1.careSpell as c1_1 left join c1_1.patient as p1_1 where (p1_1.id = :Patient_id) order by e1_1.startDate desc ";//WDEV-12385
  		
  		List<?> list = getDomainFactory().find(hql, "Patient_id", patientId.getID_Patient());
  		if (list == null || list.size() == 0)
  			return null;
  		
  		return EpisodeofCareShortVoAssembler.createEpisodeofCareShortVoCollectionFromEpisodeOfCare(list);
  	}
  
  	public CareContextForPatientDocumentVoCollection listCareContext(EpisodeOfCareRefVo episodeOfCare) 
  	{
  		if(episodeOfCare == null || !episodeOfCare.getID_EpisodeOfCareIsNotNull())
  		{
  			throw new CodingRuntimeException("Supplied Episode Of Care is null or doesn't have an id.");
  		}
  		
  		String hql = "from CareContext as cc where cc.episodeOfCare.id = :ep order by cc.startDateTime desc";//WDEV-12385
  		
  		List<?> list = getDomainFactory().find(hql, "ep", episodeOfCare.getID_EpisodeOfCare());
  		
  		if (list == null || list.size() == 0)
  			return null;
  		
  		return CareContextForPatientDocumentVoAssembler.createCareContextForPatientDocumentVoCollectionFromCareContext(list);
  	}
  
  	public ClinicalContactShortVoCollection listClinicalContact(CareContextRefVo careContext) 
  	{
  		if(careContext == null || !careContext.getID_CareContextIsNotNull())
  		{
  			throw new CodingRuntimeException("Supplied Care Context is null or doesn't have an id.");
  		}
  		
  		String hql = "from ClinicalContact as c where c.careContext.id = :cc order by c.startDateTime desc ";//WDEV-12385
  		
  		List<?> list = getDomainFactory().find(hql, "cc", careContext.getID_CareContext());
  		
  		if (list == null || list.size() == 0)
  			return null;
  		
  		return ClinicalContactShortVoAssembler.createClinicalContactShortVoCollectionFromClinicalContact(list);
  	}
  
  	public DocumentCategoryConfigShortVoCollection searchReports(String templateName, String listOfMandatorySeeds, DocumentCategory documentType, Specialty specialty) 
  	{
  		DomainFactory factory = getDomainFactory();
  		ArrayList<String> markers = new ArrayList<String>();
  		ArrayList<Object> values = new ArrayList<Object>();
  		
  		String subHql = "";
  		
  		if(listOfMandatorySeeds != null && listOfMandatorySeeds.length() > 0)
  		{
  			subHql = " and r21.bOName not in (" + listOfMandatorySeeds + ")";
  		}
  			
  		String mainHql = "select d from DocumentCategoryConfig as d left join d.template as t left join t.report as r";
  		String whereHql = " where t.id not in (select t11.id from TemplateBo as t11 left join t11.report as r11 left join r11.seeds as r21 where (r21.canBeNull = 0" + subHql + ")) and r.reportXml is not null and t.templateXml is not null and r.isActive = 1 and t.isActive = 1";//	WDEV-13519
  		
  		if(templateName != null && templateName.length() > 0)
  		{
  			whereHql += " and upper(t.name) like :templateName";
  			markers.add("templateName");
  			values.add(templateName.toUpperCase() + "%");
  		}
  		
  		if(documentType != null)
  		{
  			whereHql += " and d.category.id = :catId";
  			markers.add("catId");
  			values.add(documentType.getID());
  		}
  		
  		if(specialty != null)
  		{
  			mainHql += " left join d.specialty as s left join s.instance as i";
  			whereHql += " and i.id = :specialtyId";
  			markers.add("specialtyId");
  			values.add(specialty.getID());
  		}
  		
  		String hql = mainHql + whereHql + " order by upper(r.reportName) asc, upper(t.name) asc";//	WDEV-13519
  		List<?> list = factory.find(hql, markers, values);
  		
  		return DocumentCategoryConfigShortVoAssembler.createDocumentCategoryConfigShortVoCollectionFromDocumentCategoryConfig(list);//	WDEV-13519
  	}
  
  	public void deleteDocument(PatientDocumentRefVo patRef)
  	{
  		if (patRef == null || !patRef.getID_PatientDocumentIsNotNull())
  		{
  			throw new DomainRuntimeException("Invalid patient document provided in delete");
  		}
  		DomainObject dom = getDomainFactory().getDomainObject(PatientDocument.class, patRef.getID_PatientDocument());
  		try
  		{
  			getDomainFactory().delete(dom);
  		}
  		catch (ForeignKeyViolationException e)
  		{
  			//How to handle this ????
  			e.printStackTrace();
  		}	
  	}
  
  	//wdev-14230
  	public PatientSummaryNoteByHcpShortVoCollection listSummaryNotes(PatientRefVo listSummaryNotes) 
  	{
  		if (listSummaryNotes == null || !listSummaryNotes.getID_PatientIsNotNull())
  			throw new DomainRuntimeException("Can not search after null patient");
  
  		String query = " from PatientSummaryNoteByHCP as sumNote where sumNote.patient.id = :ID order by sumNote.authoringInformation.authoringDateTime desc";
  
  		ArrayList<String> paramNames = new ArrayList<String>();
  		ArrayList<Object> paramValues = new ArrayList<Object>();
  
  		paramNames.add("ID");
  		paramValues.add(listSummaryNotes.getID_Patient());
  
  		return PatientSummaryNoteByHcpShortVoAssembler.createPatientSummaryNoteByHcpShortVoCollectionFromPatientSummaryNoteByHCP(getDomainFactory().find(query, paramNames, paramValues));
  	}
  
  	public Boolean getCopyLetter(PatientRefVo patientId) 
  	{
  		if (patientId == null || !patientId.getID_PatientIsNotNull())
  		{
  			throw new CodingRuntimeException("Supplied patient is null or doesn't have an id.");
  		}
  		
  		String hql = "select p.copyPatientOnCorrespondence from Patient as p where p.id = :PID";
  		
  		List<?> list = getDomainFactory().find(hql, "PID", patientId.getID_Patient());
  		if (list == null || list.size() == 0)
  			return null;
  		
  