Skip to content
API Reference

API Reference

The github.com/gofhir/fhirpath package provides a complete FHIRPath 2.0 expression evaluator for FHIR® resources in Go. This section documents every public function, type, and interface available in the library.

Package Overview

The library is organized into two packages:

PackageImport PathDescription
fhirpathgithub.com/gofhir/fhirpathCore evaluation engine, compilation, caching, and options
typesgithub.com/gofhir/fhirpath/typesFHIRPath type system: Value, Collection, and all primitive types

Quick Navigation

Core Evaluation

  • Evaluate FunctionsEvaluate, MustEvaluate, and EvaluateCached for one-shot expression evaluation against JSON resources.
  • Compile and ExpressionCompile, MustCompile, and the Expression type for precompiling expressions and evaluating them many times.
  • Typed Evaluation – Convenience functions that return Go-native types: EvaluateToBoolean, EvaluateToString, EvaluateToStrings, Exists, and Count.

Resource Handling

  • Resource Interface – The Resource interface, EvaluateResource, EvaluateResourceCached, and ResourceJSON for evaluating Go structs directly.

Performance and Configuration

  • Expression CacheExpressionCache with LRU eviction, DefaultCache, cache statistics, and monitoring.
  • Evaluation OptionsEvalOptions, functional options (WithTimeout, WithContext, WithVariable, etc.), and the ReferenceResolver interface.

Type System

  • Types Package – The Value interface, Collection type with all its methods, and all FHIRPath primitive types (Boolean, Integer, Decimal, String, Date, DateTime, Time, Quantity, ObjectValue).

Choosing the Right Function

Use the following decision tree to pick the best entry point for your use case:

Do you have a Go struct implementing Resource?
  YES --> Do you evaluate many expressions on it?
            YES --> Use ResourceJSON (serialize once, evaluate many)
            NO  --> Use EvaluateResource / EvaluateResourceCached
  NO  --> (You have raw JSON bytes)
          Do you reuse the same expression many times?
            YES --> Use Compile + Expression.Evaluate
                    (or ExpressionCache for automatic caching)
            NO  --> Do you need a specific Go type back?
                      YES --> Use EvaluateToBoolean / EvaluateToString / Exists / Count
                      NO  --> Use Evaluate or EvaluateCached
Last updated on