Packages
hl7v2
2.3.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/xon.ex
defmodule HL7v2.Type.XON do
@moduledoc """
Extended Composite Name and ID for Organizations (XON) -- HL7v2 composite data type.
10 components:
1. Organization Name (ST)
2. Organization Name Type Code (IS) -- Table 0204: A=Alias, D=Display, L=Legal
3. ID Number (NM) -- deprecated
4. Check Digit (NM)
5. Check Digit Scheme (ID) -- Table 0061
6. Assigning Authority (HD) -- sub-components delimited by `&`
7. Identifier Type Code (ID) -- Table 0203
8. Assigning Facility (HD) -- sub-components delimited by `&`
9. Name Representation Code (ID) -- Table 0465
10. Organization Identifier (ST)
"""
@behaviour HL7v2.Type
alias HL7v2.Type
alias HL7v2.Type.HD
defstruct [
:organization_name,
:organization_name_type_code,
:id_number,
:check_digit,
:check_digit_scheme,
:assigning_authority,
:identifier_type_code,
:assigning_facility,
:name_representation_code,
:organization_identifier
]
@type t :: %__MODULE__{
organization_name: binary() | nil,
organization_name_type_code: binary() | nil,
id_number: binary() | nil,
check_digit: binary() | nil,
check_digit_scheme: binary() | nil,
assigning_authority: HD.t() | nil,
identifier_type_code: binary() | nil,
assigning_facility: HD.t() | nil,
name_representation_code: binary() | nil,
organization_identifier: binary() | nil
}
@doc """
Parses an XON from a list of components.
## Examples
iex> HL7v2.Type.XON.parse(["General Hospital", "L", "", "", "", "HOSP&2.16.840.1.113883.19.4.6&ISO", "XX", "", "", "GH001"])
%HL7v2.Type.XON{
organization_name: "General Hospital",
organization_name_type_code: "L",
assigning_authority: %HL7v2.Type.HD{namespace_id: "HOSP", universal_id: "2.16.840.1.113883.19.4.6", universal_id_type: "ISO"},
identifier_type_code: "XX",
organization_identifier: "GH001"
}
iex> HL7v2.Type.XON.parse([])
%HL7v2.Type.XON{}
"""
@spec parse(list()) :: t()
def parse(components) when is_list(components) do
%__MODULE__{
organization_name: Type.get_component(components, 0),
organization_name_type_code: Type.get_component(components, 1),
id_number: Type.get_component(components, 2),
check_digit: Type.get_component(components, 3),
check_digit_scheme: Type.get_component(components, 4),
assigning_authority: Type.parse_sub(HD, Type.get_component(components, 5)),
identifier_type_code: Type.get_component(components, 6),
assigning_facility: Type.parse_sub(HD, Type.get_component(components, 7)),
name_representation_code: Type.get_component(components, 8),
organization_identifier: Type.get_component(components, 9)
}
end
@doc """
Encodes an XON to a list of component strings.
## Examples
iex> HL7v2.Type.XON.encode(%HL7v2.Type.XON{organization_name: "General Hospital", organization_name_type_code: "L"})
["General Hospital", "L"]
iex> HL7v2.Type.XON.encode(nil)
[]
"""
@spec encode(t() | nil) :: list()
def encode(nil), do: []
def encode(%__MODULE__{} = xon) do
[
xon.organization_name || "",
xon.organization_name_type_code || "",
xon.id_number || "",
xon.check_digit || "",
xon.check_digit_scheme || "",
Type.encode_sub(HD, xon.assigning_authority),
xon.identifier_type_code || "",
Type.encode_sub(HD, xon.assigning_facility),
xon.name_representation_code || "",
xon.organization_identifier || ""
]
|> Type.trim_trailing()
end
end