/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/ValueObjects/src/ims/ocrr/vo/OrderSpecimenVo.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.OrderSpecimen business object (ID: 1070100010).
 */
public class OrderSpecimenVo extends ims.ocrr.orderingresults.vo.OrderSpecimenRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public OrderSpecimenVo()
	{
	}
	public OrderSpecimenVo(Integer id, int version)
	{
		super(id, version);
	}
	public OrderSpecimenVo(ims.ocrr.vo.beans.OrderSpecimenVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.colldatetimeplacer = bean.getCollDateTimePlacer() == null ? null : bean.getCollDateTimePlacer().buildDateTime();
		this.collectingmos = bean.getCollectingMos() == null ? null : new ims.core.resource.people.vo.MemberOfStaffRefVo(new Integer(bean.getCollectingMos().getId()), bean.getCollectingMos().getVersion());
		this.ispatientcollect = bean.getIsPatientCollect();
		this.isawaitingcollection = bean.getIsAwaitingCollection();
		this.specimensource = bean.getSpecimenSource() == null ? null : ims.ocrr.vo.lookups.SpecimenType.buildLookup(bean.getSpecimenSource());
		this.discipline = bean.getDiscipline() == null ? null : new ims.core.clinical.vo.ServiceRefVo(new Integer(bean.getDiscipline().getId()), bean.getDiscipline().getVersion());
		if(bean.getInvestigations() != null)
		{
			this.investigations = new ims.ocrr.orderingresults.vo.OrderInvestigationRefVoCollection();
			for(int investigations_i = 0; investigations_i < bean.getInvestigations().length; investigations_i++)
			{
				this.investigations.add(new ims.ocrr.orderingresults.vo.OrderInvestigationRefVo(new Integer(bean.getInvestigations()[investigations_i].getId()), bean.getInvestigations()[investigations_i].getVersion()));
			}
		}
		this.order = bean.getOrder() == null ? null : new ims.ocrr.orderingresults.vo.OcsOrderSessionRefVo(new Integer(bean.getOrder().getId()), bean.getOrder().getVersion());
		this.containers = ims.ocrr.vo.OrderSpecimenContainerVoCollection.buildFromBeanCollection(bean.getContainers());
		this.instructionstocollector = bean.getInstructionsToCollector();
		this.collectorcomment = bean.getCollectorComment();
		this.sitecd = bean.getSiteCd() == null ? null : ims.ocrr.vo.lookups.SpecimenSite.buildLookup(bean.getSiteCd());
		this.requestedtype = bean.getRequestedType() == null ? null : ims.ocrr.vo.lookups.SpecimenCollectionType.buildLookup(bean.getRequestedType());
		this.sysinfo = bean.getSysInfo() == null ? null : bean.getSysInfo().buildSystemInformation();
		this.specimenworklistitem = bean.getSpecimenWorklistItem() == null ? null : bean.getSpecimenWorklistItem().buildVo();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.ocrr.vo.beans.OrderSpecimenVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.colldatetimeplacer = bean.getCollDateTimePlacer() == null ? null : bean.getCollDateTimePlacer().buildDateTime();
		this.collectingmos = bean.getCollectingMos() == null ? null : new ims.core.resource.people.vo.MemberOfStaffRefVo(new Integer(bean.getCollectingMos().getId()), bean.getCollectingMos().getVersion());
		this.ispatientcollect = bean.getIsPatientCollect();
		this.isawaitingcollection = bean.getIsAwaitingCollection();
		this.specimensource = bean.getSpecimenSource() == null ? null : ims.ocrr.vo.lookups.SpecimenType.buildLookup(bean.getSpecimenSource());
		this.discipline = bean.getDiscipline() == null ? null : new ims.core.clinical.vo.ServiceRefVo(new Integer(bean.getDiscipline().getId()), bean.getDiscipline().getVersion());
		if(bean.getInvestigations() != null)
		{
			this.investigations = new ims.ocrr.orderingresults.vo.OrderInvestigationRefVoCollection();
			for(int investigations_i = 0; investigations_i < bean.getInvestigations().length; investigations_i++)
			{
				this.investigations.add(new ims.ocrr.orderingresults.vo.OrderInvestigationRefVo(new Integer(bean.getInvestigations()[investigations_i].getId()), bean.getInvestigations()[investigations_i].getVersion()));
			}
		}
		this.order = bean.getOrder() == null ? null : new ims.ocrr.orderingresults.vo.OcsOrderSessionRefVo(new Integer(bean.getOrder().getId()), bean.getOrder().getVersion());
		this.containers = ims.ocrr.vo.OrderSpecimenContainerVoCollection.buildFromBeanCollection(bean.getContainers());
		this.instructionstocollector = bean.getInstructionsToCollector();
		this.collectorcomment = bean.getCollectorComment();
		this.sitecd = bean.getSiteCd() == null ? null : ims.ocrr.vo.lookups.SpecimenSite.buildLookup(bean.getSiteCd());
		this.requestedtype = bean.getRequestedType() == null ? null : ims.ocrr.vo.lookups.SpecimenCollectionType.buildLookup(bean.getRequestedType());
		this.sysinfo = bean.getSysInfo() == null ? null : bean.getSysInfo().buildSystemInformation();
		this.specimenworklistitem = bean.getSpecimenWorklistItem() == null ? null : bean.getSpecimenWorklistItem().buildVo(map);
	}
	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.OrderSpecimenVoBean bean = null;
		if(map != null)
			bean = (ims.ocrr.vo.beans.OrderSpecimenVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.ocrr.vo.beans.OrderSpecimenVoBean();
			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("COLLDATETIMEPLACER"))
			return getCollDateTimePlacer();
		if(fieldName.equals("COLLECTINGMOS"))
			return getCollectingMos();
		if(fieldName.equals("ISPATIENTCOLLECT"))
			return getIsPatientCollect();
		if(fieldName.equals("ISAWAITINGCOLLECTION"))
			return getIsAwaitingCollection();
		if(fieldName.equals("SPECIMENSOURCE"))
			return getSpecimenSource();
		if(fieldName.equals("DISCIPLINE"))
			return getDiscipline();
		if(fieldName.equals("INVESTIGATIONS"))
			return getInvestigations();
		if(fieldName.equals("ORDER"))
			return getOrder();
		if(fieldName.equals("CONTAINERS"))
			return getContainers();
		if(fieldName.equals("INSTRUCTIONSTOCOLLECTOR"))
			return getInstructionsToCollector();
		if(fieldName.equals("COLLECTORCOMMENT"))
			return getCollectorComment();
		if(fieldName.equals("SITECD"))
			return getSiteCd();
		if(fieldName.equals("REQUESTEDTYPE"))
			return getRequestedType();
		if(fieldName.equals("SYSINFO"))
			return getSysInfo();
		if(fieldName.equals("SPECIMENWORKLISTITEM"))
			return getSpecimenWorklistItem();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getCollDateTimePlacerIsNotNull()
	{
		return this.colldatetimeplacer != null;
	}
	public ims.framework.utils.DateTime getCollDateTimePlacer()
	{
		return this.colldatetimeplacer;
	}
	public void setCollDateTimePlacer(ims.framework.utils.DateTime value)
	{
		this.isValidated = false;
		this.colldatetimeplacer = value;
	}
	public boolean getCollectingMosIsNotNull()
	{
		return this.collectingmos != null;
	}
	public ims.core.resource.people.vo.MemberOfStaffRefVo getCollectingMos()
	{
		return this.collectingmos;
	}
	public void setCollectingMos(ims.core.resource.people.vo.MemberOfStaffRefVo value)
	{
		this.isValidated = false;
		this.collectingmos = value;
	}
	public boolean getIsPatientCollectIsNotNull()
	{
		return this.ispatientcollect != null;
	}
	public Boolean getIsPatientCollect()
	{
		return this.ispatientcollect;
	}
	public void setIsPatientCollect(Boolean value)
	{
		this.isValidated = false;
		this.ispatientcollect = value;
	}
	public boolean getIsAwaitingCollectionIsNotNull()
	{
		return this.isawaitingcollection != null;
	}
	public Boolean getIsAwaitingCollection()
	{
		return this.isawaitingcollection;
	}
	public void setIsAwaitingCollection(Boolean value)
	{
		this.isValidated = false;
		this.isawaitingcollection = value;
	}
	public boolean getSpecimenSourceIsNotNull()
	{
		return this.specimensource != null;
	}
	public ims.ocrr.vo.lookups.SpecimenType getSpecimenSource()
	{
		return this.specimensource;
	}
	public void setSpecimenSource(ims.ocrr.vo.lookups.SpecimenType value)
	{
		this.isValidated = false;
		this.specimensource = value;
	}
	public boolean getDisciplineIsNotNull()
	{
		return this.discipline != null;
	}
	public ims.core.clinical.vo.ServiceRefVo getDiscipline()
	{
		return this.discipline;
	}
	public void setDiscipline(ims.core.clinical.vo.ServiceRefVo value)
	{
		this.isValidated = false;
		this.discipline = value;
	}
	public boolean getInvestigationsIsNotNull()
	{
		return this.investigations != null;
	}
	public ims.ocrr.orderingresults.vo.OrderInvestigationRefVoCollection getInvestigations()
	{
		return this.investigations;
	}
	public void setInvestigations(ims.ocrr.orderingresults.vo.OrderInvestigationRefVoCollection value)
	{
		this.isValidated = false;
		this.investigations = value;
	}
	public boolean getOrderIsNotNull()
	{
		return this.order != null;
	}
	public ims.ocrr.orderingresults.vo.OcsOrderSessionRefVo getOrder()
	{
		return this.order;
	}
	public void setOrder(ims.ocrr.orderingresults.vo.OcsOrderSessionRefVo value)
	{
		this.isValidated = false;
		this.order = value;
	}
	public boolean getContainersIsNotNull()
	{
		return this.containers != null;
	}
	public ims.ocrr.vo.OrderSpecimenContainerVoCollection getContainers()
	{
		return this.containers;
	}
	public void setContainers(ims.ocrr.vo.OrderSpecimenContainerVoCollection value)
	{
		this.isValidated = false;
		this.containers = value;
	}
	public boolean getInstructionsToCollectorIsNotNull()
	{
		return this.instructionstocollector != null;
	}
	public String getInstructionsToCollector()
	{
		return this.instructionstocollector;
	}
	public static int getInstructionsToCollectorMaxLength()
	{
		return 10000;
	}
	public void setInstructionsToCollector(String value)
	{
		this.isValidated = false;
		this.instructionstocollector = value;
	}
	public boolean getCollectorCommentIsNotNull()
	{
		return this.collectorcomment != null;
	}
	public String getCollectorComment()
	{
		return this.collectorcomment;
	}
	public static int getCollectorCommentMaxLength()
	{
		return 500;
	}
	public void setCollectorComment(String value)
	{
		this.isValidated = false;
		this.collectorcomment = value;
	}
	public boolean getSiteCdIsNotNull()
	{
		return this.sitecd != null;
	}
	public ims.ocrr.vo.lookups.SpecimenSite getSiteCd()
	{
		return this.sitecd;
	}
	public void setSiteCd(ims.ocrr.vo.lookups.SpecimenSite value)
	{
		this.isValidated = false;
		this.sitecd = value;
	}
	public boolean getRequestedTypeIsNotNull()
	{
		return this.requestedtype != null;
	}
	public ims.ocrr.vo.lookups.SpecimenCollectionType getRequestedType()
	{
		return this.requestedtype;
	}
	public void setRequestedType(ims.ocrr.vo.lookups.SpecimenCollectionType value)
	{
		this.isValidated = false;
		this.requestedtype = value;
	}
	public boolean getSysInfoIsNotNull()
	{
		return this.sysinfo != null;
	}
	public ims.vo.SystemInformation getSysInfo()
	{
		return this.sysinfo;
	}
	public void setSysInfo(ims.vo.SystemInformation value)
	{
		this.isValidated = false;
		this.sysinfo = value;
	}
	public boolean getSpecimenWorklistItemIsNotNull()
	{
		return this.specimenworklistitem != null;
	}
	public ims.ocrr.vo.SpecimenWorkListItemVo getSpecimenWorklistItem()
	{
		return this.specimenworklistitem;
	}
	public void setSpecimenWorklistItem(ims.ocrr.vo.SpecimenWorkListItemVo value)
	{
		this.isValidated = false;
		this.specimenworklistitem = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.containers != null)
		{
			if(!this.containers.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.ispatientcollect == null)
			listOfErrors.add("IsPatientCollect is mandatory");
		if(this.isawaitingcollection == null)
			listOfErrors.add("IsAwaitingCollection is mandatory");
		if(this.specimensource == null)
			listOfErrors.add("SpecimenSource is mandatory");
		if(this.discipline == null)
			listOfErrors.add("Discipline is mandatory");
		if(this.containers != null)
		{
			String[] listOfOtherErrors = this.containers.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.collectorcomment != null)
			if(this.collectorcomment.length() > 500)
				listOfErrors.add("The length of the field [collectorcomment] in the value object [ims.ocrr.vo.OrderSpecimenVo] is too big. It should be less or equal to 500");
		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;
	
		OrderSpecimenVo clone = new OrderSpecimenVo(this.id, this.version);
		
		if(this.colldatetimeplacer == null)
			clone.colldatetimeplacer = null;
		else
			clone.colldatetimeplacer = (ims.framework.utils.DateTime)this.colldatetimeplacer.clone();
		clone.collectingmos = this.collectingmos;
		clone.ispatientcollect = this.ispatientcollect;
		clone.isawaitingcollection = this.isawaitingcollection;
		if(this.specimensource == null)
			clone.specimensource = null;
		else
			clone.specimensource = (ims.ocrr.vo.lookups.SpecimenType)this.specimensource.clone();
		clone.discipline = this.discipline;
		clone.investigations = this.investigations;
		clone.order = this.order;
		if(this.containers == null)
			clone.containers = null;
		else
			clone.containers = (ims.ocrr.vo.OrderSpecimenContainerVoCollection)this.containers.clone();
		clone.instructionstocollector = this.instructionstocollector;
		clone.collectorcomment = this.collectorcomment;
		if(this.sitecd == null)
			clone.sitecd = null;
		else
			clone.sitecd = (ims.ocrr.vo.lookups.SpecimenSite)this.sitecd.clone();
		if(this.requestedtype == null)
			clone.requestedtype = null;
		else
			clone.requestedtype = (ims.ocrr.vo.lookups.SpecimenCollectionType)this.requestedtype.clone();
		if(this.sysinfo == null)
			clone.sysinfo = null;
		else
			clone.sysinfo = (ims.vo.SystemInformation)this.sysinfo.clone();
		if(this.specimenworklistitem == null)
			clone.specimenworklistitem = null;
		else
			clone.specimenworklistitem = (ims.ocrr.vo.SpecimenWorkListItemVo)this.specimenworklistitem.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 (!(OrderSpecimenVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A OrderSpecimenVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((OrderSpecimenVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((OrderSpecimenVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.colldatetimeplacer != null)
			count++;
		if(this.collectingmos != null)
			count++;
		if(this.ispatientcollect != null)
			count++;
		if(this.isawaitingcollection != null)
			count++;
		if(this.specimensource != null)
			count++;
		if(this.discipline != null)
			count++;
		if(this.investigations != null)
			count++;
		if(this.order != null)
			count++;
		if(this.containers != null)
			count++;
		if(this.instructionstocollector != null)
			count++;
		if(this.collectorcomment != null)
			count++;
		if(this.sitecd != null)
			count++;
		if(this.requestedtype != null)
			count++;
		if(this.sysinfo != null)
			count++;
		if(this.specimenworklistitem != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 15;
	}
	protected ims.framework.utils.DateTime colldatetimeplacer;
	protected ims.core.resource.people.vo.MemberOfStaffRefVo collectingmos;
	protected Boolean ispatientcollect;
	protected Boolean isawaitingcollection;
	protected ims.ocrr.vo.lookups.SpecimenType specimensource;
	protected ims.core.clinical.vo.ServiceRefVo discipline;
	protected ims.ocrr.orderingresults.vo.OrderInvestigationRefVoCollection investigations;
	protected ims.ocrr.orderingresults.vo.OcsOrderSessionRefVo order;
	protected ims.ocrr.vo.OrderSpecimenContainerVoCollection containers;
	protected String instructionstocollector;
	protected String collectorcomment;
	protected ims.ocrr.vo.lookups.SpecimenSite sitecd;
	protected ims.ocrr.vo.lookups.SpecimenCollectionType requestedtype;
	protected ims.vo.SystemInformation sysinfo;
	protected ims.ocrr.vo.SpecimenWorkListItemVo specimenworklistitem;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
