/*******************************************************************************
 *  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.hl7model.messages.patientadministration;

import cdac.medinfo.sdk.hl7282.baselibs.messages.AbstractQuery;
import cdac.medinfo.sdk.hl7282.baselibs.segments.DSC;
import cdac.medinfo.sdk.hl7282.baselibs.segments.ERR;
import cdac.medinfo.sdk.hl7282.baselibs.segments.MSA;
import cdac.medinfo.sdk.hl7282.baselibs.segments.QAK;
import cdac.medinfo.sdk.hl7282.baselibs.segments.QPD;
import cdac.medinfo.sdk.hl7282.baselibs.segments.SFT;
import cdac.medinfo.sdk.hl7282.commoninterface.IGroup;
import cdac.medinfo.sdk.hl7282.commoninterface.ISegment;
import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.utils.EnumMessageCode;
import cdac.medinfo.sdk.hl7282.utils.EnumMessageStructure;
import cdac.medinfo.sdk.hl7282.utils.EnumSegments;
import cdac.medinfo.sdk.hl7282.utils.EnumTriggerEvent;
import cdac.medinfo.sdk.hl7282.utils.IMap;

/**
 * RSP_K32 - Find Candidates including Visit Information Response (RSP) (Events Q32).
 * This event is designed for interaction between a client system and an MPI (Master
 * Person Index).
 * <p>Represents a RSP_K32 message structure (see chapter 3.2.63). This structure contains the 
 * following elements: </p>
 * 0: MSH (Message Header) <b>SINGLE_COMPULSARY</b><br>
 * 1: SFT (Software Segment) <b>MULTIPLE_OPTIONAL</b><br>
 * 2: MSA (Message Acknowledgment) <b>SINGLE_COMPULSARY</b><br>
 * 3: ERR (Error) <b>SINGLE_OPTIONAL</b><br>
 * 4: QAK (Query Acknowledgment) <b>SINGLE_COMPULSARY</b><br>
 * 5: QPD (Query Parameter Definition) <b>SINGLE_COMPULSARY</b><br>
 * 6: RSP_K32_QUERY_RESPONSE (a Group object) <b>SINGLE_OPTIONAL</b><br>
 * 7: DSC (Continuation Pointer) <b>SINGLE_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.
 * These elements can be easily populated & populated values can be easily retrieved.
 * The class has validate method which validates Message against HL7 v 2.8.2 standard.
 *
 * <p>Following is the step to create message<br>
 * Before that, respective Message Source and Message Recipient to be set on Message Factory.</p>
 * <p>RSP_K32 objK32 = (RSP_K32)MessageFactory.createInstance().createSendSupportedMessage("RSP", "K32");</p>
 */

public final class RSP_K32 extends AbstractQuery{

	/**
	 * Constructs the RSP_K32 message.
	 */
	RSP_K32(IMap objMessageMap)
	{
		super(objMessageMap, EnumMessageCode.RSP.getValue(), EnumTriggerEvent.K32.getValue(), EnumMessageStructure.RSP_K32.getValue());
	}

	/**
	 * Veifies whether message is Response.
	 * @return boolean
	 */
	public boolean isResponse()
	{
		return true;
	}	

	/**
	 * Adds Software Segment(SFT) to this message.
	 * @param objSFT Specified Software Segment(SFT)to be added in message.
	 */
	public void addSoftwareSegment(SFT objSFT)
	{
		addSegment(EnumSegments.HL7_SEG_SFT, objSFT);
	}


	/**
	 * Adds collection of Software Segment(SFT) to this message.
	 * @param objSFTSegmentCollection Collection of Software Segments to add in this message
	 */
	@SuppressWarnings("unchecked")
	public void addSoftwareSegment(ISingleCollection<SFT>  objSFTSegmentCollection)
	{
		ISingleCollection<?> objSegmentCollection =  objSFTSegmentCollection;
		addSegment(EnumSegments.HL7_SEG_SFT, (ISingleCollection<ISegment>)objSegmentCollection);
	}

	/**
	 * Retrieves Collection of Software Segments(SFT) present in this message.
	 * @return ISingleCollection<SFT> - Collection of Software Segments(SFT) present in this message.
	 */
	@SuppressWarnings("unchecked")
	public ISingleCollection<SFT> getSoftwareSegments()
	{
		ISingleCollection<?> objSegmentCollection = getSegment(EnumSegments.HL7_SEG_SFT);
		return (ISingleCollection<SFT>)objSegmentCollection;
	}


