Converts a raw-parsed HL7v2 message into typed segment structs.
Each segment in the RawMessage is dispatched to its corresponding segment
module via a registry lookup:
- Known segments (MSH, PID, PV1, ...) are parsed through
SegmentModule.parse(raw_fields, separators). - Z-segments (names starting with
"Z") becomeHL7v2.Segment.ZXXstructs viaZXX.new/2, preserving the original segment name. - Unknown segments are kept as raw
{name, fields}tuples so nothing is lost.
Summary
Functions
Converts a RawMessage into a TypedMessage with parsed segment structs.
Returns the segment module for a given segment ID, or nil if unknown.
Converts a TypedMessage back into a RawMessage.
Functions
@spec convert(HL7v2.RawMessage.t()) :: {:ok, HL7v2.TypedMessage.t()} | {:error, term()}
Converts a RawMessage into a TypedMessage with parsed segment structs.
Returns {:ok, typed_message} on success, or {:error, reason} if
conversion fails.
Examples
iex> {:ok, raw} = HL7v2.Parser.parse("MSH|^~\\&|S|F||R|20240101||ADT^A01|1|P|2.5\r")
iex> {:ok, typed} = HL7v2.TypedParser.convert(raw)
iex> %HL7v2.Segment.MSH{} = hd(typed.segments)
Returns the segment module for a given segment ID, or nil if unknown.
@spec to_raw(HL7v2.TypedMessage.t()) :: HL7v2.RawMessage.t()
Converts a TypedMessage back into a RawMessage.
Each typed segment struct is encoded back to its raw field list via
SegmentModule.encode/1. Z-segments use their stored segment_id, and
unknown raw tuples pass through unchanged.
Examples
iex> {:ok, raw} = HL7v2.Parser.parse("MSH|^~\\&|S|F||R|20240101||ADT^A01|1|P|2.5\r")
iex> {:ok, typed} = HL7v2.TypedParser.convert(raw)
iex> raw_again = HL7v2.TypedParser.to_raw(typed)
iex> %HL7v2.RawMessage{} = raw_again