/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/ValueObjects/src/ims/core/vo/Hcp.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.resource.people.Hcp business object (ID: 1006100000).
 */
public class Hcp extends ims.core.vo.HcpFilter implements ims.vo.ImsCloneable, Comparable, ims.vo.interfaces.IHcp, ims.vo.interfaces.IMos
{
	private static final long serialVersionUID = 1L;

	public Hcp()
	{
	}
	public Hcp(Integer id, int version)
	{
		super(id, version);
	}
	public Hcp(ims.core.vo.beans.HcpBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.hcptype = bean.getHcpType() == null ? null : ims.core.vo.lookups.HcpDisType.buildLookup(bean.getHcpType());
		this.queryname = bean.getQueryName() == null ? null : bean.getQueryName().buildVo();
		this.isactive = bean.getIsActive();
		this.mos = bean.getMos() == null ? null : bean.getMos().buildVo();
		this.ishcparesponsiblehcp = bean.getIsHCPaResponsibleHCP();
		this.isalocalconsultant = bean.getIsALocalConsultant();
		this.isaresponsibleedclinician = bean.getIsAResponsibleEDClinician();
		this.ishcpaendoscopist = bean.getIsHCPaEndoscopist();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.core.vo.beans.HcpBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.hcptype = bean.getHcpType() == null ? null : ims.core.vo.lookups.HcpDisType.buildLookup(bean.getHcpType());
		this.queryname = bean.getQueryName() == null ? null : bean.getQueryName().buildVo(map);
		this.isactive = bean.getIsActive();
		this.mos = bean.getMos() == null ? null : bean.getMos().buildVo(map);
		this.ishcparesponsiblehcp = bean.getIsHCPaResponsibleHCP();
		this.isalocalconsultant = bean.getIsALocalConsultant();
		this.isaresponsibleedclinician = bean.getIsAResponsibleEDClinician();
		this.ishcpaendoscopist = bean.getIsHCPaEndoscopist();
	}
	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.HcpBean bean = null;
		if(map != null)
			bean = (ims.core.vo.beans.HcpBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.core.vo.beans.HcpBean();
			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("ISACTIVE"))
			return getIsActive();
		if(fieldName.equals("MOS"))
			return getMos();
		if(fieldName.equals("ISHCPARESPONSIBLEHCP"))
			return getIsHCPaResponsibleHCP();
		if(fieldName.equals("ISALOCALCONSULTANT"))
			return getIsALocalConsultant();
		if(fieldName.equals("ISARESPONSIBLEEDCLINICIAN"))
			return getIsAResponsibleEDClinician();
		if(fieldName.equals("ISHCPAENDOSCOPIST"))
			return getIsHCPaEndoscopist();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getIsActiveIsNotNull()
	{
		return this.isactive != null;
	}
	public Boolean getIsActive()
	{
		return this.isactive;
	}
	public void setIsActive(Boolean value)
	{
		this.isValidated = false;
		this.isactive = value;
	}
	public boolean getMosIsNotNull()
	{
		return this.mos != null;
	}
	public ims.core.vo.MemberOfStaffShortVo getMos()
	{
		return this.mos;
	}
	public void setMos(ims.core.vo.MemberOfStaffShortVo value)
	{
		this.isValidated = false;
		this.mos = value;
	}
	public boolean getIsHCPaResponsibleHCPIsNotNull()
	{
		return this.ishcparesponsiblehcp != null;
	}
	public Boolean getIsHCPaResponsibleHCP()
	{
		return this.ishcparesponsiblehcp;
	}
	public void setIsHCPaResponsibleHCP(Boolean value)
	{
		this.isValidated = false;
		this.ishcparesponsiblehcp = value;
	}
	public boolean getIsALocalConsultantIsNotNull()
	{
		return this.isalocalconsultant != null;
	}
	public Boolean getIsALocalConsultant()
	{
		return this.isalocalconsultant;
	}
	public void setIsALocalConsultant(Boolean value)
	{
		this.isValidated = false;
		this.isalocalconsultant = value;
	}
	public boolean getIsAResponsibleEDClinicianIsNotNull()
	{
		return this.isaresponsibleedclinician != null;
	}
	public Boolean getIsAResponsibleEDClinician()
	{
		return this.isaresponsibleedclinician;
	}
	public void setIsAResponsibleEDClinician(Boolean value)
	{
		this.isValidated = false;
		this.isaresponsibleedclinician = value;
	}
	public boolean getIsHCPaEndoscopistIsNotNull()
	{
		return this.ishcpaendoscopist != null;
	}
	public Boolean getIsHCPaEndoscopist()
	{
		return this.ishcpaendoscopist;
	}
	public void setIsHCPaEndoscopist(Boolean value)
	{
		this.isValidated = false;
		this.ishcpaendoscopist = value;
	}
	/**
	* getName()
	*/
	public ims.core.vo.PersonName getName()
	{
		if (mos == null) return null;
		else return mos.getName();
	}
	/**
	* toString()
	*/
	public String toString()
	{
		if (this.mos != null && this.mos.getName() != null)
		{
			return this.mos.getName().toString();
		}
		else
		{
			return super.toString();
		}
	}
	/**
	* getHcpAsHTML: Get's a HTML string representation of this HCP.
	*/
	public String getHTMLString() 
	{
		if (this instanceof MedicVo)
			return getMedicHTML();
		else if (this instanceof TherapistVo)
			return getTherapistHTML();
		else if (this instanceof NurseVo)
			return getNurseHTML();
		else
		      return getOtherHTML();
	}
	public String getPasCode()
	{
		if (this.getMos() == null) 
			return null;
		return this.getMos().getPasCode();
	}
	public String getNationalConsCode()
	{
		if (this.getMos() == null) 
			return null;
		return this.getMos().getNationalConsCode();
	}
	
