Newsletter: June 2006
Project Corner - Special Characters
How do I parse HL7 messages that illegaly embed delimiter characters within field contents?
HL7 messages use special characters, called delimiter characters, to delimit message contents. There are standard delimiter characters for fields (|), subfields (^), sub-sub fields (&), repeats (~), and so on. These characters are used by HL7 message parsers to determine where message elements begin and end.
In real world applications of HL7, however, it is often desirable to send these special characters as text inside individual fields as well. For example, a doctor's report appearing in the fifth field of an OBX segment might contain a sentence like, "White & red blood cell counts are normal." In these cases, the official HL7 standard mandates that the '&' character be replaced by a special escape sequence, "\T\", before it is sent so that the recipient parser doesn't inadvertantly treat the '&' as a delimiter.
Unfortunately, it is not uncommon to have sending applications that ignore the prescribed escaping behaviour and send along special delimiter characters in field contents. There are two main approaches for handling these types of unconforming HL7 messages in the Chameleon Development Environment:
- In Chameleon's options, you can go to the "Message Delimiters" tab and modify how the messages are parsed. You can set the "Escape Character", for example, to the Character 0x00, and the "Field Repeat Char" to 0x00. Other approaches are outlined in our manual here: http://www.interfaceware.com/manual/message_delimiters.html
-
You can pre-process the message using the Global Inbound python equation so that these characters are appropriately replaced as illustrated in the following example:
You must be careful to leave the beginning of the MSH unmodified (ie, the "MSH|^~\&|" part).
The following python code is a simple example of how to safely replace all ~ characters with their corresponding escape character. This would usually be entered into the In Bound Equation under the Chameleon pull-down since this code is executed before any other processing of the raw incoming HL7 message.
value = string.replace(value, '^~\\&', 'TOTALLYUNIQUESTRING') value = string.replace(value, '~', '') value = string.replace(value, 'TOTALLYUNIQUESTRING', '^~\\&')
Additional information about Python scripting is available in the following section of the manual: http://www.interfaceware.com/manual/python.html
The following section of the manual describes the HL7 delimiter characters: http://interfaceware.com/manual/delimiter_characters.html

