Announcement

Collapse

Mirth Connect 3.12.0 Released!

Mirth Connect 3.12.0 is now available as an appliance update and on our GitHub page. This release includes database performance improvements, improves visual HL7 representation, message pruning, keystore handling, PDF generation, community contributions, and fixes several security vulnerabilities. This release also contains many improvements to commercial extensions. See the release notes for the list of fixes and updates.

Download | See What's New | Upgrade Guide | Release Notes

For discussion on this release, see this thread.
See more
See less

Moving IN1 and Child IN2 Segs to the Outbound Msg

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Moving IN1 and Child IN2 Segs to the Outbound Msg

    Hi All!

    I?ve struggled recently attempting to match optional child IN2 segments with its parent IN1 segment. After a lot of head scratching, fist pounding, and experimentation I finally figure out how to do it in javascript! Yay? Anyhoo, I thought I?d share my solution in case anyone else out there may need an example. For what it?s worth, here goes ?.

    The problem is as follows: You have repeating IN1 segments with optional, child IN2 segments. Here?s a couple of possible patterns:

    Pattern 1
    IN1
    IN2
    IN1
    IN2
    IN1
    IN2

    Pattern 2
    IN1
    IN1
    IN2
    IN1
    IN2

    You need to move the IN1/IN2 block from the inbound to the outbound message possibly making changes to the IN1/IN2 message content for the outbound.

    Here?s a verbal description of the solution I came up with. Please note that this particular solution may not be the best one; in fact it may be the worst one. However, it works which for now pleases me greatly.

    Take an initial pass through the inbound message a build a map of the IN1/IN2 pattern found.

    Process the incoming message. When an IN1 segment is detected move it to the outbound message then use the map created in the initial pass to determine whether there is an associated IN2 segment. If there is an associated IN2 segment create one in the outbound message and move the appropriate inbound IN2 segment to the outbound message under the IN1 segment.

    If there is no associated IN2 segment do nothing and go back to reading the inbound message.

    The map mentioned above is, in reality, two ?text? arrays containing the word ?IN1?, ?IN2, or ?no?. The first array holds the IN1 pattern and the second array holds the IN2 pattern. So let?s take pattern number 1 above and build the IN1/IN2 map:

    Pattern 1 Array 1
    ?IN1?
    ?IN1?
    ?IN1?

    Pattern 1 Array 2
    ?IN2?
    ?IN2?
    ?IN2?

    Here?s the map of pattern number 2 above:

    Pattern 2 Array 1
    ?IN1?
    ?IN1?
    ?IN1?

    Pattern 2 Array 2
    ?no?
    ?IN2?
    ?IN2?

    As you can see the map of pattern number 1 indicates that every IN1 segment has an associated IN2 segment. In pattern number 2 the second and third IN1 segments have an associated IN2 segment. The first IN1 segment does not. As you loop through the IN1 segments in the incoming message, it?s a simple matter to use the map arrays to determine if any given IN1 segment has an associated IN2 segment. You can grab the corresponding incoming IN2 segment based on the index number you?re using to loop through the IN1s.

    Here? the code ?

    Code:
    //
    // Build a map of IN1s and any associated IN2 segments for use below
    //
    var rawhl7 = messageObject.getRawData();
    var parts = [];
    var in1ary = [];
    var in2ary = [];
    var x=0;
    var x1=0;
    var x2=0;
    parts = rawhl7.split('r');
    for (x in parts)
    {
        var a = parts[x].substring(0,3);
        if (a == "IN1"«»)
        {
            in1ary[x1] = a;
            x1++;
    //	logger.error('x=' + x);
            var c=x;
            c++;
    //	logger.error('c: ' + c + ' parts[' + c + ']=' + parts[c]);
            if (parts[c].substring(0,3) != "IN2"«»)
            {
                in2ary[x2] = "no";
                x2++;
            }
        }
        if (a == "IN2"«»)
        {
            in2ary[x2] = a;
            x2++
        }
    }
    //
    // *********************** This is "below" ******************
    //
    var i = 0;
    var j = 0;
    for each (in1 in msg..IN1)
    {
        var it1 = msg['IN1'][i];
        tmp['IN1'][i] = in1;
        if (in2ary[i] == "IN2"«»)
        {
            in2 = msg['IN2'][j];
            tmp['IN2'][j] = in2;
            j++;
        }
        i++;
    }
    Again, this may not (and probably is not) the best solution to the problem. If you've done something like this in a completely different way I'd absolutely love to see it.

    Bob Dilworth
    University of Toledo Medical Center
    Toledo, Ohio
    [email protected]

    Post edited by: bdilworth, at: 08/07/2008 08:13

    Post edited by: bdilworth, at: 08/07/2008 10:22
    Bob Dilworth
    University of Toledo Medical Center
    Toledo, Ohio
Working...
X