No announcement yet.

createSegment function behavior

  • Filter
  • Time
  • Show
Clear All
new posts

  • createSegment function behavior

    In 1.7.1, there are four createSegment function for the xml msg
    createSegment('segmentName'); // Creates a new segment that can be used in any message.
    createSegment('segmentName', msg); // Creates segment in the msg object.
    createSegment('segmentName', msg, i); // Creates a segment in the msg object at a certain index.
    createSegmentAfter('segmentName', target); // Creates a segment after the provided segment object.

    There is no question on the first one, which create a stand alone segment.

    As with the second one, the new segment is created at the very end of the message. Question, does this function return the reference to the newly created segment object? If so, building the contents should be easy. Otherwise, working on this segment can be tricky.

    The third one, a new segment is created at the index "i". For example, the inbound message have the following segments, MSH, EVN, PID, PV1, NK1. Calling this function "createSegment('PV2', msg, 4)" should create the PV2 segment after the PV1 and push NK1 to the 5 position. However, as with my testing, the behavior is not as expected. Instead of inserting PV2 at 4, it adds PV2 at the end of msg.

    The four one is just another form similar to the third. As with the following example, calling "createSegmentAfter('PV2', msg['PV1'])" is expected to create the new segment PV2 after PV1. However, as with my testing, the new segment is also created at the end.

    What is the expected behavior of these functions?

    Can all of above functions returning the reference to the newly created segment object? If so, indivisual field can be easily manipulated for this segment. If not, can a new set of functions be created as
    var segobj = createSegment('segmentName'); // just like the current function
    // manipulate the field for this segment
    createSegmentInMessage(segobj, msg); // add this segment at the end of message
    createSegmentInPosition(segobj, msg, index); // insert segment at position index
    createSegmentAfter(segobj, msg['PV1']); // insert segment after the given segment. If this segment is not exist, add it at the end


  • #2
    Re:createSegment function behavior

    There is a problem with createSegmentAfter - see this issue:
    Chris Lang