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

import cdac.medinfo.sdk.hl7282.baselibs.CWE;
import cdac.medinfo.sdk.hl7282.baselibs.EI;
import cdac.medinfo.sdk.hl7282.baselibs.NM;
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;

/**
 * SDD - Sterilization Device Data Segment <p>
 * The SDD segment contains the attributes of an instance of a cycle that provides sterilization or decontamination of medical supplies.
 * <p>Represents an HL7 SDD message segment. 
 * This segment has the following fields:</p><p>
 * SDD-1 : Lot Number (EI) <b>Optional</b><br>
 * SDD-2 : Device Number (EI) <b>Optional</b><br>
 * SDD-3 : Device Name (ST) <b>Optional</b><br>
 * SDD-4 : Device Data State (CWE) <b>Optional</b><br>
 * SDD-5 : Load Status (CWE) <b>Optional</b><br>
 * SDD-6 : Control Code(NM) <b>Optional</b><br>
 * SDD-7 : Operator 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 SDD extends Segment
{
	/**
	 *  Constructs the SDD segment. 
	 */
	public SDD()
	{super(EnumSegments.HL7_SEG_SDD);
	}
	
	//Integer values used in getter/setter is unique item id defined 
	//for each attribute.
	
	/**
	 * 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(2098);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (EI)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Device Number.
	 * The number of the device (e.g., 01 VAC).
	 * @return EI - deviceNumber
	 */
	public EI getDeviceNumber() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2099);
		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 SDD-2 (e.g., 01 VAC).
	 * @return ST - deviceName
	 */
	public ST getDeviceName() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2281);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Device Data State.
	 * The state of data being sent, i.e., historic data of the cycle or a real-time snapshot of the current value of the cycle data. 
	 * @return CWE - deviceDataState
	 */
	public CWE getDeviceDataState() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2100);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Load Status.
	 * The status of the load.  
	 * @return CWE - loadStatus
	 */
	public CWE getLoadStatus() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2101);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Control Code.
	 * A code to command the device to send cycle data from the previous load to the instrument-tracking system.
	 * @return NM - controlCode
	 */
	public NM getControlCode() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2102);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * Retrieves the Operator Name.
	 * The person who started the device load for the decontamination/sterilization process.
	 * @return ST - operatorName
	 */
	public ST getOperatorName() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(2103);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (ST)objDataCollection.elementAt(0);
		else
			return null;
	}
	
	/**
	 * 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(2098);
		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(2098,objLotNumber);

	}
	
	/**
	 * Set the Device Number.
	 * The number of the device (e.g., 01 VAC).
	 * @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(2099);
		objEI.setEntityIdentifier(strEntityIdentifier);
		objEI.setNamespaceId(strNamespaceId);
		objEI.setUniversalId(strUniversalId);
		objEI.setUniversalIdType(strUniversalIdType);
		setDeviceNumber(objEI);

	} 
	
	/** 
	 * Set the Device Number.
	 * The number of the device (e.g., 01 VAC).
	 * @param objDeviceNumber Object of Device Number
	 */ 
	public void setDeviceNumber(EI objDeviceNumber)
	{
		setDataType(2099,objDeviceNumber);

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

	} 

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

	}
	
	/**
	 * Set the Device Data State.
	 * The state of data being sent, i.e., historic data of the cycle or a real-time snapshot of the current value of the cycle data. 
	 * @param strIdentifier Specifies of characters (the code) that uniquely identifies the item being referenced. 
	 * @param strText Specifies The descriptive or textual name of the identifier, e.g., myocardial infarction. 
	 * @param strNameOfCodingSystem Identifies the coding scheme being used in the identifier component.
	 * @param strAlternateIdentifier Specifies an alternate sequence of characters (the code) that uniquely identifies the item being referenced.
	 * @param strAlternateText Specifies the descriptive or textual name of the alternate identifier. See usage note in section introduction.
	 * @param strNameOfAlternateCodingSystem Identifies the coding scheme being used in the alternate identifier component. 
	 * @param strCodingSystemVersionID A sequence of characters that uniquely identifies a second alternate code.
	 * @param strAlternateCodingSystemVersionId This component carries the version for the coding system identified by components 4-6.
	 * @param strOriginalText The text as seen and/or selected by the user who entered the data.
	 * @param strSecondAlternateIdentifier A sequence of characters that uniquely identifies a second alternate code.
	 * @param strSecondAlternateText The descriptive or textual name of the alternate identifier.
	 * @param strNameofSecondAlternateCodingSystem Identifies the coding scheme being used in the alternate identifier component.
	 * @param strSecondAlternateCodingSystemVersionID This component carries the version for the coding system identified by components 10-12.
	 * @param strCodingSystemOID This component contains the ISO Object Identifier (OID) for the coding system or value set named in CWE.3.
	 * @param strValueSetOID This component contains the ISO Object Identifier (OID) to allow identification of the value set from which the value in CWE.1 is obtained.
	 * @param strValueSetVersionID This component carries the version for the value set identified by CWE.15. The version is a date. The date is the date/time that the value set being used was published.
	 * @param strAlternateCodingSystemOID This component contains the ISO Object Identifier (OID) for the coding system or value set named in CWE.6.
	 * @param strAlternateValueSetOID This component contains the ISO Object Identifier (OID) to allow identification of the value set from which the value in CWE.4 is obtained.
	 * @param strAlternateValueSetVersionID This component carries the version for the value set identified by CWE.18. The version is a date.
	 * @param strSecondAlternateCodingSystemOID This component contains the ISO Object Identifier (OID) for the coding system or value set named in CWE.12.
	 * @param strSecondAlternateValueSetOID This component contains the ISO Object Identifier (OID) to allow identification of the value set from which the value in CWE.10 is obtained.
	 * @param strSecondAlternateValueSetVersionID This component carries the version for the value set identified by CWE.21. The version is a date.
	 */ 
	public void setDeviceDataState(String strIdentifier,String strText,String strNameOfCodingSystem,
			String strAlternateIdentifier,String strAlternateText,String strNameOfAlternateCodingSystem, String strCodingSystemVersionID, String strAlternateCodingSystemVersionId,
			String strOriginalText, String  strSecondAlternateIdentifier, String strSecondAlternateText, 
			String strNameofSecondAlternateCodingSystem, String strSecondAlternateCodingSystemVersionID, String strCodingSystemOID, String strValueSetOID,
			String strValueSetVersionID, String strAlternateCodingSystemOID, String strAlternateValueSetOID, String strAlternateValueSetVersionID,
			String  strSecondAlternateCodingSystemOID, String strSecondAlternateValueSetOID, String strSecondAlternateValueSetVersionID)
	{
		CWE cwe  = (CWE)getDataElement(2100);
		cwe.setIdentifier(strIdentifier);
		cwe.setText(strText);
		cwe.setNameOfCodingSystem(strNameOfCodingSystem);
		cwe.setAlternateIdentifier(strAlternateIdentifier);
		cwe.setAlternateText(strAlternateText);
		cwe.setNameOfAlternateCodingSystem(strNameOfAlternateCodingSystem); 
		cwe.setCodingSystemVersionID(strCodingSystemVersionID);
		cwe.setAlternateCodingSystemVersionId(strAlternateCodingSystemVersionId);
		cwe.setOriginalText(strOriginalText);
		cwe.setSecondAlternateIdentifier(strSecondAlternateIdentifier);
		cwe.setSecondAlternateText(strSecondAlternateText);
		cwe.setNameofSecondAlternateCodingSystem(strNameofSecondAlternateCodingSystem);
		cwe.setSecondAlternateCodingSystemVersionID(strSecondAlternateCodingSystemVersionID);
		cwe.setCodingSystemOID(strCodingSystemOID);
		cwe.setValueSetOID(strValueSetOID);
		cwe.setValueSetVersionID(strValueSetVersionID);
		cwe.setAlternateCodingSystemOID(strAlternateCodingSystemOID);
		cwe.setAlternateValueSetOID(strAlternateValueSetOID);
		cwe.setAlternateValueSetVersionID(strAlternateValueSetVersionID);
		cwe.setSecondAlternateCodingSystemOID(strSecondAlternateCodingSystemOID);
		cwe.setSecondAlternateValueSetOID(strSecondAlternateValueSetOID);
		cwe.setSecondAlternateValueSetVersionID(strSecondAlternateValueSetVersionID); 
		setDeviceDataState(cwe);

	} 
	
	/** 
	 * Set the Device Data State.
	 * The state of data being sent, i.e., historic data of the cycle or a real-time snapshot of the current value of the cycle data. 
	 * @param objDeviceDataState Object of Device Data State.
	 */ 
	public void setDeviceDataState(CWE objDeviceDataState)
	{
		setDataType(2100,objDeviceDataState);

	}
	
	/**
	 * Set the Load Status.
	 * The status of the load.   
	 * @param strIdentifier Specifies of characters (the code) that uniquely identifies the item being referenced. 
	 * @param strText Specifies The descriptive or textual name of the identifier, e.g., myocardial infarction. 
	 * @param strNameOfCodingSystem Identifies the coding scheme being used in the identifier component.
	 * @param strAlternateIdentifier Specifies an alternate sequence of characters (the code) that uniquely identifies the item being referenced.
	 * @param strAlternateText Specifies the descriptive or textual name of the alternate identifier. See usage note in section introduction.
	 * @param strNameOfAlternateCodingSystem Identifies the coding scheme being used in the alternate identifier component. 
	 * @param strCodingSystemVersionID A sequence of characters that uniquely identifies a second alternate code.
	 * @param strAlternateCodingSystemVersionId This component carries the version for the coding system identified by components 4-6.
	 * @param strOriginalText The text as seen and/or selected by the user who entered the data.
	 * @param strSecondAlternateIdentifier A sequence of characters that uniquely identifies a second alternate code.
	 * @param strSecondAlternateText The descriptive or textual name of the alternate identifier.
	 * @param strNameofSecondAlternateCodingSystem Identifies the coding scheme being used in the alternate identifier component.
	 * @param strSecondAlternateCodingSystemVersionID This component carries the version for the coding system identified by components 10-12.
	 * @param strCodingSystemOID This component contains the ISO Object Identifier (OID) for the coding system or value set named in CWE.3.
	 * @param strValueSetOID This component contains the ISO Object Identifier (OID) to allow identification of the value set from which the value in CWE.1 is obtained.
	 * @param strValueSetVersionID This component carries the version for the value set identified by CWE.15. The version is a date. The date is the date/time that the value set being used was published.
	 * @param strAlternateCodingSystemOID This component contains the ISO Object Identifier (OID) for the coding system or value set named in CWE.6.
	 * @param strAlternateValueSetOID This component contains the ISO Object Identifier (OID) to allow identification of the value set from which the value in CWE.4 is obtained.
	 * @param strAlternateValueSetVersionID This component carries the version for the value set identified by CWE.18. The version is a date.
	 * @param strSecondAlternateCodingSystemOID This component contains the ISO Object Identifier (OID) for the coding system or value set named in CWE.12.
	 * @param strSecondAlternateValueSetOID This component contains the ISO Object Identifier (OID) to allow identification of the value set from which the value in CWE.10 is obtained.
	 * @param strSecondAlternateValueSetVersionID This component carries the version for the value set identified by CWE.21. The version is a date.
	 */ 
	public void setLoadStatus(String strIdentifier,String strText,String strNameOfCodingSystem,
			String strAlternateIdentifier,String strAlternateText,String strNameOfAlternateCodingSystem, String strCodingSystemVersionID, String strAlternateCodingSystemVersionId,
			String strOriginalText, String  strSecondAlternateIdentifier, String strSecondAlternateText, 
			String strNameofSecondAlternateCodingSystem, String strSecondAlternateCodingSystemVersionID, String strCodingSystemOID, String strValueSetOID,
			String strValueSetVersionID, String strAlternateCodingSystemOID, String strAlternateValueSetOID, String strAlternateValueSetVersionID,
			String  strSecondAlternateCodingSystemOID, String strSecondAlternateValueSetOID, String strSecondAlternateValueSetVersionID)
	{
		CWE cwe  = (CWE)getDataElement(2101);
		cwe.setIdentifier(strIdentifier);
		cwe.setText(strText);
		cwe.setNameOfCodingSystem(strNameOfCodingSystem);
		cwe.setAlternateIdentifier(strAlternateIdentifier);
		cwe.setAlternateText(strAlternateText);
		cwe.setNameOfAlternateCodingSystem(strNameOfAlternateCodingSystem); 
		cwe.setCodingSystemVersionID(strCodingSystemVersionID);
		cwe.setAlternateCodingSystemVersionId(strAlternateCodingSystemVersionId);
		cwe.setOriginalText(strOriginalText);
		cwe.setSecondAlternateIdentifier(strSecondAlternateIdentifier);
		cwe.setSecondAlternateText(strSecondAlternateText);
		cwe.setNameofSecondAlternateCodingSystem(strNameofSecondAlternateCodingSystem);
		cwe.setSecondAlternateCodingSystemVersionID(strSecondAlternateCodingSystemVersionID);
		cwe.setCodingSystemOID(strCodingSystemOID);
		cwe.setValueSetOID(strValueSetOID);
		cwe.setValueSetVersionID(strValueSetVersionID);
		cwe.setAlternateCodingSystemOID(strAlternateCodingSystemOID);
		cwe.setAlternateValueSetOID(strAlternateValueSetOID);
		cwe.setAlternateValueSetVersionID(strAlternateValueSetVersionID);
		cwe.setSecondAlternateCodingSystemOID(strSecondAlternateCodingSystemOID);
		cwe.setSecondAlternateValueSetOID(strSecondAlternateValueSetOID);
		cwe.setSecondAlternateValueSetVersionID(strSecondAlternateValueSetVersionID); 
		setLoadStatus(cwe);

	} 
	
	/** 
	 * Set the Load Status.
	 * The status of the load.   
	 * @param objLoadStatus Object of Load Status.
	 */ 
	public void setLoadStatus(CWE objLoadStatus)
	{
		setDataType(2101,objLoadStatus);

	}
	
	/**
	 * Set the Control Code.
	 * A code to command the device to send cycle data from the previous load to the instrument-tracking system.  
	 * @param strControlCode Use as Control Code
	 */ 
	public void setControlCode(String strControlCode) 
	{
		NM objNM  = (NM)getDataElement(2102);
		objNM.setValue(strControlCode); 
		setControlCode(objNM);

	} 

	/** 
	 * Set the Control Code.
	 * A code to command the device to send cycle data from the previous load to the instrument-tracking system.
	 * @param objControlCode Use as Control Code
	 */ 
	public void setControlCode(NM objControlCode)
	{
		setDataType(2102,objControlCode);

	}
	
	/**
	 * Set the Operator Name.
	 * The person who started the device load for the decontamination/sterilization process.
	 * @param strOperatorName Used as Operator Name.
	 */ 
	public void setOperatorName(String strOperatorName) 
	{
		ST objST  = (ST)getDataElement(2103);
		objST.setValue(strOperatorName); 
		setOperatorName(objST);

	} 

	/** 
	 * Set the Operator Name.
	 * The person who started the device load for the decontamination/sterilization process.
	 * @param objOperatorName Object of Operator Name.
	 */ 
	public void setOperatorName(ST objOperatorName)
	{
		setDataType(2103,objOperatorName);

	}
	
	/**
	 * 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);
		}
	}
}
