Packages
hl7v2
1.2.0
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/type/ed.ex
defmodule HL7v2.Type.ED do
@moduledoc """
Encapsulated Data (ED) -- HL7v2 composite data type.
Used for transmitting encapsulated data from other standards (e.g., PDF,
JPEG, DICOM, CDA). Common in OBX-5 when value_type is "ED".
5 components:
1. Source Application (HD) -- sub-components delimited by `&`
2. Type of Data (ID) -- Table 0191: e.g., "Application", "Audio", "Image", "TEXT"
3. Data Subtype (ID) -- Table 0291: e.g., "PDF", "RTF", "JPEG", "DICOM", "x-hl7-cda-level-one"
4. Encoding (ID) -- Table 0299: "A" (no encoding), "Hex", "Base64"
5. Data (TX) -- the actual encoded data
"""
@behaviour HL7v2.Type
alias HL7v2.Type
alias HL7v2.Type.HD
defstruct [:source_application, :type_of_data, :data_subtype, :encoding, :data]
@type t :: %__MODULE__{
source_application: HD.t() | nil,
type_of_data: binary() | nil,
data_subtype: binary() | nil,
encoding: binary() | nil,
data: binary() | nil
}
@doc """
Parses an ED from a list of components.
## Examples
iex> HL7v2.Type.ED.parse(["LAB&1.2.3&ISO", "Application", "PDF", "Base64", "JVBER..."])
%HL7v2.Type.ED{
source_application: %HL7v2.Type.HD{namespace_id: "LAB", universal_id: "1.2.3", universal_id_type: "ISO"},
type_of_data: "Application",
data_subtype: "PDF",
encoding: "Base64",
data: "JVBER..."
}
iex> HL7v2.Type.ED.parse(["", "TEXT", "plain", "A", "Hello world"])
%HL7v2.Type.ED{type_of_data: "TEXT", data_subtype: "plain", encoding: "A", data: "Hello world"}
iex> HL7v2.Type.ED.parse([])
%HL7v2.Type.ED{}
"""
@spec parse(list()) :: t()
def parse(components) when is_list(components) do
%__MODULE__{
source_application: Type.parse_sub(HD, Type.get_component(components, 0)),
type_of_data: Type.get_component(components, 1),
data_subtype: Type.get_component(components, 2),
encoding: Type.get_component(components, 3),
data: Type.get_component(components, 4)
}
end
@doc """
Encodes an ED to a list of component strings.
## Examples
iex> HL7v2.Type.ED.encode(%HL7v2.Type.ED{
...> source_application: %HL7v2.Type.HD{namespace_id: "LAB"},
...> type_of_data: "Application",
...> data_subtype: "PDF",
...> encoding: "Base64",
...> data: "JVBER..."
...> })
["LAB", "Application", "PDF", "Base64", "JVBER..."]
iex> HL7v2.Type.ED.encode(%HL7v2.Type.ED{type_of_data: "TEXT", data_subtype: "plain", encoding: "A", data: "Hello"})
["", "TEXT", "plain", "A", "Hello"]
iex> HL7v2.Type.ED.encode(nil)
[]
"""
@spec encode(t() | nil) :: list()
def encode(nil), do: []
def encode(%__MODULE__{} = ed) do
[
Type.encode_sub(HD, ed.source_application),
ed.type_of_data || "",
ed.data_subtype || "",
ed.encoding || "",
ed.data || ""
]
|> Type.trim_trailing()
end
end