Detects and manages HL7v2 message delimiters from MSH-1/MSH-2.
Every HL7v2 message declares its delimiter set in the first 9 characters of the
MSH segment: MSH (3 chars) + field separator (MSH-1, 1 char) + encoding
characters (MSH-2, 4 or 5 chars). The defaults are |^~\& but the standard
allows any single-byte characters.
HL7 v2.7+ allows an optional 5th encoding character: the truncation character.
When present (e.g., ^~\&#), it indicates that field values ending with this
character were truncated. It is a display hint, not a delimiter.
Examples
iex> HL7v2.Separator.default()
%HL7v2.Separator{field: ?|, component: ?^, repetition: ?~, escape: ?\\, sub_component: ?&, truncation: nil, segment: ?\r}
iex> {:ok, sep} = HL7v2.Separator.from_msh("MSH|^~\\&|SENDING_APP|")
iex> sep.field
?|
iex> {:ok, sep} = HL7v2.Separator.from_msh("MSH|^~\\&#|SENDING_APP|")
iex> sep.truncation
?#
Summary
Functions
Returns the default HL7v2 delimiter set (|^~\& with CR segment terminator, no truncation character).
Returns the encoding characters string (MSH-2 value) for this separator set.
Extracts delimiters from an MSH header binary.
Types
@type t() :: %HL7v2.Separator{ component: non_neg_integer(), escape: non_neg_integer(), field: non_neg_integer(), repetition: non_neg_integer(), segment: non_neg_integer(), sub_component: non_neg_integer(), truncation: non_neg_integer() | nil }
Functions
@spec default() :: t()
Returns the default HL7v2 delimiter set (|^~\& with CR segment terminator, no truncation character).
Returns the encoding characters string (MSH-2 value) for this separator set.
When a truncation character is present (v2.7+), the returned string is 5 characters.
Examples
iex> HL7v2.Separator.encoding_characters(HL7v2.Separator.default())
"^~\\&"
Extracts delimiters from an MSH header binary.
MSH-1 is the single character immediately after "MSH" (the field separator).
MSH-2 is the next 4 characters (component, repetition, escape, sub-component),
written as a literal string and NOT delimited. In HL7 v2.7+, a 5th character
(truncation) may follow. The truncation character is distinguished from the
start of the next field by checking whether the 5th byte equals the field
separator: if it does not, it is the truncation character.
Returns {:ok, separator} or {:error, reason}.
Examples
iex> {:ok, sep} = HL7v2.Separator.from_msh("MSH|^~\\&|SendApp|")
iex> sep.field
?|
iex> sep.component
?^
iex> {:ok, sep} = HL7v2.Separator.from_msh("MSH|^~\\&#|SendApp|")
iex> sep.truncation
?#