Replace OBX to NTE


I had a situation where in, all the OBX segments in a HL7 message is supposed to change to NTE. I am not sure why, but this was the requirement.

I have used various techniques to do so but most of them failed.

Then one of the finest clue I could get from http://www.mirthcorp.com/community/forums/showthread.php?t=6525

Loop for each OBX
  Loop foe each fields in OBX
    start copying them into NTE

But you know this trick has an headache that no. of fields were not constant in my case. Sometimes OBX|1 has just 20 fields, somtiems may be the 25th field will be present. Hence copying each segment-field to NTE stopped me to do so.

Finally the outcome which I found, seems to be the easiest solution ever:

     channelMap.put('originalHL7msg', messageObject.getRawData());
    var originalHL7msg = channelMap.get('originalHL7msg');
    var customHL7msg = originalHL7msg.replaceAll("OBX\\|", "NTE\\|").toString(); // Listen you cant replace the msg neither converted msg to xml.toString or anything will not work.
    channelMap.put("customHL7msg", customHL7msg);

And finally at the output end, just use “customHL7msg” as the final output message instead encoded data.

2 comments on “Replace OBX to NTE

  1. Kicha says:

    This realy helpful thanks for sharing this code

  2. Ladonna says:

    I ԝas pretty pleased to discover tҺis pagᥱ. І wanteԁ to thank you foг yߋur timе foг thіѕ partіcularly
    fantastic гead!! I defіnitely savorerd еvery ⅼittle bit
    of it and i also һave ʏoս bookmarked to check
    oսt new infοrmation ߋn youг website.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s