	/**
	 * Retrieves Message Acknowledgment(MSA) segment present in this message
	 * @return MSA - the Message Acknowledgment Segment present in this message or null if unavailable.
	 */
	public MSA getMessageAcknowledgmentSegment()
	{
		ISingleCollection<ISegment> objSingleCollection = getSegment(EnumSegments.HL7_SEG_MSA);
		if(objSingleCollection != null)
			return (MSA)objSingleCollection.elementAt(0);
		return null;
	}
	/**
	 * Sets value of Message Acknowledgment segment for this message,overwrites if already present.
	 * @param objMSA Specified Message Acknowledgment Segment 
	 */
	public void setMessageAcknowledgmentSegment(MSA objMSA)
	{
		setSegment(EnumSegments.HL7_SEG_MSA,objMSA);
	}

	/**
	 * Retrieves Error(ERR) segment present in this message
	 * @return ERR - the Error Segment present in this message or null if unavailable.
	 */
	public ERR getErrorSegment()
	{
		ISingleCollection<ISegment> objSingleCollection = getSegment(EnumSegments.HL7_SEG_ERR);
		if(objSingleCollection != null)
			return (ERR)objSingleCollection.elementAt(0);
		return null;
	}

	/**
	 * Sets value of Error segment for this message,overwrites if already present.
	 * @param objERR Specified Error Segment 
	 */
	public void setErrorSegment(ERR objERR)
	{
		setSegment(EnumSegments.HL7_SEG_ERR,objERR);
	}

	/**
	 * Retrieves the Query Acknowledgement(QAK) Segment present in this message
	 * @return QAK - the Query Acknowledgement Segment present in this message or null if unavailable.
	 */
	public QAK getQueryAcknowledgementSegment()
	{
		ISingleCollection<ISegment> objSingleCollection = getSegment(EnumSegments.HL7_SEG_QAK);
		if(objSingleCollection != null)
			return (QAK)objSingleCollection.elementAt(0);
		return null;
	}
	/**
	 * Set the value of Query Acknowledgement Segment for this message,overwrites if already present.
	 * @param objQAK Specified Query Acknowledgement Segment 
	 */
	public void setQueryAcknowledgementSegment(QAK objQAK)
	{
		setSegment(EnumSegments.HL7_SEG_QAK,objQAK);
	}

	/**
	 * Retrieves the Query Parameter Definition(QPD) Segment present in this message
	 * @return QPD - the Query Parameter Definition Segment present in this message or null if unavailable.
	 */
	public QPD getQueryParameterDefinitionSegment()
	{
		ISingleCollection<ISegment> objSingleCollection = getSegment(EnumSegments.HL7_SEG_QPD);
		if(objSingleCollection != null)
			return (QPD)objSingleCollection.elementAt(0);
		return null;
	}
	/**
	 * Set the value of Query Parameter Definition Segment for this message,overwrites if already present.
	 * @param objQPD Specified Query Parameter Definition Segment 
	 */
	public void setQueryParameterDefinitionSegment(QPD objQPD)
	{
		setSegment(EnumSegments.HL7_SEG_QPD,objQPD);
	}

	/**
	 * Retrieves QUERY RESPONSE Group present in this message.
	 * @return Group - QUERY RESPONSE Group present in this message.
	 */
	public IGroup getQueryResponseGroup()
	{
		ISingleCollection<IGroup> objGroupCollection = getGroup(EnumSegments.HL7_GROUP_QUERY_RESPONSE);
		if(objGroupCollection != null)
			return objGroupCollection.elementAt(0);
		return null;
	}

	/**
	 * Sets value of QUERY RESPONSE Group for this message,overwrites if already present.
	 * @param objGroup Specified QUERY RESPONSE Group 
	 */
	public void setQueryResponseGroup(IGroup objGroup)
	{
		setGroup(EnumSegments.HL7_GROUP_QUERY_RESPONSE,objGroup);
	}

	/**
	 * Retrieves the Continuation Pointer(DSC) Segment present in this message
	 * @return DSC - the Continuation Pointer Segment present in this message or null if unavailable.
	 */
	public DSC getContinuationPointerSegment()
	{
		ISingleCollection<ISegment> objSingleCollection = getSegment(EnumSegments.HL7_SEG_DSC);
		if(objSingleCollection != null)
			return (DSC)objSingleCollection.elementAt(0);
		return null;
	}

	/**
	 * Set the value of Continuation Pointer Segment for this message,overwrites if already present.
	 * @param objDSC Specified Continuation Pointer Segment 
	 */
	public void setContinuationPointerSegment(DSC objDSC)
	{
		setSegment(EnumSegments.HL7_SEG_DSC,objDSC);
	}
}
