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

	public DischargeDetailsWithAssessmentVo()
	{
	}
	public DischargeDetailsWithAssessmentVo(Integer id, int version)
	{
		super(id, version);
	}
	public DischargeDetailsWithAssessmentVo(ims.clinical.vo.beans.DischargeDetailsWithAssessmentVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.carecontext = bean.getCareContext() == null ? null : new ims.core.admin.vo.CareContextRefVo(new Integer(bean.getCareContext().getId()), bean.getCareContext().getVersion());
		this.dateofdischarge = bean.getDateOfDischarge() == null ? null : bean.getDateOfDischarge().buildDateTime();
		this.dischargemethod = bean.getDischargeMethod() == null ? null : ims.core.vo.lookups.DischargeMethod.buildLookup(bean.getDischargeMethod());
		this.dischargedestination = bean.getDischargeDestination() == null ? null : ims.coe.vo.lookups.DischargeDestination.buildLookup(bean.getDischargeDestination());
		this.dischargingward = bean.getDischargingWard() == null ? null : bean.getDischargingWard().buildVo();
		this.systeminformation = bean.getSystemInformation() == null ? null : bean.getSystemInformation().buildSystemInformation();
		this.initiatinghcp = bean.getInitiatingHCP() == null ? null : bean.getInitiatingHCP().buildVo();
		this.dischargeletterstatus = bean.getDischargeLetterStatus() == null ? null : ims.clinical.vo.lookups.DischargeLetterStatus.buildLookup(bean.getDischargeLetterStatus());
		this.hasnocomplications = bean.getHasNoComplications();
		this.hasnocomorbidities = bean.getHasNoComorbidities();
		this.dischargingconsultant = bean.getDischargingConsultant() == null ? null : bean.getDischargingConsultant().buildVo();
		this.secondarydischargingconsultant = bean.getSecondaryDischargingConsultant() == null ? null : bean.getSecondaryDischargingConsultant().buildVo();
		this.dischargingspecialty = bean.getDischargingSpecialty() == null ? null : ims.core.vo.lookups.Specialty.buildLookup(bean.getDischargingSpecialty());
		this.dischargesupplementaryletterstatus = bean.getDischargeSupplementaryLetterStatus() == null ? null : ims.clinical.vo.lookups.DischargeSupplementaryLetterStatus.buildLookup(bean.getDischargeSupplementaryLetterStatus());
		this.nurseenabledinstructions = bean.getNurseEnabledInstructions() == null ? null : bean.getNurseEnabledInstructions().buildVo();
		this.hasnodiagnosis = bean.getHasNoDiagnosis();
		this.methodofdischarge = bean.getMethodOfDischarge() == null ? null : ims.core.vo.lookups.MethodOfDischarge.buildLookup(bean.getMethodOfDischarge());
		this.isdiagnosiscomplete = bean.getIsDiagnosisComplete();
		this.patient = bean.getPatient() == null ? null : bean.getPatient().buildVo();
		this.patientassessment = bean.getPatientAssessment() == null ? null : bean.getPatientAssessment().buildVo();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.clinical.vo.beans.DischargeDetailsWithAssessmentVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.carecontext = bean.getCareContext() == null ? null : new ims.core.admin.vo.CareContextRefVo(new Integer(bean.getCareContext().getId()), bean.getCareContext().getVersion());
		this.dateofdischarge = bean.getDateOfDischarge() == null ? null : bean.getDateOfDischarge().buildDateTime();
		this.dischargemethod = bean.getDischargeMethod() == null ? null : ims.core.vo.lookups.DischargeMethod.buildLookup(bean.getDischargeMethod());
		this.dischargedestination = bean.getDischargeDestination() == null ? null : ims.coe.vo.lookups.DischargeDestination.buildLookup(bean.getDischargeDestination());
		this.dischargingward = bean.getDischargingWard() == null ? null : bean.getDischargingWard().buildVo(map);
		this.systeminformation = bean.getSystemInformation() == null ? null : bean.getSystemInformation().buildSystemInformation();
		this.initiatinghcp = bean.getInitiatingHCP() == null ? null : bean.getInitiatingHCP().buildVo(map);
		this.dischargeletterstatus = bean.getDischargeLetterStatus() == null ? null : ims.clinical.vo.lookups.DischargeLetterStatus.buildLookup(bean.getDischargeLetterStatus());
		this.hasnocomplications = bean.getHasNoComplications();
		this.hasnocomorbidities = bean.getHasNoComorbidities();
		this.dischargingconsultant = bean.getDischargingConsultant() == null ? null : bean.getDischargingConsultant().buildVo(map);
		this.secondarydischargingconsultant = bean.getSecondaryDischargingConsultant() == null ? null : bean.getSecondaryDischargingConsultant().buildVo(map);
		this.dischargingspecialty = bean.getDischargingSpecialty() == null ? null : ims.core.vo.lookups.Specialty.buildLookup(bean.getDischargingSpecialty());
		this.dischargesupplementaryletterstatus = bean.getDischargeSupplementaryLetterStatus() == null ? null : ims.clinical.vo.lookups.DischargeSupplementaryLetterStatus.buildLookup(bean.getDischargeSupplementaryLetterStatus());
		this.nurseenabledinstructions = bean.getNurseEnabledInstructions() == null ? null : bean.getNurseEnabledInstructions().buildVo(map);
		this.hasnodiagnosis = bean.getHasNoDiagnosis();
		this.methodofdischarge = bean.getMethodOfDischarge() == null ? null : ims.core.vo.lookups.MethodOfDischarge.buildLookup(bean.getMethodOfDischarge());
		this.isdiagnosiscomplete = bean.getIsDiagnosisComplete();
		this.patient = bean.getPatient() == null ? null : bean.getPatient().buildVo(map);
		this.patientassessment = bean.getPatientAssessment() == null ? null : bean.getPatientAssessment().buildVo(map);
	}
	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.DischargeDetailsWithAssessmentVoBean bean = null;
		if(map != null)
			bean = (ims.clinical.vo.beans.DischargeDetailsWithAssessmentVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.clinical.vo.beans.DischargeDetailsWithAssessmentVoBean();
			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("PATIENTASSESSMENT"))
			return getPatientAssessment();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getPatientAssessmentIsNotNull()
	{
		return this.patientassessment != null;
	}
	public ims.assessment.vo.PatientAssessmentVo getPatientAssessment()
	{
		return this.patientassessment;
	}
	public void setPatientAssessment(ims.assessment.vo.PatientAssessmentVo value)
	{
		this.isValidated = false;
		this.patientassessment = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.nurseenabledinstructions != null)
		{
			if(!this.nurseenabledinstructions.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.patientassessment != null)
		{
			if(!this.patientassessment.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.carecontext == null)
			listOfErrors.add("CareContext is mandatory");
		if(this.initiatinghcp == null)
			listOfErrors.add("InitiatingHCP is mandatory");
		if(this.dischargeletterstatus == null)
			listOfErrors.add("DischargeLetterStatus is mandatory");
		if(this.nurseenabledinstructions != null)
		{
			String[] listOfOtherErrors = this.nurseenabledinstructions.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.patientassessment != null)
		{
			String[] listOfOtherErrors = this.patientassessment.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		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;
	
		DischargeDetailsWithAssessmentVo clone = new DischargeDetailsWithAssessmentVo(this.id, this.version);
		
		clone.carecontext = this.carecontext;
		if(this.dateofdischarge == null)
			clone.dateofdischarge = null;
		else
			clone.dateofdischarge = (ims.framework.utils.DateTime)this.dateofdischarge.clone();
		if(this.dischargemethod == null)
			clone.dischargemethod = null;
		else
			clone.dischargemethod = (ims.core.vo.lookups.DischargeMethod)this.dischargemethod.clone();
		if(this.dischargedestination == null)
			clone.dischargedestination = null;
		else
			clone.dischargedestination = (ims.coe.vo.lookups.DischargeDestination)this.dischargedestination.clone();
		if(this.dischargingward == null)
			clone.dischargingward = null;
		else
			clone.dischargingward = (ims.core.vo.LocationLiteVo)this.dischargingward.clone();
		if(this.systeminformation == null)
			clone.systeminformation = null;
		else
			clone.systeminformation = (ims.vo.SystemInformation)this.systeminformation.clone();
		if(this.initiatinghcp == null)
			clone.initiatinghcp = null;
		else
			clone.initiatinghcp = (ims.core.vo.HcpLiteVo)this.initiatinghcp.clone();
		if(this.dischargeletterstatus == null)
			clone.dischargeletterstatus = null;
		else
			clone.dischargeletterstatus = (ims.clinical.vo.lookups.DischargeLetterStatus)this.dischargeletterstatus.clone();
		clone.hasnocomplications = this.hasnocomplications;
		clone.hasnocomorbidities = this.hasnocomorbidities;
		if(this.dischargingconsultant == null)
			clone.dischargingconsultant = null;
		else
			clone.dischargingconsultant = (ims.core.vo.HcpLiteVo)this.dischargingconsultant.clone();
		if(this.secondarydischargingconsultant == null)
			clone.secondarydischargingconsultant = null;
		else
			clone.secondarydischargingconsultant = (ims.core.vo.HcpLiteVo)this.secondarydischargingconsultant.clone();
		if(this.dischargingspecialty == null)
			clone.dischargingspecialty = null;
		else
			clone.dischargingspecialty = (ims.core.vo.lookups.Specialty)this.dischargingspecialty.clone();
		if(this.dischargesupplementaryletterstatus == null)
			clone.dischargesupplementaryletterstatus = null;
		else
			clone.dischargesupplementaryletterstatus = (ims.clinical.vo.lookups.DischargeSupplementaryLetterStatus)this.dischargesupplementaryletterstatus.clone();
		if(this.nurseenabledinstructions == null)
			clone.nurseenabledinstructions = null;
		else
			clone.nurseenabledinstructions = (ims.clinical.vo.NurseEnabledInstructionsVo)this.nurseenabledinstructions.clone();
		clone.hasnodiagnosis = this.hasnodiagnosis;
		if(this.methodofdischarge == null)
			clone.methodofdischarge = null;
		else
			clone.methodofdischarge = (ims.core.vo.lookups.MethodOfDischarge)this.methodofdischarge.clone();
		clone.isdiagnosiscomplete = this.isdiagnosiscomplete;
		if(this.patient == null)
			clone.patient = null;
		else
			clone.patient = (ims.core.vo.PatientShort)this.patient.clone();
		if(this.patientassessment == null)
			clone.patientassessment = null;
		else
			clone.patientassessment = (ims.assessment.vo.PatientAssessmentVo)this.patientassessment.clone();
		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 (!(DischargeDetailsWithAssessmentVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A DischargeDetailsWithAssessmentVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((DischargeDetailsWithAssessmentVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((DischargeDetailsWithAssessmentVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = super.countFieldsWithValue();
		if(this.patientassessment != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return super.countValueObjectFields() + 1;
	}
	protected ims.assessment.vo.PatientAssessmentVo patientassessment;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
