/*******************************************************************************
 *  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;

/**
 * XON - Extended composite name and identification number for organizations<p>
 * This data type specifies - extended composite name and identification number for organizations.
 * <p>Represents an HL7 XON data type. 
 * This data type has the following attributes:</p><p>
 *  1. Organization Name (ST)<b>Optional</b><br>
 *  2. Organization Name Type Code (CWE)<b>Optional</b><br>
 *  3. ID Number <b>Withdrawn</b><br>
 *  4. Identifier Check Digit <b>Withdrawn</b><br>
 *  5. Check Digit Scheme <b>Withdrawn</b><br>
 *  6. Assigning Authority (HD)<b>Optional</b><br>
 *  7. Identifier Type Code (ID)<b>Optional</b><br>
 *  8. Assigning Facility (HD)<b>Optional</b><br>
 *  9. Name Representation Code (ID)<b>Optional</b><br>
 * 10. Organization Identifier (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 XON extends CompositeDataType    
{
	

	/**
	 * Default constructor for XON.
	 */
	public XON()
	{
		super(EnumDataType.HL7_DT_XON);
		 
	}
	/**
	 * Constructor for XON 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 XON(int iMinLength, int iMaxLength, String strCLength,int iComponentType) throws InvalidComponentTypeException
	{
		this(iMinLength, iMaxLength , strCLength,0,iComponentType);
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}
	/**
	 * Constructor for XON 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 iComponentType The Type of the component i.e Component or a subcomponent.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public XON(int iMinLength, int iMaxLength, String strCLength,int iTableNo,int iComponentType)
	{
		super(EnumDataType.HL7_DT_XON);
		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 XON class which takes four 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 XON(int iComponentType,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_XON);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;

		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}
	/**
	 * Constructor for XON 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 XON(int iComponentType,int iMinLength, int iMaxLength, String strCLength,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_XON);
		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 XON 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 XON(int iComponentType,int iMinLength, int iMaxLength, String strCLength,int ITableNo,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_XON);
		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 Organization Name.
	 * @param strOrganizationName Specifies name of the specified organization.
	 */
	public void setOrganizationName(String strOrganizationName)
	{
		if(strOrganizationName!=null)
			setComponentType(1, strOrganizationName);
		else
			setOrganizationName((ST)null);
	}
	/**
	 * Sets the Organization Name.
	 * @param objST Specifies name of the specified organization.
	 */
	public void setOrganizationName(ST objST)
	{
		setComponentType(1,objST);
	}
	
	/**
	 * Sets the Organization Name Type Code.
	 * @param strOrganizationNameTypeCode Specifies a code that represents the type of name i.e., legal name, display name.
	 * 										Suggested Values A,L,D,SL.[Refer to table No.0204]  
	 */
	public void setOrganizationNameTypeCode(String strOrganizationNameTypeCode)
	{
		if(strOrganizationNameTypeCode!=null)
			setComponentType(2, strOrganizationNameTypeCode);
		else
			setOrganizationNameTypeCode((CWE)null);
	}
	
	/**
	 * Sets the Organization Name Type Code.
	 * @param objCWE Specifies a code that represents the type of name i.e., legal name, display name.
	 * 										Suggested Values A,L,D,SL.[Refer to table No.0204]  
	 */
	public void setOrganizationNameTypeCode(CWE objCWE)
	{
		setComponentType(2,objCWE);
	}
	
	/**
	 * Sets the Assigning Authority.
	 * @param objAssigningAuthority Specifies The assigning authority is a unique identifier of the system 
	 * 									(or organization or agency or department) that creates the data. 
	 */
	public void setAssigningAuthority(HD objAssigningAuthority)
	{
		setComponentType(6,objAssigningAuthority);
	}

	/**
	 * Sets the Identifier Type Code.
	 * @param strIdentifierTypeCode Specifies a code corresponding to the type of identifier. 
	 */
	public void setIdentifierTypeCode(String strIdentifierTypeCode)
	{
		if(strIdentifierTypeCode!=null)
			setComponentType(7, strIdentifierTypeCode);
		else
			setIdentifierTypeCode((ID)null);
	}
	/**
	 * Sets the Identifier Type Code.
	 * @param strIdentifierTypeCode Specifies a code corresponding to the type of identifier. 
	 */
	public void setIdentifierTypeCode(ID objID)
	{
		setComponentType(7,objID);
	}
	/**
	 * Sets the Assigning Facility.
	 * @param objAssigningFacility Specifies The place or location identifier where the identifier was first assigned to the person. 
	 */
	public void setAssigningFacility(HD objAssigningFacility)
	{
		setComponentType(8,objAssigningFacility);
	}

	/**
	 * 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(9, 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(9,objID);
	}
	/**
	 * Sets the Organization Identifier.
	 * @param strOrganizationIdentifier This component contains the sequence of characters (the code) that uniquely 
	 * 									  identifies the item being referenced by XON.1 Organization Name. 
	 * 									  This component replaces XON.3 ID Number as of v 2.5.
	 */
	public void setOrganizationIdentifier(String strOrganizationIdentifier)
	{
		if(strOrganizationIdentifier!=null)
			setComponentType(10, strOrganizationIdentifier);
		else
			setOrganizationIdentifier((ST)null);
	}
	/**
	 * Sets the Organization Identifier.
	 * @param objST This component contains the sequence of characters (the code) that uniquely 
	 * 									  identifies the item being referenced by XON.1 Organization Name. 
	 * 									  This component replaces XON.3 ID Number as of v 2.5.
	 */
	public void setOrganizationIdentifier(ST objST)
	{
		setComponentType(10,objST);
	}
	/**
	 * Returns Organization Name
	 * @return ST - data type.
	 */
	public ST getOrganizationName()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(1);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Organization Name Type Code
	 * @return CWE - data type.
	 */
	public CWE getOrganizationNameTypeCode()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(2);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Returns Assigning Authority
	 * @return HD - data type.
	 */
	public HD getAssigningAuthority()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(6);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}
	/**
	 * Returns Identifier Type Code
	 * @return ID - data type.
	 */
	public ID getIdentifierTypeCode()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(7);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}
	/**
	 * Returns Assigning Facility
	 * @return HD - data type.
	 */
	public HD getAssigningFacility()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(8);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}
	/**
	 * Returns Name Representation Code
	 * @return ID - data type.
	 */
	public ID getNameRepresentationCode()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(9);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Organization Identifier
	 * @return ST - data type.
	 */
	public ST getOrganizationIdentifier()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(10);
		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 XON)))
			return false;

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

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

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

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

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

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

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

		return true;
	}
}
