/*******************************************************************************
 *  Copyright 2017 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *    http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *******************************************************************************/
package cdac.medinfo.sdk.hl7282.baselibs;

import cdac.medinfo.sdk.hl7282.baselibs.segmentfactory.DataElementFactory;
import cdac.medinfo.sdk.hl7282.commoninterface.IDataType;
import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidComponentTypeException;
import cdac.medinfo.sdk.hl7282.utils.EnumDataType;
import cdac.medinfo.sdk.hl7282.utils.IDataTypeMap;

/**
 * XPN - Extended person name<p>
 * This data type specifies extended person name
 * <p>Represents an HL7 XPN data type. 
 * This data type has the following attributes:</p><p>
 *  1. Family Name (FN)<b>RequiredButMayBeEmpty</b><br>
 *  2. Given Name (ST)<b>Optional</b><br>
 *  3. Second and Further Given Names or Initials Thereof (ST)<b>Optional</b><br>
 *  4. Suffix (e.g., JR or III) (ST)<b>Optional</b><br>
 *  5. Prefix (e.g., DR) (ST)<b>Optional</b><br>
 *  6. Degree  <b>Withdrawn</b><br>
 *  7. Name Type Code (ID)<b>Optional</b><br>
 *  8. Name Representation Code (ID)<b>Optional</b><br>
 *  9. Name Context (CWE)<b>Optional</b><br>
 * 10. Name Validity Range <b>Withdrawn</b>
 * 11. Name Assembly Order (ID)<b>Optional</b><br>
 * 12. Effective Date (DTM)<b>Optional</b><br>
 * 13. Expiration Date (DTM)<b>Optional</b><br>
 * 14. Professional Suffix (ST)<b>Optional</b><br>
 * 15. Called By (ST)<b>Optional</b><br><p>
 * This class provides accessors & mutators for the elements mentioned above.
 * This class override the equal method, to check whether some other object is "equal to" this one.
 * 
 * <p>User can also create Data Type through {@link DataElementFactory} 
 */
public class XPN extends CompositeDataType   
{
	

	/**
	 * Default Constructor for XPN
	 */
	public XPN()
	{
		super(EnumDataType.HL7_DT_XPN);
		 
	}

	/**
	 * Constructor  for XPN class which takes four arguments and 
	 * sets the value in the respective member variable.
	 * @param iMinLength The Minimum length the DataType can have.
	 * @param iMaxLength The Maximum length the DataType can have.
	 * @param iCLength The Conformance length the DataType can have.
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */ 
	public XPN(int iMinLength, int iMaxLength, String strCLength,int iComponentType) throws InvalidComponentTypeException
	{
		super(EnumDataType.HL7_DT_XPN);
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}

	/**
	 * Constructor for XPN class which takes five arguments and 
	 * sets the value in the respective member variable.
	 * @param iMinLength The Minimum length the DataType can have.
	 * @param iMaxLength The Maximum length the DataType can have.
	 * @param iCLength The Conformance length the DataType can have.
	 * @param iTableNo The Table number to which the value for the component is specified. 
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public XPN(int iMinLength, int iMaxLength, String strCLength,int iTableNo,int iComponentType) throws InvalidComponentTypeException
	{
		super(EnumDataType.HL7_DT_XPN);
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;
		this.iTableNo = iTableNo;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());		
		}
	}
	/**
	 * Constructor for XPN class which takes two arguments and 
	 * sets the value in the respective member variable.
	 * @param objIDataTypeMap object of Data Type Map.
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public XPN(int iComponentType,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_XPN);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}
	/**
	 * Constructor for XPN class which takes five arguments and 
	 * sets the value in the respective member variable.
	 * @param objIDataTypeMap object of Data Type Map.
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @param iMinLength The Minimum length the DataType can have.
	 * @param iMaxLength The Maximum length the DataType can have.
	 * @param iCLength The Conformance length the DataType can have.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public XPN(int iComponentType,int iMinLength, int iMaxLength, String strCLength,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_XPN);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;

		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}
	/**
	 * Constructor for XPN class which takes six arguments and 
	 * sets the value in the respective member variable.
	 * @param objIDataTypeMap object of Data Type Map.
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @param iMinLength The Minimum length the DataType can have.
	 * @param iMaxLength The Maximum length the DataType can have.
	 * @param iCLength The Conformance length the DataType can have.
	 * @param iTableNo The Table number to which the value for the component is specified. 
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public XPN(int iComponentType,int iMinLength, int iMaxLength, String strCLength,int ITableNo,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_XPN);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;
		this.iTableNo = ITableNo;
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;

		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}

	/**
	 * Sets the Family Name.
	 * @param objFamilyName Specifies the surname of a person. 
	 */
	public void setFamilyName(FN objFamilyName)
	{
		setComponentType(1,objFamilyName);
	}

