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

/**
 * Linked to emergency.Tracking business object (ID: 1086100005).
 */
public class Tracking_TrackingAttendanceWorklistVo extends ims.emergency.vo.TrackingRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public Tracking_TrackingAttendanceWorklistVo()
	{
	}
	public Tracking_TrackingAttendanceWorklistVo(Integer id, int version)
	{
		super(id, version);
	}
	public Tracking_TrackingAttendanceWorklistVo(ims.emergency.vo.beans.Tracking_TrackingAttendanceWorklistVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.patient = bean.getPatient() == null ? null : bean.getPatient().buildVo();
		this.attendance = bean.getAttendance() == null ? null : bean.getAttendance().buildVo();
		this.triagedetails = bean.getTriageDetails() == null ? null : bean.getTriageDetails().buildVo();
		this.currentstatus = bean.getCurrentStatus() == null ? null : bean.getCurrentStatus().buildVo();
		this.isdischarged = bean.getIsDischarged();
		this.currentarea = bean.getCurrentArea() == null ? null : bean.getCurrentArea().buildVo();
		this.hospitalno = bean.getHospitalNo();
		this.los = bean.getLOS();
		this.seenby = bean.getSeenBy() == null ? null : bean.getSeenBy().buildVo();
		this.seenbynurse = bean.getSeenByNurse() == null ? null : bean.getSeenByNurse().buildVo();
		this.requiringdischargedocumentationreview = bean.getRequiringDischargeDocumentationReview();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.emergency.vo.beans.Tracking_TrackingAttendanceWorklistVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.patient = bean.getPatient() == null ? null : bean.getPatient().buildVo(map);
		this.attendance = bean.getAttendance() == null ? null : bean.getAttendance().buildVo(map);
		this.triagedetails = bean.getTriageDetails() == null ? null : bean.getTriageDetails().buildVo(map);
		this.currentstatus = bean.getCurrentStatus() == null ? null : bean.getCurrentStatus().buildVo(map);
		this.isdischarged = bean.getIsDischarged();
		this.currentarea = bean.getCurrentArea() == null ? null : bean.getCurrentArea().buildVo(map);
		this.hospitalno = bean.getHospitalNo();
		this.los = bean.getLOS();
		this.seenby = bean.getSeenBy() == null ? null : bean.getSeenBy().buildVo(map);
		this.seenbynurse = bean.getSeenByNurse() == null ? null : bean.getSeenByNurse().buildVo(map);
		this.requiringdischargedocumentationreview = bean.getRequiringDischargeDocumentationReview();
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.emergency.vo.beans.Tracking_TrackingAttendanceWorklistVoBean bean = null;
		if(map != null)
			bean = (ims.emergency.vo.beans.Tracking_TrackingAttendanceWorklistVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.emergency.vo.beans.Tracking_TrackingAttendanceWorklistVoBean();
			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("ATTENDANCE"))
			return getAttendance();
		if(fieldName.equals("TRIAGEDETAILS"))
			return getTriageDetails();
		if(fieldName.equals("CURRENTSTATUS"))
			return getCurrentStatus();
		if(fieldName.equals("ISDISCHARGED"))
			return getIsDischarged();
		if(fieldName.equals("CURRENTAREA"))
			return getCurrentArea();
		if(fieldName.equals("HOSPITALNO"))
			return getHospitalNo();
		if(fieldName.equals("LOS"))
			return getLOS();
		if(fieldName.equals("SEENBY"))
			return getSeenBy();
		if(fieldName.equals("SEENBYNURSE"))
			return getSeenByNurse();
		if(fieldName.equals("REQUIRINGDISCHARGEDOCUMENTATIONREVIEW"))
			return getRequiringDischargeDocumentationReview();
		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 getAttendanceIsNotNull()
	{
		return this.attendance != null;
	}
	public ims.emergency.vo.EmergencyAttendance_TracklistVo getAttendance()
	{
		return this.attendance;
	}
	public void setAttendance(ims.emergency.vo.EmergencyAttendance_TracklistVo value)
	{
		this.isValidated = false;
		this.attendance = value;
	}
	public boolean getTriageDetailsIsNotNull()
	{
		return this.triagedetails != null;
	}
	public ims.emergency.vo.TriageForTrackingVo getTriageDetails()
	{
		return this.triagedetails;
	}
	public void setTriageDetails(ims.emergency.vo.TriageForTrackingVo value)
	{
		this.isValidated = false;
		this.triagedetails = value;
	}
	public boolean getCurrentStatusIsNotNull()
	{
		return this.currentstatus != null;
	}
	public ims.emergency.vo.TrackingAttendanceStatusForTrackingVo getCurrentStatus()
	{
		return this.currentstatus;
	}
	public void setCurrentStatus(ims.emergency.vo.TrackingAttendanceStatusForTrackingVo value)
	{
		this.isValidated = false;
		this.currentstatus = value;
	}
	public boolean getIsDischargedIsNotNull()
	{
		return this.isdischarged != null;
	}
	public Boolean getIsDischarged()
	{
		return this.isdischarged;
	}
	public void setIsDischarged(Boolean value)
	{
		this.isValidated = false;
		this.isdischarged = value;
	}
	public boolean getCurrentAreaIsNotNull()
	{
		return this.currentarea != null;
	}
	public ims.emergency.vo.TrackingAreaForTrackingLiteVo getCurrentArea()
	{
		return this.currentarea;
	}
	public void setCurrentArea(ims.emergency.vo.TrackingAreaForTrackingLiteVo value)
	{
		this.isValidated = false;
		this.currentarea = value;
	}
	public boolean getHospitalNoIsNotNull()
	{
		return this.hospitalno != null;
	}
	public String getHospitalNo()
	{
		return this.hospitalno;
	}
	public static int getHospitalNoMaxLength()
	{
		return 255;
	}
	public void setHospitalNo(String value)
	{
		this.isValidated = false;
		this.hospitalno = value;
	}
	public boolean getLOSIsNotNull()
	{
		return this.los != null;
	}
	public Integer getLOS()
	{
		return this.los;
	}
	public void setLOS(Integer value)
	{
		this.isValidated = false;
		this.los = value;
	}
	public boolean getSeenByIsNotNull()
	{
		return this.seenby != null;
	}
	public ims.emergency.vo.SeenByForTrackingAndAttendanceWorklistVo getSeenBy()
	{
		return this.seenby;
	}
	public void setSeenBy(ims.emergency.vo.SeenByForTrackingAndAttendanceWorklistVo value)
	{
		this.isValidated = false;
		this.seenby = value;
	}
	public boolean getSeenByNurseIsNotNull()
	{
		return this.seenbynurse != null;
	}
	public ims.emergency.vo.SeenByForTrackingAndAttendanceWorklistVo getSeenByNurse()
	{
		return this.seenbynurse;
	}
	public void setSeenByNurse(ims.emergency.vo.SeenByForTrackingAndAttendanceWorklistVo value)
	{
		this.isValidated = false;
		this.seenbynurse = value;
	}
	public boolean getRequiringDischargeDocumentationReviewIsNotNull()
	{
		return this.requiringdischargedocumentationreview != null;
	}
	public Boolean getRequiringDischargeDocumentationReview()
	{
		return this.requiringdischargedocumentationreview;
	}
	public void setRequiringDischargeDocumentationReview(Boolean value)
	{
		this.isValidated = false;
		this.requiringdischargedocumentationreview = value;
	}
	/**
	* calculate LOS
	*/
	public void calculateLOS()
	{
		if( ims.configuration.gen.ConfigFlag.DOM.STARTTIME_FOR_LOS_AND_BREACH_CALCULATIONS.getValue().equals("RegistrationDateTime"))	//wdev-18327
		{
			if (Boolean.TRUE.equals(this.isdischarged) && this.attendance.getDischargeDateTime() != null)
	    		{
	    			long minuteDifference = (this.attendance.getDischargeDateTime().getJavaDate().getTime() - this.attendance.getRegistrationDateTime().getJavaDate().getTime()) / (1000 * 60);
	    				
	    			this.los = (int) minuteDifference;
	    		}
	    		else
	    		{
	    			long minuteDifference = (new ims.framework.utils.DateTime().getJavaDate().getTime() - this.attendance.getRegistrationDateTime().getJavaDate().getTime()) / (1000 * 60);
	    			
	    			this.los = (int) minuteDifference;
	    		}
		}
		else
		{
	    		if (Boolean.TRUE.equals(this.isdischarged) && this.attendance.getDischargeDateTime() != null)
	    		{
	    			long minuteDifference = (this.attendance.getDischargeDateTime().getJavaDate().getTime() - this.attendance.getArrivalDateTime().getJavaDate().getTime()) / (1000 * 60);
	    				
	    			this.los = (int) minuteDifference;
	    		}
	    		else
	    		{
	    			long minuteDifference = (new ims.framework.utils.DateTime().getJavaDate().getTime() - this.attendance.getArrivalDateTime().getJavaDate().getTime()) / (1000 * 60);
	    			
	    			this.los = (int) minuteDifference;
	    		}
		}
	}
	
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.patient != null)
		{
			if(!this.patient.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.patient != null)
		{
			String[] listOfOtherErrors = this.patient.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.attendance == null)
			listOfErrors.add("Attendance is mandatory");
		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;
	
		Tracking_TrackingAttendanceWorklistVo clone = new Tracking_TrackingAttendanceWorklistVo(this.id, this.version);
		
		if(this.patient == null)
			clone.patient = null;
		else
			clone.patient = (ims.core.vo.PatientLiteVo)this.patient.clone();
		if(this.attendance == null)
			clone.attendance = null;
		else
			clone.attendance = (ims.emergency.vo.EmergencyAttendance_TracklistVo)this.attendance.clone();
		if(this.triagedetails == null)
			clone.triagedetails = null;
		else
			clone.triagedetails = (ims.emergency.vo.TriageForTrackingVo)this.triagedetails.clone();
		if(this.currentstatus == null)
			clone.currentstatus = null;
		else
			clone.currentstatus = (ims.emergency.vo.TrackingAttendanceStatusForTrackingVo)this.currentstatus.clone();
		clone.isdischarged = this.isdischarged;
		if(this.currentarea == null)
			clone.currentarea = null;
		else
			clone.currentarea = (ims.emergency.vo.TrackingAreaForTrackingLiteVo)this.currentarea.clone();
		clone.hospitalno = this.hospitalno;
		clone.los = this.los;
		if(this.seenby == null)
			clone.seenby = null;
		else
			clone.seenby = (ims.emergency.vo.SeenByForTrackingAndAttendanceWorklistVo)this.seenby.clone();
		if(this.seenbynurse == null)
			clone.seenbynurse = null;
		else
			clone.seenbynurse = (ims.emergency.vo.SeenByForTrackingAndAttendanceWorklistVo)this.seenbynurse.clone();
		clone.requiringdischargedocumentationreview = this.requiringdischargedocumentationreview;
		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 (!(Tracking_TrackingAttendanceWorklistVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A Tracking_TrackingAttendanceWorklistVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		Tracking_TrackingAttendanceWorklistVo compareObj = (Tracking_TrackingAttendanceWorklistVo)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getAttendance() == null && compareObj.getAttendance() != null)
				return -1;
			if(this.getAttendance() != null && compareObj.getAttendance() == null)
				return 1;
			if(this.getAttendance() != null && compareObj.getAttendance() != null)
				retVal = this.getAttendance().compareTo(compareObj.getAttendance());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.patient != null)
			count++;
		if(this.attendance != null)
			count++;
		if(this.triagedetails != null)
			count++;
		if(this.currentstatus != null)
			count++;
		if(this.isdischarged != null)
			count++;
		if(this.currentarea != null)
			count++;
		if(this.hospitalno != null)
			count++;
		if(this.los != null)
			count++;
		if(this.seenby != null)
			count++;
		if(this.seenbynurse != null)
			count++;
		if(this.requiringdischargedocumentationreview != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 11;
	}
	protected ims.core.vo.PatientLiteVo patient;
	protected ims.emergency.vo.EmergencyAttendance_TracklistVo attendance;
	protected ims.emergency.vo.TriageForTrackingVo triagedetails;
	protected ims.emergency.vo.TrackingAttendanceStatusForTrackingVo currentstatus;
	protected Boolean isdischarged;
	protected ims.emergency.vo.TrackingAreaForTrackingLiteVo currentarea;
	protected String hospitalno;
	protected Integer los;
	protected ims.emergency.vo.SeenByForTrackingAndAttendanceWorklistVo seenby;
	protected ims.emergency.vo.SeenByForTrackingAndAttendanceWorklistVo seenbynurse;
	protected Boolean requiringdischargedocumentationreview;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
