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

import cdac.medinfo.sdk.hl7282.baselibs.messages.Message;
import cdac.medinfo.sdk.hl7282.baselibs.segments.REL;
import cdac.medinfo.sdk.hl7282.baselibs.segments.RF1;
import cdac.medinfo.sdk.hl7282.baselibs.segments.SFT;
import cdac.medinfo.sdk.hl7282.baselibs.segments.UAC;
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;

/**
 * CCQ_I19 – Collaborative Care Query (Event I19).
 * This event triggers a query message to be sent from a referring healthcare provider to a referred to healthcare provider, 
 * regarding a specific, previously sent collaborative care referral. 
 * <p>Represents a CCQ_I19 message structure (see chapter 11.7.1). This structure contains the 
 * following elements: </p>
 * 0: MSH (Message Header Segment) <b>SINGLE_COMPULSARY</b><br>
 * 1: SFT (Software Segment) <b>MULTIPLE_OPTIONAL</b><br>
 * 2: UAC (User Authentication Credential) <b>SINGLE OPTIONAL</b><br/>
 * 3: RF1 (Referral Information) <b>SINGLE_COMPULSARY</b><br>
 * 4: PROVIDER_CONTACT (a Group in CCU_I20 message) <b>MULTIPLE_OPTIONAL</b><br>
 * 5: REL (Relationship) <b>MULTIPLE_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. 
 */
public final class CCQ_I19 extends Message {

	/**
	 * Constructs the CCU_I19 message.
	 */
	public CCQ_I19(IMap objMessageMap) {
		super(objMessageMap, EnumMessageCode.CCQ.getValue(), EnumTriggerEvent.I19.getValue(), EnumMessageStructure.CCQ_I19.getValue());
	}
	
	/**
	 * 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;
	}

	/**
	 * Adds Software Segment(SFT) to this message.
	 * @param objSFT Specified Software Segment(SFT) to be added in this messageto this 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 User Authentication Credential(UAC) segment present in this message
	 * @return UAC - Specified UAC Segment
	 */
	public UAC getUserAuthenticationCredentialSegment()
	{
		ISingleCollection<ISegment> objSingleCollection = getSegment(EnumSegments.HL7_SEG_UAC);
		if(objSingleCollection != null)
			return (UAC)objSingleCollection.elementAt(0);
		return null;
	}

	/**
	 * Sets value of User Authentication Credential segment for this message,overwrites if already present.
	 * @param objUAC Specified UAC Segment
	 */
	public void setUserAuthenticationCredentialSegment(UAC objUAC)
	{
		setSegment(EnumSegments.HL7_SEG_UAC,objUAC);
	}

	/**
	 *  Retrieves Referral Information(RF1) segment present in this message
	 * @return RFI - the Referral Information Segment present in this message or null if unavailable.
	 */
	public RF1 getReferralInformationSegment()
	{
		ISingleCollection<ISegment> objSingleCollection = getSegment(EnumSegments.HL7_SEG_RF1);
		if(objSingleCollection != null)
			return (RF1)objSingleCollection.elementAt(0);
		return null;
	}

	/**
	 * Sets value of Referral Information segment for this message,overwrites if already present.
	 * @param objRF1 Specified Referral Information Segment 
	 */
	public void setReferralInformationSegment(RF1 objRF1)
	{
		setSegment(EnumSegments.HL7_SEG_RF1,objRF1);
	}	
	
	/**
	 * Retrieves Collection of Provider Contact GROUP present in this message.
	 * @return ISingleCollection<Group> - Collection of Provider Contact Group present 
	 */
	public ISingleCollection<IGroup> getProviderContactGroups()
	{
		return getGroup(EnumSegments.HL7_GROUP_PROVIDER_CONTACT);
	}

	/**
	 * Adds Collection of Provider Contact GROUP to this message.
	 * @param objSingleCollection Specified  Provider Contact GROUP Collection.
	 */
	public void addProviderContactGroups(ISingleCollection<IGroup> objSingleCollection)
	{
		addGroup(EnumSegments.HL7_GROUP_PROVIDER_CONTACT, objSingleCollection);
	}

	/**
	 * Adds Provider Contact GROUP to this message.
	 * @param objGroup Provider Contact GROUP. 
	 */
	public void addProviderContactGroup(IGroup objGroup)
	{
		addGroup(EnumSegments.HL7_GROUP_PROVIDER_CONTACT, objGroup);
	}
	
	/**
	 * Adds Relationship Segment(REL) to this message.
	 * @param objREL Specified Relationship Segment(REL)to be added in message.
	 */
	public void addRelationshipSegment(REL objREL)
	{
		addSegment(EnumSegments.HL7_SEG_REL, objREL);
	}


	/**
	 * Adds collection of Relationship Segment(REL) to this message.
	 * @param objRELSegmentCollection Collection of Relationship Segments to add in this message
	 */
	@SuppressWarnings("unchecked")
	public void addRelationshipSegment(ISingleCollection<REL>  objRELSegmentCollection)
	{
		ISingleCollection<?> objSegmentCollection =  objRELSegmentCollection;
		addSegment(EnumSegments.HL7_SEG_REL, (ISingleCollection<ISegment>)objSegmentCollection);
	}
	
	/**
	 * Retrieves Collection of Relationship Segments(REL) present in this message.
	 * @return ISingleCollection<REL> - Collection of Relationship Segments(REL) present in this message.
	 */
	@SuppressWarnings("unchecked")
	public ISingleCollection<REL> getRelationshipSegments()
	{
		ISingleCollection<?> objSegmentCollection = getSegment(EnumSegments.HL7_SEG_REL);
		return (ISingleCollection<REL>)objSegmentCollection;
	}
}
