javascriptmirth

Copy multiple repetition PID-3 to PID-4


I have an ORU interface in Mirth which splits to two destinations. I need to make some changes to the PID in Mirth before sending to one destination which I have managed except I cannot seem to copy all of PID3 to PID 4 just the first repetition.

Mirth Connect: 3.7.1

Transformer Code:

var i = msg['PID']['PID.3'].length();
var assigner = msg['PID']['PID.3'][0]['PID.3.4']['PID.3.4.1'].toString();




// PID tweaking for xxx
while(i--)




{
    //Copy all of PID-3 to PID-4
    msg['PID']['PID.4']['PID.4.1']=msg['PID']['PID.3'][i]['PID.3.1'].toString()
    msg['PID']['PID.4']['PID.4.4']['PID.4.4.1']=msg['PID']['PID.3'][i]['PID.3.4'] 
['PID.3.4.1'].toString()
    msg['PID']['PID.4']['PID.4.5']=msg['PID']['PID.3'][i]['PID.3.5'].toString()
    msg['PID']['PID.4']['PID.4.6']=msg['PID']['PID.3'][i]['PID.3.6'].toString()



  



if (msg['PID']['PID.3'][i]['PID.3.5'].toString() == '016') {



        // Copy MRN into PID-2
       msg['PID']['PID.2']['PID.2.1']=msg['PID']['PID.3'][i]['PID.3.1'].toString();
}
//Delete PID-3 and replace with DUMMY ID
if (i!=0){
    delete msg['PID']['PID.3'][i];
} else{
    msg['PID']['PID.3'][i]['PID.3.1']='DUMMY ID';
    delete msg['PID']['PID.3'][i]['PID.3.2'];
    delete msg['PID']['PID.3'][i]['PID.3.3'];
    delete msg['PID']['PID.3'][i]['PID.3.4'];
    delete msg['PID']['PID.3'][i]['PID.3.5'];
    delete msg['PID']['PID.3'][i]['PID.3.6'];        
    }
}

Raw PID:

PID|||485286^^^MRN&&GUID^016^MRN~2858365^^^AUID&&GUID^004^AUID||

Transformed PID:

PID||485286|DUMMY ID|485286^^^MRN^016^MRN|

Desired Transformed PID:

PID||485286|DUMMY ID|485286^^^MRN^016^MRN~2858365^^^AUID&&GUID^004^AUID|

Solution

  • Thanks Gavin, I did initially try this but got the error: TypeError: Cannot set property "PID.4.1" of undefined to "2858365"

    After some more investigation I realised that I needed to create the repetitions in PID-4. So I addition to what Gavin mentioned I needed to add the following above:

    //Ensure a PID.4 exists for each PID.3 repetition
    var i = msg['PID']['PID.3'].length()-1;
    while(i--) {
    msg['PID']['PID.4']=msg['PID']['PID.4']+<PID.4/>;
    }
    var i = msg['PID']['PID.3'].length();