AddSegmentAfter()

Top  Previous  Next

<----------New In Version 4.x---------->

Object: EHL7.EHL7Message

FileName: EHL7.dll

 

METHOD

 

Name: AddSegmentAfter() / AddSegmentBefore()

Parameters:

1.oSegment (The reference segment object)
2.strSegment (String) the name of the HL7 Segment to add.
3.bIncludeDefault (optional Boolean default = False)

Returns: Object (Segment Object) - The segment object that was created.

Description: Adds a segment to the current message either after (AddSegmentAfter) or before (AddSegmentBefore) the reference segment passed in the first parameter

 

Programming Notes:

1.The segment name passed in strSegment must exist in the HL7 definition of the vendor being used to create the message. 
2.The MSH segment is automatically created, see CreateMessage()
3.EasyHL7 does not validate the sequential validity of the message, segments will appear in the message in the order in which they are added.  It is up to you to add the segments in the correct order (if applicable) for the type of hl7 message you are creating.
4.If bIncludeDefault is passed as [True] then IF default values have been set up in the vendor definitions, the default values will be populated for all elements in the segment.  If bIncludeDefault is passed as [False] (the default) default values configured in the vendor definition are ignored.  See Extended Element Properties.
5.Calling AddSegmentBefore() and passing the MSH segment object for the message in oSegment will create an error.
6.Calling AddSegmentAfter() and passing the last segment in the message in the first parameter is functionally equivalent to calling the AddSegment() function.

Example:

Private Sub MessageTest()

'Creates a message, adds an EVN segment then

Dim myVendorObj As New EHL7.HL7Vendors

Dim myMsg As New EHL7.EHL7Message

Dim strVendorID As String

Dim oSegment As Object,oPID As Object

Dim oMSH As Object

myVendorObj.VendorPath = "C:\EasyHL7"

strVendorID = myVendorObj.GetVendorID("Default","2.3")

If strVendorID = "" Then

    MsgBox myVendorObj.LastError

    Set myVendorObj = Nothing

    Exit Sub

End If

If Not MyVendorObj.OpenVendor(strVendorID) Then

    MsgBox myVendorObj.LastError

    Set myVendorObj = Nothing

    Exit Sub

End If

With myMsg

   Set oMSH = .CreateMessage(myVendorObj, True)

   If .IsError Then

     MsgBox .LastError

     .ClearErrors

     Exit Sub

   End If

   Set oSegment = .AddSegment("EVN",True)

   Set oPID = .AddSegmentAfter(oSegment,"PID",True)

   If .IsError Then

     MsgBox .LastError

     .ClearErrors

     Exit Sub

   End If

End With

End Sub