Announcement

Collapse
No announcement yet.

Segment order of IN1 and IN2

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

  • Segment order of IN1 and IN2

    Mirth 3.1.1.7461
    How can I keep pairs of IN1 and IN2 together while invoking a JS transformer.

    Input:
    MSH blah blah blah
    IN1 (insurance 1)
    IN2 (additional info on insurance 1)
    IN1 (insurance 2)
    IN1 (insurance 3)
    IN2 (additional info on insurance 3)

    Output of JS transformer.
    MSH blah blah blah
    IN1
    IN1
    IN1
    IN2
    IN2

    The receiver will have no way of knowing which insurance the IN2 segments go with.

    I even tried to add a setID to each IN2 so that I could loop through them as the IN1 segments are copied to find the IN2 with the same setID. Not even that worked.

    Here's my latest attempt:


    var segName = "";
    var setID = 1;

    for each (a in msg..IN1) {
    //get leftmost character of IN1.25
    a['IN1.25']['IN1.25.1'] = a['IN1.25']['IN1.25.1'].toString().substring(0,1);
    }
    for each (b in msg..IN2) {
    //add setID to IN2 segments so that we can use the ID later in the message segment sort
    b['IN2.1']['IN2.1.1'] = setID;
    setID++;
    }



    for each (seg in msg.children()) {

    segName = seg.name().toString();
    switch(segName){
    case "MSH":
    tmp.MSH = seg.copy();
    break;

    case "EVN":
    tmp.EVN = seg.copy();
    break;

    case "PID":
    tmp.PID = seg.copy();
    tmp['PID']['PID.1'] = "1";
    break;

    case "NK1":
    tmp.NK1 = msg.NK1.copy();
    break;

    case"PV1":
    tmp.PV1 = seg.copy();
    tmp['PV1']['PV1.1'] = "1";
    break;


    case "DG1":
    tmp.DG1 = msg.DG1.copy();
    break;

    case "IN1":
    tmp.IN1 = msg.IN1.copy();
    var id = seg['IN1.1']['IN1.1.1'].toString();
    for each (a in msg..IN2) {
    if (a['IN2.1']['IN2.1.1'].toString() == id)
    {
    tmp.IN2 = msg.IN2.copy();
    }
    }

    }

    }


    Thanks,
    Steve

  • #2
    Couldn't you nest the IN2 loop within the IN1 loop like you would for an OBR/OBX? It looks like you are closing the IN1 loop and starting the IN2 loop. I believe you could also utilize the getSegmentsAfter function here as well.

    Comment

    Working...
    X