Skip to content

OpenConceptLab/ocl_online#452 | An expansion evaluation narrowed to some codes; an import's codes matched as a code reference matches them - #1094

Open
paynejd wants to merge 149 commits into
fhir-452-b-importsfrom
fhir-452-b-codes
Open

paynejd wants to merge 149 commits into
fhir-452-b-importsfrom
fhir-452-b-codes

Conversation

@paynejd

@paynejd paynejd commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Merge this after #1091, and only once we've pushed here again. When #1091 is squashed into master, this branch conflicts with master. We'll then test and push an updated head, and take this line out.

How to read this PR for now (Dec 4): GitHub shows 69 changed files until #1088, #1087, #1090, #1103, #1092 and #1093 are on master, because this branch already contains them. Its own change is 15 files, about 1,570 lines added, 1,140 of them tests.

  • The command that shows it (after git fetch): git diff 9b6a388a 66f5e54b -- core/collections core/concepts. That's 12 files, with nothing from another PR in them. The other three are in core/fhir, and all of their change is in two commits: git show 76e0390f ca66dbe9.
  • Or read it in the order it was written, each part described below:
    1. c8ae51de..58ff6e46, twelve commits, one at a time: an evaluation narrowed to some codes.
    2. git diff 2eb51e93 2f872769: what's answered about a reference outside a build.
    3. git show 76e0390f ca66dbe9: a fast $expand of an expansion that keeps versions apart.
    4. git diff 8df7fc72 66f5e54b: two corrections to locks.

This note goes once those PRs are on master and this branch has merged it.


Added Dec 4: $expand of an expansion that keeps versions apart is fast enough for a large one. Commits 76e0390f and ca66dbe9, in core/fhir/ops/expand.py and one option in core/fhir/search.py, with their tests. Review them on their own.

  • Why here: OpenConceptLab/ocl_online#452 | Two versions of one source kept apart, behind the per-evaluation switch #1090 keeps versions apart under FHIR's rules, and stored $expand reads what it kept. This has to be in place before the rules are switched on, and it was written for a later draft (OpenConceptLab/ocl_online#452 | FHIR: $expand of a value set the request carries, over OCL's own expansion #1097).

  • What was slow: Expander.entries() found what to list by comparing each of the expansion's rows with the others in SQL, three times a request.

  • Now: the rows the caller is shown, and what selected each, are read once, in plain statements, and compared in Python. The total, the page, activeOnly, filter and used-codesystem all come from those.

  • One snapshot: an $expand now reads the database as it was at one moment (REPEATABLE READ, for its own transaction only). Without it, a row saved between the two reads was listed without what selected it.

  • One answer changes: a member selected at HEAD, and also in a release the caller isn't shown, is now listed as HEAD's. Before, it was left out. The new answer is right because HEAD's selection is enough to make it a member, and what a hidden release selected must not change what the caller gets. A member only hidden releases selected is still left out.

  • Otherwise unchanged: an expansion that doesn't keep versions apart is listed as before, from one snapshot, and no other operation changes.

  • Times: seconds for count=0 / count=10 / count=10 with a text filter, on PostgreSQL 14.7 with JIT off and work_mem 4 MB, data in memory. A request may take 5 s; the times before were measured with that limit raised.

    Members selected at HEAD:

    Members Before Now
    5,000 2.2 / 3.2 / 2.4 0.2 / 0.2 / 0.2
    38,363 4.2 / 5.4 / 15.6 1.0 / 0.9 / 1.4
    110,000 6.9 / 9.1 / 14.3 1.9 / 2.0 / 3.0

    Members selected in two releases each:

    Members Before Now
    5,000 1.5 / 2.2 / 1.1 0.1 / 0.1 / 0.1
    38,363 3.6 / 4.8 / 11.4 0.3 / 0.4 / 0.8
    110,000 7.3 / 9.4 / 15.3 1.2 / 1.2 / 2.2
  • Tests: every way HEAD, a live, a private, a deleted, a draft and a retired release can have selected a member, for three callers; a hidden release that changes no answer and no statement; 1,000 members kept apart answered in time where PostgreSQL has recorded the tables as empty; a row saved by another connection between the two reads. They fail on the code before.

  • Full gate on 66f5e54b, with the next change too, as pr.yml runs it: pylint 10.00; 4,777 tests OK (2 skipped) and 822 search-index tests OK; coverage 97%. With the branches above it, the HL7 Terminology Ecosystem IG's 707 in-scope tests still pass.

  • Compared with the OCL API on two large value sets (38,363 and 38,364 members) built under FHIR's rules: $expand lists exactly the API's members.

