Using a Mirth Transformer to loop through multiple PID.3 Segments

skyman picture skyman · Jun 25, 2015 · Viewed 7.2k times · Source

I have a message structure where I need to loop through multiple PID.3 segments, selecting one with a PID.3.5 == 'MR' and then replacing PID.3.4 with identifier. I understand how to loop through multiple segments such as OBX, but not sub-segments. I have some sample code (not correct) as a start. Any guidance appreciated.

var pid = msg.PID;

for each (pid3 in pid[PID.3]) {
    if (pid3[PID.3.5] == 'MR') {
        pid3[PID.3.4] = 'IDENTIFIER';
    };
};

Answer

skyman picture skyman · Jun 25, 2015

This seems to work

for each (pid3 in msg['PID']['PID.3']) {
    if (pid3['PID.3.5'].toString() == 'MR') {
        pid3['PID.3.4'] = 'IDENTIFIER';
    }
}