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

import cdac.medinfo.sdk.hl7282.baselibs.CWE;
import cdac.medinfo.sdk.hl7282.baselibs.NM;
import cdac.medinfo.sdk.hl7282.baselibs.SCV;
import cdac.medinfo.sdk.hl7282.commoninterface.IDataType;
import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.exceptions.FieldMissingException;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidSegmentException;
import cdac.medinfo.sdk.hl7282.utils.EnumSegments;
import cdac.medinfo.sdk.hl7282.utils.SingleCollection;

/**
 * APR - Appointment Preferences Segment<p>
 * The APR segment contains parameters and preference specifications used for requesting
 * appointments in the SRM message.
 * <p>Represents an HL7 APR message segment. 
 * This segment has the following fields:</p><p>
 * APR-1: Time Selection Criteria (SCV)<b>Optional</b><br> 
 * APR-2: Resource Selection Criteria (SCV)<b>Optional</b><br> 
 * APR-3: Location Selection Criteria (SCV)<b>Optional</b><br> 
 * APR-4: Slot Spacing Criteria (NM)<b>Optional</b><br> 
 * APR-5: Filler Override Criteria (SCV)<b>Optional</b><br><p> 
 * This class provides mechanism to validate message against HL7 v 2.8.2 standard.
 * The class provides accessors & mutators for the elements mentioned above.
 * The class has validate method which validates Message against HL7 v 2.8.2 standard.
 *
 * <p>User can also create Segment through {@link SegmentFactory}
 */
 public class APR extends Segment   
{
	

	/**
	 * Constructs the APR segment.
	 */
	public APR()
	{super(EnumSegments.HL7_SEG_APR);
	}

	//Integer values used in getter/setter is unique item id defined 
	//for each attribute.

