Documentation
¶
Overview ¶
Package types defines the FHIRPath type system.
Index ¶
- Constants
- Variables
- func CalendarUnitForUCUMCode(code string) (string, bool)
- func CompareDecimals(a, b decimal.Decimal) int
- func EqualTemporal(left, right Value) (bool, error)
- func HoldsNoValue(v Value) bool
- func InDecimalRange(d decimal.Decimal) bool
- func InRange(v Value) bool
- func IsAbstractResourceType(fhirType string) bool
- func IsFHIRPrimitive(value Value) bool
- func IsSystemTypeName(name string) bool
- func IsTemporal(v Value) bool
- func IsUnknownTemporalComparison(err error) bool
- func IsValueless(v Value) bool
- func IsValuelessQuantity(v Value) bool
- func MoneyEqual(left, right *ObjectValue) (equal, ok bool)
- func ParseDecimal(s string) (decimal.Decimal, error)
- func PutCollection(c *Collection)
- func SecondUnitMilliseconds(value decimal.Decimal, unit string) (int, bool)deprecated
- func ShiftAmount(value decimal.Decimal, unit string, onClock bool) (amount int, shiftUnit string, err error)
- 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 GetCollection() *Collection
- func JSONToCollection(data []byte) (Collection, error)
- func JSONToCollectionWithType(data []byte, fhirType string) (Collection, error)
- func NewCollectionWithCap(capacity int) Collection
- func ReadRoot(data []byte) (Collection, error)
- func ReadRootWithType(data []byte, fhirType string) (Collection, error)
- func SingletonCollection(v Value) 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) SubsetOf(other Collection) bool
- func (c Collection) SupersetOf(other Collection) bool
- 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
- func (c Collection) Valueless() bool
- 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 (dt DateTime) EffectiveOffset() (minutes int, ok bool)
- 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) WithDefaultOffset(offset time.Duration) DateTime
- 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() Integerdeprecated
- 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() Integerdeprecated
- func (p Decimal) HasElement() bool
- func (d Decimal) ImplicitPrecision() int
- func (d Decimal) IsEmpty() bool
- func (d Decimal) IsInteger() bool
- func (d Decimal) LastPlace() int64
- 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() Integerdeprecated
- 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 ElementOrderResolver
- type ElementTypeResolver
- type EqualityIndex
- type Integer
- func (i Integer) Abs() Integerdeprecated
- func (i Integer) AbsExact() (Integer, error)
- func (i Integer) Add(other Integer) Integerdeprecated
- func (i Integer) AddExact(other Integer) (Integer, error)
- 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) Integerdeprecated
- func (i Integer) MultiplyExact(other Integer) (Integer, error)
- func (i Integer) Negate() Integerdeprecated
- func (i Integer) NegateExact() (Integer, error)
- func (i Integer) Power(exp Integer) Decimal
- func (i Integer) Sqrt() (Decimal, error)
- func (i Integer) String() string
- func (i Integer) Subtract(other Integer) Integerdeprecated
- func (i Integer) SubtractExact(other Integer) (Integer, error)
- 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) AsQuantity() (Quantity, bool, error)
- func (o *ObjectValue) Children() Collection
- func (o *ObjectValue) Data() []byte
- func (o *ObjectValue) ElementPath() string
- func (o *ObjectValue) EnableCaching()
- 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) GetChoiceCollection(name string, suffixes []string) Collection
- func (o *ObjectValue) GetChoiceCollectionWithType(name string, choiceTypes []string) Collection
- 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) Location() string
- func (o *ObjectValue) MarkPrivate()
- func (o *ObjectValue) MarkShared()
- func (o *ObjectValue) OverflowingQuantity() (Quantity, bool)
- func (o *ObjectValue) Parent() *ObjectValue
- func (o *ObjectValue) ParentField() string
- func (o *ObjectValue) QuantityBound() errordeprecated
- func (o *ObjectValue) ReadString(field string) (string, bool)
- func (o *ObjectValue) SetElementPath(path 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
- func (o *ObjectValue) Valueless() bool
- 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) EqualityUndecided(other Quantity) 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" TypeNameLong = "Long" TypeNameAny = "Any" )
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 DecimalDigits = 1000
DecimalDigits bounds this engine's decimals: at most this many digits before the decimal point, and none further than this many places after it.
FHIRPath sets a range every implementation must reach, (-10^28+1)/10^8 to (10^28-1)/10^8 with a step of 10^-8, and lets one go further; this engine goes far further, but not without end. A decimal is held exactly, so one written 1E8227822 is a number of eight million digits, and comparing or rounding it wrote them all out: half a second for each =, and more than five for round(). FHIR's own decimal allows an exponent of nine digits, so the bound is the engine's, and a value beyond it is an overflow: "Operations that cause arithmetic overflow or underflow will result in empty".
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 DivisionPlaces = 16
DivisionPlaces is the places a quotient that does not end is rounded to. The engine passes it to every division itself: shopspring's Div reads a process-wide setting a program may change (#237).
const UCUMSystem = "http://unitsofmeasure.org"
UCUMSystem identifies UCUM as the code system of a FHIR Quantity.
const UnknownQueries = -1
UnknownQueries es lo que se pasa a NewEqualityIndex cuando no se sabe cuántas preguntas vendrán.
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 ErrDecimalRange = errors.New("decimal beyond the range this engine holds")
ErrDecimalRange reports a decimal beyond DecimalDigits.
var ErrDivideByZero = errors.New("division by zero")
ErrDivideByZero reports a division whose divisor is zero, which the specification answers with empty, not an error: "12 / 0 // empty ({ })". Callers translate it into an empty collection.
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 ErrIntegerRange = errors.New("integer beyond the range this engine holds")
ErrIntegerRange reports an Integer result beyond the 64 bits this engine holds an Integer in. FHIRPath: "Operations that cause arithmetic overflow or underflow will result in empty".
var ErrInvalidTemporal = errors.New("not a date or time on the calendar and the clock")
ErrInvalidTemporal reports a date off the calendar, February 30 or month 13, a time off the clock, hour 25, or an offset no timezone has. FHIRPath's Date runs from @0001-01-01 to @9999-12-31 and its Time from @T00:00:00.000 to @T23:59:59.999; reading such a value as written and comparing it normalized, as time.Date does, made equality intransitive.
var ErrOffsetMismatch = errors.New("one temporal value specifies a timezone offset and the other does not")
ErrOffsetMismatch reports that one of two temporal values carries a timezone offset and the other does not, so there is nothing to convert the bare value into and the outcome cannot be determined.
The specification leaves this to the implementation: "For DateTime values that do not have a timezone offsets, whether or not to provide a default timezone offset is a policy decision", and "To support comparison of DateTime values, either both values have no timezone offset specified, or both values are converted to a common timezone offset." This engine provides no default, which is the reading the specification calls the simplest case, so the comparison has no answer rather than a wrong one — @2012-04-15T15:00:00Z and @2012-04-15T10:00:00 are the same instant at UTC-5 and different ones anywhere else.
It is its own sentinel rather than ErrPrecisionMismatch because the two say different things about the values: this one is reached when the precisions agree exactly, and reporting it as a precision mismatch sent anyone reading the message looking in the wrong place.
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 ErrQuantityBound = errors.New("a FHIR Quantity with a comparator is a bound, not a value")
ErrQuantityBound was reported for a FHIR Quantity with a comparator.
Deprecated: a quantity with a comparator now converts to its value, as in the HL7 validator, and nothing reports this error.
var ErrSpansOverlap = errors.New("temporal values at different offsets name overlapping spans of time")
ErrSpansOverlap reported that two temporal values written at different offsets named spans of time that overlap without being the same.
Deprecated: no comparison returns it since two values at different offsets are compared as instants, as fhirpath.js and the HL7 validator compare them; see compareTemporal. It is kept so that code naming it still compiles.
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 CompareDecimals ¶ added in v1.16.7
CompareDecimals orders two decimals exactly, as decimal.Decimal.Cmp does, a decimal beyond DecimalDigits among them. Comparing rescales one to the other's exponent, which costs the digits between them: nothing for two decimals within the bound, millions for one beyond it read from a resource, 1e5000000 against 1 (#232). So where the exponents lie far apart the sign and the place of the leading digit decide first, and only decimals that tie on both, whose exponents then lie within their own digits of each other, are rescaled.
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 HoldsNoValue ¶ added in v1.13.3
HoldsNoValue reports an object under which nothing holds a value: an element written as {}, as {"extension": [{}]}, or a resource written with nothing but its resourceType. ele-1, which every element inherits, says "All FHIR elements must have a @value or children", and such an element has neither. It is still an item of its collection, as it is in the HL7 validator, which reads it as there for every function but exists() and empty(): those answer as though it were not.
func InDecimalRange ¶ added in v1.13.0
InDecimalRange reports a decimal within DecimalDigits on either side of the point.
A zero is bounded too: 0E2000000000 is no larger than 0, but writing it out at its scale writes two billion zeroes.
func InRange ¶ added in v1.13.0
InRange reports a value whose decimal, its own or a quantity's, is within DecimalDigits; any other value is in range.
func IsAbstractResourceType ¶ added in v1.9.6
IsAbstractResourceType reports whether a declared type is one of the abstract resource types an element can hold any resource under: Bundle.entry.resource and every contained are Resource.
func IsFHIRPrimitive ¶ added in v1.10.4
IsFHIRPrimitive reports whether a value is a primitive FHIR declares rather than a System value: "FHIR.string is a different type to System.String". A FHIR primitive has the value property, and hasValue() and getValue() read it; a System value has no properties.
What tells them apart is where the value came from. One read from the resource is a FHIR primitive, whether or not a model gave it a type, and even where the model types it a System one, as R4 types Resource.id and Extension.url, whose FHIR type structuredefinition-fhir-type names; one an expression wrote, a literal, or a function computed is a System value. A value built with the constructors of this package is a System value, NewString and the rest, unless it is built with a FHIR type or an element.
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 IsUnknownTemporalComparison ¶ added in v1.8.1
IsUnknownTemporalComparison reports whether err means a comparison of two temporal values has no answer, rather than that it went wrong. The specification expresses both as an empty result, so callers translate them alike; asking through this predicate is what keeps a new one from being handled in one place and forgotten in another.
func IsValueless ¶ added in v1.13.3
IsValueless reports an item that is a primitive written with no value; see ObjectValue.Valueless.
func IsValuelessQuantity ¶ added in v1.15.1
IsValuelessQuantity reports a FHIR Quantity written without a value, its unit alone: Quantity.value is optional, and such a quantity holds no amount to compute with, as a primitive with no value holds none. Nor does one whose value is beyond DecimalDigits: the value reads, but computing with it overflows (#232).
func MoneyEqual ¶ added in v1.12.1
func MoneyEqual(left, right *ObjectValue) (equal, ok bool)
MoneyEqual compares two Money values by their amount and currency, and reports false for anything that is not a Money on both sides. A Money is no quantity, so it would otherwise compare as an object, by its JSON as written; 30 USD is 30.0 USD however each was written, and is not 30 EUR.
func ParseDecimal ¶ added in v1.13.0
ParseDecimal reads a decimal, refusing one beyond DecimalDigits.
func PutCollection ¶
func PutCollection(c *Collection)
PutCollection returns a Collection to the pool for reuse. The collection is reset to length 0.
func SecondUnitMilliseconds
deprecated
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.
Deprecated: use ShiftAmount, which reads the value without wrapping past the int range.
func ShiftAmount ¶ added in v1.13.6
func ShiftAmount(value decimal.Decimal, unit string, onClock bool) (amount int, shiftUnit string, err error)
ShiftAmount converts a time-valued quantity into the whole amount, and the unit, that AddDuration and SubtractDuration take, reading the value as a decimal, so that no amount wraps past the int range on the way: a value is whole periods of its unit, but seconds keep their fraction as milliseconds, and a week is seven days.
On a time of day, which is cyclic, a clock unit's amount is taken modulo a day: @T10:00 + 9223372036854775807 hours is @T17:00. On a date or a date-time, an amount longer than the calendar, ten thousand years in its unit, reaches past the years 1 to 9999 from any start, and is reported as the error "If the resulting year is out of range, an error is thrown" asks for. A unit that is no duration is passed through, for the shift to refuse as it does.
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 JSONToCollectionWithType ¶ added in v1.9.7
func JSONToCollectionWithType(data []byte, fhirType string) (Collection, error)
JSONToCollectionWithType converts JSON bytes to a Collection, reading the value as the FHIR type a model declares for it, as navigation reads a value it reaches: "2019-12-08" declared dateTime is a dateTime, not the Date its shape suggests, and an object declared Quantity is a Quantity. The items of an array are each read as the type. An empty fhirType reads as JSONToCollection does.
This is for a root that is an element rather than a resource — what a validator evaluates an element's invariants on.
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 ReadRoot ¶ added in v1.9.11
func ReadRoot(data []byte) (Collection, error)
ReadRoot reads a document already known to be well formed, as JSONToCollection reads one, without first scanning the whole of it for where its value ends. An object — a resource, an element — is taken as it stands when it begins with { and ends with }, and its fields are read as they are asked for; anything else is read by JSONToCollection.
That scan is what tells a malformed document, and it costs more than many evaluations do. Skipping it is only right for a document its caller has decoded or checked: one cut off after a nested object, or followed by more, would be read as far as it goes. A document that has not been checked is read with JSONToCollection.
func ReadRootWithType ¶ added in v1.9.12
func ReadRootWithType(data []byte, fhirType string) (Collection, error)
ReadRootWithType is JSONToCollectionWithType for a document already known to be well formed, as ReadRoot is JSONToCollection's: an object is read as the declared type as it stands, without first scanning the whole of it.
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) SubsetOf ¶ added in v1.16.8
func (c Collection) SubsetOf(other Collection) bool
SubsetOf reports whether every item of c is equal to some item of other.
func (Collection) SupersetOf ¶ added in v1.16.8
func (c Collection) SupersetOf(other Collection) bool
SupersetOf reports whether every item of other is equal to some item of c.
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.
func (Collection) Valueless ¶ added in v1.13.3
func (c Collection) Valueless() bool
Valueless reports a collection of a single primitive written with no value, which reads as empty wherever a value is wanted; see ObjectValue.Valueless.
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. Hours and finer units are converted to days first, truncating, since a date has no time of day: @2000-01-01 - 25 hours is @1999-12-31.
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) Equal ¶
Equal reports two temporals = finds equal, component by component, with seconds and milliseconds one precision: what union(), distinct(), in and contains test. A comparison = has no answer for, values at different precisions or an offset against none, is not equal: @2020T and @2020-01-01T00:00:00Z are two values, not one. A Date compares with a DateTime, as it converts to one; a Time with neither.
func (Date) Equivalent ¶
Equivalent is Equal: "the comparison is the same as for equality, with the exception that if the input values have different levels of precision, the result is false, rather than empty", and false is what Equal answers there, as for an offset against none. Seconds and milliseconds compare as = compares them, as the specification's examples do: @2012-01-01T10:30:31.1 ~ @2012-01-01T10:30:31 is false.
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) EffectiveOffset ¶ added in v1.9.0
EffectiveOffset returns the offset to place the value at, in minutes east of UTC, and whether there is one: the offset the value states, or the default a caller supplied for it, or neither.
This is what ordering and duration read. HasTZ and TZOffset answer the narrower question of what the value itself states.
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) Equal ¶
Equal reports two temporals = finds equal, component by component, with seconds and milliseconds one precision: what union(), distinct(), in and contains test. A comparison = has no answer for, values at different precisions or an offset against none, is not equal: @2020T and @2020-01-01T00:00:00Z are two values, not one. A Date compares with a DateTime, as it converts to one; a Time with neither.
func (DateTime) Equivalent ¶
Equivalent is Equal: "the comparison is the same as for equality, with the exception that if the input values have different levels of precision, the result is false, rather than empty", and false is what Equal answers there, as for an offset against none. Seconds and milliseconds compare as = compares them, as the specification's examples do: @2012-01-01T10:30:31.1 ~ @2012-01-01T10:30:31 is false.
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) WithDefaultOffset ¶ added in v1.9.0
WithDefaultOffset returns a copy that assumes the given offset when the value states none. A value that states its own keeps it.
This is for callers whose language settles what an unwritten offset means. FHIRPath does not: it calls the default "a policy decision", so this engine supplies none and a comparison it cannot place has no answer. CQL does settle it, and settles it at construction — "If no timezone offset is supplied, the timezone offset of the evaluation request timestamp is assumed" — so a CQL value written without an offset does not have an unknown one, it has the request's.
The default is remembered apart from what was written, and does not become part of the value. String and HasTZ answer about the value as it was written, so a literal written without an offset still evaluates to itself — which CQL requires of the same values, and which materializing the default would break. What consults the default is what needs an instant: ordering, equality, and the durations between values.
The offset is a duration so that the unit is in the call rather than in the documentation: -5 * time.Hour cannot be read as five minutes. Only offsets a timezone can have are accepted — a whole number of minutes, within the fourteen hours FHIR and XML Schema allow — and anything else leaves the value as it was, so a comparison declines rather than answering from an invented instant.
The default applies at every precision. CQL assigns the evaluation offset to a literal however far it is written — @2012T, @2012-01-01T — and to the DateTime that ToDateTime makes of a Date: "the time components unspecified, except for the timezone offset, which will be set to the timezone offset of the evaluation request timestamp" (CQL 1.5.3, Literals and ToDateTime). A value coarser than the hour has no instant of its own, but it names a span that starts at one, placed at that offset; compareTemporal reads it so.
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, refusing one beyond DecimalDigits.
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 ReadDecimal ¶ added in v1.16.7
ReadDecimal reads a decimal as a resource or a string writes it, one beyond DecimalDigits too: FHIR's decimal has no such bound, and a value read is no operation that overflows (#232). Such a value is held as written and compared exactly, but nothing computes with it: see InRange. A zero at a scale beyond the bound is taken to the nearest scale within it, keeping its text, so 0e2000 + 1 is 1, and so is a value whose places past the bound are all zeros: 1 written with 1001 zeros after the point is 1.
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, its exponent applied and never below 0: "1.0" has precision 1, "1.00" 2, "42" 0, "1.5e2" 0 and "1E-17" 17. It is LastPlace, clamped.
func (Decimal) LastPlace ¶ added in v1.16.7
LastPlace returns the place of the last digit written, counted after the point: 2 for 1.50, 0 for 150, -1 for 1.5e2, 17 for 1E-17 (#246). A value read from text answers from that text, the mantissa's places less the exponent, even past the bound, where the decoded scale is capped; the decoder refuses an exponent past int32, so this cannot overflow.
A computed value has no text, but its scale still records how many fractional digits it carries: (1.50 * 2).precision() is 2, as the HL7 validator answers.
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, writes no exponent and drops the fraction's trailing zeros, whatever a program sets in the decimal library (#237).
func (Decimal) Value ¶
Value returns the underlying decimal.Decimal value.
A decimal read from a resource may lie beyond DecimalDigits, 1e5000000 held as a coefficient and an exponent; computing with it, or writing it out with String, writes out every digit. Check InDecimalRange before computing.
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 ElementOrderResolver ¶ added in v1.11.0
ElementOrderResolver is implemented by a model that knows the order an element's definition lists its children in: for "Reference", "id", "extension", "reference", "type", "identifier", "display"; a choice element by its name with [x], "value[x]". The path is a type name or an element's path, as TypeOf takes it. It returns nil for a path it does not know.
The specification leaves the order of children() and descendants() undefined, and allows "the logical order implied by the object model", which is the order the HL7 validator returns them in. A model that does not implement it leaves them in the order the JSON writes them.
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 EqualityIndex ¶ added in v1.16.8
type EqualityIndex struct {
// contains filtered or unexported fields
}
EqualityIndex guarda elementos y responde si alguno es igual, por =, a un valor. Bajo cierto tamaño revisa los elementos, como Collection.Contains; desde ahí los reparte por una clave de igualdad, de modo que un valor se compara solo con los de su cubeta y con los que no tienen clave: ver equalityKey.
La respuesta es la misma en los dos casos: la clave solo elige a quién se pregunta, y Equal decide. Cada comparación conserva el receptor y el argumento, guardado.Equal(valor), porque = entre unidades de calendario no es simétrica (0.0833333333333333 year = 1 month, y al revés no).
Los valores guardados no deben cambiar mientras se use el índice: cada uno queda en la cubeta de la clave que tenía al entrar. Ver ObjectValue.Data.
Un índice no es seguro para varias goroutines.
func NewEqualityIndex ¶ added in v1.16.8
func NewEqualityIndex(queries int) *EqualityIndex
NewEqualityIndex crea un índice vacío, que se llena con AddIfAbsent. queries es cuántas preguntas se harán, o UnknownQueries: con menos que el umbral recorrer sale más barato que construir el índice, que cuesta una clave por elemento.
func (*EqualityIndex) AddIfAbsent ¶ added in v1.16.8
func (x *EqualityIndex) AddIfAbsent(v Value) bool
AddIfAbsent guarda v si ningún elemento guardado es igual a él, y dice si lo guardó.
func (*EqualityIndex) Contains ¶ added in v1.16.8
func (x *EqualityIndex) Contains(v Value) bool
Contains dice si algún elemento guardado es igual a v: guardado.Equal(v).
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 IntegerFromDecimal ¶ added in v1.13.5
IntegerFromDecimal reads a whole decimal as an Integer, or reports ErrIntegerRange where it lies past the int64 range. A fraction is dropped, toward zero, as decimal.IntPart drops it.
func (Integer) AbsExact ¶ added in v1.13.5
AbsExact returns the absolute value, or ErrIntegerRange for the least int64, whose absolute value lies past the range.
func (Integer) AddExact ¶ added in v1.13.5
AddExact returns the sum of two integers, or ErrIntegerRange where it lies past the int64 range.
func (Integer) Div ¶
Div returns the integer division result, or ErrIntegerRange for the one quotient past the int64 range, the least int64 divided by -1.
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 between integers.
Against a decimal it is the decimal's equivalence, at the precision of the less precise side, so that 1 ~ 1.4 answers as 1.4 ~ 1 does.
func (Integer) HasElement ¶ added in v1.5.0
func (p Integer) HasElement() bool
HasElement reports whether any element accompanied the value.
func (Integer) MultiplyExact ¶ added in v1.13.5
MultiplyExact returns the product of two integers, or ErrIntegerRange where it lies past the int64 range.
func (Integer) NegateExact ¶ added in v1.13.5
NegateExact returns the negation of the integer, or ErrIntegerRange for the least int64, whose negation lies past the range.
func (Integer) SubtractExact ¶ added in v1.13.5
SubtractExact returns the difference of two integers, or ErrIntegerRange where it lies past the int64 range.
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").
An object of a FHIR primitive's type is the element of a primitive written with no value, as a validator builds "_family" to evaluate it, and is Valueless.
func (*ObjectValue) AsQuantity ¶ added in v1.12.1
func (o *ObjectValue) AsQuantity() (Quantity, bool, error)
AsQuantity converts a FHIR Quantity as ObjectValue.ToQuantity does, and reports a value beyond the decimals this engine holds as ErrDecimalRange.
A comparator is not read: < 5 'mg' converts to 5 'mg', as in the HL7 validator, which reads the value of a quantity whatever bounds it. FHIR marks the comparator a modifier and states no FHIRPath rule for it; CONFORMANCE.md records the choice.
func (*ObjectValue) Children ¶
func (o *ObjectValue) Children() Collection
Children returns a collection of all child values.
func (*ObjectValue) Data ¶
func (o *ObjectValue) Data() []byte
Data returns the raw JSON data. The bytes are shared, not copied, and must not be modified: objects read out of them, caches and equality indexes keep what they read.
func (*ObjectValue) ElementPath ¶ added in v1.9.3
func (o *ObjectValue) ElementPath() string
ElementPath is the path of the element the object was reached as — "Claim.diagnosis" for an entry of a Claim's diagnosis — which is what a model resolves the object's own fields beneath. It is "" for an object a model did not place, and a resource needs none: its type is its path.
It belongs to the object rather than to the evaluation because it is a fact about where the object sits in the resource, which nothing evaluated before or after it changes.
func (*ObjectValue) EnableCaching ¶ added in v1.7.0
func (o *ObjectValue) EnableCaching()
EnableCaching makes the object keep the fields it reads, and the objects it reads them into keep theirs.
This is for a resource that several expressions are evaluated against, where what one expression navigates is worth keeping for the next. It trades memory for that, and an object that caches must not be read from two goroutines at once.
func (*ObjectValue) Equal ¶
func (o *ObjectValue) Equal(other Value) bool
Equal reports two objects whose children are equal, recursively, found by key wherever each object writes them: see equalJSON.
func (*ObjectValue) Equivalent ¶
func (o *ObjectValue) Equivalent(other Value) bool
Equivalent compares two objects child by child, each with the equivalence of its type, recursively: see equivalentJSON. Two Quantities compare as quantities, at any depth, as in the HL7 validator: a reference range whose low is 1 'g' is equivalent to one whose low is 1000 'mg'.
func (*ObjectValue) Get ¶
func (o *ObjectValue) Get(field string) (Value, bool)
Get retrieves a field value, caching the result.
func (*ObjectValue) GetChoiceCollection ¶ added in v1.9.2
func (o *ObjectValue) GetChoiceCollection(name string, suffixes []string) Collection
GetChoiceCollection reads the variant of a choice element the object holds — valueQuantity or valueString for value — trying the given type suffixes in order, and reads it as GetCollectionParsedAs does.
Trying each suffix as a field of its own reads the object once per suffix, and for a name the object does not hold at all, which is what most lookups of this kind are, each of those reads goes to the end of the object. This reads the keys once and tries only the suffixes found among them. The first that reads as something wins: where the object holds more than one variant, which valid FHIR never does, that is the one listed first, and a variant written as null, which holds nothing, does not hide one that holds a value.
The answer is kept under the name alone, so a caller passes the same suffixes for a name every time it asks.
func (*ObjectValue) GetChoiceCollectionWithType ¶ added in v1.9.4
func (o *ObjectValue) GetChoiceCollectionWithType(name string, choiceTypes []string) Collection
GetChoiceCollectionWithType is GetChoiceCollection for the choice types a model gives an element: each is tried as name with the type capitalized — valueString for string — in the model's order, only where the object holds that key, and read as GetCollectionWithType does.
The answer as a whole is not kept, since another model may give the element other choice types; each variant read is kept, as GetCollectionWithType keeps it, and the object's keys are read from its field index.
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.
When caching is on, the result is kept, so reading the same field again — a second expression over the same document, or a second mention of the field in one expression — costs a map lookup rather than another scan of the object. The objects read out of the field cache in turn, so the saving compounds down a path: the invariants of one resource share the whole of what they navigate.
The collection handed back cannot grow into the cached one: it is capped at its length, so appending to it copies. Its values are immutable.
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) Location ¶ added in v1.10.0
func (o *ObjectValue) Location() string
Location is where the object sits in the input it was read from, spelled from the root with the index of each item of an array:
Patient Patient.contact[1] Patient.contact[0].name Bundle.entry[0].resource.contact[2].name
Two objects with the same content are equal, and reached by the same expression they have the same ElementPath, but they do not sit in the same place. Location tells them apart, which is what checking a result against an element found some other way — a validator's own walk of the resource — takes.
The root is named by its resourceType, and a root without one, an element read as the root, by nothing: its fields are located as "given[0]". A field is named by its key as the JSON spells it, so a choice element is "Patient.deceasedBoolean", and an index counts every position of the JSON array, nulls included, so it matches the instance's own indexing rather than a FHIRPath collection's, which drops a position with neither a value nor an element.
A primitive has no location of its own. The element FHIR writes beside it under _name, which ElementOf returns, is located as the primitive is named: "Patient.name[0].given[1]" for the element of the second given, "Patient.birthDate" for what is read from _birthDate.
The location is the same however the object was reached — a path, children(), descendants(), a where() or an ofType() keeping it, resolve() to a contained resource or an entry of the same Bundle. It is "" for an object that was not read from the input: one a function made, a resource a Resolver handed back, the items of a JSON array read as the root.
A read records on the object the object it was read out of, the field and the index, in the room the struct already takes, so navigation pays nothing for them, and Location spells the path from them and the root's name, which is read once, the first time any object under the root is located. It costs the depth of the path, not the size of what holds it or where the root's resourceType is written in it, so locating every entry of a large Bundle is linear. It allocates only the string, and may be called on objects other goroutines read.
func (*ObjectValue) MarkPrivate ¶ added in v1.9.10
func (o *ObjectValue) MarkPrivate()
MarkPrivate records that only one goroutine reads the object, which lets it keep what it works out about itself — its type, the fields read through Get — instead of working them out again each time.
An object that is not private is only ever read, so a root a caller builds can be evaluated against from several goroutines at once. An object that caches is private as well. Objects read out of a private or caching one are private in turn: each is created by the read, not shared.
func (*ObjectValue) MarkShared ¶ added in v1.9.10
func (o *ObjectValue) MarkShared()
MarkShared undoes MarkPrivate: the object may be read from several goroutines from now on, so it no longer writes what it works out to itself. What it wrote while private stays, and is only read.
An evaluation marks what it returns shared: the objects it read privately are handed to a caller who may share them. An object that caches stays single-goroutine, as caching documents.
func (*ObjectValue) OverflowingQuantity ¶ added in v1.16.7
func (o *ObjectValue) OverflowingQuantity() (Quantity, bool)
OverflowingQuantity converts a FHIR Quantity whose value is beyond DecimalDigits, which AsQuantity reports as ErrDecimalRange, for what its unit alone decides (#232): the quantity holds the value as read, and nothing may compute with it.
func (*ObjectValue) Parent ¶ added in v1.12.3
func (o *ObjectValue) Parent() *ObjectValue
Parent returns the object this one was read out of, or nil for a root, an object no read created, or one a Resolver handed back. It is what resolve() walks to find where a reference is written: the resource that makes it, and in a Bundle, the entry that holds that resource.
The parent may still be held by the evaluation that read it, or read by other goroutines, and reading an object writes to it where one goroutine holds it. So Parent returns a fresh object over the parent's JSON, placed where the parent is and with nothing read, marked shared: like a result of an evaluation, it keeps nothing it reads — Get and GetCollection write nothing to it — and any goroutine may read it. A parent that caches, as the objects of a Document do, is read by one goroutine at a time by contract, and is returned itself, with what it has read.
func (*ObjectValue) ParentField ¶ added in v1.12.3
func (o *ObjectValue) ParentField() string
ParentField returns the field of Parent that holds the object, as the JSON spells it, or "" when there is no parent.
func (*ObjectValue) QuantityBound
deprecated
added in
v1.12.1
func (o *ObjectValue) QuantityBound() error
QuantityBound reported ErrQuantityBound for a FHIR Quantity with a comparator.
Deprecated: a quantity with a comparator now converts to its value, and this returns nil.
func (*ObjectValue) ReadString ¶ added in v1.12.3
func (o *ObjectValue) ReadString(field string) (string, bool)
ReadString reads a field that holds a string as the JSON writes it — an id or a version that looks like a date is still the string it is. An object that caches reads it through its cache, which keeps the string it reads; any other reads the JSON and writes nothing to itself. It reports false when the field is absent or holds something else.
func (*ObjectValue) SetElementPath ¶ added in v1.9.3
func (o *ObjectValue) SetElementPath(path string)
SetElementPath records the path of the element the object was reached as.
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.
A Money is not a quantity, and does not convert. A quantity with a comparator converts to its value, as in the HL7 validator: see ObjectValue.AsQuantity.
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.
The answer is kept: an object's data does not change, and navigation asks for the type of every object it passes — for an inferred type that means the structural checks below, each of which scans the object.
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.
func (*ObjectValue) Valueless ¶ added in v1.13.3
func (o *ObjectValue) Valueless() bool
Valueless reports the element of a primitive written with no value: an item of its collection, which navigation reaches, but one whose value is null, as the HL7 validator reads it. Where a value is wanted, in a Boolean reading, an operator or a String function, it is empty: Patient.active or false is empty on "_active": {}, not true.
One a caller builds itself is one too: NewObjectValueWithType of a primitive's type marks it, since a primitive with a value is read as its value and an object of a primitive's type is only ever the element standing for one with none. Evaluated as the root, it keeps the mark, and answers as navigation does: hasValue() false, and ele-1 failing on "_family": {"id": "x"}. The element beside a primitive that has a value is not marked: it is no item.
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 UnitOne ¶ added in v1.14.4
Equal checks equality with another value. For quantities with different units, uses UCUM normalization per FHIRPath spec. UnitOne is an Integer or a Decimal as a Quantity of unit '1', which is how one compares with a quantity: 2.0.0 makes Integer and Decimal to Quantity implicit conversions, toQuantity() giving "the default unit ('1')", and 3.0.0 gives 23 = 23 '1' and 23 ~ 23 '1' as true.
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 in the more granular of their units: "The unit of the result will be the most granular unit of either input" (2.0.0), 3 'm' + 3 'cm' is 303 'cm', and where neither is, the left operand's, as 3.0.0 chooses. A special unit, Cel or [degF], does not combine with another unit: "Attempting to operate on quantities with invalid or "special" units will result in empty", ErrIncompatibleUnits. Two in the same unit add, 1 'Cel' + 1 'Cel' being 2 'Cel', which the text leaves open.
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) EqualityUndecided ¶ added in v1.16.7
EqualityUndecided reports a pair that = has no answer for because of the bound: one value beyond it and units not alike, so that only converting one side to the other's unit decides them, and converting overflows. 1e1000 = 1e997 '10*3' is empty.
func (Quantity) Equivalent ¶
Equivalent checks equivalence with another value. As FHIRPath 3.0.0 has it, the two are expressed in the less granular of their units, then compared "on values rounded to the precision of the least precise operand", trailing zeroes carrying no precision: 4 'g' ~ 4040 'mg' (4 ~ 4.040, compared at whole grams) whichever side each stands on, and 1 year ~ 11 months.
Across a year or a month, where the calendar and UCUM have no common unit, the calendar side is read in the UCUM unit that matches it — "convert the UCUM value to the UCUM unit that matches the calendar unit" — so 1 year ~ 1 'a' and 1 year ~ 12 'mo', where = has no answer.
func (Quantity) MultiplyQuantity ¶ added in v1.5.0
MultiplyQuantity multiplies two quantities, combining their units: 2 'cm' by 2 'm' is 400 'cm2', in the operands' own units, the finer prefix where an atom carries two.
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 "ignoring case and locale, and normalizing whitespace": character by character, a letter in either case, and any whitespace character, of the Unicode White_Space class FHIRPath 3.0.0 names, for any other. "Multiple whitespace characters in sequence are not collapsed", nor are the ends trimmed: 'a b' ~ 'a\tb' is true, 'a b' ~ 'a b' and ' a' ~ 'a' false, as fhirpath.js answers. Case is set aside one character for another, by Unicode's simple folding; fhirpath.js, comparing upper case, also takes ß for SS.
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) Equal ¶
Equal reports two temporals = finds equal, component by component, with seconds and milliseconds one precision: what union(), distinct(), in and contains test. A comparison = has no answer for, values at different precisions or an offset against none, is not equal: @2020T and @2020-01-01T00:00:00Z are two values, not one. A Date compares with a DateTime, as it converts to one; a Time with neither.
func (Time) Equivalent ¶
Equivalent is Equal: "the comparison is the same as for equality, with the exception that if the input values have different levels of precision, the result is false, rather than empty", and false is what Equal answers there, as for an offset against none. Seconds and milliseconds compare as = compares them, as the specification's examples do: @2012-01-01T10:30:31.1 ~ @2012-01-01T10:30:31 is false.
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.
func SystemValue ¶ added in v1.10.4
SystemValue returns the System value a primitive holds: the same value, without the FHIR type it was read as, without the element beside it, and no longer a FHIR primitive. FHIR declares it as the primitive's value property, "the implicit value property that is actually of type System.String" for a string, so it has no id or extensions of its own. It reports false for anything else.
func WithinRange ¶ added in v1.13.0
WithinRange returns a computed value as this engine holds it, and false where it overflows. A zero at a scale beyond the bound is no overflow: it is taken to the nearest scale within it.