Packages
hl7v2
2.8.2
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/rp.ex
defmodule HL7v2.Type.RP do
@moduledoc """
Reference Pointer (RP) -- HL7v2 composite data type.
Points to data stored externally to the message. Common in OBX-5
when value_type is "RP".
4 components:
1. Pointer (ST) -- reference to external data (e.g., URL, file path)
2. Application ID (HD) -- sub-components delimited by `&`
3. Type of Data (ID) -- Table 0191: e.g., "Application", "Audio", "Image", "TEXT"
4. Subtype (ID) -- Table 0291: e.g., "PDF", "JPEG", "DICOM"
"""
@behaviour HL7v2.Type
alias HL7v2.Type
alias HL7v2.Type.HD
defstruct [:pointer, :application_id, :type_of_data, :subtype]
@type t :: %__MODULE__{
pointer: binary() | nil,
application_id: HD.t() | nil,
type_of_data: binary() | nil,
subtype: binary() | nil
}
@doc """
Parses an RP from a list of components.
## Examples
iex> HL7v2.Type.RP.parse(["/reports/12345.pdf", "LAB&1.2.3&ISO", "Application", "PDF"])
%HL7v2.Type.RP{
pointer: "/reports/12345.pdf",
application_id: %HL7v2.Type.HD{namespace_id: "LAB", universal_id: "1.2.3", universal_id_type: "ISO"},
type_of_data: "Application",
subtype: "PDF"
}
iex> HL7v2.Type.RP.parse(["http://example.com/image.jpg"])
%HL7v2.Type.RP{pointer: "http://example.com/image.jpg"}
iex> HL7v2.Type.RP.parse([])
%HL7v2.Type.RP{}
"""
@spec parse(list()) :: t()
def parse(components) when is_list(components) do
%__MODULE__{
pointer: Type.get_component(components, 0),
application_id: Type.parse_sub(HD, Type.get_component(components, 1)),
type_of_data: Type.get_component(components, 2),
subtype: Type.get_component(components, 3)
}
end
@doc """
Encodes an RP to a list of component strings.
## Examples
iex> HL7v2.Type.RP.encode(%HL7v2.Type.RP{
...> pointer: "/reports/12345.pdf",
...> application_id: %HL7v2.Type.HD{namespace_id: "LAB", universal_id: "1.2.3", universal_id_type: "ISO"},
...> type_of_data: "Application",
...> subtype: "PDF"
...> })
["/reports/12345.pdf", "LAB&1.2.3&ISO", "Application", "PDF"]
iex> HL7v2.Type.RP.encode(%HL7v2.Type.RP{pointer: "/image.jpg"})
["/image.jpg"]
iex> HL7v2.Type.RP.encode(nil)
[]
"""
@spec encode(t() | nil) :: list()
def encode(nil), do: []
def encode(%__MODULE__{} = rp) do
[
rp.pointer || "",
Type.encode_sub(HD, rp.application_id),
rp.type_of_data || "",
rp.subtype || ""
]
|> Type.trim_trailing()
end
end