Skip to content

library: SNOMED CT, LOINC and RxNorm from sqlite-v2 files (opt-in, per code system) - #405

Draft
jmandel wants to merge 29 commits into
HealthIntersections:mainfrom
jmandel:feat/sqlite-v2-code-systems
Draft

jmandel wants to merge 29 commits into
HealthIntersections:mainfrom
jmandel:feat/sqlite-v2-code-systems

Conversation

@jmandel

@jmandel jmandel commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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):

built-in sqlite-v2
private memory per process, loaded 604-616 MB 358-391 MB
cluster total at the peak, IG Publisher replay (3,534 requests) 2.60-2.62 GB 1.83-1.86 GB
cluster total at the peak, heavy mix (1,506 requests) 3.48-3.92 GB 2.56-2.97 GB
worker CPU, IG replay, one request at a time 6.4-6.8 s 5.6-5.8 s
worker CPU, heavy mix, one request at a time 66-72 s 33-35 s
heavy mix at 30 requests/s: the slowest request 20.6-21.2 s 1.6 s
heavy mix at 30 requests/s: requests over 200 ms 20-26 4-8
cluster start-up to ready; CPU per process 24-25 s; 12-13 s 17 s; 7 s
answers identical to built-in IG 3,532/3,534, mix 1,504/1,506 (measured before the file format change; built-in not re-run); tx-ecosystem tests 5,569 / 5,602 on the new files with the repo's fixture library (LOINC and both SNOMED CT lines changed to sqlite-v2 files, everything else as in the repo). The 33 that fail are the ecosystem-* cases, which ask the Swiss server tx.fhir.ch about its SNOMED CT edition; it was unreachable during the run (the public registry reported EHOSTUNREACH). 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 -v2 line does not load any of this code. Each line is a
library 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.

sources:
  - snomed-v2!:sct-intl-20260701.db      # was snomed!:Snomed_Intl_20260701.cache
  - loinc-v2!:loinc-2.83.db              # was loinc!:Loinc_2.83f.db
  - rxnorm:rxnorm_20261005-a.cache       # unchanged: stays built-in

Scope

Included

