Skip to content

OpenConceptLab/ocl_online#452 | FHIR: $validate-code and $batch-validate-code on content the request carries - #1098

Draft
paynejd wants to merge 23 commits into
fhir-452-b-expandfrom
fhir-452-b-validate
Draft

paynejd wants to merge 23 commits into
fhir-452-b-expandfrom
fhir-452-b-validate

Conversation

@paynejd

@paynejd paynejd commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Branch fhir-452-b-validate, base fhir-452-b-expand (#1097).

Updated Dec 1: a value set carried in a request that imports a value set OCL stores is now read the same way by $validate-code and $expand.

  • The import is read through OCL's evaluation of it (core/collections/imports.py), narrowed to the code in question. The stored expansion is read as before only where nothing the request brings can change it; under version parameters that can (system-version, force-system-version and the like), the import is evaluated again under them.
  • An include of a code system and a stored value set, or of several value sets with a stored one, is answered by OCL's evaluation of the include, which intersects them release by release (Include.held_within, Include.together_say). Whether another value set of such an include leaves the answer open is judged in the releases that evaluation keeps, after the value set's exclusions.
  • A stored import's member is in each release the evaluation selected it in, and is checked against check-system-version in each.
  • A version parameter that names a version of the code system that doesn't exist is reported for a stored import as for a carried include: open on the unknown version (x-caused-by-unknown-system), where its failing reference could select the code.
  • Commits e3e7bfc8 to 45d8f960; tests in core/fhir/workspace/tests_membership.py. On this branch: pylint 10.00; the FHIR tests 1,124 OK (2 skipped), and 165 with Elasticsearch.

What it does

  • Membership (core/fhir/workspace/membership.py): whether a value set holds a code, as OCL's own evaluation answers it over the request's workspace.
  • ValueSet and CodeSystem $validate-code (core/fhir/engine/validate.py), as the HL7 Terminology Ecosystem IG sets them out: a code, a Coding or a CodeableConcept, with the version rules, display checks, and the IG's issues and message ids. core/fhir/ops/validate_code.py hands a request that carries terminology resources to the engine, as $expand does.
  • $batch-validate-code at the type level, for ValueSet and CodeSystem (core/fhir/ops/batch_validate.py):
    • Many validations in one request, POST only. The top-level inputs apply to each, and there are at most FHIR_TX_BATCH_LIMIT.
    • The capability statement leaves it out: it has no R4 OperationDefinition, and the IG's cases expect each resource type to list exactly FHIR's own operations.
  • The engine's answers are written as R4 Parameters as they come (core/fhir/adapters/r4.py).

Reading order

core/fhir/workspace/membership.py, core/fhir/engine/validate.py, core/fhir/ops/validate_code.py, core/fhir/ops/batch_validate.py, then the tests: core/fhir/engine/tests_validate.py, core/fhir/workspace/tests_membership.py, core/fhir/tests_batch_validate.py, and core/fhir/tests_stored.py's engine-over-stored cases.

What a reviewer checks

  • Membership asks OCL's evaluation, narrowed to the codes in question, and never decides it itself.
  • A request about stored content reaches the stored path as before.

What changes for existing callers

  • $validate-code with carried terminology resources is now answered for them. Before, the stored path didn't read them.
  • New: ValueSet/$batch-validate-code and CodeSystem/$batch-validate-code (POST).

Size

About 1.4k 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,313 OK, 2 skipped.
  • 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

…ate-code on content the request carries

- Membership (core.fhir.workspace.membership): whether a value set holds a code, as OCL's own
  evaluation answers it over the request's workspace. The value set's definition is read as
  $expand reads it; each include is evaluated on its own by OCL's expansion model, narrowed to the
  code asked about (ExpansionEvaluation.narrowed_to), with the value set's exclusions applied as
  OCL applies them. A value set reached by several routes is prepared once for the request.
- ValueSet and CodeSystem $validate-code (core.fhir.engine.validate) as the HL7 Terminology
  Ecosystem IG sets them out: a code, a Coding or a CodeableConcept, with the version rules,
  display checks and the IG's issues and message ids. core.fhir.ops.validate_code hands a request
  that carries terminology resources to the engine, as $expand does.
- $batch-validate-code at the type level, for ValueSet and CodeSystem (core.fhir.ops.batch_validate):
  many validations in one request, the top-level inputs applying to each, at most
  FHIR_TX_BATCH_LIMIT. POST only. The capability statement leaves it out: it has no R4
  OperationDefinition, and the IG's cases expect each resource type to list exactly FHIR's own.
- The engine's answers are written as R4 Parameters as they come.
- Tests: the engine's $validate-code, membership, batch validation, and the engine over stored
  code systems and value sets.

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

Takes #1097'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
paynejd added a commit that referenced this pull request Dec 1, 2026
…into fhir-452-b-ops

Takes #1098'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
paynejd and others added 14 commits December 1, 2026 02:32
…to fhir-452-b-validate

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

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

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

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
…to fhir-452-b-validate

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
…to fhir-452-b-validate

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
…as $expand does

A carried value set that imports a value set OCL stores: its membership now asks OCL's
evaluation of the import (core.collections.imports), narrowed to the code in question,
which is what $expand reads. The stored expansion is read as before only where nothing
the request brings can change what it holds. Where the request's version parameters can
(system-version, force-system-version and the like), the import is evaluated again under
them, so $validate-code and $expand give the same members. A coding's own version is
held only in that release, as the stored expansion is read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXgSvP7oUQhCRnPJAH
…is asked within it; a member in each release

Review fixes to e3e7bfc:
- An include of a code system and a value set OCL stores is their intersection, which
  OCL evaluates release by release. The import is now asked within that code system
  part: OCL's evaluation of the part with that import alone, narrowed to the code, as
  $expand evaluates the include. An include pinning another release than a version
  parameter names now agrees with $expand.
- An import evaluated again can hold a code in several releases: each is a member, so
  an exclusion of one release leaves the others (Workspace.held_entries).
- A row the reader finds no concept for (a reserved code's) is no member, as $expand
  lists none; it no longer reaches the validation without a concept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXgSvP7oUQhCRnPJAH
…tersect as OCL's; version checks in each release

Review fixes to 870fa43:
- An include of value sets alone takes the first one's members, each in its version,
  that the others hold there, as OCL intersects them. A stored value set after the
  first is now answered by OCL's evaluation of the include, narrowed to the code, and
  the first one's members are kept in the releases that evaluation holds the code in.
- A stored import's member is checked against check-system-version in each release
  the import's evaluation selected the code in, not only the one the answer picks, as
  $expand fails on any of them.
- A code's exact spelling is preferred within each release, so a case-insensitive
  match in another release isn't dropped (Workspace.held_entries).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXgSvP7oUQhCRnPJAH
…CL's evaluation of the include decides

Review fixes to 05da1ac. Of value sets alone, more than one and one of them stored,
OCL's evaluation of the include, narrowed to the code, now gives the members: the first
one's members, each in its version, that the others hold there, as $expand evaluates
it. A carried one is asked only whether it leaves the answer open (it may hold the code
in the first one's release though not on its own), and the first one only for its own
entry for the code. A member is no longer one release the first one's own reading
picked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXgSvP7oUQhCRnPJAH
…filter, one parity helper

From the simplification review: an evaluation's rows of a code, kept to a coding's own
version, come from one helper (held_in); the paired $expand and $validate-code test of
a carried import after a stored one uses the class's parity helper; Validation.member
takes the members it picks from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXgSvP7oUQhCRnPJAH
…settles it; its own members kept

Fixes to c72e47d from the final review check:
- Of value sets alone, more than one and one stored, the first one not holding the
  code settles it: OCL's intersection takes the first one's members, so a later one
  leaving the answer open (a fragment) can't make it a member.
- Where the first one holds the code in a release OCL's evaluation keeps, its own
  members there are the members, each with its own entry for the code (two includes
  listing the code with their own displays both count).
- A coding's wildcard version keeps the rows of the releases it matches (held_in).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXgSvP7oUQhCRnPJAH
…nswered by OCL's evaluation alone

Fixes to a236bbe from the second final review check. An include of value sets alone,
more than one and one of them stored, now has its own path (together_say): OCL's
evaluation of the include, narrowed to the code, gives the members, one from each of
its rows. The others are asked only whether they leave the answer open, and the first
one for its own entries for the code:
- a no from the first one counts only when OCL's evaluation holds nothing (a code in
  another case in a case-insensitive code system is held through the intersection);
- each member keeps the first one's entry of its own include, and is checked as a
  stored import's member is, against check-system-version in every release it's in;
- a wildcard version never keeps a row in no release (held_in).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXgSvP7oUQhCRnPJAH
…n open import keeps the answer open

Fixes to 4e50dd6 from the third final review check:
- When OCL's evaluation of the include holds the code but another value set leaves the
  answer open (an exclusion whose code system version can't be read), the answer stays
  open, as before the together path.
- When the first value set doesn't hold the code, OCL's evaluation is asked before the
  others: holding nothing settles it, so a later one isn't read at the coding's release,
  where its filter may not apply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXgSvP7oUQhCRnPJAH
paynejd and others added 6 commits December 1, 2026 14:08
…n the release kept; an unknown version reported

- Of value sets alone, more than one and one of them stored, another's open answer is
  judged in the releases OCL's evaluation keeps once the value set's exclusions apply:
  those of the members they leave, else those of the first one's members they leave.
  Each is asked about the code in those releases, so one that is open only in a release
  the intersection doesn't use (a fragment) no longer overrides OCL's evaluation and the
  value set's exclusions. $validate-code agrees with $expand.
- A stored import evaluated again whose code system a version parameter of the request
  names in a version that doesn't exist is now answered as a carried include of that
  code system is: open on the unknown version (x-caused-by-unknown-system), not "not in
  the value set".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXgSvP7oUQhCRnPJAH
…pen answers; unknown versions where they apply

Review fixes to 43d9543:
- Another value set of an intersection is asked about the code in a release OCL's
  evaluation keeps only for whether it leaves the answer open: a filter of one of its
  includes it can't apply in that release is no open answer, as OCL's evaluation of the
  include doesn't fail on it.
- When the first value set leaves the answer open, what the others leave open counts
  too, an unknown version among it, as for value sets alone that are all carried.
- An unknown version a version parameter names is reported for a stored import only
  where its own reference that failed could select the code (one naming no single code,
  or that code): a value set listing other codes says the code isn't in it, as a carried
  include listing them does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXgSvP7oUQhCRnPJAH
…their release; unknown versions through imports

Review fixes to 0456bf1:
- When the first value set of an intersection leaves the answer open, a later one not
  holding the code settles it, as when all are carried.
- A carried value set whose includes of the code system can't be at a release OCL's
  evaluation keeps is no open answer there: it no longer answers from another release.
- An unknown version a version parameter names, met through a stored value set the
  import imports, is reported where that value set's own failing reference could select
  the code, when the caller may view every value set on the route.
- Only a concept reference counts as one that could select a code, not a mapping
  reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXgSvP7oUQhCRnPJAH
…h members isn't settled by a later no

Review fixes to 535a15b:
- When the first value set of an intersection leaves the answer open with members of
  its own (an exclusion that can't say), a later one's no doesn't settle it: OCL may
  hold those members in their releases through it.
- A later value set asked about a coding's own version, when the first leaves the
  answer open, that can't apply one of its filters there is inconclusive, not an error.
- An unknown version met only through a stored value set's exclusion isn't reported:
  no member can come of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXgSvP7oUQhCRnPJAH
… flag, no sentinel

From the simplification review: an import asked about a coding's own version that
can't apply one of its filters there gives no answer (None), as the code reading it
already treats one; whether another leaves the answer open is a flag; a test compares
its two answers directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXgSvP7oUQhCRnPJAH
…ter error stands

Fix to 36ea663 from the final review check: when the first value set of an
intersection leaves the answer open, a later one asked about a coding that names no
version is in its own evaluation, so a filter of it that can't be applied fails the
request, as before; only one asked about the release a coding names is inconclusive.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXgSvP7oUQhCRnPJAH
…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
paynejd added a commit that referenced this pull request Dec 2, 2026
…into fhir-452-b-ops

Takes #1098'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