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

/***
 * DSP - display data segment.<p>
 * The DSP segment is used to contain data that has been preformatted by the sender
 * for display.  The semantic content of the data is lost; the data is simply treated as lines of text.
 * <p>Represents an HL7 DSP message segment. 
 * This segment has the following fields:</p><p>
 * DSP-1: Set ID - DSP (SI)<b>Optional</b><br> 
 * DSP-2: Display Level (SI)<b>Optional</b><br> 
 * DSP-3: Data Line (TX)<b>Required</b><br> 
 * DSP-4: Logical Break Point (ST)<b>Optional</b><br> 
 * DSP-5: Result ID (TX)<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 DSP extends Segment   
{
	





	/***
	 * Constructs the DSP segment.
	 */
	public DSP()
	{super(EnumSegments.HL7_SEG_DSP);
	}

	/**
	 * Retrieves the Data Line.
	 * This field contains an actual line as it should be displayed.  
	 * @return TX - dataLine
	 */
	public TX getDataLine() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(63);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (TX)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Display Level.
	 * This field contains numbering to define groups of fields as assigned by the individual sites or applications.
	 * @return SI - displayLevel
	 */
	public SI getDisplayLevel() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(62);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (SI)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Logical Break Point.
	 * This field is non-null, if this line is the last line of a logical break point in the response as defined by the responding system.  
	 * @return ST - logicalBreakPoint
	 */
	public ST getLogicalBreakPoint() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(64);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Result ID.
	 * @return TX - resultID
	 */
	public TX getResultID() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(65);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (TX)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Set ID DSP.
	 * This field is used optionally to number multiple display segments.
	 * @return SI - setIDDSP
	 */
	public SI getSetIDDSP() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(61);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (SI)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Set the Data Line.
	 * This field contains an actual line as it should be displayed.  
	 * @param strSoftwareProductInformation Used for SoftwareProductInformation.
	 */ 
	public void setDataLine(String strSoftwareProductInformation)
	{
		TX dataLine  = (TX)getDataElement(63); 
		dataLine.setValue(strSoftwareProductInformation); 
		setDataLine(dataLine);
	} 

	/** Set the Data Line.
	 * This field contains an actual line as it should be displayed.  
	 * @param objdataLine object of Data Line.
	 */ 
	public void setDataLine(TX objdataLine)
	{
		setDataType(63,objdataLine);
	}

	/**
	 * Set the Logical Break Point.
	 * This field is non-null, if this line is the last line of a logical break point in the response as defined by the responding system.  
	 * @param strAccidentLocation Used for AccidentLocation.
	 */ 
	public void setLogicalBreakPoint(String strAccidentLocation)
	{
		ST logicalBreakPoint  = (ST)getDataElement(64);
		logicalBreakPoint.setValue(strAccidentLocation); 
		setLogicalBreakPoint(logicalBreakPoint);
	} 

	/** Set the Logical Break Point.
	 * This field is non-null, if this line is the last line of a logical break point in the response as defined by the responding system.  
	 * @param objlogicalBreakPoint object of logical Break Point.
	 */ 
	public void setLogicalBreakPoint(ST objlogicalBreakPoint)
	{
		setDataType(64,objlogicalBreakPoint);
	}
	/**
	 * Set the Result ID.
	 * @param strSoftwareProductInformation Used for SoftwareProductInformation.
	 */ 
	public void setResultID(String strSoftwareProductInformation)
	{
		TX resultID  = (TX)getDataElement(65); 
		resultID.setValue(strSoftwareProductInformation); 
		setResultID(resultID);
	} 

	/** Set the Result ID.
	 * @param objresultID object of Result ID Used.
	 */ 
	public void setResultID(TX objresultID)
	{
		setDataType(65,objresultID);
	}

	/**
	 * Set the Set ID DSP.
	 * This field is used optionally to number multiple display segments.
	 * @param strSetID_AL1 This field contains the number that identifies AL1 transaction. 
	 */ 
	public void setSetIDDSP(String strSetID_AL1)
	{
		SI setIDDSP  = (SI)getDataElement(61);
		setIDDSP.setValue(strSetID_AL1); 
		setSetIDDSP(setIDDSP);
	} 

	/** Set the Set ID DSP.
	 * This field is used optionally to number multiple display segments.
	 * @param objsetIDDSP object of set ID DSP. 
	 */ 
	public void setSetIDDSP(SI objsetIDDSP)
	{
		setDataType(61,objsetIDDSP);
	}

	/**
	 * Set the Display Level.
	 * This field contains numbering to define groups of fields as assigned by the individual sites or applications.
	 * @param strSetID_AL1 This field contains the number that identifies AL1 transaction. 
	 */ 
	public void setDisplayLevel(String strSetID_AL1)
	{
		SI displayLevel  = (SI)getDataElement(62);
		displayLevel.setValue(strSetID_AL1); 
		setDisplayLevel(displayLevel);
	} 

	/** Set the Display Level.
	 * This field contains numbering to define groups of fields as assigned by the individual sites or applications.
	 * @param objdisplayLevel object of Display Level. 
	 */ 
	public void setDisplayLevel(SI objdisplayLevel)
	{
		setDataType(62,objdisplayLevel);
	}


	/**
	 * 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. 
	 */	
	@Override
	public boolean validate() throws InvalidSegmentException 
	{
		/*
		 * Data Line is required field.
		 */
		try 
		{
			super.validate();
			return true;		
		}
		catch(FieldMissingException ex)
		{
			throw new InvalidSegmentException(enumSegments.getValue(),ex);
		}
	}
}