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

	public PatientMedicalInsuranceVo()
	{
	}
	public PatientMedicalInsuranceVo(Integer id, int version)
	{
		super(id, version);
	}
	public PatientMedicalInsuranceVo(ims.core.vo.beans.PatientMedicalInsuranceVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.patient = bean.getPatient() == null ? null : new ims.core.patient.vo.PatientRefVo(new Integer(bean.getPatient().getId()), bean.getPatient().getVersion());
		this.company = bean.getCompany() == null ? null : bean.getCompany().buildVo();
		this.policynumber = bean.getPolicyNumber();
		this.policytype = bean.getPolicyType() == null ? null : ims.core.vo.lookups.PrivateInsurancePolicyType.buildLookup(bean.getPolicyType());
		this.authorisationnumber = bean.getAuthorisationNumber();
		this.expirydate = bean.getExpiryDate() == null ? null : bean.getExpiryDate().buildDate();
		this.currentstatus = bean.getCurrentStatus() == null ? null : ims.core.vo.lookups.PrivateInsuranceStatus.buildLookup(bean.getCurrentStatus());
		this.statuschangedate = bean.getStatusChangeDate() == null ? null : bean.getStatusChangeDate().buildDate();
		this.planorunits = bean.getPlanOrUnits();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.core.vo.beans.PatientMedicalInsuranceVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.patient = bean.getPatient() == null ? null : new ims.core.patient.vo.PatientRefVo(new Integer(bean.getPatient().getId()), bean.getPatient().getVersion());
		this.company = bean.getCompany() == null ? null : bean.getCompany().buildVo(map);
		this.policynumber = bean.getPolicyNumber();
		this.policytype = bean.getPolicyType() == null ? null : ims.core.vo.lookups.PrivateInsurancePolicyType.buildLookup(bean.getPolicyType());
		this.authorisationnumber = bean.getAuthorisationNumber();
		this.expirydate = bean.getExpiryDate() == null ? null : bean.getExpiryDate().buildDate();
		this.currentstatus = bean.getCurrentStatus() == null ? null : ims.core.vo.lookups.PrivateInsuranceStatus.buildLookup(bean.getCurrentStatus());
		this.statuschangedate = bean.getStatusChangeDate() == null ? null : bean.getStatusChangeDate().buildDate();
		this.planorunits = bean.getPlanOrUnits();
	}
	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.PatientMedicalInsuranceVoBean bean = null;
		if(map != null)
			bean = (ims.core.vo.beans.PatientMedicalInsuranceVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.core.vo.beans.PatientMedicalInsuranceVoBean();
			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("PATIENT"))
			return getPatient();
		if(fieldName.equals("COMPANY"))
			return getCompany();
		if(fieldName.equals("POLICYNUMBER"))
			return getPolicyNumber();
		if(fieldName.equals("POLICYTYPE"))
			return getPolicyType();
		if(fieldName.equals("AUTHORISATIONNUMBER"))
			return getAuthorisationNumber();
		if(fieldName.equals("EXPIRYDATE"))
			return getExpiryDate();
		if(fieldName.equals("CURRENTSTATUS"))
			return getCurrentStatus();
		if(fieldName.equals("STATUSCHANGEDATE"))
			return getStatusChangeDate();
		if(fieldName.equals("PLANORUNITS"))
			return getPlanOrUnits();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getPatientIsNotNull()
	{
		return this.patient != null;
	}
	public ims.core.patient.vo.PatientRefVo getPatient()
	{
		return this.patient;
	}
	public void setPatient(ims.core.patient.vo.PatientRefVo value)
	{
		this.isValidated = false;
		this.patient = value;
	}
	public boolean getCompanyIsNotNull()
	{
		return this.company != null;
	}
	public ims.core.vo.PrivateInsuranceCompanyVo getCompany()
	{
		return this.company;
	}
	public void setCompany(ims.core.vo.PrivateInsuranceCompanyVo value)
	{
		this.isValidated = false;
		this.company = value;
	}
	public boolean getPolicyNumberIsNotNull()
	{
		return this.policynumber != null;
	}
	public String getPolicyNumber()
	{
		return this.policynumber;
	}
	public static int getPolicyNumberMaxLength()
	{
		return 20;
	}
	public void setPolicyNumber(String value)
	{
		this.isValidated = false;
		this.policynumber = value;
	}
	public boolean getPolicyTypeIsNotNull()
	{
		return this.policytype != null;
	}
	public ims.core.vo.lookups.PrivateInsurancePolicyType getPolicyType()
	{
		return this.policytype;
	}
	public void setPolicyType(ims.core.vo.lookups.PrivateInsurancePolicyType value)
	{
		this.isValidated = false;
		this.policytype = value;
	}
	public boolean getAuthorisationNumberIsNotNull()
	{
		return this.authorisationnumber != null;
	}
	public String getAuthorisationNumber()
	{
		return this.authorisationnumber;
	}
	public static int getAuthorisationNumberMaxLength()
	{
		return 20;
	}
	public void setAuthorisationNumber(String value)
	{
		this.isValidated = false;
		this.authorisationnumber = value;
	}
	public boolean getExpiryDateIsNotNull()
	{
		return this.expirydate != null;
	}
	public ims.framework.utils.Date getExpiryDate()
	{
		return this.expirydate;
	}
	public void setExpiryDate(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.expirydate = value;
	}
	public boolean getCurrentStatusIsNotNull()
	{
		return this.currentstatus != null;
	}
	public ims.core.vo.lookups.PrivateInsuranceStatus getCurrentStatus()
	{
		return this.currentstatus;
	}
	public void setCurrentStatus(ims.core.vo.lookups.PrivateInsuranceStatus value)
	{
		this.isValidated = false;
		this.currentstatus = value;
	}
	public boolean getStatusChangeDateIsNotNull()
	{
		return this.statuschangedate != null;
	}
	public ims.framework.utils.Date getStatusChangeDate()
	{
		return this.statuschangedate;
	}
	public void setStatusChangeDate(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.statuschangedate = value;
	}
	public boolean getPlanOrUnitsIsNotNull()
	{
		return this.planorunits != null;
	}
	public String getPlanOrUnits()
	{
		return this.planorunits;
	}
	public static int getPlanOrUnitsMaxLength()
	{
		return 100;
	}
	public void setPlanOrUnits(String value)
	{
		this.isValidated = false;
		this.planorunits = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.company != null)
		{
			if(!this.company.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.company != null)
		{
			String[] listOfOtherErrors = this.company.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.policynumber != null)
			if(this.policynumber.length() > 20)
				listOfErrors.add("The length of the field [policynumber] in the value object [ims.core.vo.PatientMedicalInsuranceVo] is too big. It should be less or equal to 20");
		if(this.authorisationnumber != null)
			if(this.authorisationnumber.length() > 20)
				listOfErrors.add("The length of the field [authorisationnumber] in the value object [ims.core.vo.PatientMedicalInsuranceVo] is too big. It should be less or equal to 20");
		if(this.planorunits != null)
			if(this.planorunits.length() > 100)
				listOfErrors.add("The length of the field [planorunits] in the value object [ims.core.vo.PatientMedicalInsuranceVo] is too big. It should be less or equal to 100");
		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;
	
		PatientMedicalInsuranceVo clone = new PatientMedicalInsuranceVo(this.id, this.version);
		
		clone.patient = this.patient;
		if(this.company == null)
			clone.company = null;
		else
			clone.company = (ims.core.vo.PrivateInsuranceCompanyVo)this.company.clone();
		clone.policynumber = this.policynumber;
		if(this.policytype == null)
			clone.policytype = null;
		else
			clone.policytype = (ims.core.vo.lookups.PrivateInsurancePolicyType)this.policytype.clone();
		clone.authorisationnumber = this.authorisationnumber;
		if(this.expirydate == null)
			clone.expirydate = null;
		else
			clone.expirydate = (ims.framework.utils.Date)this.expirydate.clone();
		if(this.currentstatus == null)
			clone.currentstatus = null;
		else
			clone.currentstatus = (ims.core.vo.lookups.PrivateInsuranceStatus)this.currentstatus.clone();
		if(this.statuschangedate == null)
			clone.statuschangedate = null;
		else
			clone.statuschangedate = (ims.framework.utils.Date)this.statuschangedate.clone();
		clone.planorunits = this.planorunits;
		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 (!(PatientMedicalInsuranceVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A PatientMedicalInsuranceVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((PatientMedicalInsuranceVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((PatientMedicalInsuranceVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.patient != null)
			count++;
		if(this.company != null)
			count++;
		if(this.policynumber != null)
			count++;
		if(this.policytype != null)
			count++;
		if(this.authorisationnumber != null)
			count++;
		if(this.expirydate != null)
			count++;
		if(this.currentstatus != null)
			count++;
		if(this.statuschangedate != null)
			count++;
		if(this.planorunits != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 9;
	}
	protected ims.core.patient.vo.PatientRefVo patient;
	protected ims.core.vo.PrivateInsuranceCompanyVo company;
	protected String policynumber;
	protected ims.core.vo.lookups.PrivateInsurancePolicyType policytype;
	protected String authorisationnumber;
	protected ims.framework.utils.Date expirydate;
	protected ims.core.vo.lookups.PrivateInsuranceStatus currentstatus;
	protected ims.framework.utils.Date statuschangedate;
	protected String planorunits;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