Also added Dec 4: two small corrections to how locks behave under FHIR's rules. With the switch off, nothing changes. Review git diff 8df7fc72 66f5e54b on its own: 7edf4d68 and 6fb39e7a are the changes, and 66f5e54b corrects both after review. About 70 lines of code and 160 of tests.

  • A rebuild for the rules drops the version locks no reference uses (Expansion.add_references). Some older expansions recorded two versions of one source. The first edit under the rules that touches that source rebuilds the expansion, and every reference takes the newer version. The older one stayed recorded, though. So health still said the source is recorded twice, and resolved-repo-updates offered a move that had already been made. Value set locks are treated the same way. A lock a reference still uses stays, and so does one that only references to concept or mapping versions were found by, unless other references took another version of its source.
  • Only a deleted version's lock falls back (Expansion.system_versions_that_fall_back). This is the open point from the second review of OpenConceptLab/ocl_online#452 | Version rules in OCL's core: wildcards, a declared version algorithm and the version parameters, behind the per-evaluation switch #1087.
    • What was wrong: HEAD's system-version names a version that never existed, so under the rules HEAD has no members for it. A release made with the lock fell back to the latest version, and had members HEAD never had.
    • Now: the release leaves unresolved what HEAD leaves unresolved, when it's created and at each rebuild. An entry whose version was deleted still falls back, and so does one HEAD itself fell back for, as it was built without the rules.
    • Why it doesn't read deleted_locked_repo_versions: a rebuild clears that field, so the second rebuild after a deletion would have emptied the release. It reads what the last build left unresolved, which lasts.
    • A choice: a release has what its HEAD has, even when that's nothing. So if the version was deleted and HEAD was rebuilt under the rules since, HEAD has no members for that entry, and a release made from it has none either.
  • Tests: they fail on the code before, or on a version of the fix that reads only the deleted locks. They cover a deletion before and after the release, two and three rebuilds in a row, a HEAD built without the rules, an imported value set the same entry reaches, a wildcard entry, and a release evaluated again for a value set that imports it.

