Documentation
¶
Overview ¶
Package cql provides a native CQL (Clinical Quality Language) engine for Go.
The engine parses CQL text into an AST, evaluates expressions, and supports FHIR data retrieval through pluggable data and terminology providers.
Basic usage:
engine := cql.NewEngine(
cql.WithDataProvider(myDataProvider),
cql.WithTimeout(30 * time.Second),
)
results, err := engine.EvaluateLibrary(ctx, cqlSource, patientJSON, params)
Index ¶
- type Engine
- func (e *Engine) Compile(cqlSource string) error
- func (e *Engine) EvaluateExpression(ctx context.Context, cqlSource string, expressionName string, ...) (fptypes.Value, error)
- func (e *Engine) EvaluateLibrary(ctx context.Context, cqlSource string, contextResource json.RawMessage, ...) (map[string]fptypes.Value, error)
- type ErrEvaluation
- type ErrSyntaxError
- type ErrTimeout
- type ErrTooCostly
- type EvalOption
- type Option
- func WithDataProvider(dp eval.DataProvider) Option
- func WithMaxDepth(n int) Option
- func WithMaxExpressionLen(n int) Option
- func WithMaxRetrieveSize(n int) Option
- func WithModelInfo(mi model.ModelInfo) Option
- func WithTerminologyProvider(tp eval.TerminologyProvider) Option
- func WithTimeout(d time.Duration) Option
- func WithTraceListener(tl eval.TraceListener) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the public API for the CQL engine.
func (*Engine) Compile ¶
Compile parses a CQL source string without evaluating it. Useful for syntax validation and data requirements analysis.
func (*Engine) EvaluateExpression ¶
func (e *Engine) EvaluateExpression( ctx context.Context, cqlSource string, expressionName string, contextResource json.RawMessage, params map[string]fptypes.Value, evalOpts ...EvalOption, ) (fptypes.Value, error)
EvaluateExpression parses CQL source and evaluates a single named expression. Optional EvalOption arguments allow per-call configuration (e.g., WithCallTraceListener).
func (*Engine) EvaluateLibrary ¶
func (e *Engine) EvaluateLibrary( ctx context.Context, cqlSource string, contextResource json.RawMessage, params map[string]fptypes.Value, evalOpts ...EvalOption, ) (map[string]fptypes.Value, error)
EvaluateLibrary parses and evaluates a CQL library, returning named expression results. Optional EvalOption arguments allow per-call configuration (e.g., WithCallTraceListener).
type ErrEvaluation ¶
type ErrEvaluation struct {
Cause error
}
ErrEvaluation indicates a runtime evaluation error (HTTP 422).
func (*ErrEvaluation) Error ¶
func (e *ErrEvaluation) Error() string
func (*ErrEvaluation) Unwrap ¶
func (e *ErrEvaluation) Unwrap() error
type ErrSyntaxError ¶
type ErrSyntaxError struct {
Cause error
}
ErrSyntaxError indicates a CQL parse error (HTTP 400).
func (*ErrSyntaxError) Error ¶
func (e *ErrSyntaxError) Error() string
func (*ErrSyntaxError) Unwrap ¶
func (e *ErrSyntaxError) Unwrap() error
type ErrTimeout ¶
ErrTimeout indicates the evaluation exceeded the configured timeout (HTTP 408).
func (*ErrTimeout) Error ¶
func (e *ErrTimeout) Error() string
type ErrTooCostly ¶
type ErrTooCostly struct {
Msg string
}
ErrTooCostly indicates the evaluation is too expensive (HTTP 422).
func (*ErrTooCostly) Error ¶
func (e *ErrTooCostly) Error() string
type EvalOption ¶
type EvalOption func(*evalConfig)
EvalOption configures a single evaluation call.
func WithCallTraceListener ¶
func WithCallTraceListener(tl eval.TraceListener) EvalOption
WithCallTraceListener sets a trace listener for a specific call, overriding the engine-level trace listener for that call only. This enables per-request tracing in concurrent environments.
type Option ¶
type Option func(*Engine)
Option configures the Engine.
func WithDataProvider ¶
func WithDataProvider(dp eval.DataProvider) Option
WithDataProvider sets the data provider for retrieve expressions.
func WithMaxDepth ¶
WithMaxDepth sets the maximum recursion depth for nested expressions.
func WithMaxExpressionLen ¶
WithMaxExpressionLen sets the maximum CQL source length (DoS protection).
func WithMaxRetrieveSize ¶
WithMaxRetrieveSize sets the maximum number of resources per retrieve.
func WithModelInfo ¶
WithModelInfo sets the FHIR model information.
func WithTerminologyProvider ¶
func WithTerminologyProvider(tp eval.TerminologyProvider) Option
WithTerminologyProvider sets the terminology provider for valueset checks.
func WithTimeout ¶
WithTimeout sets the per-evaluation timeout.
func WithTraceListener ¶
func WithTraceListener(tl eval.TraceListener) Option
WithTraceListener sets a trace listener for expression-level debugging. When set, OnEnter/OnExit are called for every expression evaluation, allowing construction of trace trees for debugging and profiling.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ast defines the Abstract Syntax Tree (AST) node types for CQL.
|
Package ast defines the Abstract Syntax Tree (AST) node types for CQL. |
|
Package compiler transforms CQL source text into an AST representation.
|
Package compiler transforms CQL source text into an AST representation. |
|
Package elm implements the HL7 CQL Expression Logic Model (ELM) serialization.
|
Package elm implements the HL7 CQL Expression Logic Model (ELM) serialization. |
|
Package eval implements the CQL expression evaluator.
|
Package eval implements the CQL expression evaluator. |
|
Package model provides version-agnostic FHIR model information for the CQL engine.
|
Package model provides version-agnostic FHIR model information for the CQL engine. |
|
parser
|
|
|
Package types defines CQL-specific types that extend the FHIRPath type system.
|
Package types defines CQL-specific types that extend the FHIRPath type system. |