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

/**
 * Linked to core.Documents.PatientDocument business object (ID: 1068100001).
 */
public class CheckedOutDocumentVo extends ims.core.documents.vo.PatientDocumentRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public CheckedOutDocumentVo()
	{
	}
	public CheckedOutDocumentVo(Integer id, int version)
	{
		super(id, version);
	}
	public CheckedOutDocumentVo(ims.correspondence.vo.beans.CheckedOutDocumentVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.patient = bean.getPatient() == null ? null : bean.getPatient().buildVo();
		this.name = bean.getName();
		this.lockedbyuser = bean.getLockedByUser() == null ? null : bean.getLockedByUser().buildVo();
		this.lockedondatetime = bean.getLockedOnDateTime() == null ? null : bean.getLockedOnDateTime().buildDateTime();
		this.islockedforediting = bean.getIsLockedForEditing();
		this.serverdocument = bean.getServerDocument() == null ? null : bean.getServerDocument().buildVo();
		this.documentdate = bean.getDocumentDate() == null ? null : bean.getDocumentDate().buildDate();
		this.ischecked = bean.getIsChecked();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.correspondence.vo.beans.CheckedOutDocumentVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.patient = bean.getPatient() == null ? null : bean.getPatient().buildVo(map);
		this.name = bean.getName();
		this.lockedbyuser = bean.getLockedByUser() == null ? null : bean.getLockedByUser().buildVo(map);
		this.lockedondatetime = bean.getLockedOnDateTime() == null ? null : bean.getLockedOnDateTime().buildDateTime();
		this.islockedforediting = bean.getIsLockedForEditing();
		this.serverdocument = bean.getServerDocument() == null ? null : bean.getServerDocument().buildVo(map);
		this.documentdate = bean.getDocumentDate() == null ? null : bean.getDocumentDate().buildDate();
		this.ischecked = bean.getIsChecked();
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.correspondence.vo.beans.CheckedOutDocumentVoBean bean = null;
		if(map != null)
			bean = (ims.correspondence.vo.beans.CheckedOutDocumentVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.correspondence.vo.beans.CheckedOutDocumentVoBean();
			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("NAME"))
			return getName();
		if(fieldName.equals("LOCKEDBYUSER"))
			return getLockedByUser();
		if(fieldName.equals("LOCKEDONDATETIME"))
			return getLockedOnDateTime();
		if(fieldName.equals("ISLOCKEDFOREDITING"))
			return getIsLockedForEditing();
		if(fieldName.equals("SERVERDOCUMENT"))
			return getServerDocument();
		if(fieldName.equals("DOCUMENTDATE"))
			return getDocumentDate();
		if(fieldName.equals("ISCHECKED"))
			return getIsChecked();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getPatientIsNotNull()
	{
		return this.patient != null;
	}
	public ims.core.vo.PatientLiteVo getPatient()
	{
		return this.patient;
	}
	public void setPatient(ims.core.vo.PatientLiteVo value)
	{
		this.isValidated = false;
		this.patient = value;
	}
	public boolean getNameIsNotNull()
	{
		return this.name != null;
	}
	public String getName()
	{
		return this.name;
	}
	public static int getNameMaxLength()
	{
		return 100;
	}
	public void setName(String value)
	{
		this.isValidated = false;
		this.name = value;
	}
	public boolean getLockedByUserIsNotNull()
	{
		return this.lockedbyuser != null;
	}
	public ims.core.vo.MemberOfStaffLiteVo getLockedByUser()
	{
		return this.lockedbyuser;
	}
	public void setLockedByUser(ims.core.vo.MemberOfStaffLiteVo value)
	{
		this.isValidated = false;
		this.lockedbyuser = value;
	}
	public boolean getLockedOnDateTimeIsNotNull()
	{
		return this.lockedondatetime != null;
	}
	public ims.framework.utils.DateTime getLockedOnDateTime()
	{
		return this.lockedondatetime;
	}
	public void setLockedOnDateTime(ims.framework.utils.DateTime value)
	{
		this.isValidated = false;
		this.lockedondatetime = value;
	}
	public boolean getIsLockedForEditingIsNotNull()
	{
		return this.islockedforediting != null;
	}
	public Boolean getIsLockedForEditing()
	{
		return this.islockedforediting;
	}
	public void setIsLockedForEditing(Boolean value)
	{
		this.isValidated = false;
		this.islockedforediting = value;
	}
	public boolean getServerDocumentIsNotNull()
	{
		return this.serverdocument != null;
	}
	public ims.core.vo.ServerDocumentVo getServerDocument()
	{
		return this.serverdocument;
	}
	public void setServerDocument(ims.core.vo.ServerDocumentVo value)
	{
		this.isValidated = false;
		this.serverdocument = value;
	}
	public boolean getDocumentDateIsNotNull()
	{
		return this.documentdate != null;
	}
	public ims.framework.utils.Date getDocumentDate()
	{
		return this.documentdate;
	}
	public void setDocumentDate(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.documentdate = value;
	}
	public boolean getIsCheckedIsNotNull()
	{
		return this.ischecked != null;
	}
	public Boolean getIsChecked()
	{
		return this.ischecked;
	}
	public void setIsChecked(Boolean value)
	{
		this.isValidated = false;
		this.ischecked = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.serverdocument != null)
		{
			if(!this.serverdocument.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.name == null || this.name.length() == 0)
			listOfErrors.add("Name is mandatory");
		else if(this.name.length() > 100)
			listOfErrors.add("The length of the field [name] in the value object [ims.correspondence.vo.CheckedOutDocumentVo] is too big. It should be less or equal to 100");
		if(this.serverdocument == null)
			listOfErrors.add("ServerDocument is mandatory");
		if(this.serverdocument != null)
		{
			String[] listOfOtherErrors = this.serverdocument.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;
	
		CheckedOutDocumentVo clone = new CheckedOutDocumentVo(this.id, this.version);
		
		if(this.patient == null)
			clone.patient = null;
		else
			clone.patient = (ims.core.vo.PatientLiteVo)this.patient.clone();
		clone.name = this.name;
		if(this.lockedbyuser == null)
			clone.lockedbyuser = null;
		else
			clone.lockedbyuser = (ims.core.vo.MemberOfStaffLiteVo)this.lockedbyuser.clone();
		if(this.lockedondatetime == null)
			clone.lockedondatetime = null;
		else
			clone.lockedondatetime = (ims.framework.utils.DateTime)this.lockedondatetime.clone();
		clone.islockedforediting = this.islockedforediting;
		if(this.serverdocument == null)
			clone.serverdocument = null;
		else
			clone.serverdocument = (ims.core.vo.ServerDocumentVo)this.serverdocument.clone();
		if(this.documentdate == null)
			clone.documentdate = null;
		else
			clone.documentdate = (ims.framework.utils.Date)this.documentdate.clone();
		clone.ischecked = this.ischecked;
		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 (!(CheckedOutDocumentVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A CheckedOutDocumentVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((CheckedOutDocumentVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((CheckedOutDocumentVo)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.name != null)
			count++;
		if(this.lockedbyuser != null)
			count++;
		if(this.lockedondatetime != null)
			count++;
		if(this.islockedforediting != null)
			count++;
		if(this.serverdocument != null)
			count++;
		if(this.documentdate != null)
			count++;
		if(this.ischecked != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 8;
	}
	protected ims.core.vo.PatientLiteVo patient;
	protected String name;
	protected ims.core.vo.MemberOfStaffLiteVo lockedbyuser;
	protected ims.framework.utils.DateTime lockedondatetime;
	protected Boolean islockedforediting;
	protected ims.core.vo.ServerDocumentVo serverdocument;
	protected ims.framework.utils.Date documentdate;
	protected Boolean ischecked;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
