Packages
hl7v2
2.1.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/type/vid.ex
defmodule HL7v2.Type.VID do
@moduledoc """
Version Identifier (VID) -- HL7v2 composite data type.
Used in MSH-12 to identify the HL7 version.
3 components:
1. Version ID (ID) -- Table 0104: 2.5, 2.5.1, etc.
2. Internationalization Code (CE)
3. International Version ID (CE)
"""
@behaviour HL7v2.Type
alias HL7v2.Type
alias HL7v2.Type.CE
defstruct [:version_id, :internationalization_code, :international_version_id]
@type t :: %__MODULE__{
version_id: binary() | nil,
internationalization_code: CE.t() | nil,
international_version_id: CE.t() | nil
}
@doc """
Parses a VID from a list of components.
Components 2 and 3 are CE types, which when embedded use `&` sub-components.
## Examples
iex> HL7v2.Type.VID.parse(["2.5.1"])
%HL7v2.Type.VID{version_id: "2.5.1"}
iex> HL7v2.Type.VID.parse([])
%HL7v2.Type.VID{}
"""
@spec parse(list()) :: t()
def parse(components) when is_list(components) do
%__MODULE__{
version_id: Type.get_component(components, 0),
internationalization_code: parse_sub_ce(Type.get_component(components, 1)),
international_version_id: parse_sub_ce(Type.get_component(components, 2))
}
end
@doc """
Encodes a VID to a list of component strings.
## Examples
iex> HL7v2.Type.VID.encode(%HL7v2.Type.VID{version_id: "2.5.1"})
["2.5.1"]
iex> HL7v2.Type.VID.encode(nil)
[]
"""
@spec encode(t() | nil) :: list()
def encode(nil), do: []
def encode(%__MODULE__{} = vid) do
[
vid.version_id || "",
Type.encode_sub(CE, vid.internationalization_code),
Type.encode_sub(CE, vid.international_version_id)
]
|> Type.trim_trailing()
end
defp parse_sub_ce(nil), do: nil
defp parse_sub_ce(value) when is_binary(value) do
value
|> String.split(Type.sub_component_separator(), parts: 6)
|> CE.parse()
end
end