/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/Nursing/src/ims/nursing/domain/impl/PatientSECSImpl.java
//#############################################################################
//#                                                                           #
//#  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 Alexie Ursache using IMS Development Environment (version 1.53 build 2510.31460)
// Copyright (C) 1995-2006 IMS MAXIMS plc. All rights reserved.

package ims.nursing.domain.impl;

import ims.clinical.vo.domain.PatientSECSShortVoAssembler;
import ims.core.patient.vo.PatientRefVo;
import ims.domain.DomainFactory;
import ims.domain.exceptions.DomainRuntimeException;
import ims.framework.exceptions.CodingRuntimeException;
import ims.nursing.domain.base.impl.BasePatientSECSImpl;

import java.util.ArrayList;
import java.util.List;

public class PatientSECSImpl extends BasePatientSECSImpl
{

	private static final long serialVersionUID = 1L;

	/**
	* list the PatientSECSShortVoCollection
	*/
	public ims.clinical.vo.PatientSECSShortVoCollection listPatientSECS(ims.framework.utils.DateTime startDate, ims.framework.utils.DateTime endDate,PatientRefVo patRef)
	{
		if(startDate == null || endDate == null)
			throw new CodingRuntimeException("Please provide both From Date and To Date");
		if (!patRef.getID_PatientIsNotNull())
			throw new DomainRuntimeException("Please provide a patient with and id");
		
		StringBuffer hql = new StringBuffer();
		hql.append(" select patS from PatientSECS as patS ");
		hql.append(" where");
		hql.append(" (( patS.authoringInformation.authoringDateTime is null ");
		hql.append(" or");
		hql.append(" (patS.authoringInformation.authoringDateTime >= :startDate");
		hql.append(" and"); 
		hql.append(" patS.authoringInformation.authoringDateTime <= :endDate)) ");
		hql.append(" and patS.careContext.episodeOfCare.careSpell.patient.id = :patID");
		hql.append(" and patS.isRIE is null) order by patS.authoringInformation.authoringDateTime desc" );
		
		ArrayList paramValues = new ArrayList();
		ArrayList paramNames  = new ArrayList();
		
		paramValues.add(startDate.getJavaDate());
		paramValues.add(endDate.getJavaDate());
		paramValues.add(patRef.getID_Patient());
		
		paramNames.add("startDate");
		paramNames.add("endDate");
		paramNames.add("patID");
		
		DomainFactory factory = getDomainFactory();
		List list = factory.find(hql.toString(), paramNames, paramValues);
		
		return PatientSECSShortVoAssembler.createPatientSECSShortVoCollectionFromPatientSECS(list);
	}

}
