Documentation ¶
Overview ¶
Package system provides types and related utility functions for all the valid FHIRPath System types to be used for literals.
More documentation about FHIRPath System types can be found here: - http://hl7.org/fhirpath/N1/#literals
Index ¶
- Variables
- func Equal(lhs, rhs Any) bool
- func IsPrimitive(input any) bool
- func IsValid(typeName string) bool
- func TryEqual(lhs, rhs Any) (bool, bool)
- type Any
- type Boolean
- type Collection
- func (c Collection) Contains(value any) bool
- func (c Collection) IsEmpty() bool
- func (c Collection) IsSingleton() bool
- func (c Collection) ToBool() (bool, error)
- func (c Collection) ToFloat64() (float64, error)
- func (c Collection) ToInt32() (int32, error)
- func (c Collection) ToSingleton() (any, error)
- func (c Collection) ToSingletonBoolean() ([]Boolean, error)
- func (c Collection) ToString() (string, error)
- func (c Collection) TryEqual(other Collection) (bool, bool)
- type Date
- func (d Date) Add(input Quantity) (Date, error)
- func (d Date) Equal(d2 Date) bool
- func (d Date) Less(input Any) (Boolean, error)
- func (d Date) Name() string
- func (d Date) String() string
- func (d Date) Sub(input Quantity) (Date, error)
- func (d Date) ToDateTime() DateTime
- func (d Date) ToProtoDate() *dtpb.Date
- func (d Date) TryEqual(input Any) (bool, bool)
- type DateTime
- func (dt DateTime) Add(input Quantity) (DateTime, error)
- func (dt DateTime) Equal(dt2 DateTime) bool
- func (dt DateTime) Less(input Any) (Boolean, error)
- func (dt DateTime) Name() string
- func (dt DateTime) String() string
- func (dt DateTime) Sub(input Quantity) (DateTime, error)
- func (dt DateTime) ToProtoDateTime() *dtpb.DateTime
- func (dt DateTime) TryEqual(input Any) (bool, bool)
- type Decimal
- func (d Decimal) Add(input Decimal) Decimal
- func (d Decimal) Div(input Decimal) Decimal
- func (d Decimal) Equal(input Any) bool
- func (d Decimal) FloorDiv(input Decimal) (Integer, error)
- func (d Decimal) Less(input Any) (Boolean, error)
- func (d Decimal) Mod(input Decimal) Decimal
- func (d Decimal) Mul(input Decimal) Decimal
- func (d Decimal) Name() string
- func (d Decimal) Round(precision int32) Decimal
- func (d Decimal) String() string
- func (d Decimal) Sub(input Decimal) Decimal
- func (d Decimal) ToProtoDecimal() *dtpb.Decimal
- type Integer
- func (i Integer) Add(input Integer) (Integer, error)
- func (i Integer) Div(input Integer) Decimal
- func (i Integer) Equal(input Any) bool
- func (i Integer) FloorDiv(input Integer) Integer
- func (i Integer) Less(input Any) (Boolean, error)
- func (i Integer) Mod(input Integer) Integer
- func (i Integer) Mul(input Integer) (Integer, error)
- func (i Integer) Name() string
- func (i Integer) Sub(input Integer) (Integer, error)
- func (i Integer) ToProtoInteger() *dtpb.Integer
- type Quantity
- func (q Quantity) Add(input Quantity) (Quantity, error)
- func (q Quantity) Equal(q2 Quantity) bool
- func (q Quantity) Less(input Any) (Boolean, error)
- func (q Quantity) Name() string
- func (q Quantity) Negate() Quantity
- func (q Quantity) String() string
- func (q Quantity) Sub(input Quantity) (Quantity, error)
- func (q Quantity) ToProtoQuantity() *dtpb.Quantity
- func (q Quantity) TryEqual(input Any) (bool, bool)
- type String
- type Time
- func (t Time) Add(input Quantity) (Time, error)
- func (t Time) Equal(t2 Time) bool
- func (t Time) Less(input Any) (Boolean, error)
- func (t Time) Name() string
- func (t Time) String() string
- func (t Time) Sub(input Quantity) (Time, error)
- func (t Time) ToProtoTime() *dtpb.Time
- func (t Time) TryEqual(input Any) (bool, bool)
Constants ¶
This section is empty.
Variables ¶
var ( ErrTypeMismatch = errors.New("operation not defined between given types") // Date, Time, DateTime, and Quantity have special cases for equality and inequality logic // where an empty collection should be returned when their precisions/units are mismatched. ErrMismatchedPrecision = errors.New("mismatched precision") ErrMismatchedUnit = errors.New("mismatched unit") ErrIntOverflow = errors.New("operation resulted in integer overflow") )
Common errors.
var ErrCantBeCast = errors.New("value can't be cast to system type")
var ( // ErrNotConvertible is an error raised when attempting to call Collection.To* // to a type that is not convertible. ErrNotConvertible = errors.New("not convertible") )
Functions ¶
func Equal ¶
Equal compares two FHIRPath System types for equality. This uses standard equality semantics and will return true if the value should yield a value that is true, and false otherwise.
This is effectively sugar over calling:
result, ok := TryEqual(lhs, rhs) return result && ok
func IsPrimitive ¶
IsPrimitive evaluates to check whether or not the input is a primitive FHIR type. If so, returns true, otherwise returns false
func TryEqual ¶
TryEqual compares two FHIRPath System types for equality. This returns a value if and only if the comparison of the underlying System types should also yield a value, as defined in FHIRPath's equality operation.
See https://hl7.org/fhirpath/n1/#equality
For system types that define a custom "Equal" function, this will call the underlying function. For system types that define a custom "TryEqual" function this will call the underlying function. Otherwise, this will compare the raw representation instead.
Types ¶
type Any ¶
type Any interface { Name() string Less(input Any) (Boolean, error) // contains filtered or unexported methods }
Any is the root abstraction for all FHIRPath system types.
type Boolean ¶
type Boolean bool
Boolean is a representation for a true or false value.
func ParseBoolean ¶
ParseBoolean parses a boolean string and returns a Boolean value FHIRPath docs here: https://hl7.org/fhirpath/N1/#toboolean-boolean
func (Boolean) Equal ¶
Equal returns true if the input value is a System Boolean, and contains the same value.
type Collection ¶
type Collection []any
Collection abstracts the input and output type for FHIRPath expressions as a collection that can contain anything.
func (Collection) Contains ¶
func (c Collection) Contains(value any) bool
Contains returns true if the specified value is contained within this collection. This will normalize types to system-types if necessary to check for containment.
func (Collection) IsEmpty ¶
func (c Collection) IsEmpty() bool
IsEmpty is a utility function to determine if a collection is empty.
func (Collection) IsSingleton ¶
func (c Collection) IsSingleton() bool
IsSingleton is a utility function to determine if a collection is a "Singleton" collection (i.e. contains 1 value).
func (Collection) ToBool ¶
func (c Collection) ToBool() (bool, error)
ToBool converts this Collection into a Go native 'bool' type, following the logic of singleton evaluation of booleans. If this collection is empty, it returns false, if it contains more than 1 entry, it will return an error.
func (Collection) ToFloat64 ¶
func (c Collection) ToFloat64() (float64, error)
ToFloat64 converts this Collection into a Go native 'float64' type. If this collection is empty, or contains more than 1 entry, it will return an error. If the type in the collection is not a System.Integer, or something derived from a FHIR.Integer, this will raise an ErrNotConvertible.
func (Collection) ToInt32 ¶
func (c Collection) ToInt32() (int32, error)
ToInt32 converts this Collection into a Go native 'int32' type. If this collection is empty, or contains more than 1 entry, it will return an error. If the type in the collection is not a System.Integer, or something derived from a FHIR.Integer, this will raise an ErrNotConvertible.
func (Collection) ToSingleton ¶
func (c Collection) ToSingleton() (any, error)
ToSingleton evaluates a collection as a single value, returning an error if the collection contains 0 or more than 1 entry.
func (Collection) ToSingletonBoolean ¶
func (c Collection) ToSingletonBoolean() ([]Boolean, error)
ToSingletonBoolean evaluates a collection as a boolean with singleton evaluation of collection rules. Returns a collection containing a single Boolean, or empty if the input is empty.
func (Collection) ToString ¶
func (c Collection) ToString() (string, error)
ToString converts this Collection into a Go native 'string' type. If this collection is empty, or contains more than 1 entry, it will return an error. If the type in the collection is not a System.String, or something derived from a FHIR.String, this will raise an ErrNotConvertible.
func (Collection) TryEqual ¶
func (c Collection) TryEqual(other Collection) (bool, bool)
TryEqual compares this collection to the supplied collection for, comparing each entry with the corresponding entry in c2. Returns true if every entry in c1 is equivalent to that of c2. If the lengths are mismatched, returns false.
type Date ¶
type Date struct {
// contains filtered or unexported fields
}
Date represents Date values in the range 0001-01-01 to 9999-12-31 with a 1 day step size. It uses YYYY-MM-DD with optional month and day parts.
func DateFromProto ¶
DateFromProto takes a proto Date as input and returns a system Date.
func MustParseDate ¶
MustParseDate takes as input a string and returns a Date if the input is valid. Panics if the string can't be parsed.
func ParseDate ¶
ParseDate takes as input a string and returns a Date if the input is a valid FHIRPath Date string, otherwise returns an error.
func (Date) Add ¶
Add returns the result of d + input. Returns an error if it is not a valid time-valued quantity.
func (Date) Less ¶
Less returns true if the value of d is less than input.(Date). Compares component by component, and returns an error if there is a precision mismatch. If input is not a Date, returns an error.
func (Date) Sub ¶
Sub returns the result of d - input. Returns an error if the input does not represent a valid time-valued quantity.
func (Date) ToDateTime ¶
func (Date) ToProtoDate ¶
ToProtoDate returns a proto Date based on a system Date.
type DateTime ¶
type DateTime struct {
// contains filtered or unexported fields
}
DateTime represents date/time values and partial date/time values in the format YYYY-MM-DDThh:mm:ss.fff(+|-)hh:mm format.
func DateTimeFromProto ¶
DateTimeFromProto takes a proto DateTime as input and returns a System DateTime. Note that the highest precision supported by System.DateTime is Millisecond.
func MustParseDateTime ¶
MustParseDateTime returns a DateTime if the string represents a valid DateTime. Otherwise, panics.
func ParseDateTime ¶
ParseDateTime parses a string and returns a DateTime object if the string is a valid FHIRPath DateTime string, or an error otherwise.
func (DateTime) Add ¶
Add returns the result of dt + input. Returns an error if input does not represent a valid time valued quantity.
func (DateTime) Less ¶
Less returns true if the value of dt is less than input.(DateTime). Compares component by component, and returns an error if there is a precision mismatch. If input is not a Date, returns an error.
func (DateTime) Sub ¶
Sub returns the result of dt - input.(Quantity). Returns an error if the input is not a Quantity, or if it does not represent a valid time duration.
func (DateTime) ToProtoDateTime ¶
ToProtoDateTime returns a proto DateTime based on a system DateTime. Note that the highest precision supported by System.DateTime is Millisecond.
type Decimal ¶
Decimal represents fixed-point decimals. Must use utilities provided by "github.com/shopspring/decimal" to perform arithmetic.
func MustParseDecimal ¶
MustParseDecimal converts a string into a Decimal type. If the string is not parseable it will throw a panic().
func ParseDecimal ¶
ParseDecimal parses a string representing a decimal, and returns an error if the input is invalid.
func (Decimal) Equal ¶
Equal returns a bool representing whether or not the two Decimals being compared are equal. Uses the API provided by the decimal library.
func (Decimal) Less ¶
Less returns true if d is less than input.(Decimal). If input is not a Decimal, returns an error.
func (Decimal) ToProtoDecimal ¶
ToProtoDecimal returns the proto Decimal representation of decimal.
type Integer ¶
type Integer int32
Integer represents integer values in the range 0 to 2^31 - 1. Negative integers in FHIRPath are denoted with the
func ParseInteger ¶
ParseInteger parses a string into an int32 value, and returns an error if the input does not represent a valid int32.
func (Integer) Equal ¶
Equal returns true if the input value is a System Integer, and contains the same int32 value.
func (Integer) Less ¶
Less returns true if i is less than input.(Integer). If input is not an Integer, returns an error.
func (Integer) Mul ¶
Mul multiplies the two integers together. Returns an error if the result overflows.
func (Integer) Sub ¶
Sub subtracts the input Integer from i. Returns an error if the result overflows.
func (Integer) ToProtoInteger ¶
ToProtoInteger returns the proto representation of the system integer.
type Quantity ¶
type Quantity struct {
// contains filtered or unexported fields
}
Quantity type represents a decimal value along with a UCUM unit or a calendar duration keyword.
func MustParseQuantity ¶
MustParseQuantity constructs a Quantity object from a number string and unit string. Panics if the inputs do not fit into a valid Quantity.
func ParseQuantity ¶
ParseQuantity takes as input a number string and a unit string and constructs a Quantity object. Returns error if the input does not fit into a valid Quantity
func (Quantity) Less ¶
Less returns true if q is less than input.(Quantity). If the units are mismatched, returns an error. If input is not a Quantity, returns an error.
func (Quantity) ToProtoQuantity ¶
ToProtoQuantity returns a proto Quantity based on a system Quantity.
type String ¶
type String string
String represents string values.
func ParseString ¶
ParseString parses the input string and replaces FHIRPath escape sequences with their Go-equivalent escape characters.
func (String) Equal ¶
Equal returns true if the input value is a System String, and contains the same string value.
type Time ¶
type Time struct {
// contains filtered or unexported fields
}
Time represents a time of day in the range 00:00:00.000 to 23:59:59.999 with a step size of 1ms. It uses the format hh:mm:ss.fff format to parse times.
func MustParseTime ¶
MustParseTime takes an input string and returns a Time object if formatted correctly. Otherwise, panics.
func ParseTime ¶
ParseTime takes an input string and returns a Time object if formatted correctly according to the FHIRPath spec, otherwise an error.
func TimeFromProto ¶
TimeFromProto takes a proto Time and returns a System Time.
func (Time) Add ¶
Add returns the result of t with the time-valued quantity added to it. Returns an error if the Quantity does not represent a valid duration.
func (Time) Less ¶
Less returns true if the value of t is less than input.(Time). Compares component by component, and returns an error if there is a precision mismatch. If input is not a Time, returns an error.
func (Time) Sub ¶
Sub returns the result of the time-valued quantity subtracted from t. Returns an error if the Quantity does not represent a valid duration.
func (Time) ToProtoTime ¶
ToProtoTime returns a proto Time based on a system Time.