/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/ValueObjects/src/ims/core/vo/InpatientEpisodeMaintenanceVo.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.core.vo;

/**
 * Linked to core.admin.pas.Inpatient Episode business object (ID: 1014100000).
 */
public class InpatientEpisodeMaintenanceVo extends ims.core.vo.InpatientEpisodeVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public InpatientEpisodeMaintenanceVo()
	{
	}
	public InpatientEpisodeMaintenanceVo(Integer id, int version)
	{
		super(id, version);
	}
	public InpatientEpisodeMaintenanceVo(ims.core.vo.beans.InpatientEpisodeMaintenanceVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.isonleave = bean.getIsOnLeave();
		this.pasevent = bean.getPasEvent() == null ? null : bean.getPasEvent().buildVo();
		this.comments = bean.getComments();
		this.wardstays = ims.core.vo.WardStayVoCollection.buildFromBeanCollection(bean.getWardStays());
		this.admissiondatetime = bean.getAdmissionDateTime() == null ? null : bean.getAdmissionDateTime().buildDateTime();
		this.estdischargedate = bean.getEstDischargeDate() == null ? null : bean.getEstDischargeDate().buildDateTime();
		this.bedno = bean.getBedNo();
		this.admissiontype = bean.getAdmissionType() == null ? null : ims.core.vo.lookups.AdmissionType.buildLookup(bean.getAdmissionType());
		this.ismaternityinpatient = bean.getIsMaternityInpatient();
		this.ischaplainrequired = bean.getIsChaplainRequired();
		this.methodofadmission = bean.getMethodOfAdmission() == null ? null : ims.core.vo.lookups.MethodOfAdmission.buildLookup(bean.getMethodOfAdmission());
		this.reasonforadmission = bean.getReasonForAdmission();
		this.sourceofadmission = bean.getSourceOfAdmission() == null ? null : ims.core.vo.lookups.SourceOfAdmission.buildLookup(bean.getSourceOfAdmission());
		this.wardtype = bean.getWardType() == null ? null : ims.core.vo.lookups.WardType.buildLookup(bean.getWardType());
		this.preadmitnumber = bean.getPreAdmitNumber();
		this.readmissiontype = bean.getReadmissionType() == null ? null : ims.core.vo.lookups.ReadmissionType.buildLookup(bean.getReadmissionType());
		this.dischargereadydate = bean.getDischargeReadyDate() == null ? null : bean.getDischargeReadyDate().buildDate();
		this.homeleaves = ims.core.vo.HomeLeaveVoCollection.buildFromBeanCollection(bean.getHomeLeaves());
		this.patientstatus = bean.getPatientStatus() == null ? null : ims.core.vo.lookups.PatientStatus.buildLookup(bean.getPatientStatus());
		this.extendeddetails = bean.getExtendedDetails() == null ? null : bean.getExtendedDetails().buildVo();
		this.admissiondetails = bean.getAdmissionDetails() == null ? null : new ims.core.admin.pas.vo.AdmissionDetailRefVo(new Integer(bean.getAdmissionDetails().getId()), bean.getAdmissionDetails().getVersion());
		this.bed = bean.getBed() == null ? null : bean.getBed().buildVo();
		this.wardstatus = bean.getWardStatus() == null ? null : ims.core.vo.lookups.WardBayStatus.buildLookup(bean.getWardStatus());
		this.transferreason = bean.getTransferReason() == null ? null : ims.core.vo.lookups.TransferReason.buildLookup(bean.getTransferReason());
		this.transfercomment = bean.getTransferComment();
		this.admissiondetailupdates = bean.getAdmissionDetailUpdates() == null ? null : bean.getAdmissionDetailUpdates().buildVo();
		this.consultantstays = ims.core.vo.ConsultantStayVoCollection.buildFromBeanCollection(bean.getConsultantStays());
		this.referringconsultant = bean.getReferringConsultant() == null ? null : bean.getReferringConsultant().buildVo();
		this.referringhcpref = bean.getReferringHcpRef() == null ? null : new ims.core.resource.people.vo.MedicRefVo(new Integer(bean.getReferringHcpRef().getId()), bean.getReferringHcpRef().getVersion());
		this.consultanthcpref = bean.getConsultantHcpRef() == null ? null : new ims.core.resource.people.vo.MedicRefVo(new Integer(bean.getConsultantHcpRef().getId()), bean.getConsultantHcpRef().getVersion());
		this.service = bean.getService() == null ? null : bean.getService().buildVo();
		this.sourceofemergencyreferral = bean.getSourceOfEmergencyReferral() == null ? null : ims.core.vo.lookups.SourceOfEmergencyReferral.buildLookup(bean.getSourceOfEmergencyReferral());
		this.admissionward = bean.getAdmissionWard() == null ? null : bean.getAdmissionWard().buildVo();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.core.vo.beans.InpatientEpisodeMaintenanceVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.isonleave = bean.getIsOnLeave();
		this.pasevent = bean.getPasEvent() == null ? null : bean.getPasEvent().buildVo(map);
		this.comments = bean.getComments();
		this.wardstays = ims.core.vo.WardStayVoCollection.buildFromBeanCollection(bean.getWardStays());
		this.admissiondatetime = bean.getAdmissionDateTime() == null ? null : bean.getAdmissionDateTime().buildDateTime();
		this.estdischargedate = bean.getEstDischargeDate() == null ? null : bean.getEstDischargeDate().buildDateTime();
		this.bedno = bean.getBedNo();
		this.admissiontype = bean.getAdmissionType() == null ? null : ims.core.vo.lookups.AdmissionType.buildLookup(bean.getAdmissionType());
		this.ismaternityinpatient = bean.getIsMaternityInpatient();
		this.ischaplainrequired = bean.getIsChaplainRequired();
		this.methodofadmission = bean.getMethodOfAdmission() == null ? null : ims.core.vo.lookups.MethodOfAdmission.buildLookup(bean.getMethodOfAdmission());
		this.reasonforadmission = bean.getReasonForAdmission();
		this.sourceofadmission = bean.getSourceOfAdmission() == null ? null : ims.core.vo.lookups.SourceOfAdmission.buildLookup(bean.getSourceOfAdmission());
		this.wardtype = bean.getWardType() == null ? null : ims.core.vo.lookups.WardType.buildLookup(bean.getWardType());
		this.preadmitnumber = bean.getPreAdmitNumber();
		this.readmissiontype = bean.getReadmissionType() == null ? null : ims.core.vo.lookups.ReadmissionType.buildLookup(bean.getReadmissionType());
		this.dischargereadydate = bean.getDischargeReadyDate() == null ? null : bean.getDischargeReadyDate().buildDate();
		this.homeleaves = ims.core.vo.HomeLeaveVoCollection.buildFromBeanCollection(bean.getHomeLeaves());
		this.patientstatus = bean.getPatientStatus() == null ? null : ims.core.vo.lookups.PatientStatus.buildLookup(bean.getPatientStatus());
		this.extendeddetails = bean.getExtendedDetails() == null ? null : bean.getExtendedDetails().buildVo(map);
		this.admissiondetails = bean.getAdmissionDetails() == null ? null : new ims.core.admin.pas.vo.AdmissionDetailRefVo(new Integer(bean.getAdmissionDetails().getId()), bean.getAdmissionDetails().getVersion());
		this.bed = bean.getBed() == null ? null : bean.getBed().buildVo(map);
		this.wardstatus = bean.getWardStatus() == null ? null : ims.core.vo.lookups.WardBayStatus.buildLookup(bean.getWardStatus());
		this.transferreason = bean.getTransferReason() == null ? null : ims.core.vo.lookups.TransferReason.buildLookup(bean.getTransferReason());
		this.transfercomment = bean.getTransferComment();
		this.admissiondetailupdates = bean.getAdmissionDetailUpdates() == null ? null : bean.getAdmissionDetailUpdates().buildVo(map);
		this.consultantstays = ims.core.vo.ConsultantStayVoCollection.buildFromBeanCollection(bean.getConsultantStays());
		this.referringconsultant = bean.getReferringConsultant() == null ? null : bean.getReferringConsultant().buildVo(map);
		this.referringhcpref = bean.getReferringHcpRef() == null ? null : new ims.core.resource.people.vo.MedicRefVo(new Integer(bean.getReferringHcpRef().getId()), bean.getReferringHcpRef().getVersion());
		this.consultanthcpref = bean.getConsultantHcpRef() == null ? null : new ims.core.resource.people.vo.MedicRefVo(new Integer(bean.getConsultantHcpRef().getId()), bean.getConsultantHcpRef().getVersion());
		this.service = bean.getService() == null ? null : bean.getService().buildVo(map);
		this.sourceofemergencyreferral = bean.getSourceOfEmergencyReferral() == null ? null : ims.core.vo.lookups.SourceOfEmergencyReferral.buildLookup(bean.getSourceOfEmergencyReferral());
		this.admissionward = bean.getAdmissionWard() == null ? null : bean.getAdmissionWard().buildVo(map);
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.core.vo.beans.InpatientEpisodeMaintenanceVoBean bean = null;
		if(map != null)
			bean = (ims.core.vo.beans.InpatientEpisodeMaintenanceVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.core.vo.beans.InpatientEpisodeMaintenanceVoBean();
			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("REFERRINGCONSULTANT"))
			return getReferringConsultant();
		if(fieldName.equals("REFERRINGHCPREF"))
			return getReferringHcpRef();
		if(fieldName.equals("CONSULTANTHCPREF"))
			return getConsultantHcpRef();
		if(fieldName.equals("SERVICE"))
			return getService();
		if(fieldName.equals("SOURCEOFEMERGENCYREFERRAL"))
			return getSourceOfEmergencyReferral();
		if(fieldName.equals("ADMISSIONWARD"))
			return getAdmissionWard();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getReferringConsultantIsNotNull()
	{
		return this.referringconsultant != null;
	}
	public ims.core.vo.MedicVo getReferringConsultant()
	{
		return this.referringconsultant;
	}
	public void setReferringConsultant(ims.core.vo.MedicVo value)
	{
		this.isValidated = false;
		this.referringconsultant = value;
	}
	public boolean getReferringHcpRefIsNotNull()
	{
		return this.referringhcpref != null;
	}
	public ims.core.resource.people.vo.MedicRefVo getReferringHcpRef()
	{
		return this.referringhcpref;
	}
	public void setReferringHcpRef(ims.core.resource.people.vo.MedicRefVo value)
	{
		this.isValidated = false;
		this.referringhcpref = value;
	}
	public boolean getConsultantHcpRefIsNotNull()
	{
		return this.consultanthcpref != null;
	}
	public ims.core.resource.people.vo.MedicRefVo getConsultantHcpRef()
	{
		return this.consultanthcpref;
	}
	public void setConsultantHcpRef(ims.core.resource.people.vo.MedicRefVo value)
	{
		this.isValidated = false;
		this.consultanthcpref = value;
	}
	public boolean getServiceIsNotNull()
	{
		return this.service != null;
	}
	public ims.core.vo.ServiceLiteVo getService()
	{
		return this.service;
	}
	public void setService(ims.core.vo.ServiceLiteVo value)
	{
		this.isValidated = false;
		this.service = value;
	}
	public boolean getSourceOfEmergencyReferralIsNotNull()
	{
		return this.sourceofemergencyreferral != null;
	}
	public ims.core.vo.lookups.SourceOfEmergencyReferral getSourceOfEmergencyReferral()
	{
		return this.sourceofemergencyreferral;
	}
	public void setSourceOfEmergencyReferral(ims.core.vo.lookups.SourceOfEmergencyReferral value)
	{
		this.isValidated = false;
		this.sourceofemergencyreferral = value;
	}
	public boolean getAdmissionWardIsNotNull()
	{
		return this.admissionward != null;
	}
	public ims.core.vo.LocationLiteVo getAdmissionWard()
	{
		return this.admissionward;
	}
	public void setAdmissionWard(ims.core.vo.LocationLiteVo value)
	{
		this.isValidated = false;
		this.admissionward = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.pasevent != null)
		{
			if(!this.pasevent.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.wardstays != null)
		{
			if(!this.wardstays.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.extendeddetails != null)
		{
			if(!this.extendeddetails.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.consultantstays != null)
		{
			if(!this.consultantstays.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.pasevent != null)
		{
			String[] listOfOtherErrors = this.pasevent.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.comments != null)
			if(this.comments.length() > 1500)
				listOfErrors.add("The length of the field [comments] in the value object [ims.core.vo.InpatientEpisodeMaintenanceVo] is too big. It should be less or equal to 1500");
		if(this.wardstays != null)
		{
			String[] listOfOtherErrors = this.wardstays.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.bedno != null)
			if(this.bedno.length() > 10)
				listOfErrors.add("The length of the field [bedno] in the value object [ims.core.vo.InpatientEpisodeMaintenanceVo] is too big. It should be less or equal to 10");
		if(this.reasonforadmission != null)
			if(this.reasonforadmission.length() > 255)
				listOfErrors.add("The length of the field [reasonforadmission] in the value object [ims.core.vo.InpatientEpisodeMaintenanceVo] is too big. It should be less or equal to 255");
		if(this.extendeddetails != null)
		{
			String[] listOfOtherErrors = this.extendeddetails.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.consultantstays != null)
		{
			String[] listOfOtherErrors = this.consultantstays.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;
	
		InpatientEpisodeMaintenanceVo clone = new InpatientEpisodeMaintenanceVo(this.id, this.version);
		
		clone.isonleave = this.isonleave;
		if(this.pasevent == null)
			clone.pasevent = null;
		else
			clone.pasevent = (ims.core.vo.PasEventVo)this.pasevent.clone();
		clone.comments = this.comments;
		if(this.wardstays == null)
			clone.wardstays = null;
		else
			clone.wardstays = (ims.core.vo.WardStayVoCollection)this.wardstays.clone();
		if(this.admissiondatetime == null)
			clone.admissiondatetime = null;
		else
			clone.admissiondatetime = (ims.framework.utils.DateTime)this.admissiondatetime.clone();
		if(this.estdischargedate == null)
			clone.estdischargedate = null;
		else
			clone.estdischargedate = (ims.framework.utils.DateTime)this.estdischargedate.clone();
		clone.bedno = this.bedno;
		if(this.admissiontype == null)
			clone.admissiontype = null;
		else
			clone.admissiontype = (ims.core.vo.lookups.AdmissionType)this.admissiontype.clone();
		clone.ismaternityinpatient = this.ismaternityinpatient;
		clone.ischaplainrequired = this.ischaplainrequired;
		if(this.methodofadmission == null)
			clone.methodofadmission = null;
		else
			clone.methodofadmission = (ims.core.vo.lookups.MethodOfAdmission)this.methodofadmission.clone();
		clone.reasonforadmission = this.reasonforadmission;
		if(this.sourceofadmission == null)
			clone.sourceofadmission = null;
		else
			clone.sourceofadmission = (ims.core.vo.lookups.SourceOfAdmission)this.sourceofadmission.clone();
		if(this.wardtype == null)
			clone.wardtype = null;
		else
			clone.wardtype = (ims.core.vo.lookups.WardType)this.wardtype.clone();
		clone.preadmitnumber = this.preadmitnumber;
		if(this.readmissiontype == null)
			clone.readmissiontype = null;
		else
			clone.readmissiontype = (ims.core.vo.lookups.ReadmissionType)this.readmissiontype.clone();
		if(this.dischargereadydate == null)
			clone.dischargereadydate = null;
		else
			clone.dischargereadydate = (ims.framework.utils.Date)this.dischargereadydate.clone();
		if(this.homeleaves == null)
			clone.homeleaves = null;
		else
			clone.homeleaves = (ims.core.vo.HomeLeaveVoCollection)this.homeleaves.clone();
		if(this.patientstatus == null)
			clone.patientstatus = null;
		else
			clone.patientstatus = (ims.core.vo.lookups.PatientStatus)this.patientstatus.clone();
		if(this.extendeddetails == null)
			clone.extendeddetails = null;
		else
			clone.extendeddetails = (ims.core.vo.ExtendedAdmissionDetailVo)this.extendeddetails.clone();
		clone.admissiondetails = this.admissiondetails;
		if(this.bed == null)
			clone.bed = null;
		else
			clone.bed = (ims.core.vo.BedSpaceStateLiteVo)this.bed.clone();
		if(this.wardstatus == null)
			clone.wardstatus = null;
		else
			clone.wardstatus = (ims.core.vo.lookups.WardBayStatus)this.wardstatus.clone();
		if(this.transferreason == null)
			clone.transferreason = null;
		else
			clone.transferreason = (ims.core.vo.lookups.TransferReason)this.transferreason.clone();
		clone.transfercomment = this.transfercomment;
		if(this.admissiondetailupdates == null)
			clone.admissiondetailupdates = null;
		else
			clone.admissiondetailupdates = (ims.core.vo.AdmissionDetailForADTUpdateAdmissionVo)this.admissiondetailupdates.clone();
		if(this.consultantstays == null)
			clone.consultantstays = null;
		else
			clone.consultantstays = (ims.core.vo.ConsultantStayVoCollection)this.consultantstays.clone();
		if(this.referringconsultant == null)
			clone.referringconsultant = null;
		else
			clone.referringconsultant = (ims.core.vo.MedicVo)this.referringconsultant.clone();
		clone.referringhcpref = this.referringhcpref;
		clone.consultanthcpref = this.consultanthcpref;
		if(this.service == null)
			clone.service = null;
		else
			clone.service = (ims.core.vo.ServiceLiteVo)this.service.clone();
		if(this.sourceofemergencyreferral == null)
			clone.sourceofemergencyreferral = null;
		else
			clone.sourceofemergencyreferral = (ims.core.vo.lookups.SourceOfEmergencyReferral)this.sourceofemergencyreferral.clone();
		if(this.admissionward == null)
			clone.admissionward = null;
		else
			clone.admissionward = (ims.core.vo.LocationLiteVo)this.admissionward.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 (!(InpatientEpisodeMaintenanceVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A InpatientEpisodeMaintenanceVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((InpatientEpisodeMaintenanceVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((InpatientEpisodeMaintenanceVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = super.countFieldsWithValue();
		if(this.referringconsultant != null)
			count++;
		if(this.referringhcpref != null)
			count++;
		if(this.consultanthcpref != null)
			count++;
		if(this.service != null)
			count++;
		if(this.sourceofemergencyreferral != null)
			count++;
		if(this.admissionward != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return super.countValueObjectFields() + 6;
	}
	protected ims.core.vo.MedicVo referringconsultant;
	protected ims.core.resource.people.vo.MedicRefVo referringhcpref;
	protected ims.core.resource.people.vo.MedicRefVo consultanthcpref;
	protected ims.core.vo.ServiceLiteVo service;
	protected ims.core.vo.lookups.SourceOfEmergencyReferral sourceofemergencyreferral;
	protected ims.core.vo.LocationLiteVo admissionward;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
