Packages
hl7v2
2.7.1
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/ad.ex
defmodule HL7v2.Type.AD do
@moduledoc """
Address (AD) -- HL7v2 composite data type.
A simpler address type used in older HL7 versions. Superseded by XAD in v2.3+.
8 components:
1. Street Address (ST)
2. Other Designation (ST)
3. City (ST)
4. State or Province (ST)
5. Zip or Postal Code (ST)
6. Country (ID) -- Table 0399
7. Address Type (ID) -- Table 0190
8. Other Geographic Designation (ST)
"""
@behaviour HL7v2.Type
alias HL7v2.Type
defstruct [
:street_address,
:other_designation,
:city,
:state_or_province,
:zip_or_postal_code,
:country,
:address_type,
:other_geographic_designation
]
@type t :: %__MODULE__{
street_address: binary() | nil,
other_designation: binary() | nil,
city: binary() | nil,
state_or_province: binary() | nil,
zip_or_postal_code: binary() | nil,
country: binary() | nil,
address_type: binary() | nil,
other_geographic_designation: binary() | nil
}
@doc """
Parses an AD from a list of components.
## Examples
iex> HL7v2.Type.AD.parse(["123 Main St", "Suite 100", "Springfield", "IL", "62704", "USA"])
%HL7v2.Type.AD{street_address: "123 Main St", other_designation: "Suite 100", city: "Springfield", state_or_province: "IL", zip_or_postal_code: "62704", country: "USA"}
iex> HL7v2.Type.AD.parse(["456 Oak Ave"])
%HL7v2.Type.AD{street_address: "456 Oak Ave"}
iex> HL7v2.Type.AD.parse([])
%HL7v2.Type.AD{}
"""
@spec parse(list()) :: t()
def parse(components) when is_list(components) do
%__MODULE__{
street_address: Type.get_component(components, 0),
other_designation: Type.get_component(components, 1),
city: Type.get_component(components, 2),
state_or_province: Type.get_component(components, 3),
zip_or_postal_code: Type.get_component(components, 4),
country: Type.get_component(components, 5),
address_type: Type.get_component(components, 6),
other_geographic_designation: Type.get_component(components, 7)
}
end
@doc """
Encodes an AD to a list of component strings.
## Examples
iex> HL7v2.Type.AD.encode(%HL7v2.Type.AD{street_address: "123 Main St", city: "Springfield", state_or_province: "IL"})
["123 Main St", "", "Springfield", "IL"]
iex> HL7v2.Type.AD.encode(nil)
[]
"""
@spec encode(t() | nil) :: list()
def encode(nil), do: []
def encode(%__MODULE__{} = ad) do
[
ad.street_address || "",
ad.other_designation || "",
ad.city || "",
ad.state_or_province || "",
ad.zip_or_postal_code || "",
ad.country || "",
ad.address_type || "",
ad.other_geographic_designation || ""
]
|> Type.trim_trailing()
end
end