/*******************************************************************************
 *  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.SI;
import cdac.medinfo.sdk.hl7282.baselibs.ST;
import cdac.medinfo.sdk.hl7282.commoninterface.IDataType;
import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidSegmentException;
import cdac.medinfo.sdk.hl7282.utils.EnumSegments;

/**
* SGT - Segment Group Header<p>
* The SGH segment is only used to provide information about the instantiated message structure to 
* the parsing process to indicate that the segment group ends and subsequent segments should be 
* interpreted accordingly. It does not contain any patient related data.  
* The Segment Group Trailer is required if the segment group header exists. 
* <p>Represents an HL7 SGT message segment. 
* This segment has the following fields:</p><p>
* SGT-1: Set ID - SGT (SI)<b>Required</b><br> 
* SGT-2: Segment Group Name (ST)<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 SGT extends Segment 
{
	

	/**
	 * Constructs the SGT segment.
	 */
	public SGT()
	{super(EnumSegments.HL7_SEG_SGT);
	}

	/**
	 * Retrieves the Set ID SGT.
	 * For the first segment group  transmitted, the sequence number shall be 1; for the second , it shall be 2; and so on. 
	 * @return String - setID_SGT
	 */
	public SI getSetID_SGT() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(3394);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (SI)objDataCollection.elementAt(0);
		else
			return null;
	}
	/**
	 * Set the Set ID SGT.
	 * For the first segment group  transmitted, the sequence number shall be 1; for the second , it shall be 2; and so on. 
	 * @param strSetID_SGT This field contains the number that identifies SGT transaction. 
	 */	
	public void setSetID_SGT(String strSetID_SGT)
	{
		SI setID_SGT  = (SI)getDataElement(3394);
		setID_SGT.setValue(strSetID_SGT); 
		setSetID_SGT(setID_SGT);
	}

	/**
	 * Set the Set ID SGT.
	 * For the first segment group  transmitted, the sequence number shall be 1; for the second , it shall be 2; and so on. 
	 * @param objSetID_SGT Object of Set ID SGT.
	 */
	public void setSetID_SGT(SI objSetID_SGT)
	{
		setDataType(3394,objSetID_SGT);
	}
	
	/**
	 * Retrieves the Segment Group Name.
	 * This field contains the name of the segment group. 
	 * @return String - SegmentGroupName
	 */
	public ST getSegmentGroupName() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(3395);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Set the Segment Group Name.
	 * This field contains the name of the segment group. 
	 * @param strSegmentGroupName String value of Segment Group Name
	 */
	public void setSegmentGroupName(String strSegmentGroupName) 
	{
		ST SegmentGroupName  = (ST)getDataElement(3395);			
		SegmentGroupName.setValue(strSegmentGroupName);
		setSegmentGroupName(SegmentGroupName);
	}

	/**
	 * Set the Segment Group Name.
	 * This field contains the name of the segment group.
	 * @param objSegmentGroupName Segment Group Name
	 */
	public void setSegmentGroupName(ST objSegmentGroupName)
	{
		setDataType(3395,objSegmentGroupName);
	}
	
	/**
	 * Validates HL7 Message objects .
	 * Validate method checks for validation each and every segments in side the Message object against specified message Structure. 
	 * Validation chcecks 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 Throws when Segment Validation fails.
	 */
	public boolean validate() throws InvalidSegmentException
	{
		//All fields are optional in this segment
		//		This Segment Supports Feature Modes For Updating via Repeating Segment.
		//Validation Mode for this segments validation doesn't affect. 
		super.validate();
		return true;
	}
}
