HL7v2.Type.DR (HL7v2 v3.10.1)

Copy Markdown View Source

Date/Time Range (DR) -- HL7v2 composite data type.

Two components: range start and range end, both TS (Time Stamp) type. When only a start is known, component 2 is null (open-ended range). When only an end is known, component 1 is null.

Summary

Functions

Encodes a date/time range to a list of component strings.

Parses a date/time range from a list of components.

Types

t()

@type t() :: %HL7v2.Type.DR{
  range_end: HL7v2.Type.TS.t() | nil,
  range_start: HL7v2.Type.TS.t() | nil
}

Functions

encode(dr)

@spec encode(t() | nil) :: list()

Encodes a date/time range to a list of component strings.

Examples

iex> HL7v2.Type.DR.encode(%HL7v2.Type.DR{
...>   range_start: %HL7v2.Type.TS{time: %HL7v2.Type.DTM{year: 2026, month: 1, day: 1}},
...>   range_end: %HL7v2.Type.TS{time: %HL7v2.Type.DTM{year: 2026, month: 12, day: 31}}
...> })
["20260101", "20261231"]

iex> HL7v2.Type.DR.encode(nil)
[]

parse(components)

@spec parse(list()) :: t()

Parses a date/time range from a list of components.

Each component is itself a TS, so sub-components within are split by &. In practice, most DR values carry only a DTM string per component.

Examples

iex> HL7v2.Type.DR.parse(["20260101", "20261231"])
%HL7v2.Type.DR{
  range_start: %HL7v2.Type.TS{time: %HL7v2.Type.DTM{year: 2026, month: 1, day: 1}},
  range_end: %HL7v2.Type.TS{time: %HL7v2.Type.DTM{year: 2026, month: 12, day: 31}}
}

iex> HL7v2.Type.DR.parse([])
%HL7v2.Type.DR{}