Updated Dec 2: one more change, about 120 lines of core code and 530 of tests, and it comes first here because it's the part to read closely: what OCL answers about a reference outside a build follows the version parameters its build applies. Review git diff 2eb51e93 2f872769 on its own: six commits, b5053aae (the change) and five from its review.

  • Why: under FHIR's rules, a build evaluates each reference in the version the expansion's parameters give it (force-system-version above all, from OpenConceptLab/ocl_online#452 | Version rules in OCL's core: wildcards, a declared version algorithm and the version parameters, behind the per-evaluation switch #1087). Answers given outside a build asked the version the reference names instead. So adding a reference could be refused with a 400 for a filter its build would apply, and a conversion's preview could say keeps_members and the conversion then drop the member.
  • What follows the parameters now:
    • the filter check on adding references;
    • the preview of a reference;
    • the preview and confirmation of a conversion (repo_version is the version it's evaluated in, and chosen_by can be parameter);
    • the references a cascade and transform saves;
    • resolved_repo_versions, /resolve/, member health and the source distribution, which name the version the last build used.
  • How: CollectionReference.resolve_system_version, which a build never asks, is what the collection's default expansion would give the reference (version_rule, by VersionRules). own_system_version is the old code, and it's what a build asks. What an expansion recorded is read by Expansion.get_source_versions_given.
  • One change in the build, under FHIR's rules only: adding to an auto-generated expansion that has version parameters evaluates the reference again, so its members and the versions it records agree.
  • With the switch off, nothing changes, and core/collections/tests/tests_version_answers.py checks each answer with it off as well as on.
  • Already right: resolved-repo-updates (it used VersionRules), the check for value set loops, and a reference's translation, which only words what the reference says.
  • Not covered:
    • The preview of a reference to a value set reads the value set's stored expansion. A build may evaluate it again under the parameters, and reads it by version.
    • An expansion doesn't record versions per reference, so when references to one source were built in two releases, the resolved versions name both.
    • The staff-run rebuild_expansion_version_lists doesn't know the version parameters.
  • Review: three Codex passes, a simplification review and three checks of the later commits. Every finding is fixed with a test that failed before it, or accepted with a reason.

Branch fhir-452-b-codes, base fhir-452-b-imports (#1091). The last of the OCL API PRs for OpenConceptLab/ocl_online#452 (phase B, one expansion model for the OCL API and FHIR).

Commits to review

Besides the change above: twelve commits, about 400 lines with their tests. Review c8ae51de..58ff6e46 one commit at a time: the first six are the changes, and the last six came from the review loop.

  1. f990fd0b A test stand-in takes the further argument. OpenConceptLab/ocl_online#452 | $cascade walks a level at a time and a cut walk keeps the nearest entries; reference filters with FHIR's operators matched in the database, behind the switch #1088 gives CollectionReference._apply_filters a further argument, so the stand-in that OpenConceptLab/ocl_online#452 | Two versions of one source kept apart, behind the per-evaluation switch #1090's exclusion test patches in takes it too.
  2. ead0b58d An expansion evaluation can be narrowed to some codes.
    • ExpansionEvaluation.narrowed_to(codes) opens a block in which each reference evaluated under it selects only its concepts with one of those codes. A reference's concept query does this in CollectionReference.narrow_to_evaluation_codes; references to one code do it in CodeReferenceBatch.
    • So asking whether a few codes are members of a value set never reads or writes the whole of a source. FHIR's $validate-code on a value set a request carries is the one caller, later in the series.
  3. 59d8686a A request-time import is kept by the codes its evaluation is narrowed to, so one narrowed to other codes, or to none, is never read from the other's cache.
  4. 4c5d4ddc A test: outside a request, a private import evaluated again is viewed by its importing reference's creator.
  5. ecff63cf An import's code is found in a source version as a code reference finds it there. In a source that isn't case-sensitive, and under FHIR's rules, that means exact first, else in any case.
  6. ec2954ad Two concept-model changes, moved here from the FHIR PR OpenConceptLab/ocl_online#452 | FHIR on stored content: CodeSystem properties and filters, full $lookup, CodeSystem $subsumes #1084, so no core change ships only inside a FHIR PR:
    • Concept.get_property_value(code): the value a concept's properties list gives one property, factored out of that list (unchanged output; the one exception is an extra stored as the list's own internal marker string). FHIR's CodeSystem properties and filters read one property without building the list.
    • get_level_hierarchy_ids reads a HEAD row's latest version from a hierarchy_latest_version_id annotation when the query that loaded it supplied one, instead of a query of its own. FHIR's $subsumes and $lookup load concepts that way; without the annotation it reads as before.
  7. 79bba4de, 70b8c933 The narrowing, made exact about what it keeps (review passes 1 and 2):
    • A reference with a cascade is evaluated whole, its value sets too, and what it reaches is narrowed after.
    • A reference to one code (or one concept version) is narrowed by its own code, in any case. Narrowed away, it selects nothing and isn't recorded as unresolved.
    • An exclusion is narrowed in any case.
    • Anything built or read at request time is kept by the narrowing it was made under (narrowing_of, ValueSetImports.read).
    • What narrowed_to guarantees is in its docstring: it never leaves out a member whose code is one of the codes as the reference compares codes; where no one source says how to compare them, it keeps any case, for the caller to match the case it means.
  8. 030d27b1 An import's code with no exact match is the newest concept whose code differs only in case, as a code reference finds it.
  9. e827811d Documentation: ExpansionEvaluation.codes are compared as OCL stores codes, so a caller with another spelling passes each stored form.
  10. 19aaaa2b, 58ff6e46 One keeps_code check for the batch and for a reference, the codes lowered once (the simplification review). The batch's guard for a code narrowed away stays, with a test (the final check).

The merges first

This branch ends the queue of OCL API PRs, so the FHIR-layer PRs build on all of them. Before its own commits it merges three open PRs into #1091's stack. Each was reviewed on its own PR, so only the conflict resolutions are new here (git show --remerge-diff <merge>). They are the conflicts whoever merges the second of each pair would meet:

Until those reach this PR's base, its diff also shows them. Once they are on master, and #1091's stack is brought up to master, only this PR's own change remains.

What changes for API users

Nothing. narrowed_to changes only an evaluation that opens it, and nothing in the OCL API does. The import matching applies only under FHIR's rules, which are off for API users. The properties list and the hierarchy step answer as before.

How it was tested

  • Full gate on 58ff6e46, as pr.yml runs it: pylint 10.00; 4,506 tests OK (2 skipped) and 822 search-index tests OK; coverage 97%.
  • New tests:
    • NarrowedEvaluationTest (core/collections/tests/tests_evaluation.py): a whole source, a filter, exclusions, code references, case, a reference to value sets alone, a cascade, a pinned concept version, an exclusion across versions, and a batch evaluated again, each narrowed and not.
    • core/collections/tests/tests_imports.py: the cache by codes; a carried expansion under another narrowing; a cascade through an import evaluated again; the private import at build time.
    • core/collections/tests/tests_member_versions.py: an import's code in another case; one held as given; the newest of two.
    • Each review fix's test fails without its fix.
  • Review: three Codex defect passes, a simplification review, and two Codex checks of the later commits. Every P1 and P2 is fixed or answered; nothing is open. One P2 is accepted: an extra stored as the properties list's internal marker string.
  • The FHIR series built on this branch passes the HL7 Terminology Ecosystem IG's 707 in-scope test cases (hl7.fhir.uv.tx-ecosystem 1.11.0, general mode).

Merge order

#1088, #1087, #1090, #1103, #1091, with #1092 and #1093 together at any point before this one, then this. The FHIR-layer PRs (#1083 first) are based on this branch, and stay drafts until the whole is ready.

Rollback

Revert this PR. No migrations, no settings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qV2gzsF5GhF5BwTJ6x

paynejd and others added 30 commits November 29, 2026 09:03
…lection follows a link to any row of a concept

- In a source version, $cascade's hierarchy step (Concept.get_hierarchy_queryset) matched a link's exact row, then
  kept it only if the version held that row. A child whose row links to an older row of its parent (the parent changed
  in a later release, as in LOINC 2.81) lost that parent, and the parent lost that child. The step now matches by
  concept, as the version views already do (get_version_hierarchy_queryset): a version's concepts cascade to their
  parents and children in that version, whichever row a link names.
- A collection's expansion, at HEAD or in a version, is read the same way. It can hold HEAD rows as well as version
  rows, so a member that is its concept's HEAD or latest version also has the links of the other one, as the API reads
  a concept at HEAD. Before, a collection version never reached a HEAD row, and a collection at HEAD never reached a
  version row.
- get_version_hierarchy_queryset takes the member set, and reads parents from every row of the concept the version
  holds, not only the first. The exact-row variant of get_hierarchy_related_queryset had no other callers and is gone.
- A source's HEAD is unchanged. Covers $cascade (flat and as a hierarchy, both directions), $clone and cascade
  references in collection expansions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXRkP3QEc5U3NfPZp9
… expansion, no deleted members, a HEAD's newest latest version; $clone clones a concept once

Codex review pass 1 (F1.1 to F1.4):
- A collection's hierarchy step reads the concepts of the expansion the rest of its cascade reads (its default one),
  not every expansion of the collection version (F1.1).
- It leaves out deleted members, as the HEAD walk did, such as a HEAD row an import dropped from its source (F1.2).
- A HEAD member has the links of its newest active latest version only, as get_hierarchy_ids reads it, not those of
  an older row still flagged latest (F1.3).
- $clone clones each concept once when a release holds two rows of it (F1.4).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXRkP3QEc5U3NfPZp9
…s that expansion; deleted rows and a stopped clone walk

Codex review pass 2 (F2.1 to F2.3):
- $cascade under a collection version's named expansion (.../expansions/<name>/concepts/<code>/$cascade/) walks that
  expansion, its hierarchy and its mappings; the version's own route walks its default expansion, as before. The
  expansion goes from the view through the Bundle to Concept.cascade and cascade_as_hierarchy. Before, the mappings
  always came from the default expansion, whatever the URL named (F2.1).
- $clone refuses a cascade its budget stopped, even when two rows of one concept leave it at or under the budget,
  rather than cloning part of it (F2.2).
- In a source version, deleted rows are no part of the cascade's hierarchy, as in a collection: their links don't
  count, and they aren't returned (F2.3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXRkP3QEc5U3NfPZp9
… views' parents as before; a collection root's own links

Codex review pass 3 (F3.1, F3.3, F3.4):
- $clone reads the cascade's stopped flag only when the cascade gives one: its early returns (an equivalent already
  in the target, cascadeLevels 0) don't (F3.1).
- The version views (a source version's concept parents) read the first row of the concept the version holds, as
  before; only the cascade reads every active row (F3.3).
- A reverse cascade in a collection also reads its root's own links, as before, so a root the route found in another
  expansion of the version still reaches its parents in the expansion walked (F3.4).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXRkP3QEc5U3NfPZp9
…rows helper, reuse the newest-latest subquery

Simplification review (S1 to S4): the helper that read each row's links as get_hierarchy_ids does had one caller and is
inlined; annotate_has_children uses newest_latest_version_id rather than its own copy of the rule; shorter docstrings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXRkP3QEc5U3NfPZp9
… a collection's reverse cascade

Codex check FC.1: the root's own row, read in a reverse cascade in a collection, counts only when it isn't deleted,
as the expansion's members do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXRkP3QEc5U3NfPZp9
…ps the nearest entries when cut, and no longer recurses

- One step for a whole level: Concept.get_level_cascaded_resources (mappings, mapped concepts, hierarchy) and
  get_level_hierarchy_queryset answer with what each concept's own step answers, together, in one query per kind.
  The per-concept step (get_cascaded_resources, get_hierarchy_queryset) is that step for a level of one, so the
  hierarchy has one definition.
- cascade() walks level by level in a loop, so a walk's queries grow with its depth rather than its size, and a
  chain of any depth no longer hits Python's recursion limit (it did past about 900 levels). cascade_as_hierarchy()
  is a loop too.
- Untruncated answers are unchanged: the same concepts and mappings, proven against a walk concept by concept
  (a cycle, two parents, mappings, retired, source HEAD and a collection, both directions, levels 1, 2 and all),
  and by the existing $cascade, $clone, reference and collection tests.
- What changes, for every caller of a truncated walk ($cascade with max_results, $clone over its budget): a strict
  walk that reaches max_results keeps every level before the cut, then the cut level's mappings and concepts by id
  (mappings first). Before, it kept the lowest row ids across the whole walk, so a nearer concept could be dropped
  for a deeper one. It also reads no more of a wide level than fits (plus one, to tell it was cut), where it read
  every id of the level first. Whether a walk is truncated, and how many entries it returns, are as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qTiXpee3gahwF7WgUt
…base, with FHIR's operators, under FHIR's rules

Behind the per-evaluation switch (ExpansionEvaluation.fhir_rules): FHIR's evaluations turn it on, and API users
keep today's behaviour until EXPANSION_FHIR_RULES_TOGGLE is turned on for them. With it off, nothing here changes:
filters go through the search index, only = and in apply, and expressions and parsing are as before.

Under it, a concept reference's filter entries are matched in the database (core.collections.filters):
- = and in on OCL's keyword fields as the search index matches them (concept_class and datatype ignoring case;
  retired, locale, name_types and description_types exactly), and exactly on extras.<key>: a value's text, a boolean
  as true or false, a number as written, each item of a list, a Coding by its code. The index matched extras as
  words ("chronic" found "Chronic Care").
- new ops: not-in (a concept without the property is kept), exists, and regex: the whole value, on RE2 (linear
  time; google-re2 added); a pattern RE2 can't compile is refused.
- on a concept's code (concept or code) and its display (as display_name picks it).
- hierarchy filters on concept or code, walked with $cascade: is-a, descendent-of, child-of, is-not-a, generalizes,
  descendent-leaf. Hierarchy only, through retired concepts, matched by concept, complete or too costly: a walk past
  REFERENCE_HIERARCHY_FILTER_LIMIT (100,000) raises EvaluationTooCostly, unless the reference is evaluated in the
  background.
- q, and the search index's text and relation fields, stay on the index (= and in, as before).
- what can't be applied is refused at add time with its reason, and selects nothing.
- codes are matched ignoring case when the source says it isn't case-sensitive (a version that says nothing, as its
  HEAD says): in filters, in code references, and in an expansion's batched code references.
