//#############################################################################
//#                                                                           #
//#  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 Daniel Laffan using IMS Development Environment (version 1.22 build 50211.900)
// Copyright (C) 1995-2005 IMS MAXIMS plc. All rights reserved.
// 23/03/2005 - AU - Null pointer exception fixed 
package ims.spinalinjuries.domain.impl;

import java.util.ArrayList;
import ims.admin.domain.HcpAdmin;
import ims.admin.domain.impl.HcpAdminImpl;
import ims.core.vo.CareContextShortVo;
import ims.core.vo.PatientCurrentConcernVo;
import ims.core.vo.domain.PatientCurrentConcernVoAssembler;
import ims.domain.exceptions.StaleObjectException;
import ims.domain.DomainFactory;
import ims.domain.exceptions.DomainRuntimeException;
import ims.domain.impl.DomainImpl;
import ims.generalmedical.vo.MedicalProbOnAdmisVoCollection;
import ims.generalmedical.vo.domain.MedicalProbOnAdmisVoAssembler;
import ims.spinalinjuries.domain.MedConcernOnAdmis;
import ims.core.clinical.domain.objects.PatientConcern;
import ims.core.clinical.vo.PatientConcernRefVo;

public class SharedNewConcernImpl extends DomainImpl implements ims.spinalinjuries.domain.SharedNewConcern, ims.domain.impl.Transactional
{
	public ims.core.vo.PatientCurrentConcernVo saveConcern(ims.core.vo.PatientCurrentConcernVo concern, ims.core.vo.PatientShort patient) throws StaleObjectException
	{
		if(!concern.isValidated())
		{
			throw new DomainRuntimeException("PatientCurrentConcern Value Object Alert has not been validated");
		}
		
		DomainFactory factory = getDomainFactory();
		
		PatientConcern doConcern = PatientCurrentConcernVoAssembler.extractPatientConcern(factory,concern);

		factory.save(doConcern);
	
		return PatientCurrentConcernVoAssembler.create(doConcern);
	}

	public ims.core.vo.HcpCollection listHcps(ims.core.vo.HcpFilter filter)
	{
		HcpAdmin impl = (HcpAdmin) getDomainImpl(HcpAdminImpl.class);
		return impl.listHCPs(filter);
	}

	public MedicalProbOnAdmisVoCollection listProbsOnAdmission(CareContextShortVo voClinicalContactShort)
	{
		DomainFactory factory = getDomainFactory();
			
		String hql = " from PatientProblem medicalProbOnAdmis "; 
		StringBuffer condStr = new StringBuffer();
		String andStr = " ";
	
		ArrayList markers = new ArrayList();
		ArrayList values = new ArrayList();
	
		if(voClinicalContactShort != null)
		{
			condStr.append(andStr + " medicalProbOnAdmis.careContext.id = :id_CareContext"); 
			markers.add("id_CareContext");
			values.add(voClinicalContactShort.getID_CareContext());
			andStr = " and ";
		}	
		
		if (andStr.equals(" and "))
			hql += " where ";
	
		hql += condStr.toString();
		return MedicalProbOnAdmisVoAssembler.createMedicalProbOnAdmisVoCollectionFromPatientProblem(factory.find(hql, markers, values));
	}

	public PatientCurrentConcernVo getConcern(PatientConcernRefVo concernId) {
		MedConcernOnAdmis impl = (MedConcernOnAdmis) getDomainImpl(MedConcernOnAdmisImpl.class);
		return impl.getConcern(concernId);
	}

}
