Class Hl7Escape

java.lang.Object
com.framed.interop.hl7.hl7v2.Hl7Escape

public final class Hl7Escape extends Object
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 Type
    Method
    Description
    static String
    components(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 String
    field(String text)
    Escapes all reserved characters, for data that occupies a whole field or component: \ -> \E\, | -> \F\, ^ -> \S\, ~ -> \R\, & -> \T\, and the segment/line breaks CR -> \X0D\, LF -> \X0A\ (hex escape, §2.7.4).
    static String
    Decodes the escape sequences produced by field(java.lang.String) (delimiter escapes \E\ \F\ \S\ \R\ \T\ and hex escapes \Xhh..\) back to the original text.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • field

      public static String field(String text)
      Escapes all reserved characters, for data that occupies a whole field or component: \ -> \E\, | -> \F\, ^ -> \S\, ~ -> \R\, & -> \T\, and the segment/line breaks CR -> \X0D\, LF -> \X0A\ (hex escape, §2.7.4).
      Parameters:
      text - the raw text (may be null)
      Returns:
      the escaped text; "" for null
    • components

      public static String components(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.
      Parameters:
      structured - the component-structured text (may be null)
      Returns:
      the text with every component escaped; "" for null
    • unescape

      public static String unescape(String text)
      Decodes the escape sequences produced by field(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 be null)
      Returns:
      the decoded text; "" for null