/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/ValueObjects/src/ims/emergency/vo/RTAVo.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 Barbara Worwood using IMS Development Environment (version 1.80 build 5589.25814)
// Copyright (C) 1995-2015 IMS MAXIMS. All rights reserved.
// WARNING: DO NOT MODIFY the content of this file

package ims.emergency.vo;

/**
 * Linked to core.admin.RTA business object (ID: 1086100000).
 */
public class RTAVo extends ims.core.admin.vo.RTARefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public RTAVo()
	{
	}
	public RTAVo(Integer id, int version)
	{
		super(id, version);
	}
	public RTAVo(ims.emergency.vo.beans.RTAVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.rtatype = bean.getRTAType() == null ? null : ims.emergency.vo.lookups.RTAPatientType.buildLookup(bean.getRTAType());
		this.protectiondevice = bean.getProtectionDevice() == null ? null : ims.emergency.vo.lookups.ProtectionDevice.buildLookup(bean.getProtectionDevice());
		this.isdriverowner = bean.getIsDriverOwner();
		this.drivername = bean.getDriverName() == null ? null : bean.getDriverName().buildVo();
		this.driveraddress = bean.getDriverAddress() == null ? null : bean.getDriverAddress().buildVo();
		this.notes = bean.getNotes();
		this.policeinvolved = bean.getPoliceInvolved();
		this.policeid = bean.getPoliceID();
		this.policestation = bean.getPoliceStation() == null ? null : ims.emergency.vo.lookups.PoliceStation.buildLookup(bean.getPoliceStation());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.emergency.vo.beans.RTAVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.rtatype = bean.getRTAType() == null ? null : ims.emergency.vo.lookups.RTAPatientType.buildLookup(bean.getRTAType());
		this.protectiondevice = bean.getProtectionDevice() == null ? null : ims.emergency.vo.lookups.ProtectionDevice.buildLookup(bean.getProtectionDevice());
		this.isdriverowner = bean.getIsDriverOwner();
		this.drivername = bean.getDriverName() == null ? null : bean.getDriverName().buildVo(map);
		this.driveraddress = bean.getDriverAddress() == null ? null : bean.getDriverAddress().buildVo(map);
		this.notes = bean.getNotes();
		this.policeinvolved = bean.getPoliceInvolved();
		this.policeid = bean.getPoliceID();
		this.policestation = bean.getPoliceStation() == null ? null : ims.emergency.vo.lookups.PoliceStation.buildLookup(bean.getPoliceStation());
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.emergency.vo.beans.RTAVoBean bean = null;
		if(map != null)
			bean = (ims.emergency.vo.beans.RTAVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.emergency.vo.beans.RTAVoBean();
			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("RTATYPE"))
			return getRTAType();
		if(fieldName.equals("PROTECTIONDEVICE"))
			return getProtectionDevice();
		if(fieldName.equals("ISDRIVEROWNER"))
			return getIsDriverOwner();
		if(fieldName.equals("DRIVERNAME"))
			return getDriverName();
		if(fieldName.equals("DRIVERADDRESS"))
			return getDriverAddress();
		if(fieldName.equals("NOTES"))
			return getNotes();
		if(fieldName.equals("POLICEINVOLVED"))
			return getPoliceInvolved();
		if(fieldName.equals("POLICEID"))
			return getPoliceID();
		if(fieldName.equals("POLICESTATION"))
			return getPoliceStation();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getRTATypeIsNotNull()
	{
		return this.rtatype != null;
	}
	public ims.emergency.vo.lookups.RTAPatientType getRTAType()
	{
		return this.rtatype;
	}
	public void setRTAType(ims.emergency.vo.lookups.RTAPatientType value)
	{
		this.isValidated = false;
		this.rtatype = value;
	}
	public boolean getProtectionDeviceIsNotNull()
	{
		return this.protectiondevice != null;
	}
	public ims.emergency.vo.lookups.ProtectionDevice getProtectionDevice()
	{
		return this.protectiondevice;
	}
	public void setProtectionDevice(ims.emergency.vo.lookups.ProtectionDevice value)
	{
		this.isValidated = false;
		this.protectiondevice = value;
	}
	public boolean getIsDriverOwnerIsNotNull()
	{
		return this.isdriverowner != null;
	}
	public Boolean getIsDriverOwner()
	{
		return this.isdriverowner;
	}
	public void setIsDriverOwner(Boolean value)
	{
		this.isValidated = false;
		this.isdriverowner = value;
	}
	public boolean getDriverNameIsNotNull()
	{
		return this.drivername != null;
	}
	public ims.core.vo.PersonName getDriverName()
	{
		return this.drivername;
	}
	public void setDriverName(ims.core.vo.PersonName value)
	{
		this.isValidated = false;
		this.drivername = value;
	}
	public boolean getDriverAddressIsNotNull()
	{
		return this.driveraddress != null;
	}
	public ims.core.vo.PersonAddress getDriverAddress()
	{
		return this.driveraddress;
	}
	public void setDriverAddress(ims.core.vo.PersonAddress value)
	{
		this.isValidated = false;
		this.driveraddress = value;
	}
	public boolean getNotesIsNotNull()
	{
		return this.notes != null;
	}
	public String getNotes()
	{
		return this.notes;
	}
	public static int getNotesMaxLength()
	{
		return 255;
	}
	public void setNotes(String value)
	{
		this.isValidated = false;
		this.notes = value;
	}
	public boolean getPoliceInvolvedIsNotNull()
	{
		return this.policeinvolved != null;
	}
	public Boolean getPoliceInvolved()
	{
		return this.policeinvolved;
	}
	public void setPoliceInvolved(Boolean value)
	{
		this.isValidated = false;
		this.policeinvolved = value;
	}
	public boolean getPoliceIDIsNotNull()
	{
		return this.policeid != null;
	}
	public String getPoliceID()
	{
		return this.policeid;
	}
	public static int getPoliceIDMaxLength()
	{
		return 40;
	}
	public void setPoliceID(String value)
	{
		this.isValidated = false;
		this.policeid = value;
	}
	public boolean getPoliceStationIsNotNull()
	{
		return this.policestation != null;
	}
	public ims.emergency.vo.lookups.PoliceStation getPoliceStation()
	{
		return this.policestation;
	}
	public void setPoliceStation(ims.emergency.vo.lookups.PoliceStation value)
	{
		this.isValidated = false;
		this.policestation = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.drivername != null)
		{
			if(!this.drivername.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.driveraddress != null)
		{
			if(!this.driveraddress.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]);
			}
		}
		if(this.rtatype == null)
			listOfErrors.add("RTAType is mandatory");
		if(this.isdriverowner == null)
			listOfErrors.add("isDriverOwner is mandatory");
		if(this.drivername != null)
		{
			String[] listOfOtherErrors = this.drivername.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.driveraddress != null)
		{
			String[] listOfOtherErrors = this.driveraddress.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.notes != null)
			if(this.notes.length() > 255)
				listOfErrors.add("The length of the field [notes] in the value object [ims.emergency.vo.RTAVo] is too big. It should be less or equal to 255");
		if(this.policeid != null)
			if(this.policeid.length() > 40)
				listOfErrors.add("The length of the field [policeid] in the value object [ims.emergency.vo.RTAVo] is too big. It should be less or equal to 40");
		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;
	
		RTAVo clone = new RTAVo(this.id, this.version);
		
		if(this.rtatype == null)
			clone.rtatype = null;
		else
			clone.rtatype = (ims.emergency.vo.lookups.RTAPatientType)this.rtatype.clone();
		if(this.protectiondevice == null)
			clone.protectiondevice = null;
		else
			clone.protectiondevice = (ims.emergency.vo.lookups.ProtectionDevice)this.protectiondevice.clone();
		clone.isdriverowner = this.isdriverowner;
		if(this.drivername == null)
			clone.drivername = null;
		else
			clone.drivername = (ims.core.vo.PersonName)this.drivername.clone();
		if(this.driveraddress == null)
			clone.driveraddress = null;
		else
			clone.driveraddress = (ims.core.vo.PersonAddress)this.driveraddress.clone();
		clone.notes = this.notes;
		clone.policeinvolved = this.policeinvolved;
		clone.policeid = this.policeid;
		if(this.policestation == null)
			clone.policestation = null;
		else
			clone.policestation = (ims.emergency.vo.lookups.PoliceStation)this.policestation.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 (!(RTAVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A RTAVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((RTAVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((RTAVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.rtatype != null)
			count++;
		if(this.protectiondevice != null)
			count++;
		if(this.isdriverowner != null)
			count++;
		if(this.drivername != null)
			count++;
		if(this.driveraddress != null)
			count++;
		if(this.notes != null)
			count++;
		if(this.policeinvolved != null)
			count++;
		if(this.policeid != null)
			count++;
		if(this.policestation != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 9;
	}
	protected ims.emergency.vo.lookups.RTAPatientType rtatype;
	protected ims.emergency.vo.lookups.ProtectionDevice protectiondevice;
	protected Boolean isdriverowner;
	protected ims.core.vo.PersonName drivername;
	protected ims.core.vo.PersonAddress driveraddress;
	protected String notes;
	protected Boolean policeinvolved;
	protected String policeid;
	protected ims.emergency.vo.lookups.PoliceStation policestation;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