- an op other than = and in is written into the reference's expression as property:op=value, and read back by the
  parser, so "p=v" and "p not-in v" are two references (they were one expression, so adding both kept one).

Proven by a test per operator with the switch on and off, a parity test with the search index (each keyword field,
with case variants, selects the same concepts both ways), a dry_run_rebuild of a collection filtered as production
collections are (only the extras word match changes), and a hierarchy filter over a release with a link to an older
row (LOINC 2.81's shape).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qTiXpee3gahwF7WgUt
…nambiguous expressions, whole walks outside request time

- A hierarchy filter's walk is limited only at request time (REFERENCE_HIERARCHY_FILTER_LIMIT); a build, a queued
  rebuild or an add walks the whole hierarchy, so a rebuild never stops part way.
- A property the source declares (Source.properties) can be filtered by its code, read as Concept.properties reads
  it: its extras value, an object's value unwrapped, else, for a class or datatype property, the concept's own.
  extras.<key> unwraps an object's value too.
- Under FHIR's rules an expression keeps every clause: an op other than = and in, or a second clause on one
  property, is written property:op=value (eq for =), one clause each, and read back so.
- A concept-version reference's code stays exact, as the versions holding it are found by it.
- exists treats an empty list as no value; a number matches only as JSON writes it (2, not 2e0); descendent-leaf
  sees a child that cycles back to the root; the case-insensitive code batch looks codes up in one map.
- The wide-level walker test checks that no read of children is unbounded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qTiXpee3gahwF7WgUt
…ere evaluated, concept versions ignoring case, more fields in the database

- A property the source declares is checked in the versions the reference is evaluated in (an expansion's
  system-version), not only its own, and is read as declared even when OCL has a field of that name; a class or
  datatype with no extras value compares the concept's own as the index does (ignoring case).
- The add-references check resolves each reference in its collection, as adding it does.
- Under FHIR's rules a concept-version reference's code is matched ignoring case in a source that isn't
  case-sensitive, in finding the versions that hold it too; the version itself stays exact.
- is_latest_version, id_lowercase and updated_by are matched in the database, as the index matches them; the index's
  fields about a concept's repository, memberships and mappings stay on it.
- A property name that reads as property:op is written with its own op, so the two can't collide.
- exists treats a wrapped empty value ({"value": []}, {"value": null}) as no value; a filter value with a non-ASCII
  digit stays a string match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qTiXpee3gahwF7WgUt
…xtras value, declarations of the version evaluated

- An extras value's texts (value_texts) are the one definition every op compares: =, in and not-in find their
  candidates by a containment search the database can index, then check each by it, as regex and exists do. An
  object with a value is read by its value only, a Coding by its code; null and nested lists are no value.
- A filter applies a declared property only in a version whose source declares it, and only one its creator can
  view; reporting reads the reference's own version and those it's evaluated in. A declared property named like a
  search parameter (page, limit) is a filter.
- A supplied expression whose query string isn't its structured filter (a copied one, changed) takes its filter's.
- The batched lookup of the versions holding concept versions ignores case whatever kind of reference comes first.
- A declared display is read from its extras value by every op; a digit string too long for an int stays a string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qTiXpee3gahwF7WgUt
…ids helper, no unused union, regex check and tokens inline

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qTiXpee3gahwF7WgUt
…n empty text is no value, names escaped, q a search

- A supplied expression is compared with its structured filter only once the filter's schema is valid, so an invalid
  one is refused as before; a list's values compare in any order.
- exists counts only a text that isn't empty ('' and {"value": ""} are no value, as before the last pass).
- Under FHIR's rules a property name is escaped as a value is, so one with & or = reads back whole.
- q is a text search wherever it's declared, in checking and in applying a filter alike.
- An expansion's lookup of the versions holding concept versions takes its own rules (the code batch's), not the
  first reference's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qTiXpee3gahwF7WgUt
