Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ad02440
sqlite-v2: code system providers for SNOMED CT, LOINC and RxNorm, and…
jmandel Nov 17, 2026
4581d4a
library: snomed-v2:, loinc-v2: and rxnorm-v2: source lines load sqlit…
jmandel Nov 13, 2026
3182c79
expand: a selecting provider's total only within the response limit, …
jmandel Nov 13, 2026
d3d57ed
expand: a selecting provider's whole grammar-based system says unclos…
jmandel Nov 13, 2026
82906ac
expand: a selecting provider's total when its page is never filled, a…
jmandel Nov 13, 2026
10d3ca8
expand: count=0 of a selecting provider's filter over the walk limit …
jmandel Nov 13, 2026
94e39fa
expand: a selecting provider's full page ends the expansion where the…
jmandel Nov 14, 2026
29c1c2b
tests: the sqlite-v2 provider and importer suites
jmandel Nov 17, 2026
d03ebc1
sqlite-v2: drop an unused import (eslint no-unused-vars)
jmandel Nov 17, 2026
5ab8477
Merge main (1.0.5) into the sqlite-v2 code systems branch
jmandel Nov 18, 2026
32e35f4
sqlite-v2: follow main 1.0.5 (async ECL and expression checks, cache …
jmandel Nov 18, 2026
93bca4b
Merge main (fac66577) into the sqlite-v2 code systems branch
jmandel Nov 21, 2026
4b5faa0
SNOMED CT engine: choose the display by English dialect, as cs-snomed…
jmandel Nov 18, 2026
27b3808
sqlite-v2 SNOMED CT: xsct editions get xSCT-<edition>-<date>, as main…
jmandel Nov 21, 2026
4e31293
sqlite-v2 SNOMED CT importers: main's display reference sets per edition
jmandel Nov 21, 2026
4c3bac3
sqlite-v2: read a `concept in` list code by code when checking for un…
jmandel Nov 21, 2026
f4f38a7
sqlite-v2 RxNorm: filters, order and totals as cs-rxnorm.js
jmandel Nov 21, 2026
9c4e9c6
sqlite-v2 SNOMED CT: code spellings and filter refusals as cs-snomed.js
jmandel Nov 21, 2026
8d19047
sqlite-v2 RxNorm: drop the atom-level relationship table, refuse AUI:…
jmandel Nov 21, 2026
062db49
sqlite-v2 SNOMED CT importers: leave out inactive relationships typed…
jmandel Nov 21, 2026
a5d35af
sqlite-v2: one terminology file format (tx-terminology/1) for the imp…
jmandel Nov 22, 2026
1aa675c
Merge origin/main into the sqlite-v2 branch
jmandel Nov 22, 2026
93ef7e3
sqlite-v2 LOINC: code-valued $lookup properties carry the named code'…
jmandel Nov 22, 2026
45184ce
sqlite-v2 SNOMED CT importers: an empty fallback display refset is a …
jmandel Nov 22, 2026
b0cea4f
sqlite-v2 LOINC importer: an answer's external code from any of its rows
jmandel Nov 22, 2026
aeeadaa
sqlite-v2 SNOMED CT: a description id as a code is an unknown code, a…
jmandel Nov 22, 2026
f394a29
sqlite-v2 SNOMED CT: closedness of a compose decided per include and …
jmandel Nov 23, 2026
d763d0a
Merge upstream main fdb43e97 into feat/sqlite-v2-code-systems
jmandel Nov 24, 2026
8357c61
Merge upstream main 84d41223 into feat/sqlite-v2-code-systems
jmandel Nov 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 155 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
"yaml": "^2.8.2"
},
"optionalDependencies": {
"koffi": "^3.3.6"
"koffi": "^3.3.6",
"roaring": "^2.7.0"
},
"devDependencies": {
"@types/jest": "^30.0.0",
Expand Down
55 changes: 53 additions & 2 deletions tests/tx/expand-process-selection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('$expand: handing a whole compose to the provider (processSelection)',
for (const code of page) {
set.add(this.codeSystem.getConceptByCode(code));
}
const total = behaviour === 'no-total' ? -1 : behaviour === 'large' ? 1000000 : all.length;
const total = behaviour === 'no-total' ? -1 : behaviour === 'large' ? 1000000 : behaviour === 'huge' ? 1000001 : all.length;
return { sets: [set], total };
}));
}, 60000);
Expand Down Expand Up @@ -231,17 +231,38 @@ describe('$expand: handing a whole compose to the provider (processSelection)',
const vs = await expand(app, valueSet({ include: [wholeSystem] }),
[{ name: 'limit', valueInteger: 5 }, { name: 'count', valueInteger: 3 }]);
expect(codesOf(vs)).toEqual(codes.slice(0, 3));
expect(vs.expansion.total).toBe(1000000);
// no total: the selection is over the limit, and a paged walk reports none then (#finishIfPageFilled)
expect(vs.expansion.total).toBeUndefined();
});

