Packages
hl7v2
3.6.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/cnn.ex
defmodule HL7v2.Type.CNN do
@moduledoc """
Composite Number and Name without Authority (CNN) -- HL7v2 composite data type.
A simplified person identifier used as the name component of NDL (Name with
Date and Location). Unlike XCN, CNN does not carry assigning authority or
identifier type information.
11 components per HL7 v2.5.1:
1. ID Number (ST)
2. Family Name (ST) -- simple string, not FN composite
3. Given Name (ST)
4. Second and Further Given Names or Initials (ST)
5. Suffix (ST)
6. Prefix (ST)
7. Degree (IS)
8. Source Table (IS)
9. Assigning Authority - Namespace ID (IS)
10. Assigning Authority - Universal ID (ST)
11. Assigning Authority - Universal ID Type (ID)
Note: components 9-11 are flattened parts of an HD, not a nested HD composite.
"""
@behaviour HL7v2.Type
alias HL7v2.Type
defstruct [
:id_number,
:family_name,
:given_name,
:second_name,
:suffix,
:prefix,
:degree,
:source_table,
:assigning_authority_namespace_id,
:assigning_authority_universal_id,
:assigning_authority_universal_id_type
]
@type t :: %__MODULE__{
id_number: binary() | nil,
family_name: binary() | nil,
given_name: binary() | nil,
second_name: binary() | nil,
suffix: binary() | nil,
prefix: binary() | nil,
degree: binary() | nil,
source_table: binary() | nil,
assigning_authority_namespace_id: binary() | nil,
assigning_authority_universal_id: binary() | nil,
assigning_authority_universal_id_type: binary() | nil
}
@doc """
Parses a CNN from a list of components (or sub-components).
## Examples
iex> HL7v2.Type.CNN.parse(["12345", "Smith", "John"])
%HL7v2.Type.CNN{id_number: "12345", family_name: "Smith", given_name: "John"}
iex> HL7v2.Type.CNN.parse(["12345", "Smith", "John", "Q", "JR", "DR", "MD", "PHYS", "NPI", "2.16.840.1.113883.4.6", "ISO"])
%HL7v2.Type.CNN{
id_number: "12345",
family_name: "Smith",
given_name: "John",
second_name: "Q",
suffix: "JR",
prefix: "DR",
degree: "MD",
source_table: "PHYS",
assigning_authority_namespace_id: "NPI",
assigning_authority_universal_id: "2.16.840.1.113883.4.6",
assigning_authority_universal_id_type: "ISO"
}
iex> HL7v2.Type.CNN.parse([])
%HL7v2.Type.CNN{}
"""
@spec parse(list()) :: t()
def parse(components) when is_list(components) do
%__MODULE__{
id_number: Type.get_component(components, 0),
family_name: Type.get_component(components, 1),
given_name: Type.get_component(components, 2),
second_name: Type.get_component(components, 3),
suffix: Type.get_component(components, 4),
prefix: Type.get_component(components, 5),
degree: Type.get_component(components, 6),
source_table: Type.get_component(components, 7),
assigning_authority_namespace_id: Type.get_component(components, 8),
assigning_authority_universal_id: Type.get_component(components, 9),
assigning_authority_universal_id_type: Type.get_component(components, 10)
}
end
@doc """
Encodes a CNN to a list of component strings.
## Examples
iex> HL7v2.Type.CNN.encode(%HL7v2.Type.CNN{id_number: "12345", family_name: "Smith", given_name: "John"})
["12345", "Smith", "John"]
iex> HL7v2.Type.CNN.encode(nil)
[]
iex> HL7v2.Type.CNN.encode(%HL7v2.Type.CNN{})
[]
"""
@spec encode(t() | nil) :: list()
def encode(nil), do: []
def encode(%__MODULE__{} = cnn) do
[
cnn.id_number || "",
cnn.family_name || "",
cnn.given_name || "",
cnn.second_name || "",
cnn.suffix || "",
cnn.prefix || "",
cnn.degree || "",
cnn.source_table || "",
cnn.assigning_authority_namespace_id || "",
cnn.assigning_authority_universal_id || "",
cnn.assigning_authority_universal_id_type || ""
]
|> Type.trim_trailing()
end
end