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

	public NextOfKin()
	{
	}
	public NextOfKin(Integer id, int version)
	{
		super(id, version);
	}
	public NextOfKin(ims.core.vo.beans.NextOfKinBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.name = bean.getName() == null ? null : bean.getName().buildVo();
		this.address = bean.getAddress() == null ? null : bean.getAddress().buildVo();
		this.relationship = bean.getRelationship() == null ? null : ims.core.vo.lookups.PersonRelationship.buildLookup(bean.getRelationship());
		this.commchannels = ims.core.vo.CommChannelVoCollection.buildFromBeanCollection(bean.getCommChannels());
		this.pdsupdatemode = bean.getPdsUpdateMode() == null ? null : ims.core.vo.lookups.PDSUpdateMode.buildLookup(bean.getPdsUpdateMode());
		this.objectidentifier = bean.getObjectidentifier();
		this.role = bean.getRole() == null ? null : ims.core.vo.lookups.PDSPersonRole.buildLookup(bean.getRole());
		this.nhsnum = bean.getNhsNum();
		this.contactrank = bean.getContactRank();
		this.nokind = bean.getNokInd();
		this.cpycorresp = bean.getCpyCorresp();
		this.callbckcons = bean.getCallbckCons() == null ? null : ims.core.vo.lookups.PDSConsent.buildLookup(bean.getCallbckCons());
		this.beffdatecnf = bean.getBeffdatecnf();
		this.betdatecnf = bean.getBetdatecnf();
		this.beffdate = bean.getBeffdate() == null ? null : bean.getBeffdate().buildDate();
		this.betdate = bean.getBetdate() == null ? null : bean.getBetdate().buildDate();
		this.dob = bean.getDob() == null ? null : bean.getDob().buildPartialDate();
		this.active = bean.getActive();
		this.pdscontactpreferences = bean.getPDScontactPreferences() == null ? null : bean.getPDScontactPreferences().buildVo();
		this.pdslanguage = bean.getPDSlanguage() == null ? null : ims.core.vo.lookups.PDSPreferredCommunicationLanguage.buildLookup(bean.getPDSlanguage());
		this.pdsinterpreterrequired = bean.getPDSInterpreterRequired();
		this.pending = bean.getPending();
		this.isconfidential = bean.getIsConfidential();
		this.timestamp = bean.getTimestamp();
		this.tempfield = bean.getTempField();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.core.vo.beans.NextOfKinBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.name = bean.getName() == null ? null : bean.getName().buildVo(map);
		this.address = bean.getAddress() == null ? null : bean.getAddress().buildVo(map);
		this.relationship = bean.getRelationship() == null ? null : ims.core.vo.lookups.PersonRelationship.buildLookup(bean.getRelationship());
		this.commchannels = ims.core.vo.CommChannelVoCollection.buildFromBeanCollection(bean.getCommChannels());
		this.pdsupdatemode = bean.getPdsUpdateMode() == null ? null : ims.core.vo.lookups.PDSUpdateMode.buildLookup(bean.getPdsUpdateMode());
		this.objectidentifier = bean.getObjectidentifier();
		this.role = bean.getRole() == null ? null : ims.core.vo.lookups.PDSPersonRole.buildLookup(bean.getRole());
		this.nhsnum = bean.getNhsNum();
		this.contactrank = bean.getContactRank();
		this.nokind = bean.getNokInd();
		this.cpycorresp = bean.getCpyCorresp();
		this.callbckcons = bean.getCallbckCons() == null ? null : ims.core.vo.lookups.PDSConsent.buildLookup(bean.getCallbckCons());
		this.beffdatecnf = bean.getBeffdatecnf();
		this.betdatecnf = bean.getBetdatecnf();
		this.beffdate = bean.getBeffdate() == null ? null : bean.getBeffdate().buildDate();
		this.betdate = bean.getBetdate() == null ? null : bean.getBetdate().buildDate();
		this.dob = bean.getDob() == null ? null : bean.getDob().buildPartialDate();
		this.active = bean.getActive();
		this.pdscontactpreferences = bean.getPDScontactPreferences() == null ? null : bean.getPDScontactPreferences().buildVo(map);
		this.pdslanguage = bean.getPDSlanguage() == null ? null : ims.core.vo.lookups.PDSPreferredCommunicationLanguage.buildLookup(bean.getPDSlanguage());
		this.pdsinterpreterrequired = bean.getPDSInterpreterRequired();
		this.pending = bean.getPending();
		this.isconfidential = bean.getIsConfidential();
		this.timestamp = bean.getTimestamp();
		this.tempfield = bean.getTempField();
	}
	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.NextOfKinBean bean = null;
		if(map != null)
			bean = (ims.core.vo.beans.NextOfKinBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.core.vo.beans.NextOfKinBean();
			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("TEMPFIELD"))
			return getTempField();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getTempFieldIsNotNull()
	{
		return this.tempfield != null;
	}
	public String getTempField()
	{
		return this.tempfield;
	}
	public static int getTempFieldMaxLength()
	{
		return 50;
	}
	public void setTempField(String value)
	{
		this.isValidated = false;
		this.tempfield = value;
	}
	/**
	* getNOKInfo: Get's a HTML string representation of this NOK.
	*/
	public String getHTMLString() 
	{
	    	NextOfKin voNextOfKin = this;					
	    	StringBuffer strNOK = new StringBuffer();
			
		if (voNextOfKin.getNameIsNotNull())
		{
			strNOK.append("<p><b>Name         : </b>");
			strNOK.append(voNextOfKin.getName().toString() + "</p>");
			strNOK.append("<p>&nbsp;</p>");			
		}
		if (voNextOfKin.getAddressIsNotNull())
		{
			strNOK.append("<p><b>Address      : </b>");
			strNOK.append("<address>");
			if(voNextOfKin.getAddress().getLine1IsNotNull())
				strNOK.append(voNextOfKin.getAddress().getLine1().toString() + "<br>");
			if(voNextOfKin.getAddress().getLine2IsNotNull())
				strNOK.append(voNextOfKin.getAddress().getLine2().toString() + "<br>");
			if(voNextOfKin.getAddress().getLine3IsNotNull())
				strNOK.append(voNextOfKin.getAddress().getLine3().toString() + "<br>");
			if(voNextOfKin.getAddress().getLine4IsNotNull())
				strNOK.append(voNextOfKin.getAddress().getLine4().toString() + "<br>");
			if(voNextOfKin.getAddress().getLine5IsNotNull())
				strNOK.append(voNextOfKin.getAddress().getLine5().toString());
			strNOK.append("</address>");
			strNOK.append("<p>&nbsp;</p>");			
		}
		if (voNextOfKin.getAddressIsNotNull())
		{
			strNOK.append("<p><b>Post Code    : </b>");
			if(voNextOfKin.getAddress().getPostCodeIsNotNull())
				strNOK.append(voNextOfKin.getAddress().getPostCode().toString() + "</p>");
			strNOK.append("<p>&nbsp;</p>");			
		}		
		if (voNextOfKin.getAddressIsNotNull())
		{
			strNOK.append("<p><b>Phone Number : </b>");
			if(voNextOfKin.getAddress().getPhoneIsNotNull())
				strNOK.append(voNextOfKin.getAddress().getPhone().toString() + "</p>");
			strNOK.append("<p>&nbsp;</p>");			
		}		
		if (voNextOfKin.getRelationshipIsNotNull())
		{
			strNOK.append("<p><b>Relationship : </b>");
			strNOK.append(voNextOfKin.getRelationship().toString() + "</p>");
			strNOK.append("<p>&nbsp;</p>");			
		}	
		return strNOK.toString();
	}
	/**
	* getCommunicationChannel - Returns the Communication Channel for a specified channel type
	*/
	public ims.core.vo.CommChannelVo getCommunicationChannel(ims.core.vo.lookups.ChannelType channelType)
	{
		if (commchannels == null) return null;
		for (int i = 0; i < commchannels.size(); i++)
		{
			ims.core.vo.CommChannelVo voCommChannel = commchannels.get(i);
			if (voCommChannel.getChannelType().equals(channelType))
			{
				return voCommChannel;
			}
		}
		return null;
	}
	/**
	* getHomePhoneNumber
	*/
	public ims.core.vo.CommChannelVo getHomePhoneNumber()
	{
		return getCommunicationChannel(ims.core.vo.lookups.ChannelType.HOME_PHONE);
	}
	/**
	* getWorkPhoneNumber
	*/
	public ims.core.vo.CommChannelVo getWorkPhoneNumber()
	{
		return getCommunicationChannel(ims.core.vo.lookups.ChannelType.WORK_PHONE);
	}
	/**
	* getMobile
	*/
	public ims.core.vo.CommChannelVo getMobile()
	{
		return getCommunicationChannel(ims.core.vo.lookups.ChannelType.MOBILE);
	}
	/**
	* addCommunicationChannel - adds a new communication channel to the collection of communications
	*/
	public void addCommunicationChannel(ims.core.vo.lookups.ChannelType channelType, String val)
	{
		if (commchannels == null) commchannels = new ims.core.vo.CommChannelVoCollection();
		ims.core.vo.CommChannelVo voCommChannell = getCommunicationChannel(channelType);
		if (voCommChannell != null)
		{
			if (val == null || val.length() == 0)
			{
				commchannels.remove(commchannels.indexOf(voCommChannell ));
			}
			else
			{
				voCommChannell.setCommValue(val);
			}	
		}
		else
		{
			if (val != null && val.length() > 0)
			{
				voCommChannell = new ims.core.vo.CommChannelVo();
				voCommChannell .setChannelType(channelType);
				voCommChannell .setCommValue(val);
				commchannels.add(voCommChannell);
			}
				
		}
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.name != null)
		{
			if(!this.name.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.address != null)
		{
			if(!this.address.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.commchannels != null)
		{
			if(!this.commchannels.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.pdscontactpreferences != null)
		{
			if(!this.pdscontactpreferences.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.name != null)
		{
			String[] listOfOtherErrors = this.name.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.address != null)
		{
			String[] listOfOtherErrors = this.address.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.commchannels != null)
		{
			String[] listOfOtherErrors = this.commchannels.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.objectidentifier != null)
			if(this.objectidentifier.length() > 14)
				listOfErrors.add("The length of the field [objectidentifier] in the value object [ims.core.vo.NextOfKin] is too big. It should be less or equal to 14");
		if(this.nhsnum != null)
			if(this.nhsnum.length() > 50)
				listOfErrors.add("The length of the field [nhsnum] in the value object [ims.core.vo.NextOfKin] is too big. It should be less or equal to 50");
		if(this.contactrank != null)
			if(this.contactrank.length() > 2)
				listOfErrors.add("The length of the field [contactrank] in the value object [ims.core.vo.NextOfKin] is too big. It should be less or equal to 2");
		if(this.pdscontactpreferences != null)
		{
			String[] listOfOtherErrors = this.pdscontactpreferences.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.tempfield != null)
			if(this.tempfield.length() > 50)
				listOfErrors.add("The length of the field [tempfield] in the value object [ims.core.vo.NextOfKin] is too big. It should be less or equal to 50");
		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;
	
		NextOfKin clone = new NextOfKin(this.id, this.version);
		
		if(this.name == null)
			clone.name = null;
		else
			clone.name = (ims.core.vo.PersonName)this.name.clone();
		if(this.address == null)
			clone.address = null;
		else
			clone.address = (ims.core.vo.PersonAddress)this.address.clone();
		if(this.relationship == null)
			clone.relationship = null;
		else
			clone.relationship = (ims.core.vo.lookups.PersonRelationship)this.relationship.clone();
		if(this.commchannels == null)
			clone.commchannels = null;
		else
			clone.commchannels = (ims.core.vo.CommChannelVoCollection)this.commchannels.clone();
		if(this.pdsupdatemode == null)
			clone.pdsupdatemode = null;
		else
			clone.pdsupdatemode = (ims.core.vo.lookups.PDSUpdateMode)this.pdsupdatemode.clone();
		clone.objectidentifier = this.objectidentifier;
		if(this.role == null)
			clone.role = null;
		else
			clone.role = (ims.core.vo.lookups.PDSPersonRole)this.role.clone();
		clone.nhsnum = this.nhsnum;
		clone.contactrank = this.contactrank;
		clone.nokind = this.nokind;
		clone.cpycorresp = this.cpycorresp;
		if(this.callbckcons == null)
			clone.callbckcons = null;
		else
			clone.callbckcons = (ims.core.vo.lookups.PDSConsent)this.callbckcons.clone();
		clone.beffdatecnf = this.beffdatecnf;
		clone.betdatecnf = this.betdatecnf;
		if(this.beffdate == null)
			clone.beffdate = null;
		else
			clone.beffdate = (ims.framework.utils.Date)this.beffdate.clone();
		if(this.betdate == null)
			clone.betdate = null;
		else
			clone.betdate = (ims.framework.utils.Date)this.betdate.clone();
		if(this.dob == null)
			clone.dob = null;
		else
			clone.dob = (ims.framework.utils.PartialDate)this.dob.clone();
		clone.active = this.active;
		if(this.pdscontactpreferences == null)
			clone.pdscontactpreferences = null;
		else
			clone.pdscontactpreferences = (ims.core.vo.PDSRelativeContactPrefVo)this.pdscontactpreferences.clone();
		if(this.pdslanguage == null)
			clone.pdslanguage = null;
		else
			clone.pdslanguage = (ims.core.vo.lookups.PDSPreferredCommunicationLanguage)this.pdslanguage.clone();
		clone.pdsinterpreterrequired = this.pdsinterpreterrequired;
		clone.pending = this.pending;
		clone.isconfidential = this.isconfidential;
		clone.timestamp = this.timestamp;
		clone.tempfield = this.tempfield;
		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 (!(NextOfKin.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A NextOfKin object cannot be compared an Object of type " + obj.getClass().getName());
		}
		NextOfKin compareObj = (NextOfKin)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getName() == null && compareObj.getName() != null)
				return -1;
			if(this.getName() != null && compareObj.getName() == null)
				return 1;
			if(this.getName() != null && compareObj.getName() != null)
				retVal = this.getName().compareTo(compareObj.getName());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = super.countFieldsWithValue();
		if(this.tempfield != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return super.countValueObjectFields() + 1;
	}
	protected String tempfield;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
