cdac.medinfo.sdk.hl7282.baselibs.segments

## Class Segment

- java.lang.Object
- - cdac.medinfo.sdk.hl7282.baselibs.segments.Segment

- All Implemented Interfaces:
    ISegment
  Direct Known Subclasses:
    ABS, ACC, ADD, ADJ, AFF, AIG, AIL, AIP, AIS, AL1, APR, ARQ, ARV, AUT, BHS, BLC, BLG, BPO, BPX, BTS, BTX, BUI, CDM, CDO, CER, CM0, CM1, CM2, CNS, ConsentSeg, CSP, CSR, CSS, CTD, CTI, DB1, DG1, DMI, DON, DPS, DRG, DSC, DSP, ECD, ECR, EDU, EQL, EQP, EQU, ERQ, ERR, EVN, FAC, FHS, FT1, FTS, GOL, GP1, GP2, GT1, IAM, IAR, IIM, ILT, IN1, IN2, IN3, INV, IPC, IPR, ISD, ITM, IVC, IVT, LAN, LCC, LCH, LDP, LOC, LRL, MCP, MFA, MFE, MFI, MRG, MSA, MSH, NCK, NDS, NK1, NPU, NSC, NST, NTE, OBR, OBX, ODS, ODT, OM1, OM2, OM3, OM4, OM5, OM6, OM7, OMC, ORC, ORG, OVR, PAC, PCE, PCR, PD1, PDA, PDC, PEO, PES, PID, PKG, PM1, PMT, PR1, PRA, PRB, PRC, PRD, PRT, PSG, PSH, PSL, PSS, PTH, PV1, PV2, PYE, QAK, QID, QPD, QRI, RCP, RDF, RDT, REL, RF1, RFI, RGS, RMI, ROL, RQ1, RQD, RXA, RXC, RXD, RXE, RXG, RXO, RXR, RXV, SAC, SCD, SCH, SCP, SDD, SFT, SGH, SGT, SHP, SID, SLT, SPM, SPR, STF, STZ, TCC, TCD, TQ1, TQ2, TXA, UAC, UB2, VAR, VND

      public abstract class Segment
      extends java.lang.Object
      implements ISegment

  Segment is the abstract class which Declares the Methods Parse and Serialize. and a vector variable which contains the list of Fields. This class provides mechanism to serialize, parse and validate segment 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. It provides user with serialize method to serialize message object to any stream & parse method to obtain fully populated & validated Message object from any stream. This class provides the Utility methods likes Update and Remove of Data Elements. This class has a facility to Serialize Segment information on XML and Word Doc.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Segment(ISegmentKey objSegmentKey)` Initialize instance member variable.
    `Segment(ISegmentKey objSegmentKey, ISegmentMap objSegmentMap)` Initialize instance member variable.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addUnRecognizedField(UnRecognizedField objUnRecognizedField)` Add UnRecognizedField in list
    `void` | `dumpSegment(IHL7Stream objIHL7Stream, IDelimiter objIDelimiter, int iLevel)` Serializes Segment information like it name, Attribute name and its values.
    `IMultiValuedPairedCollection<java.lang.Integer,IDataType>` | `getFields()` Get the Fields collection of Segment
    `ISegmentKey` | `getName()` This method returns SegmentName.
    `ISingleCollection<UnRecognizedField>` | `getUnrecognizedFields()` Retrieves list of Unrecognized field.
    `void` | `moveToNextSegment(java.lang.String strFieldStream)` Moves to next Segment.
    `int` | `parse(java.lang.String strSegmentStream, IDelimiter objIDelimiter)` Parses HL7 Segment Strings from any Stream into HL7 Segment object.
    `int` | `removeDataElement(int iItemIDToBeRemoved, boolean isForcefullyRemove)` Removes Data Element from Data Element List
    `int` | `removeDataElement(java.lang.String strAttributeName, boolean isForcefullyRemove)` Removes Data Element from Data Element List
    `int` | `serialize(IHL7Stream objIHL7Stream, IDelimiter objIDelimiter)` Serializes HL7 Message objects.
    `void` | `setName(ISegmentKey enumName)` This method Sets SegmentName.
    `void` | `setUnRecognizedField(java.lang.String segmentName, java.lang.String fieldName, java.lang.String data)`
    `int` | `updateDataElement(int iItemIDToBeUpdated, IDataType objIDataType)` Update Data Element from Data Element List
    `int` | `updateDataElement(int iItemIDToBeUpdated, java.lang.String strSegmentStream, IDelimiter objDelimiter)` Update Data Element from Data Element List
    `boolean` | `validate()` Validates HL7 Message objects .
    `int` | `writeToXML(javax.xml.stream.XMLEventWriter eventWriter)` Method writes the data to the Stream.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Segment

          public Segment(ISegmentKey objSegmentKey)

      Initialize instance member variable.
      Parameters:
        `objSegmentKey` - enum used for SegmentName.

    - #### Segment

          public Segment(ISegmentKey objSegmentKey,
                 ISegmentMap objSegmentMap)

      Initialize instance member variable.
      Parameters:
        `objSegmentKey` - enum used for SegmentName.
        `objSegmentMap` - Object of the Segment Map, containing Map of Segment.

  - ### Method Detail

    - #### addUnRecognizedField

          public void addUnRecognizedField(UnRecognizedField objUnRecognizedField)

      Add UnRecognizedField in list
      Specified by:
        `addUnRecognizedField` in interface `ISegment`
      Parameters:
        `objUnRecognizedField` - object of UnRecognizedField.

    - #### getUnrecognizedFields

          public ISingleCollection<UnRecognizedField> getUnrecognizedFields()

      Retrieves list of Unrecognized field.
      Specified by:
        `getUnrecognizedFields` in interface `ISegment`
      Returns:
        Isinglecollection - list of UnRecognized field.

    - #### getFields

          public IMultiValuedPairedCollection<java.lang.Integer,IDataType> getFields()

      Get the Fields collection of Segment
      Specified by:
        `getFields` in interface `ISegment`
      Returns:
        IMultiValuedPairedCollection>Integer, IDataType< - Collection of DataType of the Segment.

    - #### serialize

          public int serialize(IHL7Stream objIHL7Stream,
                      IDelimiter objIDelimiter)
                        throws SerializeException,
                               java.io.IOException

      Serializes HL7 Message objects. Before serializaton it validates Message as per HL7 v2.8.2 standard. For successfully serialization , Message Object should follow order of segments as per its corresponding Message Structure. Serialize method fails if given stream is null. It mandates presence of required segments and the number of occurrences specified by the standard. This method also checks for presence of Mandatory Groups.It also verifies repeatability of Group.
      Specified by:
        `serialize` in interface `ISegment`
      Parameters:
        `objIHL7Stream` - Object of HL7Stream class
        `objIDelimiter` - Object of Delimiter class present as inner class in MSG class
      Returns:
        int - function status [success/failure].
      Throws:
        `SerializeException` - Thrown when serialization of Message fails.
        `java.io.IOException` - Signals that an I/O exception of some sort has occurred.

    - #### validate

          public boolean validate()
                           throws InvalidSegmentException

      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.
      Specified by:
        `validate` in interface `ISegment`
      Returns:
        boolean - true or false.
      Throws:
        `InvalidSegmentException` - Throws when Segment Validation fails.

    - #### parse

          public int parse(java.lang.String strSegmentStream,
                  IDelimiter objIDelimiter)
                    throws InvalidSegmentException,
                           java.io.IOException

      Parses HL7 Segment Strings from any Stream into HL7 Segment object. This method checks for the Repetition of the fields in the Segment. It also checks for the optionality of the fields as whether they are mandatory or optional. Successful parsing of the segment populates the object with the data present on the stream and provides easy accessor and mutator methods to navigate the message. It also leads to failure if version of given HL7 Message is not 2.8.2. This method raises exception if there is Segment which is not valid as per HL7 v 2.8.2 standard.
      Specified by:
        `parse` in interface `ISegment`
      Parameters:
        `strSegmentStream` - String of HL7Stream.
        `objIDelimiter` - Object of class Delimiter.
      Returns:
        int - Success if segment is valid. - Fail if segment in not valid.
      Throws:
        `InvalidSegmentException` - Thrown when Segment Validation Fails.
        `java.io.IOException` - Signals that an I/O exception of some sort has occurred.

    - #### getName

          public ISegmentKey getName()

      This method returns SegmentName.
      Specified by:
        `getName` in interface `ISegment`
      Returns:
        EnumSegments - enum used for SegmentName.

    - #### setName

          public void setName(ISegmentKey enumName)

      This method Sets SegmentName.
      Specified by:
        `setName` in interface `ISegment`
      Parameters:
        `enumName` - enum used for SegmentName.

    - #### moveToNextSegment

          public void moveToNextSegment(java.lang.String strFieldStream)

      Description copied from interface: `ISegment`
      Moves to next Segment.
      Specified by:
        `moveToNextSegment` in interface `ISegment`
      Parameters:
        `strFieldStream` - String from HL7Stream.

    - #### writeToXML

          public int writeToXML(javax.xml.stream.XMLEventWriter eventWriter)
                         throws java.io.IOException,
                                javax.xml.stream.XMLStreamException

      Method writes the data to the Stream.
      Specified by:
        `writeToXML` in interface `ISegment`
      Parameters:
        `eventWriter` - Object of XMLEventWriter
      Returns:
        int - Success or failure of the read.
      Throws:
        `java.io.IOException` - - if IO operation fails
        `javax.xml.stream.XMLStreamException` - - The base exception for unexpected processing errors. This Exception class is used to report well-formedness errors as well as unexpected processing conditions.

    - #### dumpSegment

          public void dumpSegment(IHL7Stream objIHL7Stream,
                         IDelimiter objIDelimiter,
                         int iLevel)
                           throws DumpException,
                                  java.io.IOException

      Serializes Segment information like it name, Attribute name and its values.
      Specified by:
        `dumpSegment` in interface `ISegment`
      Parameters:
        `objIHL7Stream` - Object of IHL7Stream
        `objIDelimiter` - Object of IDelimiter
        `iLevel` - integer shows level of an attribute.
      Throws:
        `DumpException` - Signals that dump operation is failed
        `java.io.IOException` - Signals that an I/O exception of some sort has occurred.

    - #### removeDataElement

          public int removeDataElement(java.lang.String strAttributeName,
                              boolean isForcefullyRemove)

      Removes Data Element from Data Element List
      Specified by:
        `removeDataElement` in interface `ISegment`
      Parameters:
        `strAttributeName` - String value of Attribute Name.
      Returns:
        True - if attribute removed successfully, else returns false.

    - #### removeDataElement

          public int removeDataElement(int iItemIDToBeRemoved,
                              boolean isForcefullyRemove)

      Removes Data Element from Data Element List
      Specified by:
        `removeDataElement` in interface `ISegment`
      Parameters:
        `iItemIDToBeRemoved` - Integer value for attribute which is Item ID specified by HL7.
      Returns:
        True - if attribute removed successfully, else returns false.

    - #### updateDataElement

          public int updateDataElement(int iItemIDToBeUpdated,
                              java.lang.String strSegmentStream,
                              IDelimiter objDelimiter)
                                throws java.io.IOException

      Update Data Element from Data Element List
      Specified by:
        `updateDataElement` in interface `ISegment`
      Parameters:
        `iItemIDToBeUpdated` - Integer value for attribute which is Item ID specified by HL7.
        `objDelimiter` - Object of IDelimiter
      Returns:
        True - if attribute removed successfully, else returns false.
      Throws:
        `java.io.IOException`

    - #### updateDataElement

          public int updateDataElement(int iItemIDToBeUpdated,
                              IDataType objIDataType)
                                throws java.io.IOException

      Update Data Element from Data Element List
      Specified by:
        `updateDataElement` in interface `ISegment`
      Parameters:
        `iItemIDToBeUpdated` - Integer value for attribute which is Item ID specified by HL7.
        `objIDataType` - Object of DataType.
      Returns:
        True - if attribute removed successfully, else returns false.
      Throws:
        `java.io.IOException`

    - #### setUnRecognizedField

          public void setUnRecognizedField(java.lang.String segmentName,
                                  java.lang.String fieldName,
                                  java.lang.String data)