Repository navigation
Conversation
…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
…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
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
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
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
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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
…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 was referenced Dec 4, 2026
paynejd
marked this pull request as ready for review
December 4, 2026 13:25
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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 incore/fhir, and all of their change is in two commits:git show 76e0390f ca66dbe9.c8ae51de..58ff6e46, twelve commits, one at a time: an evaluation narrowed to some codes.git diff 2eb51e93 2f872769: what's answered about a reference outside a build.git show 76e0390f ca66dbe9: a fast$expandof an expansion that keeps versions apart.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:
$expandof an expansion that keeps versions apart is fast enough for a large one. Commits76e0390fandca66dbe9, incore/fhir/ops/expand.pyand one option incore/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
$expandreads 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,filterandused-codesystemall come from those.One snapshot: an
$expandnow 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=10with a text filter, on PostgreSQL 14.7 with JIT off andwork_mem4 MB, data in memory. A request may take 5 s; the times before were measured with that limit raised.Members selected at HEAD:
Members selected in two releases each:
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, aspr.ymlruns 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:
$expandlists 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 66f5e54bon its own:7edf4d68and6fb39e7aare the changes, and66f5e54bcorrects both after review. About 70 lines of code and 160 of tests.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, andresolved-repo-updatesoffered 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.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.system-versionnames 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.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.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 2f872769on its own: six commits,b5053aae(the change) and five from its review.force-system-versionabove 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 saykeeps_membersand the conversion then drop the member.repo_versionis the version it's evaluated in, andchosen_bycan beparameter);resolved_repo_versions,/resolve/, member health and the source distribution, which name the version the last build used.CollectionReference.resolve_system_version, which a build never asks, is what the collection's default expansion would give the reference (version_rule, byVersionRules).own_system_versionis the old code, and it's what a build asks. What an expansion recorded is read byExpansion.get_source_versions_given.core/collections/tests/tests_version_answers.pychecks each answer with it off as well as on.resolved-repo-updates(it usedVersionRules), the check for value set loops, and a reference'stranslation, which only words what the reference says.rebuild_expansion_version_listsdoesn't know the version parameters.Branch
fhir-452-b-codes, basefhir-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..58ff6e46one commit at a time: the first six are the changes, and the last six came from the review loop.f990fd0bA 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 givesCollectionReference._apply_filtersa 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.ead0b58dAn 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 inCollectionReference.narrow_to_evaluation_codes; references to one code do it inCodeReferenceBatch.$validate-codeon a value set a request carries is the one caller, later in the series.59d8686aA 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.4c5d4ddcA test: outside a request, a private import evaluated again is viewed by its importing reference's creator.ecff63cfAn 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.ec2954adTwo 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_idsreads a HEAD row's latest version from ahierarchy_latest_version_idannotation when the query that loaded it supplied one, instead of a query of its own. FHIR's$subsumesand$lookupload concepts that way; without the annotation it reads as before.79bba4de,70b8c933The narrowing, made exact about what it keeps (review passes 1 and 2):narrowing_of,ValueSetImports.read).narrowed_toguarantees 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.030d27b1An import's code with no exact match is the newest concept whose code differs only in case, as a code reference finds it.e827811dDocumentation:ExpansionEvaluation.codesare compared as OCL stores codes, so a caller with another spelling passes each stored form.19aaaa2b,58ff6e46Onekeeps_codecheck 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:958b92e7merges 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 (with OpenConceptLab/ocl_online#452 | $cascade in a source version or a collection follows a link to any row of a concept #1085 and OpenConceptLab/ocl_online#452 | A reference's search options apply to its search again, in either spelling #1089). Incore/collections/evaluation.py,CodeReferenceBatchkeeps both sides' methods. Incore/collections/models.py, both import lists are kept, andadd_references' references and code batch share the build's one default evaluation (build_evaluation, 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), which is the default 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 adds.f9e64707merges OpenConceptLab/ocl_online#452 | Stored $expand needs next to no shared memory, and its 422 reads the same for hidden content as for missing content #1092: thecore.collections.modelsimport incore/fhir/ops/expand.py.c8ae51demerges OpenConceptLab/ocl_online#452 | Stored $expand, $validate-code and $translate show a member only where a version the base shows holds its row #1093: no conflicts.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_tochanges 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
58ff6e46, aspr.ymlruns it: pylint 10.00; 4,506 tests OK (2 skipped) and 822 search-index tests OK; coverage 97%.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.hl7.fhir.uv.tx-ecosystem1.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