/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/RACPC/src/ims/racpc/domain/impl/RACPCReferralImpl.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 Andrei Stefan Bondar using IMS Development Environment (version 1.80 build 4035.27320)
// Copyright (C) 1995-2011 IMS MAXIMS. All rights reserved.

package ims.racpc.domain.impl;

import ims.core.admin.domain.objects.CareContext;
import ims.core.admin.vo.CareContextRefVo;
import ims.core.clinical.domain.objects.RACPReferral;
import ims.domain.DomainFactory;
import ims.domain.exceptions.DomainRuntimeException;
import ims.framework.exceptions.CodingRuntimeException;
import ims.racpc.domain.RACPCSummary;
import ims.racpc.domain.base.impl.BaseRACPCReferralImpl;
import ims.racpc.vo.CareContextForRACPCReferralVo;
import ims.racpc.vo.domain.CareContextForRACPCReferralVoAssembler;
import ims.racpc.vo.domain.RACPCReferralVoAssembler;
public class RACPCReferralImpl extends BaseRACPCReferralImpl
{

	private static final long serialVersionUID = 1L;

	public ims.racpc.vo.RACPCReferralVo getRACPCReferral(ims.core.admin.vo.CareContextRefVo careContext)
	{
		if(careContext == null || !careContext.getID_CareContextIsNotNull())
			throw new CodingRuntimeException("Invalid Care Context Context Ref");
		
		DomainFactory factory = getDomainFactory();		
		StringBuffer hql = new StringBuffer("select r1_1 from RACPReferral as r1_1 left join r1_1.careContext as c1_1");
		hql.append(" where (c1_1.id = " + careContext.getID_CareContext() + " and r1_1.isRIE is null )");
		
		return RACPCReferralVoAssembler.create((RACPReferral)factory.findFirst(hql.toString()));
	}

	public ims.racpc.vo.RACPCReferralVo saveRACPCReferral(ims.racpc.vo.RACPCReferralVo racpcReferral) throws ims.domain.exceptions.DomainInterfaceException, ims.domain.exceptions.StaleObjectException, ims.domain.exceptions.UniqueKeyViolationException
	{
		if(!racpcReferral.isValidated())
			throw new DomainRuntimeException("This RACPReferral has not been validated");
		
		DomainFactory factory = getDomainFactory();
		RACPReferral doRACPCReferral = RACPCReferralVoAssembler.extractRACPReferral(factory, racpcReferral);
		factory.save(doRACPCReferral);
		return RACPCReferralVoAssembler.create(doRACPCReferral);
	}

	public CareContextForRACPCReferralVo getCareContext(CareContextRefVo careContext) 
	{
		if(careContext == null || !careContext.getID_CareContextIsNotNull())
			throw new CodingRuntimeException("Invalid Care Context Context Ref");
	
		return CareContextForRACPCReferralVoAssembler.create((CareContext) getDomainFactory().getDomainObject(CareContext.class, careContext.getID_CareContext()));
	}

	//WDEV-13437
	public Boolean isRACPCSummaryComplete(CareContextRefVo careContext) 
	{
		RACPCSummary impl = (RACPCSummary)getDomainImpl(RACPCSummaryImpl.class);
		return impl.isRACPCSummaryComplete(careContext);
	}
}
