Packages
hl7v2
3.3.6
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/rfr.ex
defmodule HL7v2.Type.RFR do
@moduledoc """
Reference Range (RFR) -- HL7v2 composite data type.
Specifies a reference range for an observation with optional demographic qualifiers.
7 components:
1. Numeric Range (NR) -- sub-components (low & high)
2. Administrative Sex (IS) -- Table 0001
3. Age Range (NR) -- sub-components
4. Gestational Age Range (NR) -- sub-components
5. Species (ST)
6. Race/Subspecies (ST)
7. Conditions (TX)
"""
@behaviour HL7v2.Type
alias HL7v2.Type
alias HL7v2.Type.NR
defstruct [
:numeric_range,
:administrative_sex,
:age_range,
:gestational_age_range,
:species,
:race_subspecies,
:conditions
]
@type t :: %__MODULE__{
numeric_range: NR.t() | nil,
administrative_sex: binary() | nil,
age_range: NR.t() | nil,
gestational_age_range: NR.t() | nil,
species: binary() | nil,
race_subspecies: binary() | nil,
conditions: binary() | nil
}
@doc """
Parses an RFR from a list of components.
## Examples
iex> HL7v2.Type.RFR.parse(["3.5&5.5", "M"])
%HL7v2.Type.RFR{
numeric_range: %HL7v2.Type.NR{
low: %HL7v2.Type.NM{value: "3.5", original: "3.5"},
high: %HL7v2.Type.NM{value: "5.5", original: "5.5"}
},
administrative_sex: "M"
}
iex> HL7v2.Type.RFR.parse([])
%HL7v2.Type.RFR{}
"""
@spec parse(list()) :: t()
def parse(components) when is_list(components) do
%__MODULE__{
numeric_range: Type.parse_sub(NR, Type.get_component(components, 0)),
administrative_sex: Type.get_component(components, 1),
age_range: Type.parse_sub(NR, Type.get_component(components, 2)),
gestational_age_range: Type.parse_sub(NR, Type.get_component(components, 3)),
species: Type.get_component(components, 4),
race_subspecies: Type.get_component(components, 5),
conditions: Type.get_component(components, 6)
}
end
@doc """
Encodes an RFR to a list of component strings.
## Examples
iex> HL7v2.Type.RFR.encode(%HL7v2.Type.RFR{numeric_range: %HL7v2.Type.NR{low: %HL7v2.Type.NM{value: "3.5", original: "3.5"}, high: %HL7v2.Type.NM{value: "5.5", original: "5.5"}}, administrative_sex: "M"})
["3.5&5.5", "M"]
iex> HL7v2.Type.RFR.encode(nil)
[]
"""
@spec encode(t() | nil) :: list()
def encode(nil), do: []
def encode(%__MODULE__{} = rfr) do
[
Type.encode_sub(NR, rfr.numeric_range),
rfr.administrative_sex || "",
Type.encode_sub(NR, rfr.age_range),
Type.encode_sub(NR, rfr.gestational_age_range),
rfr.species || "",
rfr.race_subspecies || "",
rfr.conditions || ""
]
|> Type.trim_trailing()
end
end