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

/**
 * Linked to OCRR.OrderingResults.OcsOrderSession business object (ID: 1070100000).
 */
public class NewResultOcsOrderVo extends ims.ocrr.vo.OcsOrderShortVo implements ims.vo.ImsCloneable, Comparable, ims.vo.interfaces.IQuestionNotes
{
	private static final long serialVersionUID = 1L;

	public NewResultOcsOrderVo()
	{
	}
	public NewResultOcsOrderVo(Integer id, int version)
	{
		super(id, version);
	}
	public NewResultOcsOrderVo(ims.ocrr.vo.beans.NewResultOcsOrderVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.clinicalcontact = bean.getClinicalContact() == null ? null : new ims.core.admin.vo.ClinicalContactRefVo(new Integer(bean.getClinicalContact().getId()), bean.getClinicalContact().getVersion());
		this.patient = bean.getPatient() == null ? null : bean.getPatient().buildVo();
		this.orderedby = bean.getOrderedBy() == null ? null : bean.getOrderedBy().buildVo();
		this.responsibleclinician = bean.getResponsibleClinician() == null ? null : bean.getResponsibleClinician().buildVo();
		this.responsiblegp = bean.getResponsibleGp() == null ? null : bean.getResponsibleGp().buildVo();
		this.patientlocation = bean.getPatientLocation() == null ? null : bean.getPatientLocation().buildVo();
		this.patientclinic = bean.getPatientClinic() == null ? null : bean.getPatientClinic().buildVo();
		this.additclinnotes = bean.getAdditClinNotes();
		this.sysinfo = bean.getSysInfo() == null ? null : bean.getSysInfo().buildSystemInformation();
		this.carecontext = bean.getCareContext() == null ? null : bean.getCareContext().buildVo();
		this.orderinghospital = bean.getOrderingHospital() == null ? null : new ims.core.resource.place.vo.LocSiteRefVo(new Integer(bean.getOrderingHospital().getId()), bean.getOrderingHospital().getVersion());
		this.outpatientdept = bean.getOutpatientDept() == null ? null : bean.getOutpatientDept().buildVo();
		this.authorisationorderstatus = bean.getAuthorisationOrderStatus() == null ? null : ims.ocrr.vo.lookups.AuthorisationOrderStatus.buildLookup(bean.getAuthorisationOrderStatus());
		this.clinicalinfo = bean.getClinicalInfo() == null ? null : bean.getClinicalInfo().buildVo();
		this.summaryclinicalinformation = bean.getSummaryClinicalInformation();
		this.investigations = ims.ocrr.vo.OrderInvestigationForNewResultOcsOrderVoCollection.buildFromBeanCollection(bean.getInvestigations());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.ocrr.vo.beans.NewResultOcsOrderVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.clinicalcontact = bean.getClinicalContact() == null ? null : new ims.core.admin.vo.ClinicalContactRefVo(new Integer(bean.getClinicalContact().getId()), bean.getClinicalContact().getVersion());
		this.patient = bean.getPatient() == null ? null : bean.getPatient().buildVo(map);
		this.orderedby = bean.getOrderedBy() == null ? null : bean.getOrderedBy().buildVo(map);
		this.responsibleclinician = bean.getResponsibleClinician() == null ? null : bean.getResponsibleClinician().buildVo(map);
		this.responsiblegp = bean.getResponsibleGp() == null ? null : bean.getResponsibleGp().buildVo(map);
		this.patientlocation = bean.getPatientLocation() == null ? null : bean.getPatientLocation().buildVo(map);
		this.patientclinic = bean.getPatientClinic() == null ? null : bean.getPatientClinic().buildVo(map);
		this.additclinnotes = bean.getAdditClinNotes();
		this.sysinfo = bean.getSysInfo() == null ? null : bean.getSysInfo().buildSystemInformation();
		this.carecontext = bean.getCareContext() == null ? null : bean.getCareContext().buildVo(map);
		this.orderinghospital = bean.getOrderingHospital() == null ? null : new ims.core.resource.place.vo.LocSiteRefVo(new Integer(bean.getOrderingHospital().getId()), bean.getOrderingHospital().getVersion());
		this.outpatientdept = bean.getOutpatientDept() == null ? null : bean.getOutpatientDept().buildVo(map);
		this.authorisationorderstatus = bean.getAuthorisationOrderStatus() == null ? null : ims.ocrr.vo.lookups.AuthorisationOrderStatus.buildLookup(bean.getAuthorisationOrderStatus());
		this.clinicalinfo = bean.getClinicalInfo() == null ? null : bean.getClinicalInfo().buildVo(map);
		this.summaryclinicalinformation = bean.getSummaryClinicalInformation();
		this.investigations = ims.ocrr.vo.OrderInvestigationForNewResultOcsOrderVoCollection.buildFromBeanCollection(bean.getInvestigations());
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.ocrr.vo.beans.NewResultOcsOrderVoBean bean = null;
		if(map != null)
			bean = (ims.ocrr.vo.beans.NewResultOcsOrderVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.ocrr.vo.beans.NewResultOcsOrderVoBean();
			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("CLINICALINFO"))
			return getClinicalInfo();
		if(fieldName.equals("SUMMARYCLINICALINFORMATION"))
			return getSummaryClinicalInformation();
		if(fieldName.equals("INVESTIGATIONS"))
			return getInvestigations();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getClinicalInfoIsNotNull()
	{
		return this.clinicalinfo != null;
	}
	public ims.ocrr.vo.OcsQASessionVo getClinicalInfo()
	{
		return this.clinicalinfo;
	}
	public void setClinicalInfo(ims.ocrr.vo.OcsQASessionVo value)
	{
		this.isValidated = false;
		this.clinicalinfo = value;
	}
	public boolean getSummaryClinicalInformationIsNotNull()
	{
		return this.summaryclinicalinformation != null;
	}
	public String getSummaryClinicalInformation()
	{
		return this.summaryclinicalinformation;
	}
	public static int getSummaryClinicalInformationMaxLength()
	{
		return 2000;
	}
	public void setSummaryClinicalInformation(String value)
	{
		this.isValidated = false;
		this.summaryclinicalinformation = value;
	}
	public boolean getInvestigationsIsNotNull()
	{
		return this.investigations != null;
	}
	public ims.ocrr.vo.OrderInvestigationForNewResultOcsOrderVoCollection getInvestigations()
	{
		return this.investigations;
	}
	public void setInvestigations(ims.ocrr.vo.OrderInvestigationForNewResultOcsOrderVoCollection value)
	{
		this.isValidated = false;
		this.investigations = value;
	}
	/**
	* IQuestionNotes Interface methods
	*/
	public String[] getReOrderMessages() 
	{
		if(investigations == null)
				return null;
			
		java.util.ArrayList<String> messages = new java.util.ArrayList<String>();
	
		for(ims.ocrr.vo.OrderInvestigationForNewResultOcsOrderVo investigation : investigations)
		{
			if(investigation == null)
				continue;
				
			if(investigation.getReorderReason() != null && investigation.getReorderReason().length() > 0)
			{
				messages.add("<b>" + investigation.getInvestigation().getInvestigationIndex().getName() + "</b> : " + investigation.getReorderReason());
			}
		}
			
		if(messages.size() == 0)
			return null;
			
		java.util.Collections.sort(messages, new java.util.Comparator<String>() 
											{
												public int compare(String strA, String strB) 
												{
													return strA.compareToIgnoreCase(strB);
												}
											});
			
		String[] messagesArray = new String[messages.size()];
		messages.toArray(messagesArray);
			
		return messagesArray;
	
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.clinicalinfo != null)
		{
			if(!this.clinicalinfo.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.patient == null)
			listOfErrors.add("Patient is mandatory");
		if(this.clinicalinfo != null)
		{
			String[] listOfOtherErrors = this.clinicalinfo.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.summaryclinicalinformation != null)
			if(this.summaryclinicalinformation.length() > 2000)
				listOfErrors.add("The length of the field [summaryclinicalinformation] in the value object [ims.ocrr.vo.NewResultOcsOrderVo] is too big. It should be less or equal to 2000");
		if(this.investigations == null || this.investigations.size() == 0)
			listOfErrors.add("Investigations are 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;
	
		NewResultOcsOrderVo clone = new NewResultOcsOrderVo(this.id, this.version);
		
		clone.clinicalcontact = this.clinicalcontact;
		if(this.patient == null)
			clone.patient = null;
		else
			clone.patient = (ims.core.vo.PatientShort)this.patient.clone();
		if(this.orderedby == null)
			clone.orderedby = null;
		else
			clone.orderedby = (ims.core.vo.MemberOfStaffLiteVo)this.orderedby.clone();
		if(this.responsibleclinician == null)
			clone.responsibleclinician = null;
		else
			clone.responsibleclinician = (ims.core.vo.HcpLiteVo)this.responsibleclinician.clone();
		if(this.responsiblegp == null)
			clone.responsiblegp = null;
		else
			clone.responsiblegp = (ims.core.vo.GpLiteVo)this.responsiblegp.clone();
		if(this.patientlocation == null)
			clone.patientlocation = null;
		else
			clone.patientlocation = (ims.core.vo.LocationLiteVo)this.patientlocation.clone();
		if(this.patientclinic == null)
			clone.patientclinic = null;
		else
			clone.patientclinic = (ims.core.vo.ClinicLiteVo)this.patientclinic.clone();
		clone.additclinnotes = this.additclinnotes;
		if(this.sysinfo == null)
			clone.sysinfo = null;
		else
			clone.sysinfo = (ims.vo.SystemInformation)this.sysinfo.clone();
		if(this.carecontext == null)
			clone.carecontext = null;
		else
			clone.carecontext = (ims.core.vo.CareContextPasVo)this.carecontext.clone();
		clone.orderinghospital = this.orderinghospital;
		if(this.outpatientdept == null)
			clone.outpatientdept = null;
		else
			clone.outpatientdept = (ims.core.vo.LocationLiteVo)this.outpatientdept.clone();
		if(this.authorisationorderstatus == null)
			clone.authorisationorderstatus = null;
		else
			clone.authorisationorderstatus = (ims.ocrr.vo.lookups.AuthorisationOrderStatus)this.authorisationorderstatus.clone();
		if(this.clinicalinfo == null)
			clone.clinicalinfo = null;
		else
			clone.clinicalinfo = (ims.ocrr.vo.OcsQASessionVo)this.clinicalinfo.clone();
		clone.summaryclinicalinformation = this.summaryclinicalinformation;
		if(this.investigations == null)
			clone.investigations = null;
		else
			clone.investigations = (ims.ocrr.vo.OrderInvestigationForNewResultOcsOrderVoCollection)this.investigations.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 (!(NewResultOcsOrderVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A NewResultOcsOrderVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((NewResultOcsOrderVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((NewResultOcsOrderVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = super.countFieldsWithValue();
		if(this.clinicalinfo != null)
			count++;
		if(this.summaryclinicalinformation != null)
			count++;
		if(this.investigations != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return super.countValueObjectFields() + 3;
	}
	protected ims.ocrr.vo.OcsQASessionVo clinicalinfo;
	protected String summaryclinicalinformation;
	protected ims.ocrr.vo.OrderInvestigationForNewResultOcsOrderVoCollection investigations;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