	private String getTherapistHTML()
	{
	      TherapistVo voTherapist = (TherapistVo)this;				
		StringBuffer sTherapist = new StringBuffer();
	
		sTherapist.append("<p><b>HCP Discipline : </b> Therapy</p>");
		if (voTherapist.getTherapistTypeIsNotNull())
		{
			sTherapist.append("<p><b>Therapist Type : </b>");
			sTherapist.append(voTherapist.getTherapistType().toString() + "</p>");
		}
	
		if (voTherapist.getSpecialtyIsNotNull())
		{
			sTherapist.append("<p><b>Specialty : </b>");
			sTherapist.append(voTherapist.getSpecialty().toString() + "</p>");
		}
	
		if (voTherapist.getPasCode() != null)
		{
			sTherapist.append("<p><b>PAS Code : </b>");
			sTherapist.append(voTherapist.getPasCode() + "</p>");
		}	
	
		if (Boolean.TRUE.equals(voTherapist.getIsHCPaResponsibleHCP()))
		{
			sTherapist.append("<p><b>HCP is a Responsible HCP.</b></p>");
		}
	
		if (Boolean.TRUE.equals(voTherapist.getIsAResponsibleEDClinician()))
		{
			sTherapist.append("<p><b>HCP is an ED Responsible Clinician.</b></p>");
		}
		
		return sTherapist.toString();
	
	}
	
	
	private String getNurseHTML() 
	{
	    NurseVo voNurse = (NurseVo)this;				
		StringBuffer sNurse = new StringBuffer();
	
		sNurse.append("<p><b>HCP Discipline : </b> Nursing</p>");
	
		if (voNurse.getNurseTypeIsNotNull())
		{
			sNurse.append("<p><b>Nurse Type : </b>");
			sNurse.append(voNurse.getNurseType().toString() + "</p>");
		}
	
		if (voNurse.getSpecialtyIsNotNull())
		{
			sNurse.append("<p><b>Specialty : </b>");
			sNurse.append(voNurse.getSpecialty().toString() + "</p>");
		}
	
		if (voNurse.getPasCode() != null)
		{
			sNurse.append("<p><b>PAS Code : </b>");
			sNurse.append(voNurse.getPasCode() + "</p>");
		}
	
		if (Boolean.TRUE.equals(voNurse.getIsHCPaResponsibleHCP()))
		{
			sNurse.append("<p><b>HCP is a Responsible HCP.</b></p>");
		}
	
		if (Boolean.TRUE.equals(voNurse.getIsAResponsibleEDClinician()))
		{
			sNurse.append("<p><b>HCP is an ED Responsible Clinician.</b></p>");
		}
	
		return sNurse.toString();
	}
	
	
	private String getMedicHTML() 
	{
	      MedicVo voMedic = (MedicVo)this;					
		StringBuffer sMedic = new StringBuffer();
	
		sMedic.append("<p><b>HCP Discipline : </b> Medical</p>");
		if (voMedic.getMedicTypeIsNotNull())
		{
			sMedic.append("<p><b>Medic Type : </b>");
			sMedic.append(voMedic.getMedicType().toString() + "</p>");
		}
		if (voMedic.getGradeIsNotNull())
		{
			sMedic.append("<p><b>Medical Grade : </b>");
			sMedic.append(voMedic.getGrade().toString() + "</p>");
		}
		if (voMedic.getSpecialtyIsNotNull())
		{
			sMedic.append("<p><b>Specialty : </b>");
			sMedic.append(voMedic.getSpecialty().toString() + "</p>");
		}
		if (voMedic.getNationalConsCode() != null)
		{
			sMedic.append("<p><b>National Consultant Code : </b>");
			sMedic.append(voMedic.getNationalConsCode() + "</p>");
		}
		if (voMedic.getPasCode() != null)
		{
			sMedic.append("<p><b>PAS Code : </b>");
			sMedic.append(voMedic.getPasCode() + "</p>");			
		}
		
		if (Boolean.TRUE.equals(voMedic.getIsHCPaResponsibleHCP()))
		{
			sMedic.append("<p><b>HCP is a Responsible HCP.</b></p>");
		}
		
		if (Boolean.TRUE.equals(voMedic.getIsAResponsibleEDClinician()))
		{
			sMedic.append("<p><b>HCP is an ED Responsible Clinician.</b></p>");
		}
		
		return sMedic.toString();
	}
	
