Search code examples
javascripthl7mirthmirth-connect

How to loop over all the headers in hl7 message in mirth?


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.


Solution

  • 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