Ruby implementation of FHIRPath, the expression language used to navigate and extract data from FHIR resources. This is a port of fhirpath-py — when in doubt about behavior, naming, or edge cases, treat fhirpath-py as the reference implementation rather than re-deriving from the spec alone. fhirpath-py is itself a port of fhirpath.js (the canonical HL7 reference implementation), so fhirpath.js is the next place to check if fhirpath-py is ambiguous.
Repo scaffolding only — no evaluator code has been ported yet. lib/fhirpath.rb just defines
the Fhirpath module and Fhirpath::Error. Everything in "Planned architecture" below
describes the target design, not current code.
Mirror fhirpath-py's module boundaries; they map cleanly to a Ruby gem's lib/ layout:
| fhirpath-py | Planned Ruby equivalent | Purpose |
|---|---|---|
fhirpathpy/__init__.py (evaluate, compile) |
lib/fhirpath.rb (Fhirpath.evaluate, Fhirpath.compile) |
Public API |
fhirpathpy/parser/FHIRPath.g4 + antlr-generated parser |
lib/fhirpath/parser/ |
Grammar + parser producing an AST. No Ruby ANTLR runtime is planned by default — evaluate whether to generate a parser from the same .g4 grammar (via a build step, not committed generated code) or hand-write a recursive-descent/Parslet/Racc parser that accepts the same grammar. |
fhirpathpy/engine/nodes.py (FP_Type, FP_Quantity, FP_DateTime, ResourceNode, ...) |
lib/fhirpath/engine/nodes.rb (or one file per type under lib/fhirpath/engine/nodes/) |
FHIRPath value types (quantities, date/time with partial precision, resource wrapper) and their equals/equivalent_to/compare semantics |
fhirpathpy/engine/__init__.py (do_eval) + evaluators/ |
lib/fhirpath/engine/evaluator.rb |
AST node dispatch — walks the parsed tree and evaluates each node kind against the current context |
fhirpathpy/engine/invocations/*.py (aggregate, collections, combining, constants, datetime, equality, existence, filtering, logic, math, misc, navigation, strings, subsetting, types) |
lib/fhirpath/engine/invocations/*.rb, one file per category |
Built-in function library (where, select, first, substring, today(), ...); each category stays its own file to match fhirpath-py |
fhirpathpy/engine/util.py (get_data, parse_value, set_paths, arraify, process_user_invocation_table) |
lib/fhirpath/engine/util.rb |
Shared helpers used across the engine |
fhirpathpy/models/{dstu2,stu3,r4,r5} |
lib/fhirpath/models/{dstu2,stu3,r4,r5}.rb |
Per-FHIR-version model data (choice-type expansion, primitive extension handling) used to disambiguate polymorphic fields like Patient.deceased[x] |
Public API surface to match fhirpath-py's evaluate/compile (see its README):
Fhirpath.evaluate(resource, path, context = {}, model = nil, options = {})
Fhirpath.compile(path, model = nil, options = {}) # => callable, parses once, reusable across resourcesoptions[:user_invocation_table] should let callers override or add functions, mirroring
fhirpath-py's userInvocationTable (see its README's "User-defined functions" section).
fhirpath-py's tests/cases/*.yaml are FHIRPath-spec-section-organized YAML test cases (e.g.
5.1_existence.yaml, 6.5_boolean_logic.yaml) plus FHIR-specific cases (fhir-r4.yaml,
fhir-quantity.yaml). When porting the evaluator, port these fixtures (or write a shared
YAML-driven RSpec runner that reads an equivalent fixture format) rather than inventing a
parallel set of hand-written examples — they encode a lot of spec edge cases that are easy to
miss otherwise.
- Ruby >= 3.0,
frozen_string_literal: truein every file. - Gem name is
fhirpath-rb(matching thefhirpath-pynaming pattern) but the module is flatFhirpath, notFhirpath::Rb—rb/pyare naming suffixes on the repo/gem, not part of the API, so callers writeFhirpath.evaluate(...), notFhirpath::Rb.evaluate(...). - RSpec for tests (
spec/), RuboCop for linting (.rubocop.yml).bundle exec rakeruns both (the default Rake task) and must stay clean. - No implementation code should be added speculatively — this file describes the target shape so future work has a map, not a request to build it all now.
The maintainer typing "bump" (or "bump X.Y.Z") to Claude is standing, in-the-moment authorization for the full state-changing sequence below — commit, push, tag, push tag, and GitHub release — for that one release only. No separate confirmation is needed per step; run the whole sequence end-to-end without pausing to ask "should I push now?" etc.
Version to release:
- Plain "bump" → increment the patch version (Z in X.Y.Z) of whatever's currently in
lib/fhirpath/version.rb. - "bump X.Y.Z" (an explicit version, e.g. for a minor/major bump like
0.2.0) → set the version to exactly that string instead of incrementing.
Steps, in order:
git status— working tree must be clean and up to date withorigin/mainbefore starting. If it isn't (uncommitted changes, unrelated local commits), stop and ask rather than assuming they should be swept into the release.- Edit
lib/fhirpath/version.rbto the new version. - Run
bundle exec rake(specs + RuboCop) and confirm it's green. If parser sources aren't already built, runbundle exec rake parser:setup compilefirst (see rakelib/parser.rake). - Mandatory packaging sanity check — this is the step that was skipped before 0.1.1/0.1.2
shipped a broken native extension (the gemspec's generated-files glob had silently gone
missing and nothing caught it until a user hit a
LoadErrorin production):gem build fhirpath-rb.gemspec- Install the built
.geminto a throwaway isolatedGEM_HOME(e.g. under a scratch dir), withenv -u BUNDLE_GEMFILE -u RUBYOPTto avoid this repo's own bundler env leaking in, and withGEM_PATHpointing at a location that already hasrice/fhir_modelsinstalled (or allow network) so dependencies resolve. - From that isolated
GEM_HOME,require "fhirpath"and callFhirpath.evaluateon a trivial resource. Confirm the native extension (fhir_path_parser.bundle/.so) actually got compiled into that GEM_HOME'sextensions/dir and the require succeeds. - Clean up the scratch gem/dirs afterward. If this check fails, stop — do not tag or release a broken build; fix the gemspec/extension setup first.
git add lib/fhirpath/version.rb(plus any other files that were part of this bump, e.g. a packaging fix) and commit asBump X.Y.Z, with whatever commit attribution footer is currently in effect for the session.git push origin main.git tag -a vX.Y.Z -m "Version X.Y.Z"andgit push origin vX.Y.Z.gh release create vX.Y.Z --title "vX.Y.Z" --generate-notes— this triggers.github/workflows/release.yml, which publishes to rubygems.org via Trusted Publishing.gh run watch <run-id> --exit-status(find the run withgh run list --workflow=release.yml --limit 1) and confirm it completes successfully.- Final live-artifact check: in a scratch dir,
gem install fhirpath-rb -v X.Y.Zfrom rubygems.org (not the local build) andrequire "fhirpath"to confirm what's actually published works, not just what was built locally. - Report back: new version, release URL, and confirmation that the published gem loads.
If step 4 or 10 fails, the release is broken in the same way 0.1.1/0.1.2 were — do not consider
the release done, and do not stop at "gem pushed successfully" as the definition of success.
gem push succeeding only means RubyGems accepted the upload; it says nothing about whether
the native extension actually compiles for an installer.