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

/**
 * Linked to Scheduling.Appointment_Status business object (ID: 1055100008).
 */
public class Appointment_StatusForAppointmentOutcomeVo extends ims.scheduling.vo.Appointment_StatusRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public Appointment_StatusForAppointmentOutcomeVo()
	{
	}
	public Appointment_StatusForAppointmentOutcomeVo(Integer id, int version)
	{
		super(id, version);
	}
	public Appointment_StatusForAppointmentOutcomeVo(ims.scheduling.vo.beans.Appointment_StatusForAppointmentOutcomeVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.status = bean.getStatus() == null ? null : ims.scheduling.vo.lookups.Status_Reason.buildLookup(bean.getStatus());
		this.statusreason = bean.getStatusReason() == null ? null : ims.scheduling.vo.lookups.Status_Reason.buildLookup(bean.getStatusReason());
		this.statuschangedatetime = bean.getStatusChangeDateTime() == null ? null : bean.getStatusChangeDateTime().buildDateTime();
		this.apptdate = bean.getApptDate() == null ? null : bean.getApptDate().buildDate();
		this.appttime = bean.getApptTime() == null ? null : bean.getApptTime().buildTime();
		this.session = bean.getSession() == null ? null : new ims.scheduling.vo.Sch_SessionRefVo(new Integer(bean.getSession().getId()), bean.getSession().getVersion());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.scheduling.vo.beans.Appointment_StatusForAppointmentOutcomeVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.status = bean.getStatus() == null ? null : ims.scheduling.vo.lookups.Status_Reason.buildLookup(bean.getStatus());
		this.statusreason = bean.getStatusReason() == null ? null : ims.scheduling.vo.lookups.Status_Reason.buildLookup(bean.getStatusReason());
		this.statuschangedatetime = bean.getStatusChangeDateTime() == null ? null : bean.getStatusChangeDateTime().buildDateTime();
		this.apptdate = bean.getApptDate() == null ? null : bean.getApptDate().buildDate();
		this.appttime = bean.getApptTime() == null ? null : bean.getApptTime().buildTime();
		this.session = bean.getSession() == null ? null : new ims.scheduling.vo.Sch_SessionRefVo(new Integer(bean.getSession().getId()), bean.getSession().getVersion());
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.scheduling.vo.beans.Appointment_StatusForAppointmentOutcomeVoBean bean = null;
		if(map != null)
			bean = (ims.scheduling.vo.beans.Appointment_StatusForAppointmentOutcomeVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.scheduling.vo.beans.Appointment_StatusForAppointmentOutcomeVoBean();
			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("STATUS"))
			return getStatus();
		if(fieldName.equals("STATUSREASON"))
			return getStatusReason();
		if(fieldName.equals("STATUSCHANGEDATETIME"))
			return getStatusChangeDateTime();
		if(fieldName.equals("APPTDATE"))
			return getApptDate();
		if(fieldName.equals("APPTTIME"))
			return getApptTime();
		if(fieldName.equals("SESSION"))
			return getSession();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getStatusIsNotNull()
	{
		return this.status != null;
	}
	public ims.scheduling.vo.lookups.Status_Reason getStatus()
	{
		return this.status;
	}
	public void setStatus(ims.scheduling.vo.lookups.Status_Reason value)
	{
		this.isValidated = false;
		this.status = value;
	}
	public boolean getStatusReasonIsNotNull()
	{
		return this.statusreason != null;
	}
	public ims.scheduling.vo.lookups.Status_Reason getStatusReason()
	{
		return this.statusreason;
	}
	public void setStatusReason(ims.scheduling.vo.lookups.Status_Reason value)
	{
		this.isValidated = false;
		this.statusreason = value;
	}
	public boolean getStatusChangeDateTimeIsNotNull()
	{
		return this.statuschangedatetime != null;
	}
	public ims.framework.utils.DateTime getStatusChangeDateTime()
	{
		return this.statuschangedatetime;
	}
	public void setStatusChangeDateTime(ims.framework.utils.DateTime value)
	{
		this.isValidated = false;
		this.statuschangedatetime = value;
	}
	public boolean getApptDateIsNotNull()
	{
		return this.apptdate != null;
	}
	public ims.framework.utils.Date getApptDate()
	{
		return this.apptdate;
	}
	public void setApptDate(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.apptdate = value;
	}
	public boolean getApptTimeIsNotNull()
	{
		return this.appttime != null;
	}
	public ims.framework.utils.Time getApptTime()
	{
		return this.appttime;
	}
	public void setApptTime(ims.framework.utils.Time value)
	{
		this.isValidated = false;
		this.appttime = value;
	}
	public boolean getSessionIsNotNull()
	{
		return this.session != null;
	}
	public ims.scheduling.vo.Sch_SessionRefVo getSession()
	{
		return this.session;
	}
	public void setSession(ims.scheduling.vo.Sch_SessionRefVo value)
	{
		this.isValidated = false;
		this.session = value;
	}
	/**
	* AppointmentStatusVoStatusChangeDateTimeComparator  (class definition)
	*/
	public static class AppointmentStatusVoStatusChangeDateTimeComparator implements java.util.Comparator
	{
		private int direction = 1;
		public AppointmentStatusVoStatusChangeDateTimeComparator()
		{
			this(ims.framework.enumerations.SortOrder.ASCENDING);
		}
		public AppointmentStatusVoStatusChangeDateTimeComparator(ims.framework.enumerations.SortOrder order)
		{
			if (order == ims.framework.enumerations.SortOrder.DESCENDING)
			{
				direction = -1;
			}
		}
		public int compare(Object obj1, Object obj2)
		{
			Appointment_StatusForAppointmentOutcomeVo voObj1 = (Appointment_StatusForAppointmentOutcomeVo)obj1;
			Appointment_StatusForAppointmentOutcomeVo voObj2 = (Appointment_StatusForAppointmentOutcomeVo)obj2;
	
			if (voObj1.getStatusChangeDateTime() == null && voObj2.getStatusChangeDateTime() == null)
				return 0;	
			if (voObj1.getStatusChangeDateTime() == null)
				return -1*direction;
			if (voObj2.getStatusChangeDateTime() == null)
				return direction;
	
			return direction*(voObj1.getStatusChangeDateTime().compareTo(voObj2.getStatusChangeDateTime()));	
		}
		
		public boolean equals(Object obj)
		{
			return false;
		}	
	}
	/**
	* getStatusDateTimeComparator - retrieves a new instance of static class AppointmentStatusVoStatusChangeDateTimeComparator
	*/
	public static AppointmentStatusVoStatusChangeDateTimeComparator getStatusDateTimeComparator(ims.framework.enumerations.SortOrder sortOrder)
	{
		return new Appointment_StatusForAppointmentOutcomeVo.AppointmentStatusVoStatusChangeDateTimeComparator(sortOrder);
	}
	
	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;
	
		Appointment_StatusForAppointmentOutcomeVo clone = new Appointment_StatusForAppointmentOutcomeVo(this.id, this.version);
		
		if(this.status == null)
			clone.status = null;
		else
			clone.status = (ims.scheduling.vo.lookups.Status_Reason)this.status.clone();
		if(this.statusreason == null)
			clone.statusreason = null;
		else
			clone.statusreason = (ims.scheduling.vo.lookups.Status_Reason)this.statusreason.clone();
		if(this.statuschangedatetime == null)
			clone.statuschangedatetime = null;
		else
			clone.statuschangedatetime = (ims.framework.utils.DateTime)this.statuschangedatetime.clone();
		if(this.apptdate == null)
			clone.apptdate = null;
		else
			clone.apptdate = (ims.framework.utils.Date)this.apptdate.clone();
		if(this.appttime == null)
			clone.appttime = null;
		else
			clone.appttime = (ims.framework.utils.Time)this.appttime.clone();
		clone.session = this.session;
		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 (!(Appointment_StatusForAppointmentOutcomeVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A Appointment_StatusForAppointmentOutcomeVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		Appointment_StatusForAppointmentOutcomeVo compareObj = (Appointment_StatusForAppointmentOutcomeVo)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getStatusChangeDateTime() == null && compareObj.getStatusChangeDateTime() != null)
				return -1;
			if(this.getStatusChangeDateTime() != null && compareObj.getStatusChangeDateTime() == null)
				return 1;
			if(this.getStatusChangeDateTime() != null && compareObj.getStatusChangeDateTime() != null)
				retVal = this.getStatusChangeDateTime().compareTo(compareObj.getStatusChangeDateTime());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.status != null)
			count++;
		if(this.statusreason != null)
			count++;
		if(this.statuschangedatetime != null)
			count++;
		if(this.apptdate != null)
			count++;
		if(this.appttime != null)
			count++;
		if(this.session != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 6;
	}
	protected ims.scheduling.vo.lookups.Status_Reason status;
	protected ims.scheduling.vo.lookups.Status_Reason statusreason;
	protected ims.framework.utils.DateTime statuschangedatetime;
	protected ims.framework.utils.Date apptdate;
	protected ims.framework.utils.Time appttime;
	protected ims.scheduling.vo.Sch_SessionRefVo session;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
