HL7v2.Type.DT (HL7v2 v3.10.1)

Copy Markdown View Source

Date (DT) -- HL7v2 primitive data type.

Format: YYYY[MM[DD]]. Supports year, month, and day precision. Parses to an %HL7v2.Type.DT{} struct preserving precision, or a Date when full day precision is available.

Summary

Functions

Encodes a date value to YYYYMMDD, YYYYMM, or YYYY format.

Parses a date string in YYYY[MM[DD]] format.

Types

t()

@type t() :: %HL7v2.Type.DT{
  day: pos_integer() | nil,
  month: pos_integer() | nil,
  original: term(),
  year: pos_integer()
}

Functions

encode(arg1)

@spec encode(Date.t() | t() | nil) :: binary()

Encodes a date value to YYYYMMDD, YYYYMM, or YYYY format.

Examples

iex> HL7v2.Type.DT.encode(~D[1988-07-04])
"19880704"

iex> HL7v2.Type.DT.encode(%HL7v2.Type.DT{year: 1995, month: 3})
"199503"

iex> HL7v2.Type.DT.encode(%HL7v2.Type.DT{year: 2026})
"2026"

iex> HL7v2.Type.DT.encode(nil)
""

parse(raw)

@spec parse(binary() | nil) :: Date.t() | t() | nil

Parses a date string in YYYY[MM[DD]] format.

Returns a Date struct when fully specified (8 digits), or an %HL7v2.Type.DT{} struct for partial dates.

Examples

iex> HL7v2.Type.DT.parse("19880704")
~D[1988-07-04]

iex> HL7v2.Type.DT.parse("199503")
%HL7v2.Type.DT{year: 1995, month: 3, day: nil}

iex> HL7v2.Type.DT.parse("2026")
%HL7v2.Type.DT{year: 2026, month: nil, day: nil}

iex> HL7v2.Type.DT.parse("")
nil

iex> HL7v2.Type.DT.parse(nil)
nil