Packages
hl7v2
3.3.3
3.10.1
3.9.0
3.8.0
3.7.0
3.6.0
3.5.0
3.4.0
3.3.6
3.3.5
3.3.4
3.3.3
3.3.2
3.3.1
3.3.0
3.2.0
3.1.1
3.1.0
3.0.2
3.0.1
3.0.0
2.11.0
2.10.0
2.9.1
2.9.0
2.8.2
2.8.1
2.8.0
2.7.1
2.7.0
2.6.0
2.5.0
2.4.0
2.3.0
2.2.0
2.1.3
2.1.2
2.1.1
2.1.0
1.4.6
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.0
1.2.0
1.1.0
1.0.0
0.6.0
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.1.0
Pure Elixir HL7 v2.x toolkit — schema-driven parsing, typed segments, message builder, MLLP transport
Current section
Files
Jump to
Current section
Files
lib/hl7v2/raw_message.ex
defmodule HL7v2.RawMessage do
@moduledoc """
Represents a parsed HL7v2 message in raw form.
The raw message preserves the structure and content of the original message —
no type coercion, no validation, no data loss. Round-tripping is canonical:
line endings are normalized to CR and a trailing CR is always present, so
`parse(text) |> encode()` produces the canonical wire form, which may differ
from the input only in line-ending normalization.
## Structure
Each segment is a tuple `{name, fields}` where:
- `name` is a binary segment identifier (e.g., `"MSH"`, `"PID"`)
- `fields` is an ordered list of field values, starting from the first field
after the segment name
### Field Value Representation
Field values use nested lists to represent the HL7v2 delimiter hierarchy:
- **Simple field**: a binary string — `"Smith"`
- **Components**: a list of binaries — `["Smith", "John", "", "Dr"]`
- **Repetitions**: a list of component-lists — `[["12345", "", "", "MRN"], ["67890", "", "", "SSN"]]`
- **Sub-components**: lists nested within components as needed
For MSH, field 1 is always the field separator character as a single-byte binary
(e.g., `"|"`), and field 2 is the encoding characters as a literal string
(e.g., `"^~\\\\&"`).
"""
@type field_value :: binary() | [binary()] | [[binary()]] | [[[binary()]]]
@type t :: %__MODULE__{
separators: HL7v2.Separator.t(),
type: {binary(), binary()} | {binary(), binary(), binary()},
segments: [{binary(), [field_value()]}]
}
defstruct [:separators, :type, :segments]
end
defimpl String.Chars, for: HL7v2.RawMessage do
def to_string(msg), do: HL7v2.Encoder.encode(msg)
end