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

/**
 * NDL - Name with Date and Location <p>
 * This class represents the data type NDL which,
 * Specifies the name of the person performing a service, 
 * when the person performed the service and where the person performed the service. 
 * <p>Represents an HL7 NDL data type. 
 * This data type has the following attributes:</p><p>
 *  1. Name Of Person (CNN)<b>Optional</b><br>
 *  2. Start Date/time (DTM)<b>Optional</b><br>
 *  3. End Date/time (DTM)<b>Optional</b><br>
 *  4. Point of Care (IS)<b>Optional</b><br>
 *  5. Room (IS)<b>Optional</b><br>
 *  6. Bed (IS)<b>Optional</b><br>
 *  7. Facility (HD)<b>Optional</b><br>
 *  8. Location Status (IS)<b>Optional</b><br>
 *  9. Patient Location Type (IS)<b>Optional</b><br>
 * 10. Building (IS)<b>Optional</b><br>
 * 11. Floor (IS)<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 NDL extends CompositeDataType    
{
	

	/**
	 * Default Constructor for NDL
	 */
	public NDL()
	{
		super(EnumDataType.HL7_DT_NDL);
		 
	}

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

	/**
	 * Constructor for NDL 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 NDL(int iMinLength, int iMaxLength, String strCLength,int iTableNo,int iComponentType) throws InvalidComponentTypeException
	{
		super(EnumDataType.HL7_DT_NDL);
		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 NDL 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 NDL(int iComponentType,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_NDL);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}
	/**
	 * Constructor for NDL 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 NDL(int iComponentType,int iMinLength, int iMaxLength, String strCLength,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_NDL);
		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 NDL 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 NDL(int iComponentType,int iMinLength, int iMaxLength, String strCLength,int ITableNo,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_NDL);
		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 Name.
	 *@param objName Specifies the name of the person performing a service.
	 */
	public void setName(CNN objName)
	{
		setComponentType(1,objName);
	}
	
	/**
	 * Sets the StartDateTime.
	 * @param strStartDateTime Specifies the starting date and time for when the person is performing the service.
	 */
	
	public void setStartDateTime(String strStartDateTime)
	{
		if(strStartDateTime!=null)
			setComponentType(2, strStartDateTime);
		else
			setStartDateTime((DTM)null);
	}
	/**
	 *Sets the StartDateTime.
	 *@param objStartDateTime Specifies the starting date and time for when the person is performing the service.
	 */
	public void setStartDateTime(DTM objStartDateTime)
	{
		setComponentType(2,objStartDateTime);
	}
	
	/**
	 * Sets the EndDateTime.
	 * @param strStartDateTime Specifies the ending date and time for when the person is performing the service. 
	 */
	
	public void setEndDateTime(String strEndDateTime)
	{
		if(strEndDateTime!=null)
			setComponentType(3, strEndDateTime);
		else
			setEndDateTime((DTM)null);
	}
	/**
	 *Sets the EndDateTime.
	 *@param objEndDateTime Specifies the ending date and time for when the person is performing the service. 
	 */
	public void setEndDateTime(DTM objEndDateTime)
	{
		setComponentType(3,objEndDateTime);
	}
	/**
	 *Sets the PointOfCare.
	 *@param strPointOfCare Specifies the code for the point where patient care is administered.  
	 */
	public void setPointOfCare(String strPointOfCare)
	{
		if(strPointOfCare!=null)
			setComponentType(4, strPointOfCare);
		else
			setPointOfCare((IS)null);
	}
	/**
	 *Sets the PointOfCare.
	 *@param objString Specifies the code for the point where patient care is administered. 
	 */
	public void setPointOfCare(IS objIS)
	{
		setComponentType(4,objIS);
	}
	/**
	 *Sets the Room.
	 *@param strRoom Specifies most general location designation.  
	 */
	public void setRoom(String strRoom)
	{
		if(strRoom!=null)
			setComponentType(5, strRoom);
		else
			setRoom((IS)null);
	}
	/**
	 *Sets the Room.
	 *@param objIS Specifies most general location designation. 
	 */
	public void setRoom(IS objIS)
	{
		setComponentType(5,objIS);
	}
	/**
	 *Sets the Bed.
	 *@param strBed Specifies the code for the patient's bed.  
	 */
	public void setBed(String strBed)
	{
		if(strBed!=null)
			setComponentType(6, strBed);
		else
			setBed((IS)null);
	}
	/**
	 *Sets the Bed.
	 *@param objIS Specifies the code for the patient's bed. 
	 */
	public void setBed(IS objIS)
	{
		setComponentType(6,objIS);
	}
	/**
	 * Sets the Facility.
	 * @param objFacility Specifies site interpretation but generally describes the
	 * 							 highest level physical designation of an institution, medical center or enterprise.
	 */
	public void setFacility(HD objFacility)
	{
		setComponentType(7,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(8, 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(8,objIS);
	}
	/**
	 *Sets the PatientLocationType.
	 *@param strPatientLocationType Specifies the categorization of the location defined by facility, building, floor, point of care, room or bed.  
	 */
	public void setPatientLocationType(String strPatientLocationType)
	{
		if(strPatientLocationType!=null)
			setComponentType(9, strPatientLocationType);
		else
			setPatientLocationType((IS)null);
	}
	/**
	 *Sets the PatientLocationType.
	 *@param objIS Specifies the categorization of the location defined by facility, building, floor, point of care, room or bed. 
	 */
	public void setPatientLocationType(IS objIS)
	{
		setComponentType(9,objIS);
	}
	/**
	 *Sets the Building.
	 *@param strBuilding Specifies the code for the building where the person is located.  
	 */
	public void setBuilding(String strBuilding)
	{
		if(strBuilding!=null)
			setComponentType(10, strBuilding);
		else
			setBuilding((IS)null);
	}
	/**
	 *Sets the Building.
	 *@param objIS Specifies the code for the building where the person is located. 
	 */
	public void setBuilding(IS objIS)
	{
		setComponentType(10,objIS);
	}
	/**
	 *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(11, strFloor);
		else
			setFloor((IS)null);
	}
	/**
	 *Sets the Floor.
	 *@param objIS Specifies the code for the floor where the person is located.
	 */
	public void setFloor(IS objIS)
	{
		setComponentType(11,objIS);
	}

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

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

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

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

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

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

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

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

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

	/**
	 * Returns Floor
	 * @return IS - data type.
	 */
	public IS getFloor()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(11);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (IS)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 NDL)))
			return false;

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

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

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

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

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

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

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

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

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

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

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

		return true;
	}
}
