/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/ValueObjects/src/ims/core/vo/BayConfigVo.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.layout.BayConfig business object (ID: 1095100004).
 */
public class BayConfigVo extends ims.core.vo.BayConfigLiteVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public BayConfigVo()
	{
	}
	public BayConfigVo(Integer id, int version)
	{
		super(id, version);
	}
	public BayConfigVo(ims.core.vo.beans.BayConfigVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.bay = bean.getBay() == null ? null : bean.getBay().buildVo();
		this.isactive = bean.getIsActive();
		this.male = bean.getMale();
		this.female = bean.getFemale();
		this.paediatric = bean.getPaediatric();
		this.numofbeds = bean.getNumOfBeds();
		this.numofoccupiedbeds = bean.getNumOfOccupiedBeds();
		this.openingtime = bean.getOpeningTime() == null ? null : bean.getOpeningTime().buildTime();
		this.closingtime = bean.getClosingTime() == null ? null : bean.getClosingTime().buildTime();
		this.weekdaysonly = bean.getWeekdaysOnly();
		this.bayavailabilitystatus = bean.getBayAvailabilityStatus() == null ? null : ims.core.vo.lookups.WardBayStatus.buildLookup(bean.getBayAvailabilityStatus());
		this.reopenoutofhours = ims.core.vo.ReopenBayOutOfHoursVoCollection.buildFromBeanCollection(bean.getReOpenOutOfHours());
		this.temporarybaygender = bean.getTemporaryBayGender() == null ? null : ims.core.vo.lookups.Sex.buildLookup(bean.getTemporaryBayGender());
		this.floorbedspacelayout = bean.getFloorBedSpaceLayout() == null ? null : bean.getFloorBedSpaceLayout().buildVo();
		this.dependency = bean.getDependency() == null ? null : ims.core.vo.lookups.BayDependencyLevel.buildLookup(bean.getDependency());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.core.vo.beans.BayConfigVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.bay = bean.getBay() == null ? null : bean.getBay().buildVo(map);
		this.isactive = bean.getIsActive();
		this.male = bean.getMale();
		this.female = bean.getFemale();
		this.paediatric = bean.getPaediatric();
		this.numofbeds = bean.getNumOfBeds();
		this.numofoccupiedbeds = bean.getNumOfOccupiedBeds();
		this.openingtime = bean.getOpeningTime() == null ? null : bean.getOpeningTime().buildTime();
		this.closingtime = bean.getClosingTime() == null ? null : bean.getClosingTime().buildTime();
		this.weekdaysonly = bean.getWeekdaysOnly();
		this.bayavailabilitystatus = bean.getBayAvailabilityStatus() == null ? null : ims.core.vo.lookups.WardBayStatus.buildLookup(bean.getBayAvailabilityStatus());
		this.reopenoutofhours = ims.core.vo.ReopenBayOutOfHoursVoCollection.buildFromBeanCollection(bean.getReOpenOutOfHours());
		this.temporarybaygender = bean.getTemporaryBayGender() == null ? null : ims.core.vo.lookups.Sex.buildLookup(bean.getTemporaryBayGender());
		this.floorbedspacelayout = bean.getFloorBedSpaceLayout() == null ? null : bean.getFloorBedSpaceLayout().buildVo(map);
		this.dependency = bean.getDependency() == null ? null : ims.core.vo.lookups.BayDependencyLevel.buildLookup(bean.getDependency());
	}
	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.BayConfigVoBean bean = null;
		if(map != null)
			bean = (ims.core.vo.beans.BayConfigVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.core.vo.beans.BayConfigVoBean();
			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("FLOORBEDSPACELAYOUT"))
			return getFloorBedSpaceLayout();
		if(fieldName.equals("DEPENDENCY"))
			return getDependency();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getFloorBedSpaceLayoutIsNotNull()
	{
		return this.floorbedspacelayout != null;
	}
	public ims.core.vo.FloorBedSpaceLayoutLiteVo getFloorBedSpaceLayout()
	{
		return this.floorbedspacelayout;
	}
	public void setFloorBedSpaceLayout(ims.core.vo.FloorBedSpaceLayoutLiteVo value)
	{
		this.isValidated = false;
		this.floorbedspacelayout = value;
	}
	public boolean getDependencyIsNotNull()
	{
		return this.dependency != null;
	}
	public ims.core.vo.lookups.BayDependencyLevel getDependency()
	{
		return this.dependency;
	}
	public void setDependency(ims.core.vo.lookups.BayDependencyLevel value)
	{
		this.isValidated = false;
		this.dependency = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.bay != null)
		{
			if(!this.bay.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.reopenoutofhours != null)
		{
			if(!this.reopenoutofhours.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.bay == null)
			listOfErrors.add("Bay is mandatory");
		if(this.bay != null)
		{
			String[] listOfOtherErrors = this.bay.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.isactive == null)
			listOfErrors.add("isActive is mandatory");
		if(this.reopenoutofhours != null)
		{
			String[] listOfOtherErrors = this.reopenoutofhours.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.floorbedspacelayout == null)
			listOfErrors.add("Bed Space Layout is mandatory");
		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;
	
		BayConfigVo clone = new BayConfigVo(this.id, this.version);
		
		if(this.bay == null)
			clone.bay = null;
		else
			clone.bay = (ims.core.vo.LocationLiteVo)this.bay.clone();
		clone.isactive = this.isactive;
		clone.male = this.male;
		clone.female = this.female;
		clone.paediatric = this.paediatric;
		clone.numofbeds = this.numofbeds;
		clone.numofoccupiedbeds = this.numofoccupiedbeds;
		if(this.openingtime == null)
			clone.openingtime = null;
		else
			clone.openingtime = (ims.framework.utils.Time)this.openingtime.clone();
		if(this.closingtime == null)
			clone.closingtime = null;
		else
			clone.closingtime = (ims.framework.utils.Time)this.closingtime.clone();
		clone.weekdaysonly = this.weekdaysonly;
		if(this.bayavailabilitystatus == null)
			clone.bayavailabilitystatus = null;
		else
			clone.bayavailabilitystatus = (ims.core.vo.lookups.WardBayStatus)this.bayavailabilitystatus.clone();
		if(this.reopenoutofhours == null)
			clone.reopenoutofhours = null;
		else
			clone.reopenoutofhours = (ims.core.vo.ReopenBayOutOfHoursVoCollection)this.reopenoutofhours.clone();
		if(this.temporarybaygender == null)
			clone.temporarybaygender = null;
		else
			clone.temporarybaygender = (ims.core.vo.lookups.Sex)this.temporarybaygender.clone();
		if(this.floorbedspacelayout == null)
			clone.floorbedspacelayout = null;
		else
			clone.floorbedspacelayout = (ims.core.vo.FloorBedSpaceLayoutLiteVo)this.floorbedspacelayout.clone();
		if(this.dependency == null)
			clone.dependency = null;
		else
			clone.dependency = (ims.core.vo.lookups.BayDependencyLevel)this.dependency.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 (!(BayConfigVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A BayConfigVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		BayConfigVo compareObj = (BayConfigVo)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getBay() == null && compareObj.getBay() != null)
				return -1;
			if(this.getBay() != null && compareObj.getBay() == null)
				return 1;
			if(this.getBay() != null && compareObj.getBay() != null)
				retVal = this.getBay().compareTo(compareObj.getBay());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = super.countFieldsWithValue();
		if(this.floorbedspacelayout != null)
			count++;
		if(this.dependency != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return super.countValueObjectFields() + 2;
	}
	protected ims.core.vo.FloorBedSpaceLayoutLiteVo floorbedspacelayout;
	protected ims.core.vo.lookups.BayDependencyLevel dependency;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