	/**
	 * Retrieves the Filler Override Criteria.
	 * This field specify the override parameters to the filler application.
	 * @return ISingleCollection<SCV> - fillerOverrideCriteria
	 */
	public ISingleCollection<SCV> getFillerOverrideCriteria() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(912);
		ISingleCollection<SCV> objDataList = new SingleCollection<SCV>(); 
		if(objDataCollection != null && objDataCollection.size() != 0)
		{
			for(IDataType objDataType : objDataCollection)
			{
				SCV objSCV = (SCV)objDataType;
				objDataList.add(objSCV);
			}
		}
		return objDataList;
	}

	/**
	 * Retrieves the Location Selection Criteria.
	 * This field specify the communicate parameters and preferences to the filler application regarding the selection of an appropriate location for an appointment.
	 * @return ISingleCollection<SCV> - locationSelectionCriteria
	 */
	public ISingleCollection<SCV> getLocationSelectionCriteria() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(910);
		ISingleCollection<SCV> objDataList = new SingleCollection<SCV>(); 
		if(objDataCollection != null && objDataCollection.size() != 0)
		{
			for(IDataType objDataType : objDataCollection)
			{
				SCV objSCV = (SCV)objDataType;
				objDataList.add(objSCV);
			}
		}
		return objDataList;
	}

	/**
	 * Retrieves the Resource Selection Criteria.
	 * This field specify the communicate parameters and preferences to the filler application regarding the selection of an appropriate resource for an appointment.
	 * @return ISingleCollection<SCV> - resourceSelectionCriteria
	 */
	public ISingleCollection<SCV> getResourceSelectionCriteria() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(909);
		ISingleCollection<SCV> objDataList = new SingleCollection<SCV>(); 
		if(objDataCollection != null && objDataCollection.size() != 0)
		{
			for(IDataType objDataType : objDataCollection)
			{
				SCV objSCV = (SCV)objDataType;
				objDataList.add(objSCV);
			}
		}
		return objDataList;
	}

	/**
	 * Retrieves the Slot Spacing Criteria.
	 * This field specify the queries returning lists of possible appointment slots, or other lists of slots.
	 * @return NM - slotSpacingCriteria
	 */
	public NM getSlotSpacingCriteria() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(911);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Time Selection Criteria.
	 * This field specify the communicate parameters and preferences to the filler application regarding the selection of an appropriate time slot for an appointment.
	 * @return ISingleCollection<SCV> - timeSelectionCriteria
	 */
	public ISingleCollection<SCV> getTimeSelectionCriteria() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(908);
		ISingleCollection<SCV> objDataList = new SingleCollection<SCV>(); 
		if(objDataCollection != null && objDataCollection.size() != 0)
		{
			for(IDataType objDataType : objDataCollection)
			{
				SCV objSCV = (SCV)objDataType;
				objDataList.add(objSCV);
			}
		}
		return objDataList;
	}

	/**
	 * Add the Time Selection Criteria.
	 * This field specify the communicate parameters and preferences to the filler application regarding the selection of an appropriate time slot for an appointment.
	 * @param objParameterClass Identifies the parameter or preference being passed to the filler application. 
	 * @param strParameterValue Actual data value for that parameter.  
	 */ 
	public void addTimeSelectionCriteria (CWE objParameterClass,String strParameterValue) 
	{
		SCV timeSelectionCriteria = (SCV)getDataElement(908);
		timeSelectionCriteria.setParameterClass(objParameterClass);
		timeSelectionCriteria.setParameterValue(strParameterValue); 
		addTimeSelectionCriteria(timeSelectionCriteria);

	} 

	/** 
	 * Add the Time Selection Criteria.
	 * This field specify the communicate parameters and preferences to the filler application regarding the selection of an appropriate time slot for an appointment.
	 * @param objtimeSelectionCriteria Object of Time Selection Criteria.  
	 */ 
	public void addTimeSelectionCriteria(SCV objtimeSelectionCriteria)
	{
		addDataType(908,objtimeSelectionCriteria);

	} 

	/** 
	 * Set the Time Selection Criteria.
	 * This field specify the communicate parameters and preferences to the filler application regarding the selection of an appropriate time slot for an appointment.
	 * @param objtimeSelectionCriteriaList List of Time Selection Criteria.  
	 */ 
	@SuppressWarnings("unchecked")
	public void setTimeSelectionCriteria(ISingleCollection<SCV> objtimeSelectionCriteriaList)
	{
		ISingleCollection<IDataType> objCollection = null;
		ISingleCollection<?> objUnknownCollection = (ISingleCollection<?>)objtimeSelectionCriteriaList;
		objCollection = (ISingleCollection<IDataType>)objUnknownCollection;
		setDataType(908,objCollection);
	}

	/**
	 * Add the Resource Selection Criteria.
	 * This field specify the communicate parameters and preferences to the filler application regarding the selection of an appropriate resource for an appointment.
	 * @param objParameterClass Identifies the parameter or preference being passed to the filler application. 
	 * @param strParameterValue Actual data value for that parameter.  
	 */ 
	public void addResourceSelectionCriteria (CWE objParameterClass,String strParameterValue) 
	{
		SCV resourceSelectionCriteria = (SCV)getDataElement(909);
		resourceSelectionCriteria.setParameterClass(objParameterClass);
		resourceSelectionCriteria.setParameterValue(strParameterValue); 
		addResourceSelectionCriteria(resourceSelectionCriteria);

	} 

	/** 
	 * Add the Resource Selection Criteria.
	 * This field specify the communicate parameters and preferences to the filler application regarding the selection of an appropriate resource for an appointment.
	 * @param objresourceSelectionCriteria Object of Resource Selection Criteria.  
	 */ 
	public void addResourceSelectionCriteria(SCV objresourceSelectionCriteria)
	{
		addDataType(909,objresourceSelectionCriteria);

	} 

	/** 
	 * Set the Resource Selection Criteria.
	 * This field specify the communicate parameters and preferences to the filler application regarding the selection of an appropriate resource for an appointment.
	 * @param objresourceSelectionCriteriaList List of Resource Selection Criteria.  
	 */ 
	@SuppressWarnings("unchecked")
	public void setResourceSelectionCriteria(ISingleCollection<SCV> objresourceSelectionCriteriaList)
	{
		ISingleCollection<IDataType> objCollection = null;
		ISingleCollection<?> objUnknownCollection = (ISingleCollection<?>)objresourceSelectionCriteriaList;
		objCollection = (ISingleCollection<IDataType>)objUnknownCollection;
		setDataType(909,objCollection);
	}

	/**
	 * Add the Location Selection Criteria.
	 * This field specify the communicate parameters and preferences to the filler application regarding the selection of an appropriate location for an appointment.
	 * @param objParameterClass Identifies the parameter or preference being passed to the filler application. 
	 * @param strParameterValue Actual data value for that parameter.  
	 */ 
	public void addLocationSelectionCriteria (CWE objParameterClass,String strParameterValue) 
	{
		SCV locationSelectionCriteria = (SCV)getDataElement(910);
		locationSelectionCriteria.setParameterClass(objParameterClass);
		locationSelectionCriteria.setParameterValue(strParameterValue); 
		addLocationSelectionCriteria(locationSelectionCriteria);

	} 

	/** 
	 * Add the Location Selection Criteria.
	 * This field specify the communicate parameters and preferences to the filler application regarding the selection of an appropriate location for an appointment.
	 * @param objlocationSelectionCriteria Object of Location Selection Criteria.  
	 */ 
	public void addLocationSelectionCriteria(SCV objlocationSelectionCriteria)
	{
		addDataType(910,objlocationSelectionCriteria);

	} 

	/** 
	 * Set the Location Selection Criteria.
	 * This field specify the communicate parameters and preferences to the filler application regarding the selection of an appropriate location for an appointment.
	 * @param objlocationSelectionCriteriaList List of Location Selection Criteria.  
	 */ 
	@SuppressWarnings("unchecked")
	public void setLocationSelectionCriteria(ISingleCollection<SCV> objlocationSelectionCriteriaList)
	{
		ISingleCollection<IDataType> objCollection = null;
		ISingleCollection<?> objUnknownCollection = (ISingleCollection<?>)objlocationSelectionCriteriaList;
		objCollection = (ISingleCollection<IDataType>)objUnknownCollection;
		setDataType(910,objCollection);
	}


	/**
	 * Set the Slot Spacing Criteria.
	 * This field specify the queries returning lists of possible appointment slots, or other lists of slots.  
	 * @param strSlotSpacingCriteria String value of Slot Spacing Criteria.
	 */ 
	public void setSlotSpacingCriteria (String strSlotSpacingCriteria) 
	{
		NM slotSpacingCriteria  = (NM)getDataElement(911);
		slotSpacingCriteria.setValue(strSlotSpacingCriteria); 
		setSlotSpacingCriteria(slotSpacingCriteria);

	} 

	/** 
	 * Set the Slot Spacing Criteria.
	 * This field specify the queries returning lists of possible appointment slots, or other lists of slots.  
	 * @param objslotSpacingCriteria Object of Slot Spacing Criteria.
	 */ 
	public void setSlotSpacingCriteria(NM objslotSpacingCriteria)
	{
		setDataType(911,objslotSpacingCriteria);

	}

	/**
	 * Add the Filler Override Criteria.
	 * This field specify the override parameters to the filler application.  
	 * @param objParameterClass Identifies the parameter or preference being passed to the filler application. 
	 * @param strParameterValue Actual data value for that parameter.  
	 */ 
	public void addFillerOverrideCriteria (CWE objParameterClass,String strParameterValue) 
	{
		SCV fillerOverrideCriteria = (SCV)getDataElement(912);
		fillerOverrideCriteria.setParameterClass(objParameterClass);
		fillerOverrideCriteria.setParameterValue(strParameterValue); 
		addFillerOverrideCriteria(fillerOverrideCriteria);

	} 

	/** 
	 * Add the Filler Override Criteria.
	 * This field specify the override parameters to the filler application.  
	 * @param objfillerOverrideCriteria Object of Filler Override Criteria.  
	 */ 
	public void addFillerOverrideCriteria(SCV objfillerOverrideCriteria)
	{
		addDataType(912,objfillerOverrideCriteria);

	} 

	/** 
	 * Set the Filler Override Criteria.
	 * This field specify the override parameters to the filler application.  
	 * @param objfillerOverrideCriteriaList List of Filler Override Criteria. 
	 */ 
	@SuppressWarnings("unchecked")
	public void setFillerOverrideCriteria(ISingleCollection<SCV> objfillerOverrideCriteriaList)
	{
		ISingleCollection<IDataType> objCollection = null;
		ISingleCollection<?> objUnknownCollection = (ISingleCollection<?>)objfillerOverrideCriteriaList;
		objCollection = (ISingleCollection<IDataType>)objUnknownCollection;
		setDataType(912,objCollection);
	}

	/**
	 * Validates HL7 Message objects .
	 * Validate method checks for validation each and every segments in side the Message object against specified message Structure. 
	 * Validation checks include optionality of segment or group.
	 * It also verifies the number of times segment or group is repeated in message.
	 * e.g 
	 * {PSH} while parsing PSH segment validate method will check for its mandatory presence.
	 * [PSH] in this case validate will throw exception if one tries to enter more than one PSH segment.
	 * @return boolean - true or false.
	 * @throws InvalidSegmentException Thrown when Segment Validation Fails.
	 */
	@Override
	public boolean validate() throws InvalidSegmentException 
	{
		try
		{
			super.validate();

			return true;
		}
		catch(FieldMissingException ex)
		{
			throw new InvalidSegmentException(enumSegments.getValue(),ex);
		}
	}
}