system

package
v0.0.0-...-5b88717 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

View Source
var ErrCantBeCast = errors.New("value can't be cast to system type")
View Source
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

func Equal(lhs, rhs Any) bool

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

See https://hl7.org/fhirpath/n1/#equality

func IsPrimitive

func IsPrimitive(input any) bool

IsPrimitive evaluates to check whether or not the input is a primitive FHIR type. If so, returns true, otherwise returns false

func IsValid

func IsValid(typeName string) bool

IsValid validates whether the input string represents a valid system type name.

func TryEqual

func TryEqual(lhs, rhs Any) (bool, bool)

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.

func From

func From(input any) (Any, error)

From converts primitive FHIR types to System types. Returns the input if already a System type, and an error if the input is not convertible.

func Normalize

func Normalize(from Any, to Any) Any

Normalize casts the "from" type to the "to" type if implicit casting is supported between the types. Otherwise, it returns the from input.

type Boolean

type Boolean bool

Boolean is a representation for a true or false value.

func ParseBoolean

func ParseBoolean(input string) (Boolean, error)

ParseBoolean parses a boolean string and returns a Boolean value FHIRPath docs here: https://hl7.org/fhirpath/N1/#toboolean-boolean

func (Boolean) Equal

func (b Boolean) Equal(input Any) bool

Equal returns true if the input value is a System Boolean, and contains the same value.

func (Boolean) Less

func (b Boolean) Less(input Any) (Boolean, error)

Less returns error for Boolean comparison.

func (Boolean) Name

func (b Boolean) Name() string

Name returns the type name.

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

func DateFromProto(proto *dtpb.Date) (Date, error)

DateFromProto takes a proto Date as input and returns a system Date.

func MustParseDate

func MustParseDate(value string) Date

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

func ParseDate(value string) (Date, error)

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

func (d Date) Add(input Quantity) (Date, error)

Add returns the result of d + input. Returns an error if it is not a valid time-valued quantity.

func (Date) Equal

func (d Date) Equal(d2 Date) bool

Equal method to override cmp.Equal.

func (Date) Less

func (d Date) Less(input Any) (Boolean, error)

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) Name

func (d Date) Name() string

Name returns the type name.

func (Date) String

func (d Date) String() string

String formats the time as a date string.

func (Date) Sub

func (d Date) Sub(input Quantity) (Date, error)

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 (d Date) ToDateTime() DateTime

func (Date) ToProtoDate

func (d Date) ToProtoDate() *dtpb.Date

ToProtoDate returns a proto Date based on a system Date.

func (Date) TryEqual

func (d Date) TryEqual(input Any) (bool, bool)

TryEqual returns a bool representing whether or not the value of d is equal to input.(Date). This function may not return a value, depending on the precision of the other value; represented by the second bool return value.

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

func DateTimeFromProto(proto *dtpb.DateTime) (DateTime, error)

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

func MustParseDateTime(value string) DateTime

MustParseDateTime returns a DateTime if the string represents a valid DateTime. Otherwise, panics.

func ParseDateTime

func ParseDateTime(value string) (DateTime, error)

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

func (dt DateTime) Add(input Quantity) (DateTime, error)

Add returns the result of dt + input. Returns an error if input does not represent a valid time valued quantity.

func (DateTime) Equal

func (dt DateTime) Equal(dt2 DateTime) bool

Equal method to override cmp.Equal.

func (DateTime) Less

func (dt DateTime) Less(input Any) (Boolean, error)

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) Name

func (dt DateTime) Name() string

Name returns the type name.

func (DateTime) String

func (dt DateTime) String() string

String returns a formatted DateTime string.

func (DateTime) Sub

func (dt DateTime) Sub(input Quantity) (DateTime, error)

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

func (dt DateTime) ToProtoDateTime() *dtpb.DateTime

ToProtoDateTime returns a proto DateTime based on a system DateTime. Note that the highest precision supported by System.DateTime is Millisecond.

func (DateTime) TryEqual

func (dt DateTime) TryEqual(input Any) (bool, bool)

TryEqual returns a boolean representing whether or not the value of dt is equal to the value of dt2. Not intended to be used for cmp.Equal. The comparison is not symmetric and may cause unexpected behaviour.

type Decimal

type Decimal decimal.Decimal

Decimal represents fixed-point decimals. Must use utilities provided by "github.com/shopspring/decimal" to perform arithmetic.

func MustParseDecimal

func MustParseDecimal(str string) Decimal

MustParseDecimal converts a string into a Decimal type. If the string is not parseable it will throw a panic().

func ParseDecimal

func ParseDecimal(value string) (Decimal, error)

ParseDecimal parses a string representing a decimal, and returns an error if the input is invalid.

func (Decimal) Add

func (d Decimal) Add(input Decimal) Decimal

Add adds d to the input Decimal

func (Decimal) Div

func (d Decimal) Div(input Decimal) Decimal

Div divides d by input.

func (Decimal) Equal

func (d Decimal) Equal(input Any) bool

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) FloorDiv

func (d Decimal) FloorDiv(input Decimal) (Integer, error)

FloorDiv divides d by input and rounds down.

func (Decimal) Less

func (d Decimal) Less(input Any) (Boolean, error)

Less returns true if d is less than input.(Decimal). If input is not a Decimal, returns an error.

func (Decimal) Mod

func (d Decimal) Mod(input Decimal) Decimal

