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

/**
 * Linked to core.patient.Patient business object (ID: 1001100000).
 */
public class PatientLiteClinicListVo extends ims.core.vo.PatientLite_IdentifiersVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public PatientLiteClinicListVo()
	{
	}
	public PatientLiteClinicListVo(Integer id, int version)
	{
		super(id, version);
	}
	public PatientLiteClinicListVo(ims.core.vo.beans.PatientLiteClinicListVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.name = bean.getName() == null ? null : bean.getName().buildVo();
		this.sex = bean.getSex() == null ? null : ims.core.vo.lookups.Sex.buildLookup(bean.getSex());
		this.dob = bean.getDob() == null ? null : bean.getDob().buildPartialDate();
		this.isactive = bean.getIsActive();
		this.isquickregistrationpatient = bean.getIsQuickRegistrationPatient();
		this.primaryidvalueused = bean.getPrimaryIdValueUsed();
		this.identifiers = ims.core.vo.PatientIdCollection.buildFromBeanCollection(bean.getIdentifiers());
		this.dod = bean.getDod() == null ? null : bean.getDod().buildDate();
		this.age = bean.getAge();
		this.agetext = bean.getAgeText();
		this.patientcategory = bean.getPatientCategory() == null ? null : ims.core.vo.lookups.PatientStatus.buildLookup(bean.getPatientCategory());
		if(bean.getPatientAlerts() != null)
		{
			this.patientalerts = new ims.core.clinical.vo.PatientAlertRefVoCollection();
			for(int patientalerts_i = 0; patientalerts_i < bean.getPatientAlerts().length; patientalerts_i++)
			{
				this.patientalerts.add(new ims.core.clinical.vo.PatientAlertRefVo(new Integer(bean.getPatientAlerts()[patientalerts_i].getId()), bean.getPatientAlerts()[patientalerts_i].getVersion()));
			}
		}
		this.hasalerts = bean.getHasAlerts();
		this.associatedpatient = bean.getAssociatedPatient() == null ? null : new ims.core.patient.vo.PatientRefVo(new Integer(bean.getAssociatedPatient().getId()), bean.getAssociatedPatient().getVersion());
		this.ward = bean.getWard() == null ? null : bean.getWard().buildVo();
		this.isselfadmitpatient = bean.getIsSelfAdmitPatient();
		this.timeofdeath = bean.getTimeOfDeath() == null ? null : bean.getTimeOfDeath().buildTime();
		this.commchannels = ims.core.vo.CommChannelsLiteVoCollection.buildFromBeanCollection(bean.getCommChannels());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.core.vo.beans.PatientLiteClinicListVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.name = bean.getName() == null ? null : bean.getName().buildVo(map);
		this.sex = bean.getSex() == null ? null : ims.core.vo.lookups.Sex.buildLookup(bean.getSex());
		this.dob = bean.getDob() == null ? null : bean.getDob().buildPartialDate();
		this.isactive = bean.getIsActive();
		this.isquickregistrationpatient = bean.getIsQuickRegistrationPatient();
		this.primaryidvalueused = bean.getPrimaryIdValueUsed();
		this.identifiers = ims.core.vo.PatientIdCollection.buildFromBeanCollection(bean.getIdentifiers());
		this.dod = bean.getDod() == null ? null : bean.getDod().buildDate();
		this.age = bean.getAge();
		this.agetext = bean.getAgeText();
		this.patientcategory = bean.getPatientCategory() == null ? null : ims.core.vo.lookups.PatientStatus.buildLookup(bean.getPatientCategory());
		if(bean.getPatientAlerts() != null)
		{
			this.patientalerts = new ims.core.clinical.vo.PatientAlertRefVoCollection();
			for(int patientalerts_i = 0; patientalerts_i < bean.getPatientAlerts().length; patientalerts_i++)
			{
				this.patientalerts.add(new ims.core.clinical.vo.PatientAlertRefVo(new Integer(bean.getPatientAlerts()[patientalerts_i].getId()), bean.getPatientAlerts()[patientalerts_i].getVersion()));
			}
		}
		this.hasalerts = bean.getHasAlerts();
		this.associatedpatient = bean.getAssociatedPatient() == null ? null : new ims.core.patient.vo.PatientRefVo(new Integer(bean.getAssociatedPatient().getId()), bean.getAssociatedPatient().getVersion());
		this.ward = bean.getWard() == null ? null : bean.getWard().buildVo(map);
		this.isselfadmitpatient = bean.getIsSelfAdmitPatient();
		this.timeofdeath = bean.getTimeOfDeath() == null ? null : bean.getTimeOfDeath().buildTime();
		this.commchannels = ims.core.vo.CommChannelsLiteVoCollection.buildFromBeanCollection(bean.getCommChannels());
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.core.vo.beans.PatientLiteClinicListVoBean bean = null;
		if(map != null)
			bean = (ims.core.vo.beans.PatientLiteClinicListVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.core.vo.beans.PatientLiteClinicListVoBean();
			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("COMMCHANNELS"))
			return getCommChannels();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getCommChannelsIsNotNull()
	{
		return this.commchannels != null;
	}
	public ims.core.vo.CommChannelsLiteVoCollection getCommChannels()
	{
		return this.commchannels;
	}
	public void setCommChannels(ims.core.vo.CommChannelsLiteVoCollection value)
	{
		this.isValidated = false;
		this.commchannels = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.name != null)
		{
			if(!this.name.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.identifiers != null)
		{
			if(!this.identifiers.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.name != null)
		{
			String[] listOfOtherErrors = this.name.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.primaryidvalueused != null)
			if(this.primaryidvalueused.length() > 50)
				listOfErrors.add("The length of the field [primaryidvalueused] in the value object [ims.core.vo.PatientLiteClinicListVo] is too big. It should be less or equal to 50");
		if(this.identifiers != null)
		{
			String[] listOfOtherErrors = this.identifiers.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;
	
		PatientLiteClinicListVo clone = new PatientLiteClinicListVo(this.id, this.version);
		
		if(this.name == null)
			clone.name = null;
		else
			clone.name = (ims.core.vo.PersonName)this.name.clone();
		if(this.sex == null)
			clone.sex = null;
		else
			clone.sex = (ims.core.vo.lookups.Sex)this.sex.clone();
		if(this.dob == null)
			clone.dob = null;
		else
			clone.dob = (ims.framework.utils.PartialDate)this.dob.clone();
		clone.isactive = this.isactive;
		clone.isquickregistrationpatient = this.isquickregistrationpatient;
		clone.primaryidvalueused = this.primaryidvalueused;
		if(this.identifiers == null)
			clone.identifiers = null;
		else
			clone.identifiers = (ims.core.vo.PatientIdCollection)this.identifiers.clone();
		if(this.dod == null)
			clone.dod = null;
		else
			clone.dod = (ims.framework.utils.Date)this.dod.clone();
		clone.age = this.age;
		clone.agetext = this.agetext;
		if(this.patientcategory == null)
			clone.patientcategory = null;
		else
			clone.patientcategory = (ims.core.vo.lookups.PatientStatus)this.patientcategory.clone();
		clone.patientalerts = this.patientalerts;
		clone.hasalerts = this.hasalerts;
		clone.associatedpatient = this.associatedpatient;
		if(this.ward == null)
			clone.ward = null;
		else
			clone.ward = (ims.core.vo.LocationLiteVo)this.ward.clone();
		clone.isselfadmitpatient = this.isselfadmitpatient;
		if(this.timeofdeath == null)
			clone.timeofdeath = null;
		else
			clone.timeofdeath = (ims.framework.utils.Time)this.timeofdeath.clone();
		if(this.commchannels == null)
			clone.commchannels = null;
		else
			clone.commchannels = (ims.core.vo.CommChannelsLiteVoCollection)this.commchannels.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 (!(PatientLiteClinicListVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A PatientLiteClinicListVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((PatientLiteClinicListVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((PatientLiteClinicListVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = super.countFieldsWithValue();
		if(this.commchannels != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return super.countValueObjectFields() + 1;
	}
	protected ims.core.vo.CommChannelsLiteVoCollection commchannels;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
