HL7 uses special characters for formatting. If any of the special characters are included in the data elements of an HL7 message, they must be escaped. Escaping a special character in an HL7 message tells the system that will consume the message that the characters should be treated as text. The actual escape character is defined in the MSH-2 field of the HL7 message. The default is \, the examples below use the default (\).
Below is a list of the default special characters with the escape sequence.
| (pipe) - HL7 Field Separator \F\
^ (hat) - HL7 Component Seperator \S\
~ (tilde) - HL7 Repitition Character \R\
\ (backslash) - HL7 Escape Character \E\
& (ampersand) - Sub-Component \T\
In QIE use the escape and un-escape HL7 functions. Below are some examples of escaped and un-escaped HL7 special characters.
_______________________________________________________________________
var myString = "<This | is a test 'for' me,~ I need to learn how to escape & repeat ^ in code.>";
var eHL7 = qie.escapeHL7(myString);
qie.debug('Escaped HL7: ' + HL7);
var HL7 = qie.unescapeHL7(HL7);
qie.debug('Unescaped HL7: ' + HL7);
_______________________________________________________________________
myString = "<This | is a test 'for' me,~ I need to learn how to escape & repeat ^ in code.>"
Unescaped HL7: <This | is a test 'for' me,~ I need to learn how to escape & repeat ^ in code.>
Escaped HL7: <This \F\ is a test 'for' me,\R\ I need to learn how to escape \T\ repeat \S\ in code.>
Notice, when escaped; '|' becomes \F\, '~' becomes \R\, '&' becomes \T\ and '^' becomes \S\.
_______________________________________________________________________
var myString = "H&M";
Unescaped HL7: H&M
Escaped HL7: H\T\M
_______________________________________________________________________
var myString = "c:\\somepath\\somesubdirectory"
Unescaped HL7: c:\somepath\somesubdirectory
Escaped HL7: c:\E\somepath\E\somesubdirectory