Monday, 4 April 2016

Escaping HL7 ampersands with Mirth Connect (NextGen Connect)

HL7 uses &'s to separate the subcomponents in a message, So if you need to include an '&' in a field, such as the address "Corner of High & Main St" you are going to run into problems.

MSH|^~\&|App1|Fac1|App2|Fac2|20160315121250||ADT^A31|1000|P|2.3.1

PID|1||10000||Smith^John^^^MR^^||19790708|M|||Corner of High & Main St^^City^New York^^UK|

Fortunately HL7 comes with escape characters, but they are a little bit "unique" in my eyes. Here is a great, comprehensive place to find all the escape codes. The one we are interested in for the ampersand is \T\.

MSH|^~\&|App1|Fac1|App2|Fac2|20160315121250||ADT^A31|1000|P|2.3.1

PID|1||10000||Smith^John^^^MR^^||19790708|M|||Corner of High \T\ Main St^^City^New York^^UK|

Mirth Connect actually supports automatically transforming the escaped characters for you, providing you turn on the 'Use Strict Parser' setting.

clip_image001

However, this then turns Mirth into an HL7 Nazi, constantly rejecting messages due to fields not containing the right values. I don't know about you, but I don't think I've worked on an HL7 interface that didn't have some slight breaking of the rules somewhere.

For this reason I recommend leaving the Strict Parser off and editing your source transformer code so that values are transformed with the escape characters replace.

You just need to navigate to the transformers for the fields you’d like to escape and append the following code to the string.

().replace(/\\T\\/g, "\&");

e.g. the Doctors address line one becomes

msg['ZPD']['ZPD.2']['ZPD.2.1'].toString().replace(/\\T\\/g, "\&");

clip_image002

(Update: Yep, I use Integration Host now by HL7 Soup so this is all just a right-click option without pain. If all this is in the too hard basket, do the same...)

2 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete