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

/**
 * Linked to eDischarge.TTAMedication business object (ID: 1099100003).
 */
public class TTOMedicationVo extends ims.edischarge.vo.TTAMedicationRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public TTOMedicationVo()
	{
	}
	public TTOMedicationVo(Integer id, int version)
	{
		super(id, version);
	}
	public TTOMedicationVo(ims.clinical.vo.beans.TTOMedicationVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.dispensegivecode = bean.getDispenseGiveCode();
		this.datedispensed = bean.getDateDispensed() == null ? null : bean.getDateDispensed().buildDateTime();
		this.actualdispenseamount = bean.getActualDispenseAmount();
		this.actualdispenseunits = bean.getActualDispenseUnits() == null ? null : ims.core.vo.lookups.MedicationDoseUnit.buildLookup(bean.getActualDispenseUnits());
		this.noofrefillsremaining = bean.getNoOfRefillsRemaining();
		this.dispensenotes = bean.getDispenseNotes();
		this.needshumanreview = bean.getNeedsHumanReview() == null ? null : ims.core.vo.lookups.YesNo.buildLookup(bean.getNeedsHumanReview());
		this.specialdispensinginstructions = bean.getSpecialDispensingInstructions();
		this.sortorder = bean.getSortOrder();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.clinical.vo.beans.TTOMedicationVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.dispensegivecode = bean.getDispenseGiveCode();
		this.datedispensed = bean.getDateDispensed() == null ? null : bean.getDateDispensed().buildDateTime();
		this.actualdispenseamount = bean.getActualDispenseAmount();
		this.actualdispenseunits = bean.getActualDispenseUnits() == null ? null : ims.core.vo.lookups.MedicationDoseUnit.buildLookup(bean.getActualDispenseUnits());
		this.noofrefillsremaining = bean.getNoOfRefillsRemaining();
		this.dispensenotes = bean.getDispenseNotes();
		this.needshumanreview = bean.getNeedsHumanReview() == null ? null : ims.core.vo.lookups.YesNo.buildLookup(bean.getNeedsHumanReview());
		this.specialdispensinginstructions = bean.getSpecialDispensingInstructions();
		this.sortorder = bean.getSortOrder();
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.clinical.vo.beans.TTOMedicationVoBean bean = null;
		if(map != null)
			bean = (ims.clinical.vo.beans.TTOMedicationVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.clinical.vo.beans.TTOMedicationVoBean();
			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("DISPENSEGIVECODE"))
			return getDispenseGiveCode();
		if(fieldName.equals("DATEDISPENSED"))
			return getDateDispensed();
		if(fieldName.equals("ACTUALDISPENSEAMOUNT"))
			return getActualDispenseAmount();
		if(fieldName.equals("ACTUALDISPENSEUNITS"))
			return getActualDispenseUnits();
		if(fieldName.equals("NOOFREFILLSREMAINING"))
			return getNoOfRefillsRemaining();
		if(fieldName.equals("DISPENSENOTES"))
			return getDispenseNotes();
		if(fieldName.equals("NEEDSHUMANREVIEW"))
			return getNeedsHumanReview();
		if(fieldName.equals("SPECIALDISPENSINGINSTRUCTIONS"))
			return getSpecialDispensingInstructions();
		if(fieldName.equals("SORTORDER"))
			return getSortOrder();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getDispenseGiveCodeIsNotNull()
	{
		return this.dispensegivecode != null;
	}
	public String getDispenseGiveCode()
	{
		return this.dispensegivecode;
	}
	public static int getDispenseGiveCodeMaxLength()
	{
		return 100;
	}
	public void setDispenseGiveCode(String value)
	{
		this.isValidated = false;
		this.dispensegivecode = value;
	}
	public boolean getDateDispensedIsNotNull()
	{
		return this.datedispensed != null;
	}
	public ims.framework.utils.DateTime getDateDispensed()
	{
		return this.datedispensed;
	}
	public void setDateDispensed(ims.framework.utils.DateTime value)
	{
		this.isValidated = false;
		this.datedispensed = value;
	}
	public boolean getActualDispenseAmountIsNotNull()
	{
		return this.actualdispenseamount != null;
	}
	public Float getActualDispenseAmount()
	{
		return this.actualdispenseamount;
	}
	public void setActualDispenseAmount(Float value)
	{
		this.isValidated = false;
		this.actualdispenseamount = value;
	}
	public boolean getActualDispenseUnitsIsNotNull()
	{
		return this.actualdispenseunits != null;
	}
	public ims.core.vo.lookups.MedicationDoseUnit getActualDispenseUnits()
	{
		return this.actualdispenseunits;
	}
	public void setActualDispenseUnits(ims.core.vo.lookups.MedicationDoseUnit value)
	{
		this.isValidated = false;
		this.actualdispenseunits = value;
	}
	public boolean getNoOfRefillsRemainingIsNotNull()
	{
		return this.noofrefillsremaining != null;
	}
	public Integer getNoOfRefillsRemaining()
	{
		return this.noofrefillsremaining;
	}
	public void setNoOfRefillsRemaining(Integer value)
	{
		this.isValidated = false;
		this.noofrefillsremaining = value;
	}
	public boolean getDispenseNotesIsNotNull()
	{
		return this.dispensenotes != null;
	}
	public String getDispenseNotes()
	{
		return this.dispensenotes;
	}
	public static int getDispenseNotesMaxLength()
	{
		return 200;
	}
	public void setDispenseNotes(String value)
	{
		this.isValidated = false;
		this.dispensenotes = value;
	}
	public boolean getNeedsHumanReviewIsNotNull()
	{
		return this.needshumanreview != null;
	}
	public ims.core.vo.lookups.YesNo getNeedsHumanReview()
	{
		return this.needshumanreview;
	}
	public void setNeedsHumanReview(ims.core.vo.lookups.YesNo value)
	{
		this.isValidated = false;
		this.needshumanreview = value;
	}
	public boolean getSpecialDispensingInstructionsIsNotNull()
	{
		return this.specialdispensinginstructions != null;
	}
	public String getSpecialDispensingInstructions()
	{
		return this.specialdispensinginstructions;
	}
	public static int getSpecialDispensingInstructionsMaxLength()
	{
		return 255;
	}
	public void setSpecialDispensingInstructions(String value)
	{
		this.isValidated = false;
		this.specialdispensinginstructions = value;
	}
	public boolean getSortOrderIsNotNull()
	{
		return this.sortorder != null;
	}
	public Integer getSortOrder()
	{
		return this.sortorder;
	}
	public void setSortOrder(Integer value)
	{
		this.isValidated = false;
		this.sortorder = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.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.dispensegivecode != null)
			if(this.dispensegivecode.length() > 100)
				listOfErrors.add("The length of the field [dispensegivecode] in the value object [ims.clinical.vo.TTOMedicationVo] is too big. It should be less or equal to 100");
		if(this.dispensenotes != null)
			if(this.dispensenotes.length() > 200)
				listOfErrors.add("The length of the field [dispensenotes] in the value object [ims.clinical.vo.TTOMedicationVo] is too big. It should be less or equal to 200");
		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;
	
		TTOMedicationVo clone = new TTOMedicationVo(this.id, this.version);
		
		clone.dispensegivecode = this.dispensegivecode;
		if(this.datedispensed == null)
			clone.datedispensed = null;
		else
			clone.datedispensed = (ims.framework.utils.DateTime)this.datedispensed.clone();
		clone.actualdispenseamount = this.actualdispenseamount;
		if(this.actualdispenseunits == null)
			clone.actualdispenseunits = null;
		else
			clone.actualdispenseunits = (ims.core.vo.lookups.MedicationDoseUnit)this.actualdispenseunits.clone();
		clone.noofrefillsremaining = this.noofrefillsremaining;
		clone.dispensenotes = this.dispensenotes;
		if(this.needshumanreview == null)
			clone.needshumanreview = null;
		else
			clone.needshumanreview = (ims.core.vo.lookups.YesNo)this.needshumanreview.clone();
		clone.specialdispensinginstructions = this.specialdispensinginstructions;
		clone.sortorder = this.sortorder;
		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 (!(TTOMedicationVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A TTOMedicationVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((TTOMedicationVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((TTOMedicationVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.dispensegivecode != null)
			count++;
		if(this.datedispensed != null)
			count++;
		if(this.actualdispenseamount != null)
			count++;
		if(this.actualdispenseunits != null)
			count++;
		if(this.noofrefillsremaining != null)
			count++;
		if(this.dispensenotes != null)
			count++;
		if(this.needshumanreview != null)
			count++;
		if(this.specialdispensinginstructions != null)
			count++;
		if(this.sortorder != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 9;
	}
	protected String dispensegivecode;
	protected ims.framework.utils.DateTime datedispensed;
	protected Float actualdispenseamount;
	protected ims.core.vo.lookups.MedicationDoseUnit actualdispenseunits;
	protected Integer noofrefillsremaining;
	protected String dispensenotes;
	protected ims.core.vo.lookups.YesNo needshumanreview;
	protected String specialdispensinginstructions;
	protected Integer sortorder;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
