3

I'm new to mirth and trying to loop over all the hl7 message headers in mirth, I know that I can loop over one header like this:

for each(var OBX in msg['OBX']) {
    logger.info('message OBX obj: ' + OBX['OBX.3']['OBX.3.2'].toString());
}

but what I need is to loop over all the headers not one so I'm trying to do something like this:

for each(var header in msg) {
        logger.info('message header: ' + header.toString());
}

for each(var header in msg['HL7Message']) {
    logger.info('message header: ' + header.toString());
}

but this is not working and also I can't convert the hl7 to json please help and many thanks in advance.

Alex Ananjev
  • 269
  • 3
  • 16
Fadi
  • 2,320
  • 8
  • 38
  • 77

1 Answers1

1

i have found a way to loop over, the msg variable is the current instance of the inbound message

for each (seg in msg.elements()) {
 logger.info('message elements: ' + JSON.stringify(seg.name().toString()));
}

some useful links:

https://www.mirthcorp.com/community/forums/showthread.php?t=6902&page=2
http://www.mirthproject.org/community/forums/showthread.php?t=12334
https://wso2.com/project/mashup/0.2/docs/e4xquickstart.html
https://stackoverflow.com/questions/6601712/what-does-msg-mean-in-mirth
Fadi
  • 2,320
  • 8
  • 38
  • 77
  • @Shamil first thank you for your great comment, and second can you post the link for the two code snippets. – Fadi Aug 02 '18 at 06:22
  • @Fadi: How do you like me to post the link? Link to where? Open any channel, open filter or transformer editor, select "Reference" tab and look for "iterate ..." functions in the list. Drag and drop those to your JS step. – Shamil Aug 02 '18 at 19:09