package cdac.medinfo.sdk.hl7282.baselibs.segments;

import cdac.medinfo.sdk.hl7282.baselibs.EI;
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.FieldMissingException;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidSegmentException;
import cdac.medinfo.sdk.hl7282.utils.EnumSegments;

/**
 * SLT - Sterilization Lot Segment <p>
 * The SLT segment defines requests, responses, and notifications of sterilization lots and supply item descriptions.  
 * <p>Represents an HL7 SLT message segment. 
 * This segment has the following fields:</p><p>
 * SLT-1 : Device Number (EI) <b>Optional</b><br>
 * SLT-2 : Device Name (ST) <b>Optional</b><br>
 * SLT-3 : Lot Number (EI) <b>Optional</b><br>
 * SLT-4 : Item Identifier (EI) <b>Optional</b><br>
 * SLT-5 : Bar Code (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 SLT extends Segment 
{
	/**
	 *  Constructs the SLT segment. 
	 */
	public SLT()
	{super(EnumSegments.HL7_SEG_SLT);
	}
	
	//Integer values used in getter/setter is unique item id defined 
	//for each attribute.
	
	/**
	 * Retrieves the Device Number.
	 * The unique identifier of the device (assigned by user, not assigned by the software application; e.g.: 01).
	 * @return EI - deviceNumber
	 */
	public EI getDeviceNumber() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2094);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (EI)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Device Name.
	 * The name of the device associated with the device number in SLT-1 (e.g., VAC).
	 * @return ST - deviceName
	 */
	public ST getDeviceName() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2280);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Lot Number.
	 * A unique number associated with an instance of a sterilization/decontamination cycle assigned by the instrument-tracking system.
	 * @return EI - lotNumber
	 */
	public EI getLotNumber() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2095);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (EI)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Item Identifier.
	 * The Item Identifier is a unique code assigned to the material item by 
	 * the Instrument-tracking software application to identify the item being sterilized or decontaminated.
	 * @return EI - itemIdentifier
	 */
	public EI getItemIdentifier() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2096);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (EI)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Bar Code.
	 * The special identification code, printed as a set of vertical bars of differing widths, 
	 * used on instruments to identify them and provide for rapid, error-free input by a barcode scanning device.
	 * @return ST - barCode
	 */
	public ST getBarCode() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2097);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Set the Device Number.
	 * The unique identifier of the device (assigned by user, not assigned by the software application; e.g.: 01).
	 * @param strEntityIdentifier Specifies to be unique within the series of identifiers created by the 
	 * 								assigning authority, defined by a hierarchic designator
	 * @param strNamespaceId Specifies the assigning authority is a unique identifier of the system 
	 * 							(or organization or agency or department) that creates the data. 
	 * @param strUniversalId Specifies a string formatted according to the scheme defined by the third component universal ID type.
	 * 							It is intended to be unique over time within the UID type.
	 * @param strUniversalIdType Governs the interpretation of the Universal ID.
	 */ 
	public void setDeviceNumber(String strEntityIdentifier,String strNamespaceId,String strUniversalId,
			String strUniversalIdType)
	{
		EI objEI  = (EI)getDataElement(2094);
		objEI.setEntityIdentifier(strEntityIdentifier);
		objEI.setNamespaceId(strNamespaceId);
		objEI.setUniversalId(strUniversalId);
		objEI.setUniversalIdType(strUniversalIdType);
		setDeviceNumber(objEI);

	} 
	
	/** 
	 * Set the Device Number.
	 * The unique identifier of the device (assigned by user, not assigned by the software application; e.g.: 01).
	 * @param objDeviceNumber Object of Device Number
	 */ 
	public void setDeviceNumber(EI objDeviceNumber)
	{
		setDataType(2094,objDeviceNumber);

	}
	
	/**
	 * Set the Device Name.
	 * The name of the device associated with the device number in SLT-1 (e.g., VAC).
	 * @param strDeviceName Used as Device Name.
	 */ 
	public void setDeviceName(String strDeviceName) 
	{
		ST objST  = (ST)getDataElement(2280);
		objST.setValue(strDeviceName); 
		setDeviceName(objST);

	} 

	/** 
	 * Set the Device Name.
	 * The name of the device associated with the device number in SLT-1 (e.g., VAC).
	 * @param objDeviceName Object of Device Name.
	 */ 
	public void setDeviceName(ST objDeviceName)
	{
		setDataType(2280,objDeviceName);

	}
	
	/**
	 * Set the Lot Number.
	 * A unique number associated with an instance of a sterilization/decontamination cycle assigned by the instrument-tracking system.
	 * @param strEntityIdentifier Specifies to be unique within the series of identifiers created by the 
	 * 								assigning authority, defined by a hierarchic designator
	 * @param strNamespaceId Specifies the assigning authority is a unique identifier of the system 
	 * 							(or organization or agency or department) that creates the data. 
	 * @param strUniversalId Specifies a string formatted according to the scheme defined by the third component universal ID type.
	 * 							It is intended to be unique over time within the UID type.
	 * @param strUniversalIdType Governs the interpretation of the Universal ID.
	 */ 
	public void setLotNumber(String strEntityIdentifier,String strNamespaceId,String strUniversalId,
			String strUniversalIdType)
	{
		EI objEI  = (EI)getDataElement(2095);
		objEI.setEntityIdentifier(strEntityIdentifier);
		objEI.setNamespaceId(strNamespaceId);
		objEI.setUniversalId(strUniversalId);
		objEI.setUniversalIdType(strUniversalIdType);
		setLotNumber(objEI);

	} 
	
	/** 
	 * Set the Lot Number.
	 * A unique number associated with an instance of a sterilization/decontamination cycle assigned by the instrument-tracking system.
	 * @param objLotNumber Object of Lot Number
	 */ 
	public void setLotNumber(EI objLotNumber)
	{
		setDataType(2095,objLotNumber);

	}
	
	/**
	 * Set the Item Identifier.
	 * The Item Identifier is a unique code assigned to the material item by 
	 * the Instrument-tracking software application to identify the item being sterilized or decontaminated.
	 * @param strEntityIdentifier Specifies to be unique within the series of identifiers created by the 
	 * 								assigning authority, defined by a hierarchic designator
	 * @param strNamespaceId Specifies the assigning authority is a unique identifier of the system 
	 * 							(or organization or agency or department) that creates the data. 
	 * @param strUniversalId Specifies a string formatted according to the scheme defined by the third component universal ID type.
	 * 							It is intended to be unique over time within the UID type.
	 * @param strUniversalIdType Governs the interpretation of the Universal ID.
	 */ 
	public void setItemIdentifier(String strEntityIdentifier,String strNamespaceId,String strUniversalId,
			String strUniversalIdType)
	{
		EI objEI  = (EI)getDataElement(2096);
		objEI.setEntityIdentifier(strEntityIdentifier);
		objEI.setNamespaceId(strNamespaceId);
		objEI.setUniversalId(strUniversalId);
		objEI.setUniversalIdType(strUniversalIdType);
		setItemIdentifier(objEI);

	} 
	
	/** 
	 * Set the Item Identifier.
	 * The Item Identifier is a unique code assigned to the material item by 
	 * the Instrument-tracking software application to identify the item being sterilized or decontaminated.
	 * @param objItemIdentifier Object of Item Identifier
	 */ 
	public void setItemIdentifier(EI objItemIdentifier)
	{
		setDataType(2096,objItemIdentifier);

	}
	
	/**
	 * Set the Bar Code.
	 * The special identification code, printed as a set of vertical bars of differing widths, 
	 * used on instruments to identify them and provide for rapid, error-free input by a barcode scanning device.
	 * @param strBarCode Used as Bar Code
	 */ 
	public void setBarCode(String strBarCode) 
	{
		ST objST  = (ST)getDataElement(2097);
		objST.setValue(strBarCode); 
		setBarCode(objST);

	} 

	/** 
	 * Set the Bar Code.
	 * The special identification code, printed as a set of vertical bars of differing widths, 
	 * used on instruments to identify them and provide for rapid, error-free input by a barcode scanning device.
	 * @param objBarCode Object of Bar Code
	 */ 
	public void setBarCode(ST objBarCode)
	{
		setDataType(2097,objBarCode);

	}
	
	/**
	 * 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 
	 * {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 If Segment Validation fails 
	 */
	@Override
	public boolean validate() throws InvalidSegmentException 
	{
		try
		{
			/*
			 * Item Identifier is required fields of this segment.
			 */
			super.validate();

			return true;
		}
		catch(FieldMissingException ex)
		{
			throw new InvalidSegmentException(enumSegments.getValue(),ex);
		}
	}
	
}
