Skip to content

OpenConceptLab/ocl_online#452 | FHIR: $expand of a value set the request carries, over OCL's own expansion - #1097

Draft
paynejd wants to merge 9 commits into
fhir-452-b-workspacefrom
fhir-452-b-expand
Draft

paynejd wants to merge 9 commits into
fhir-452-b-workspacefrom
fhir-452-b-expand

Conversation

@paynejd

@paynejd paynejd commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Branch fhir-452-b-expand, base fhir-452-b-workspace (#1096).

What it does

  • Dispatch (core/fhir/engine/operations.py): one rule decides which requests are the engine's.
    • It takes those that carry terminology resources (tx-resource, an inline valueSet) and are about a target the request carries, a FHIR built-in OCL stores no copy of, or one nobody has. Every other request goes to the stored path as before.
    • An engine answer that finds its value set is a stored one hands the request back to the stored path, with the version its rules chose.
    • Failures are OperationOutcomes with the IG's issue types and message ids, never a 5xx. An operation runs within FHIR_TX_TIME_LIMIT_MS (within_search_timeout takes its deadline).
  • The definition (core/fhir/engine/definition.py): a carried value set's compose, read and checked as the IG has it, beside OCL's evaluation of it.
  • $expand (core/fhir/engine/expand.py) is an adapter over OCL's own evaluation.
    • The request's workspace builds the value set's OCL expansion: includes, excludes and imports under the request's version parameters, with two versions of a code system kept apart. The members are the expansion's.
    • The request's own narrowing (activeOnly, excludeNotForUI, filter), paging, nesting, designations, properties and the used-* parameters are presented from it.
    • The answer is an R5-shaped ValueSet, written as R4 by core/fhir/adapters/r4.py (engine_value_set).
  • Stored $expand (core/fhir/ops/expand.py):
    • A request that carries terminology resources is the engine's, unless the value set it names is a stored one.
    • TerminologyCapabilities lists the inputs the engine reads too: all twelve of the IG's.
    • A member is shown only where a release the base shows selected it, or HEAD did. A recorded failed version check is shown by the version it used, so a 422 names nothing the base hides from its caller.

Reading order

core/fhir/engine/operations.py (the dispatch rule, and running an operation), definition.py, expand.py, then core/fhir/ops/expand.py, then the tests: core/fhir/workspace/tests.py (loading, the guard, the deadline, the kill switch, resolution, the rollback), core/fhir/engine/tests_expand.py.

What a reviewer checks

  • One model: the engine builds an OCL expansion in the workspace and only presents it. It has no evaluator of its own.
  • A request about a stored value set reaches the stored path exactly as before.

What changes for existing callers

  • ValueSet/$expand with carried terminology resources is now answered for them. Before, tx-resource was ignored, and an inline valueSet was refused as not supported.
  • With FHIR_WORKSPACE_TOGGLE off (production's fixture), a request the engine would take is a 422 not-supported.
  • A supplement carried for stored content is refused rather than ignored.

Size

About 1.8k lines of code and 1.5k of tests.

Rollback

Revert this PR and the ones after it, or turn FHIR_WORKSPACE_TOGGLE off. No migrations.

How it was tested

  • On this branch alone: pylint 10.00 (core); the FHIR, CodeSystem and ValueSet tests with Elasticsearch: 1,176 OK, 2 skipped. The workspace's tests and the engine's $expand tests are among them.
  • Its code was reviewed in the work it comes from: three Codex defect passes, a simplification review and checks of later commits on each part, and an adversarial review of who can see what, on the whole. This split was checked by building each PR's own tree and running its tests.

The series

The FHIR layer for OpenConceptLab/ocl_online#452. It is one linear series, and each PR is based on the one before:

  1. OpenConceptLab/ocl_online#452 | An expansion evaluation narrowed to some codes; an import's codes matched as a code reference matches them #1094: the end of the OCL API PRs (core changes, reviewed first)
  2. OpenConceptLab/ocl_online#452 | FHIR metadata: CapabilityStatement and TerminologyCapabilities for the Terminology Ecosystem IG #1083: capabilities
  3. OpenConceptLab/ocl_online#452 | FHIR on stored content: CodeSystem properties and filters, full $lookup, CodeSystem $subsumes #1084: stored CodeSystem properties and filters, $lookup, $subsumes
  4. OpenConceptLab/ocl_online#452 | FHIR: the request-scoped terminology engine's foundations #1095: the engine's foundations
  5. OpenConceptLab/ocl_online#452 | FHIR: carried content in OCL's own tables for one request, and the stored provider #1096: the workspace and the stored provider
  6. OpenConceptLab/ocl_online#452 | FHIR: $expand of a value set the request carries, over OCL's own expansion #1097: $expand on carried content, and dispatch
  7. OpenConceptLab/ocl_online#452 | FHIR: $validate-code and $batch-validate-code on content the request carries #1098: $validate-code and $batch-validate-code
  8. OpenConceptLab/ocl_online#452 | FHIR: $lookup, $subsumes and $translate on content the request carries #1099: $lookup, $subsumes and $translate on carried content

Each diff is its own. The last one's tree is the whole that was tested: 707 of the HL7 Terminology Ecosystem IG's 707 in-scope test cases pass (hl7.fhir.uv.tx-ecosystem 1.11.0, general mode; supplements are out of scope). The series stays in draft until the whole ships, after the OCL API PRs. As those land on master, each PR here is retargeted, never force-pushed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qV2gzsF5GhF5BwTJ6x

…est carries, over OCL's own expansion

- Dispatch (core.fhir.engine.operations): one rule decides which requests are the engine's: those
  that carry terminology resources (tx-resource, an inline valueSet), about a target the request
  carries, a FHIR built-in OCL stores no copy of, or one nobody has. Every other request goes to
  the stored path as before. An engine answer that finds its value set is a stored one hands the
  request back to the stored path, with the version its rules chose. Failures are
  OperationOutcomes with the IG's issue types and message ids, never a 5xx, and an operation runs
  within FHIR_TX_TIME_LIMIT_MS (within_search_timeout takes its deadline).
- The definition (core.fhir.engine.definition): a carried value set's compose, read and checked
  as the IG has it, beside OCL's evaluation of it.
- $expand (core.fhir.engine.expand) is an adapter over OCL's own evaluation: the request's
  workspace builds the value set's OCL expansion (includes, excludes and imports under the
  request's version parameters, two versions of a code system kept apart), and its members are the
  expansion's. The request's own narrowing (activeOnly, excludeNotForUI, filter), paging, nesting,
  designations, properties and the used-* parameters are presented from it. The answer is an
  R5-shaped ValueSet that core.fhir.adapters.r4 writes as R4.
- Stored $expand: a request that carries terminology resources is the engine's unless the value
  set it names is a stored one. TerminologyCapabilities lists the inputs the engine reads too.
  A member is shown only where a release the base shows selected it, or HEAD did, and a recorded
  failed version check is shown by the version it used, so a 422 names nothing the base hides.
- Tests: the workspace's own (loading, the guard, the deadline, the kill switch, resolution, the
  rollback), and the engine's $expand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qV2gzsF5GhF5BwTJ6x
paynejd and others added 8 commits December 1, 2026 00:39
… into fhir-452-b-expand

Takes #1096's new head, which brings in master's
#1085, #1086 and
#1082. No change to this branch's own code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWUTom6BGgjQy6oehZ
…nerous time limit, so a busy machine can't fail it

It proves each imported value set is built once, a count, but ran under the 10-second request limit and took
about 9 seconds when the machine was busy. With FHIR_TX_TIME_LIMIT_MS at 120 seconds for this test, a value set
built once for each of its routes still never finishes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWUTom6BGgjQy6oehZ
… into fhir-452-b-expand

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qX3xher9sfoCLLKrTC
… (with fhir-452-b9-valueset and phase C's storage and core) into fhir-452-b-expand

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWapJWFsFc1Xjopf9k
… into fhir-452-b-expand

Phase C's storage migrations and collections/0081 bound their lock waits; an import's stored expansion isn't read as
it is when a supplement may apply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWapJWFsFc1Xjopf9k
… into fhir-452-b-expand

An import is evaluated again only when a supplement applies to a version it used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWapJWFsFc1Xjopf9k
… into fhir-452-b-expand

The migrations bound their lock waits before their first DDL, both ways.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWapJWFsFc1Xjopf9k
… into fhir-452-b-expand

Takes #1096's new head, which brings in master
(#1089, #1109 and
#1106): REFERENCE_SEARCH_OPTIONS_TOGGLE is on in every
environment, as on master. Merged cleanly; no change to this branch's own
code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
paynejd added a commit that referenced this pull request Dec 2, 2026
…to fhir-452-b-validate

Takes #1097's new head, which brings in master
(#1089, #1109 and
#1106): REFERENCE_SEARCH_OPTIONS_TOGGLE is on in every
environment, as on master. Merged cleanly; no change to this branch's own
code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant