/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/Nursing/src/ims/nursing/domain/impl/HandlingMovementImpl.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 Daniel Laffan 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 java.util.List;

import ims.domain.DomainFactory;
import ims.framework.enumerations.SortOrder;
import ims.framework.exceptions.CodingRuntimeException;
import ims.nursing.domain.base.impl.BaseHandlingMovementImpl;
import ims.nursing.domain.objects.PatientHandlingMovement;
import ims.nursing.vo.domain.PatientHandlingMovementVoAssembler;

public class HandlingMovementImpl extends BaseHandlingMovementImpl
{

	private static final long serialVersionUID = 1L;

	/**
	* savePatientHandlingMovement
	*/
	public ims.nursing.vo.PatientHandlingMovementVo savePatientHandlingMovement(ims.nursing.vo.PatientHandlingMovementVo patHandlingMovement) throws ims.domain.exceptions.StaleObjectException
	{
		if(patHandlingMovement == null)
			throw new CodingRuntimeException("patHandlingMovement parameter is null - method savePatientHandlingMovement");
		if(!patHandlingMovement.isValidated())
			throw new CodingRuntimeException("patHandlingMovement has not been validated - method savePatientHandlingMovement");
			
		DomainFactory factory = getDomainFactory();
		PatientHandlingMovement doPatHandlingMovement = PatientHandlingMovementVoAssembler.extractPatientHandlingMovement(factory, patHandlingMovement);
		factory.save(doPatHandlingMovement);
		
		return PatientHandlingMovementVoAssembler.create(doPatHandlingMovement);
	}

	/**
	* listPatientHandlingMovementByCareContext
	*/
	public ims.nursing.vo.PatientHandlingMovementVoCollection listPatientHandlingMovementByCareContext(ims.core.admin.vo.CareContextRefVo careContext)
	{
		DomainFactory factory = getDomainFactory();
		List patHandlingMovements = factory.find("from PatientHandlingMovement patHandMove where patHandMove.careContext.id = :idCareContext", new String[]{"idCareContext"}, new Object[]{careContext.getID_CareContext()});
		if(patHandlingMovements != null && patHandlingMovements.size() > 0)
			return PatientHandlingMovementVoAssembler.createPatientHandlingMovementVoCollectionFromPatientHandlingMovement(patHandlingMovements).sort(SortOrder.DESCENDING);
		
		return null;
	}
}
