/*******************************************************************************
 *  Copyright 2017 Center 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.DTM;
import cdac.medinfo.sdk.hl7282.baselibs.ID;
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;

/**
 * RFI - Request for Information
 * <p>Represents an HL7 RFI message segment.
 * This segment has the following fields:</p><p>
 * RFI-1 :  Request Date(DTM)<b>Required</b><br> 
 * RFI-2 :  Response Due Date(DTM)<b>Required</b><br>
 * RFI-3 :  Patient Consent(ID) <b>Optional</b><br>   
 * RFI-4 :  Date Additional Information Was Submitted(DTM) <b>Optional</b><br>   
 * 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 RFI extends Segment{

	/**
	 * Constructs the RFI segment.
	 */
	public RFI()
	{
		super(EnumSegments.HL7_SEG_RFI);
	}
	
	/**
	 * Retrieves Request Date (DTM)   
	 * @return DTM - return the object of Requested date.
	 */
	public DTM getRequestDate()
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1910);
		if(objDataCollection != null) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves  Response Due Date   (DTM)      
	 * @return DTM - return the object of Response due date.
	 */
	public DTM getResponseDueDate()
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1911);
		if(objDataCollection != null) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves Patient Consent   (ID) 
	 * @return ID - return object of Patient Consent.  
	 */
	public ID getpatientConsent()
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1912);
		if(objDataCollection != null) 
			return (ID)objDataCollection.elementAt(0);
		else
			return null;
	}
	/**
	 * Retrieves  Date Additional Information Was Submitted   (DTM)      
	 * @return DTM - return the object of Date Additional Information Was Submitted.
	 */
	public DTM getDateAdditionalInformationWasSubmitted()
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(1913);
		if(objDataCollection != null) 
			return (DTM)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Set Request Date(DTM)
	 * @param String - Request Date - string of characters the tells about the latest requested date by the requester.
	 */
	public void setRequestDate(String strRequestDate)
	{
		DTM objRequestDate = (DTM)getDataElement(1910);
		objRequestDate.setValue(strRequestDate);
		setRequestDate(objRequestDate);
	}
	
	/**
	 * Set Request Date(DTM)
	 * @param  objRequestDate - object of Latest date requested dated return to the requester.
	 */
	public void setRequestDate(DTM objRequestDate)
	{
		setDataType(1910, objRequestDate);
	}
	
	/**
	 * Set Response Due Date   (DTM)   
	 * This Field is about the The latest date by which the additional information is to be returned to requester.
	 * @param String - String of Response Due Date - The latest date by which the additional information is to be returned to requester.
	 */
	public void setResponseDueDate(String strResponseDueDate)
	{
		DTM objResponseDueDate = (DTM)getDataElement(1911);
		objResponseDueDate.setValue(strResponseDueDate);
		setResponseDueDate(objResponseDueDate);
	}
	
	/**
	 * Set Response Due Date   (DTM)   
	 * This Field is about the The latest date by which the additional information is to be returned to requester.
	 * @param objResponseDueDate - object of Response Due Date - The latest date by which the additional information is to be returned to requester.
	 */
	public void setResponseDueDate(DTM objResponseDueDate)
	{
		setDataType(1911, objResponseDueDate);
	}
	
	/**
	 * Patient Consent   (ID)   
	 * This field is about Code indicating if the Payer has obtained patient consent for release of information.
	 * @param String - String of Patient Consent - Code indicating if the Payer has obtained patient consent for release of information.
	 */
	public void setPatientConsent(String strPatientConsent)
	{
		ID objPatientConsent = (ID)getDataElement(1912);
		objPatientConsent.setValue(strPatientConsent);
		setPatientConsent(objPatientConsent);
	}
	
	/**
	 * Patient Consent   (ID)   
	 * This field is about Code indicating if the Payer has obtained patient consent for release of information.
	 * @param ID - Object of Patient Consent - Code indicating if the Payer has obtained patient consent for release of information.
	 */
	public void setPatientConsent(ID objPatientConsent)
	{
		setDataType(1912, objPatientConsent);
	}
	
	/**
	 * Set Date Additional Information Was Submitted  (DTM)
	 * This field is about The date on which the information was assembled for transmission to the Payer.  Not necessarily the same as the message date.  
	 * @param String - string of Date Additional Information Was Submitted - The date on which the information was assembled for transmission to the Payer.
	 */
	public void setDateAdditionalInformationWasSubmitted(String strDateAdditionalInformation)
	{
		DTM objDateAdditionalInformation = (DTM)getDataElement(1913);
		objDateAdditionalInformation.setValue(strDateAdditionalInformation);
		setDateAdditionalInformationWasSubmitted(objDateAdditionalInformation);
	}
	
	/**
	 * Set Date Additional Information Was Submitted  (DTM)
	 * This field is about The date on which the information was assembled for transmission to the Payer.  Not necessarily the same as the message date.  
	 * @param DTM - object of Date Additional Information Was Submitted - The date on which the information was assembled for transmission to the Payer.
	 */
	public void setDateAdditionalInformationWasSubmitted(DTM objDateAdditionalInformation)
	{
		setDataType(1913, objDateAdditionalInformation);
	}
	
	/**
	 * 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 
	 * {RFI} while parsing RFI segment validate method will check for its mandatory presence.
	 * [RFI] in this case validate will throw exception if one tries to enter more than one RFI segment.
	 * @return boolean - true or false.
	 * @throws InvalidSegmentException Throws when Segment Validation fails.
	 */
	public boolean validate() throws InvalidSegmentException
	{
		try
		{
			super.validate();
			return true;
		}
		catch(FieldMissingException ex)
		{
			throw new InvalidSegmentException(enumSegments.getValue(),ex);
		}
	}
}