…ilter selects nothing; tests for a declared q and the expansion's own rules

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qTiXpee3gahwF7WgUt
… its search again, in either spelling

A reference made from a pasted search URL carries that search's options
(excludeWildcard, excludeFuzzy, includeSearchMeta, searchMapCodes,
exactMatch, verbose) in its filter. Since the change for ocl_issues#2201
(camelCase filter properties such as conceptClass), the camelCase options
were matched as fields the index doesn't have, so such a reference
selected nothing. References saved since then store the options
snake_cased, which were matched the same way.

- The options are recognised in either spelling before the camelCase
  switch, and never matched as fields. conceptClass and the other
  camelCase properties still work.
- They're applied to `q` as the search API applies them: exact matches,
  or wildcard matches too when excludeWildcard is false, or fuzzy matches
  too when excludeFuzzy is false; searchMapCodes false leaves out map
  codes. A reference still matches exactly unless its filter says
  otherwise.
- A filter of options alone selects everything the reference's system or
  value set has, as the search with no `q` lists it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWzjyD2kDtz5SyuRMw
…kip the index; last value wins; exact spellings; fuzzy text lowercased

- A filter of search options alone selects what the reference's system or
  value set has without asking the search index, so a member not indexed
  yet still counts, and a large version isn't read 500 ids at a time.
