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

/**
 * Linked to Oncology.InternalReferral business object (ID: 1074100041).
 */
public class InternalReferralVo extends ims.oncology.vo.InternalReferralRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public InternalReferralVo()
	{
	}
	public InternalReferralVo(Integer id, int version)
	{
		super(id, version);
	}
	public InternalReferralVo(ims.oncology.vo.beans.InternalReferralVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.status = bean.getStatus() == null ? null : ims.core.vo.lookups.PreActiveActiveInactiveStatus.buildLookup(bean.getStatus());
		this.internalreferraloutcome = bean.getInternalReferralOutcome() == null ? null : bean.getInternalReferralOutcome().buildVo();
		this.referraldate = bean.getReferralDate() == null ? null : bean.getReferralDate().buildDate();
		this.referraltype = bean.getReferralType() == null ? null : ims.oncology.vo.lookups.InternalReferralTypeAndReason.buildLookup(bean.getReferralType());
		this.referralsource = bean.getReferralSource() == null ? null : ims.oncology.vo.lookups.InternalReferralSource.buildLookup(bean.getReferralSource());
		this.referredby = bean.getReferredBy() == null ? null : bean.getReferredBy().buildVo();
		this.diagnosistext = bean.getDiagnosisText();
		this.planneddischargedate = bean.getPlannedDischargeDate() == null ? null : bean.getPlannedDischargeDate().buildDate();
		this.treatmentstartdate = bean.getTreatmentStartDate() == null ? null : bean.getTreatmentStartDate().buildDate();
		this.treatmentenddate = bean.getTreatmentEndDate() == null ? null : bean.getTreatmentEndDate().buildDate();
		this.comments = bean.getComments();
		this.referralreason = ims.oncology.vo.lookups.InternalReferralTypeAndReasonCollection.buildFromBeanCollection(bean.getReferralReason());
		this.patient = bean.getPatient() == null ? null : new ims.core.patient.vo.PatientRefVo(new Integer(bean.getPatient().getId()), bean.getPatient().getVersion());
		this.episodeofcare = bean.getEpisodeOfCare() == null ? null : bean.getEpisodeOfCare().buildVo();
		this.referralseen = bean.getReferralSeen();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.oncology.vo.beans.InternalReferralVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.status = bean.getStatus() == null ? null : ims.core.vo.lookups.PreActiveActiveInactiveStatus.buildLookup(bean.getStatus());
		this.internalreferraloutcome = bean.getInternalReferralOutcome() == null ? null : bean.getInternalReferralOutcome().buildVo(map);
		this.referraldate = bean.getReferralDate() == null ? null : bean.getReferralDate().buildDate();
		this.referraltype = bean.getReferralType() == null ? null : ims.oncology.vo.lookups.InternalReferralTypeAndReason.buildLookup(bean.getReferralType());
		this.referralsource = bean.getReferralSource() == null ? null : ims.oncology.vo.lookups.InternalReferralSource.buildLookup(bean.getReferralSource());
		this.referredby = bean.getReferredBy() == null ? null : bean.getReferredBy().buildVo(map);
		this.diagnosistext = bean.getDiagnosisText();
		this.planneddischargedate = bean.getPlannedDischargeDate() == null ? null : bean.getPlannedDischargeDate().buildDate();
		this.treatmentstartdate = bean.getTreatmentStartDate() == null ? null : bean.getTreatmentStartDate().buildDate();
		this.treatmentenddate = bean.getTreatmentEndDate() == null ? null : bean.getTreatmentEndDate().buildDate();
		this.comments = bean.getComments();
		this.referralreason = ims.oncology.vo.lookups.InternalReferralTypeAndReasonCollection.buildFromBeanCollection(bean.getReferralReason());
		this.patient = bean.getPatient() == null ? null : new ims.core.patient.vo.PatientRefVo(new Integer(bean.getPatient().getId()), bean.getPatient().getVersion());
		this.episodeofcare = bean.getEpisodeOfCare() == null ? null : bean.getEpisodeOfCare().buildVo(map);
		this.referralseen = bean.getReferralSeen();
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.oncology.vo.beans.InternalReferralVoBean bean = null;
		if(map != null)
			bean = (ims.oncology.vo.beans.InternalReferralVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.oncology.vo.beans.InternalReferralVoBean();
			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("STATUS"))
			return getStatus();
		if(fieldName.equals("INTERNALREFERRALOUTCOME"))
			return getInternalReferralOutcome();
		if(fieldName.equals("REFERRALDATE"))
			return getReferralDate();
		if(fieldName.equals("REFERRALTYPE"))
			return getReferralType();
		if(fieldName.equals("REFERRALSOURCE"))
			return getReferralSource();
		if(fieldName.equals("REFERREDBY"))
			return getReferredBy();
		if(fieldName.equals("DIAGNOSISTEXT"))
			return getDiagnosisText();
		if(fieldName.equals("PLANNEDDISCHARGEDATE"))
			return getPlannedDischargeDate();
		if(fieldName.equals("TREATMENTSTARTDATE"))
			return getTreatmentStartDate();
		if(fieldName.equals("TREATMENTENDDATE"))
			return getTreatmentEndDate();
		if(fieldName.equals("COMMENTS"))
			return getComments();
		if(fieldName.equals("REFERRALREASON"))
			return getReferralReason();
		if(fieldName.equals("PATIENT"))
			return getPatient();
		if(fieldName.equals("EPISODEOFCARE"))
			return getEpisodeOfCare();
		if(fieldName.equals("REFERRALSEEN"))
			return getReferralSeen();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getStatusIsNotNull()
	{
		return this.status != null;
	}
	public ims.core.vo.lookups.PreActiveActiveInactiveStatus getStatus()
	{
		return this.status;
	}
	public void setStatus(ims.core.vo.lookups.PreActiveActiveInactiveStatus value)
	{
		this.isValidated = false;
		this.status = value;
	}
	public boolean getInternalReferralOutcomeIsNotNull()
	{
		return this.internalreferraloutcome != null;
	}
	public ims.oncology.vo.InternalReferralOutcomeVo getInternalReferralOutcome()
	{
		return this.internalreferraloutcome;
	}
	public void setInternalReferralOutcome(ims.oncology.vo.InternalReferralOutcomeVo value)
	{
		this.isValidated = false;
		this.internalreferraloutcome = value;
	}
	public boolean getReferralDateIsNotNull()
	{
		return this.referraldate != null;
	}
	public ims.framework.utils.Date getReferralDate()
	{
		return this.referraldate;
	}
	public void setReferralDate(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.referraldate = value;
	}
	public boolean getReferralTypeIsNotNull()
	{
		return this.referraltype != null;
	}
	public ims.oncology.vo.lookups.InternalReferralTypeAndReason getReferralType()
	{
		return this.referraltype;
	}
	public void setReferralType(ims.oncology.vo.lookups.InternalReferralTypeAndReason value)
	{
		this.isValidated = false;
		this.referraltype = value;
	}
	public boolean getReferralSourceIsNotNull()
	{
		return this.referralsource != null;
	}
	public ims.oncology.vo.lookups.InternalReferralSource getReferralSource()
	{
		return this.referralsource;
	}
	public void setReferralSource(ims.oncology.vo.lookups.InternalReferralSource value)
	{
		this.isValidated = false;
		this.referralsource = value;
	}
	public boolean getReferredByIsNotNull()
	{
		return this.referredby != null;
	}
	public ims.core.vo.HcpLiteVo getReferredBy()
	{
		return this.referredby;
	}
	public void setReferredBy(ims.core.vo.HcpLiteVo value)
	{
		this.isValidated = false;
		this.referredby = value;
	}
	public boolean getDiagnosisTextIsNotNull()
	{
		return this.diagnosistext != null;
	}
	public String getDiagnosisText()
	{
		return this.diagnosistext;
	}
	public static int getDiagnosisTextMaxLength()
	{
		return 255;
	}
	public void setDiagnosisText(String value)
	{
		this.isValidated = false;
		this.diagnosistext = value;
	}
	public boolean getPlannedDischargeDateIsNotNull()
	{
		return this.planneddischargedate != null;
	}
	public ims.framework.utils.Date getPlannedDischargeDate()
	{
		return this.planneddischargedate;
	}
	public void setPlannedDischargeDate(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.planneddischargedate = value;
	}
	public boolean getTreatmentStartDateIsNotNull()
	{
		return this.treatmentstartdate != null;
	}
	public ims.framework.utils.Date getTreatmentStartDate()
	{
		return this.treatmentstartdate;
	}
	public void setTreatmentStartDate(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.treatmentstartdate = value;
	}
	public boolean getTreatmentEndDateIsNotNull()
	{
		return this.treatmentenddate != null;
	}
	public ims.framework.utils.Date getTreatmentEndDate()
	{
		return this.treatmentenddate;
	}
	public void setTreatmentEndDate(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.treatmentenddate = value;
	}
	public boolean getCommentsIsNotNull()
	{
		return this.comments != null;
	}
	public String getComments()
	{
		return this.comments;
	}
	public static int getCommentsMaxLength()
	{
		return 1000;
	}
	public void setComments(String value)
	{
		this.isValidated = false;
		this.comments = value;
	}
	public boolean getReferralReasonIsNotNull()
	{
		return this.referralreason != null;
	}
	public ims.oncology.vo.lookups.InternalReferralTypeAndReasonCollection getReferralReason()
	{
		return this.referralreason;
	}
	public void setReferralReason(ims.oncology.vo.lookups.InternalReferralTypeAndReasonCollection value)
	{
		this.isValidated = false;
		this.referralreason = 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 getEpisodeOfCareIsNotNull()
	{
		return this.episodeofcare != null;
	}
	public ims.core.vo.EpisodeOfCareForInternalReferralVo getEpisodeOfCare()
	{
		return this.episodeofcare;
	}
	public void setEpisodeOfCare(ims.core.vo.EpisodeOfCareForInternalReferralVo value)
	{
		this.isValidated = false;
		this.episodeofcare = value;
	}
	public boolean getReferralSeenIsNotNull()
	{
		return this.referralseen != null;
	}
	public Boolean getReferralSeen()
	{
		return this.referralseen;
	}
	public void setReferralSeen(Boolean value)
	{
		this.isValidated = false;
		this.referralseen = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.internalreferraloutcome != null)
		{
			if(!this.internalreferraloutcome.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.status == null)
			listOfErrors.add("Status is mandatory");
		if(this.internalreferraloutcome != null)
		{
			String[] listOfOtherErrors = this.internalreferraloutcome.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.referraldate == null)
			listOfErrors.add("ReferralDate is mandatory");
		if(this.referraltype == null)
			listOfErrors.add("ReferralType is mandatory");
		if(this.referralsource == null)
			listOfErrors.add("ReferralSource is mandatory");
		if(this.referredby == null)
			listOfErrors.add("ReferredBy is mandatory");
		if(this.diagnosistext == null || this.diagnosistext.length() == 0)
			listOfErrors.add("Current Reason for Treatment is mandatory");
		else if(this.diagnosistext.length() > 255)
			listOfErrors.add("The length of the field [diagnosistext] in the value object [ims.oncology.vo.InternalReferralVo] is too big. It should be less or equal to 255");
		if(this.comments != null)
			if(this.comments.length() > 1000)
				listOfErrors.add("The length of the field [comments] in the value object [ims.oncology.vo.InternalReferralVo] is too big. It should be less or equal to 1000");
		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;
	
		InternalReferralVo clone = new InternalReferralVo(this.id, this.version);
		
		if(this.status == null)
			clone.status = null;
		else
			clone.status = (ims.core.vo.lookups.PreActiveActiveInactiveStatus)this.status.clone();
		if(this.internalreferraloutcome == null)
			clone.internalreferraloutcome = null;
		else
			clone.internalreferraloutcome = (ims.oncology.vo.InternalReferralOutcomeVo)this.internalreferraloutcome.clone();
		if(this.referraldate == null)
			clone.referraldate = null;
		else
			clone.referraldate = (ims.framework.utils.Date)this.referraldate.clone();
		if(this.referraltype == null)
			clone.referraltype = null;
		else
			clone.referraltype = (ims.oncology.vo.lookups.InternalReferralTypeAndReason)this.referraltype.clone();
		if(this.referralsource == null)
			clone.referralsource = null;
		else
			clone.referralsource = (ims.oncology.vo.lookups.InternalReferralSource)this.referralsource.clone();
		if(this.referredby == null)
			clone.referredby = null;
		else
			clone.referredby = (ims.core.vo.HcpLiteVo)this.referredby.clone();
		clone.diagnosistext = this.diagnosistext;
		if(this.planneddischargedate == null)
			clone.planneddischargedate = null;
		else
			clone.planneddischargedate = (ims.framework.utils.Date)this.planneddischargedate.clone();
		if(this.treatmentstartdate == null)
			clone.treatmentstartdate = null;
		else
			clone.treatmentstartdate = (ims.framework.utils.Date)this.treatmentstartdate.clone();
		if(this.treatmentenddate == null)
			clone.treatmentenddate = null;
		else
			clone.treatmentenddate = (ims.framework.utils.Date)this.treatmentenddate.clone();
		clone.comments = this.comments;
		if(this.referralreason == null)
			clone.referralreason = null;
		else
			clone.referralreason = (ims.oncology.vo.lookups.InternalReferralTypeAndReasonCollection)this.referralreason.clone();
		clone.patient = this.patient;
		if(this.episodeofcare == null)
			clone.episodeofcare = null;
		else
			clone.episodeofcare = (ims.core.vo.EpisodeOfCareForInternalReferralVo)this.episodeofcare.clone();
		clone.referralseen = this.referralseen;
		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 (!(InternalReferralVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A InternalReferralVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((InternalReferralVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((InternalReferralVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.status != null)
			count++;
		if(this.internalreferraloutcome != null)
			count++;
		if(this.referraldate != null)
			count++;
		if(this.referraltype != null)
			count++;
		if(this.referralsource != null)
			count++;
		if(this.referredby != null)
			count++;
		if(this.diagnosistext != null)
			count++;
		if(this.planneddischargedate != null)
			count++;
		if(this.treatmentstartdate != null)
			count++;
		if(this.treatmentenddate != null)
			count++;
		if(this.comments != null)
			count++;
		if(this.referralreason != null)
			count++;
		if(this.patient != null)
			count++;
		if(this.episodeofcare != null)
			count++;
		if(this.referralseen != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 15;
	}
	protected ims.core.vo.lookups.PreActiveActiveInactiveStatus status;
	protected ims.oncology.vo.InternalReferralOutcomeVo internalreferraloutcome;
	protected ims.framework.utils.Date referraldate;
	protected ims.oncology.vo.lookups.InternalReferralTypeAndReason referraltype;
	protected ims.oncology.vo.lookups.InternalReferralSource referralsource;
	protected ims.core.vo.HcpLiteVo referredby;
	protected String diagnosistext;
	protected ims.framework.utils.Date planneddischargedate;
	protected ims.framework.utils.Date treatmentstartdate;
	protected ims.framework.utils.Date treatmentenddate;
	protected String comments;
	protected ims.oncology.vo.lookups.InternalReferralTypeAndReasonCollection referralreason;
	protected ims.core.patient.vo.PatientRefVo patient;
	protected ims.core.vo.EpisodeOfCareForInternalReferralVo episodeofcare;
	protected Boolean referralseen;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
