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

/**
 * Linked to core.clinical.PatientFamilyHistory business object (ID: 1003100056).
 */
public class FamilyHistoryVo extends ims.core.clinical.vo.PatientFamilyHistoryRefVo implements ims.vo.ImsCloneable, Comparable, ims.vo.interfaces.IClinicalCodingValue
{
	private static final long serialVersionUID = 1L;

	public FamilyHistoryVo()
	{
	}
	public FamilyHistoryVo(Integer id, int version)
	{
		super(id, version);
	}
	public FamilyHistoryVo(ims.clinical.vo.beans.FamilyHistoryVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.clinicalcontact = bean.getClinicalContact() == null ? null : bean.getClinicalContact().buildVo();
		this.relationship = bean.getRelationship() == null ? null : ims.core.vo.lookups.SupportNetworkRelationship.buildLookup(bean.getRelationship());
		this.relativename = bean.getRelativeName();
		this.relativedob = bean.getRelativeDOB() == null ? null : bean.getRelativeDOB().buildPartialDate();
		this.ageatonset = bean.getAgeAtOnset();
		this.relativeliving = bean.getRelativeLiving() == null ? null : ims.core.vo.lookups.YesNoUnknown.buildLookup(bean.getRelativeLiving());
		this.ageatdeath = bean.getAgeAtDeath();
		this.notes = bean.getNotes();
		this.diagnosis = bean.getDiagnosis() == null ? null : bean.getDiagnosis().buildVo();
		this.authoringinformation = bean.getAuthoringInformation() == null ? null : bean.getAuthoringInformation().buildVo();
		this.diagnosisdescription = bean.getDiagnosisDescription();
		this.patient = bean.getPatient() == null ? null : new ims.core.patient.vo.PatientRefVo(new Integer(bean.getPatient().getId()), bean.getPatient().getVersion());
		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.clinical.vo.beans.FamilyHistoryVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.clinicalcontact = bean.getClinicalContact() == null ? null : bean.getClinicalContact().buildVo(map);
		this.relationship = bean.getRelationship() == null ? null : ims.core.vo.lookups.SupportNetworkRelationship.buildLookup(bean.getRelationship());
		this.relativename = bean.getRelativeName();
		this.relativedob = bean.getRelativeDOB() == null ? null : bean.getRelativeDOB().buildPartialDate();
		this.ageatonset = bean.getAgeAtOnset();
		this.relativeliving = bean.getRelativeLiving() == null ? null : ims.core.vo.lookups.YesNoUnknown.buildLookup(bean.getRelativeLiving());
		this.ageatdeath = bean.getAgeAtDeath();
		this.notes = bean.getNotes();
		this.diagnosis = bean.getDiagnosis() == null ? null : bean.getDiagnosis().buildVo(map);
		this.authoringinformation = bean.getAuthoringInformation() == null ? null : bean.getAuthoringInformation().buildVo(map);
		this.diagnosisdescription = bean.getDiagnosisDescription();
		this.patient = bean.getPatient() == null ? null : new ims.core.patient.vo.PatientRefVo(new Integer(bean.getPatient().getId()), bean.getPatient().getVersion());
		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.clinical.vo.beans.FamilyHistoryVoBean bean = null;
		if(map != null)
			bean = (ims.clinical.vo.beans.FamilyHistoryVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.clinical.vo.beans.FamilyHistoryVoBean();
			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("CLINICALCONTACT"))
			return getClinicalContact();
		if(fieldName.equals("RELATIONSHIP"))
			return getRelationship();
		if(fieldName.equals("RELATIVENAME"))
			return getRelativeName();
		if(fieldName.equals("RELATIVEDOB"))
			return getRelativeDOB();
		if(fieldName.equals("AGEATONSET"))
			return getAgeAtOnset();
		if(fieldName.equals("RELATIVELIVING"))
			return getRelativeLiving();
		if(fieldName.equals("AGEATDEATH"))
			return getAgeAtDeath();
		if(fieldName.equals("NOTES"))
			return getNotes();
		if(fieldName.equals("DIAGNOSIS"))
			return getDiagnosis();
		if(fieldName.equals("AUTHORINGINFORMATION"))
			return getAuthoringInformation();
		if(fieldName.equals("DIAGNOSISDESCRIPTION"))
			return getDiagnosisDescription();
		if(fieldName.equals("PATIENT"))
			return getPatient();
		if(fieldName.equals("CARECONTEXT"))
			return getCareContext();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getClinicalContactIsNotNull()
	{
		return this.clinicalcontact != null;
	}
	public ims.core.vo.ClinicalContactShortVo getClinicalContact()
	{
		return this.clinicalcontact;
	}
	public void setClinicalContact(ims.core.vo.ClinicalContactShortVo value)
	{
		this.isValidated = false;
		this.clinicalcontact = value;
	}
	public boolean getRelationshipIsNotNull()
	{
		return this.relationship != null;
	}
	public ims.core.vo.lookups.SupportNetworkRelationship getRelationship()
	{
		return this.relationship;
	}
	public void setRelationship(ims.core.vo.lookups.SupportNetworkRelationship value)
	{
		this.isValidated = false;
		this.relationship = value;
	}
	public boolean getRelativeNameIsNotNull()
	{
		return this.relativename != null;
	}
	public String getRelativeName()
	{
		return this.relativename;
	}
	public static int getRelativeNameMaxLength()
	{
		return 100;
	}
	public void setRelativeName(String value)
	{
		this.isValidated = false;
		this.relativename = value;
	}
	public boolean getRelativeDOBIsNotNull()
	{
		return this.relativedob != null;
	}
	public ims.framework.utils.PartialDate getRelativeDOB()
	{
		return this.relativedob;
	}
	public void setRelativeDOB(ims.framework.utils.PartialDate value)
	{
		this.isValidated = false;
		this.relativedob = value;
	}
	public boolean getAgeAtOnsetIsNotNull()
	{
		return this.ageatonset != null;
	}
	public Integer getAgeAtOnset()
	{
		return this.ageatonset;
	}
	public void setAgeAtOnset(Integer value)
	{
		this.isValidated = false;
		this.ageatonset = value;
	}
	public boolean getRelativeLivingIsNotNull()
	{
		return this.relativeliving != null;
	}
	public ims.core.vo.lookups.YesNoUnknown getRelativeLiving()
	{
		return this.relativeliving;
	}
	public void setRelativeLiving(ims.core.vo.lookups.YesNoUnknown value)
	{
		this.isValidated = false;
		this.relativeliving = value;
	}
	public boolean getAgeAtDeathIsNotNull()
	{
		return this.ageatdeath != null;
	}
	public Integer getAgeAtDeath()
	{
		return this.ageatdeath;
	}
	public void setAgeAtDeath(Integer value)
	{
		this.isValidated = false;
		this.ageatdeath = value;
	}
	public boolean getNotesIsNotNull()
	{
		return this.notes != null;
	}
	public String getNotes()
	{
		return this.notes;
	}
	public static int getNotesMaxLength()
	{
		return 500;
	}
	public void setNotes(String value)
	{
		this.isValidated = false;
		this.notes = value;
	}
	public boolean getDiagnosisIsNotNull()
	{
		return this.diagnosis != null;
	}
	public ims.core.vo.DiagLiteVo getDiagnosis()
	{
		return this.diagnosis;
	}
	public void setDiagnosis(ims.core.vo.DiagLiteVo value)
	{
		this.isValidated = false;
		this.diagnosis = value;
	}
	public boolean getAuthoringInformationIsNotNull()
	{
		return this.authoringinformation != null;
	}
	public ims.core.vo.AuthoringInformationVo getAuthoringInformation()
	{
		return this.authoringinformation;
	}
	public void setAuthoringInformation(ims.core.vo.AuthoringInformationVo value)
	{
		this.isValidated = false;
		this.authoringinformation = value;
	}
	public boolean getDiagnosisDescriptionIsNotNull()
	{
		return this.diagnosisdescription != null;
	}
	public String getDiagnosisDescription()
	{
		return this.diagnosisdescription;
	}
	public static int getDiagnosisDescriptionMaxLength()
	{
		return 255;
	}
	public void setDiagnosisDescription(String value)
	{
		this.isValidated = false;
		this.diagnosisdescription = value;
	}
	public boolean getPatientIsNotNull()
	{
		return this.patient != null;
	}
	public ims.core.patient.vo.PatientRefVo getPatient()
	{
		return this.patient;
	}
	public void setPatient(ims.core.patient.vo.PatientRefVo value)
	{
		this.isValidated = false;
		this.patient = 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;
	}
	/**
	* IClinicalCoding methods
	*/
	public ims.vo.ValueObject getIClinicalCodingValue() 
	{
		return this.diagnosis;
	}
	public void setIClinicalCodingValue(ims.vo.ValueObject vo) 
	{
		this.diagnosis = (ims.core.vo.DiagLiteVo) vo;
	}
	public String getIClinicalCodingValueDescription() 
	{
		return this.diagnosisdescription;
	}
	public void setIClinicalCodingValueDescription(String value) 
	{
		this.diagnosisdescription = value;
	}		
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.diagnosis != null)
		{
			if(!this.diagnosis.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.authoringinformation != null)
		{
			if(!this.authoringinformation.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.relationship == null)
			listOfErrors.add("Relationship is mandatory");
		if(this.relativename != null)
			if(this.relativename.length() > 100)
				listOfErrors.add("The length of the field [relativename] in the value object [ims.clinical.vo.FamilyHistoryVo] is too big. It should be less or equal to 100");
		if(this.notes != null)
			if(this.notes.length() > 500)
				listOfErrors.add("The length of the field [notes] in the value object [ims.clinical.vo.FamilyHistoryVo] is too big. It should be less or equal to 500");
		if(this.diagnosis != null)
		{
			String[] listOfOtherErrors = this.diagnosis.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.authoringinformation != null)
		{
			String[] listOfOtherErrors = this.authoringinformation.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.diagnosisdescription == null || this.diagnosisdescription.length() == 0)
			listOfErrors.add("Diagnosis description is mandatory.");
		else if(this.diagnosisdescription.length() > 255)
			listOfErrors.add("The length of the field [diagnosisdescription] in the value object [ims.clinical.vo.FamilyHistoryVo] is too big. It should be less or equal to 255");
		if(this.patient == null)
			listOfErrors.add("Patient 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;
	
		FamilyHistoryVo clone = new FamilyHistoryVo(this.id, this.version);
		
		if(this.clinicalcontact == null)
			clone.clinicalcontact = null;
		else
			clone.clinicalcontact = (ims.core.vo.ClinicalContactShortVo)this.clinicalcontact.clone();
		if(this.relationship == null)
			clone.relationship = null;
		else
			clone.relationship = (ims.core.vo.lookups.SupportNetworkRelationship)this.relationship.clone();
		clone.relativename = this.relativename;
		if(this.relativedob == null)
			clone.relativedob = null;
		else
			clone.relativedob = (ims.framework.utils.PartialDate)this.relativedob.clone();
		clone.ageatonset = this.ageatonset;
		if(this.relativeliving == null)
			clone.relativeliving = null;
		else
			clone.relativeliving = (ims.core.vo.lookups.YesNoUnknown)this.relativeliving.clone();
		clone.ageatdeath = this.ageatdeath;
		clone.notes = this.notes;
		if(this.diagnosis == null)
			clone.diagnosis = null;
		else
			clone.diagnosis = (ims.core.vo.DiagLiteVo)this.diagnosis.clone();
		if(this.authoringinformation == null)
			clone.authoringinformation = null;
		else
			clone.authoringinformation = (ims.core.vo.AuthoringInformationVo)this.authoringinformation.clone();
		clone.diagnosisdescription = this.diagnosisdescription;
		clone.patient = this.patient;
		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 (!(FamilyHistoryVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A FamilyHistoryVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		FamilyHistoryVo compareObj = (FamilyHistoryVo)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getAuthoringInformation() == null && compareObj.getAuthoringInformation() != null)
				return -1;
			if(this.getAuthoringInformation() != null && compareObj.getAuthoringInformation() == null)
				return 1;
			if(this.getAuthoringInformation() != null && compareObj.getAuthoringInformation() != null)
				retVal = this.getAuthoringInformation().compareTo(compareObj.getAuthoringInformation());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.clinicalcontact != null)
			count++;
		if(this.relationship != null)
			count++;
		if(this.relativename != null)
			count++;
		if(this.relativedob != null)
			count++;
		if(this.ageatonset != null)
			count++;
		if(this.relativeliving != null)
			count++;
		if(this.ageatdeath != null)
			count++;
		if(this.notes != null)
			count++;
		if(this.diagnosis != null)
			count++;
		if(this.authoringinformation != null)
			count++;
		if(this.diagnosisdescription != null)
			count++;
		if(this.patient != null)
			count++;
		if(this.carecontext != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 13;
	}
	protected ims.core.vo.ClinicalContactShortVo clinicalcontact;
	protected ims.core.vo.lookups.SupportNetworkRelationship relationship;
	protected String relativename;
	protected ims.framework.utils.PartialDate relativedob;
	protected Integer ageatonset;
	protected ims.core.vo.lookups.YesNoUnknown relativeliving;
	protected Integer ageatdeath;
	protected String notes;
	protected ims.core.vo.DiagLiteVo diagnosis;
	protected ims.core.vo.AuthoringInformationVo authoringinformation;
	protected String diagnosisdescription;
	protected ims.core.patient.vo.PatientRefVo patient;
	protected ims.core.admin.vo.CareContextRefVo carecontext;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