	private String getOtherHTML()
	{
		StringBuffer sHcp = new StringBuffer();
		sHcp.append("<p><b>HCP Discipline : </b> Other</p>");
	
		if (this.getHcpTypeIsNotNull())
		{
			sHcp.append("<p><b>HCP Type : </b>");
			sHcp.append(this.getHcpType().toString() + "</p>");
		}
	
		if (this.getPasCode() != null)
		{
			sHcp.append("<p><b>PAS Code : </b>");
			sHcp.append(this.getPasCode() + "</p>");
		}
	
		if (Boolean.TRUE.equals(this.getIsHCPaResponsibleHCP()))
		{
			sHcp.append("<p><b>HCP is a Responsible HCP.</b></p>");
		}
	
		return sHcp.toString();
	}				
	/**
	* Extract a representative HCP VO instance from the given User instance
	*/
	public static ims.core.vo.Hcp extractHcpFromUser(ims.framework.interfaces.IAppUser user)
	{
		ims.core.vo.Hcp hcp = new ims.core.vo.Hcp();
		hcp.setID_Hcp(user.getHcpId());
		ims.core.vo.PersonName name = new ims.core.vo.PersonName();
		name.setSurname(user.getUserRealName());
		ims.core.vo.MemberOfStaffShortVo mos = new ims.core.vo.MemberOfStaffShortVo();
		mos.setName(name);
		hcp.setMos(mos);
		return hcp;
	}
	/**
	* IHcp Interface methods
	*/
		public Integer getIHcpId()
		{
			return this.id;
		}
		public String getIHcpName()
		{
			ims.core.vo.PersonName name = getName();
			if(name != null)
				return name.toString();
				
			return null;
		}
	/**
	* IMos Interface Methods
	*/
	public Integer getIMosId()
	{
		if(mos!= null)
			return mos.getID_MemberOfStaff();
	
		return null;
	}
	public String getIMosName()
	{
		ims.core.vo.PersonName name = getName();
		if(name != null)
			return name.toString();
			
		return null;
	}
	public Integer getIMosHcpId()
	{
		return this.id;
	}
	/**
	* toHcpLiteVo()
	*/
	public HcpLiteVo toHcpLiteVo()
	{
		HcpLiteVo hcp = new HcpLiteVo(this.id, this.version);
		
		hcp.setMos(this.mos);
		hcp.setIsActive(this.isactive);
		hcp.setHcpType(this.hcptype);
		hcp.setIsHCPaResponsibleHCP(this.ishcparesponsiblehcp);
		hcp.setIsAResponsibleEDClinician(this.isaresponsibleedclinician);
		hcp.setIsHCPaEndoscopist(this.ishcpaendoscopist);
	
		return hcp;
	}
	
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.queryname != null)
		{
			if(!this.queryname.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.mos != null)
		{
			if(!this.mos.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.queryname != null)
		{
			String[] listOfOtherErrors = this.queryname.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.mos != null)
		{
			String[] listOfOtherErrors = this.mos.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;
	
		Hcp clone = new Hcp(this.id, this.version);
		
		if(this.hcptype == null)
			clone.hcptype = null;
		else
			clone.hcptype = (ims.core.vo.lookups.HcpDisType)this.hcptype.clone();
		if(this.queryname == null)
			clone.queryname = null;
		else
			clone.queryname = (ims.core.vo.PersonName)this.queryname.clone();
		clone.isactive = this.isactive;
		if(this.mos == null)
			clone.mos = null;
		else
			clone.mos = (ims.core.vo.MemberOfStaffShortVo)this.mos.clone();
		clone.ishcparesponsiblehcp = this.ishcparesponsiblehcp;
		clone.isalocalconsultant = this.isalocalconsultant;
		clone.isaresponsibleedclinician = this.isaresponsibleedclinician;
		clone.ishcpaendoscopist = this.ishcpaendoscopist;
		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 (!(Hcp.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A Hcp object cannot be compared an Object of type " + obj.getClass().getName());
		}
		Hcp compareObj = (Hcp)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getMos() == null && compareObj.getMos() != null)
				return -1;
			if(this.getMos() != null && compareObj.getMos() == null)
				return 1;
			if(this.getMos() != null && compareObj.getMos() != null)
				retVal = this.getMos().compareTo(compareObj.getMos());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = super.countFieldsWithValue();
		if(this.isactive != null)
			count++;
		if(this.mos != null)
			count++;
		if(this.ishcparesponsiblehcp != null)
			count++;
		if(this.isalocalconsultant != null)
			count++;
		if(this.isaresponsibleedclinician != null)
			count++;
		if(this.ishcpaendoscopist != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return super.countValueObjectFields() + 6;
	}
	protected Boolean isactive;
	protected ims.core.vo.MemberOfStaffShortVo mos;
	protected Boolean ishcparesponsiblehcp;
	protected Boolean isalocalconsultant;
	protected Boolean isaresponsibleedclinician;
	protected Boolean ishcpaendoscopist;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
