2

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|
agermano
  • 1,679
  • 6
  • 16
SCH
  • 21
  • 2

3 Answers3

1

You need to index your left hand side. For example, instead of

 msg['PID']['PID.4']['PID.4.5']=msg['PID']['PID.3'][i]['PID.3.5'].toString()

You would need

  msg['PID']['PID.4'][i]['PID.4.5']=msg['PID']['PID.3'][i]['PID.3.5'].toString()
Gavin Perkins
  • 685
  • 1
  • 9
  • 28
0

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();
SCH
  • 21
  • 2
0

There is an official repository of code templates at https://github.com/nextgenhealthcare/connect-examples

There is a useful code template for doing this called renameField found here.

Using that code template, you can reduce all of your code down to

// Copy all repetitions of PID-3 to PID-4
msg['PID']['PID.4'] = renameField(msg['PID']['PID.3'], 'PID.4');
// Iterate over PID-3 repetitions
for each (var pid3 in msg['PID']['PID.3']) {
    if (pid3['PID.3.5'].toString() == '016') {
        // Copy MRN into PID-2
        msg['PID']['PID.2']['PID.2.1'] = pid3['PID.3.1'].toString();
    }
}
// Replace all PID-3 with single repetition containing only DUMMY ID using xml literal
msg['PID']['PID.3'] = <PID.3><PID.3.1>DUMMY ID</PID.3.1></PID.3>;
agermano
  • 1,679
  • 6
  • 16