Documentation
¶
Overview ¶
Package types defines the FHIRPath type system.
Index ¶
- Constants
- Variables
- func CalendarUnitForUCUMCode(code string) (string, bool)
- func EqualTemporal(left, right Value) (bool, error)
- func IsSystemTypeName(name string) bool
- func IsTemporal(v Value) bool
- func PutCollection(c *Collection)
- func SecondUnitMilliseconds(value decimal.Decimal, unit string) (int, bool)
- func TemporalDifference(from, to Value, precision string) (int64, error)
- func TemporalDuration(from, to Value, precision string) (int64, error)
- type Boolean
- func (b Boolean) Bool() bool
- func (p Boolean) Element() *ObjectValue
- func (b Boolean) Equal(other Value) bool
- func (b Boolean) Equivalent(other Value) bool
- func (p Boolean) HasElement() bool
- func (b Boolean) IsEmpty() bool
- func (b Boolean) Not() Boolean
- func (b Boolean) String() string
- func (b Boolean) Type() string
- func (b Boolean) WithElement(element *ObjectValue) Boolean
- func (b Boolean) WithFHIRType(fhirType string) Boolean
- type Collection
- func (c Collection) AllFalse() bool
- func (c Collection) AllTrue() bool
- func (c Collection) AnyFalse() bool
- func (c Collection) AnyTrue() bool
- func (c Collection) Combine(other Collection) Collection
- func (c Collection) Contains(v Value) bool
- func (c Collection) Count() int
- func (c Collection) Distinct() Collection
- func (c Collection) Empty() bool
- func (c Collection) Exclude(other Collection) Collection
- func (c Collection) First() (Value, bool)
- func (c Collection) Intersect(other Collection) Collection
- func (c Collection) IsDistinct() bool
- func (c Collection) Last() (Value, bool)
- func (c Collection) Single() (Value, error)
- func (c Collection) SingletonBoolean() (value, ok bool)
- func (c Collection) Skip(n int) Collection
- func (c Collection) String() string
- func (c Collection) Tail() Collection
- func (c Collection) Take(n int) Collection
- func (c Collection) ToBoolean() (bool, error)
- func (c Collection) Union(other Collection) Collection
- type Comparable
- type Date
- func (d Date) AddDuration(value int, unit string) (Date, error)
- func (d Date) Compare(other Value) (int, error)
- func (d Date) Day() int
- func (p Date) Element() *ObjectValue
- func (d Date) Equal(other Value) bool
- func (d Date) Equivalent(other Value) bool
- func (p Date) HasElement() bool
- func (d Date) IsEmpty() bool
- func (d Date) Month() int
- func (d Date) Precision() DatePrecision
- func (d Date) String() string
- func (d Date) SubtractDuration(value int, unit string) (Date, error)
- func (d Date) ToTime() time.Time
- func (d Date) Type() string
- func (d Date) WithElement(element *ObjectValue) Date
- func (d Date) WithFHIRType(fhirType string) Date
- func (d Date) Year() int
- type DatePrecision
- type DateTime
- func (dt DateTime) AddDuration(value int, unit string) (DateTime, error)
- func (dt DateTime) Compare(other Value) (int, error)
- func (dt DateTime) Day() int
- func (p DateTime) Element() *ObjectValue
- func (dt DateTime) Equal(other Value) bool
- func (dt DateTime) Equivalent(other Value) bool
- func (p DateTime) HasElement() bool
- func (dt DateTime) HasTZ() bool
- func (dt DateTime) Hour() int
- func (dt DateTime) IsEmpty() bool
- func (dt DateTime) Millisecond() int
- func (dt DateTime) Minute() int
- func (dt DateTime) Month() int
- func (dt DateTime) Precision() DateTimePrecision
- func (dt DateTime) Second() int
- func (dt DateTime) String() string
- func (dt DateTime) SubtractDuration(value int, unit string) (DateTime, error)
- func (dt DateTime) TZOffset() int
- func (dt DateTime) ToTime() time.Time
- func (dt DateTime) Type() string
- func (dt DateTime) WithElement(element *ObjectValue) DateTime
- func (dt DateTime) WithFHIRType(fhirType string) DateTime
- func (dt DateTime) Year() int
- type DateTimePrecision
- type Decimal
- func (d Decimal) Abs() Decimal
- func (d Decimal) Add(other Decimal) Decimal
- func (d Decimal) Ceiling() Integer
- func (d Decimal) Compare(other Value) (int, error)
- func (d Decimal) Divide(other Decimal) (Decimal, error)
- func (p Decimal) Element() *ObjectValue
- func (d Decimal) Equal(other Value) bool
- func (d Decimal) Equivalent(other Value) bool
- func (d Decimal) Exp() Decimal
- func (d Decimal) Floor() Integer
- func (p Decimal) HasElement() bool
- func (d Decimal) ImplicitPrecision() int
- func (d Decimal) IsEmpty() bool
- func (d Decimal) IsInteger() bool
- func (d Decimal) Ln() (Decimal, error)
- func (d Decimal) Log(base Decimal) (Decimal, error)
- func (d Decimal) Multiply(other Decimal) Decimal
- func (d Decimal) Negate() Decimal
- func (d Decimal) Power(exp Decimal) Decimal
- func (d Decimal) Round(precision int32) Decimal
- func (d Decimal) Sqrt() (Decimal, error)
- func (d Decimal) String() string
- func (d Decimal) Subtract(other Decimal) Decimal
- func (d Decimal) ToDecimal() Decimal
- func (d Decimal) ToInteger() (Integer, bool)
- func (d Decimal) Truncate() Integer
- func (d Decimal) Type() string
- func (d Decimal) Value() decimal.Decimal
- func (d Decimal) WithElement(element *ObjectValue) Decimal
- func (d Decimal) WithFHIRType(fhirType string) Decimal
- type ElementCarrier
- type ElementTypeResolver
- type Integer
- func (i Integer) Abs() Integer
- func (i Integer) Add(other Integer) Integer
- func (i Integer) Compare(other Value) (int, error)
- func (i Integer) Div(other Integer) (Integer, error)
- func (i Integer) Divide(other Integer) (Decimal, error)
- func (p Integer) Element() *ObjectValue
- func (i Integer) Equal(other Value) bool
- func (i Integer) Equivalent(other Value) bool
- func (p Integer) HasElement() bool
- func (i Integer) IsEmpty() bool
- func (i Integer) Mod(other Integer) (Integer, error)
- func (i Integer) Multiply(other Integer) Integer
- func (i Integer) Negate() Integer
- func (i Integer) Power(exp Integer) Decimal
- func (i Integer) Sqrt() (Decimal, error)
- func (i Integer) String() string
- func (i Integer) Subtract(other Integer) Integer
- func (i Integer) ToDecimal() Decimal
- func (i Integer) Type() string
- func (i Integer) Value() int64
- func (i Integer) WithElement(element *ObjectValue) Integer
- func (i Integer) WithFHIRType(fhirType string) Integer
- type Numeric
- type ObjectValue
- func (o *ObjectValue) Children() Collection
- func (o *ObjectValue) Data() []byte
- func (o *ObjectValue) Equal(other Value) bool
- func (o *ObjectValue) Equivalent(other Value) bool
- func (o *ObjectValue) Get(field string) (Value, bool)
- func (o *ObjectValue) GetCollection(field string) Collection
- func (o *ObjectValue) GetCollectionParsedAs(field, suffix string) Collection
- func (o *ObjectValue) GetCollectionWithType(field, fhirType string) Collection
- func (o *ObjectValue) IsEmpty() bool
- func (o *ObjectValue) Keys() []string
- func (o *ObjectValue) String() string
- func (o *ObjectValue) ToQuantity() (Quantity, bool)
- func (o *ObjectValue) Type() string
- func (o *ObjectValue) TypedChildren(basePath string, res ElementTypeResolver) []TypedChild
- type Quantity
- func (q Quantity) Abs() Quantity
- func (q Quantity) Add(other Quantity) (Quantity, error)
- func (q Quantity) Comparable(other Quantity) bool
- func (q Quantity) Compare(other Value) (int, error)
- func (q Quantity) ConvertTo(unit string) (Quantity, bool)
- func (q Quantity) Divide(divisor decimal.Decimal) (Quantity, error)
- func (q Quantity) DivideQuantity(other Quantity) (Quantity, error)
- func (q Quantity) Equal(other Value) bool
- func (q Quantity) Equivalent(other Value) bool
- func (q Quantity) IsEmpty() bool
- func (q Quantity) Multiply(factor decimal.Decimal) Quantity
- func (q Quantity) MultiplyQuantity(other Quantity) (Quantity, error)
- func (q Quantity) Negate() Quantity
- func (q Quantity) String() string
- func (q Quantity) Subtract(other Quantity) (Quantity, error)
- func (q Quantity) Type() string
- func (q Quantity) Unit() string
- func (q Quantity) Value() decimal.Decimal
- type String
- func (s String) Compare(other Value) (int, error)
- func (s String) Contains(substr string) bool
- func (p String) Element() *ObjectValue
- func (s String) EndsWith(suffix string) bool
- func (s String) Equal(other Value) bool
- func (s String) Equivalent(other Value) bool
- func (p String) HasElement() bool
- func (s String) IndexOf(substr string) int
- func (s String) IsEmpty() bool
- func (s String) Length() int
- func (s String) Lower() String
- func (s String) Replace(old, replacement string) String
- func (s String) StartsWith(prefix string) bool
- func (s String) String() string
- func (s String) Substring(start, length int) String
- func (s String) ToChars() Collection
- func (s String) Type() string
- func (s String) Upper() String
- func (s String) Value() string
- func (s String) WithElement(element *ObjectValue) String
- func (s String) WithFHIRType(fhirType string) String
- type Time
- func (t Time) AddDuration(value int, unit string) (Time, error)
- func (t Time) Compare(other Value) (int, error)
- func (p Time) Element() *ObjectValue
- func (t Time) Equal(other Value) bool
- func (t Time) Equivalent(other Value) bool
- func (p Time) HasElement() bool
- func (t Time) Hour() int
- func (t Time) IsEmpty() bool
- func (t Time) Millisecond() int
- func (t Time) Minute() int
- func (t Time) Precision() TimePrecision
- func (t Time) Second() int
- func (t Time) String() string
- func (t Time) SubtractDuration(value int, unit string) (Time, error)
- func (t Time) Type() string
- func (t Time) WithElement(element *ObjectValue) Time
- func (t Time) WithFHIRType(fhirType string) Time
- type TimePrecision
- type TypeError
- type TypedChild
- type Value
Constants ¶
const ( TypeNameBoolean = "Boolean" TypeNameString = "String" TypeNameInteger = "Integer" TypeNameDecimal = "Decimal" TypeNameDate = "Date" TypeNameDateTime = "DateTime" TypeNameTime = "Time" TypeNameQuantity = "Quantity" )
The names of the System types, as FHIRPath spells them.
These are the values Type() returns and the names is, as and ofType() match against, so they are shared rather than written out at each site: the engine compares them across three packages, and a disagreement about one of them would surface as a type test that silently never matches.
FHIR primitives are deliberately not here. FHIR.boolean is a distinct type from System.Boolean and is spelled in lower camel case for exactly that reason; the mapping between the two lives in the evaluator, which is where the distinction is decided.
const DefaultQuantityUnit = "1"
DefaultQuantityUnit is the unit a quantity carries when its source gave none.
The specification calls it "the UCUM default unit" and writes it as '1': 42.toQuantity() is 42 '1'. It matters that the unit is present rather than blank, because '1' is dimensionless and so not convertible to a meter — which is why 45.toQuantity('m') is empty rather than 45 'm'.
const UCUMSystem = "http://unitsofmeasure.org"
UCUMSystem identifies UCUM as the code system of a FHIR Quantity.
Variables ¶
var EmptyCollection = Collection{}
EmptyCollection is a shared empty collection to avoid allocations.
var ErrCalendarConversionRequired = errors.New("UCUM year and month durations require explicit conversion to calendar units")
ErrCalendarConversionRequired reports that a UCUM year or month was used to shift a date or time.
A UCUM year is a fixed span of 365.25 days and a UCUM month a fixed 30.44, while adding a calendar year or month moves to the same date in another year or month. The FHIRPath specification keeps the two systems apart above seconds and requires an explicit conversion to cross between them, so @1973-12-25 + 1 'a' does not silently pick one meaning.
var ErrDateComponentOnTime = errors.New("a date component cannot shift a time")
ErrDateComponentOnTime reports an attempt to shift a time of day by a unit that measures the calendar.
A time carries no date, so there is nothing for a day or a month to move. "If there is more than one item, an item of an incompatible type, or an unsupported unit for the type, the evaluation of the expression will end and signal an error ... This includes attempting to add date components to a Time."
var ErrIncompatibleUnits = errors.New("incompatible units")
ErrIncompatibleUnits reports that two quantities are not commensurable, so no conversion between their units exists. Per the FHIRPath spec, "attempting to operate on quantities with invalid units will result in empty ({})", so callers translate this sentinel into an empty collection instead of failing the whole expression.
var ErrPrecisionMismatch = errors.New("temporal values are specified to different precisions")
ErrPrecisionMismatch reports that two temporal values agree on every precision they have in common, but one is specified more precisely than the other, so the outcome cannot be determined.
The FHIRPath specification requires the operation to yield empty in this case: "If one value is specified to a different level of precision than the other, the result is empty ({ }) to indicate that the result of the comparison is unknown." Callers translate this sentinel into an empty collection.
Order matters: the comparison walks precisions from the most significant down and stops at the first difference, so this is only reached when everything shared matches. now() > today() is empty, while now() > @1974-12-25 is true, decided at the year.
var ErrUnsupportedPrecision = errors.New("precision is not valid for this temporal type")
ErrUnsupportedPrecision reports that the precision named in a difference() or duration() call is not one the input's type admits.
The specification fixes the permitted set per type: a date takes year, month, week or day; a datetime adds hour, minute, second and millisecond; a time takes only the four time-of-day precisions. Asking a date for the number of hours crossed is not an unknown result — it is a nonsensical request, so it is an error rather than empty.
var FalseCollection = Collection{falseBoolean}
FalseCollection is a cached collection containing false.
var TrueCollection = Collection{trueBoolean}
TrueCollection is a cached collection containing true.
Functions ¶
func CalendarUnitForUCUMCode ¶ added in v1.5.0
CalendarUnitForUCUMCode returns the calendar duration keyword FHIR maps a time-valued UCUM code onto, and whether the code is one it maps.
This is what lets a Quantity read from FHIR data take part in date arithmetic at all: a Quantity of 1 'a' would be refused, since a UCUM year is a definite 365.25 days and cannot be added to a calendar, while the 1 year it maps to is exactly what the calendar can add.
func EqualTemporal ¶ added in v1.5.0
EqualTemporal reports whether two temporal values are equal, under the same precision rule as ordering: the comparison proceeds precision by precision and stops at the first difference, so equality is unknown — and the operator yields empty — only when the values match on everything they share while one is specified more precisely.
@2012-01 = @2012 // empty, different precision @2012-01 = @2012-02 // false, decided at the month @T10:30:00 = @T10:30:00.0 // true, seconds and milliseconds are one precision
Returns ErrPrecisionMismatch for the unknown case, and an error when the values are not comparable temporals at all.
func IsSystemTypeName ¶ added in v1.5.0
IsSystemTypeName reports whether the name is one of the System types FHIRPath declares in its Literals section.
This is the type system of the language rather than a FHIR version-specific list, so it does not go stale: any other type name on a primitive value came from the FHIR model (code, uri, id, markdown, ...).
func IsTemporal ¶ added in v1.5.0
IsTemporal reports whether a value is a Date, DateTime or Time.
func PutCollection ¶
func PutCollection(c *Collection)
PutCollection returns a Collection to the pool for reuse. The collection is reset to length 0.
func SecondUnitMilliseconds ¶ added in v1.5.0
SecondUnitMilliseconds converts a quantity given in seconds to whole milliseconds, reporting false when the unit is not a second.
This is the one place a duration's fractional part survives: "The decimal portion of the time-valued quantity is only applied for second or millisecond precisions; for all other precisions, the decimal portion is ignored, since date/time arithmetic is performed with calendar duration semantics." So 0.1 's' shifts by 100 milliseconds, while 7.9 days shifts by seven.
func TemporalDifference ¶ added in v1.5.0
TemporalDifference returns the number of boundaries of the given precision crossed between two temporal values, negative when the input is the later of the two.
A boundary is a point at which the named component changes: the difference in weeks between two dates is the number of Sundays that fall after the first and on or before the second, which is why @2025-01-02.difference(@2025-01-07, 'week') is 1 even though only five days separate them.
Reports ErrPrecisionMismatch when either value is specified less precisely than the request, which callers translate to empty, and ErrUnsupportedPrecision when the precision does not apply to the type.
func TemporalDuration ¶ added in v1.5.0
TemporalDuration returns the number of whole periods of the given precision between two temporal values, negative when the input is the later of the two.
This is the "how long since" reading, distinct from the boundary count: @2025-01-01.duration(@2025-09-01, 'year') is 0 because the year has not elapsed, where difference() would report 0 as well but @2024-12-31.difference(@2025-01-01, 'year') is 1 and its duration is 0.
Reports the same errors as TemporalDifference.
Types ¶
type Boolean ¶
type Boolean struct {
// contains filtered or unexported fields
}
Boolean represents a FHIRPath boolean value.
func (Boolean) Element ¶ added in v1.5.0
func (p Boolean) Element() *ObjectValue
Element returns the FHIR element a primitive was read with, or nil when the primitive stood alone in the JSON.
func (Boolean) Equivalent ¶
Equivalent is the same as Equal for booleans.
func (Boolean) HasElement ¶ added in v1.5.0
func (p Boolean) HasElement() bool
HasElement reports whether any element accompanied the value.
func (Boolean) WithElement ¶ added in v1.5.0
func (b Boolean) WithElement(element *ObjectValue) Boolean
WithElement returns a copy carrying the FHIR element that accompanied the value in the JSON, which is where its extensions and id live.
func (Boolean) WithFHIRType ¶ added in v1.5.0
WithFHIRType returns a copy that reports the FHIR type it was declared with. FHIR primitives are types in their own right — a FHIR.boolean is not a System.Boolean — so a value keeps the name the model gave it.
type Collection ¶
type Collection []Value
Collection is an ordered sequence of FHIRPath values. It is the fundamental return type for all FHIRPath expressions.
func GetCollection ¶
func GetCollection() *Collection
GetCollection returns a Collection from the pool. The returned collection has length 0 but may have capacity > 0.
func JSONToCollection ¶
func JSONToCollection(data []byte) (Collection, error)
JSONToCollection converts JSON bytes to a Collection.
func NewCollectionWithCap ¶
func NewCollectionWithCap(capacity int) Collection
NewCollectionWithCap creates a new Collection with the specified capacity. Use this when you know the expected size to avoid reallocations.
func SingletonCollection ¶
func SingletonCollection(v Value) Collection
SingletonCollection creates a collection with a single value. This is a common operation that benefits from optimization.
func (Collection) AllFalse ¶
func (c Collection) AllFalse() bool
AllFalse returns true if all items are boolean false.
func (Collection) AllTrue ¶
func (c Collection) AllTrue() bool
AllTrue returns true if all items are boolean true.
func (Collection) AnyFalse ¶
func (c Collection) AnyFalse() bool
AnyFalse returns true if any item is boolean false.
func (Collection) AnyTrue ¶
func (c Collection) AnyTrue() bool
AnyTrue returns true if any item is boolean true.
func (Collection) Combine ¶
func (c Collection) Combine(other Collection) Collection
Combine returns a new collection that combines c and other. Unlike Union, duplicates are preserved.
func (Collection) Contains ¶
func (c Collection) Contains(v Value) bool
Contains returns true if the collection contains a value equal to v.
func (Collection) Count ¶
func (c Collection) Count() int
Count returns the number of elements in the collection.
func (Collection) Distinct ¶
func (c Collection) Distinct() Collection
Distinct returns a new collection with duplicate values removed. Preserves the order of first occurrence.
func (Collection) Empty ¶
func (c Collection) Empty() bool
Empty returns true if the collection has no elements.
func (Collection) Exclude ¶
func (c Collection) Exclude(other Collection) Collection
Exclude returns elements in c that are not in other.
func (Collection) First ¶
func (c Collection) First() (Value, bool)
First returns the first element and true, or nil and false if empty.
func (Collection) Intersect ¶
func (c Collection) Intersect(other Collection) Collection
Intersect returns elements that are in both collections.
func (Collection) IsDistinct ¶
func (c Collection) IsDistinct() bool
IsDistinct returns true if all elements in the collection are unique.
func (Collection) Last ¶
func (c Collection) Last() (Value, bool)
Last returns the last element and true, or nil and false if empty.
func (Collection) Single ¶
func (c Collection) Single() (Value, error)
Single returns the single element if the collection has exactly one element. Returns an error if empty or has more than one element.
func (Collection) SingletonBoolean ¶ added in v1.5.0
func (c Collection) SingletonBoolean() (value, ok bool)
SingletonBoolean applies the FHIRPath "Singleton Evaluation of Collections" rule for operations that expect a Boolean input: a single Boolean node evaluates to its value, and a single node of any other type evaluates to true. FHIR invariants rely on this — age-1 opens with "(code or value.empty())", where code is a string.
ok is false when the collection is empty or holds more than one item; callers propagate empty in that case.
func (Collection) Skip ¶
func (c Collection) Skip(n int) Collection
Skip returns a collection with the first n elements removed.
func (Collection) String ¶
func (c Collection) String() string
String returns a string representation of the collection.
func (Collection) Tail ¶
func (c Collection) Tail() Collection
Tail returns all elements except the first.
func (Collection) Take ¶
func (c Collection) Take(n int) Collection
Take returns a collection with only the first n elements.
func (Collection) ToBoolean ¶
func (c Collection) ToBoolean() (bool, error)
ToBoolean converts singleton collection to boolean. Returns error if not a singleton or not a boolean value.
func (Collection) Union ¶
func (c Collection) Union(other Collection) Collection
Union returns a new collection that is the union of c and other. Duplicates are removed.
type Comparable ¶
type Comparable interface {
Value
// Compare returns -1 if less than, 0 if equal, 1 if greater than.
// Returns error if types are incompatible.
Compare(other Value) (int, error)
}
Comparable is implemented by types that support ordering.
type Date ¶
type Date struct {
// contains filtered or unexported fields
}
Date represents a FHIRPath date value. Supports partial dates: year, year-month, year-month-day.
func NewDateFromTime ¶
NewDateFromTime creates a Date from a time.Time.
func (Date) AddDuration ¶
AddDuration adds a duration (as Quantity with temporal unit) to the date. Supported units: year(s), month(s), week(s), day(s)
func (Date) Compare ¶
Compare compares two dates. Returns -1, 0, or 1. Implements the Comparable interface. Returns empty (error) if precisions differ and comparison is ambiguous.
func (Date) Element ¶ added in v1.5.0
func (p Date) Element() *ObjectValue
Element returns the FHIR element a primitive was read with, or nil when the primitive stood alone in the JSON.
func (Date) Equivalent ¶
Equivalent checks equivalence with another value.
func (Date) HasElement ¶ added in v1.5.0
func (p Date) HasElement() bool
HasElement reports whether any element accompanied the value.
func (Date) Precision ¶
func (d Date) Precision() DatePrecision
Precision returns the date precision.
func (Date) SubtractDuration ¶
SubtractDuration subtracts a duration from the date.
func (Date) WithElement ¶ added in v1.5.0
func (d Date) WithElement(element *ObjectValue) Date
WithElement returns a copy carrying the FHIR element that accompanied the value in the JSON, which is where its extensions and id live.
func (Date) WithFHIRType ¶ added in v1.5.0
WithFHIRType returns a copy that reports the FHIR type it was declared with. FHIR primitives are types in their own right — a FHIR.boolean is not a System.Boolean — so a value keeps the name the model gave it.
type DatePrecision ¶
type DatePrecision int
DatePrecision indicates the precision of a date.
const ( YearPrecision DatePrecision = iota MonthPrecision DayPrecision )
type DateTime ¶
type DateTime struct {
// contains filtered or unexported fields
}
DateTime represents a FHIRPath datetime value.
func NewDateTime ¶
NewDateTime creates a DateTime from a string.
func NewDateTimeFromTime ¶
NewDateTimeFromTime creates a DateTime from time.Time.
func (DateTime) AddDuration ¶
AddDuration adds a duration (as Quantity with temporal unit) to the datetime. Supported units: year(s), month(s), week(s), day(s), hour(s), minute(s), second(s), millisecond(s)
func (DateTime) Compare ¶
Compare compares two datetimes. Returns -1, 0, or 1. Implements the Comparable interface. Returns error if precisions differ and comparison is ambiguous.
func (DateTime) Element ¶ added in v1.5.0
func (p DateTime) Element() *ObjectValue
Element returns the FHIR element a primitive was read with, or nil when the primitive stood alone in the JSON.
func (DateTime) Equivalent ¶
Equivalent checks equivalence with another value.
func (DateTime) HasElement ¶ added in v1.5.0
func (p DateTime) HasElement() bool
HasElement reports whether any element accompanied the value.
func (DateTime) HasTZ ¶ added in v1.3.0
HasTZ returns whether the datetime has an explicit timezone.
func (DateTime) Millisecond ¶
func (DateTime) Precision ¶ added in v1.3.0
func (dt DateTime) Precision() DateTimePrecision
Precision returns the datetime precision.
func (DateTime) SubtractDuration ¶
SubtractDuration subtracts a duration from the datetime.
func (DateTime) WithElement ¶ added in v1.5.0
func (dt DateTime) WithElement(element *ObjectValue) DateTime
WithElement returns a copy carrying the FHIR element that accompanied the value in the JSON, which is where its extensions and id live.
func (DateTime) WithFHIRType ¶ added in v1.5.0
WithFHIRType returns a copy that reports the FHIR type it was declared with. FHIR primitives are types in their own right — a FHIR.boolean is not a System.Boolean — so a value keeps the name the model gave it.
type DateTimePrecision ¶
type DateTimePrecision int
DateTimePrecision indicates the precision of a datetime.
const ( DTYearPrecision DateTimePrecision = iota DTMonthPrecision DTDayPrecision DTHourPrecision DTMinutePrecision DTSecondPrecision DTMillisPrecision )
type Decimal ¶
type Decimal struct {
// contains filtered or unexported fields
}
Decimal represents a FHIRPath decimal value with arbitrary precision.
func MustDecimal ¶
MustDecimal creates a new Decimal, panicking on error.
func NewDecimal ¶
NewDecimal creates a new Decimal from a string.
func NewDecimalFromDecimal ¶ added in v1.5.0
NewDecimalFromDecimal wraps an already-exact decimal value.
func NewDecimalFromFloat ¶
NewDecimalFromFloat creates a new Decimal from a float64.
func NewDecimalFromInt ¶
NewDecimalFromInt creates a new Decimal from an int64.
func (Decimal) Element ¶ added in v1.5.0
func (p Decimal) Element() *ObjectValue
Element returns the FHIR element a primitive was read with, or nil when the primitive stood alone in the JSON.
func (Decimal) Equivalent ¶
Equivalent compares two decimals at the precision of the less precise one.
"Decimal: values must be equal, comparison is done on values rounded to the precision of the least precise operand. Trailing zeroes after the decimal are ignored in determining precision."
This is what separates ~ from =: 1.2 / 1.8 is 0.666..., which equals nothing, but is equivalent to 0.67 because 0.67 is given to two places and the quotient rounded to two places is 0.67.
func (Decimal) HasElement ¶ added in v1.5.0
func (p Decimal) HasElement() bool
HasElement reports whether any element accompanied the value.
func (Decimal) ImplicitPrecision ¶ added in v1.4.0
ImplicitPrecision returns the number of decimal places in this value, inferred from the original string representation. For example, "1.0" has precision 1, "1.00" has precision 2, and "42" has precision 0. Returns 0 for computed values with no original string.
func (Decimal) String ¶
String returns the decimal string representation. For values created from string parsing, preserves the original representation (e.g., "1.0" stays "1.0"). For computed values, uses the default shopspring representation.
func (Decimal) WithElement ¶ added in v1.5.0
func (d Decimal) WithElement(element *ObjectValue) Decimal
WithElement returns a copy carrying the FHIR element that accompanied the value in the JSON, which is where its extensions and id live.
func (Decimal) WithFHIRType ¶ added in v1.5.0
WithFHIRType returns a copy that reports the FHIR type it was declared with. FHIR primitives are types in their own right — a FHIR.boolean is not a System.Boolean — so a value keeps the name the model gave it.
type ElementCarrier ¶ added in v1.5.0
type ElementCarrier interface {
Element() *ObjectValue
HasElement() bool
}
ElementCarrier is implemented by the primitive types, which may carry the FHIR element their JSON representation keeps beside the value.
Declared as an interface so that extension() and friends can ask any value for its element without knowing which primitive it is.
type ElementTypeResolver ¶ added in v1.5.0
ElementTypeResolver resolves a FHIR element path to its type, e.g. "Observation.subject" to "Reference". It is the single slice of the engine's FHIR model that type-aware child navigation needs, declared here so that this package stays independent of the evaluator.
type Integer ¶
type Integer struct {
// contains filtered or unexported fields
}
Integer represents a FHIRPath integer value.
func GetInteger ¶
GetInteger returns a cached Integer for values in range [-128, 127]. For other values, creates a new Integer.
func (Integer) Element ¶ added in v1.5.0
func (p Integer) Element() *ObjectValue
Element returns the FHIR element a primitive was read with, or nil when the primitive stood alone in the JSON.
func (Integer) Equal ¶
Equal returns true if other is an Integer with the same value, or a Decimal with an equivalent integer value.
func (Integer) Equivalent ¶
Equivalent is the same as Equal for integers.
func (Integer) HasElement ¶ added in v1.5.0
func (p Integer) HasElement() bool
HasElement reports whether any element accompanied the value.
func (Integer) WithElement ¶ added in v1.5.0
func (i Integer) WithElement(element *ObjectValue) Integer
WithElement returns a copy carrying the FHIR element that accompanied the value in the JSON, which is where its extensions and id live.
func (Integer) WithFHIRType ¶ added in v1.5.0
WithFHIRType returns a copy that reports the FHIR type it was declared with. FHIR primitives are types in their own right — a FHIR.boolean is not a System.Boolean — so a value keeps the name the model gave it.
type Numeric ¶
type Numeric interface {
Value
// ToDecimal converts the numeric to a Decimal.
ToDecimal() Decimal
}
Numeric is implemented by numeric types (Integer, Decimal).
type ObjectValue ¶
type ObjectValue struct {
// contains filtered or unexported fields
}
ObjectValue represents a FHIR resource or complex type as a JSON object.
func ElementOf ¶ added in v1.5.0
func ElementOf(value Value) (*ObjectValue, bool)
ElementOf returns the FHIR element accompanying a value, and whether there is one. An ObjectValue is its own element: a complex type keeps its extensions in the same object as the rest of its fields.
func NewObjectValue ¶
func NewObjectValue(data []byte) *ObjectValue
NewObjectValue creates a new ObjectValue from JSON bytes.
func NewObjectValueWithType ¶ added in v1.3.1
func NewObjectValueWithType(data []byte, typeName string) *ObjectValue
NewObjectValueWithType creates a new ObjectValue with an explicit FHIR type. Used when the type is known from polymorphic field resolution (e.g., valueQuantity → "Quantity").
func (*ObjectValue) Children ¶
func (o *ObjectValue) Children() Collection
Children returns a collection of all child values.
func (*ObjectValue) Equal ¶
func (o *ObjectValue) Equal(other Value) bool
Equal returns true if the JSON data is identical.
func (*ObjectValue) Equivalent ¶
func (o *ObjectValue) Equivalent(other Value) bool
Equivalent is the same as Equal for objects.
func (*ObjectValue) Get ¶
func (o *ObjectValue) Get(field string) (Value, bool)
Get retrieves a field value, caching the result.
func (*ObjectValue) GetCollection ¶
func (o *ObjectValue) GetCollection(field string) Collection
GetCollection retrieves a field as a Collection. If the field is an array, returns all elements. If the field is a single value, returns a singleton collection.
func (*ObjectValue) GetCollectionParsedAs ¶ added in v1.5.0
func (o *ObjectValue) GetCollectionParsedAs(field, suffix string) Collection
GetCollectionParsedAs retrieves a field as a Collection from a type read off a polymorphic field name, such as the Oid in valueOid.
Such a name is capitalized to form the field, while FHIR writes primitive type names in lower camel case and complex ones capitalized. The value itself says which it is — a primitive parses to a primitive — so the recorded type is corrected accordingly rather than kept in the field's spelling.
func (*ObjectValue) GetCollectionWithType ¶ added in v1.3.0
func (o *ObjectValue) GetCollectionWithType(field, fhirType string) Collection
GetCollectionWithType retrieves a field as a Collection, using the FHIR type hint to properly parse string values as Date, DateTime, Time, etc.
func (*ObjectValue) IsEmpty ¶
func (o *ObjectValue) IsEmpty() bool
IsEmpty returns false for object values.
func (*ObjectValue) Keys ¶
func (o *ObjectValue) Keys() []string
Keys returns all field names in the object.
func (*ObjectValue) String ¶
func (o *ObjectValue) String() string
String returns the JSON representation.
func (*ObjectValue) ToQuantity ¶
func (o *ObjectValue) ToQuantity() (Quantity, bool)
ToQuantity attempts to convert an ObjectValue to a Quantity. This is used when the object represents a FHIR Quantity type (with fields like "value", "unit", "code", "system"). Returns the Quantity and true if successful, or zero Quantity and false if not.
func (*ObjectValue) Type ¶
func (o *ObjectValue) Type() string
Type returns the FHIR type of this object. Checks explicit type (from polymorphic resolution), then resourceType, then infers from structure.
func (*ObjectValue) TypedChildren ¶ added in v1.5.0
func (o *ObjectValue) TypedChildren(basePath string, res ElementTypeResolver) []TypedChild
TypedChildren returns the object's children with their FHIR types resolved through res, which makes the model — not structural inference — decide what each child is. A child whose type the model does not know falls back to inference, exactly like ObjectValue.Children.
basePath is this object's FHIR path (e.g. "Observation.component"); it may be empty, in which case only the object's own type is used to resolve children.
type Quantity ¶
type Quantity struct {
// contains filtered or unexported fields
}
Quantity represents a FHIRPath quantity value with a numeric value and unit.
func NewQuantity ¶
NewQuantity creates a Quantity from a string.
func NewQuantityFromDecimal ¶
NewQuantityFromDecimal creates a Quantity from a decimal value and unit.
func ParseQuantityString ¶ added in v1.5.0
ParseQuantityString converts a string to a Quantity under the rule toQuantity() states, and reports whether the string is convertible at all.
The distinction the pattern draws is between a quoted unit and a bare word. A quoted unit is a UCUM code and is taken as written. A bare word is a calendar duration keyword, so it has to be one — '1 wk' does not convert, because wk is a UCUM code that was written without its quotes, while '4 days' does.
func (Quantity) Abs ¶ added in v1.5.0
Abs returns the quantity with a non-negative value, keeping the unit.
func (Quantity) Add ¶
Add adds two quantities. Commensurable units are converted into the left operand's unit, which is also the unit of the result: 1 'g' + 500 'mg' is 1.5 'g'.
func (Quantity) Comparable ¶ added in v1.5.0
Comparable reports whether the two quantities can be compared, that is whether their units are commensurable. Quantities sharing a unit always are; otherwise both units must reduce to the same canonical unit.
func (Quantity) Compare ¶
Compare compares two quantities. Returns -1, 0, or 1 if units are compatible, or error if not. Uses UCUM normalization to compare quantities with different but compatible units. Implements the Comparable interface.
func (Quantity) ConvertTo ¶ added in v1.5.0
ConvertTo restates a quantity in another unit, reporting false when the units are not commensurable — which the specification treats as an empty result rather than an error: "24 'm'.toQuantity('kg') // empty".
func (Quantity) DivideQuantity ¶ added in v1.5.0
DivideQuantity divides two quantities, combining their units: 4 'g' by 2 'm' is 2 'g.m-1'.
func (Quantity) Equal ¶
Equal checks equality with another value. For quantities with different units, uses UCUM normalization per FHIRPath spec.
func (Quantity) Equivalent ¶
Equivalent checks equivalence with another value. For quantities, this uses UCUM normalization to compare values with different units. Per FHIRPath spec: quantities are equivalent if their canonical normalized forms are equal.
func (Quantity) MultiplyQuantity ¶ added in v1.5.0
MultiplyQuantity multiplies two quantities, combining their units: 2 'cm' by 2 'm' is 0.04 'm2'.
func (Quantity) Negate ¶ added in v1.5.0
Negate returns the quantity with its value's sign flipped, keeping the unit: a negative mass is still a mass.
func (Quantity) String ¶
String returns the string representation. String returns the quantity in FHIRPath literal notation. A UCUM unit is quoted — 1 'wk' — while a calendar duration keyword is not — 1 week — which is how the grammar distinguishes the two.
func (Quantity) Subtract ¶
Subtract subtracts two quantities. Units are handled as in Quantity.Add.
type String ¶
type String struct {
// contains filtered or unexported fields
}
String represents a FHIRPath string value.
func NewStringWithFHIRType ¶ added in v1.3.1
NewStringWithFHIRType creates a new String value with an explicit FHIR type. Used for URI subtypes (id, oid, url, uuid, code, etc.) to preserve type identity so that ofType() can discriminate between them.
func (String) Element ¶ added in v1.5.0
func (p String) Element() *ObjectValue
Element returns the FHIR element a primitive was read with, or nil when the primitive stood alone in the JSON.
func (String) Equivalent ¶
Equivalent compares strings case-insensitively with normalized whitespace.
func (String) HasElement ¶ added in v1.5.0
func (p String) HasElement() bool
HasElement reports whether any element accompanied the value.
func (String) Replace ¶
Replace returns a new String with all occurrences of old replaced by replacement.
func (String) StartsWith ¶
StartsWith returns true if the string starts with the prefix.
func (String) ToChars ¶
func (s String) ToChars() Collection
ToChars returns a collection of single-character strings.
func (String) WithElement ¶ added in v1.5.0
func (s String) WithElement(element *ObjectValue) String
WithElement returns a copy carrying the FHIR element that accompanied the value in the JSON, which is where its extensions and id live.
func (String) WithFHIRType ¶ added in v1.5.0
WithFHIRType returns a copy that reports the FHIR type it was declared with. FHIR primitives are types in their own right — a FHIR.code is not a System.String — so a value keeps the name the model gave it.
type Time ¶
type Time struct {
// contains filtered or unexported fields
}
Time represents a FHIRPath time value.
func NewTimeFromGoTime ¶
NewTimeFromGoTime creates a Time from time.Time.
func (Time) AddDuration ¶ added in v1.5.0
AddDuration shifts a time of day, wrapping around the day.
"As Time is cyclic, using arithmetic operations + or - on Time types can result in overflowing the time value, which will wrap around the beginning of the day. So adding 1 hour to @T23:30:00 will wrap around to @T00:30:00, which is consistent with the behavior of DateTime values."
A time carries no date, so only the clock units apply. Adding a day to a time of day names no value, and the specification says so: "This includes attempting to add date components to a Time."
func (Time) Compare ¶
Compare compares two times. Returns -1, 0, or 1. Implements the Comparable interface. Returns error if precisions differ and comparison is ambiguous.
func (Time) Element ¶ added in v1.5.0
func (p Time) Element() *ObjectValue
Element returns the FHIR element a primitive was read with, or nil when the primitive stood alone in the JSON.
func (Time) Equivalent ¶
Equivalent checks equivalence with another value.
func (Time) HasElement ¶ added in v1.5.0
func (p Time) HasElement() bool
HasElement reports whether any element accompanied the value.
func (Time) Millisecond ¶
func (Time) Precision ¶ added in v1.3.0
func (t Time) Precision() TimePrecision
Precision returns the time precision.
func (Time) SubtractDuration ¶ added in v1.5.0
SubtractDuration shifts a time of day backwards, wrapping around the day.
func (Time) WithElement ¶ added in v1.5.0
func (t Time) WithElement(element *ObjectValue) Time
WithElement returns a copy carrying the FHIR element that accompanied the value in the JSON, which is where its extensions and id live.
func (Time) WithFHIRType ¶ added in v1.5.0
WithFHIRType returns a copy that reports the FHIR type it was declared with. FHIR primitives are types in their own right — a FHIR.boolean is not a System.Boolean — so a value keeps the name the model gave it.
type TimePrecision ¶
type TimePrecision int
TimePrecision indicates the precision of a time.
const ( HourPrecision TimePrecision = iota MinutePrecision SecondPrecision MillisPrecision )
type TypeError ¶
TypeError represents a type mismatch error.
func NewTypeError ¶
NewTypeError creates a new TypeError.
type TypedChild ¶ added in v1.5.0
TypedChild is a child value together with the FHIR path it was reached by, so that a recursive walk (descendants()) can keep resolving types as it descends.
type Value ¶
type Value interface {
// Type returns the FHIRPath type name.
Type() string
// Equal compares exact equality (= operator).
Equal(other Value) bool
// Equivalent compares equivalence (~ operator).
// For strings: case-insensitive, ignores leading/trailing whitespace.
Equivalent(other Value) bool
// String returns a string representation of the value.
String() string
// IsEmpty indicates if this value represents empty.
IsEmpty() bool
}
Value is the base interface for all FHIRPath values.