test('a deep page is not refused: only the page counts against the limit', async () => {
behaviour = 'large';
const vs = await expand(app, valueSet({ include: [wholeSystem] }),
[{ name: 'limit', valueInteger: 5 }, { name: 'offset', valueInteger: 4 }, { name: 'count', valueInteger: 3 }]);
expect(codesOf(vs)).toEqual(codes.slice(4, 7));
expect(vs.expansion.total).toBeUndefined();
});

test('a page past the last code: the total, as the walk counts every code when its page never fills', async () => {
behaviour = 'large';
const vs = await expand(app, valueSet({ include: [wholeSystem] }),
[{ name: 'limit', valueInteger: 5 }, { name: 'offset', valueInteger: 1000000 }, { name: 'count', valueInteger: 3 }]);
expect(codesOf(vs)).toEqual([]);
expect(vs.expansion.total).toBe(1000000);
});

test('count=0 of a filter over the walk limit: too costly, as the usual path\'s counting walk; the whole system is counted', async () => {
behaviour = 'huge';
const filtered = valueSet({ include: [{ system: CS_URL, filter: [{ property: 'group', op: '=', value: 'x' }] }] });
const res = await request(app).post('/tx/r5/ValueSet/$expand').set('Content-Type', 'application/json')
.send({ resourceType: 'Parameters', parameter: [{ name: 'tx-resource', resource: CS }, { name: 'valueSet', resource: filtered },
{ name: 'count', valueInteger: 0 }] });
expect(res.status).toBe(422);
expect(res.body.issue[0].details.text).toContain('>1000000');
const vs = await expand(app, valueSet({ include: [wholeSystem] }), [{ name: 'count', valueInteger: 0 }]);
expect(vs.expansion.total).toBe(1000001);
});

test('the requested properties are on each code the provider selected', async () => {
const vs = await expand(app, valueSet({ include: [wholeSystem] }),
[{ name: 'property', valueString: 'grade' }, { name: 'count', valueInteger: 4 }]);
Expand All @@ -262,6 +283,36 @@ describe('$expand: handing a whole compose to the provider (processSelection)',
expect(codesOf(res.body)).toEqual(['c03', 'c04']);
});

// a value set that names a supplement no code system takes (replay: a Belgian SNOMED CT
// supplement for http://snomed.info/sct/11000172109, which no loaded edition is): the usual path
// reports it missing only when its walk gets to the end of the compose; a paged walk that stops
// with the expansion finished (#finishIfPageFilled) never checks. Handed over, the same answer
test.each([
['unpaged', [wholeSystem], [], [], 'handle', 422],
['a full page, the rest over the limit', [wholeSystem], [], [{ name: 'limit', valueInteger: 5 }, { name: 'count', valueInteger: 3 }], 'large', 200],
['a full page within the limit (the walk takes the size as the total)', [wholeSystem], [], [{ name: 'count', valueInteger: 3 }], 'handle', 200],
['the last page, exactly full', [wholeSystem], [], [{ name: 'offset', valueInteger: 9 }, { name: 'count', valueInteger: 3 }], 'handle', 200],
['a page that is never filled', [wholeSystem], [], [{ name: 'count', valueInteger: 50 }], 'handle', 422],
['a full page within the limit, with an exclude (the walk counts to the end)', [wholeSystem], [excludeTwo], [{ name: 'count', valueInteger: 3 }], 'handle', 422]
])('a required supplement that is not there, %s: the usual path\'s status and codes', async (_label, include, exclude, extra, handled, status) => {
const vs = valueSet({ include, exclude });
vs.extension = [{ url: 'http://hl7.org/fhir/StructureDefinition/valueset-supplement', valueCanonical: 'http://example.org/fhir/CodeSystem/no-such-supplement' }];
const run = async () => request(app).post('/tx/r5/ValueSet/$expand').set('Content-Type', 'application/json')
.send({ resourceType: 'Parameters', parameter: [{ name: 'tx-resource', resource: CS }, { name: 'valueSet', resource: vs }, ...extra] });
behaviour = 'off';
const usual = await run();
behaviour = handled;
const res = await run();
expect(calls).toHaveLength(1);
expect(usual.status).toBe(status);
expect(res.status).toBe(status);
if (status === 200) {
expect(codesOf(res.body)).toEqual(codesOf(usual.body));
} else {
expect(res.body.issue[0].details.text).toBe(usual.body.issue[0].details.text);
}
});

test.each([
['a text filter', { include: [wholeSystem] }, [{ name: 'filter', valueString: 'c03' }]],
['an enumerated concept list', { include: [{ system: CS_URL, concept: [{ code: 'c03' }, { code: 'c04' }] }] }, []],
Expand Down
91 changes: 91 additions & 0 deletions tests/tx/library-sqlite-v2.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
'use strict';

// Library: SNOMED CT, LOINC and RxNorm from sqlite-v2 files (snomed-v2:, loinc-v2:, rxnorm-v2:
// source lines). The test file is a SNOMED CT edition built from the RF2 in tx/data/snomed.

const fs = require('fs');
const os = require('os');
const path = require('path');
const { spawnSync } = require('child_process');
const { Library } = require('../../tx/library');
const folders = require('../../library/folder-setup');

const SRC = path.resolve(__dirname, '../../tx/data/snomed');
// the terminology-cache name records the file format: a file of an earlier format is not reused
const NAME = 'library-sqlite-v2-tx1-test.db';

const walk = (d) => fs.readdirSync(d, { withFileTypes: true }).flatMap((e) => (e.isDirectory() ? walk(path.join(d, e.name)) : [path.join(d, e.name)]));

// one snapshot from the test RF2's modules (as tests/tx/sqlite-v2-sct-lookup.test.js)
function mergeSnapshot(src, dst) {
const groups = new Map();
for (const f of walk(src)) {
if (!f.endsWith('.txt') || /Readme/i.test(f)) continue;
const rel = path.relative(src, f);
const key = path.join(path.dirname(rel), path.basename(rel).replace(/_(INT|TEST1000003|LO1010000)_/, '_MERGED_'));
if (!groups.has(key)) groups.set(key, []);
groups.get(key).push(f);
}
for (const [k, files] of groups) {
const out = path.join(dst, k);
fs.mkdirSync(path.dirname(out), { recursive: true });
fs.writeFileSync(out, files.flatMap((f, i) => fs.readFileSync(f, 'utf8').split(/\r?\n/).filter(Boolean).slice(i ? 1 : 0)).join('\n') + '\n');
}
}

let tmpDir;

beforeAll(async () => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'lib-sqlite-v2-'));
const target = path.join(folders.subDir('terminology-cache'), NAME);
if (!fs.existsSync(target)) {
mergeSnapshot(SRC, path.join(tmpDir, 'Snapshot'));
const { importSnomedV2 } = require('../../tx/importers/import-sct-v2.module');
await importSnomedV2({ source: path.join(tmpDir, 'Snapshot'), dest: path.join(tmpDir, NAME), edition: '31000003106', version: '20250909',
versionUri: 'http://snomed.info/xsct/31000003106/version/20250909', overwrite: true, log: () => {} });
fs.copyFileSync(path.join(tmpDir, NAME), target);
}
});