- A repeated option (a pasted URL's excludeFuzzy=true&excludeFuzzy=false)
  takes its last value, as the search API reads it.
- Options are recognised as the search API spells them or snake_cased,
  nothing looser.
- Fuzzy matching gets the lowercased text, as the search API sends it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWzjyD2kDtz5SyuRMw
…elect what no filter selects; the text read as the search API reads it

- A filter of search options alone returns the reference's queryset as a
  reference with no filter does, whatever the resource-versions toggle.
- A `q` value is trimmed and its quotes dropped, as the search API reads
  its text, and the wildcard clause gets the search API's form of it.
  (No production reference's `q` has quotes or surrounding spaces.)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWzjyD2kDtz5SyuRMw
… text as it is; only wildcard and fuzzy normalise it

A reference whose filter has only `q` matches exactly as before, a literal
quote included (a mapped code such as AB'12). Wildcard and fuzzy matches,
which only a search option turns on, read the text as the search API does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWzjyD2kDtz5SyuRMw
… tests, an early return

- has_param_in_filter returns early for a name that isn't a search option.
- The spelling cases live in get_filter_clause_property's table; the
  release test is a case of the no-filter comparison, which now also
  names the source without a version.
- The repeated-value and snake_case cases stay in the end-to-end tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWzjyD2kDtz5SyuRMw
…search URL reads its text as that search does

A filter with search options came from a search URL, so its `q` is read
as the search API reads its text (trimmed, quotes dropped) for exact
matches too. A `q` alone is still matched as it is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWzjyD2kDtz5SyuRMw
…only for a code with no exact match

The code reference batch read EXPANSION_FHIR_RULES_TOGGLE on every build, through a default evaluation made for it,
whether or not any rule applied. Matching a code ignoring case (under FHIR's rules, in a source that isn't
case-sensitive) matters only for a code with no exact match, so the batch now searches exactly first and asks the
build's evaluation, and whether the source is case-sensitive, only for such a code, once a version. A build whose
codes all match reads no toggle and runs no more queries, as the version rules (#1087) require.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWqZpkKF5gppdmP1JP
…ly exactly as without them

A reference's search options (excludeWildcard, excludeFuzzy,
includeSearchMeta, searchMapCodes, exactMatch, verbose) behave the same
with FHIR's rules on and off: master's fix for them
(#1089), and the database path uses it.

- Both spellings, camelCase and snake_case, are options, through one
  definition (get_search_modifier); the database path's own set is gone.
- They apply to `q` as the search API applies them, through the search
  both paths share.
- A filter of options alone selects what a reference with no filter
  selects, with FHIR's rules on as off.
- An option or a pasted parameter with an op OCL can't apply is refused
  under FHIR's rules too, as without them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWzjyD2kDtz5SyuRMw
…e as FHIR spells it

OCL stores a code with reserved characters percent-encoded (ICD-11's ND53.Y&XK70 as ND53.Y%26XK70), and FHIR's
operations answer with it decoded. Under FHIR's rules a regex filter on `concept` or `code` compared the stored
spelling, so a pattern written for the code as FHIR spells it missed such a code. It now compares the decoded code,
decoded as core.fhir.ops.concepts.fhir_code decodes it (percent-encoding only: a + stays a +). Only the regex reads it;
the filter applies only under FHIR's rules, so nothing changes with them off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWnJcYXZ5geiBgML73
…n links without a subquery per link; $clone keeps the row asked for

- The collection child step's HEAD-row part found each link's child's newest latest version with an ORDER BY ...
  LIMIT 1 subquery run once per link row. A wide LOINC parent has a link from every row of each child, so it ran
  once per link: about 99,000 times for the widest parent in a local LOINC copy, 283,000 on OCL Online. It's now a
  join and NOT EXISTS a newer latest version, which reads the latest versions only. Same rows; the widest parent's
  step went from 999 ms to 312 ms warm (1,807 to 493 cold) on a collection holding LOINC 2.81.
- $clone keeps the root's own row when the release holds two rows of its concept, so its equivalency mapping
  points at the row asked for.
- A collection version's concept routes look the version and its expansion up once per request.
- A test pins that a release's reverse step reads the release's rows only, not the root's HEAD row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qXjDrGi7Trb7ERK92a
…nd REFERENCE_SEARCH_OPTIONS_TOGGLE, off everywhere

With the toggle off, a reference's search options are matched as fields, as on master today, so nothing
changes when this merges. With it on, they apply to `q` and options alone select what a reference with no
filter selects, retired content included, as references did before Jul 2025.

- REFERENCE_SEARCH_OPTIONS_TOGGLE: a new row in toggles.json, off in every environment.
- Gated: search options set aside instead of matched as fields, options alone selecting the version without
  the index, and a search URL's `q` text read the search API's way. The allowed properties and the filter
  errors are as on master.
- Tests: the restored behaviour with the toggle on; master's with it off (options-only, `q` with options,
  verbose alone, a quoted `q`, the clause properties); an options-only reference added to an expansion and
  rebuilt with the toggle off and on; the fixture ships it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qTi2oWEe5q1Dj7NkUp
…reference's description leaves its search options out

A search option only changes how `q` matches, so the description no longer reads it as a property match
("having excludeWildcard equal to ..."). With the toggle off, the description is as before, since the options
are still matched as fields then.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qTi2oWEe5q1Dj7NkUp
…toggle off, `q` is matched by master's own code

- With the toggle off, or no search option, `q`'s matches are built as on master (an option read in the
  search API's spelling, the text as it is, the matches AND-ed), so not even the query sent differs.
- With it on, another spelling of exactMatch (ExactMatch) is a property it can't apply, as for the other
  options, instead of being set aside.
- The toggle is read only for a filter with a search option.
- The toggle's fixture row is pk 14, since 13 is taken on another open branch.
- The fixture test turns the toggle on in every environment column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qTi2oWEe5q1Dj7NkUp
paynejd and others added 20 commits December 4, 2026 10:50
…oduction until the version lists are rebuilt (#1124)

Expansion health reads the version lists that expansions recorded, so it runs in
production after they're rebuilt there (OpenConceptLab/ocl_online#549). Staging
stays on.


Claude-Session: https://claude.ai/code/session_01AaZ4qUWvM4HRKZktm5NSVk

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
… and locks the expansions last and once

Applied or reversed, it waits at most 0.3 s for each lock, then fails and
changes nothing. Its three waits together are below PostgreSQL's
deadlock_timeout (1 s), so in a deadlock this migration gives up and the other
transaction goes on.

collection_expansions, whose lock reads wait for, comes after the foreign keys
to concepts and sources, so it isn't held while they wait for a write there.
Its strongest lock is the first taken: a weaker one made stronger later is a
deadlock with a build that has read the table and then writes to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
… versions apart once, in plain statements

What such an expansion lists was found in SQL by comparing each of its rows
with the others, three times a request. Past a few thousand members that took
seconds, and past some ten thousand longer than a request may.

Expander.entries now reads the rows the caller is shown and what selected each,
once, and compares them in Python. The total, the page, activeOnly, filter and
used-codesystem all come from those.

An $expand reads one snapshot of the database. Otherwise a row saved between
the two reads would be listed without what selected it.

One answer changes: a member selected at HEAD, and also in a release the caller
isn't shown, is listed as one HEAD alone selected. It was left out, so the
answer told of the hidden release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
Its column takes a lock on sources that every read of the table waits for.
Behind a long transaction, the migration and all those reads waited until it
ended. It now gives up after 0.3 s and changes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
… PostgreSQL's deadlock check

Each lock wait is bounded at 0.3 s instead of 5 s, applied and reversed. 0079
locks collections and then collection_expansions: with 5 s, PostgreSQL could
cancel a transaction that had read the second and then read the first. Its two
waits now end before that check, so it's the migration that gives up. Reads of
a table that 0054, 0079 or 0080 waits for are held up for well under a second,
not for 5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
…e helper exports already use

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
$expand finds the members of a large expansion that a caller is shown with
parallel joins (#1093). PostgreSQL keeps the hash tables
those joins share between workers in shared memory, about 45 MB a request. This
repository's compose files give the database 128 MB, so a few requests at once
failed. Its statements no longer share hash tables: each worker builds its own,
about 1 MB a request. The setting ends with $expand's transaction; searches and
other operations keep theirs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
paynejd and others added 3 commits December 4, 2026 07:13
…version locks no reference uses

An add to an expansion built before the rules rebuilds it with its locks.
One that recorded two versions of a source moves every reference to the
newer, but the older stayed recorded: health still counted the source as
recorded twice, and the newer-release check offered a move already made.
The same for value set locks. Without the rules nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
…rsion's lock falls back

A system-version entry that names a version that never existed leaves
HEAD's references unresolved under the rules, but a version built with
lock from it fell back to the latest release, so it had members HEAD never
had. It now leaves unresolved what HEAD's does, at each rebuild.

An entry whose version was deleted still falls back, at each rebuild too:
which entries do is read from what the last build left unresolved, as the
record of deleted locks is cleared by a rebuild.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
…ept versions, wildcards, imports evaluated again

- A lock that only references to concept or mapping versions were found by
  was used, so a rebuild for the rules keeps it, unless other references
  took another version of its source.
- A wildcard entry whose version was deleted before a version is built with
  lock falls back, as one naming that version does.
- A version built with lock, evaluated again for a value set that imports
  it, leaves unresolved what its own last build did.

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.

2 participants