part what size
providers 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 in store.js 15 files, 6,458 lines of code
importers tx/importers/import-{sct,sct-cache,loinc,loinc-classic,rxnorm}-v2.module.js, sct-v2-common.js and tx/importers/sqlite-v2/ (the generic file builder, index builder, schema, diff.js, verify-indexes.js). tx-import finds them as usual. From RF2, the LOINC CSV release, RxNorm RRF; and from an existing .cache or classic LOINC .db, for editions without the release at hand 14 files, 2,850 lines of code
library tx/library.js +33: source types snomed-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 is required inside the loader only +33
expand tx/workers/expand.js +47/-2: five rules, below +47 / -2
dependency roaring in optionalDependencies, next to koffi. If it fails to install, a server without -v2 lines is unaffected package.json +1
tests tests/tx/library-sqlite-v2.test.js (the source types; a library without -v2 lines leaves the engine and roaring out of require.cache); expand-process-selection.test.js (the five rules); 19 sqlite-v2-*.test.js suites (the file builder, importers, providers against main's, engine, format cases), with the counting helper, on the fixtures in tx/data 22 files, 4,302 lines of code; 617 tests, 60 s (one jest worker, node 24, this machine)

The five rules in expand.js

All five are in processCodes, on the path a provider with handlesSelecting() takes (the provider is handed the
whole 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:
processSelection gets offset and count but not the response limit, and it does not order extensions that core
adds. Repro: the request on this branch, then on the hook commit without the rule.

# rule request built-in, and this branch without the rule
1 the total only for count=0, or a selection under the response limit (as #finishIfPageFilled) ValueSet/$expand?url=http://loinc.org/vs&count=3 no total total 257,266
2 a whole grammar-based system: valueset-unclosed first, then the reason ValueSet/$expand?url=http://snomed.info/sct?fhir_vs&count=5 unclosed, reason reason, unclosed
3 the total when the page is never filled (the walk runs to the end and counts) …?url=http://loinc.org/vs&offset=257200&count=50&activeOnly=true total 255,042 no total
4 count=0 on a filter over the walk limit (1,000,000) is too costly ValueSet/$expand?url=http://snomed.info/sct/83821000000107?fhir_vs=ecl/*&count=0 (UK edition) 422 "too many codes to produce (>1000000)" 200, total 1,077,400
5 a full page ends the expansion where the paged walk would, so the required-supplement check is not reached $expand of a value set with valueset-supplement naming a supplement no code system takes, whole SNOMED CT, count=1000 (seen in IG traffic: inami.fhir.be.ereferral 3.0.0) 200, 1,000 codes 422 "Required supplement not found"

Rule 3 is measured against the commit with rules 1 and 2; it only matters once rule 1 is in.

Not included

  • Value sets. Every value set (packages, THO, VSAC, tx-resources) stays on the built-in path. The engine branch
    has a value-set side; it would be a separate proposal, if wanted.
  • Other code systems. ICD-11, NDC, UNII, CPT, OMOP, UCUM, the internal systems and package CodeSystems are unchanged.
  • _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.
  • A request header to choose the provider, traces, stats routes, the engine's start-up report: development tools
    on the engine branch, not here.
  • No fallback. If the new provider gives an answer, it is the answer; a request never falls back to the built-in
    provider.
  • Syndication. The loader does not call #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).

check result
after the file format change: the benchmark request sets (lookup, validate, filters, text, ECL, paging, displays) on the same releases, earlier files against new files, whole answers compared identical: RxNorm 38 / 38, SNOMED CT Intl 59 / 59, UK 65 / 65, LOINC 53 / 53
after the file format change: tx-ecosystem test cases (tests/tx/test-cases.test.js), library with loinc-v2! and snomed-v2! lines 5,569 / 5,602 on the new files with the repo's fixture library (LOINC and both SNOMED CT lines changed to sqlite-v2 files, everything else as in the repo). The 33 that fail are the ecosystem-* cases, which ask the Swiss server tx.fhir.ch about its SNOMED CT edition; it was unreachable during the run (the public registry reported EHOSTUNREACH). The same cases passed in a run a few hours earlier while it was up.
the rows below: on the earlier file layout, before the merges (not rerun)
IG Publisher replay (16 builds, with their cache-id sessions), whole responses compared after dropping ids, meta, dates and timings 3,532 / 3,534, both runs (on 248eb44 / 0437ff0, before the merges)
heavy mix (1,506 requests) 1,504 / 1,506, both runs (on 248eb44 / 0437ff0, before the merges)
the same requests at 16 at once, original timing and 30/s, against each arm's own serial answers identical (on 248eb44 / 0437ff0, before the merges)
200 requests in XML 200 / 200 (on 248eb44 / 0437ff0, before the merges)
732 text-filter, ECL, display-regex and language queries (SNOMED CT Intl, US, NL, es; LOINC with a supplement; RxNorm) 732 / 732, displays and issues included (on 248eb44 / 0437ff0, before the merges)
the same test cases before the file format change (earlier files, this PR before the push) 5,602 / 5,602 (main fac6657's test-cases.test.js; built-in, main's fixture library, on 1084d1e: 5,362 / 5,362)
fresh imports from the release files against the files measured here identical: every fact table, every stored set, the order tables (on 248eb44 / 0437ff0, before the merges); the reverse loaders against release builds are checked in the suites (diff.js)
unit tests on this branch: the sqlite-v2 suites (sqlite-v2-*, library-sqlite-v2, expand-process-selection), and the whole npm test 617 / 617 (21 files, 60 s, one jest worker); the whole npm test (without test-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 well
RxNorm March 2026, 11 filters (TTY, SAB, STY, CUI relationships, combinations, REL / RELA names that only atom-level rows have), main's provider vs a v2 file built here from the same RRF 11 / 11: same codes in the same order. AUI: values differ: see Known differences

Known differences

Rows marked (new) changed with this push's file format.

case main sqlite-v2
an unknown SNOMED CT concept in a concept is-not-a filter 500 exception 400 invalid
RxNorm REL / RELA = AUI:<rxaui> (new: the optional build) follows RXNREL's atom-level rows of every source default build: 422 FILTER_NOT_UNDERSTOOD; a file built with --atom-relationships answers as main
(new) SNOMED CT <attribute> = <number> on a concrete attribute (1142139005 = 1) 500 "Invalid concept ID: 1" the concepts with that concrete value (#1 too)
(new) SNOMED CT reference set whose members are descriptions (^ R, concept in R) not compared on these editions the concepts of the member descriptions
the opioid imported-value-set $expand (mix line 1685) 422 too-costly, at its 20 s limit 200 in 0.1 s
an AU refset in ECL; code 0 in the US edition; a code with its term attached; RxNorm PSN display in a VSAC value set sent as a tx-resource invalid; a second issue; no normalized-code; rejected not-supported; one issue; normalized-code; accepted
LOINC extension edition, concept 760691010000106: two synonyms both preferred, no display-refset entry one synonym the other
SNOMED CT filter=0 with count=0 20,184 on the test cache (each concept once per identifier length its range covers) 2,227 (each concept once)
SNOMED CT concept in A,B in list order by concept id
SNOMED CT concept generalizes X in its ancestor walk's order by concept id
SNOMED CT expressions = true/false as the only filter no codes every concept
SNOMED CT 116680003 = X (is-a as an attribute filter) 1 code on the test cache none

Data, not code:

  • A v2 file is built from a release (or reverse-loaded from main's .cache / classic .db). Its answers match the
    built-in provider's on the same edition. The files compared here came from the same releases and caches as the
    built-in files.
  • tx.fhir.org's current files are newer imports (SNOMED CT cache format 20, Loinc_2.83f, RxNorm 2026-10-05). These
    runs 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.

# behaviour built-in v2 note
1 Every snomed.info/xsct edition gets the id SCT-h-t Fixed in both: an xsct edition is xSCT-<edition>-<date>, an undated one has no id tx/cs/cs-snomed.js SnomedServicesFactory.id() (#412, 8fd5c1a) tx/sqlite-v2/snomed.js id(); sqlite-v2-cs-ids.test.js (fixture xSCT-31000003106-20250909, an undated xsct row, two dated editions differ) Fixed in main by #412; v2 follows (27b3808)
2 A missing required supplement is 200 when the paged walk finishes early, and 422 otherwise (unpaged, a page that isn't filled, an exclude) tx/workers/expand.js :2258-2264 (the check), skipped by setFinished from #finishIfPageFilled :776-791 and #checkLimit :372-381 tx/workers/expand.js rule 5 :1192-1197, #walkFinishesAfterPage :1209-1222; expand-process-selection.test.js:290 Rule 5 exists only for this
3 SNOMED CT generalizes leaves out the concept itself tx/cs/cs-snomed.js filter case :3790-3792 → filterGeneralizes :891-918 (also used by ECL >, which is right to exclude it) tx/sqlite-v2/dialects.js generalizesExcludesSelf; engine/compile.js The fix goes at the filter call site, so ECL > keeps ancestors only
4 A whole-SNOMED-CT expansion lists only what the walk from the active roots reaches (Intl 20260701: the 383,345 active of 534,402); ECL * lists them all tx/cs/cs-snomed.js iterator(null) :3275-3297; tx/workers/expand.js :1276-1311; roots: tx/importers/import-sct.module.js :1853-1925 tx/sqlite-v2/orders.js snomedWalk (walk.reached); engine/engine.js
5a count=0: a SNOMED CT filter over the walk limit (1,000,000) is too costly, while the whole edition is counted. SNOMED CT filter sets always report "not closed", so the filterSize shortcut never applies and the filter is walked. A single LOINC or RxNorm filter is counted from its size tx/workers/expand.js :1501-1517 (sizeIsTotal), #checkLimit :372-381; tx/cs/cs-snomed.js filtersNotClosed :3924-3931 tx/workers/expand.js rule 4 :1133-1137 Rule 4 exists only for this
5b A paged request over the response limit has no total, unless its page isn't filled (the last page, or an offset past the end) tx/workers/expand.js #finishIfPageFilled :776-791, :1305-1310 tx/workers/expand.js rules 1 and 3 :1182-1191
5c The whole-SNOMED-CT total counts the inactive concepts that the listing (row 4) leaves out tx/cs/cs-snomed.js countAllCodes :2957-2959, iterator :3294 tx/sqlite-v2/provider.js Follows row 4
6 count=0 of a whole code system ignores activeOnly; LOINC also ignores compose.inactive = false tx/workers/expand.js :1269-1274, :2155-2157; tx/cs/cs-api.js countAllCodes :213-215 tx/sqlite-v2/provider.js; sqlite-v2-loinc.test.js The total doesn't match the codes listed. RxNorm too: v2 now counts the whole system as cs-api's default countAllCodes does (tx/sqlite-v2/provider.js countAllCodes), so compose.inactive = false and activeOnly don't change the RxNorm count=0 total either (it was the active count).
7 LOINC: only DISCOURAGED is inactive; DEPRECATED is active, and isDeprecated is always false tx/cs/cs-loinc.js :372-385 tx/importers/import-loinc-v2.module.js; import-loinc-v2-classic.module.js
8 LOINC LIST = 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 an ORDER BY that is constant, and gives an empty set tx/cs/cs-loinc.js :889, :1040-1048, :1062-1071 tx/sqlite-v2/dialects.js; engine/engine.js _firstSeen
9 LOINC AnswerList = LL… returns both the terms bound to the list and the answers in it tx/importers/import-loinc.module.js :1185, :1371 tx/sqlite-v2/dialects.js
10 LOINC STATUS = NotStated selects every code with status key 0 (answer lists, answers, hierarchy-only parts) tx/cs/cs-loinc.js :1276-1283 tx/sqlite-v2/dialects.js
11 LOINC CLASSTYPE: =/in take 1-4 or the name; regex matches only names tx/cs/cs-loinc.js :1202-1227, :1256 tx/sqlite-v2/dialects.js
12 LOINC text-filter ties are ordered by localeCompare with no locale (the order depends on the server's locale) tx/cs/cs-loinc.js :995-996 tx/sqlite-v2/text-index.js
13 SNOMED CT filter= with digits matches by id prefix: filter=0 adds nearly every active concept ahead of the text matches tx/cs/cs-snomed.js #addCodeMatches :2814-2842 tx/sqlite-v2/text-index.js sctCodeMatches
14 SNOMED CT codes with leading zeros or whitespace locate the concept (022298006) tx/cs/cs-snomed.js stringToIdOrZero :368-375, locate :3208-3233 tx/sqlite-v2/snomed.js sctIdOf, normaliseCode v2 now reads a code as main does, through BigInt (sctIdOf): +22298006 and 0x1543d96 locate 22298006, and -22298006 is an unknown concept, not a bad expression.
15 SNOMED CT concept in X,Y with 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-in is not one of main's SNOMED CT operators: a 422 tx/workers/expand.js filterConceptCodes, #filterNamesUnknownCode; tx/cs/cs-snomed.js SNOMED_CONCEPT_FILTER_OPS tx/sqlite-v2/provider.js _namesUnknownConcept; tx/sqlite-v2/dialects.js snomed filter Same on both now (sqlite-v2-sct-parity-http.test.js); what remains of #357 is is-not-a (Known differences)
16 SNOMED CT ECL result order follows how the expression is written (A AND B and B AND A page differently) tx/cs/cs-snomed.js _eclIntersect :2680, _eclUnion :2695, _eclMinus :2744 tx/sqlite-v2/engine/engine.js _eclOrdered
17 SNOMED CT, LOINC and RxNorm declare no property definitions (expansion.property has no URIs) tx/cs/cs-api.js propertyDefinitions :220 (not overridden) tx/sqlite-v2/provider.js
18 SNOMED CT property=* leaves out normalForm / normalFormTerse tx/cs/cs-snomed.js #askedFor :3482-3486 tx/sqlite-v2/snomed.js Deliberate in main, per its comment
19 RxNorm: a concept is obsolete only if its display atom has SUPPRESS = O tx/cs/cs-rxnorm.js #isObsolete :209-231 tx/importers/import-rxnorm-v2.module.js
20 RxNorm text-filter ties are ordered by RXCUI as text (10 before 9) tx/cs/cs-rxnorm.js #rank :601-611 tx/sqlite-v2/text-index.js

In expand.js, rules 1, 3 and 4 exist only for 5a and 5b, and rule 5 only for row 2. Rule 2 only puts two
extensions 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, DDL tx/importers/sqlite-v2/schema.sql,
meta format tx-terminology/1, PRAGMA user_version = 1), replacing the earlier 13-table layout before anything
depends on it:

  • Model. Concepts (ids 1..N, active first) and items below them (descriptions, atoms, definitions; ids above N)
    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). A
    property catalog says for each property, refset and relation which table holds it and what may search it (FHIR
    filters, ECL refinements, *, subsumption, inverse and union properties, ordered lists). ix_* tables are derived
    and rebuildable from the facts (verify-indexes.js); an index that only some rows need is built only for the
    catalog rows that ask for it (by_target: links by target; by_subject: identifiers by subject). Statistics are
    sqlite_stat1 only (no sqlite_stat4, which makes SQLite re-plan a col = ? statement on every bind).
  • Settings in the file. Where any reader of these files would present a system the same way, the file says
    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 keys
    and no per-format store.
  • New answers from the same releases (Known differences, (new)): 1142139005 = 1, refsets of
    descriptions. RxNorm AUI: values with --atom-relationships.
  • Operators: files of the earlier layout are refused at start-up (user_version 5) with a message naming the
    importer 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):

  • Operations: $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).
  • Filters: every property and operator the built-in provider accepts, and the same 422 for the ones it doesn't
    (Report a filter a code system can't do as a 4xx, not 500 #383).
    • LOINC: parts, answers-for, LIST, STATUS, concept / code is-a, ancestor, copyright; = / in /
      exists / regex.
    • RxNorm: TTY, STY, SAB (=, in), concept / code (=, in), and a REL or RELA with CUI:
      values (=, in). AUI: values are refused with a 422 unless the file was built with --atom-relationships.
    • SNOMED CT: 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.
  • ECL: main's parser (tx/sct/ecl.js); refinements, member-of, {{ term / dialect / language / type }} filters,
    and main's result order (AND, OR, MINUS, <<!).
  • SNOMED CT expressions: main's tx/sct/expressions.js.
  • Text filter (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.
  • Implicit value sets: SNOMED CT ?fhir_vs, =isa/, =refset/, =ecl/; loinc.org/vs, /vs/LL…, /vs/LP….
  • Languages: designations by language and use, displayLanguage / Accept-Language, and SNOMED CT's default
    language as 1.0.4 (SNOMED CT: text filter with no request language returns nothing on caches written by the original server #397).
  • Supplements: tx-resource and package supplements, applied in memory (a per-process cache of 64 MB).
  • Batch prefetch: prefetchCodes with $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-code
    SNOMED CT batch: 2 SQLite statements instead of 2,000, measured on an earlier build).
  • Cooperative evaluation: long reads pause every 10 ms through opContext.checkAndYield, as the built-in loops
    do, 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 -v2 lines: 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's
current 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)

built-in sqlite-v2
per process, loaded (master, tx1, tx2) 604-616 358-391
cluster, loaded 1,847-1,857 1,131-1,162
cluster, after the IG replay 1,961-2,135 1,417-1,472
cluster peak, IG replay 2,599-2,622 1,834-1,864
cluster, after the heavy mix 3,359-3,902 2,517-2,968
cluster peak, heavy mix 3,482-3,924 2,555-2,968
largest process seen 1,749 1,327
one process (server.js), anon at ready 811-928 414-443

After 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

built-in sqlite-v2
IG replay, one at a time: worker CPU 6.4-6.8 s 5.6-5.8 s
IG replay, 16 at once: wall / slowest request 1.9-2.3 s / 193-589 ms 1.9-2.0 s / 154-251 ms
heavy mix, one at a time: worker CPU 66.1-71.8 s 32.6-35.4 s
the same, without the one request that runs into built-in's 20 s limit 45.2-48.5 s 32.5-35.3 s
heavy mix, 16 at once: wall / requests over 1 s / slowest 25.6-28.2 s / 32-38 / 20.5-22.1 s 7.5 s / 12-15 / 4.9-7.0 s
heavy mix at 30/s: process CPU 60-68 s 33-36 s
heavy mix at 30/s: over 200 ms / over 1 s / slowest 20-26 / 2-3 / 20.6-21.2 s 4-8 / 1 / 1.6 s
heavy mix at 30/s: the worst wait of a cheap request a 6.4 ms $validate-code took 140 ms a 2.9 ms $expand took 28 ms
  • On IG traffic, in steady state, the two cost the same: one process, the replay twice, 3.4 s against 3.5 s on the
    second 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).
  • At 16 at once the faster arm also runs the mix 3.5 times faster (200 requests/s against 53-59/s). Each of its
    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

  • Main's block monitor (holds of 2 s or more): nothing logged in any of the 8 clusters, either arm.
  • Holds of 50 ms or more, from a 10 ms timer in each process:
    • heavy mix: both arms, 1-5 per run, the longest 104-149 ms;
    • IG replay: built-in none; sqlite-v2 1-5 per run, 104-251 ms, all of them the first-use cost below, now fixed.
  • A ping every 50 ms beside the load runs: median 1 ms on both. The slowest ping on the mix at 16 at once was 90-134 ms
    built-in and 107-110 ms sqlite-v2; at 30/s, 40-42 ms against 39-47 ms.
  • The sqlite-v2 holds on the IG replay were a first-use cost, now fixed. The first filter on each SNOMED CT
    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 in filter that held 231 ms takes 0.9 ms; the same 3,534 answers.

Start-up and first requests

built-in sqlite-v2
cluster ready 24-25 s 17 s
CPU per process at ready 11.7-12.9 s 6.7-7.2 s
first SNOMED CT filter=heart attack / the second 3.3 s / 5 ms 19-35 ms / 2-2.6 ms
first RxNorm TTY = SCD / the second 0.4-0.8 s / 1 ms 2.5 ms / 1.7 ms
first LOINC CLASS = CHEM / the second 0.28-0.30 s / 1.5 ms 15-18 ms / 9 ms
first SNOMED CT ECL << 73211009 / the second 12 ms / 4-6 ms 16-26 ms / 2.5-3.2 ms

Operations

Building the files

node tx/importers/tx-import.js snomed-v2 import -s <RF2 release dir> -d sct-intl-20260701.db -e 900000000000207008 --snomed-version 20260701
node tx/importers/tx-import.js loinc-v2 import -s <LOINC release dir> -d loinc-2.83.db -v 2.83
node tx/importers/tx-import.js rxnorm-v2 import -s <RxNorm rrf dir> -d rxnorm-20261005.db -v 10052026 [--atom-relationships]
# editions whose release isn't at hand: from the file the server already has
node tx/importers/tx-import.js snomed-v2-from-cache import -s sct_es_20250510.cache -d sct-es-20250510.db
node tx/importers/tx-import.js loinc-v2-classic import -s loinc-2.77-c.db -d loinc-2.77.db
system v2 importer main's importer v2 file built-in file
SNOMED CT Intl 20260701 (RF2) 148 s not finished after 21 min (its readme: 2-6 h) 836 MiB 600 MiB .cache
SNOMED CT UK 20261021, from its .cache 376 s 2,517 MiB 1,709 MiB .cache
LOINC 2.83 96 s 426 s 944 MiB 796 MiB
RxNorm (March 2026) 48 s; 63 s with --atom-relationships 124 s 295 MiB; 338 MiB 2,256 MiB

(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.db compares two files by codes.

Running

  • Enable: change a line's type to snomed-v2, loinc-v2 or rxnorm-v2 and point it at the v2 file. ! works as
    on every type. The file can come from base.url like any other (getOrDownloadFile), and the terminology-cache
    pruning 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.
  • Disable: change the line back. Nothing else is stored.
  • Older files: a file built before this push is refused at start-up, with the importer to re-run.
  • Cluster: files open read-only, so the master and every tx-worker load the same lines (no role flag). The
    measured cluster is 2 workers.
  • Memory guard: unchanged, nothing to configure. The providers' SQLite pages are mapped from the file (page
    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.
  • Settings: none. The providers run with fixed limits (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

Maintenance

  • Code: 29 files, 9,288 lines of code (+1,977 comment lines). Providers 6,451; importers and tools 2,837. Core: 80 lines. For scale, main's built-in providers and importers for the same three
    systems are 16,545 lines.
  • Tests in this PR: 21 test files and a helper, 617 tests, 60 s (one jest worker, node 24): the source types, the five
    rules, the file builder, and 18 code-system suites (importers from the release, a .cache and a classic .db; LOINC through the
    router; 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 beyond
    the 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).
  • How parity is kept: a comparison harness outside the repo (fhirsmith-harness): it replays traffic to two
    servers 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

  1. Names. snomed-v2: / loinc-v2: / rxnorm-v2:, or one sqlite-v2: type where the file says which system it is?
  2. One PR or two? Providers (6.0k lines) and importers (2.7k) could go separately. The importers are useful on
    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.
  3. Who keeps parity? Every change to a built-in provider's answers needs the same change here. The comparison
    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?
  4. The unknown-concept case (SNOMED: a ValueSet filter naming an unknown concept is a 400, not a 500 #357): now only concept is-not-a: built-in 500, v2 400. Which should both say?
  5. Syndication: should v2 files be in the feed, and published to the bucket next to the .cache files?
  6. roaring is a native module (prebuilt binaries for the common platforms). Is an optional dependency acceptable?
  7. Value sets: not proposed here, as discussed. Is the code-system part wanted on its own?
  8. The file format (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 a
    documented format with its own version (tx-terminology/1) the right unit, or should it stay internal to the providers?
  9. Production traffic: these numbers are from IG Publisher transcripts and a heavy mix, not a tx.fhir.org capture.
    A capture with request bodies would let us check answers on real traffic.

🤖 Generated with Claude Code

jmandel and others added 9 commits November 17, 2026 11:27
… 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>
@jmandel

jmandel commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

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 npm audit --audit-level=high today: it reaches main through jest, typescript-eslint and sqlite3 (node-gyp > tinyglobby > picomatch). The only one of those that comes from this PR is roaring's node-gyp. Your next PR will hit it too until picomatch ships a fix.

@grahamegrieve

grahamegrieve commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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?

  1. Test-edition ids. cs-snomed.js id() does match = "x"+match, which makes the match a string, so every snomed.info/xsct edition gets the id SCT-h-t. tx/sqlite-v2/snomed.js reproduces this on purpose. That's a bug in main, and I'd rather fix it in both places than preserve it.
  2. Whether a missing supplement is reported depends on paging. From 94e39fa: a value set requiring a supplement no code system takes (inami.fhir.be.ereferral 3.0.0) returns 200 with count=1000, because the paged walk finishes before the required-supplement check, but 422 unpaged. expand.js now makes the selection path return 200 too. The answer shouldn't depend on count.
  3. SNOMED generalizes leaves out the concept itself. filterGeneralizes returns ancestors only, and v2 copies this (generalizesExcludesSelf: true). FHIR defines generalizes as including the given concept.
  4. A whole-system SNOMED expansion leaves out inactive concepts, but ECL * includes them. It only has what the walk from active roots reaches (orders.js snomedWalk). Is that intended, or something the walk happens to do?
  5. Totals and too-costly rules in expand.js. With count=0, a filter over the walk limit is refused but the whole system is counted. A paged request over the limit has no total, except when the offset is past the end. These come from how the walk is built rather than a design decision.

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

jmandel and others added 2 commits November 18, 2026 06:25
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>
@jmandel

jmandel commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

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.

  1. SCT-h-t. Intended copy. You've fixed it in main since (Give each SNOMED CT xsct edition its own CodeSystem id #412, xSCT-<module>-<date>). v2 picks up the same change when I next merge main into this branch.
  2. Missing supplement depends on paging. Intended copy; rule 5 exists only for this. It goes a bit further than count: a page that isn't filled, or a compose with an exclude, still gets the 422, and it happens for every code system, not only SNOMED CT. Agreed it's a bug. My suggestion is to run the check whether or not the walk finished early, so it's always 422. Rule 5 would then go.
  3. generalizes. Intended copy, and agreed. One detail for the fix: ECL > also calls filterGeneralizes and needs ancestors only, so the concept itself should be added at the filter case (cs-snomed.js around line 3791), not inside filterGeneralizes. In v2 it's dropping generalizesExcludesSelf.
  4. Whole-system SNOMED CT leaves out inactive concepts. Intended copy. I read it as something the walk happens to do. The iterator's own total and countAllCodes count every concept, includeCodeAndDescendants checks activeOnly for each concept as if it could meet inactive ones, and your comment on _eclEnumerateAllConcepts says * should agree with the whole code system. On Intl 20260701 the walk lists the 383,345 active concepts and * gives all 534,402. Whether the whole system should list everything is your call.
  5. Totals and too-costly. Intended copies; rules 1, 3 and 4 exist only for these. One correction on the count=0 case: main only walks a filter to count it when it can't trust the filter's size. Every SNOMED CT filter set reports "not closed" (filtersNotClosed), so SNOMED CT filters are always walked, and they hit the walk limit. A single LOINC or RxNorm filter is counted from its size. On paging: a total also appears for a short last page, not only past the end. Which rule you want is your call. Rules 1, 3 and 4 then change to match it, or go.

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 activeOnly (row 6), filter=0 on SNOMED CT returning nearly the whole edition (13), and the locale-dependent and text-ordered tie breaks (12, 20).

While checking this I also found one place where v2 doesn't match main. RxNorm filters beyond = and in (for example TTY regex, concept is-a) get a 422 from main but an answer from v2, and AUI: values go the other way. I'll make v2 refuse what main refuses.

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.

jmandel and others added 7 commits November 20, 2026 19:15
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>
@jmandel

jmandel commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

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:

  • Give each SNOMED CT xsct edition its own CodeSystem id #412: xsct editions get xSCT-<edition>-<date> in v2 too, and the test expects it.
  • SNOMED CT: choose the display by English dialect (en-GB gets the GB term) #407 and 12de689: SNOMED CT displays by English dialect (en-GB gets the GB term), and the Australian, Canadian, New Zealand and Irish editions display from their own reference set first. Both v2 importers now use your per-edition table. The RF2 importer used US English for every edition, so a UK edition built from RF2 showed the US term. That's fixed as well.
  • 4e99d16 (in added to the unknown-concept check): v2 checks each code of the list too. The concept in row in Known differences goes away. is-not-a with an unknown concept is still 500 on main and 400 on v2.

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. AUI: values are answered as main answers them. That needed the atom-level RXNREL rows, so the importer now stores them (49 MB on the March 2026 release), and an older RxNorm v2 file needs a rebuild for AUI: values. I ran both providers on that release: same codes, same order, same errors for each filter. While doing this I found three more RxNorm differences and fixed them:

  • Results come in RXCUI text order, as main's queries return them.
  • The whole-system total excludes archived concepts (228,042, not 336,430).
  • count=0 ignores activeOnly and compose.inactive = false, as main does.

SNOMED CT. Codes such as +22298006 or 0x1543d96 now locate the concept, as BigInt does in main. v2 now refuses the operators main refuses (concept not-in, code regex, display =, constraint with anything but =). A new test runs a property × operator matrix through the router on both providers. It turned up a few differences that I haven't fixed, and I've added them to Known differences:

  • filter=0 with count=0: main's total counts some concepts several times.
  • The order of concept in and of generalizes.
  • expressions as the only filter.
  • 116680003 = X.

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 npm test passes: 369 files, 0 failed. I haven't re-run the replays or the performance runs since the merges, and the description now says so.

jmandel and others added 2 commits November 21, 2026 07:17
… 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>
@jmandel

jmandel commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Two more changes pushed (8d19047, 062db49):

RxNorm AUI: filter values: side table removed. My last push added an RxNorm-only table (rxnorm_atom_rel, 3,034,792 rows, 49 MiB of a 337 MiB file) so that relationship filters with AUI:<rxaui> values would answer as cs-rxnorm.js does. I took it back out: it sat outside schema-v2.sql, and I found no AUI: value in VSAC's 40,267 value sets, the 403,042 JSON files of my package cache, the tx-ecosystem suite or the IG Publisher replays — the only uses are FHIRsmith's own unit tests. sqlite-v2 now answers an AUI: value with 422 FILTER_NOT_UNDERSTOOD (listed under Known differences); CUI: filters still match cs-rxnorm.js (e.g. has_ingredient = CUI:161: the same 964 codes in the same order). If you know of a client that sends AUI: values, tell me and I'll look at storing atoms properly.

SNOMED CT UK Edition 20261021 would not import. The cache importer stopped with property 1142139005 defined as both concept and literal: two inactive relationship rows on the inactive concept 149501000000101 are typed 1142139005 and 1142140007 with concept targets, and those attributes also carry concrete values. Both v2 SNOMED importers now leave out inactive relationship rows whose type is a concrete-value attribute and count them in the import summary. cs-snomed.js never reads inactive relationships, and on this cache main and the rebuilt v2 file give the same $lookup of that concept and the same results for 1142139005 = 38112003 (none) and ECL * : 1142139005 = #9 (16). A new test fails without the fix.

Unit tests after both: 595 / 595 in the 20 sqlite-v2 files; whole npm test 371 files passed, 7,647 tests.

🤖 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>
@jmandel

jmandel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@grahamegrieve: this push replaces the file format the sqlite-v2 providers read before anyone depends on it.
Nothing about how a server is configured changes (the same snomed-v2: / loinc-v2: / rxnorm-v2: lines,
the same importer commands); the files have to be re-imported.

What changed. The earlier files had 13 tables shaped around the three terminologies plus side tables and
~18 configuration keys the reader interpreted. The new file is terminology-neutral: concepts and their items
(descriptions, atoms, definitions) in one id space; four statement shapes (link subject -> node, literal
subject -> value, identifier value -> subject, record n-ary rows such as refset members); a property
catalog that says for every property, refset and relation where its rows are and what may search it; and
index tables (ix_*) that can be dropped and rebuilt from the facts. The format is described in
tx/sqlite-v2/README.md; the DDL is tx/importers/sqlite-v2/schema.sql.

Why. Things the old layout could not hold now have a place, without new tables: SNOMED CT description ids,
refsets whose members are descriptions, an attribute with both relationship rows and concrete values
(1142139005 = 1 now answers instead of main's 500), and RxNorm atom-level relationships (optional). The reader
lost its per-format store and its configuration keys: the file carries the few presentation settings a server
needs (meta behaviour.*, e.g. RxNorm designations as distinct texts), and an unknown setting is an error at open.

Measured (same releases as before; earlier files -> new files):

RxNorm 03/2026 SNOMED CT Intl 20260701 SNOMED CT UK 20261021 LOINC 2.83
file MiB 288.4 -> 295.1 862.8 -> 835.5 2,630.1 -> 2,516.7 928.4 -> 943.7
open ms 80 -> 16 233 -> 35 568 -> 71 547 -> 19
benchmark requests, identical answers 38 / 38 59 / 59 65 / 65 53 / 53
warm total ms 88 -> 94 760 -> 417 842 -> 506 1,487 -> 455
import s 44 -> 48 115 -> 148 294 -> 376 84 -> 96
  • Most of the SNOMED CT warm-time gain is a reader change (a property filter on links pushed into SQL) that would
    help the earlier files as much; what is the format's own is open time, file size, LOINC's inverse properties
    (child exists one bitmap) and the cases above.
  • tx-ecosystem test cases with LOINC and SNOMED CT on the new files, the repo's fixture library otherwise
    unchanged: 5,569 / 5,602. The 33 that fail are the ecosystem-* cases, which need the Swiss server
    tx.fhir.ch; it was unreachable during the run. They passed a few hours earlier while it was up.
  • npm test (without the tx-ecosystem cases): the 617 sqlite-v2 tests pass (60 s alone). A whole run on this
    machine fails some LOINC sqlite-v2 tests on main's side (timeouts, empty answers) before and after this push alike;
    with --workerIdleMemoryLimit=2GB the whole run passes: 372 suites, 7,669 tests, 739 s.
  • RxNorm REL / RELA = AUI:<rxaui>: still a 422 by default. A file built with --atom-relationships stores
    RXNREL's atom-level rows of every source (one statement per row, +43 MiB) and gives main's codes for
    1,512 of 1,512 sampled filters (the 81 earlier ones and 1,431 from 1,000 random atom rows of every source), in the same order.

The list of known differences in the PR description is updated (three rows changed). Old files are refused at
start-up with a message naming the importer to re-run.

jmandel and others added 3 commits November 22, 2026 06:29
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>
jmandel and others added 5 commits November 22, 2026 07:21
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>
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