Skip to content

OpenConceptLab/ocl_online#798 | A ValueSet written through FHIR keeps what its compose says - #1102

Draft
paynejd wants to merge 23 commits into
fhir-452-c-corefrom
fhir-452-b9-valueset
Draft

paynejd wants to merge 23 commits into
fhir-452-c-corefrom
fhir-452-b9-valueset

Conversation

@paynejd

@paynejd paynejd commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Updated Dec 1:

Part of phase B (B-9, accepted Dec 1). API users' own writes don't change.

Ticket: OpenConceptLab/ocl_online#798 (B-9: a ValueSet written through FHIR keeps what it says).

Branch fhir-452-b9-valueset, based on fhir-452-b-codes (#1094, the end of phase B's OCL API PRs), whose evaluation rules it uses. It also merges fhir-452-b9-codesystem (#1101: FHIR updates save onto HEAD from HEAD), so the two don't conflict in core/value_sets/serializers.py. Review this PR's own commits: f751a6ad, 5a3e8147, d17066ca, ca885630, 6da68616 and e8bdd678. The two merge commits only bring in #1101's commits: 81e6f577 resolves one conflict, and 5cb0d969 has none.

The change

A FHIR ValueSet write (create or update) used to mark every include and exclude transform: resourceversions. That replaced a listed code's version, named or not, with the newest source version holding that concept version, released or not. It also dropped compose.inactive and listed codes' designations and extensions, and saved filters OCL can't apply, which then added nothing. Now:

  • Includes and excludes stay as written: no transform. A listed code keeps the version its include names, or none, so OCL's version rules pick one wherever the value set is evaluated. Only FHIR's elements of an include are read (system, version, concept, filter, valueSet).
  • compose.inactive is the collection's own rule: Collection.include_retired.
    • false leaves retired concepts out wherever the collection is evaluated: its own expansions under either rule set, and when it's evaluated again as an import.
    • An expansion's activeOnly keeps the value it was given (ExpansionParameters(..., retired_left_out=...), from Expansion.apply_parameters and its import stand-in).
    • New versions take HEAD's rule.
    • true or absent keeps OCL's default. A compose given without inactive clears the rule; an update that gives no compose keeps HEAD's.
  • A listed code's designations and extensions are kept on its reference (CollectionReference.concept_details), copied to new versions with it. The ValueSet read shows them, with compose.inactive, and reads each clause back as its own include.
  • An update's compose replaces HEAD's, in one transaction with HEAD's save. References it leaves out are removed (only references to concepts, which a compose can show), then the new ones are added. If any is refused (say, an import loop), HEAD's metadata and references are left as they were.
    • A stored reference of the same clause is kept only if it's evaluated as the update's would be (no cascade or pinned concept version, the same transform), and takes the update's display, designations and extensions. Otherwise the update's replaces it.
    • When references are removed, or the rule on retired concepts changes, HEAD's default expansion is rebuilt with its version locks.
    • An update that gives no compose leaves HEAD's references as they are.
  • Clauses that share an expression stay apart. A whole code system and the same code system intersected with a value set, or an include and an exclude, have one expression. FHIR writes keep them apart (add_references(by_clause=True), also in its duplicate check); the API's own writes dedupe by expression as before.
  • What can't be used as written is refused (400), not saved:
    • a modifier extension on the ValueSet, the compose, an include or exclude, a listed code, a designation or a filter;
    • an include or exclude with both codes and filters (FHIR R4's vsd-3), a listed code with no code, or a list that isn't one (null included);
    • a ValueSet marked SUBSETTED written back with its compose, since it shows only part of the value set's;
    • a filter with no value;
    • codes or filters with no system (core/value_sets/compose.py, compose_errors);
    • a filter OCL can't apply, as the API refuses it when the reference is added (Collection.get_reference_filter_errors).

Migration

collections/0081_value_set_compose_details (renumbered from 0079, above): two nullable columns with no default, added by a catalog update only.

Numbering: #1103 adds collections/0079 and 0080, and merges first; this one is 0081.

Production

No collection has ever been written through FHIR: 0 collections with collection_type ValueSet, active or not, and 0 references on them (read-only count, Dec 1). So no stored expansion changes.

Not in this PR

  • The FHIR layer reading stored listed-code details in $expand and $validate-code. That's a follow-up on the FHIR-layer branch. Master's stored $expand isn't changed.
  • One compose check, not two: the FHIR layer's check_definition (on the FHIR-layer branch) should call compose_errors when the branches meet.
  • A modifier extension on a CodeSystem or ConceptMap written through FHIR isn't refused yet. That's a possible next step.

Tests

  • core/value_sets/tests.py (ValueSetComposeWriteTest):
    • a listed code keeps the version its include names, or none;
    • an exclude is kept as written;
    • only FHIR's elements are read;
    • compose.inactive false is the value set's own rule, and without it retired concepts stay;
    • designations and extensions are kept and read;
    • modifier extensions, filters with no value and codes with no system are refused;
    • a filter OCL can't apply is refused.
  • Four existing tests described the old behaviour. They now check the new one:
    • a filter it can't apply was saved;
    • is-a was saved with the rules off;
    • an update kept references its compose leaves out;
    • the WHO integration test expected an include to gain a version on write.
  • core/collections/tests/tests_include_retired.py:
    • the rule under either rule set, and true or absent;
    • activeOnly keeps its value;
    • an import evaluated again keeps its own rule, and the importer's rule reaches what it imports;
    • a new version takes the rule and the details.
  • Full gate on e8bdd67, as pr.yml runs it: pylint 10.00; 4,553 tests OK (2 skipped) and 822 search-index tests OK; coverage 97%.

Review

  • Three Codex defect passes found 8, 8 and 8 findings.
    • Fixed, among them:
      • an update ignoring a corrected designation;
      • clauses of one code system read back as one;
      • HEAD's expansion left on an old inactive rule;
      • clauses that share an expression deduplicated or refused as duplicates;
      • references an update's compose leaves out kept;
      • a refused update losing HEAD's references;
      • a SUBSETTED read written back;
      • a compose without inactive keeping the old rule;
      • a cascaded API reference kept under a FHIR compose;
      • malformed lists and modifier extensions answered with server errors.
    • Accepted, with reasons on the tracking ticket:
      • the create-time filter check without the owner's namespace (the URL registry is off in production);
      • the HEAD lock not held through version creation;
      • HEAD rows for an unversioned filter clause when INTENSIONAL_REFERENCE_RESOURCE_VERSIONS_TOGGLE is off (it's on in production; a test pins the outcome);
      • a filter on a name OCL reads as a search parameter (page and the like) is skipped, not refused, unless the code system declares that property.
  • A simplification review proposed 5 cuts: 4 applied, 1 declined (it would read the old rule outside HEAD's lock).
  • A final Codex check of the later commits found 3.
    • Fixed in e8bdd67: a refused update could leave HEAD's metadata saved without its references; HEAD's save and its references now share one transaction.
    • Reverted in e8bdd67: refusing a filter by a search parameter's name, which also refused a property a code system declares with that name.
    • Accepted: a database error inside add_references under this transaction when OCL's locks toggle is off (it's on in production, where add_references already runs in one).

Rollback

Reverse migration collections/0081 (manage.py migrate collections 0080), then revert this PR. Both columns are nullable, and nothing else reads them.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH

paynejd and others added 22 commits December 1, 2026 04:36
…AD, and its new version is made from that HEAD

A FHIR CodeSystem, ValueSet or ConceptMap update (PUT) loaded the version its URL resolved, usually the latest
release, applied the resource to it and saved it over HEAD. Any HEAD field the resource doesn't carry took that
release's value, so an edit made to HEAD through the API since that release was undone by a metadata-only PUT, and so
was HEAD's own access.

Now one helper on FhirRepositorySerializerMixin does it for all three:
- update_head: HEAD is the stored HEAD with what the resource says. A private HEAD still stays private whatever a
  concurrent write does (persist_changes keep_private), and the resource's id never renames HEAD.
- as_new_version: the new version is made from that HEAD, with the resource's version and status, as the latest
  version, without HEAD's background tasks or its record of removed members.

A CodeSystem update that doesn't give a language writes a supplement's concepts in HEAD's language, which is the one
it keeps. Kept as they were: the version-exists check, concepts, references and mappings, and the supplement fields.

Tests: core/fhir/tests_updates.py, for each resource type. Three existing tests described the old behaviour (a private
release's access copied onto HEAD; a release without supplements refusing the PUT) and now check the new one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH
… schema and the access HEAD has when it's saved

- HEAD is saved with its stored validation schema as the original schema, as an API edit that sends none is. With
  None, a HEAD whose schema differs from its latest release's, and which has concepts, was revalidated to None and
  the update failed.
- The save keeps the access HEAD has once it's locked for the save (keep_access beside keep_private), so a publish
  made between the update's read of HEAD and its save isn't undone, as a make-private already wasn't.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH
…dates save onto HEAD from HEAD) into the ValueSet writes

So the two B-9 changes don't conflict in core/value_sets/serializers.py. One conflict, in
CodeSystemDetailSerializer.update: this branch kept HEAD's version_algorithm over the release's on a FHIR update; an
update that starts from HEAD keeps it already (an R4 CodeSystem doesn't carry one), so the merge takes update_head.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH
… HEAD as read for update, and queues no schema revalidation

- update_head reads HEAD FOR NO KEY UPDATE in the transaction that saves it, and applies the resource to that row, so
  an API edit committed before the update locks HEAD is the one kept, not the values read earlier.
- persist_changes takes revalidates_schema=False from a write that can't change the validation schema. A FHIR update
  can't, so it no longer queues a revalidation of HEAD's concepts, whose full-row save could undo a concurrent change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH
…s stored once written, without HEAD's member counts

- as_new_version reloads HEAD before making the version from it, so an edit made to HEAD after the update saved it
  (while concepts, references or mappings were written) gives one consistent version, not the update's values mixed
  with HEAD's.
- The new version starts with no member counts, as any new version does, so a version that isn't expanded doesn't
  show HEAD's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH
…of revalidates_schema; the ValueSet update uses as_new_version's result

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH
… what its compose says

- Includes and excludes become references as written, with no transform: a listed code keeps the version its include
  names, or none, so OCL's version rules pick one wherever the value set is evaluated. Only FHIR's elements of an
  include are read (system, version, concept, filter, valueSet).
- compose.inactive is the collection's own rule, Collection.include_retired. False leaves retired concepts out wherever
  the collection is evaluated, under either rule set and when it's evaluated again as an import, while an expansion's
  activeOnly keeps the value it was given (ExpansionParameters retired_left_out). New versions take HEAD's rule.
- A listed code's designations and extensions are kept on its reference (CollectionReference.concept_details), copied
  to new versions with it, and shown in the ValueSet read with compose.inactive.
- What can't be used as written is refused, not saved to add nothing: a modifier extension (on the compose, an
  include or exclude, a listed code or a filter), a filter with no value, codes or filters with no system
  (core.value_sets.compose.compose_errors), and a filter OCL can't apply, as the API's add-references refuses it
  (Collection.get_reference_filter_errors).
- Migration collections/0079: two nullable columns with no default (catalog-only).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH
… retired status from the update, as its released

The version is made from HEAD reloaded, so a concurrent change to HEAD's retired flag no longer reaches it: like
released, retired is the update's status, else the resolved version's. The member-count test checks each count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH
… an update keeps listed codes' details current and rebuilds HEAD for a new rule

- The read keeps each compose clause apart (ComposeValueSetField.clause_of): listed codes of one code system version
  share one include; a filter, an import or a whole code system is one of its own. An include shows its codes, filter
  and value sets together.
- An update gives a reference HEAD already has (by expression, include or exclude) the update's display, designations
  and extensions.
- An update that changes compose.inactive rebuilds HEAD's default expansion with its version locks, as a change of
  rules does, so an import that reads it reads the new rule's members.
- An update's filters are checked in its HEAD's namespace, as the API's add-references checks them.
- An import that holds a code at another version applies its own rule on retired concepts to its candidates.
- compose_errors also refuses a modifier extension on a listed code's designation, and lists or entries that aren't
  what FHIR makes them (a 400, not a server error).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH
… fixes (up to 2c4026a) into the ValueSet writes

No conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH
…HEAD's; clauses sharing an expression are kept apart

- An update that gives a compose makes HEAD's references what it says: a reference it leaves out is removed (only
  references to concepts, which a compose can show), then the new ones are added, and HEAD's default expansion is
  rebuilt with its version locks, since a removal also takes members kept references have and keeps what an
  exclusion took. The rule on retired concepts it compares is HEAD's as read for update.
- Collection.add_references(by_clause=True), from FHIR writes only, keeps references that differ only in including
  or excluding, or in the value sets they intersect with, apart (CollectionReference.clause_key): their expression
  doesn't say either. The API's own writes dedupe by expression as before.
- A listed code gives the parser its code and display only, so an OCL key such as resource_version isn't read.
- Refused: a modifier extension on the ValueSet itself, a modifierExtension that isn't a list of objects, and an
  include or exclude with both codes and filters (FHIR R4's vsd-3).
- The WHO integration test no longer expects an include to gain a version on write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH
…HEAD's in one transaction, and refuses what it can't keep as written

- HEAD's references are replaced in one transaction: a refusal of any new one (say, an import loop) leaves HEAD's
  references and members as they were. Those left out go first, so a clause added back differently doesn't meet the
  one it replaces.
- A stored reference of the same clause is kept only if it's evaluated as the update's would be (no cascade or pinned
  concept version, the same transform); otherwise the update's replaces it.
- add_references(by_clause=True) also checks for a reference already there by clause (Collection.validate), so two
  includes that share an expression and differ in their value sets are both kept.
- A compose given is the value set's rule on retired concepts: one without inactive clears it. An update that gives no
  compose keeps HEAD's.
- Refused: a ValueSet marked SUBSETTED written back with its compose (it shows only part of the value set's); a listed
  code with no code; a concept, filter or valueSet list given as null; a filter on a search parameter (page, limit
  and the like), which a reference ignores.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH
… guards, one test for a listed code's version, one builder of an evaluation's parameters

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH
…'s metadata and references as they were

- HEAD's save and the replacement of its references run in one transaction, under HEAD's lock, so a refused reference
  rolls back both: HEAD keeps its rule on retired concepts with the members built under it.
- A filter's property is no longer refused for naming a search parameter: a code system may declare a property of
  that name, and a reference already skips the search parameter otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXBZMHpxmJnf6SMKTH
…o fhir-452-b9-valueset

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qX3xher9sfoCLLKrTC
…d reserved code spaces in OCL's model, on fhir-452-b-codes) into fhir-452-b9-valueset

One conflict, in core/collections/models.py: both add a Collection field after locked_date (include_retired here,
declared_supplements there) and copy it to new versions. Both are kept. The migration numbers meet next: this branch's
collections/0079 is renumbered in the following commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWapJWFsFc1Xjopf9k
…ompose_details to 0081, after phase C's 0079 and 0080

Phase C's storage (fhir-452-c-storage) merges first with collections/0079_supplements and 0080_expansion_reserved_codes,
so this branch's migration becomes 0081 and depends on 0080. Its operations are unchanged; the migration graph stays
linear.

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

The storage migrations now bound their lock waits, and 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
…s, as phase C's storage migrations do

It first sets lock_timeout (5s) in its own transaction, both ways: behind a long transaction on collection_references or
collections, it fails in seconds and changes nothing, instead of holding its locks, and every query queued behind
them, until that transaction ends. Its operations are otherwise unchanged.

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

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
… fhir-452-b9-valueset

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWapJWFsFc1Xjopf9k
…s before its first DDL, both ways

As phase C's storage migrations now do: a forward-only first operation and a reverse-only last one set lock_timeout,
since a reversed migration runs its operations last first.

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

Takes #1104'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-capabilities

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