Documentation ¶
Overview ¶
Package expr contains all the expression types and related logic for FHIRPath expressions.
Index ¶
- Constants
- Variables
- func EvaluateAdd(lhs, rhs system.Any) (system.Any, error)
- func EvaluateDiv(lhs, rhs system.Any) (system.Any, error)
- func EvaluateFloorDiv(lhs, rhs system.Any) (system.Any, error)
- func EvaluateMod(lhs, rhs system.Any) (system.Any, error)
- func EvaluateMul(lhs, rhs system.Any) (system.Any, error)
- func EvaluateSub(lhs, rhs system.Any) (system.Any, error)
- type ArithmeticExpression
- type AsExpression
- type BooleanExpression
- type ComparisonExpression
- type ConcatExpression
- type Context
- type EqualityExpression
- type Expression
- type ExpressionSequence
- type ExternalConstantExpression
- type FieldExpression
- type FunctionExpression
- type IdentityExpression
- type IndexExpression
- type IsExpression
- type LiteralExpression
- type NegationExpression
- type Operator
- type TypeExpression
Constants ¶
const ( Equals = "=" NotEquals = "!=" Equivalence = "~" Inequivalence = "!~" Is = "is" As = "as" And = "and" Or = "or" Xor = "xor" Implies = "implies" Lt = "<" Gt = ">" Lte = "<=" Gte = ">=" Add = "+" Sub = "-" Concat = "&" Mul = "*" Div = "/" FloorDiv = "div" Mod = "mod" )
Operator constants.
Variables ¶
var ( ErrNotSingleton = errors.New("collection is not a singleton") ErrInvalidType = errors.New("collection evaluates to incorrect type") ErrInvalidOperator = errors.New("received invalid operator") ErrToBeImplemented = errors.New("expression not yet implemented") ErrInvalidField = errors.New("invalid field") ErrConstantNotFound = errors.New("external constant not found") )
Functions ¶
func EvaluateAdd ¶
EvaluateAdd takes in two system types, and calls the appropriate Add method.
func EvaluateDiv ¶
EvaluateDiv takes in two system types, and calls the appropriate Div method.
func EvaluateFloorDiv ¶
EvaluateFloorDiv takes in two system types, and calls the appropriate FloorDiv method.
func EvaluateMod ¶
EvaluateMod takes in two system types, and calls the appropriate Mod method.
func EvaluateMul ¶
EvaluateMul takes in two system types, and calls the appropriate Mul method.
Types ¶
type ArithmeticExpression ¶
type ArithmeticExpression struct { Left Expression Right Expression Op func(system.Any, system.Any) (system.Any, error) }
ArithmeticExpression enables mathematical arithmetic operations. Includes '+', '-', '*', "/", "div", and 'mod'.
func (*ArithmeticExpression) Evaluate ¶
func (e *ArithmeticExpression) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate evaluates the two subexpressions, with respect to singleton evaluation of collections, and performs the respective additive operation.
type AsExpression ¶
type AsExpression struct { Expr Expression Type reflection.TypeSpecifier }
AsExpression enables evaluation of an "as" type expression.
func (*AsExpression) Evaluate ¶
func (e *AsExpression) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate evaluates the contained expression with respect to singleton evaluation of collections, returns the singleton if it is of the given type. Returns empty otherwise.
type BooleanExpression ¶
type BooleanExpression struct { Left Expression Right Expression Op Operator }
BooleanExpression enables evaluation of boolean expressions, including "and", "or", "xor", and "implies".
func (*BooleanExpression) Evaluate ¶
func (e *BooleanExpression) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate evaluates the subexpressions with respect to singleton evaluation of collections, and performs the respective Boolean operation.
type ComparisonExpression ¶
type ComparisonExpression struct { Left Expression Right Expression Op Operator }
func (*ComparisonExpression) Evaluate ¶
func (e *ComparisonExpression) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate evaluates the subexpressions with respect to singleton evaluation of collections, and performs the respective comparison operation.
type ConcatExpression ¶
type ConcatExpression struct { Left Expression Right Expression }
ConcatExpression enables the evaluation of a string concatenation expression.
func (*ConcatExpression) Evaluate ¶
func (e *ConcatExpression) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate evaluates the two subexpressions with respect to singleton evaluation of collections, and attempts to concatenate the two strings. Returns an error if the expressions don't resolve to strings. This differs from string addition when either collection is empty. Rather than returning empty, it will treat the empty collection as an empty string.
type Context ¶
type Context struct { Now time.Time ExternalConstants map[string]any // LastResult is required for implementing most FHIRPatch operations, since // a reference to the node before the one being (inserted, replaced, moved) is // necessary in order to alter the containing object. LastResult system.Collection // BeforeLastResult is necessary for implementing FHIRPatch delete due to an // edge-case, where deleting a specific element from a list requires a pointer // to the container that holds the list. In a path like `Patient.name.given[0]`, // the 'LastResult' will be the unwrapped list from 'given', but we need the // 'name' element that contains the 'given' list in order to alter the list. BeforeLastResult system.Collection }
Context holds the global time and external constant variable map, to enable deterministic evaluation.
func InitializeContext ¶
func InitializeContext(input system.Collection) *Context
InitializeContext returns a base context, initialized with current time and initial constant variables set.
type EqualityExpression ¶
type EqualityExpression struct { Left Expression Right Expression Not bool }
EqualityExpression allows checking equality of the two contained subexpressions. The two expressions should return comparable values when evaluated.
func (*EqualityExpression) Evaluate ¶
func (e *EqualityExpression) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate evaluates the two subexpressions, and returns true if their contents are equal, using the functionality of system.Collection.Equal. If either collection is empty, returns an empty collection.
type Expression ¶
type Expression interface {
Evaluate(*Context, system.Collection) (system.Collection, error)
}
Expression is the abstraction for all FHIRPath expressions, ie. taking in some input collection and outputting some collection.
type ExpressionSequence ¶
type ExpressionSequence struct {
Expressions []Expression
}
ExpressionSequence abstracts the flow of evaluation for compound expressions. It consists of a sequence of expressions whose outputs flow into the inputs of the next expression.
func (*ExpressionSequence) Evaluate ¶
func (s *ExpressionSequence) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate iterates through the ExpressionSequence, feeding the output of an evaluation to the next Expression.
type ExternalConstantExpression ¶
type ExternalConstantExpression struct {
Identifier string
}
ExternalConstantExpression enables evaluation of external constants.
func (*ExternalConstantExpression) Evaluate ¶
func (e *ExternalConstantExpression) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate retrieves the constant from the map located in the Context. Returns an error if the constant is not present.
type FieldExpression ¶
FieldExpression is the expression that accesses the specified FieldName in the input collection.
func (*FieldExpression) Evaluate ¶
func (e *FieldExpression) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate filters the input collections by those that contain the FieldName string, and returns the result.
type FunctionExpression ¶
type FunctionExpression struct { Fn func(*Context, system.Collection, ...Expression) (system.Collection, error) Args []Expression }
FunctionExpression enables evaluation of Function Invocation expressions. It holds the function and function arguments.
func (*FunctionExpression) Evaluate ¶
func (e *FunctionExpression) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate evaluates the function with respect to its arguments. Returns the result of the function, or an error if raised.
type IdentityExpression ¶
type IdentityExpression struct{}
IdentityExpression encapsulates the top-level expression, ie. the first step in the chain of evaluation. A no-op expression that returns itself.
func (*IdentityExpression) Evaluate ¶
func (*IdentityExpression) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate returns the input collection, without raising an error.
type IndexExpression ¶
type IndexExpression struct {
Index Expression
}
IndexExpression allows accessing of an input system.Collection's index. Contains an expression, that when evaluated, should return an integer that represents the index.
func (*IndexExpression) Evaluate ¶
func (e *IndexExpression) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate indexes the input system.Collection and returns the item located at the given index. If the index is negative or out of bounds, returns an empty collection. Raises an error if the contained expression does not evaluate to an expression, or raises an error itself.
type IsExpression ¶
type IsExpression struct { Expr Expression Type reflection.TypeSpecifier }
IsExpression enables evaluation of an "is" type expression.
func (*IsExpression) Evaluate ¶
func (e *IsExpression) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate evaluates the contained expression with respect to singleton evaluation of collections, and determines whether or not it is the given type.
type LiteralExpression ¶
LiteralExpression abstracts FHIRPath system types, that are returned from parsing literals.
func (*LiteralExpression) Evaluate ¶
func (e *LiteralExpression) Evaluate(*Context, system.Collection) (system.Collection, error)
Evaluate returns the contained literal, without raising an error. Returns an empty collection if the literal is nil, representing a Null literal.
type NegationExpression ¶
type NegationExpression struct {
Expr Expression
}
NegationExpression enables negation of number values (Integer, Decimal, Quantity).
func (*NegationExpression) Evaluate ¶
func (e *NegationExpression) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate negates the contained expression, that is evaluated with respect to singleton evaluation. If the contained value is not a number, returns an error.
type TypeExpression ¶
type TypeExpression struct {
Type string
}
TypeExpression contains the FHIR Type identifier string, to be able to filter the items in the input collection that have the given type.
func (*TypeExpression) Evaluate ¶
func (e *TypeExpression) Evaluate(ctx *Context, input system.Collection) (system.Collection, error)
Evaluate filters the messages in the input that are identified by the Type defined in the expression.