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

	public NeedsAssessmentComponentEditVo()
	{
	}
	public NeedsAssessmentComponentEditVo(Integer id, int version)
	{
		super(id, version);
	}
	public NeedsAssessmentComponentEditVo(ims.core.vo.beans.NeedsAssessmentComponentEditVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.goalplanmeetingdate = bean.getGoalPlanMeetingDate() == null ? null : bean.getGoalPlanMeetingDate().buildDate();
		this.needassessmentnumber = bean.getNeedAssessmentNumber() == null ? null : ims.clinical.vo.lookups.NeedsAssessmentNumber.buildLookup(bean.getNeedAssessmentNumber());
		this.hadbooklet = bean.getHadBooklet() == null ? null : ims.core.vo.lookups.YesNoUnknown.buildLookup(bean.getHadBooklet());
		this.attachbooklettosummarysheet = bean.getAttachBookletToSummarySheet() == null ? null : ims.core.vo.lookups.YesNo.buildLookup(bean.getAttachBookletToSummarySheet());
		this.datestarted = bean.getDateStarted() == null ? null : bean.getDateStarted().buildDateTime();
		this.authoringhcp = bean.getAuthoringHCP() == null ? null : bean.getAuthoringHCP().buildVo();
		this.patientuserdefinedobject = bean.getPatientUserDefinedObject() == null ? null : new ims.assessment.instantiation.vo.PatientUserDefinedObjectRefVo(new Integer(bean.getPatientUserDefinedObject().getId()), bean.getPatientUserDefinedObject().getVersion());
		this.componentscore = ims.core.vo.NeedsAssessmentComponentScoreVoCollection.buildFromBeanCollection(bean.getComponentScore());
		this.carecontext = bean.getCareContext() == null ? null : new ims.core.admin.vo.CareContextRefVo(new Integer(bean.getCareContext().getId()), bean.getCareContext().getVersion());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.core.vo.beans.NeedsAssessmentComponentEditVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.goalplanmeetingdate = bean.getGoalPlanMeetingDate() == null ? null : bean.getGoalPlanMeetingDate().buildDate();
		this.needassessmentnumber = bean.getNeedAssessmentNumber() == null ? null : ims.clinical.vo.lookups.NeedsAssessmentNumber.buildLookup(bean.getNeedAssessmentNumber());
		this.hadbooklet = bean.getHadBooklet() == null ? null : ims.core.vo.lookups.YesNoUnknown.buildLookup(bean.getHadBooklet());
		this.attachbooklettosummarysheet = bean.getAttachBookletToSummarySheet() == null ? null : ims.core.vo.lookups.YesNo.buildLookup(bean.getAttachBookletToSummarySheet());
		this.datestarted = bean.getDateStarted() == null ? null : bean.getDateStarted().buildDateTime();
		this.authoringhcp = bean.getAuthoringHCP() == null ? null : bean.getAuthoringHCP().buildVo(map);
		this.patientuserdefinedobject = bean.getPatientUserDefinedObject() == null ? null : new ims.assessment.instantiation.vo.PatientUserDefinedObjectRefVo(new Integer(bean.getPatientUserDefinedObject().getId()), bean.getPatientUserDefinedObject().getVersion());
		this.componentscore = ims.core.vo.NeedsAssessmentComponentScoreVoCollection.buildFromBeanCollection(bean.getComponentScore());
		this.carecontext = bean.getCareContext() == null ? null : new ims.core.admin.vo.CareContextRefVo(new Integer(bean.getCareContext().getId()), bean.getCareContext().getVersion());
	}
	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.NeedsAssessmentComponentEditVoBean bean = null;
		if(map != null)
			bean = (ims.core.vo.beans.NeedsAssessmentComponentEditVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.core.vo.beans.NeedsAssessmentComponentEditVoBean();
			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("PATIENTUSERDEFINEDOBJECT"))
			return getPatientUserDefinedObject();
		if(fieldName.equals("COMPONENTSCORE"))
			return getComponentScore();
		if(fieldName.equals("CARECONTEXT"))
			return getCareContext();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getPatientUserDefinedObjectIsNotNull()
	{
		return this.patientuserdefinedobject != null;
	}
	public ims.assessment.instantiation.vo.PatientUserDefinedObjectRefVo getPatientUserDefinedObject()
	{
		return this.patientuserdefinedobject;
	}
	public void setPatientUserDefinedObject(ims.assessment.instantiation.vo.PatientUserDefinedObjectRefVo value)
	{
		this.isValidated = false;
		this.patientuserdefinedobject = value;
	}
	public boolean getComponentScoreIsNotNull()
	{
		return this.componentscore != null;
	}
	public ims.core.vo.NeedsAssessmentComponentScoreVoCollection getComponentScore()
	{
		return this.componentscore;
	}
	public void setComponentScore(ims.core.vo.NeedsAssessmentComponentScoreVoCollection value)
	{
		this.isValidated = false;
		this.componentscore = 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 isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.authoringhcp != null)
		{
			if(!this.authoringhcp.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.componentscore != null)
		{
			if(!this.componentscore.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.needassessmentnumber == null)
			listOfErrors.add("NeedAssessmentNumber is mandatory");
		if(this.hadbooklet == null)
			listOfErrors.add("HadBooklet is mandatory");
		if(this.authoringhcp == null)
			listOfErrors.add("AuthoringHCP is mandatory");
		if(this.authoringhcp != null)
		{
			String[] listOfOtherErrors = this.authoringhcp.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.componentscore != null)
		{
			String[] listOfOtherErrors = this.componentscore.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		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;
	
		NeedsAssessmentComponentEditVo clone = new NeedsAssessmentComponentEditVo(this.id, this.version);
		
		if(this.goalplanmeetingdate == null)
			clone.goalplanmeetingdate = null;
		else
			clone.goalplanmeetingdate = (ims.framework.utils.Date)this.goalplanmeetingdate.clone();
		if(this.needassessmentnumber == null)
			clone.needassessmentnumber = null;
		else
			clone.needassessmentnumber = (ims.clinical.vo.lookups.NeedsAssessmentNumber)this.needassessmentnumber.clone();
		if(this.hadbooklet == null)
			clone.hadbooklet = null;
		else
			clone.hadbooklet = (ims.core.vo.lookups.YesNoUnknown)this.hadbooklet.clone();
		if(this.attachbooklettosummarysheet == null)
			clone.attachbooklettosummarysheet = null;
		else
			clone.attachbooklettosummarysheet = (ims.core.vo.lookups.YesNo)this.attachbooklettosummarysheet.clone();
		if(this.datestarted == null)
			clone.datestarted = null;
		else
			clone.datestarted = (ims.framework.utils.DateTime)this.datestarted.clone();
		if(this.authoringhcp == null)
			clone.authoringhcp = null;
		else
			clone.authoringhcp = (ims.core.vo.Hcp)this.authoringhcp.clone();
		clone.patientuserdefinedobject = this.patientuserdefinedobject;
		if(this.componentscore == null)
			clone.componentscore = null;
		else
			clone.componentscore = (ims.core.vo.NeedsAssessmentComponentScoreVoCollection)this.componentscore.clone();
		clone.carecontext = this.carecontext;
		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 (!(NeedsAssessmentComponentEditVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A NeedsAssessmentComponentEditVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((NeedsAssessmentComponentEditVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((NeedsAssessmentComponentEditVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = super.countFieldsWithValue();
		if(this.patientuserdefinedobject != null)
			count++;
		if(this.componentscore != null)
			count++;
		if(this.carecontext != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return super.countValueObjectFields() + 3;
	}
	protected ims.assessment.instantiation.vo.PatientUserDefinedObjectRefVo patientuserdefinedobject;
	protected ims.core.vo.NeedsAssessmentComponentScoreVoCollection componentscore;
	protected ims.core.admin.vo.CareContextRefVo carecontext;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
