Mirth Connect
  1. Mirth Connect
  2. MIRTH-621

Cannot add a segment if segment is not listed in Sample Output

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.6.1
    • Fix Version/s: 1.7.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      MS Win2003 Server
    • Operating System:
      Windows XP

      Description

      When adding segments to an HL7 message, cannot add a segment unless a placeholder segment is specified in the Outgoing Data.

      For Example this code:
      tmp['OBX'][i] = obx;

      will not create a segment unless it is specified in the Outgoing Data tab. In my case my initial message specified in the Outgoing Data tab looks like:

      MSH|^~\&|||||||||||||||
      EVN|||
      PID|||||||||||||||||||||||||||||||
      PV1|||||||||||||||||||||||||||||||||||||||||||||||||||
      OBX|||||||
      AL1||||||

      Another issue is if for some reason a new OBX tag is not added, the script has to delete the placeholder tag. If the ability to add a segment is fixed, then it will not be necessary to delete the original tag.

        Activity

        Hide
        Christopher Lang added a comment -

        Brendan -

        Can reply with code that accomplishes this, or is this a bug in Mirth?

        Show
        Christopher Lang added a comment - Brendan - Can reply with code that accomplishes this, or is this a bug in Mirth?
        Hide
        John Lehew added a comment -

        I believe this is a bug. Here is the channel backup so you can see the code I'm running.

        Regards,
        John

        Show
        John Lehew added a comment - I believe this is a bug. Here is the channel backup so you can see the code I'm running. Regards, John
        Hide
        John Lehew added a comment -

        One more comment. This will be a breaking change if it is fixed. I'll have to modify my code to not delete the original segment.

        Thanks!
        John

        Show
        John Lehew added a comment - One more comment. This will be a breaking change if it is fixed. I'll have to modify my code to not delete the original segment. Thanks! John
        Hide
        Brendan Haverlock added a comment -

        This is not a bug, as this segment clearly isn't defined in the template XML.

        tmp['OBX'][i] = new XML("<OBX></OBX>");

        Chris, do you think we should automatically create the segment if someone tries to do an assignment to an undefinede segment (or is this even possible, since you were involved with this code?). Or, we should have at least a helper function to create segments e.g. createSegment("OBX").

        Show
        Brendan Haverlock added a comment - This is not a bug, as this segment clearly isn't defined in the template XML. tmp ['OBX'] [i] = new XML("<OBX></OBX>"); Chris, do you think we should automatically create the segment if someone tries to do an assignment to an undefinede segment (or is this even possible, since you were involved with this code?). Or, we should have at least a helper function to create segments e.g. createSegment("OBX").
        Hide
        John Lehew added a comment -

        When I'm working in HL7, it doesn't seem like I'm working with XML even though they seem to parallel each other the more I work with Mirth. So when I didn't find a way to add a segment with HL7, I didn't think to use "new XML".

        I like the idea of a helper function especially since there is a delete segment function. The new function could be written like createSegment( <SegmentName> , <Position>) where Position=0 is first row, Position=-1 is Last row, and Position with a valid number is the row number to add with the Default set to Last row. At least drop in an example like tmp['OBX'][i] = new XML("<OBX></OBX>");

        There is a delete segment function but when it is dragged and dropped the keyword is delete instead of deleteSegment. Not sure if that is worth changing the keyword or not.

        It may also be helpful to create a thread or example of how to create a message entirely from scratch.

        Show
        John Lehew added a comment - When I'm working in HL7, it doesn't seem like I'm working with XML even though they seem to parallel each other the more I work with Mirth. So when I didn't find a way to add a segment with HL7, I didn't think to use "new XML". I like the idea of a helper function especially since there is a delete segment function. The new function could be written like createSegment( <SegmentName> , <Position>) where Position=0 is first row, Position=-1 is Last row, and Position with a valid number is the row number to add with the Default set to Last row. At least drop in an example like tmp ['OBX'] [i] = new XML("<OBX></OBX>"); There is a delete segment function but when it is dragged and dropped the keyword is delete instead of deleteSegment. Not sure if that is worth changing the keyword or not. It may also be helpful to create a thread or example of how to create a message entirely from scratch.
        Hide
        Brendan Haverlock added a comment -

        >> When I'm working in HL7, it doesn't seem like I'm working with XML even though they seem to parallel each other the more I work with Mirth. So when I didn't find a way to add a segment with HL7, I didn't think to use "new XML".

        The advanced HL7 building that you are doing generally requires this knowledge. We will try to abstract it further with a new function.

        >> I like the idea of a helper function especially since there is a delete segment function. The new function could be written like createSegment( <SegmentName> , <Position>) where Position=0 is first row, Position=-1 is Last row, and Position with a valid number is the row number to add with the Default set to Last row. At least drop in an example like tmp['OBX'][i] = new XML("<OBX></OBX>");

        This is a good idea to include the position in the function.

        >> There is a delete segment function but when it is dragged and dropped the keyword is delete instead of deleteSegment. Not sure if that is worth changing the keyword or not.

        "delete" is a function defined in E4X for deleting an XML element.

        >> It may also be helpful to create a thread or example of how to create a message entirely from scratch.

        That's a good idea, although documentation is in the works to explain how to do this.

        Show
        Brendan Haverlock added a comment - >> When I'm working in HL7, it doesn't seem like I'm working with XML even though they seem to parallel each other the more I work with Mirth. So when I didn't find a way to add a segment with HL7, I didn't think to use "new XML". The advanced HL7 building that you are doing generally requires this knowledge. We will try to abstract it further with a new function. >> I like the idea of a helper function especially since there is a delete segment function. The new function could be written like createSegment( <SegmentName> , <Position>) where Position=0 is first row, Position=-1 is Last row, and Position with a valid number is the row number to add with the Default set to Last row. At least drop in an example like tmp ['OBX'] [i] = new XML("<OBX></OBX>"); This is a good idea to include the position in the function. >> There is a delete segment function but when it is dragged and dropped the keyword is delete instead of deleteSegment. Not sure if that is worth changing the keyword or not. "delete" is a function defined in E4X for deleting an XML element. >> It may also be helpful to create a thread or example of how to create a message entirely from scratch. That's a good idea, although documentation is in the works to explain how to do this.
        Hide
        Christopher Lang added a comment -

        Updated create segment:

        createSegment(segmentName); //Returns a single segment XML node that can be placed anywhere
        createSegment(segmentName, xmlTarget); //Creates a segment in the targetXML (msg or tmp) and returns a reference to the new segment in the target
        createSegment(segmentName, xmlTarget, index); //Creates a segment in the targetXML (msg or tmp) at the specified SEGMENT index (not message index) and returns a reference to the new segment in the target. Equivalent to xmlTarger['OBX'][index] = new XML("<OBX></OBX>");

        Example:

        for (var i = 1; i < 5; i++)

        { createSegment(msg, 'OBX', i)['OBX.5']['OBX.5.1'] = "test" + i; }
        Show
        Christopher Lang added a comment - Updated create segment: createSegment(segmentName); //Returns a single segment XML node that can be placed anywhere createSegment(segmentName, xmlTarget); //Creates a segment in the targetXML (msg or tmp) and returns a reference to the new segment in the target createSegment(segmentName, xmlTarget, index); //Creates a segment in the targetXML (msg or tmp) at the specified SEGMENT index (not message index) and returns a reference to the new segment in the target. Equivalent to xmlTarger ['OBX'] [index] = new XML("<OBX></OBX>"); Example: for (var i = 1; i < 5; i++) { createSegment(msg, 'OBX', i)['OBX.5']['OBX.5.1'] = "test" + i; }
        Hide
        Paul Bugni added a comment -

        The arguments in the example are transposed. It should read:

        for (var i = 1; i < 5; i++)

        { createSegment('OBX', msg, i)['OBX.5']['OBX.5.1'] = "test" + i; }
        Show
        Paul Bugni added a comment - The arguments in the example are transposed. It should read: for (var i = 1; i < 5; i++) { createSegment('OBX', msg, i)['OBX.5']['OBX.5.1'] = "test" + i; }

          People

          • Assignee:
            Christopher Lang
            Reporter:
            John Lehew
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 1 week, 1 day
              1w 1d
              Remaining:
              Remaining Estimate - 1 week, 1 day
              1w 1d
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development