/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/Nursing/src/ims/nursing/domain/impl/PainReviewImpl.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.20 build 40813.1400)
// Copyright (C) 1995-2004 IMS MAXIMS plc. All rights reserved.

package ims.nursing.domain.impl;

import java.util.List;
import ims.admin.domain.DrawingConfiguration;
import ims.admin.domain.impl.DrawingConfigurationImpl;
import ims.core.admin.domain.objects.CareContext;
import ims.core.admin.vo.CareContextRefVo;
import ims.core.vo.CareContextShortVoCollection;
import ims.core.vo.DrawingImageVo;
import ims.core.vo.domain.CareContextShortVoAssembler;
import ims.nursing.domain.PainBodyChart;
import ims.nursing.domain.impl.PainBodyChartImpl;
import ims.domain.DomainFactory;
import ims.domain.exceptions.DomainInterfaceException;
import ims.domain.exceptions.StaleObjectException;
import ims.domain.exceptions.UniqueKeyViolationException;
import ims.domain.impl.DomainImpl;
import ims.nursing.vo.PainAssessmentCollection;

public class PainReviewImpl extends DomainImpl implements ims.nursing.domain.PainReview, ims.domain.impl.Transactional
{
	public DrawingImageVo getDrawingImage(DrawingImageVo drawingImage) 
	{
		DrawingConfiguration drawingConfigImpl = (DrawingConfiguration)getDomainImpl(DrawingConfigurationImpl.class);
		return drawingConfigImpl.getDrawingImage(drawingImage);
	}
	/**
	 * list Pain
	 */
	public PainAssessmentCollection listPain(CareContextRefVo voCurrentCareContext)
	{
		PainBodyChart body = (PainBodyChart)getDomainImpl(PainBodyChartImpl.class);
		return body.listPain(voCurrentCareContext);
	}
	/**
	 * save Pain
	 * @throws UniqueKeyViolationException 
	 * @throws DomainInterfaceException 
	 */	
	public void savePain(ims.nursing.vo.PainAssessment painAssmt) throws StaleObjectException, UniqueKeyViolationException, DomainInterfaceException
	{
		PainBodyChart body = (PainBodyChart)getDomainImpl(PainBodyChartImpl.class);
		body.saveRecord(painAssmt, null, null);	
	}
	public CareContextShortVoCollection listPainReviewCareContexts(Integer idPatient)
	{
		if (idPatient != null)
		{
			DomainFactory factory = getDomainFactory();
			List PAaList  = factory.find(" select distinct pa.careContext from PainAssessment pa where pa.careContext.episodeOfCare.careSpell.patient.id = :patId",
					new String[]{"patId"},
					new Object[]{idPatient});
	
			CareContextShortVoCollection voCareContextList = new CareContextShortVoCollection();
			for (int x = 0; x < PAaList.size(); x++)
			{
				CareContext domPAa = (CareContext) PAaList.get(x);
				voCareContextList.add(CareContextShortVoAssembler.create(domPAa));	
			}
	
			return voCareContextList.sort();
		}
		
		return null;
	}
}