Mod computes d % input.

func (Decimal) Mul

func (d Decimal) Mul(input Decimal) Decimal

Mul multiples the two decimal values together.

func (Decimal) Name

func (d Decimal) Name() string

Name returns the type name.

func (Decimal) Round

func (d Decimal) Round(precision int32) Decimal

Round rounds a Decimal at the provided precision.

func (Decimal) String

func (d Decimal) String() string

String returns the string value from d.

func (Decimal) Sub

func (d Decimal) Sub(input Decimal) Decimal

Sub subtracts the input Decimal from d.

func (Decimal) ToProtoDecimal

func (d Decimal) ToProtoDecimal() *dtpb.Decimal

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

func ParseInteger(value string) (Integer, error)

ParseInteger parses a string into an int32 value, and returns an error if the input does not represent a valid int32.

func (Integer) Add

func (i Integer) Add(input Integer) (Integer, error)

Add adds i to the input Integer. Returns an error if the result overflows.

func (Integer) Div

func (i Integer) Div(input Integer) Decimal

Div divides i by input. Returns a Decimal.

func (Integer) Equal

func (i Integer) Equal(input Any) bool

Equal returns true if the input value is a System Integer, and contains the same int32 value.

func (Integer) FloorDiv

func (i Integer) FloorDiv(input Integer) Integer

FloorDiv divides i by input and rounds down.

func (Integer) Less

func (i Integer) Less(input Any) (Boolean, error)

Less returns true if i is less than input.(Integer). If input is not an Integer, returns an error.

func (Integer) Mod

func (i Integer) Mod(input Integer) Integer

Mod returns i % integer.

func (Integer) Mul

func (i Integer) Mul(input Integer) (Integer, error)

Mul multiplies the two integers together. Returns an error if the result overflows.

func (Integer) Name

func (i Integer) Name() string

Name returns the type name.

func (Integer) Sub

func (i Integer) Sub(input Integer) (Integer, error)

Sub subtracts the input Integer from i. Returns an error if the result overflows.

func (Integer) ToProtoInteger

func (i Integer) ToProtoInteger() *dtpb.Integer

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

func MustParseQuantity(number string, unit string) Quantity

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

func ParseQuantity(number string, unit string) (Quantity, error)

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) Add

func (q Quantity) Add(input Quantity) (Quantity, error)

Add returns q + input. Returns an error if the units are mismatched.

func (Quantity) Equal

func (q Quantity) Equal(q2 Quantity) bool

Equal method to override cmp.Equal.

func (Quantity) Less

func (q Quantity) Less(input Any) (Boolean, error)

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) Name

func (q Quantity) Name() string

Name returns the type name.

func (Quantity) Negate

func (q Quantity) Negate() Quantity

Negate returns the quantity multiplied by -1.

func (Quantity) String

func (q Quantity) String() string

String returns the quantity value formatted as a string.

func (Quantity) Sub

func (q Quantity) Sub(input Quantity) (Quantity, error)

Sub returns q - input. Returns an error if the units are mismatched.

func (Quantity) ToProtoQuantity

func (q Quantity) ToProtoQuantity() *dtpb.Quantity

ToProtoQuantity returns a proto Quantity based on a system Quantity.

func (Quantity) TryEqual

func (q Quantity) TryEqual(input Any) (bool, bool)

TryEqual returns a bool representing whether or not the value represented by q is equal to the value of q2. The comparison is not symmetric and may not return a value, represented by the second boolean being set to false.

type String

type String string

String represents string values.

func ParseString

func ParseString(input string) (String, error)

ParseString parses the input string and replaces FHIRPath escape sequences with their Go-equivalent escape characters.

func (String) Add

func (s String) Add(input String) String

Add concatenates the input String to the right of s.

func (String) Equal

func (s String) Equal(input Any) bool

Equal returns true if the input value is a System String, and contains the same string value.

func (String) Less

func (s String) Less(input Any) (Boolean, error)

Less returns true if s is less than input.(String), by lexicographic comparison. If input is not a String, returns an error.

func (String) Name

func (s String) Name() string

Name returns the type name.

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

func MustParseTime(value string) Time

MustParseTime takes an input string and returns a Time object if formatted correctly. Otherwise, panics.

func ParseTime

func ParseTime(value string) (Time, error)

ParseTime takes an input string and returns a Time object if formatted correctly according to the FHIRPath spec, otherwise an error.

func TimeFromProto

func TimeFromProto(proto *dtpb.Time) Time

TimeFromProto takes a proto Time and returns a System Time.

func (Time) Add

func (t Time) Add(input Quantity) (Time, error)

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) Equal

func (t Time) Equal(t2 Time) bool

Equal method to override cmp.Equal.

func (Time) Less

func (t Time) Less(input Any) (Boolean, error)

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) Name

func (t Time) Name() string

Name returns the type name.

func (Time) String

func (t Time) String() string

String formats the time as a time string.

func (Time) Sub

func (t Time) Sub(input Quantity) (Time, error)

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

func (t Time) ToProtoTime() *dtpb.Time

ToProtoTime returns a proto Time based on a system Time.

func (Time) TryEqual

func (t Time) TryEqual(input Any) (bool, bool)

TryEqual returns a boolean representing whether or not the value of t is equal to the value of t2. Not intended to be used for cmp.Equal. The comparison is not symmetric and may cause unexpected behaviour.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL