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

9.2k views Asked by At

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';
    };
};
1

There are 1 answers

0
skyman On BEST ANSWER

This seems to work

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