Repository navigation
Conversation
… their importers The code-system part of the sqlite-v2 engine only (snapshot of the engine branch engine-1118 at cdf84fc9, pruned to what tx/sqlite-v2/index.js and the five v2 importers require, plus schema-v2.sql, diff.js, the in-place tools add-filter-index.js, add-system-order.js, add-hierarchy-order.js and add-concept-order.js, and .gitignore): no package or VSAC content store, no request trace routes, no worker rule, no disk supplements, no _text. Against the engine's files: index.js's comment names this branch's source types; provider.js and layers.js leave out the disk-supplement and _text paths (those files are not here); settings.js holds only the four limits the providers use, with no configure (nothing on this branch sets them); comments that pointed at the engine branch's docs say what they need here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e-v2 files Opt-in, per code system: a library line names the file and the code system it must hold; the engine (tx/sqlite-v2) and roaring are required only when such a line is loaded. roaring is an optional dependency, as koffi is. Files open read-only, so cluster tx-workers load the same lines as the master. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…as the walk reports it A paged walk that reaches the limit reports no total (#finishIfPageFilled), and count=0 always counts. processSelection's total was added whatever its size, so the engine reported total 257,266 for http://loinc.org/vs with count=3 (and 534,402 for SNOMED CT ?fhir_vs) where the built-in providers report none. Now: count=0, or a total under the limit. The two paging cases of expand-process-selection (limit 5, a selection of 1,000,000) now expect no total; the page is unchanged. Only a provider with handlesSelecting() reaches this path; no built-in provider has one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed, then the reason, as the walk does Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s the walk reports it The walk counts every code when the page never fills (an offset past the last code), so it reports the total even over the response limit. The selection rule gave none there: LOINC http://loinc.org/vs&offset=257200&count=50&activeOnly=true had total 255,042 on the built-in provider and none on the engine. Only providers with handlesSelecting() take this path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…is too costly, as the walk The usual path counts a filter's codes by walking them and refuses at the walk limit (1,000,000 by default); only a whole-system include is counted without a walk (countAllCodes). The selection path counted anything: ECL * with count=0 on the UK edition (over 1,000,000 concepts) was 422 on the built-in provider and 200 with a total on the engine. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… walk's would, so a missing supplement is not reported The usual path's paged walk ends with the expansion finished (#finishIfPageFilled) once its page is full and either it took the provider's size as the total or the codes walked reach the response limit; nothing after the compose runs, the required-supplement check included. After a processSelection hand-off the expansion went on to that check. A value set naming a supplement no code system takes (replay: inami.fhir.be.ereferral 3.0.0, a supplement of http://snomed.info/sct/11000172109, the whole of SNOMED CT with count=1000) was 200 built-in and 422 "Required supplement not found" handed over. processCodes now ends where the walk would. Test: six shapes against the usual path (status, codes, message); three fail without the change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fourteen suites (on the fixtures in tx/data and files built in the test's temporary directory; nothing downloaded beyond what main's router tests load): the importers (builder, LOINC from the release and from a classic db, SNOMED CT from RF2 and from a cache, RxNorm), the providers against main's on the same editions (LOINC through the router, SNOMED CT lookup, ECL, expressions, default language, text filter, display regex, ids, RxNorm STATUS), the engine (compiler, evaluator, supplement layers, statement counts of batch prefetch), and value sets mixing a v2 system with other providers. Taken from the engine branch's suites, with what this branch does not have left out: the trace format tests, and the trace-based checks of which provider served a request (sqlite-v2-loinc.test.js checks processSelection with a spy instead). Statement counts use a counting tracer (sqlite-v2-counting-tracer.js). The router suites use tests/tx/setup.js. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
CI note: the lint error was ours (an unused import), fixed in d03ebc1. Security Scan fails because of a new advisory against picomatch, GHSA-fc5q-39xc-vjpf (ReDoS), which covers every published version, up to and including 4.0.7. main's own lockfile fails the same |
|
Thanks Josh. I have started reviewing this. Before we go further: the description says the new providers answer as the built-in ones do, errors included, but it doesn't list which errors. The "Known differences" section covers where v2 doesn't match. Going through the code, I found five places where v2 deliberately copies built-in behaviour that looks wrong to me. Can you confirm whether each one is intended, and whether there are others?
Could you add a section to the description listing the built-in behaviours v2 copies on purpose, each with where it lives in both engines? Any of them could get fixed in main later, and when that happens the fix is a known two-place change, not something parity testing turns up later. We would plan to fix them now or later, btw |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…format 21) - main's ECL evaluation is async now: ECL the engine hands to main's ECL (sct-main-ecl.js) is evaluated first and its result kept per file; the synchronous compile reads it, and the provider's async entry points evaluate what a compile needs and compile again (provider.js _compiled) - checkExpression is async in main: awaited (without it an expression the MRCM rejects was accepted), and the MRCM range matcher is async - main's view of a v2 file: an empty text index section, and getRelationshipCore - the cache importer reads format 21 with main's reader, and the older formats 16-20 (which main's server no longer reads) itself: an edition that only exists as an older cache can still be imported. The default language of an older cache is read as main read it up to 1.0.4 - tests: main's importer takes the test edition's license; format 21; an older cache gives the same file; an unknown format is refused; ECL handed to main's ECL gives cs-snomed.js's codes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks Grahame. All five are intended copies: v2 reproduces them only so its answers match the built-in providers. None of them is something I'd defend.
There are 15 others, mostly LOINC filter quirks, tie orders and SNOMED CT code handling. I've added a section to the description, "Built-in behaviours v2 copies on purpose", with all 20 and their locations in both engines. The ones I'd count as bugs are: count=0 of a whole system ignoring While checking this I also found one place where v2 doesn't match main. RxNorm filters beyond For fixes, I'd suggest main first: one small PR per behaviour, as with #412. Then I bring each into v2 here when I merge main. That way each main change is reviewed on its own, and #405 stays a parity change. Once #405 is merged, the same fix would be one PR that touches both places listed in the section. |
Co-Authored-By: Claude <noreply@anthropic.com>
….js does Ports the dialect handling of the built-in SNOMED provider to tx/sqlite-v2/snomed.js so the engine returns the same displays and designation rows: - en-GB gets the GB-preferred term when one exists; en-US and requests without a language get the US term; plain en gets the edition's default display. - $lookup and $validate-code order designations by the edition's display refsets, and tag a second preferred English synonym with its dialect. - For editions with more than one display refset, or a concept with two preferred synonyms in one language, acceptability rows are read per concept (one extra statement). - The display-only path reads designations when the edition's display dialect is not en-US and the request names another language. cs-snomed.js exports LANGUAGE_REFSET_DIALECTS so both providers share the table. tests/tx/sqlite-v2-sct-dialects.test.js imports the repo's SNOMED test data as an International, a UK and a national edition and compares every concept's designations between the engine and cs-snomed.js. Co-Authored-By: Claude <noreply@anthropic.com>
…'s id() since HealthIntersections#412 Co-Authored-By: Claude <noreply@anthropic.com>
Main (12de689) displays the Australian, Canadian, New Zealand and Irish editions from their own English reference set first, then the nearer International dialect. Both v2 importers now share one table that mirrors SnomedServices._displayRefsetOrder, with its [US, GB] default. The RF2 importer used US English for every edition, so a UK edition built from RF2 displayed the US term where main displays the GB one. It now ranks the display by the edition's reference sets, in order. sqlite-v2-sct-dialects.test.js adds an Australian edition and builds every edition from RF2 as well as from main's cache. Co-Authored-By: Claude <noreply@anthropic.com>
…known concepts Main now reports an unknown concept in an `in` list as it does for =, is-a and the others (expand.js filterConceptCodes). processSelection checked the whole comma separated value with locate(), so every `in` filter was taken as naming an unknown concept and left to the usual path. It now checks each code of the list, as expand.js does. Co-Authored-By: Claude <noreply@anthropic.com>
Filters: only what main takes (cs-rxnorm.js doesFilter / filter): = and in, with a value, on TTY, STY and SAB (any case), concept and code, and a REL or RELA that RXNREL has from any source, with every value CUI:<rxcui> or AUI:<rxaui>. Anything else is main's 422 FILTER_NOT_UNDERSTOOD (TTY regex / not-in / exists, concept is-a, display regex, a bare RXCUI, relationship exists / not-in). A filter on a supplement-defined property still goes to the supplement layer. AUI: values: the importer now stores RxNorm's atom-level RXNREL rows (every source) with the concept of the target atom (table rxnorm_atom_rel), and the REL and RELA names of the whole of RXNREL (cs_config rxRels / rxRelas). On the March 2026 release: 3,034,792 rows, 49 MiB (the file is now 337 MiB). A file built before this answers an AUI: value with the old error and asks for a rebuild. Order: results by RXCUI as text, as main's queries give them (GROUP BY / ORDER BY RXCUI); before, by the importer's TTY-rank order, so a filter that spans more than one TTY paged differently. Totals: totalCount is the RXNCONSO concepts (main's totalCodeCount), not the archived ones the file also holds; count=0 of the whole system ignores activeOnly and compose.inactive, as cs-api's default countAllCodes does (D2). The filter API (expand.js's usual path) now keeps to the live concepts as processSelection does, so an archived concept with an STY or a relationship is no longer selected. tests/tx/sqlite-v2-rxnorm-filters.test.js runs each case through the router on both engines, built from one RRF fixture. Co-Authored-By: Claude <noreply@anthropic.com>
Codes: main reads a code as a concept id when BigInt() gives a number other than 0 (stringToIdOrZero), so +22298006 and 0x1543d96 locate 22298006, and -22298006 is an unknown concept rather than a bad expression. v2 took only digits with spaces or leading zeros (D3). Filters: refused as main refuses them, with its 422 FILTER_NOT_UNDERSTOOD: concept / code not-in, regex and exists (main's SNOMED_CONCEPT_FILTER_OPS; the message names the property concept, as main's does for code), display other than regex, and constraint with an operator other than = (was a 400 "ECL expression is not supported"). tests/tx/sqlite-v2-sct-parity-http.test.js runs these, an unknown concept in concept in / not-in, a text filter of digits, and a property x operator matrix through the router on both engines over the SNOMED CT test cache. Differences it leaves out are listed in the PR (in and generalizes order, expressions alone, 116680003 = X, is-not-a with an unknown concept, and main's inflated filter=0 total). Co-Authored-By: Claude <noreply@anthropic.com>
|
I've pushed the two things I said I'd do, and some parity fixes that came out of checking them. Main merged in. The branch now merges main at fac6657 (no conflicts). Where main changed answers that v2 copies, v2 now follows:
RxNorm filters. v2 now takes only what cs-rxnorm.js takes, and refuses the rest with the same 422 FILTER_NOT_UNDERSTOOD: TTY regex / not-in / exists, concept is-a, display regex, a bare RXCUI, relationship exists / not-in.
SNOMED CT. Codes such as
The description is updated to match: it says the base is reached by merge (not rebase), with the new row 1 and the new Known differences rows. Tests: tx-ecosystem 5,602/5,602 with the v2 lines (main's test cases now have more than the 5,362 of 1.0.5). The sqlite-v2 suites are 590/590, and the rest of |
… values The importer no longer writes rxnorm_atom_rel (RxNorm's atom-level RXNREL rows of every source, with the concept of the target atom), nor keeps the RXAUI -> RXCUI map it needed. On the March 2026 release the table was 3,034,792 rows and 49 MiB of a 337 MiB file (288 MiB without it), outside schema-v2.sql and the builder's checks, for a filter value no known value set uses. A relationship filter value AUI:<rxaui> - alone or anywhere in an `in` list - is now refused as the other unsupported RxNorm filters are: 422 FILTER_NOT_UNDERSTOOD. cs-rxnorm.js answers it from the atom-level rows; this is a known difference. cs_config rxRels / rxRelas (every REL and RELA of RXNREL) stay, so a CUI: value on a REL or RELA only other sources' or atom-level rows have is accepted and selects nothing, as cs-rxnorm.js answers it. A file built by the earlier importer still opens; its rxnorm_atom_rel table is not read. Co-Authored-By: Claude <noreply@anthropic.com>
… by a concrete attribute The UK Edition 20261021 has two inactive relationship rows (149501000000101, types 1142139005 and 1142140007) with concept targets; the same types carry concrete values. A sqlite-v2 property has one value kind, so both importers stopped with "property 1142139005 defined as both concept and literal". Main's provider never reads inactive relationships (cs-snomed.js getConceptRelationships), so both importers now skip such rows and count them (inactiveConcreteTypeRelationshipsSkipped). Co-Authored-By: Claude <noreply@anthropic.com>
|
Two more changes pushed (8d19047, 062db49): RxNorm SNOMED CT UK Edition 20261021 would not import. The cache importer stopped with Unit tests after both: 595 / 595 in the 20 sqlite-v2 files; whole 🤖 Generated with Claude Code |
…orters and the reader Replaces the per-system file schema with one terminology-neutral format, user_version 1: concepts and items in one id space; statements (link, literal, identifier, record) typed by a property catalog that says how each property is stored, filtered and reported; mappings; resources; behaviour settings in meta (behaviour.*: grammar, expansion order, lookup name, designation uses, ...), an unknown key or value being an error at open; rebuildable indexes (ix_set, ix_in, ix_order, ix_key, ix_word, ix_by_subject) and sqlite_stat1 statistics. The SNOMED CT, LOINC and RxNorm importers write it and the reader serves it. Files of the earlier schema are refused at start-up with a message naming the importer to re-run. RxNorm atom-level relationships are an importer option (--atom-relationships, off by default). tx/sqlite-v2/README.md describes the format. Co-Authored-By: Claude <noreply@anthropic.com>
|
@grahamegrieve: this push replaces the file format the sqlite-v2 providers read before anyone depends on it. What changed. The earlier files had 13 tables shaped around the three terminologies plus side tables and Why. Things the old layout could not hold now have a place, without new tables: SNOMED CT description ids, Measured (same releases as before; earlier files -> new files):
The list of known differences in the PR description is updated (three rows changed). Old files are refused at |
package-lock.json regenerated with npm install --package-lock-only from the merged package.json: upstream's lock plus the roaring optional dependency and its install-time dependencies. The stale root dependencies entry for roaring is dropped, since package.json lists it under optionalDependencies. Co-Authored-By: Claude <noreply@anthropic.com>
…s display The built-in LOINC provider now adds a description part, the display of the code a code-valued property names (part axes, parent/child, AnswerList, answers-for and the other relationships), to $lookup properties. The LOINC dialect gives the same description, so its $lookup output again matches. CLASS is unchanged (a string property with partCode). Co-Authored-By: Claude <noreply@anthropic.com>
…warning The cache importer stopped (unless --force) when any display language refset listed for the edition had no members. An Australian release ships its own English refset and leaves the GB and US refset concepts without members, so a correct cache could not be imported without --force; the New Zealand, Irish and Canadian entries list fallbacks the same way. Only the first display refset present, the one the displays and item.preferred come from, is now fatal when it has no members (for an edition with an entry of its own). An empty fallback refset is a warning. The RF2 importer runs the same check on the language rows it reads and reports it as warnings (importer.displayRefsetWarnings). Co-Authored-By: Claude <noreply@anthropic.com>
AnswerList.csv carries an answer's external code (ExtCodeId, ExtCodeSystem) on the row of the list that names it, which is not always the answer's first row: LA11840-8 is in eight lists in 2.83 and only its LL6015-3 row has SNOMED CT 77507001. The importer read the external code from an answer's first row only, so 25 answers in 2.83 lacked a mapping that main's importer keeps. Every row's external code is now kept, once per answer, system and code. Co-Authored-By: Claude <noreply@anthropic.com>
…s main
For a code that is no concept of the edition but is one of its
description ids, the provider added a message naming the concept the
description belongs to ("... is a SNOMED CT description id (of the
concept ...), not a concept id"); ValueSet/$validate-code reported it as
an information issue. Main's cs-snomed.js gives such a code the answer
it gives any unknown concept id, with no message of its own. The
message is removed, so $lookup and $validate-code of a description id
now answer as main does.
The file format is unchanged: item.external_id keeps the description
SCTID, and ECL {{ D id = ... }} still uses it.
Co-Authored-By: Claude <noreply@anthropic.com>
…exclude, as main processSelection closed the whole selection once any include had expressions = false. main decides one include and exclude at a time (expand.js includeCodes / excludeCodes, cs-snomed.js filtersNotClosed): an include of the whole system, or an include or exclude whose filters are not all a supplement's and none expressions = false, makes the expansion unclosed. So [is-a X + expressions=false, is-a Y] is unclosed, as is a closed include with an exclude whose filters admit expressions. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
What it gives an operator
A server that loads its SNOMED CT, LOINC and RxNorm lines from sqlite-v2 files uses less memory and less CPU, and
gives the same answers as the built-in providers. Measured on a tx.fhir.org-shaped cluster (master + 2 workers), the
same main, machine and editions, two runs each (on 248eb44, before the merges and on the earlier file layout):
ecosystem-*cases, which ask the Swiss server tx.fhir.ch about its SNOMED CT edition; it was unreachable during the run (the public registry reportedEHOSTUNREACH). The same cases passed in a run a few hours earlier while it was up.It is opt-in, per code system. A server without a
-v2line does not load any of this code. Each line is alibrary choice: a deployment can move SNOMED CT and keep LOINC built-in. The new providers answer as the built-in
ones do, errors included. There is no fallback to the built-in provider.
Scope
Included
tx/sqlite-v2/: code system providers for SNOMED CT, LOINC and RxNorm on one SQLite file per edition (the terminology file format:tx/sqlite-v2/README.md). Concept sets are stored as Roaring bitmaps. Filters and ECL compile to set operations; every SQL statement is instore.jstx/importers/import-{sct,sct-cache,loinc,loinc-classic,rxnorm}-v2.module.js,sct-v2-common.jsandtx/importers/sqlite-v2/(the generic file builder, index builder, schema,diff.js,verify-indexes.js).tx-importfinds them as usual. From RF2, the LOINC CSV release, RxNorm RRF; and from an existing.cacheor classic LOINC.db, for editions without the release at handtx/library.js+33: source typessnomed-v2:,loinc-v2:,rxnorm-v2:. Each loads one file, checks that it holds the code system the type names, and registers its factory like any other. The engine isrequired inside the loader onlytx/workers/expand.js+47/-2: five rules, belowroaringinoptionalDependencies, next tokoffi. If it fails to install, a server without-v2lines is unaffectedpackage.json+1tests/tx/library-sqlite-v2.test.js(the source types; a library without-v2lines leaves the engine and roaring out ofrequire.cache);expand-process-selection.test.js(the five rules); 19sqlite-v2-*.test.jssuites (the file builder, importers, providers against main's, engine, format cases), with the counting helper, on the fixtures intx/dataThe five rules in
expand.jsAll five are in
processCodes, on the path a provider withhandlesSelecting()takes (the provider is handed thewhole compose and returns a page). No built-in provider has one, so no built-in answer can change. Each makes core
report such a page the way the usual walk reports the same page. The provider can't do this itself:
processSelectiongetsoffsetandcountbut not the response limit, and it does not order extensions that coreadds. Repro: the request on this branch, then on the hook commit without the rule.
#finishIfPageFilled)ValueSet/$expand?url=http://loinc.org/vs&count=3valueset-unclosedfirst, then the reasonValueSet/$expand?url=http://snomed.info/sct?fhir_vs&count=5…?url=http://loinc.org/vs&offset=257200&count=50&activeOnly=trueValueSet/$expand?url=http://snomed.info/sct/83821000000107?fhir_vs=ecl/*&count=0(UK edition)$expandof a value set withvalueset-supplementnaming a supplement no code system takes, whole SNOMED CT, count=1000 (seen in IG traffic: inami.fhir.be.ereferral 3.0.0)Rule 3 is measured against the commit with rules 1 and 2; it only matters once rule 1 is in.
Not included
has a value-set side; it would be a separate proposal, if wanted.
_text(a full-text search parameter on the demo server), and the engine branch's supplement files on disk(they need a start-up hook this PR leaves out). Not in this PR.
on the engine branch, not here.
provider.
#syndicateBinary; v2 files are not in the feed (question below).Behaviour
Parity: the rule, and how it was checked
The rule: for the same edition, the same request gets the same response: status, codes in the same order, totals,
displays, designations, properties, extensions, issue codes and message texts. Where main's answer depends on how
its importer laid out its database (LOINC's key order, its Relationships row order, SNOMED CT's concept order), the
v2 importer records that order in the file (
ix_order).tests/tx/test-cases.test.js), library withloinc-v2!andsnomed-v2!linesecosystem-*cases, which ask the Swiss server tx.fhir.ch about its SNOMED CT edition; it was unreachable during the run (the public registry reportedEHOSTUNREACH). The same cases passed in a run a few hours earlier while it was up.test-cases.test.js; built-in, main's fixture library, on 1084d1e: 5,362 / 5,362)diff.js)sqlite-v2-*,library-sqlite-v2,expand-process-selection), and the wholenpm testnpm test(withouttest-cases.test.js) with--workerIdleMemoryLimit=2GB: 371 files passed, 6 skipped by their own checks, 0 failed; 7,611 tests passed, 640 s, node 24 with an 8 GB heap. Without the flag, a whole run on this machine fails LOINC sqlite-v2 tests on main's side (timeouts or empty answers from main's provider), on the branch before this push as wellAUI:values differ: see Known differencesKnown differences
Rows marked (new) changed with this push's file format.
concept is-not-afilterexceptioninvalidREL/RELA = AUI:<rxaui>(new: the optional build)--atom-relationshipsanswers as main<attribute> = <number>on a concrete attribute (1142139005 = 1)#1too)^ R,concept in R)$expand(mix line 1685)0in the US edition; a code with its term attached; RxNorm PSN display in a VSAC value set sent as a tx-resourceinvalid; a second issue; nonormalized-code; rejectednot-supported; one issue;normalized-code; acceptedfilter=0withcount=0concept in A,Bconcept generalizes Xexpressions = true/falseas the only filter116680003 = X(is-a as an attribute filter)Data, not code:
.cache/ classic.db). Its answers match thebuilt-in provider's on the same edition. The files compared here came from the same releases and caches as the
built-in files.
Loinc_2.83f, RxNorm 2026-10-05). Theseruns used older imports of the same SNOMED CT and LOINC releases, and the March 2026 RxNorm release. Production
needs v2 files built from the files it serves.
Built-in behaviours v2 copies on purpose
v2 reproduces these so that the same request gets the same response. Each one looks wrong or arbitrary. If
main changes one, the same change is needed in both places listed. Main's lines are on 1084d1e, the merge base when this list was written (the branch now merges main fac6657;
rows 1, 14 and 15 changed since and say so). v2's places are named by function: the files changed with the file format.
EveryFixed in both: an xsct edition issnomed.info/xsctedition gets the idSCT-h-txSCT-<edition>-<date>, an undated one has no idtx/cs/cs-snomed.jsSnomedServicesFactory.id()(#412, 8fd5c1a)tx/sqlite-v2/snomed.jsid();sqlite-v2-cs-ids.test.js(fixturexSCT-31000003106-20250909, an undated xsct row, two dated editions differ)tx/workers/expand.js:2258-2264 (the check), skipped bysetFinishedfrom#finishIfPageFilled:776-791 and#checkLimit:372-381tx/workers/expand.jsrule 5 :1192-1197,#walkFinishesAfterPage:1209-1222;expand-process-selection.test.js:290generalizesleaves out the concept itselftx/cs/cs-snomed.jsfilter case :3790-3792 →filterGeneralizes:891-918 (also used by ECL>, which is right to exclude it)tx/sqlite-v2/dialects.jsgeneralizesExcludesSelf;engine/compile.js>keeps ancestors only*lists them alltx/cs/cs-snomed.jsiterator(null):3275-3297;tx/workers/expand.js:1276-1311; roots:tx/importers/import-sct.module.js:1853-1925tx/sqlite-v2/orders.jssnomedWalk(walk.reached);engine/engine.jsfilterSizeshortcut never applies and the filter is walked. A single LOINC or RxNorm filter is counted from its sizetx/workers/expand.js:1501-1517 (sizeIsTotal),#checkLimit:372-381;tx/cs/cs-snomed.jsfiltersNotClosed:3924-3931tx/workers/expand.jsrule 4 :1133-1137tx/workers/expand.js#finishIfPageFilled:776-791, :1305-1310tx/workers/expand.jsrules 1 and 3 :1182-1191tx/cs/cs-snomed.jscountAllCodes:2957-2959,iterator:3294tx/sqlite-v2/provider.jsactiveOnly; LOINC also ignorescompose.inactive = falsetx/workers/expand.js:1269-1274, :2155-2157;tx/cs/cs-api.jscountAllCodes:213-215tx/sqlite-v2/provider.js;sqlite-v2-loinc.test.jscountAllCodesdoes (tx/sqlite-v2/provider.jscountAllCodes), socompose.inactive = falseandactiveOnlydon't change the RxNorm count=0 total either (it was the active count).isDeprecatedis always falsetx/cs/cs-loinc.js:372-385tx/importers/import-loinc-v2.module.js;import-loinc-v2-classic.module.jsLIST = LL…lists answers in key order and gives a 422 for an unknown list;answers-for = LL…(the same filter) lists them in the list's sequence, through anORDER BYthat is constant, and gives an empty settx/cs/cs-loinc.js:889, :1040-1048, :1062-1071tx/sqlite-v2/dialects.js;engine/engine.js_firstSeenAnswerList = LL…returns both the terms bound to the list and the answers in ittx/importers/import-loinc.module.js:1185, :1371tx/sqlite-v2/dialects.jsSTATUS = NotStatedselects every code with status key 0 (answer lists, answers, hierarchy-only parts)tx/cs/cs-loinc.js:1276-1283tx/sqlite-v2/dialects.js=/intake 1-4 or the name;regexmatches only namestx/cs/cs-loinc.js:1202-1227, :1256tx/sqlite-v2/dialects.jslocaleComparewith no locale (the order depends on the server's locale)tx/cs/cs-loinc.js:995-996tx/sqlite-v2/text-index.jsfilter=with digits matches by id prefix:filter=0adds nearly every active concept ahead of the text matchestx/cs/cs-snomed.js#addCodeMatches:2814-2842tx/sqlite-v2/text-index.jssctCodeMatches022298006)tx/cs/cs-snomed.jsstringToIdOrZero:368-375,locate:3208-3233tx/sqlite-v2/snomed.jssctIdOf,normaliseCodeBigInt(sctIdOf):+22298006and0x1543d96locate 22298006, and-22298006is an unknown concept, not a bad expression.concept in X,Ywith one unknown concept: since main 4e99d16 expand.js checks each code of the list (filterConceptCodes), reports the unknown one and skips the include, as for=/is-a.concept not-inis not one of main's SNOMED CT operators: a 422tx/workers/expand.jsfilterConceptCodes,#filterNamesUnknownCode;tx/cs/cs-snomed.jsSNOMED_CONCEPT_FILTER_OPStx/sqlite-v2/provider.js_namesUnknownConcept;tx/sqlite-v2/dialects.jssnomedfiltersqlite-v2-sct-parity-http.test.js); what remains of #357 isis-not-a(Known differences)A AND BandB AND Apage differently)tx/cs/cs-snomed.js_eclIntersect:2680,_eclUnion:2695,_eclMinus:2744tx/sqlite-v2/engine/engine.js_eclOrderedexpansion.propertyhas no URIs)tx/cs/cs-api.jspropertyDefinitions:220 (not overridden)tx/sqlite-v2/provider.jsproperty=*leaves outnormalForm/normalFormTersetx/cs/cs-snomed.js#askedFor:3482-3486tx/sqlite-v2/snomed.jstx/cs/cs-rxnorm.js#isObsolete:209-231tx/importers/import-rxnorm-v2.module.js10before9)tx/cs/cs-rxnorm.js#rank:601-611tx/sqlite-v2/text-index.jsIn
expand.js, rules 1, 3 and 4 exist only for 5a and 5b, and rule 5 only for row 2. Rule 2 only puts twoextensions in the order the walk adds them.
The file format (this push)
The files are now in one terminology-neutral format (
tx/sqlite-v2/README.md, DDLtx/importers/sqlite-v2/schema.sql,metaformattx-terminology/1,PRAGMA user_version = 1), replacing the earlier 13-table layout before anythingdepends on it:
share one id space. Facts are four statement shapes:
link(subject -> node),literal(subject -> value),identifier(value -> subject),record(an n-ary row: every SNOMED CT refset, language refsets included). Apropertycatalog says for each property, refset and relation which table holds it and what may search it (FHIRfilters, ECL refinements,
*, subsumption, inverse and union properties, ordered lists).ix_*tables are derivedand rebuildable from the facts (
verify-indexes.js); an index that only some rows need is built only for thecatalog rows that ask for it (
by_target: links by target;by_subject: identifiers by subject). Statistics aresqlite_stat1only (nosqlite_stat4, which makes SQLite re-plan acol = ?statement on every bind).how (
meta behaviour.*: grammar, expansion order, RxNorm designations as distinct texts, lookup names, ...;property.filter_ops). An unknown setting is an error at open. The reader has no per-system configuration keysand no per-format store.
1142139005 = 1, refsets ofdescriptions. RxNorm
AUI:values with--atom-relationships.user_version5) with a message naming theimporter to re-run; there are no in-place upgrade tools any more. Answers on the benchmark requests are
identical to the earlier files' (below).
What the providers support
The same provider API as the built-in providers (
cs-api.js):$lookup,$validate-code(CodeSystem and ValueSet),$expand,$subsumes,$closure,$batch-validate-code,ancestorsOf(ancestorsOf for the built-in code system providers ($closure without pairwise tests) #388).(Report a filter a code system can't do as a 4xx, not 500 #383).
answers-for,LIST,STATUS,concept/codeis-a,ancestor,copyright;=/in/exists/regex.=,in),concept/code(=,in), and a REL or RELA withCUI:values (
=,in).AUI:values are refused with a 422 unless the file was built with--atom-relationships.concept/code=, is-a, descendent-of, child-of, generalizes, descendent-leaf, is-not-a,in(refsets),
inactive,moduleId,constraint(ECL,=),expressions, display regex,<attribute> = <value>,mapped:<scheme> exists.tx/sct/ecl.js); refinements, member-of,{{ term / dialect / language / type }}filters,and main's result order (AND, OR, MINUS,
<<!).tx/sct/expressions.js.filter=): main's tokenizer and ranking (2026 11 gg text search #398, 2026 11 gg block hunting #399), on a word index stored in the file.?fhir_vs,=isa/,=refset/,=ecl/;loinc.org/vs,/vs/LL…,/vs/LP….displayLanguage/ Accept-Language, and SNOMED CT's defaultlanguage as 1.0.4 (SNOMED CT: text filter with no request language returns nothing on caches written by the original server #397).
prefetchCodeswith $batch-validate-code: one prefetchCodes per code system version for the whole batch #378's handle: one read per code system for a whole batch (a 1,000-codeSNOMED CT batch: 2 SQLite statements instead of 2,000, measured on an earlier build).
opContext.checkAndYield, as the built-in loopsdo, so the request's deadline and client-gone checks apply.
Performance
Setup: main 248eb44 and this branch (then based on it) on one machine (12 cores),
cluster.js --workers=2. Two runs of each arm,interleaved, each on fresh clusters. The libraries are the same except the 12
-v2lines: 9 SNOMED CT editions,LOINC 2.77 and 2.83, RxNorm. Built-in SNOMED CT loaded with
load: mmap; built-in LOINC and RxNorm with main'scurrent text index. Value sets: THO 7.5.0. The traffic stands in for production: IG Publisher transcripts (with their
sessions) and a heavy mix. Raw numbers and commands: (link to MEASUREMENTS.md, or attach). The branch has since
taken main by merge, not rebase: 1.0.5 (1084d1e) in 5ab8477, and main fac6657 (1.0.7-snapshot) in 93bca4b,
with no conflicts. The performance runs were not repeated after either merge, nor after the file format change
(they are on the earlier file layout; what was re-measured on the new files is in "The file format" and the parity table).
Memory (private MB: Private_Clean + Private_Dirty; shared mapped file pages excluded)
server.js), anon at readyAfter the heavy mix both arms' workers sit at 0.7-1.3 GB: the heavy expansions' own working memory. Which process
grows, and by how much, varies by 300-700 MB between runs on both arms.
CPU and waiting
$validate-codetook 140 ms$expandtook 28 mssecond pass. The heavy mix is where the difference is: large
$expands (14-16 s against 40-42 s of CPU)and 1,000-code batches (16-17 s against 23-26 s).
requests shares the CPU with more others, so its count over 200 ms is about the same as built-in's (58-68 against
61-72). The 30/s run compares latency at the same load.
Event loop
built-in and 107-110 ms sqlite-v2; at 30/s, 40-42 ms against 39-47 ms.
edition, in each process, listed the edition's description languages with a full scan (NL 235 ms, Intl 143 ms).
Now only a text filter or a display regex asks for the list, and it comes from the file's word index (under 1 ms).
One process, the IG replay from cold, measured on the two builds: holds of 50 ms or more 4 (100-222 ms) before, none
after; the NL
concept infilter that held 231 ms takes 0.9 ms; the same 3,534 answers.Start-up and first requests
filter=heart attack/ the secondTTY = SCD/ the secondCLASS = CHEM/ the second<< 73211009/ the secondOperations
Building the files
.cache.cache.cache--atom-relationships(this machine, one run each, node 24; peak RSS 2.0 / 2.3 / 5.0 / 1.9 GB). A file holds everything it needs, including
the text-filter word index.
tx/importers/sqlite-v2/diff.js A.db B.dbcompares two files by codes.Running
snomed-v2,loinc-v2orrxnorm-v2and point it at the v2 file.!works ason every type. The file can come from
base.urllike any other (getOrDownloadFile), and the terminology-cachepruning counts it as used. The wrong file stops start-up:
loinc-v2:x.db: the file holds http://snomed.info/sct, not http://loinc.org.measured cluster is 2 workers.
cache, shared by every process, reclaimable) and are not anon memory, which the guard measures with a role. Without
a role it measures RSS. There, one v2 process is 490-584 MB against 1,177-1,862 MB built-in (one process, at
ready and after the warm-up requests). The supplement cache (64 MB) does not register a memory-guard reliever.
tx/sqlite-v2/settings.js): SQLite mmap 2 GiB per file,2 MiB page cache, a 5,000,000-row planner limit (too-costly before work starts), 64 MB of supplement layers.
When main changes
change is in the data (languages, default-language slot, dates), and the files are rebuilt. Rebuilding is minutes
per edition.
happened six times: LOINC $lookup: return properties in a fixed order #385 (LOINC
$lookuporder), ancestorsOf for the built-in code system providers ($closure without pairwise tests) #388 (ancestorsOf), SNOMED CT: text filter with no request language returns nothing on caches written by the original server #397 and 1.0.4 (SNOMED CT defaultlanguage), 2026 11 gg text search #398 and 2026 11 gg block hunting #399 (
filter=rules and ranking), more performance work based on node loop blocking hunting #401 (ECL term filters, and ECL result order). Each neededan engine change, from 47 changed lines (LOINC $lookup: return properties in a fixed order #385) to several hundred (SNOMED CT: text filter with no request language returns nothing on caches written by the original server #397, 2026 11 gg text search #398).
main's own code, called by the engine.
Maintenance
systems are 16,545 lines.
rules, the file builder, and 18 code-system suites (importers from the release, a
.cacheand a classic.db; LOINC through therouter; RxNorm; SNOMED CT lookup / ECL / expressions / default language; text filter; display regex; ids; the engine
and its statement counts; value sets mixing a v2 system with UCUM, BCP-47 and a CodeSystem resource). Most compare
the v2 provider with main's provider on the same test edition, built in the test from
tx/data(no download beyondthe R5 core package main's router tests load). Plus the tx-ecosystem test cases with v2 lines (5,569 / 5,602; the 33 failures need a server that was unreachable, see Behaviour).
fhirsmith-harness): it replays traffic to twoservers and compares whole responses, and runs the probe sets above. Each upstream change to the built-in providers
has been rerun through it.
Risks and questions
snomed-v2:/loinc-v2:/rxnorm-v2:, or onesqlite-v2:type where the file says which system it is?their own: from the same releases they took 84 s (LOINC), 48 s (RxNorm) and 135 s (SNOMED CT Intl), against 426 s,
124 s and more than 21 minutes (not finished) for main's.
suites now run in CI with the PR (they build both providers from the test editions), so a change to main's answers
that the fixtures cover fails there. Beyond the fixtures: a rule that such PRs touch both?
concept is-not-a: built-in 500, v2 400. Which should both say?.cachefiles?roaringis a native module (prebuilt binaries for the common platforms). Is an optional dependency acceptable?tx/sqlite-v2/README.md) is terminology-neutral and meant to hold other systems too (ICD-11, NDC) and to be readable by other servers. Is adocumented format with its own version (
tx-terminology/1) the right unit, or should it stay internal to the providers?A capture with request bodies would let us check answers on real traffic.
🤖 Generated with Claude Code