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

/**
 * Linked to therapies.Adaptations business object (ID: 1019100098).
 */
public class AdaptationsVo extends ims.therapies.vo.AdaptationsRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public AdaptationsVo()
	{
	}
	public AdaptationsVo(Integer id, int version)
	{
		super(id, version);
	}
	public AdaptationsVo(ims.therapies.vo.beans.AdaptationsVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.itemcategory = bean.getItemCategory() == null ? null : ims.spinalinjuries.vo.lookups.Adaptation.buildLookup(bean.getItemCategory());
		this.itemtype = bean.getItemType() == null ? null : ims.spinalinjuries.vo.lookups.Adaptation.buildLookup(bean.getItemType());
		this.supplier = bean.getSupplier() == null ? null : ims.core.vo.lookups.EquipmentAdaptationSupplier.buildLookup(bean.getSupplier());
		this.daterequired = bean.getDateRequired() == null ? null : bean.getDateRequired().buildDate();
		this.datesupplied = bean.getDateSupplied() == null ? null : bean.getDateSupplied().buildDate();
		this.suppliedfor = bean.getSuppliedFor() == null ? null : ims.core.vo.lookups.EquipmentAdaptationSuppliedFor.buildLookup(bean.getSuppliedFor());
		this.loan = bean.getLoan() == null ? null : ims.core.vo.lookups.EquipmentAdaptationLoan.buildLookup(bean.getLoan());
		this.fundedby = bean.getFundedBy() == null ? null : ims.core.vo.lookups.EquipmentAdaptationsFundedBy.buildLookup(bean.getFundedBy());
		this.carecontext = bean.getCareContext() == null ? null : new ims.core.admin.vo.CareContextRefVo(new Integer(bean.getCareContext().getId()), bean.getCareContext().getVersion());
		this.clinicalcontact = bean.getClinicalContact() == null ? null : new ims.core.admin.vo.ClinicalContactRefVo(new Integer(bean.getClinicalContact().getId()), bean.getClinicalContact().getVersion());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.therapies.vo.beans.AdaptationsVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.itemcategory = bean.getItemCategory() == null ? null : ims.spinalinjuries.vo.lookups.Adaptation.buildLookup(bean.getItemCategory());
		this.itemtype = bean.getItemType() == null ? null : ims.spinalinjuries.vo.lookups.Adaptation.buildLookup(bean.getItemType());
		this.supplier = bean.getSupplier() == null ? null : ims.core.vo.lookups.EquipmentAdaptationSupplier.buildLookup(bean.getSupplier());
		this.daterequired = bean.getDateRequired() == null ? null : bean.getDateRequired().buildDate();
		this.datesupplied = bean.getDateSupplied() == null ? null : bean.getDateSupplied().buildDate();
		this.suppliedfor = bean.getSuppliedFor() == null ? null : ims.core.vo.lookups.EquipmentAdaptationSuppliedFor.buildLookup(bean.getSuppliedFor());
		this.loan = bean.getLoan() == null ? null : ims.core.vo.lookups.EquipmentAdaptationLoan.buildLookup(bean.getLoan());
		this.fundedby = bean.getFundedBy() == null ? null : ims.core.vo.lookups.EquipmentAdaptationsFundedBy.buildLookup(bean.getFundedBy());
		this.carecontext = bean.getCareContext() == null ? null : new ims.core.admin.vo.CareContextRefVo(new Integer(bean.getCareContext().getId()), bean.getCareContext().getVersion());
		this.clinicalcontact = bean.getClinicalContact() == null ? null : new ims.core.admin.vo.ClinicalContactRefVo(new Integer(bean.getClinicalContact().getId()), bean.getClinicalContact().getVersion());
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.therapies.vo.beans.AdaptationsVoBean bean = null;
		if(map != null)
			bean = (ims.therapies.vo.beans.AdaptationsVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.therapies.vo.beans.AdaptationsVoBean();
			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("ITEMCATEGORY"))
			return getItemCategory();
		if(fieldName.equals("ITEMTYPE"))
			return getItemType();
		if(fieldName.equals("SUPPLIER"))
			return getSupplier();
		if(fieldName.equals("DATEREQUIRED"))
			return getDateRequired();
		if(fieldName.equals("DATESUPPLIED"))
			return getDateSupplied();
		if(fieldName.equals("SUPPLIEDFOR"))
			return getSuppliedFor();
		if(fieldName.equals("LOAN"))
			return getLoan();
		if(fieldName.equals("FUNDEDBY"))
			return getFundedBy();
		if(fieldName.equals("CARECONTEXT"))
			return getCareContext();
		if(fieldName.equals("CLINICALCONTACT"))
			return getClinicalContact();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getItemCategoryIsNotNull()
	{
		return this.itemcategory != null;
	}
	public ims.spinalinjuries.vo.lookups.Adaptation getItemCategory()
	{
		return this.itemcategory;
	}
	public void setItemCategory(ims.spinalinjuries.vo.lookups.Adaptation value)
	{
		this.isValidated = false;
		this.itemcategory = value;
	}
	public boolean getItemTypeIsNotNull()
	{
		return this.itemtype != null;
	}
	public ims.spinalinjuries.vo.lookups.Adaptation getItemType()
	{
		return this.itemtype;
	}
	public void setItemType(ims.spinalinjuries.vo.lookups.Adaptation value)
	{
		this.isValidated = false;
		this.itemtype = value;
	}
	public boolean getSupplierIsNotNull()
	{
		return this.supplier != null;
	}
	public ims.core.vo.lookups.EquipmentAdaptationSupplier getSupplier()
	{
		return this.supplier;
	}
	public void setSupplier(ims.core.vo.lookups.EquipmentAdaptationSupplier value)
	{
		this.isValidated = false;
		this.supplier = value;
	}
	public boolean getDateRequiredIsNotNull()
	{
		return this.daterequired != null;
	}
	public ims.framework.utils.Date getDateRequired()
	{
		return this.daterequired;
	}
	public void setDateRequired(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.daterequired = value;
	}
	public boolean getDateSuppliedIsNotNull()
	{
		return this.datesupplied != null;
	}
	public ims.framework.utils.Date getDateSupplied()
	{
		return this.datesupplied;
	}
	public void setDateSupplied(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.datesupplied = value;
	}
	public boolean getSuppliedForIsNotNull()
	{
		return this.suppliedfor != null;
	}
	public ims.core.vo.lookups.EquipmentAdaptationSuppliedFor getSuppliedFor()
	{
		return this.suppliedfor;
	}
	public void setSuppliedFor(ims.core.vo.lookups.EquipmentAdaptationSuppliedFor value)
	{
		this.isValidated = false;
		this.suppliedfor = value;
	}
	public boolean getLoanIsNotNull()
	{
		return this.loan != null;
	}
	public ims.core.vo.lookups.EquipmentAdaptationLoan getLoan()
	{
		return this.loan;
	}
	public void setLoan(ims.core.vo.lookups.EquipmentAdaptationLoan value)
	{
		this.isValidated = false;
		this.loan = value;
	}
	public boolean getFundedByIsNotNull()
	{
		return this.fundedby != null;
	}
	public ims.core.vo.lookups.EquipmentAdaptationsFundedBy getFundedBy()
	{
		return this.fundedby;
	}
	public void setFundedBy(ims.core.vo.lookups.EquipmentAdaptationsFundedBy value)
	{
		this.isValidated = false;
		this.fundedby = value;
	}
	public boolean getCareContextIsNotNull()
	{
		return this.carecontext != null;
	}
	public ims.core.admin.vo.CareContextRefVo getCareContext()
	{
		return this.carecontext;
	}
	public void setCareContext(ims.core.admin.vo.CareContextRefVo value)
	{
		this.isValidated = false;
		this.carecontext = value;
	}
	public boolean getClinicalContactIsNotNull()
	{
		return this.clinicalcontact != null;
	}
	public ims.core.admin.vo.ClinicalContactRefVo getClinicalContact()
	{
		return this.clinicalcontact;
	}
	public void setClinicalContact(ims.core.admin.vo.ClinicalContactRefVo value)
	{
		this.isValidated = false;
		this.clinicalcontact = value;
	}
	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]);
			}
		}
		if(this.itemcategory == null)
			listOfErrors.add("ItemCategory is mandatory");
		if(this.carecontext == null)
			listOfErrors.add("CareContext 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;
	
		AdaptationsVo clone = new AdaptationsVo(this.id, this.version);
		
		if(this.itemcategory == null)
			clone.itemcategory = null;
		else
			clone.itemcategory = (ims.spinalinjuries.vo.lookups.Adaptation)this.itemcategory.clone();
		if(this.itemtype == null)
			clone.itemtype = null;
		else
			clone.itemtype = (ims.spinalinjuries.vo.lookups.Adaptation)this.itemtype.clone();
		if(this.supplier == null)
			clone.supplier = null;
		else
			clone.supplier = (ims.core.vo.lookups.EquipmentAdaptationSupplier)this.supplier.clone();
		if(this.daterequired == null)
			clone.daterequired = null;
		else
			clone.daterequired = (ims.framework.utils.Date)this.daterequired.clone();
		if(this.datesupplied == null)
			clone.datesupplied = null;
		else
			clone.datesupplied = (ims.framework.utils.Date)this.datesupplied.clone();
		if(this.suppliedfor == null)
			clone.suppliedfor = null;
		else
			clone.suppliedfor = (ims.core.vo.lookups.EquipmentAdaptationSuppliedFor)this.suppliedfor.clone();
		if(this.loan == null)
			clone.loan = null;
		else
			clone.loan = (ims.core.vo.lookups.EquipmentAdaptationLoan)this.loan.clone();
		if(this.fundedby == null)
			clone.fundedby = null;
		else
			clone.fundedby = (ims.core.vo.lookups.EquipmentAdaptationsFundedBy)this.fundedby.clone();
		clone.carecontext = this.carecontext;
		clone.clinicalcontact = this.clinicalcontact;
		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 (!(AdaptationsVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A AdaptationsVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		AdaptationsVo compareObj = (AdaptationsVo)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getItemCategory() == null && compareObj.getItemCategory() != null)
				return -1;
			if(this.getItemCategory() != null && compareObj.getItemCategory() == null)
				return 1;
			if(this.getItemCategory() != null && compareObj.getItemCategory() != null)
				retVal = this.getItemCategory().compareTo(compareObj.getItemCategory());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.itemcategory != null)
			count++;
		if(this.itemtype != null)
			count++;
		if(this.supplier != null)
			count++;
		if(this.daterequired != null)
			count++;
		if(this.datesupplied != null)
			count++;
		if(this.suppliedfor != null)
			count++;
		if(this.loan != null)
			count++;
		if(this.fundedby != null)
			count++;
		if(this.carecontext != null)
			count++;
		if(this.clinicalcontact != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 10;
	}
	protected ims.spinalinjuries.vo.lookups.Adaptation itemcategory;
	protected ims.spinalinjuries.vo.lookups.Adaptation itemtype;
	protected ims.core.vo.lookups.EquipmentAdaptationSupplier supplier;
	protected ims.framework.utils.Date daterequired;
	protected ims.framework.utils.Date datesupplied;
	protected ims.core.vo.lookups.EquipmentAdaptationSuppliedFor suppliedfor;
	protected ims.core.vo.lookups.EquipmentAdaptationLoan loan;
	protected ims.core.vo.lookups.EquipmentAdaptationsFundedBy fundedby;
	protected ims.core.admin.vo.CareContextRefVo carecontext;
	protected ims.core.admin.vo.ClinicalContactRefVo clinicalcontact;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
