Documentation
¶
Overview ¶
Package types defines the FHIRPath type system.
Index ¶
- Constants
- Variables
- func PutCollection(c *Collection)
- type 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) 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
- func (d Date) Compare(other Value) (int, error)
- func (d Date) Day() int
- func (d Date) Equal(other Value) bool
- func (d Date) Equivalent(other Value) 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
- func (d Date) ToTime() time.Time
- func (d Date) Type() string
- func (d Date) Year() int
- type DatePrecision
- type DateTime
- func (dt DateTime) AddDuration(value int, unit string) DateTime
- func (dt DateTime) Compare(other Value) (int, error)
- func (dt DateTime) Day() int
- func (dt DateTime) Equal(other Value) bool
- func (dt DateTime) Equivalent(other Value) 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
- func (dt DateTime) TZOffset() int
- func (dt DateTime) ToTime() time.Time
- func (dt DateTime) Type() string
- 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 (d Decimal) Equal(other Value) bool
- func (d Decimal) Equivalent(other Value) bool
- func (d Decimal) Exp() Decimal
- func (d Decimal) Floor() Integer
- 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
- 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 (i Integer) Equal(other Value) bool
- func (i Integer) Equivalent(other Value) 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
- 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) 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
- type Quantity
- func (q Quantity) Add(other Quantity) (Quantity, error)
- func (q Quantity) Compare(other Value) (int, error)
- func (q Quantity) Divide(divisor decimal.Decimal) (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) Normalize() ucum.NormalizedQuantity
- 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 (s String) EndsWith(suffix string) bool
- func (s String) Equal(other Value) bool
- func (s String) Equivalent(other Value) 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
- type Time
- func (t Time) Compare(other Value) (int, error)
- func (t Time) Equal(other Value) bool
- func (t Time) Equivalent(other Value) 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) Type() string
- type TimePrecision
- type TypeError
- type Value
Constants ¶
const TypeNameDecimal = "Decimal"
TypeNameDecimal is the FHIRPath type name for decimal values.
Variables ¶
var EmptyCollection = Collection{}
EmptyCollection is a shared empty collection to avoid allocations.
var FalseCollection = Collection{falseBoolean}
FalseCollection is a cached collection containing false.
var TrueCollection = Collection{trueBoolean}
TrueCollection is a cached collection containing true.
Functions ¶
func PutCollection ¶
func PutCollection(c *Collection)
PutCollection returns a Collection to the pool for reuse. The collection is reset to length 0.
Types ¶
type Boolean ¶
type Boolean struct {
// contains filtered or unexported fields
}
Boolean represents a FHIRPath boolean value.
func (Boolean) Equivalent ¶
Equivalent is the same as Equal for booleans.
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) 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) Equivalent ¶
Equivalent checks equivalence with another value.
func (Date) Precision ¶
func (d Date) Precision() DatePrecision
Precision returns the date precision.
func (Date) SubtractDuration ¶
SubtractDuration subtracts a duration from the date.
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) Equivalent ¶
Equivalent checks equivalence with another 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.
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 NewDecimalFromFloat ¶
NewDecimalFromFloat creates a new Decimal from a float64.
func NewDecimalFromInt ¶
NewDecimalFromInt creates a new Decimal from an int64.
func (Decimal) Equivalent ¶
Equivalent is the same as Equal for decimals.
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.
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) 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.
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 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) 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.
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 (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) 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) Normalize ¶
func (q Quantity) Normalize() ucum.NormalizedQuantity
Normalize returns the UCUM-normalized form of this quantity.
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) Equivalent ¶
Equivalent compares strings case-insensitively with normalized whitespace.
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.
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) 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) Equivalent ¶
Equivalent checks equivalence with another value.
func (Time) Millisecond ¶
func (Time) Precision ¶ added in v1.3.0
func (t Time) Precision() TimePrecision
Precision returns the time precision.
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 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.