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

/**
 * Linked to nursing.assessment.Assessment Component business object (ID: 1015100001).
 */
public class AssessmentLeisure extends ims.nursing.vo.AssessmentComponent implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public AssessmentLeisure()
	{
	}
	public AssessmentLeisure(Integer id, int version)
	{
		super(id, version);
	}
	public AssessmentLeisure(ims.coe.vo.beans.AssessmentLeisureBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.iscomplete = bean.getIsComplete();
		this.assessmentinfo = ims.nursing.vo.AssessmentInfoCollection.buildFromBeanCollection(bean.getAssessmentInfo());
		this.copy = bean.getCopy();
		this.componenttype = bean.getComponentType() == null ? null : ims.nursing.vo.lookups.AssessmentComponentType.buildLookup(bean.getComponentType());
		this.lastassessmentinfo = bean.getLastAssessmentInfo() == null ? null : bean.getLastAssessmentInfo().buildVo();
		this.careplantemplate = ims.nursing.vo.CarePlanTemplateCollection.buildFromBeanCollection(bean.getCarePlanTemplate());
		this.careplans = ims.nursing.vo.CarePlanCollection.buildFromBeanCollection(bean.getCarePlans());
		this.leisureclubs = ims.coe.vo.LeisureClubCollection.buildFromBeanCollection(bean.getLeisureClubs());
		this.hobbies = bean.getHobbies();
		this.enjoydoingmost = bean.getEnjoyDoingMost();
		this.preferencesoftime = bean.getPreferencesOfTime();
		this.alcoholsocially = bean.getAlcoholSocially() == null ? null : ims.core.vo.lookups.YesNoUnknown.buildLookup(bean.getAlcoholSocially());
		this.alcoholdetails = bean.getAlcoholDetails();
		this.alcoholunits = bean.getAlcoholUnits();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.coe.vo.beans.AssessmentLeisureBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.iscomplete = bean.getIsComplete();
		this.assessmentinfo = ims.nursing.vo.AssessmentInfoCollection.buildFromBeanCollection(bean.getAssessmentInfo());
		this.copy = bean.getCopy();
		this.componenttype = bean.getComponentType() == null ? null : ims.nursing.vo.lookups.AssessmentComponentType.buildLookup(bean.getComponentType());
		this.lastassessmentinfo = bean.getLastAssessmentInfo() == null ? null : bean.getLastAssessmentInfo().buildVo(map);
		this.careplantemplate = ims.nursing.vo.CarePlanTemplateCollection.buildFromBeanCollection(bean.getCarePlanTemplate());
		this.careplans = ims.nursing.vo.CarePlanCollection.buildFromBeanCollection(bean.getCarePlans());
		this.leisureclubs = ims.coe.vo.LeisureClubCollection.buildFromBeanCollection(bean.getLeisureClubs());
		this.hobbies = bean.getHobbies();
		this.enjoydoingmost = bean.getEnjoyDoingMost();
		this.preferencesoftime = bean.getPreferencesOfTime();
		this.alcoholsocially = bean.getAlcoholSocially() == null ? null : ims.core.vo.lookups.YesNoUnknown.buildLookup(bean.getAlcoholSocially());
		this.alcoholdetails = bean.getAlcoholDetails();
		this.alcoholunits = bean.getAlcoholUnits();
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.coe.vo.beans.AssessmentLeisureBean bean = null;
		if(map != null)
			bean = (ims.coe.vo.beans.AssessmentLeisureBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.coe.vo.beans.AssessmentLeisureBean();
			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("LEISURECLUBS"))
			return getLeisureClubs();
		if(fieldName.equals("HOBBIES"))
			return getHobbies();
		if(fieldName.equals("ENJOYDOINGMOST"))
			return getEnjoyDoingMost();
		if(fieldName.equals("PREFERENCESOFTIME"))
			return getPreferencesOfTime();
		if(fieldName.equals("ALCOHOLSOCIALLY"))
			return getAlcoholSocially();
		if(fieldName.equals("ALCOHOLDETAILS"))
			return getAlcoholDetails();
		if(fieldName.equals("ALCOHOLUNITS"))
			return getAlcoholUnits();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getLeisureClubsIsNotNull()
	{
		return this.leisureclubs != null;
	}
	public ims.coe.vo.LeisureClubCollection getLeisureClubs()
	{
		return this.leisureclubs;
	}
	public void setLeisureClubs(ims.coe.vo.LeisureClubCollection value)
	{
		this.isValidated = false;
		this.leisureclubs = value;
	}
	public boolean getHobbiesIsNotNull()
	{
		return this.hobbies != null;
	}
	public String getHobbies()
	{
		return this.hobbies;
	}
	public static int getHobbiesMaxLength()
	{
		return 255;
	}
	public void setHobbies(String value)
	{
		this.isValidated = false;
		this.hobbies = value;
	}
	public boolean getEnjoyDoingMostIsNotNull()
	{
		return this.enjoydoingmost != null;
	}
	public String getEnjoyDoingMost()
	{
		return this.enjoydoingmost;
	}
	public static int getEnjoyDoingMostMaxLength()
	{
		return 255;
	}
	public void setEnjoyDoingMost(String value)
	{
		this.isValidated = false;
		this.enjoydoingmost = value;
	}
	public boolean getPreferencesOfTimeIsNotNull()
	{
		return this.preferencesoftime != null;
	}
	public String getPreferencesOfTime()
	{
		return this.preferencesoftime;
	}
	public static int getPreferencesOfTimeMaxLength()
	{
		return 500;
	}
	public void setPreferencesOfTime(String value)
	{
		this.isValidated = false;
		this.preferencesoftime = value;
	}
	public boolean getAlcoholSociallyIsNotNull()
	{
		return this.alcoholsocially != null;
	}
	public ims.core.vo.lookups.YesNoUnknown getAlcoholSocially()
	{
		return this.alcoholsocially;
	}
	public void setAlcoholSocially(ims.core.vo.lookups.YesNoUnknown value)
	{
		this.isValidated = false;
		this.alcoholsocially = value;
	}
	public boolean getAlcoholDetailsIsNotNull()
	{
		return this.alcoholdetails != null;
	}
	public String getAlcoholDetails()
	{
		return this.alcoholdetails;
	}
	public static int getAlcoholDetailsMaxLength()
	{
		return 255;
	}
	public void setAlcoholDetails(String value)
	{
		this.isValidated = false;
		this.alcoholdetails = value;
	}
	public boolean getAlcoholUnitsIsNotNull()
	{
		return this.alcoholunits != null;
	}
	public Integer getAlcoholUnits()
	{
		return this.alcoholunits;
	}
	public void setAlcoholUnits(Integer value)
	{
		this.isValidated = false;
		this.alcoholunits = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.assessmentinfo != null)
		{
			if(!this.assessmentinfo.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.lastassessmentinfo != null)
		{
			if(!this.lastassessmentinfo.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.careplantemplate != null)
		{
			if(!this.careplantemplate.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.careplans != null)
		{
			if(!this.careplans.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.leisureclubs != null)
		{
			if(!this.leisureclubs.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.assessmentinfo != null)
		{
			String[] listOfOtherErrors = this.assessmentinfo.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.lastassessmentinfo != null)
		{
			String[] listOfOtherErrors = this.lastassessmentinfo.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.careplantemplate != null)
		{
			String[] listOfOtherErrors = this.careplantemplate.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.careplans != null)
		{
			String[] listOfOtherErrors = this.careplans.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.leisureclubs != null)
		{
			String[] listOfOtherErrors = this.leisureclubs.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.preferencesoftime != null)
			if(this.preferencesoftime.length() > 500)
				listOfErrors.add("The length of the field [preferencesoftime] in the value object [ims.coe.vo.AssessmentLeisure] is too big. It should be less or equal to 500");
		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;
	
		AssessmentLeisure clone = new AssessmentLeisure(this.id, this.version);
		
		clone.iscomplete = this.iscomplete;
		if(this.assessmentinfo == null)
			clone.assessmentinfo = null;
		else
			clone.assessmentinfo = (ims.nursing.vo.AssessmentInfoCollection)this.assessmentinfo.clone();
		clone.copy = this.copy;
		if(this.componenttype == null)
			clone.componenttype = null;
		else
			clone.componenttype = (ims.nursing.vo.lookups.AssessmentComponentType)this.componenttype.clone();
		if(this.lastassessmentinfo == null)
			clone.lastassessmentinfo = null;
		else
			clone.lastassessmentinfo = (ims.nursing.vo.AssessmentInfo)this.lastassessmentinfo.clone();
		if(this.careplantemplate == null)
			clone.careplantemplate = null;
		else
			clone.careplantemplate = (ims.nursing.vo.CarePlanTemplateCollection)this.careplantemplate.clone();
		if(this.careplans == null)
			clone.careplans = null;
		else
			clone.careplans = (ims.nursing.vo.CarePlanCollection)this.careplans.clone();
		if(this.leisureclubs == null)
			clone.leisureclubs = null;
		else
			clone.leisureclubs = (ims.coe.vo.LeisureClubCollection)this.leisureclubs.clone();
		clone.hobbies = this.hobbies;
		clone.enjoydoingmost = this.enjoydoingmost;
		clone.preferencesoftime = this.preferencesoftime;
		if(this.alcoholsocially == null)
			clone.alcoholsocially = null;
		else
			clone.alcoholsocially = (ims.core.vo.lookups.YesNoUnknown)this.alcoholsocially.clone();
		clone.alcoholdetails = this.alcoholdetails;
		clone.alcoholunits = this.alcoholunits;
		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 (!(AssessmentLeisure.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A AssessmentLeisure object cannot be compared an Object of type " + obj.getClass().getName());
		}
		AssessmentLeisure compareObj = (AssessmentLeisure)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getID_AssessmentComponent() == null && compareObj.getID_AssessmentComponent() != null)
				return -1;
			if(this.getID_AssessmentComponent() != null && compareObj.getID_AssessmentComponent() == null)
				return 1;
			if(this.getID_AssessmentComponent() != null && compareObj.getID_AssessmentComponent() != null)
				retVal = this.getID_AssessmentComponent().compareTo(compareObj.getID_AssessmentComponent());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = super.countFieldsWithValue();
		if(this.leisureclubs != null)
			count++;
		if(this.hobbies != null)
			count++;
		if(this.enjoydoingmost != null)
			count++;
		if(this.preferencesoftime != null)
			count++;
		if(this.alcoholsocially != null)
			count++;
		if(this.alcoholdetails != null)
			count++;
		if(this.alcoholunits != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return super.countValueObjectFields() + 7;
	}
	protected ims.coe.vo.LeisureClubCollection leisureclubs;
	protected String hobbies;
	protected String enjoydoingmost;
	protected String preferencesoftime;
	protected ims.core.vo.lookups.YesNoUnknown alcoholsocially;
	protected String alcoholdetails;
	protected Integer alcoholunits;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
