Packages
hl7v2
3.8.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/xad.ex
defmodule HL7v2.Type.XAD do
@moduledoc """
Extended Address (XAD) -- HL7v2 composite data type.
14 components:
1. Street Address (SAD) -- sub-components delimited by `&`
2. Other Designation (ST)
3. City (ST)
4. State or Province (ST)
5. Zip or Postal Code (ST)
6. Country (ID) -- Table 0399, ISO 3166-1
7. Address Type (ID) -- Table 0190: H=Home, B=Business, M=Mailing, etc.
8. Other Geographic Designation (ST)
9. County/Parish Code (IS) -- Table 0289
10. Census Tract (IS) -- Table 0288
11. Address Representation Code (ID) -- Table 0465
12. Address Validity Range (DR) -- deprecated, sub-components delimited by `&`
13. Effective Date (TS) -- sub-components delimited by `&`
14. Expiration Date (TS) -- sub-components delimited by `&`
"""
@behaviour HL7v2.Type
alias HL7v2.Type
alias HL7v2.Type.{SAD, DR, TS}
defstruct [
:street_address,
:other_designation,
:city,
:state,
:zip,
:country,
:address_type,
:other_geographic,
:county_code,
:census_tract,
:address_representation_code,
:address_validity_range,
:effective_date,
:expiration_date
]
@type t :: %__MODULE__{
street_address: SAD.t() | nil,
other_designation: binary() | nil,
city: binary() | nil,
state: binary() | nil,
zip: binary() | nil,
country: binary() | nil,
address_type: binary() | nil,
other_geographic: binary() | nil,
county_code: binary() | nil,
census_tract: binary() | nil,
address_representation_code: binary() | nil,
address_validity_range: DR.t() | nil,
effective_date: TS.t() | nil,
expiration_date: TS.t() | nil
}
@doc """
Parses an XAD from a list of components.
## Examples
iex> HL7v2.Type.XAD.parse(["123 Main St&Main St&123", "", "Springfield", "IL", "62704", "USA", "H"])
%HL7v2.Type.XAD{
street_address: %HL7v2.Type.SAD{street_or_mailing_address: "123 Main St", street_name: "Main St", dwelling_number: "123"},
city: "Springfield",
state: "IL",
zip: "62704",
country: "USA",
address_type: "H"
}
iex> HL7v2.Type.XAD.parse([])
%HL7v2.Type.XAD{}
"""
@spec parse(list()) :: t()
def parse(components) when is_list(components) do
%__MODULE__{
street_address: Type.parse_sub(SAD, Type.get_component(components, 0)),
other_designation: Type.get_component(components, 1),
city: Type.get_component(components, 2),
state: Type.get_component(components, 3),
zip: Type.get_component(components, 4),
country: Type.get_component(components, 5),
address_type: Type.get_component(components, 6),
other_geographic: Type.get_component(components, 7),
county_code: Type.get_component(components, 8),
census_tract: Type.get_component(components, 9),
address_representation_code: Type.get_component(components, 10),
address_validity_range: Type.parse_sub(DR, Type.get_component(components, 11)),
effective_date: Type.parse_sub_ts(Type.get_component(components, 12)),
expiration_date: Type.parse_sub_ts(Type.get_component(components, 13))
}
end
@doc """
Encodes an XAD to a list of component strings.
## Examples
iex> HL7v2.Type.XAD.encode(%HL7v2.Type.XAD{
...> street_address: %HL7v2.Type.SAD{street_or_mailing_address: "123 Main St"},
...> city: "Springfield",
...> state: "IL",
...> zip: "62704"
...> })
["123 Main St", "", "Springfield", "IL", "62704"]
iex> HL7v2.Type.XAD.encode(nil)
[]
"""
@spec encode(t() | nil) :: list()
def encode(nil), do: []
def encode(%__MODULE__{} = xad) do
[
Type.encode_sub(SAD, xad.street_address),
xad.other_designation || "",
xad.city || "",
xad.state || "",
xad.zip || "",
xad.country || "",
xad.address_type || "",
xad.other_geographic || "",
xad.county_code || "",
xad.census_tract || "",
xad.address_representation_code || "",
Type.encode_sub(DR, xad.address_validity_range),
Type.encode_sub_ts(xad.effective_date),
Type.encode_sub_ts(xad.expiration_date)
]
|> Type.trim_trailing()
end
end