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

	public OrderResultHistoryVo()
	{
	}
	public OrderResultHistoryVo(Integer id, int version)
	{
		super(id, version);
	}
	public OrderResultHistoryVo(ims.ocrr.vo.beans.OrderResultHistoryVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.repdatetime = bean.getRepDateTime() == null ? null : bean.getRepDateTime().buildDateTime();
		this.reptimesupplied = bean.getRepTimeSupplied();
		this.ordinvstatus = bean.getOrdInvStatus() == null ? null : ims.ocrr.vo.lookups.OrderInvStatus.buildLookup(bean.getOrdInvStatus());
		this.resultstatus = bean.getResultStatus() == null ? null : ims.ocrr.vo.lookups.ResultStatus.buildLookup(bean.getResultStatus());
		this.historydatetime = bean.getHistoryDateTime() == null ? null : bean.getHistoryDateTime().buildDateTime();
		this.investigationname = bean.getInvestigationName();
		this.orderability = bean.getOrderAbility() == null ? null : ims.ocrr.vo.lookups.InvestigationOrderability.buildLookup(bean.getOrderAbility());
		this.requestedlocation = bean.getRequestedLocation() == null ? null : bean.getRequestedLocation().buildVo();
		this.confidentialtest = bean.getConfidentialTest();
		this.specimen = ims.ocrr.vo.SpecimenNameVoCollection.buildFromBeanCollection(bean.getSpecimen());
		this.specimentype = bean.getSpecimenType() == null ? null : bean.getSpecimenType().buildLookupInstVo();
		this.resultdetail = bean.getResultDetail() == null ? null : bean.getResultDetail().buildVo();
		this.invtype = bean.getInvType() == null ? null : ims.ocrr.vo.lookups.InvType.buildLookup(bean.getInvType());
		this.inveventtype = bean.getInvEventType() == null ? null : ims.ocrr.vo.lookups.InvEventType.buildLookup(bean.getInvEventType());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.ocrr.vo.beans.OrderResultHistoryVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.repdatetime = bean.getRepDateTime() == null ? null : bean.getRepDateTime().buildDateTime();
		this.reptimesupplied = bean.getRepTimeSupplied();
		this.ordinvstatus = bean.getOrdInvStatus() == null ? null : ims.ocrr.vo.lookups.OrderInvStatus.buildLookup(bean.getOrdInvStatus());
		this.resultstatus = bean.getResultStatus() == null ? null : ims.ocrr.vo.lookups.ResultStatus.buildLookup(bean.getResultStatus());
		this.historydatetime = bean.getHistoryDateTime() == null ? null : bean.getHistoryDateTime().buildDateTime();
		this.investigationname = bean.getInvestigationName();
		this.orderability = bean.getOrderAbility() == null ? null : ims.ocrr.vo.lookups.InvestigationOrderability.buildLookup(bean.getOrderAbility());
		this.requestedlocation = bean.getRequestedLocation() == null ? null : bean.getRequestedLocation().buildVo(map);
		this.confidentialtest = bean.getConfidentialTest();
		this.specimen = ims.ocrr.vo.SpecimenNameVoCollection.buildFromBeanCollection(bean.getSpecimen());
		this.specimentype = bean.getSpecimenType() == null ? null : bean.getSpecimenType().buildLookupInstVo();
		this.resultdetail = bean.getResultDetail() == null ? null : bean.getResultDetail().buildVo(map);
		this.invtype = bean.getInvType() == null ? null : ims.ocrr.vo.lookups.InvType.buildLookup(bean.getInvType());
		this.inveventtype = bean.getInvEventType() == null ? null : ims.ocrr.vo.lookups.InvEventType.buildLookup(bean.getInvEventType());
	}
	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.OrderResultHistoryVoBean bean = null;
		if(map != null)
			bean = (ims.ocrr.vo.beans.OrderResultHistoryVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.ocrr.vo.beans.OrderResultHistoryVoBean();
			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("REPDATETIME"))
			return getRepDateTime();
		if(fieldName.equals("REPTIMESUPPLIED"))
			return getRepTimeSupplied();
		if(fieldName.equals("ORDINVSTATUS"))
			return getOrdInvStatus();
		if(fieldName.equals("RESULTSTATUS"))
			return getResultStatus();
		if(fieldName.equals("HISTORYDATETIME"))
			return getHistoryDateTime();
		if(fieldName.equals("INVESTIGATIONNAME"))
			return getInvestigationName();
		if(fieldName.equals("ORDERABILITY"))
			return getOrderAbility();
		if(fieldName.equals("REQUESTEDLOCATION"))
			return getRequestedLocation();
		if(fieldName.equals("CONFIDENTIALTEST"))
			return getConfidentialTest();
		if(fieldName.equals("SPECIMEN"))
			return getSpecimen();
		if(fieldName.equals("SPECIMENTYPE"))
			return getSpecimenType();
		if(fieldName.equals("RESULTDETAIL"))
			return getResultDetail();
		if(fieldName.equals("INVTYPE"))
			return getInvType();
		if(fieldName.equals("INVEVENTTYPE"))
			return getInvEventType();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getRepDateTimeIsNotNull()
	{
		return this.repdatetime != null;
	}
	public ims.framework.utils.DateTime getRepDateTime()
	{
		return this.repdatetime;
	}
	public void setRepDateTime(ims.framework.utils.DateTime value)
	{
		this.isValidated = false;
		this.repdatetime = value;
	}
	public boolean getRepTimeSuppliedIsNotNull()
	{
		return this.reptimesupplied != null;
	}
	public Boolean getRepTimeSupplied()
	{
		return this.reptimesupplied;
	}
	public void setRepTimeSupplied(Boolean value)
	{
		this.isValidated = false;
		this.reptimesupplied = value;
	}
	public boolean getOrdInvStatusIsNotNull()
	{
		return this.ordinvstatus != null;
	}
	public ims.ocrr.vo.lookups.OrderInvStatus getOrdInvStatus()
	{
		return this.ordinvstatus;
	}
	public void setOrdInvStatus(ims.ocrr.vo.lookups.OrderInvStatus value)
	{
		this.isValidated = false;
		this.ordinvstatus = value;
	}
	public boolean getResultStatusIsNotNull()
	{
		return this.resultstatus != null;
	}
	public ims.ocrr.vo.lookups.ResultStatus getResultStatus()
	{
		return this.resultstatus;
	}
	public void setResultStatus(ims.ocrr.vo.lookups.ResultStatus value)
	{
		this.isValidated = false;
		this.resultstatus = value;
	}
	public boolean getHistoryDateTimeIsNotNull()
	{
		return this.historydatetime != null;
	}
	public ims.framework.utils.DateTime getHistoryDateTime()
	{
		return this.historydatetime;
	}
	public void setHistoryDateTime(ims.framework.utils.DateTime value)
	{
		this.isValidated = false;
		this.historydatetime = value;
	}
	public boolean getInvestigationNameIsNotNull()
	{
		return this.investigationname != null;
	}
	public String getInvestigationName()
	{
		return this.investigationname;
	}
	public static int getInvestigationNameMaxLength()
	{
		return 255;
	}
	public void setInvestigationName(String value)
	{
		this.isValidated = false;
		this.investigationname = value;
	}
	public boolean getOrderAbilityIsNotNull()
	{
		return this.orderability != null;
	}
	public ims.ocrr.vo.lookups.InvestigationOrderability getOrderAbility()
	{
		return this.orderability;
	}
	public void setOrderAbility(ims.ocrr.vo.lookups.InvestigationOrderability value)
	{
		this.isValidated = false;
		this.orderability = value;
	}
	public boolean getRequestedLocationIsNotNull()
	{
		return this.requestedlocation != null;
	}
	public ims.core.vo.LocationLiteVo getRequestedLocation()
	{
		return this.requestedlocation;
	}
	public void setRequestedLocation(ims.core.vo.LocationLiteVo value)
	{
		this.isValidated = false;
		this.requestedlocation = value;
	}
	public boolean getConfidentialTestIsNotNull()
	{
		return this.confidentialtest != null;
	}
	public Boolean getConfidentialTest()
	{
		return this.confidentialtest;
	}
	public void setConfidentialTest(Boolean value)
	{
		this.isValidated = false;
		this.confidentialtest = value;
	}
	public boolean getSpecimenIsNotNull()
	{
		return this.specimen != null;
	}
	public ims.ocrr.vo.SpecimenNameVoCollection getSpecimen()
	{
		return this.specimen;
	}
	public void setSpecimen(ims.ocrr.vo.SpecimenNameVoCollection value)
	{
		this.isValidated = false;
		this.specimen = value;
	}
	public boolean getSpecimenTypeIsNotNull()
	{
		return this.specimentype != null;
	}
	public ims.vo.LookupInstVo getSpecimenType()
	{
		return this.specimentype;
	}
	public void setSpecimenType(ims.vo.LookupInstVo value)
	{
		this.isValidated = false;
		this.specimentype = value;
	}
	public boolean getResultDetailIsNotNull()
	{
		return this.resultdetail != null;
	}
	public ims.ocrr.vo.ResultDetailsForOrderResultHistoryVo getResultDetail()
	{
		return this.resultdetail;
	}
	public void setResultDetail(ims.ocrr.vo.ResultDetailsForOrderResultHistoryVo value)
	{
		this.isValidated = false;
		this.resultdetail = value;
	}
	public boolean getInvTypeIsNotNull()
	{
		return this.invtype != null;
	}
	public ims.ocrr.vo.lookups.InvType getInvType()
	{
		return this.invtype;
	}
	public void setInvType(ims.ocrr.vo.lookups.InvType value)
	{
		this.isValidated = false;
		this.invtype = value;
	}
	public boolean getInvEventTypeIsNotNull()
	{
		return this.inveventtype != null;
	}
	public ims.ocrr.vo.lookups.InvEventType getInvEventType()
	{
		return this.inveventtype;
	}
	public void setInvEventType(ims.ocrr.vo.lookups.InvEventType value)
	{
		this.isValidated = false;
		this.inveventtype = value;
	}
	/**
	* IOrderResultDisplay Interface methods
	*/
		/**
		* IOrderResultDisplay Interface methods
		*/
		public String getIOrderResultDisplayInvName()
		{
			return investigationname;
		}
		public ims.ocrr.vo.lookups.InvestigationOrderability getIOrderResultDisplayOrderAbility()
		{
			return orderability;
		}
		public ims.ocrr.vo.PathologyResultDetailVo getIOrderResultDisplayPathResultDetails()
		{
			if(this.resultdetail != null && this.resultdetail.getPathologyResultDetails() != null && this.resultdetail.getPathologyResultDetails().size() > 0)
				return this.resultdetail.getPathologyResultDetails().get(0);
				
			return null;
		}
		public ims.ocrr.vo.RadResultDetailsVo getIOrderResultDisplayRadResultDetails()
		{
			if(this.resultdetail != null)
				return this.resultdetail.getClinicalResultDetails();
				
			return null;
		}
		public ims.framework.utils.DateTime getIOrderResultDisplayRepDateTime()
		{
			return repdatetime;
		}
		public Boolean getIOrderResultDisplayRepTimeSupplied()
		{
			return reptimesupplied;
		}
		public ims.core.vo.LocationLiteVo getIOrderResultDisplayRequestedLocation()
		{
			return requestedlocation;
		}
		public ims.ocrr.vo.lookups.OrderInvStatus getIOrderResultDisplayStatus()
		{
			return ordinvstatus;
		}
		public ims.framework.utils.DateTime getIOrderResultDisplayHistoryDateTime()
		{
			return historydatetime;
		}
		public Boolean getIOrderResultDisplayConfidentialTest()
		{
			return confidentialtest;
		}
		public String getIOrderResultSpecimen()
		{
			if (this.specimen == null || this.specimen.size() == 0 || this.specimen.get(0) == null || this.specimen.get(0).specimensource == null)
				return null;
		
			// Specimen source is mandatory for OrderSpecimen
			return this.specimen.get(0).specimensource.getText();
		}
		public java.util.LinkedHashMap<ims.ocrr.vo.lookups.ResultEDSubtype, Object> getIOrderResultDisplayExtendedDataResult()
		{
			return null;	
		}
		public String getIOrderResultLabSpecimenType()
		{
			if (this.specimentype != null)
				return this.specimentype.getText();
				
			return null;
		}
	
	public ims.ocrr.vo.lookups.InvType getIInvestigationType() 
	{
		return this.invtype;
	}
		
	public ims.ocrr.vo.lookups.InvEventType getIInvestigationEventType() 
	{
		return this.inveventtype;
	}
	
	public ims.vo.interfaces.IOrderSpecimen[] getIOrderSpecimens() 
	{
		if(this.specimen != null)
		{
			return this.specimen.toIOrderSpecimenArray();
		}
				
		return null;
	}
	
	public ims.ocrr.vo.PathologyResultDetailVo getIOrderResultDisplayPathResultDetailsForDFT(ims.vo.interfaces.IOrderSpecimen orderSpecimen) 
	{
		if(orderSpecimen == null || orderSpecimen.getIOrderSpecimenId() == null)
			return null;
						
		if(this.resultdetail == null || this.resultdetail.pathologyresultdetails == null)
			return null;
						
		for(int x=0; x<this.resultdetail.pathologyresultdetails.size(); x++)
		{
			PathologyResultDetailVo pathResult = this.resultdetail.pathologyresultdetails.get(x);
							
			if(pathResult == null || pathResult.orderspecimen == null || pathResult.orderspecimen.getID_OrderSpecimen() == null)
				continue;
							
			if(pathResult.orderspecimen.getID_OrderSpecimen().equals(orderSpecimen.getIOrderSpecimenId()))
				return pathResult;
		}
						
		return null;
	}
	
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.requestedlocation != null)
		{
			if(!this.requestedlocation.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.requestedlocation != null)
		{
			String[] listOfOtherErrors = this.requestedlocation.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;
	
		OrderResultHistoryVo clone = new OrderResultHistoryVo(this.id, this.version);
		
		if(this.repdatetime == null)
			clone.repdatetime = null;
		else
			clone.repdatetime = (ims.framework.utils.DateTime)this.repdatetime.clone();
		clone.reptimesupplied = this.reptimesupplied;
		if(this.ordinvstatus == null)
			clone.ordinvstatus = null;
		else
			clone.ordinvstatus = (ims.ocrr.vo.lookups.OrderInvStatus)this.ordinvstatus.clone();
		if(this.resultstatus == null)
			clone.resultstatus = null;
		else
			clone.resultstatus = (ims.ocrr.vo.lookups.ResultStatus)this.resultstatus.clone();
		if(this.historydatetime == null)
			clone.historydatetime = null;
		else
			clone.historydatetime = (ims.framework.utils.DateTime)this.historydatetime.clone();
		clone.investigationname = this.investigationname;
		if(this.orderability == null)
			clone.orderability = null;
		else
			clone.orderability = (ims.ocrr.vo.lookups.InvestigationOrderability)this.orderability.clone();
		if(this.requestedlocation == null)
			clone.requestedlocation = null;
		else
			clone.requestedlocation = (ims.core.vo.LocationLiteVo)this.requestedlocation.clone();
		clone.confidentialtest = this.confidentialtest;
		if(this.specimen == null)
			clone.specimen = null;
		else
			clone.specimen = (ims.ocrr.vo.SpecimenNameVoCollection)this.specimen.clone();
		clone.specimentype = this.specimentype;
		if(this.resultdetail == null)
			clone.resultdetail = null;
		else
			clone.resultdetail = (ims.ocrr.vo.ResultDetailsForOrderResultHistoryVo)this.resultdetail.clone();
		if(this.invtype == null)
			clone.invtype = null;
		else
			clone.invtype = (ims.ocrr.vo.lookups.InvType)this.invtype.clone();
		if(this.inveventtype == null)
			clone.inveventtype = null;
		else
			clone.inveventtype = (ims.ocrr.vo.lookups.InvEventType)this.inveventtype.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 (!(OrderResultHistoryVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A OrderResultHistoryVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		OrderResultHistoryVo compareObj = (OrderResultHistoryVo)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getHistoryDateTime() == null && compareObj.getHistoryDateTime() != null)
				return -1;
			if(this.getHistoryDateTime() != null && compareObj.getHistoryDateTime() == null)
				return 1;
			if(this.getHistoryDateTime() != null && compareObj.getHistoryDateTime() != null)
				retVal = this.getHistoryDateTime().compareTo(compareObj.getHistoryDateTime());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.repdatetime != null)
			count++;
		if(this.reptimesupplied != null)
			count++;
		if(this.ordinvstatus != null)
			count++;
		if(this.resultstatus != null)
			count++;
		if(this.historydatetime != null)
			count++;
		if(this.investigationname != null)
			count++;
		if(this.orderability != null)
			count++;
		if(this.requestedlocation != null)
			count++;
		if(this.confidentialtest != null)
			count++;
		if(this.specimen != null)
			count++;
		if(this.specimentype != null)
			count++;
		if(this.resultdetail != null)
			count++;
		if(this.invtype != null)
			count++;
		if(this.inveventtype != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 14;
	}
	protected ims.framework.utils.DateTime repdatetime;
	protected Boolean reptimesupplied;
	protected ims.ocrr.vo.lookups.OrderInvStatus ordinvstatus;
	protected ims.ocrr.vo.lookups.ResultStatus resultstatus;
	protected ims.framework.utils.DateTime historydatetime;
	protected String investigationname;
	protected ims.ocrr.vo.lookups.InvestigationOrderability orderability;
	protected ims.core.vo.LocationLiteVo requestedlocation;
	protected Boolean confidentialtest;
	protected ims.ocrr.vo.SpecimenNameVoCollection specimen;
	protected ims.vo.LookupInstVo specimentype;
	protected ims.ocrr.vo.ResultDetailsForOrderResultHistoryVo resultdetail;
	protected ims.ocrr.vo.lookups.InvType invtype;
	protected ims.ocrr.vo.lookups.InvEventType inveventtype;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
