/*******************************************************************************
 *  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.exceptions.InvalidDataTypeException;
import cdac.medinfo.sdk.hl7282.utils.EnumDataType;
import cdac.medinfo.sdk.hl7282.utils.IDataTypeMap;

/**
 * PL - Person Location<p>
 * This data type specifies a patient location within a healthcare institution.
 * <p>Represents an HL7 PL data type. 
 * This data type has the following attributes:</p><p>
 *  1. Point of Care (HD)<b>Conditional</b><br>
 *  2. Room (HD)<b>Optional</b><br>
 *  3. Bed (HD)<b>Optional</b><br>
 *  4. Facility (HD)<b>Optional</b><br>
 *  5. Location Status (IS)<b>Optional</b><br>
 *  6. Person Location Type (IS)<b>Optional</b><br>
 *  7. Building (HD)<b>Optional</b><br>
 *  8. Floor (HD)<b>Optional</b><br>
 *  9. Location Description (ST)<b>Optional</b><br>
 * 10. Comprehensive Location Identifier (EI)<b>Optional</b><br>
 * 11. Assigning Authority for Location (HD)<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 PL extends CompositeDataType    
{
	

	/**
	 * Default Constructor for PL
	 */
	public PL()
	{
		super(EnumDataType.HL7_DT_PL);
		 
	}

	/**
	 * Constructor  for PL 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 PL(int iMinLength, int iMaxLength, String strCLength,int iComponentType) throws InvalidComponentTypeException
	{
		super(EnumDataType.HL7_DT_PL);
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}

	/**
	 * Constructor for PL 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 PL(int iMinLength, int iMaxLength, String strCLength,int iTableNo,int iComponentType) throws InvalidComponentTypeException
	{
		super(EnumDataType.HL7_DT_PL);
		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 PL 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 PL(int iComponentType,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_PL);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}
	/**
	 * Constructor for PL 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 PL(int iComponentType,int iMinLength, int iMaxLength, String strCLength,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_PL);
		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 PL 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 PL(int iComponentType,int iMinLength, int iMaxLength, String strCLength,int ITableNo,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_PL);
		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 PointOfCare.
	 *@param objHD Specifies the code for the point where patient care is administered.
	 */
	public void setPointOfCare(HD objHD)
	{
		setComponentType(1,objHD);
	}

	
	/**
	 *Sets the Room.
	 *@param objHD Specifies the code for the patient's room. 
	 */
	public void setRoom(HD objHD)
	{
		setComponentType(2,objHD);
	}

	
	/**
	 *Sets the Bed.
	 *@param objHD Specifies the code for the patient's bed. 
	 */
	public void setBed(HD objHD)
	{
		setComponentType(3,objHD);
	}

	/**
	 * Sets the Facility.
	 * @param objFacility Specifies to site interpretation but generally describes 
	 * 							the highest level physical designation of an institution, 
	 * 							medical center or enterprise. 
	 */
	public void setFacility(HD objFacility)
	{
		setComponentType(4,objFacility);
	}

	/**
	 *Sets the LocationStatus.
	 *@param strLocationStatus Specifies the code for the status or availability of the location.  
	 */
	public void setLocationStatus(String strLocationStatus)
	{
		if(strLocationStatus!=null)
			setComponentType(5, strLocationStatus);
		else
			setLocationStatus((IS)null);
	}

	/**
	 *Sets the LocationStatus.
	 *@param objIS Specifies the code for the status or availability of the location. 
	 */
	public void setLocationStatus(IS objIS)
	{
		setComponentType(5,objIS);
	}

	/**
	 *Sets the PersonLocationType.
	 *@param strPersonLocationType Specifies the categorization of the person's location defined by 
	 * 									facility, building, floor, point of care, room or bed. 
	 */
	public void setPersonLocationType(String strPersonLocationType)
	{
		if(strPersonLocationType!=null)
			setComponentType(6, strPersonLocationType);
		else
			setPersonLocationType((IS)null);
	}

	/**
	 *Sets the PersonLocationType.
	 *@param objIS Specifies the categorization of the person's location defined by 
	 * 									facility, building, floor, point of care, room or bed. 
	 */
	public void setPersonLocationType(IS objIS)
	{
		setComponentType(6,objIS);
	}

	/**
	 *Sets the Building.
	 *@param strBuilding Specifies code for the building where the person is located.  
	 */
	public void setBuilding(String strBuilding)
	{
		if(strBuilding!=null)
			setComponentType(7, strBuilding);
		else
			setBuilding((HD)null);
	}


	/**
	 *Sets the Building.
	 *@param objHD Specifies code for the building where the person is located. 
	 */
	public void setBuilding(HD objHD)
	{
		setComponentType(7,objHD);
	}

	/**
	 *Sets the Floor.
	 *@param strFloor Specifies the code for the floor where the person is located. 
	 */
	public void setFloor(String strFloor)
	{
		if(strFloor!=null)
			setComponentType(8, strFloor);
		else
			setFloor((HD)null);
	}

	/**
	 *Sets the Floor.
	 *@param objIS Specifies the code for the floor where the person is located.
	 */
	public void setFloor(HD objHD)
	{
		setComponentType(8,objHD);
	}

	/**
	 *Sets the LocationDescription.
	 *@param strLocationDescription Specifies describes the location in free text. 
	 */
	public void setLocationDescription(String strLocationDescription)
	{
		if(strLocationDescription!=null)
			setComponentType(9, strLocationDescription);
		else
			setLocationDescription((ST)null);
	}

	/**
	 *Sets the LocationDescription.
	 *@param objST Specifies describes the location in free text.
	 */
	public void setLocationDescription(ST objST)
	{
		setComponentType(9,objST);
	}

	/**
	 * Sets the ComprehensiveLocationIdentifier.
	 * @param objComprehensiveLocationIdentifier Specifies represents the physical location as 
	 *													a whole without regard for the individual components. 
	 */
	public void setComprehensiveLocationIdentifier(EI objComprehensiveLocationIdentifier)
	{
		setComponentType(10,objComprehensiveLocationIdentifier);
	}

	/**
	 *Sets the AssigningAuthorityForLocation.
	 *@param objAssigningAuthorityForLocation Specifies the entity that creates the data for the individual physical location components.
	 */
	public void setAssigningAuthorityForLocation(HD objAssigningAuthorityForLocation)
	{
		setComponentType(11,objAssigningAuthorityForLocation);
	}

	/**
	 * Returns Point of Care
	 * @return IS - data type. 
	 */
	public HD getPointOfCare()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(1);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}

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

	/**
	 * Returns Bed
	 * @return HD - data type.
	 */
	public HD getBed()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(3);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Facility
	 * @return HD - data type.
	 */
	public HD getFacility()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(4);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Location Status
	 * @return IS - data type.
	 */
	public IS getLocationStatus()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(5);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (IS)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Person Location Type
	 * @return IS - data type.
	 */
	public IS getPersonLocationType()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(6);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (IS)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Building
	 * @return HD - data type.
	 */
	public HD getBuilding()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(7);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Floor
	 * @return HD - data type.
	 */
	public HD getFloor()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(8);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Location Description
	 * @return ST - data type.
	 */
	public ST getLocationDescription()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(9);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Comprehensive Location Identifier
	 * @return EI - data type.
	 */
	public EI getComprehensiveLocationIdentifier()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(10);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (EI)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Assigning Authority for Location
	 * @return HD - data type.
	 */
	public HD getAssigningAuthorityForLocation()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(11);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (HD)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * The Method validates the Input value,and if validated properly then returns true.
	 * Here the validetion is based on the compulsory fields for the Datatype. 
	 * @return boolean - true or false.
	 * @throws InvalidDataTypeException - if Invalid values is entered or Mandatory field is missing.
	 */
	public boolean validate() throws InvalidDataTypeException
	{
		super.validate();
		/*all fields are optional, but there is one field i.e Person Location Type
		 * but that is not to be considered.
		 */
		return true;
	}

	/**
	 * 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 PL)))
			return false;

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

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

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

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

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

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

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

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

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

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

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

		return true;
	}
}
