fhir/r4/primitive_types
parsing logic common to date, datetime, instant, time FHIR dateTime uses a subset of ISO 8601 so this is based on https://hexdocs.pm/datetime_iso8601/datetime_iso8601.html#DateTime
the goal is to make only valid times representable, but also roundtrip string exactly, including millisec implicit precision
Types
A date, or partial date (e.g., just year or year + month) as used in human communication. The format is a subset of [ISO8601] icon: YYYY, YYYY-MM, or YYYY-MM-DD, e.g., 2018, 1973-06, or 1905-08-23. There SHALL be no timezone offset. Dates SHALL be valid dates. Regex: (0-9|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1]))?)?
pub type Date {
Year(year: Int)
YearMonth(year: Int, month: calendar.Month)
YearMonthDay(year: Int, month: calendar.Month, day: Int)
}
Constructors
-
Year(year: Int) -
YearMonth(year: Int, month: calendar.Month) -
YearMonthDay(year: Int, month: calendar.Month, day: Int)
A date, date-time or partial date (e.g., just year or year + month) as used in human communication. The format is a subset of ISO8601 YYYY, YYYY-MM, YYYY-MM-DD or YYYY-MM-DDThh:mm:ss+zz:zz, e.g., 2018, 1973-06, 1905-08-23, 2015-02-07T13:28:17-05:00 or 2017-01-01T00:00:00.000Z. If hours and minutes are specified, a timezone offset SHALL be populated. Actual timezone codes can be sent using the Timezone Code extension, if desired. Seconds must be provided due to schema type constraints but may be zero-filled and may be ignored at receiver discretion. Milliseconds are optionally allowed. Dates SHALL be valid dates. The time “24:00” is not allowed. Leap Seconds are allowed
pub type DateTime {
DateTime(date: Date, time: option.Option(TimeAndZone))
}
Constructors
-
DateTime(date: Date, time: option.Option(TimeAndZone))
An instant in time in a format that is a subset of ISO8601 YYYY-MM-DDThh:mm:ss.sss+zz:zz (e.g., 2015-02-07T13:28:17.239+02:00 or 2017-01-01T00:00:00Z). The time SHALL specified at least to the second and SHALL include a timezone offset. Sub-millisecond precision is optionally allowed. Note: This is intended for when precisely observed times are required (typically system logs etc.), and not human-reported times - for those, use date or dateTime. Regex: (0-9|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(.[0-9]{1,9})?(Z|(+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))
pub type Instant {
Instant(date: Date, time: Time, timezone: Timezone)
}
Constructors
part of time after decimal point where precision is number of digits after decimal point and value is nanoseconds eg 123_000_000 nanoseconds = 0.123 seconds NanosecWithPrecision(123_000_000, Some(3)) -> .123 NanosecWithPrecision(123_000_000, Some(4)) -> .1230 NanosecWithPrecision(123_000, Some(5)) -> .00012
pub type NanosecWithPrecision {
NanosecWithPrecision(value: Int, precision: option.Option(Int))
}
Constructors
-
NanosecWithPrecision(value: Int, precision: option.Option(Int))
A time during the day, in the format hh:mm:ss a subset of ISO8601 There is no date specified. Seconds must be provided due to schema type constraints but may be zero-filled and may be ignored at receiver discretion. The time “24:00” SHALL NOT be used. A timezone offset SHALL NOT be present. Times can be converted to a Duration since midnight. Regex: ([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(.[0-9]{1,9})?
pub type Time {
Time(
hour: Int,
minute: Int,
second: Int,
nanosec: option.Option(NanosecWithPrecision),
)
}
Constructors
-
Time( hour: Int, minute: Int, second: Int, nanosec: option.Option(NanosecWithPrecision), )
Values
pub const byte_colon: Int
pub const byte_minus: Int
pub const byte_t_uppercase: Int
pub const byte_z_uppercase: Int
pub fn date_decoder() -> decode.Decoder(Date)
pub fn date_to_string(date: Date) -> String
pub fn datetime_decoder() -> decode.Decoder(DateTime)
pub fn datetime_to_string(dt: DateTime) -> String
pub fn expect_byte(
bytes: BitArray,
expected: Int,
) -> Result(BitArray, Nil)
pub fn instant_decoder() -> decode.Decoder(Instant)
pub fn instant_to_string(instant: Instant) -> String
pub fn month_to_string(month: calendar.Month) -> String
pub fn nanosec_to_string(
nanosec: option.Option(NanosecWithPrecision),
) -> String
pub fn parse_date(input: String) -> Result(Date, Nil)
pub fn parse_datetime(input: String) -> Result(DateTime, Nil)
pub fn parse_digits(
from bytes: BitArray,
count count: Int,
) -> Result(#(Int, BitArray), Nil)
pub fn parse_instant(input: String) -> Result(Instant, Nil)
pub fn parse_optional_fraction_as_nanoseconds(
bytes: BitArray,
) -> Result(#(option.Option(NanosecWithPrecision), BitArray), Nil)
pub fn parse_time(input: String) -> Result(Time, Nil)
pub fn parse_time_of_day(
bytes: BitArray,
) -> Result(
#(Int, Int, Int, option.Option(NanosecWithPrecision), BitArray),
Nil,
)
pub fn parse_timezone(
bytes: BitArray,
) -> Result(#(Timezone, BitArray), Nil)
pub fn time_decoder() -> decode.Decoder(Time)
pub fn time_of_day_to_string(
hour: Int,
minute: Int,
second: Int,
nanosec: option.Option(NanosecWithPrecision),
) -> String
pub fn time_to_string(time: Time) -> String
pub fn timezone_to_string(tz: Timezone) -> String
pub fn validate_day(
year: Int,
month: calendar.Month,
day: Int,
) -> Result(Nil, Nil)
pub fn validate_hour(hour: Int) -> Result(Nil, Nil)
pub fn validate_minute(minute: Int) -> Result(Nil, Nil)
pub fn validate_second(second: Int) -> Result(Nil, Nil)