afterAll(() => {
fs.rmSync(tmpDir, { recursive: true, force: true });
});

async function load(lines) {
const yamlPath = path.join(tmpDir, 'library.yml');
fs.writeFileSync(yamlPath, 'base:\n url: https://storage.googleapis.com/tx-fhir-org\nsources:\n' + lines.map(l => ` - ${l}\n`).join(''));
const log = { info: jest.fn(), error: jest.fn(), warn: jest.fn(), debug: jest.fn() };
const library = new Library(yamlPath, undefined, log, { addStat: jest.fn() });
await library.load();
return library;
}

describe('Library: sqlite-v2 source lines', () => {
test('a library without sqlite-v2 lines loads neither the engine nor roaring', () => {
// in a fresh process: this file's own setup has loaded the importer
const yamlPath = path.join(tmpDir, 'plain.yml');
fs.writeFileSync(yamlPath, 'base:\n url: https://storage.googleapis.com/tx-fhir-org\nsources:\n - internal:lang\n');
const script = `
const { Library } = require(${JSON.stringify(path.resolve(__dirname, '../../tx/library'))});
const log = { info() {}, error() {}, warn() {}, debug() {} };
new Library(${JSON.stringify(yamlPath)}, undefined, log, { addStat() {} }).load().then(() => {
const loaded = Object.keys(require.cache).filter(f => f.includes('sqlite-v2') || f.includes('roaring'));
process.stdout.write(JSON.stringify(loaded));
process.exit(0);
}, (e) => { console.error(e); process.exit(1); });`;
const r = spawnSync(process.execPath, ['-e', script], { encoding: 'utf8', timeout: 60000 });
expect(r.status).toBe(0);
expect(JSON.parse(r.stdout.trim().split('\n').pop())).toEqual([]);
});

test('snomed-v2! registers the file\'s factory as the default SNOMED CT', async () => {
const library = await load([`snomed-v2!:${NAME}`]);
const factory = library.codeSystemFactories.get('http://snomed.info/sct');
expect(factory.constructor.name).toBe('SnomedV2Factory');
expect(library.codeSystemFactories.get('http://snomed.info/sct|' + factory.version())).toBe(factory);
});

test('a file that holds another code system than the type names stops the load', async () => {
await expect(load([`loinc-v2:${NAME}`])).rejects.toThrow(/holds http:\/\/snomed.info\/sct, not http:\/\/loinc.org/);
});
});
Loading
Loading