HL7 Escape Sequences

November 2nd, 2006 by Mike Stockemer

9 Votes | Average: 4.56 out of 59 Votes | Average: 4.56 out of 59 Votes | Average: 4.56 out of 59 Votes | Average: 4.56 out of 59 Votes | Average: 4.56 out of 5 (9 votes, average: 4.56 out of 5)

Loading ... Loading ...

Posted in HL7 Standard, HL7 Integration

HL7 defines character sequences to represent ’special’ characters not otherwise permitted in HL7 messages. These sequences begin and end with the message’s Escape character (usually ‘\’), and contain an identifying character, followed by 0 or more characters. The most common use of these escape sequences is to escape the HL7 defined delimiter characters. These delimiter or separator characters are defined in MSH-1 and MSH-2 of the HL7 message and typically have the following values:

| Field Delimiter
^ Component Delimiter
& Sub-Component Delimiter

The other 2 special case characters defined in MSH-2 are:

~ Repetition Separator
\ Escape Character

When parsing HL7 messages, interface engines and HL7-enabled applications should be able to recognize these special escape sequences and properly convert them. Similarly, if producing HL7 messages that contain special data, the application should properly escape the data using the HL7 escape sequences.

A simple example of this can be seen in the following OBX segments:

OBX||10|||Current Medications
OBX||11|||DILANTIN & NORVASC

The OBX-5 field is defined by HL7 to contain data conforming to an ST datatype. This should be a single string value. What we see in our message is the value DILANTIN & NORVASC. The ‘&’ character is typically used as the sub-component separator in an HL7 message. By the rules of HL7 this message is not properly formatted. Since the ‘&’ character in this case is meant to be part of the resulting text, it needs to be escaped. The correct representation of this message should be as follows:

OBX||10|||Current Medications
OBX||11|||DILANTIN \T\ NORVASC

When a receiving application reads this message it should follow the rules of the HL7 standard, and convert the \T\ to the ‘&’ character prior to importing this information into their system. When pursuing an HL7 integration project in the real world, it is very common to interface with a system that claims to be HL7 compliant, but they do not support the HL7 encoding sequences.

This means that you may receive an HL7 message with improperly formatted data. This also means that when interfacing with one of these non-compliant HL7 systems, they may actually require you to send them HL7 messages where the special characters of HL7 are not properly escaped.

The table below shows the HL7 Escape sequences, and how they are converted:

Character Description Conversion
\Cxxyy\ Single-byte character set escape sequence with two hexadecimal values not converted
\E\ Escape character converted to escape character (e.g., ‘\’)
\F\ Field separator converted to field separator character (e.g., ‘|’)
\H\ Start highlighting not converted
\Mxxyyzz\ Multi-byte character set escape sequence with two or three hexadecimal values (zz is optional) not converted
\N\ Normal text (end highlighting) not converted
\R\ Repetition separator converted to repetition separator character (e.g., ‘~’)
\S\ Component separator converted to component separator character (e.g., ‘^’)
\T\ Subcomponent separator converted to subcomponent separator character (e.g., ‘&’)
\Xdd…\ Hexadecimal data (dd must be hexadecimal characters) converted to the characters identified by each pair of digits
\Zdd…\ Locally defined escape sequence not converted
Last 5 posts by Mike Stockemer
3 Responses to “HL7 Escape Sequences”
  1. HL7 Engine Mapping says:

    […] that inherits all the characteristics of the standard format – supports Z segments, non-standard separator characters, […]

  2. Variations of the HL7 ORU^R01 Message Format says:

    […] Notice also that the backslash characters () in the path need to be properly escaped using the HL7 escape sequence E. MSH|^~&|System1||||200707090801||MDM^T01|3542196|P|2.3 EVN|T01|200707090801|200707090801 […]

  3. cynthia peters says:

    This is great information…and you guys are in out backyard.
    Do you have any one day training seminars on Sat.
    For basic HL7. I need a refresher.

Leave a Reply

Discover the NeoTool Healthcare Integration Solution for Your Market.