cdac.medinfo.sdk.hl7282.baselibs.messages

## Class Message

- java.lang.Object
- - cdac.medinfo.sdk.hl7282.baselibs.messages.Message

- Direct Known Subclasses:
    AbstractQuery, ACK, ADT_A01_Common, ADT_A02, ADT_A03, ADT_A05_Common, ADT_A06_Common, ADT_A09_Common, ADT_A12, ADT_A15, ADT_A16, ADT_A17, ADT_A20, ADT_A21_Common, ADT_A24, ADT_A37, ADT_A38, ADT_A39_Common, ADT_A43_Common, ADT_A44, ADT_A44_Common, ADT_A45, ADT_A47_Common, ADT_A50_Common, ADT_A52_Common, ADT_A54, ADT_A54_Common, ADT_A55, ADT_A60, ADT_A61_Common, BAR_P01, BAR_P02, BAR_P05, BAR_P06, BAR_P10, BAR_P12, BPS_O29, BRP_O30, BRT_O32, BTS_O31, CCF_I22, CCI_I22, CCM_I21, CCQ_I19, CCR_I16_Common, CCU_I20, CQU_I19, CRM_C01_Common, CSU_C09_Common, DBC_O41, DBU_O42, DEL_O46, DEO_O45, DER_O44, DFT_P03, DFT_P11, DPR_O48, DRC_O47, DRG_O43, EAC_U07, EAN_U09, EAR_U08, EHC_E01, EHC_E02, EHC_E04, EHC_E10, EHC_E12, EHC_E13, EHC_E15, EHC_E20, EHC_E21, EHC_E24, ESR_U02, ESU_U01, INR_U06, INU_U05, LSU_U12_Common, MDM_T01_Common, MDM_T02_Common, MFK_M01_Common, MFN_M02, MFN_M04, MFN_M05, MFN_M06, MFN_M07, MFN_M08, MFN_M09, MFN_M10, MFN_M11, MFN_M12, MFN_M13, MFN_M15, MFN_M16, MFN_M17, MFN_M18, NMD_N02, OMB_O27, OMD_O03, OMG_O19, OMI_O23, OML_O21, OML_O33, OML_O35, OML_O39, OMN_O07, OMP_O09, OMQ_O42, OMS_O05, OPL_O37, OPR_O38, OPU_R25, ORA_R33, ORA_R41, ORB_O28, ORD_O04, ORG_O20, ORN_O08, ORP_O10, ORS_O06, ORU_R01, ORU_R01_Common, ORU_R30_Common, ORU_R40, ORX_O43, OSM_R26, OSU_O41, OUL_R22, OUL_R23, OUL_R24, PEX_P07_Common, PGL_PC6_Common, PMU_B01_Common, PMU_B03, PMU_B04_Common, PMU_B07, PMU_B08, PPG_PCG_Common, PPP_PCB_Common, PPR_PC1_Common, RAS_O17, RDE_O11_Common, RDS_O13, REF_I12_Common, RGV_O15, RPA_I08_Common, RPI_I01_Common, RPL_I02, RPR_I03, RQA_I08_Common, RQI_I01_Common, RQP_I04, RRA_O18, RRD_O14, RRE_O12_Common, RRG_O16, RRI_I12_Common, RSP_K22, RTB_Z74, SDR_S31_Common, SDR_S32_Common, SIU_S12_Common, SLR_S28_Common, SRM_S01_Common, SSR_U04, SSU_U03, STC_S33, TCU_U10_Common, VXU_V04

      public abstract class Message
      extends java.lang.Object

  Message is the abstract class which Declares the Methods Parse and Serialize. and a vector variable which contains the list of Segments. This class provides mechanism to serialize, parse and validate message against HL7 v 2.8.2 standard. The class provides accessors & mutators for the elements mentioned above. These elements can be easily populated & populated values can be easily retrieved. 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.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Message(IMap objMessageMap, java.lang.String strMessageCode, java.lang.String strTriggerEvent, java.lang.String strMessageStructure)` Parameterized Constructor of Message which takes MessageMap, Message Code, Trigger Event and Message Structure.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `contains(ISegmentKey enumSegments)` Check weather Segment or Group is present or not.
    `void` | `dumpMessage(IHL7Stream objIHL7Stream)` Serializes message Information in the form of Attribute Name and its Value.
    `void` | `dumpMessage(java.lang.String strFilePath)` Serializes message Information in the form of Attribute Name and its Value.
    `EnumAcknowledgementMode` | `getACKMode()` Retrieves ACK mode.
    `ISingleCollection<IGroup>` | `getGroup(ISegmentKey enumSegments)` Get the Group Collection from the Message with the help of provided Segment Key.
    `IMap` | `getGroupMap(ISegmentKey enumGroupName)` Retrieves Map of specified Group name.
    `MSH` | `getHeader()` Retrieves Message Header(MSH)
    `java.lang.String` | `getMessageCode()` Retrieves Message Code of Message.
    `java.lang.String` | `getMessageControlID()` Returns MessageControlID from MSA segment of this message.
    `java.lang.String` | `getMessageStructure()` Retrieves Message Structure of Message.
    `ISingleCollection<IDataType>` | `getQueryUserParameters()` Retrieves collection of User Parameters from QPD Segment of Message, if QPD segment is absent returns null.
    `ISingleCollection<ISegment>` | `getSegment(ISegmentKey enumSegments)` Get the Segment Collection from the Message with the help of provided Segment Key.
    `ISegmentSet` | `getSegmentSet()` Retrieves populated SegmentSet from message structure.
    `EnumSubscriptionType` | `getSubscriptionType()` gets SubscriptionType for Message.
    `java.lang.String` | `getTriggerEvent()` Retrieves Trigger Event of Message.
    `boolean` | `isQuery()` Verifies whether message is Query.
    `boolean` | `isResponse()` Verifies whether message is Response.
    `int` | `populate(ISegmentSet objSegmentSet)` Populates Message using provided SegmentSet according to Message Structure specified by HL7 standard.
    `void` | `removeGroup(ISegmentKey enumSegments)` Remove the Group from the Message.
    `void` | `removeSegment(ISegmentKey enumSegments)` Remove the Segment from the Message.
    `int` | `removeSegment(ISegmentKey enumSearchSegment, boolean isForcefullyRemove)` Removes only first level Segments or Group from the HL7 Message.
    `int` | `removeSegmentAttribute(ISegmentKey removeSegmentKey, int iItemID, boolean isForcefullyRemove)` Removes Attribute of a segment.
    `int` | `removeSegmentAttribute(ISegmentKey removeSegmentKey, java.lang.String strAttributeName, boolean isForcefullyRemove)` Removes Attribute of a segment.
    `int` | `removeSegmentAttribute(MultiValuedPairedCollection<ISegmentKey,java.lang.Integer> objSegmentKeyCollection, boolean isForcefullyRemove)` Removes Attribute of a segment.
    `int` | `removeSegments(ISingleCollection<ISegmentKey> objSegmentKeyCollection, boolean isForcefullyRemove)` Removes collection of first level message or segments from HL7 message
    `void` | `setHeader(MSH objMSH)` Sets Message Header
    `void` | `setSubscriptionType(EnumSubscriptionType enumSubscriptionType)` Sets SubscriptionType for Message.
    `int` | `updateSegmentAttribute(ISegmentKey removeSegmentKey, int iItemID, IDataType objIDataType)` Removes Attribute of a segment.
    `int` | `updateSegmentAttribute(ISegmentKey removeSegmentKey, int iItemID, java.lang.String strSegmentStream, IDelimiter objDelimiter)` Removes Attribute of a segment.
    `boolean` | `validate()` Validates HL7 Message objects.
    `int` | `writeToXML(IHL7Stream objIHL7Stream)` Serializes message Information in the form of Attribute Name and its Value.
    `int` | `writeToXML(java.lang.String strFilePath)` Serializes message Information in the form of Attribute Name and its Value.

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

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

- - ### Constructor Detail

    - #### Message

          public Message(IMap objMessageMap,
                 java.lang.String strMessageCode,
                 java.lang.String strTriggerEvent,
                 java.lang.String strMessageStructure)

      Parameterized Constructor of Message which takes MessageMap, Message Code, Trigger Event and Message Structure.
      Parameters:
        `objMessageMap` - Object of IMap
        `strMessageCode` - Message Code of Message
        `strTriggerEvent` - Event of Message
        `strMessageStructure` - Message structure of Message

  - ### Method Detail

    - #### getMessageStructure

          public java.lang.String getMessageStructure()

      Retrieves Message Structure of Message.
      Returns:
        String Message Structure

    - #### getMessageCode

          public java.lang.String getMessageCode()

      Retrieves Message Code of Message.
      Returns:
        String Message Code

    - #### getTriggerEvent

          public java.lang.String getTriggerEvent()

      Retrieves Trigger Event of Message.
      Returns:
        String Trigger Event

    - #### getSegment

          public ISingleCollection<ISegment> getSegment(ISegmentKey enumSegments)

      Get the Segment Collection from the Message with the help of provided Segment Key.
      Parameters:
        `enumSegments` - Object of ISegmentKey provides name of Segment
      Returns:
        ISingleCollection<ISegment> - Collection of the Segment

    - #### getGroup

          public ISingleCollection<IGroup> getGroup(ISegmentKey enumSegments)

      Get the Group Collection from the Message with the help of provided Segment Key.
      Parameters:
        `enumSegments` - Object of ISegmentKey provides name of Group
      Returns:
        ISingleCollection<IGroup> - Collection of the Group

    - #### contains

          public boolean contains(ISegmentKey enumSegments)

      Check weather Segment or Group is present or not.
      Parameters:
        `enumSegments` - Object of ISegmentKey provides name of Segment
      Returns:
        boolean - true: if contains otherwise false

    - #### removeSegment

          public void removeSegment(ISegmentKey enumSegments)

      Remove the Segment from the Message.
      Parameters:
        `enumSegments` - Object of ISegmentKey provides name of Segment

    - #### removeGroup

          public void removeGroup(ISegmentKey enumSegments)

      Remove the Group from the Message.
      Parameters:
        `enumSegments` - Object of ISegmentKey provides name of Group

    - #### setHeader

          public void setHeader(MSH objMSH)

      Sets Message Header
      Parameters:
        `objMSH` - Specified Message Header(MSH)

    - #### getHeader

          public MSH getHeader()

      Retrieves Message Header(MSH)
      Returns:
        MSH - the Message Header(MSH) present in this message or null if unavailable

    - #### getQueryUserParameters

          public ISingleCollection<IDataType> getQueryUserParameters()

      Retrieves collection of User Parameters from QPD Segment of Message, if QPD segment is absent returns null.
      Returns:
        ISingleCollection SingleCollection of User Parameters

    - #### getACKMode

          public EnumAcknowledgementMode getACKMode()

      Retrieves ACK mode.
      Returns:
        EnumAcknowledgementMode

    - #### isQuery

          public boolean isQuery()

      Verifies whether message is Query.
      Returns:
        boolean

    - #### isResponse

          public boolean isResponse()

      Verifies whether message is Response.
      Returns:
        boolean

    - #### getMessageControlID

          public java.lang.String getMessageControlID()

      Returns MessageControlID from MSA segment of this message.
      Returns:
        String in form of MessageControl ID

    - #### populate

          public int populate(ISegmentSet objSegmentSet)
                       throws InvalidMessageException

      Populates Message using provided SegmentSet according to Message Structure specified by HL7 standard.
      Parameters:
        `objSegmentSet` - instance of SegmentSet
      Returns:
        int - shows status as success or failure
      Throws:
        `InvalidMessageException` - If message validation fails

    - #### getSegmentSet

          public ISegmentSet getSegmentSet()
                                    throws InvalidMessageException

      Retrieves populated SegmentSet from message structure.
      Returns:
        ISegmentSet - instance of SegmentSet
      Throws:
        `InvalidMessageException` - If message validation fails

    - #### validate

          public boolean validate()
                           throws InvalidMessageException

      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
      Returns:
        boolean - true If Message and all segments in side it are validated properly - false If segment in side it is not validated properly and if compulsory segments are not present
      Throws:
        `InvalidMessageException` - Thrown when Message validation fails

    - #### getGroupMap

          public IMap getGroupMap(ISegmentKey enumGroupName)

      Retrieves Map of specified Group name.
      Parameters:
        `enumGroupName` - Object of ISegmentKey provides name of Group
      Returns:
        IMap - Object of IMap

    - #### dumpMessage

          public void dumpMessage(IHL7Stream objIHL7Stream)
                           throws java.io.IOException

      Serializes message Information in the form of Attribute Name and its Value.
      Parameters:
        `objIHL7Stream` - Object of IHL7Stream
      Throws:
        `java.io.IOException` - Signals that an I/O exception of some sort has occurred

    - #### dumpMessage

          public void dumpMessage(java.lang.String strFilePath)
                           throws java.io.IOException

      Serializes message Information in the form of Attribute Name and its Value.
      Parameters:
        `strFilePath` - Full path with file name where dump will be stored
      Throws:
        `java.io.IOException` - Signals that an I/O exception of some sort has occurred

    - #### removeSegment

          public int removeSegment(ISegmentKey enumSearchSegment,
                          boolean isForcefullyRemove)

      Removes only first level Segments or Group from the HL7 Message.
      Parameters:
        `enumSearchSegment` - enumSearchSegment Object of ISegmentKey provides name of Segment or Group
        `isForecefullyRemove` - Boolean value if True - Removes the Segment or Group forcefully regardless of whether resulting HL7 message is valid or not If false - Remove the Segment or Group from message only if resulting message is valid
      Returns:
        int HL7Constant Integer value specifying success or failure of function

    - #### removeSegments

          public int removeSegments(ISingleCollection<ISegmentKey> objSegmentKeyCollection,
                           boolean isForcefullyRemove)

      Removes collection of first level message or segments from HL7 message
      Parameters:
        `objSegmentCollection` - Object of ISingleCollection of ISegments to be removed
        `isForecefullyRemove` - Boolean value if True - Removes the Segment or Group forcefully regardless of whether resulting HL7 message is valid or not If false - Remove the Segment or Group from message only if resulting message is valid
      Returns:
        int HL7Constant Integer value specifying success or failure of function

    - #### removeSegmentAttribute

          public int removeSegmentAttribute(ISegmentKey removeSegmentKey,
                                   java.lang.String strAttributeName,
                                   boolean isForcefullyRemove)

      Removes Attribute of a segment.
      Parameters:
        `removeSegmentKey` - Object of ISegmentKey specifies name of a segment
        `strAttributeName` - String value for name of attribute
        `isForecefullyRemove` - Boolean value if True - Removes the Segment or Group forcefully regardless of whether resulting HL7 message is valid or not If false - Remove the Segment or Group from message only if resulting message is valid
      Returns:
        int - integer value 5 for successfully execution of function and -1 - for failure of a function

    - #### removeSegmentAttribute

          public int removeSegmentAttribute(MultiValuedPairedCollection<ISegmentKey,java.lang.Integer> objSegmentKeyCollection,
                                   boolean isForcefullyRemove)

      Removes Attribute of a segment.
      Parameters:
        `objSegmentKeyCollection` - Object containing Collection of SegmentKey and its item ID
      Returns:
        integer value 5 - for successfully execution of function and -1 - for failure of a function

    - #### removeSegmentAttribute

          public int removeSegmentAttribute(ISegmentKey removeSegmentKey,
                                   int iItemID,
                                   boolean isForcefullyRemove)

      Removes Attribute of a segment.
      Parameters:
        `removeSegmentKey` - Object of ISegmentKey specifies name of a segment
        `iItemID` - Integer value for attribute which is Item ID specified by HL7
      Returns:
        integervalue 5 - for successfully execution of function and -1 - for failure of a function

    - #### updateSegmentAttribute

          public int updateSegmentAttribute(ISegmentKey removeSegmentKey,
                                   int iItemID,
                                   java.lang.String strSegmentStream,
                                   IDelimiter objDelimiter)
                                     throws java.io.IOException

      Removes Attribute of a segment.
      Parameters:
        `removeSegmentKey` - Object of ISegmentKey specifies name of a segment
        `iItemID` - Integer value for attribute which is Item ID specified by HL7
      Returns:
        integervalue 5 - for successfully excecution of function and -1 - for failure of a function
      Throws:
        `java.io.IOException`

    - #### updateSegmentAttribute

          public int updateSegmentAttribute(ISegmentKey removeSegmentKey,
                                   int iItemID,
                                   IDataType objIDataType)
                                     throws java.io.IOException

      Removes Attribute of a segment.
      Parameters:
        `removeSegmentKey` - Object of ISegmentKey specifies name of a segment
        `iItemID` - Integer value for attribute which is Item ID specified by HL7
      Returns:
        integervalue 5 - for successfully excecution of function and -1 - for failure of a function
      Throws:
        `java.io.IOException`

    - #### setSubscriptionType

          public void setSubscriptionType(EnumSubscriptionType enumSubscriptionType)

      Sets SubscriptionType for Message.
      Parameters:
        `enumSubscriptionType` - it states for subscription type whether it is new or modified

    - #### getSubscriptionType

          public EnumSubscriptionType getSubscriptionType()

      gets SubscriptionType for Message.
      Returns:
        EnumSubscriptionType gets subscription type for the message

    - #### writeToXML

          public int writeToXML(java.lang.String strFilePath)
                         throws java.io.IOException,
                                javax.xml.stream.XMLStreamException

      Serializes message Information in the form of Attribute Name and its Value.
      Parameters:
        `strFilePath` - Destination file path
      Returns:
        int - Returns success or fail
      Throws:
        `java.io.IOException`
        `javax.xml.stream.XMLStreamException`

    - #### writeToXML

          public int writeToXML(IHL7Stream objIHL7Stream)
                         throws java.io.IOException,
                                javax.xml.stream.XMLStreamException

      Serializes message Information in the form of Attribute Name and its Value.
      Parameters:
        `objIHL7Stream` - object if IHL7Stream
      Returns:
        int - Returns success or fail
      Throws:
        `java.io.IOException`
        `javax.xml.stream.XMLStreamException`