Package com.framed.interop.hl7.hl7v2
Class Hl7Escape
java.lang.Object
com.framed.interop.hl7.hl7v2.Hl7Escape
HL7 v2 escaping of reserved characters (HL7 v2.5 §2.7), for embedding free-form data into
message fields built with the default encoding characters (
|^~\&). Without escaping, a
value containing e.g. | shifts every subsequent field of its segment, and a value
containing CR/LF injects bogus segment breaks — either way corrupting the message for the
receiver.
field(java.lang.String)/components(java.lang.String) encode outbound data; unescape(java.lang.String) decodes inbound
data, so values round-trip across the HL7 boundary. Unknown escape sequences (e.g. formatting
escapes like \.br\) are preserved verbatim by the decoder rather than dropped.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringcomponents(String structured) Escapes each^-separated component of an already component-structured value (e.g. a configured PV1-3 location such as"ICU^01^A"), preserving the component separators themselves.static StringEscapes all reserved characters, for data that occupies a whole field or component:\ -> \E\,| -> \F\,^ -> \S\,~ -> \R\,& -> \T\, and the segment/line breaksCR -> \X0D\,LF -> \X0A\(hex escape, §2.7.4).static StringDecodes the escape sequences produced byfield(java.lang.String)(delimiter escapes\E\ \F\ \S\ \R\ \T\and hex escapes\Xhh..\) back to the original text.
-
Method Details
-
field
Escapes all reserved characters, for data that occupies a whole field or component:\ -> \E\,| -> \F\,^ -> \S\,~ -> \R\,& -> \T\, and the segment/line breaksCR -> \X0D\,LF -> \X0A\(hex escape, §2.7.4).- Parameters:
text- the raw text (may benull)- Returns:
- the escaped text;
""fornull
-
components
Escapes each^-separated component of an already component-structured value (e.g. a configured PV1-3 location such as"ICU^01^A"), preserving the component separators themselves.- Parameters:
structured- the component-structured text (may benull)- Returns:
- the text with every component escaped;
""fornull
-
unescape
Decodes the escape sequences produced byfield(java.lang.String)(delimiter escapes\E\ \F\ \S\ \R\ \T\and hex escapes\Xhh..\) back to the original text. Any other sequence — unknown codes such as formatting escapes (\.br\), malformed hex, or a dangling backslash — is preserved verbatim, so decoding is lossless on nonconforming input.- Parameters:
text- the escaped text (may benull)- Returns:
- the decoded text;
""fornull
-
