//#############################################################################
//#                                                                           #
//#  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 Barbara Worwood using IMS Development Environment (version 1.80 build 5007.25751)
// Copyright (C) 1995-2014 IMS MAXIMS. All rights reserved.
// WARNING: DO NOT MODIFY the content of this file

package ims.nursing.vo;

/**
 * Linked to nursing.assessment.Transfers business object (ID: 1015100016).
 */
public class Transfers extends ims.nursing.assessment.vo.TransfersRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public Transfers()
	{
	}
	public Transfers(Integer id, int version)
	{
		super(id, version);
	}
	public Transfers(ims.nursing.vo.beans.TransfersBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.patienttransfers = bean.getPatientTransfers() == null ? null : ims.nursing.vo.lookups.Transfers.buildLookup(bean.getPatientTransfers());
		this.assistancerequired = bean.getAssistanceRequired() == null ? null : ims.nursing.vo.lookups.Ability.buildLookup(bean.getAssistanceRequired());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.nursing.vo.beans.TransfersBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.patienttransfers = bean.getPatientTransfers() == null ? null : ims.nursing.vo.lookups.Transfers.buildLookup(bean.getPatientTransfers());
		this.assistancerequired = bean.getAssistanceRequired() == null ? null : ims.nursing.vo.lookups.Ability.buildLookup(bean.getAssistanceRequired());
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.nursing.vo.beans.TransfersBean bean = null;
		if(map != null)
			bean = (ims.nursing.vo.beans.TransfersBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.nursing.vo.beans.TransfersBean();
			map.addValueObjectBean(this, bean);
			bean.populate(map, this);
		}
		return bean;
	}
	public Object getFieldValueByFieldName(String fieldName)
	{
		if(fieldName == null)
			throw new ims.framework.exceptions.CodingRuntimeException("Invalid field name");
		fieldName = fieldName.toUpperCase();
		if(fieldName.equals("PATIENTTRANSFERS"))
			return getPatientTransfers();
		if(fieldName.equals("ASSISTANCEREQUIRED"))
			return getAssistanceRequired();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getPatientTransfersIsNotNull()
	{
		return this.patienttransfers != null;
	}
	public ims.nursing.vo.lookups.Transfers getPatientTransfers()
	{
		return this.patienttransfers;
	}
	public void setPatientTransfers(ims.nursing.vo.lookups.Transfers value)
	{
		this.isValidated = false;
		this.patienttransfers = value;
	}
	public boolean getAssistanceRequiredIsNotNull()
	{
		return this.assistancerequired != null;
	}
	public ims.nursing.vo.lookups.Ability getAssistanceRequired()
	{
		return this.assistancerequired;
	}
	public void setAssistanceRequired(ims.nursing.vo.lookups.Ability value)
	{
		this.isValidated = false;
		this.assistancerequired = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		this.isBusy = false;
		return true;
	}
	public String[] validate()
	{
		return validate(null);
	}
	public String[] validate(String[] existingErrors)
	{
		if(this.isBusy)
			return null;
		this.isBusy = true;
	
		java.util.ArrayList<String> listOfErrors = new java.util.ArrayList<String>();
		if(existingErrors != null)
		{
			for(int x = 0; x < existingErrors.length; x++)
			{
				listOfErrors.add(existingErrors[x]);
			}
		}
		int errorCount = listOfErrors.size();
		if(errorCount == 0)
		{
			this.isBusy = false;
			this.isValidated = true;
			return null;
		}
		String[] result = new String[errorCount];
		for(int x = 0; x < errorCount; x++)
			result[x] = (String)listOfErrors.get(x);
		this.isBusy = false;
		this.isValidated = false;
		return result;
	}
	public void clearIDAndVersion()
	{
		this.id = null;
		this.version = 0;
	}
	public Object clone()
	{
		if(this.isBusy)
			return this;
		this.isBusy = true;
	
		Transfers clone = new Transfers(this.id, this.version);
		
		if(this.patienttransfers == null)
			clone.patienttransfers = null;
		else
			clone.patienttransfers = (ims.nursing.vo.lookups.Transfers)this.patienttransfers.clone();
		if(this.assistancerequired == null)
			clone.assistancerequired = null;
		else
			clone.assistancerequired = (ims.nursing.vo.lookups.Ability)this.assistancerequired.clone();
		clone.isValidated = this.isValidated;
		
		this.isBusy = false;
		return clone;
	}
	public int compareTo(Object obj)
	{
		return compareTo(obj, true);
	}
	public int compareTo(Object obj, boolean caseInsensitive)
	{
		if (obj == null)
		{
			return -1;
		}
		if(caseInsensitive); // this is to avoid eclipse warning only.
		if (!(Transfers.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A Transfers object cannot be compared an Object of type " + obj.getClass().getName());
		}
		Transfers compareObj = (Transfers)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getID_Transfers() == null && compareObj.getID_Transfers() != null)
				return -1;
			if(this.getID_Transfers() != null && compareObj.getID_Transfers() == null)
				return 1;
			if(this.getID_Transfers() != null && compareObj.getID_Transfers() != null)
				retVal = this.getID_Transfers().compareTo(compareObj.getID_Transfers());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.patienttransfers != null)
			count++;
		if(this.assistancerequired != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 2;
	}
	protected ims.nursing.vo.lookups.Transfers patienttransfers;
	protected ims.nursing.vo.lookups.Ability assistancerequired;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