	/**
	 *Sets the Given Name.
	 *@param strGivenName Specifies First name. 
	 */
	public void setGivenName(String strGivenName)
	{
		if(strGivenName!=null)
			setComponentType(2, strGivenName);
		else
			setGivenName((ST)null);
	}

	/**
	 *Sets the Given Name.
	 *@param objST Specifies First name.
	 */
	public void setGivenName(ST objST)
	{
		setComponentType(2,objST);
	}

	/**
	 *Sets the Second Name Or Initials.
	 *@param strSecondNameOrInitials Specifies multiple middle names that may be included by separating them with spaces. 
	 */
	public void setSecondNameOrInitials(String strSecondNameOrInitials)
	{
		if(strSecondNameOrInitials!=null)
			setComponentType(3, strSecondNameOrInitials);
		else
			setSecondNameOrInitials((ST)null);
	}

	/**
	 *Sets the Second Name Or Initials.
	 *@param objST Specifies multiple middle names that may be included by separating them with spaces.
	 */
	public void setSecondNameOrInitials(ST objST)
	{
		setComponentType(3,objST);
	}

	/**
	 *Sets the Suffix.
	 *@param strSuffix Used to specify a name suffix (e.g., Jr. or III). 
	 */
	public void setSuffix(String strSuffix)
	{
		if(strSuffix!=null)
			setComponentType(4, strSuffix);
		else
			setSuffix((ST)null);
	}

	/**
	 *Sets the Suffix.
	 *@param objST Used to specify a name suffix (e.g., Jr. or III).
	 */
	public void setSuffix(ST objST)
	{
		setComponentType(4,objST);
	}

	/**
	 *Sets the Prefix.
	 *@param strPrefix Used to specify a name prefix (e.g., Dr.). 
	 */
	public void setPrefix(String strPrefix)
	{
		if(strPrefix!=null)
			setComponentType(5, strPrefix);
		else
			setPrefix((ST)null);
	}

	/**
	 *Sets the Prefix.
	 *@param objString Used to specify a name prefix (e.g., Dr.).
	 */
	public void setPrefix(ST objST)
	{
		setComponentType(5,objST);
	}


	/**
	 *Sets the Name Type Code.
	 *@param strNameTypeCode Specifies a code that represents the type of name. Suggested values are A,B,C,D,I,L,M,N,P,R,S,T,U...[Refer table 0200.] 
	 */
	public void setNameTypeCode(String strNameTypeCode)
	{
		if(strNameTypeCode!=null)
			setComponentType(7, strNameTypeCode);
		else
			setNameTypeCode((ID)null);
	}

	/**
	 *Sets the Name Type Code.
	 *@param objID Specifies a code that represents the type of name. Suggested values are A,B,C,D,I,L,M,N,P,R,S,T,U...[Refer table 0200.]
	 */
	public void setNameTypeCode(ID objID)
	{
		setComponentType(7,objID);
	}

	/**
	 *Sets the Name Representation Code.
	 *@param strNameRepresentationCode specifies representations of the same name/address Suggested values are I,A,P [Refer table 0465]  
	 */
	public void setNameRepresentationCode(String strNameRepresentationCode)
	{
		if(strNameRepresentationCode!=null)
			setComponentType(8, strNameRepresentationCode);
		else
			setNameRepresentationCode((ID)null);
	}

	/**
	 *Sets the Name Representation Code.
	 *@param objID specifies representations of the same name/address Suggested values are I,A,P [Refer table 0465] 
	 */
	public void setNameRepresentationCode(ID objID)
	{
		setComponentType(8,objID);
	}

