Current section

Files

Jump to
hl7v2 lib hl7v2 typed_message.ex
Raw

lib/hl7v2/typed_message.ex

defmodule HL7v2.TypedMessage do
@moduledoc """
Typed HL7v2 message with parsed segment structs.
A `TypedMessage` is the result of converting a `RawMessage` through the
`HL7v2.TypedParser`. Known segments (MSH, PID, PV1, etc.) are represented as
their typed struct, Z-segments as `HL7v2.Segment.ZXX` structs, and truly
unknown segments are preserved as raw `{name, fields}` tuples.
"""
@type t :: %__MODULE__{
separators: HL7v2.Separator.t(),
type: {binary(), binary()} | {binary(), binary(), binary()},
segments: [struct() | {binary(), list()}]
}
defstruct [:separators, :type, :segments]
end
defimpl String.Chars, for: HL7v2.TypedMessage do
def to_string(msg) do
msg
|> HL7v2.TypedParser.to_raw()
|> HL7v2.Encoder.encode()
end
end