Packages
hl7v2
2.1.2
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/rpt.ex
defmodule HL7v2.Type.RPT do
@moduledoc """
Repeat Pattern (RPT) -- HL7v2 composite data type.
Defines a repeating schedule pattern for timing-related segments (TQ1-3).
More expressive than RI, supporting calendar-aligned and phase-based
patterns.
6 components (of 10 defined in v2.5.1; remaining 4 are rarely used):
1. Repeat Pattern Code (CWE) -- sub-components delimited by `&`, Table 0335
2. Calendar Alignment (ID) -- Table 0527: e.g., "DY" (day), "WK" (week), "MY" (month)
3. Phase Range Begin Value (NM) -- start of phase range
4. Phase Range End Value (NM) -- end of phase range
5. Period Quantity (NM) -- number of period units
6. Period Units (IS) -- Table 0xxx: e.g., "s" (seconds), "min", "h", "d", "wk", "mo"
"""
@behaviour HL7v2.Type
alias HL7v2.Type
alias HL7v2.Type.{CWE, NM}
defstruct [
:repeat_pattern_code,
:calendar_alignment,
:phase_range_begin_value,
:phase_range_end_value,
:period_quantity,
:period_units
]
@type t :: %__MODULE__{
repeat_pattern_code: CWE.t() | nil,
calendar_alignment: binary() | nil,
phase_range_begin_value: NM.t() | nil,
phase_range_end_value: NM.t() | nil,
period_quantity: NM.t() | nil,
period_units: binary() | nil
}
@doc """
Parses an RPT from a list of components.
## Examples
iex> HL7v2.Type.RPT.parse(["QAM&Every morning&HL70335"])
%HL7v2.Type.RPT{
repeat_pattern_code: %HL7v2.Type.CWE{identifier: "QAM", text: "Every morning", name_of_coding_system: "HL70335"}
}
iex> HL7v2.Type.RPT.parse(["Q6H&Every 6 hours&HL70335", "DY", "", "", "6", "h"])
%HL7v2.Type.RPT{
repeat_pattern_code: %HL7v2.Type.CWE{identifier: "Q6H", text: "Every 6 hours", name_of_coding_system: "HL70335"},
calendar_alignment: "DY",
period_quantity: %HL7v2.Type.NM{value: "6", original: "6"},
period_units: "h"
}
iex> HL7v2.Type.RPT.parse([])
%HL7v2.Type.RPT{}
"""
@spec parse(list()) :: t()
def parse(components) when is_list(components) do
%__MODULE__{
repeat_pattern_code: Type.parse_sub(CWE, Type.get_component(components, 0)),
calendar_alignment: Type.get_component(components, 1),
phase_range_begin_value: components |> Type.get_component(2) |> NM.parse(),
phase_range_end_value: components |> Type.get_component(3) |> NM.parse(),
period_quantity: components |> Type.get_component(4) |> NM.parse(),
period_units: Type.get_component(components, 5)
}
end
@doc """
Encodes an RPT to a list of component strings.
## Examples
iex> HL7v2.Type.RPT.encode(%HL7v2.Type.RPT{
...> repeat_pattern_code: %HL7v2.Type.CWE{identifier: "QAM", text: "Every morning", name_of_coding_system: "HL70335"}
...> })
["QAM&Every morning&HL70335"]
iex> HL7v2.Type.RPT.encode(%HL7v2.Type.RPT{
...> repeat_pattern_code: %HL7v2.Type.CWE{identifier: "Q6H"},
...> period_quantity: %HL7v2.Type.NM{value: "6", original: "6"},
...> period_units: "h"
...> })
["Q6H", "", "", "", "6", "h"]
iex> HL7v2.Type.RPT.encode(nil)
[]
"""
@spec encode(t() | nil) :: list()
def encode(nil), do: []
def encode(%__MODULE__{} = rpt) do
[
Type.encode_sub(CWE, rpt.repeat_pattern_code),
rpt.calendar_alignment || "",
NM.encode(rpt.phase_range_begin_value),
NM.encode(rpt.phase_range_end_value),
NM.encode(rpt.period_quantity),
rpt.period_units || ""
]
|> Type.trim_trailing()
end
end