//#############################################################################
//#                                                                           #
//#  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.emergency.vo;

/**
 * Linked to emergency.Tracking business object (ID: 1086100005).
 */
public class TrackingForBedAvailabilityVo extends ims.emergency.vo.TrackingRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public TrackingForBedAvailabilityVo()
	{
	}
	public TrackingForBedAvailabilityVo(Integer id, int version)
	{
		super(id, version);
	}
	public TrackingForBedAvailabilityVo(ims.emergency.vo.beans.TrackingForBedAvailabilityVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.currentarea = bean.getCurrentArea() == null ? null : new ims.emergency.configuration.vo.TrackingAreaRefVo(new Integer(bean.getCurrentArea().getId()), bean.getCurrentArea().getVersion());
		this.isdischarged = bean.getIsDischarged();
		this.bedavailability = bean.getBedAvailability() == null ? null : bean.getBedAvailability().buildVo();
		this.patient = bean.getPatient() == null ? null : new ims.core.patient.vo.PatientRefVo(new Integer(bean.getPatient().getId()), bean.getPatient().getVersion());
		this.associatedpendingemergencyadmission = bean.getAssociatedPendingEmergencyAdmission() == null ? null : bean.getAssociatedPendingEmergencyAdmission().buildVo();
		this.currentstatus = bean.getCurrentStatus() == null ? null : bean.getCurrentStatus().buildVo();
		this.attendance = bean.getAttendance() == null ? null : bean.getAttendance().buildVo();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.emergency.vo.beans.TrackingForBedAvailabilityVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.currentarea = bean.getCurrentArea() == null ? null : new ims.emergency.configuration.vo.TrackingAreaRefVo(new Integer(bean.getCurrentArea().getId()), bean.getCurrentArea().getVersion());
		this.isdischarged = bean.getIsDischarged();
		this.bedavailability = bean.getBedAvailability() == null ? null : bean.getBedAvailability().buildVo(map);
		this.patient = bean.getPatient() == null ? null : new ims.core.patient.vo.PatientRefVo(new Integer(bean.getPatient().getId()), bean.getPatient().getVersion());
		this.associatedpendingemergencyadmission = bean.getAssociatedPendingEmergencyAdmission() == null ? null : bean.getAssociatedPendingEmergencyAdmission().buildVo(map);
		this.currentstatus = bean.getCurrentStatus() == null ? null : bean.getCurrentStatus().buildVo(map);
		this.attendance = bean.getAttendance() == null ? null : bean.getAttendance().buildVo(map);
	}
	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.TrackingForBedAvailabilityVoBean bean = null;
		if(map != null)
			bean = (ims.emergency.vo.beans.TrackingForBedAvailabilityVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.emergency.vo.beans.TrackingForBedAvailabilityVoBean();
			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("CURRENTAREA"))
			return getCurrentArea();
		if(fieldName.equals("ISDISCHARGED"))
			return getIsDischarged();
		if(fieldName.equals("BEDAVAILABILITY"))
			return getBedAvailability();
		if(fieldName.equals("PATIENT"))
			return getPatient();
		if(fieldName.equals("ASSOCIATEDPENDINGEMERGENCYADMISSION"))
			return getAssociatedPendingEmergencyAdmission();
		if(fieldName.equals("CURRENTSTATUS"))
			return getCurrentStatus();
		if(fieldName.equals("ATTENDANCE"))
			return getAttendance();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getCurrentAreaIsNotNull()
	{
		return this.currentarea != null;
	}
	public ims.emergency.configuration.vo.TrackingAreaRefVo getCurrentArea()
	{
		return this.currentarea;
	}
	public void setCurrentArea(ims.emergency.configuration.vo.TrackingAreaRefVo value)
	{
		this.isValidated = false;
		this.currentarea = value;
	}
	public boolean getIsDischargedIsNotNull()
	{
		return this.isdischarged != null;
	}
	public Boolean getIsDischarged()
	{
		return this.isdischarged;
	}
	public void setIsDischarged(Boolean value)
	{
		this.isValidated = false;
		this.isdischarged = value;
	}
	public boolean getBedAvailabilityIsNotNull()
	{
		return this.bedavailability != null;
	}
	public ims.emergency.vo.BedAvailabilityVo getBedAvailability()
	{
		return this.bedavailability;
	}
	public void setBedAvailability(ims.emergency.vo.BedAvailabilityVo value)
	{
		this.isValidated = false;
		this.bedavailability = value;
	}
	public boolean getPatientIsNotNull()
	{
		return this.patient != null;
	}
	public ims.core.patient.vo.PatientRefVo getPatient()
	{
		return this.patient;
	}
	public void setPatient(ims.core.patient.vo.PatientRefVo value)
	{
		this.isValidated = false;
		this.patient = value;
	}
	public boolean getAssociatedPendingEmergencyAdmissionIsNotNull()
	{
		return this.associatedpendingemergencyadmission != null;
	}
	public ims.emergency.vo.PendingEmergencyAdmissionShortVo getAssociatedPendingEmergencyAdmission()
	{
		return this.associatedpendingemergencyadmission;
	}
	public void setAssociatedPendingEmergencyAdmission(ims.emergency.vo.PendingEmergencyAdmissionShortVo value)
	{
		this.isValidated = false;
		this.associatedpendingemergencyadmission = value;
	}
	public boolean getCurrentStatusIsNotNull()
	{
		return this.currentstatus != null;
	}
	public ims.emergency.vo.TrackingAttendanceStatusVo getCurrentStatus()
	{
		return this.currentstatus;
	}
	public void setCurrentStatus(ims.emergency.vo.TrackingAttendanceStatusVo value)
	{
		this.isValidated = false;
		this.currentstatus = value;
	}
	public boolean getAttendanceIsNotNull()
	{
		return this.attendance != null;
	}
	public ims.emergency.vo.EmergencyAttendanceForTriageLiteVo getAttendance()
	{
		return this.attendance;
	}
	public void setAttendance(ims.emergency.vo.EmergencyAttendanceForTriageLiteVo value)
	{
		this.isValidated = false;
		this.attendance = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.bedavailability != null)
		{
			if(!this.bedavailability.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.associatedpendingemergencyadmission != null)
		{
			if(!this.associatedpendingemergencyadmission.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.currentstatus != null)
		{
			if(!this.currentstatus.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.attendance != null)
		{
			if(!this.attendance.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.bedavailability != null)
		{
			String[] listOfOtherErrors = this.bedavailability.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.patient == null)
			listOfErrors.add("Patient is mandatory");
		if(this.associatedpendingemergencyadmission != null)
		{
			String[] listOfOtherErrors = this.associatedpendingemergencyadmission.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.currentstatus != null)
		{
			String[] listOfOtherErrors = this.currentstatus.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.attendance == null)
			listOfErrors.add("Attendance is mandatory");
		if(this.attendance != null)
		{
			String[] listOfOtherErrors = this.attendance.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[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;
	
		TrackingForBedAvailabilityVo clone = new TrackingForBedAvailabilityVo(this.id, this.version);
		
		clone.currentarea = this.currentarea;
		clone.isdischarged = this.isdischarged;
		if(this.bedavailability == null)
			clone.bedavailability = null;
		else
			clone.bedavailability = (ims.emergency.vo.BedAvailabilityVo)this.bedavailability.clone();
		clone.patient = this.patient;
		if(this.associatedpendingemergencyadmission == null)
			clone.associatedpendingemergencyadmission = null;
		else
			clone.associatedpendingemergencyadmission = (ims.emergency.vo.PendingEmergencyAdmissionShortVo)this.associatedpendingemergencyadmission.clone();
		if(this.currentstatus == null)
			clone.currentstatus = null;
		else
			clone.currentstatus = (ims.emergency.vo.TrackingAttendanceStatusVo)this.currentstatus.clone();
		if(this.attendance == null)
			clone.attendance = null;
		else
			clone.attendance = (ims.emergency.vo.EmergencyAttendanceForTriageLiteVo)this.attendance.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 (!(TrackingForBedAvailabilityVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A TrackingForBedAvailabilityVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((TrackingForBedAvailabilityVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((TrackingForBedAvailabilityVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.currentarea != null)
			count++;
		if(this.isdischarged != null)
			count++;
		if(this.bedavailability != null)
			count++;
		if(this.patient != null)
			count++;
		if(this.associatedpendingemergencyadmission != null)
			count++;
		if(this.currentstatus != null)
			count++;
		if(this.attendance != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 7;
	}
	protected ims.emergency.configuration.vo.TrackingAreaRefVo currentarea;
	protected Boolean isdischarged;
	protected ims.emergency.vo.BedAvailabilityVo bedavailability;
	protected ims.core.patient.vo.PatientRefVo patient;
	protected ims.emergency.vo.PendingEmergencyAdmissionShortVo associatedpendingemergencyadmission;
	protected ims.emergency.vo.TrackingAttendanceStatusVo currentstatus;
	protected ims.emergency.vo.EmergencyAttendanceForTriageLiteVo attendance;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