	/**
	 * Sets the Name Context.
	 * @param objNameContext Designates the context in which a name is used. [Refer User-defined Table 0448 ]
	 */
	public void setNameContext(CWE objNameContext)
	{
		setComponentType(9,objNameContext);
	}

	/**
	 *Sets the Name Assembly Order.
	 *@param strNameAssemblyOrder Specifies a code that represents the preferred display order of the components of this person name. Suggested values are G,F[Refer table 0444.] 
	 */
	public void setNameAssemblyOrder(String strNameAssemblyOrder)
	{
		if(strNameAssemblyOrder!=null)
			setComponentType(11, strNameAssemblyOrder);
		else
			setNameAssemblyOrder((ID)null);
	}

	/**
	 *Sets the Name Assembly Order.
	 *@param objID Specifies a code that represents the preferred display order of the components of this person name. Suggested values are G,F[Refer table 0444.]
	 */
	public void setNameAssemblyOrder(ID objID)
	{
		setComponentType(11,objID);
	}
	
	/**
	 *Sets the Effective Date.
	 *@param strEffectiveDate Specifies the first date, if known, on which the address is valid and active.
	 */
	public void setEffectiveDate(String strEffectiveDate)
	{
		if(strEffectiveDate !=null)
			setComponentType(12, strEffectiveDate);
		else
			setEffectiveDate((DTM)null);
	}

	/**
	 * Sets the Effective Date.
	 * @param objEffectiveDate Specifies the first date, if known, on which the address is valid and active.
	 */
	public void setEffectiveDate(DTM objEffectiveDate)
	{
		setComponentType(12,objEffectiveDate);
	}
	
	/**
	 *Sets the Expiration Date.
	 *@param strExpirationDate Specifies the last date, if known, on which the address is valid and active.
	 */
	public void setExpirationDate(String strExpirationDate)
	{
		if(strExpirationDate !=null)
			setComponentType(13, strExpirationDate);
		else
			setExpirationDate((DTM)null);
	}

	/**
	 * Sets the Expiration Date.
	 * @param objExpirationDate Specifies the last date, if known, on which the address is valid and active.
	 */
	public void setExpirationDate(DTM objExpirationDate)
	{
		setComponentType(13,objExpirationDate);
	}

	/**
	 *Sets the Professional Suffix.
	 *@param strProfessionalSuffix Used to specify an abbreviation, or a string of abbreviations, denoting qualifications that support the person's profession, (e.g., licenses). 
	 */
	public void setProfessionalSuffix(String strProfessionalSuffix)
	{
		if(strProfessionalSuffix!=null)
			setComponentType(14, strProfessionalSuffix);
		else
			setProfessionalSuffix((ST)null);
	}

	/**
	 *Sets the Professional Suffix.
	 *@param objST Used to specify an abbreviation, or a string of abbreviations, denoting qualifications that support the person's profession, (e.g., licenses).
	 */
	public void setProfessionalSuffix(ST objST)
	{
		setComponentType(14,objST);
	}
	
	/**
	 *Sets the Called By.
	 *@param strCalledBy Specifies First name. 
	 */
	public void setCalledBy(String strCalledBy)
	{
		if(strCalledBy!=null)
			setComponentType(15, strCalledBy);
		else
			setGivenName((ST)null);
	}

	/**
	 *Sets the Called By.
	 *@param objST Specifies First name.
	 */
	public void setCalledBy(ST objST)
	{
		setComponentType(15,objST);
	}

	/**
	 * Returns Family Name
	 * @return FN - data type.
	 */
	public FN getFamilyName()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(1);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (FN)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Given Name
	 * @return ST - data type.
	 */
	public ST getGivenName()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(2);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Second and Further Given Names or Initials Thereof
	 * @return ST - data type.
	 */
	public ST getSecondGivenNamesInitials()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(3);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Suffix (e.g., JR or III)
	 * @return ST - data type.
	 */
	public ST getSuffix()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(4);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Prefix (e.g., DR)
	 * @return ST - data type.
	 */
	public ST getPrefix()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(5);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Name Type Code
	 * @return ID - data type.
	 */
	public ID getNameTypeCode()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(7);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Name Representation Code
	 * @return ID - data type.
	 */
	public ID getNameRepresentationCode()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(8);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Returns Name Context
	 * @return CWE - data type.
	 */
	public CWE getNameContext()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(9);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}


	/**
	 * Returns Name Assembly Order
	 * @return ID - data type.
	 */
	public ID getNameAssemblyOrder()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(11);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Effective Date
	 * @return DTM - data type.
	 */
	public DTM getEffectiveDate()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(12);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Expiration Date
	 * @return DTM - data type.
	 */
	public DTM getExpirationDate()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(13);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Professional Suffix
	 * @return ST - data type.
	 */
	public ST getProfessionalSuffix()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(14);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Returns Called By
	 * @return ST - data type.
	 */
	public ST getCalledBy()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(15);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * This method checks the equality of Object.
	 * @param objObject object of Object class.
	 * @return boolean - shows success or failure of the comparison.
	 */
	public boolean equals(Object objObject)
	{
		if((objObject == null ) || (!(objObject instanceof XPN)))
			return false;

		if(this.getFamilyName() == null)
		{
			if(((XPN)objObject).getFamilyName() != null)
				return false;
		}
		else if(false == (this.getFamilyName().equals(((XPN)objObject).getFamilyName())))
			return false;

		if(this.getGivenName() == null)
		{
			if(((XPN)objObject).getGivenName() != null)
				return false;
		}
		else if(false == (this.getGivenName().equals(((XPN)objObject).getGivenName())))
			return false;

		if(this.getSecondGivenNamesInitials() == null)
		{
			if(((XPN)objObject).getSecondGivenNamesInitials() != null)
				return false;
		}
		else if(false == (this.getSecondGivenNamesInitials().equals(((XPN)objObject).getSecondGivenNamesInitials())))
			return false;

		if(this.getSuffix() == null)
		{
			if(((XPN)objObject).getSuffix() != null)
				return false;
		}
		else if(false == (this.getSuffix().equals(((XPN)objObject).getSuffix())))
			return false;

		if(this.getPrefix() == null)
		{
			if(((XPN)objObject).getPrefix() != null)
				return false;
		}
		else if(false == (this.getPrefix().equals(((XPN)objObject).getPrefix())))
			return false;

		if(this.getNameTypeCode() == null)
		{
			if(((XPN)objObject).getNameTypeCode() != null)
				return false;
		}
		else if(false == (this.getNameTypeCode().equals(((XPN)objObject).getNameTypeCode())))
			return false;

		if(this.getNameRepresentationCode() == null)
		{
			if(((XPN)objObject).getNameRepresentationCode() != null)
				return false;
		}
		else if(false == (this.getNameRepresentationCode().equals(((XPN)objObject).getNameRepresentationCode())))
			return false;

		if(this.getNameContext() == null)
		{
			if(((XPN)objObject).getNameContext() != null)
				return false;
		}
		else if(false == (this.getNameContext().equals(((XPN)objObject).getNameContext())))
			return false;

		if(this.getNameAssemblyOrder() == null)
		{
			if(((XPN)objObject).getNameAssemblyOrder() != null)
				return false;
		}
		else if(false == (this.getNameAssemblyOrder().equals(((XPN)objObject).getNameAssemblyOrder())))
			return false;

		if(this.getEffectiveDate() == null)
		{
			if(((XPN)objObject).getEffectiveDate() != null)
				return false;
		}
		else if(false == (this.getEffectiveDate().equals(((XPN)objObject).getEffectiveDate())))
			return false;

		if(this.getExpirationDate() == null)
		{
			if(((XPN)objObject).getExpirationDate() != null)
				return false;
		}
		else if(false == (this.getExpirationDate().equals(((XPN)objObject).getExpirationDate())))
			return false;

		if(this.getProfessionalSuffix() == null)
		{
			if(((XPN)objObject).getProfessionalSuffix() != null)
				return false;
		}
		else if(false == (this.getProfessionalSuffix().equals(((XPN)objObject).getProfessionalSuffix())))
			return false;
		
		if(this.getCalledBy() == null)
		{
			if(((XPN)objObject).getCalledBy() != null)
				return false;
		}
		else if(false == (this.getCalledBy().equals(((XPN)objObject).getCalledBy())))
			return false;

		return true;
	}
}
