Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
c54a2b2
sqlite-v2 meta: requires, known keys checked, unknown keys ignored
jmandel Dec 3, 2026
9f9cfbe
sqlite-v2: identifier.value declared TEXT; files require identifier-text
jmandel Dec 3, 2026
65e37be
sqlite-v2 word index: the names selection as data, stemmers per langu…
jmandel Dec 3, 2026
c3623d9
sqlite-v2: behaviour and order keys are obeyed from the file
jmandel Dec 3, 2026
928f49a
sqlite-v2: grammar is an open name with a registry; behaviour.filters…
jmandel Dec 3, 2026
6ed4d20
sqlite-v2: contracts written down and checked by the builder; drop n_…
jmandel Dec 3, 2026
d40acfe
sqlite-v2: optional integrity facts and verify.js
jmandel Dec 3, 2026
24d7be2
sqlite-v2: property.report never, behaviour.expansionLimit
jmandel Dec 3, 2026
22e30f6
sqlite-v2: remove the dead readBehaviour body; lint
jmandel Dec 3, 2026
3f5467f
sqlite-v2: $expand of a file with behaviour.expansionLimit
jmandel Dec 3, 2026
7a9e1f5
sqlite-v2 RxNorm: which properties $lookup reports is catalog data
jmandel Dec 3, 2026
f2b6703
sqlite-v2: remove behaviour.description
jmandel Dec 4, 2026
6238914
sqlite-v2: behaviour.lookupDesignationCode
jmandel Dec 4, 2026
3351557
sqlite-v2: lookupCopyright; contracts for requires and the word-index…
jmandel Dec 4, 2026
2217d4e
sqlite-v2 README: versionAlgorithm's meaning and default
jmandel Dec 4, 2026
83fdf38
sqlite-v2 tests: the values both readers agree on
jmandel Dec 4, 2026
fa78589
sqlite-v2: agree with the other reader on two file facts
jmandel Dec 4, 2026
3ef7683
sqlite-v2: verify.js exits 1 for every failure; report text for ICD-1…
jmandel Dec 4, 2026
495683a
sqlite-v2: an absent versionAlgorithm matches exactly
jmandel Dec 4, 2026
1241e08
sqlite-v2: no reader paths for files built before a key existed
jmandel Dec 4, 2026
8d5ecb6
sqlite-v2: reported names and the status literal are catalog data
jmandel Dec 4, 2026
5e7762b
sqlite-v2: the text search and its tie order are named in the file
jmandel Dec 4, 2026
37b05ee
sqlite-v2: behaviour.aliases replaces the three alias keys
jmandel Dec 4, 2026
6afd283
sqlite-v2: property.named_links replaces behaviour.lookupSkipsMixedLinks
jmandel Dec 4, 2026
11a2ff4
sqlite-v2: searchTieBreak code-length; refuse a catalog without the r…
jmandel Dec 4, 2026
ebf0322
sqlite-v2: behaviour.domain names the concepts answers select
jmandel Dec 4, 2026
b2fe096
sqlite-v2: the catalog id is the stored resource's id
jmandel Dec 4, 2026
373e440
sqlite-v2: names selection includeUses; LOINC and RxNorm selections s…
jmandel Dec 4, 2026
fddf7ba
sqlite-v2: item_use.reported_as, an item use reported as a property
jmandel Dec 4, 2026
ab4f854
sqlite-v2: SNOMED CT semanticTag stored as a literal
jmandel Dec 4, 2026
8a70dae
sqlite-v2: behaviour.lookupOrder orders $lookup's properties
jmandel Dec 4, 2026
e9454ba
sqlite-v2: behaviour.implicitMaps, the implicit ConceptMaps over mapp…
jmandel Dec 4, 2026
6c87a66
sqlite-v2: partial versions resolved by versionAlgorithm
jmandel Dec 4, 2026
9a52d81
sqlite-v2: the stored resource id is the CodeSystem id as it is; the …
jmandel Dec 4, 2026
e9742ed
sqlite-v2: behaviour.domain naming no catalog property refuses the file
jmandel Dec 4, 2026
e96e47a
sqlite-v2: item_use.role (fsn, synonym, name)
jmandel Dec 4, 2026
139319f
sqlite-v2: plain answer facts as behaviour keys
jmandel Dec 4, 2026
03cbd8f
sqlite-v2: the sweep's remaining facts as data (status, deprecation, …
jmandel Dec 4, 2026
3b66c7f
sqlite-v2: property filter and presentation facts; LOINC catalog rows
jmandel Dec 4, 2026
aa2ae51
sqlite-v2: listed filters over stored properties; concept in a relati…
jmandel Dec 4, 2026
e77818d
sqlite-v2: displayDesignation defaults to first
jmandel Dec 4, 2026
efbee67
sqlite-v2: three unknown-code messages (locate, filter locate, filter…
jmandel Dec 4, 2026
51c10ac
sqlite-v2: LOINC states no deprecated status
jmandel Dec 4, 2026
2734c3c
sqlite-v2: unknownCodeVersion dropped from the format
jmandel Dec 4, 2026
8db6b86
sqlite-v2: meta propertyUris is a known key
jmandel Dec 4, 2026
be5ca21
sqlite-v2 README: the plain selection row names no further systems
jmandel Dec 4, 2026
5dff821
sqlite-v2: proposal for the next format revision
jmandel Dec 4, 2026
8687251
sqlite-v2 reader: read only the fhir-reading revision
jmandel Dec 4, 2026
3da8483
sqlite-v2 importers: write the fhir-reading revision
jmandel Dec 4, 2026
f20bbc4
sqlite-v2: keep the previous answers at the revision's open points; t…
jmandel Dec 4, 2026
0553330
sqlite-v2 reader: follow the settled revision at its former open points
jmandel Dec 4, 2026
18b42db
sqlite-v2 reader: the final revision's keys (expansionNeverNests, for…
jmandel Dec 4, 2026
fc3febe
sqlite-v2 importers: write the final revision
jmandel Dec 4, 2026
0f3f25a
sqlite-v2 README: the final revision
jmandel Dec 4, 2026
4e484e2
sqlite-v2 reader: alias_literals (NDC 11-digit codes in their own right)
jmandel Dec 5, 2026
695a275
sqlite-v2 reader: implicitMaps.used (OMOP)
jmandel Dec 5, 2026
934f937
sqlite-v2 reader: the grammar cpt (codes with modifiers)
jmandel Dec 5, 2026
531baac
sqlite-v2 reader: the grammar icd11, alias_parameter and alias_extens…
jmandel Dec 5, 2026
793c1d5
sqlite-v2 reader: fhir_type date as a dateTime; the known differences…
jmandel Dec 5, 2026
e806ca0
sqlite-v2 reader: SNOMED CT ancestors nearest first; an include's fir…
jmandel Dec 5, 2026
1268800
sqlite-v2 reader: CPT $lookup of an expression reports its own notSel…
jmandel Dec 5, 2026
10e74bc
sqlite-v2 reader: ICD-11 answers as upstream's provider; whole-system…
jmandel Dec 5, 2026
53f7f7a
sqlite-v2 README: stored link order of inverse links, nesting, icd11 …
jmandel Dec 5, 2026
d8c37c4
sqlite-v2 provider: comment back on its constant
jmandel Dec 5, 2026
e02a0d3
sqlite-v2 format: literal.seq, read by order.literals stored
jmandel Dec 5, 2026
cd0c478
sqlite-v2 README: NDC multi-valued literals and OMOP domain order now…
jmandel Dec 5, 2026
70454ab
sqlite-v2 README: ICD-11 text search equals the provider's on an inde…
jmandel Dec 5, 2026
2fc4531
sqlite-v2 engine: an include of the whole system walks the stored wal…
jmandel Dec 5, 2026
7cf5ddd
sqlite-v2 README: known differences for whole-system count=0 of LOINC…
jmandel Dec 5, 2026
04cb1cb
Merge origin/main into sqlite-v2-format-round2
jmandel Dec 5, 2026
8b205ea
sqlite-v2: code links from the file (meta codeLink)
jmandel Dec 5, 2026
d3ca088
sqlite-v2: hierarchyMeaning from code_system.hierarchy_meaning
jmandel Dec 5, 2026
4a524b6
sqlite-v2 SNOMED CT: expressions in $validate-code; <<< X answers as X
jmandel Dec 5, 2026
801a301
Merge origin/main into sqlite-v2-format-round2
jmandel Dec 5, 2026
704cbca
SNOMED CT classic import: append references without recopying the buffer
jmandel Dec 5, 2026
239170a
sqlite-v2 README: known differences from main, re-checked
jmandel Dec 5, 2026
61a8b4c
sqlite-v2 icd11: label an expression's display with the language of i…
jmandel Dec 5, 2026
70500b1
sqlite-v2: concept in a reference set of descriptions is refused, as …
jmandel Dec 5, 2026
0c733bc
sqlite-v2 rxnorm: REL / RELA = AUI:<rxaui> filters from the atom-leve…
jmandel Dec 5, 2026
352a082
sqlite-v2 README: known difference, RxNorm = values with white space …
jmandel Dec 5, 2026
0ababfb
sqlite-v2: fix 6 parity bugs in SNOMED SCG/ECL/refsets, captured exis…
jmandel Dec 6, 2026
f949795
sqlite-v2: align unsupported ECL description filter error wording
jmandel Dec 6, 2026
90bcb26
sqlite-v2: fix 5 ordering/dedup parity bugs (answers-for in, concept …
jmandel Dec 6, 2026
7b68f96
sqlite-v2: support <property>.details (e.g. ICD-11 source.details) in
jmandel Dec 6, 2026
0304a0c
Fix 5 sqlite-v2 SNOMED ECL & post-coordination bugs
jmandel Dec 6, 2026
5372ffb
Fix sqlite-v2 _roots() whole-system walk order for explicit-closure s…
jmandel Dec 6, 2026
db5854b
sqlite-v2: refuse non-enumerable supplement-only filters on $expand (…
jmandel Dec 6, 2026
b8e305f
Merge remote-tracking branch 'origin/main' into sqlite-v2-format-round2
jmandel Dec 6, 2026
7cbc8e5
sqlite-v2: handle DottedExpressionConstraint in SCG ECL membership
jmandel Dec 6, 2026
ba4f5d1
sqlite-v2: ignore item-subject refset rows in ECL HISTORY supplements
jmandel Dec 6, 2026
e42b3ce
sqlite-v2: implement missing refSetMembers and refs methods in ECL fa…
jmandel Dec 6, 2026
fec10d4
sqlite-v2: reject unknown attribute ConceptReference in ECL eclAttrIds
jmandel Dec 6, 2026
296f9a7
Merge remote-tracking branch 'origin/main' into sqlite-v2-format-round2
jmandel Dec 6, 2026
7c27a3f
sqlite-v2: harden NDC, UNII, and CPT support (closed-filter CPT #486,…
jmandel Dec 6, 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
3 changes: 2 additions & 1 deletion library/server/config-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,8 @@ const RETIRED_SOURCE_TYPES = {
rxnorm: 'is no longer a source type: RxNorm is served from a sqlite-v2 file - import the release with tx-import rxnorm-v2, and load it with rxnorm-v2:<file> (tx/importers/readme.md)'
};
const SOURCE_TYPES = ['internal', 'ucum', 'loinc', 'ndc', 'unii', 'snomed', 'cpt', 'omop', 'icd11',
'snomed-v2', 'loinc-v2', 'rxnorm-v2', 'npm', 'npm/cs', 'url', 'url/cs', 'ocl', 'folder', 'file'];
'sqlite-v2', 'snomed-v2', 'loinc-v2', 'rxnorm-v2', 'ndc-v2', 'unii-v2', 'cpt-v2',
'npm', 'npm/cs', 'url', 'url/cs', 'ocl', 'folder', 'file'];

/**
* The tx library yml: it parses, has a base url, and its sources are type[!]:details[=prefix]
Expand Down
15 changes: 11 additions & 4 deletions tests/cs/code-links.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,33 @@ describe('codeLink', () => {
});

describe('sqlite-v2 files: the links main\'s providers give', () => {
// a factory with only what codeLink reads: the file's system and version
const v2 = (cls, system, version = '1') => factory(cls, { store: { system, version, cs: {} } });
// a factory with only what codeLink reads: the file's system, version and meta codeLink (the
// template the importer writes; the `snomed` grammar has its own links)
const v2 = (cls, system, version = '1', codeLink = null) => factory(cls, { store: { system, version, cs: {}, codeLink } });
const { LOINC_READING } = require('../../tx/importers/import-loinc-v2.module');
const { RXNORM_READING } = require('../../tx/importers/import-rxnorm-v2.module');

test('LOINC: codes, parts and answers link to loinc.org', () => {
const f = v2(SqliteV2Factory, 'http://loinc.org', '2.83');
const f = v2(SqliteV2Factory, 'http://loinc.org', '2.83', LOINC_READING.meta.codeLink);
expect(f.codeLink(new V2Concept(1, '2345-7'))).toBe('https://loinc.org/2345-7/');
expect(f.codeLink(new V2Concept(2, 'LP14355-9'))).toBe('https://loinc.org/LP14355-9/');
expect(f.codeLink(new V2Concept(3, 'LA6576-8'))).toBe('https://loinc.org/LA6576-8/');
expect(f.codeLink(null)).toBeUndefined();
});

test('RxNorm links to RxNav', () => {
const f = v2(SqliteV2Factory, 'http://www.nlm.nih.gov/research/umls/rxnorm', '11022026');
const f = v2(SqliteV2Factory, 'http://www.nlm.nih.gov/research/umls/rxnorm', '11022026', RXNORM_READING.meta.codeLink);
expect(f.codeLink(new V2Concept(1, '161'))).toBe('https://mor.nlm.nih.gov/RxNav/search?searchBy=RXCUI&searchTerm=161');
expect(f.codeLink(new V2Concept(1, null))).toBeUndefined();
expect(f.codeLink(null)).toBeUndefined();
});

test('any other system in a sqlite-v2 file: no link', () => {
expect(v2(SqliteV2Factory, 'http://example.org/cs').codeLink(new V2Concept(1, 'x'))).toBeUndefined();
// the link is the file's, not the system's: a LOINC file without meta codeLink has none
expect(v2(SqliteV2Factory, 'http://loinc.org', '2.83').codeLink(new V2Concept(1, '2345-7'))).toBeUndefined();
expect(v2(SqliteV2Factory, 'http://example.org/cs', '1', 'https://example.org/c/{code}').codeLink(new V2Concept(1, 'a b/c')))
.toBe('https://example.org/c/a%20b%2Fc');
});

describe('SNOMED CT: as cs-snomed.js', () => {
Expand Down
5 changes: 5 additions & 0 deletions tests/library/server/config-check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ describe('config-check', () => {
expect(report.errors.map(e => e.message)).toEqual([expect.stringContaining('\'rxnorm\' is no longer a source type: RxNorm is served from a sqlite-v2 file')]);
});

test('the library: sqlite-v2, ndc-v2, unii-v2, and cpt-v2 source types are accepted', () => {
const report = check(txConfig({ librarySource: library('base:\n url: https://example.org\nsources:\n - sqlite-v2:omop.db\n - ndc-v2!:ndc.db\n - unii-v2:unii.db\n - cpt-v2:cpt.db\n') }));
expect(report.errors).toEqual([]);
});

test('the library: no base url, and YAML that doesn\'t parse', () => {
expect(check(txConfig({ librarySource: library('sources:\n - internal:lang\n') })).errors[0].message).toContain('no base: url:');
expect(check(txConfig({ librarySource: library('base: [\n') })).errors[0].message).toContain('can\'t be read');
Expand Down
9 changes: 9 additions & 0 deletions tests/tx/library-sqlite-v2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,14 @@ describe('Library: sqlite-v2 source lines', () => {

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/);
await expect(load([`ndc-v2:${NAME}`])).rejects.toThrow(/holds http:\/\/snomed.info\/sct, not http:\/\/hl7.org\/fhir\/sid\/ndc/);
await expect(load([`unii-v2:${NAME}`])).rejects.toThrow(/holds http:\/\/snomed.info\/sct, not http:\/\/fdasis.nlm.nih.gov/);
await expect(load([`cpt-v2:${NAME}`])).rejects.toThrow(/holds http:\/\/snomed.info\/sct, not http:\/\/www.ama-assn.org\/go\/cpt/);
});

test('sqlite-v2 accepts any code system file', async () => {
const library = await load([`sqlite-v2!:${NAME}`]);
const factory = library.codeSystemFactories.get('http://snomed.info/sct');
expect(factory.constructor.name).toBe('SnomedV2Factory');
});
});
211 changes: 211 additions & 0 deletions tests/tx/sqlite-v2-alias-literals.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
'use strict';

// property.alias_literals (README.md "Alternate codes"): an identifier scheme whose identifiers with
// resolves = 2 are codes in their own right (NDC's 11-digit forms of its 10-digit package codes).
// A code read through such an identifier reports the scheme's alias_literals instead of the concept's
// stored values ({code}: the concept's own code); a filter `=` the template's value on one of those
// properties lists the scheme's identifiers, in the order of their concepts; a membership check of
// such a code tests those properties by the template and every other property by its concept. The
// fixture is a small file of the same shape as the NDC importer's, nothing in it real.

const fs = require('fs');
const os = require('os');
const path = require('path');
const request = require('supertest');
const { getTestApp, getTxModule, shutdownTestApp } = require('./setup');
const { TerminologyBuilder } = require('../../tx/importers/sqlite-v2/builder');
const { loadSqliteV2Factory } = require('../../tx/sqlite-v2');

const URI = 'http://example.org/packages';
let app, tx, dir, factory;

function build(file) {
const b = new TerminologyBuilder(file, { overwrite: true, importer: 'test' });
b.codeSystem({ uri: URI, version: '20260101', name: 'Packages' });
const codeType = b.property({ code: 'code-type', shape: 'literal', fhirType: 'string', lookupRank: 1 });
const synonym = b.property({ code: 'synonym', shape: 'literal', fhirType: 'string', lookupRank: 2 });
const kind = b.property({ code: 'kind', shape: 'literal', fhirType: 'string', lookup: 'never', expansion: 'never' });
const active = b.property({ code: 'active', shape: 'literal', fhirType: 'string', lookupRank: 6 });
const category = b.property({ code: 'category', shape: 'literal', fhirType: 'string', lookupRank: 11 });
const code11 = b.property({ code: 'code11', shape: 'identifier', lookup: 'never', expansion: 'never',
aliasLiterals: { 'code-type': '11-digit', synonym: '{code}' } });
const rows = [
// code, kind, code-type, 11-digit form, active, category
['1111-222', 'product', 'product', null, true, 'A'],
['1111-222-33', 'package', '10-digit', '01111022233', true, 'A'],
['1111-222-44', 'package', '10-digit', '01111022244', false, 'A'],
['5555-666', 'product', 'product', null, true, 'B'],
['5555-666-77', 'package', '10-digit', '05555066677', true, 'B'],
];
for (const [code, k, type, c11, act, cat] of rows) {
const c = b.concept(code, { display: `${k} ${code}` });
b.item(c, { language: 'en', text: `${k} ${code}`, preferred: true });
b.literal(c, kind, k);
b.literal(c, codeType, type);
b.literal(c, active, act ? 'true' : 'false');
b.literal(c, category, cat);
if (c11) {
b.literal(c, synonym, c11);
b.identifier(code11, c11, c, { resolves: 2 });
}
}
b.reading({
meta: { conceptStatus: [{ property: 'active', values: { false: ['inactive'] } }], version: { match: 'prefix' } },
filters: [
{ code: 'inactive', operators: ['='], reads: 'inactive', allowedValues: ['true', 'false'] },
{ code: 'kind', operators: ['='], reads: 'kind', allowedValues: ['product', 'package'], valueCase: 'exact' },
{ code: 'category', operators: ['=', 'in'], reads: 'category', valueCase: 'exact' },
{ code: 'code-type', operators: ['='], reads: 'code-type', allowedValues: ['10-digit', '11-digit', 'product'], valueCase: 'exact' },
],
});
b.finish();
}

beforeAll(async () => {
dir = fs.mkdtempSync(path.join(process.env.SQLITE_V2_TEST_TMP || os.tmpdir(), 'sqlite-v2-alias-'));
const file = path.join(dir, 'packages.db');
build(file);
app = await getTestApp();
tx = getTxModule();
factory = await loadSqliteV2Factory(tx.i18n, file);
const p = tx.endpoints[0].provider;
p.codeSystemFactories.set(URI, factory);
p.codeSystemFactories.set(URI + '|20260101', factory);
}, 60000);

afterAll(async () => {
factory.store.close();
await shutdownTestApp();
fs.rmSync(dir, { recursive: true, force: true });
});

const vs = (include) => ({ resourceType: 'ValueSet', status: 'active', compose: { include: [{ system: URI, ...include }] } });

async function post(op, parameter) {
for (const e of tx.endpoints) e.expansionCache.clearAll();
return request(app).post(`/tx/r5/${op}`).send({ resourceType: 'Parameters', parameter });
}

async function expand(include, extras = []) {
const res = await post('ValueSet/$expand', [{ name: 'valueSet', resource: vs(include) }, ...extras]);
expect(res.status).toBe(200);
return (res.body.expansion.contains || []).map((c) => c.code);
}

async function expandRaw(include, extras = []) {
const res = await post('ValueSet/$expand', [{ name: 'valueSet', resource: vs(include) }, ...extras]);
expect(res.status).toBe(200);
return res.body.expansion;
}

async function lookup(code) {
const res = await post('CodeSystem/$lookup', [{ name: 'system', valueUri: URI }, { name: 'code', valueCode: code }]);
expect(res.status).toBe(200);
return {
display: res.body.parameter.find((p) => p.name === 'display').valueString,
props: res.body.parameter.filter((p) => p.name === 'property' && p.part[0].valueCode !== 'inactive').map((p) => [p.part[0].valueCode, p.part[1].valueString ?? p.part[1].valueCode]),
};
}

async function validate(code, include) {
const parameter = [{ name: 'system', valueUri: URI }, { name: 'code', valueCode: code }];
if (include) parameter.push({ name: 'valueSet', resource: vs(include) });
const res = await post(include ? 'ValueSet/$validate-code' : 'CodeSystem/$validate-code', parameter);
expect(res.status).toBe(200);
const p = (n) => (res.body.parameter.find((x) => x.name === n) || {});
return { result: p('result').valueBoolean, code: p('code').valueCode, display: p('display').valueString };
}

const f = (property, op, value) => ({ property, op, value });

test('the file loads: alias_literals is read, not refused', () => {
expect(factory.store.aliasSchemes.map((d) => [d.code, d.aliasLiterals])).toEqual([['code11', { 'code-type': '11-digit', synonym: '{code}' }]]);
});

test('$lookup of an 11-digit form: the code as written, the template values in place of the stored ones', async () => {
const r = await lookup('01111022233');
expect(r.display).toBe('package 1111-222-33');
expect(r.props).toEqual([['code-type', '11-digit'], ['synonym', '1111-222-33'], ['active', 'true'], ['category', 'A']]);
const own = await lookup('1111-222-33');
expect(own.props).toEqual([['code-type', '10-digit'], ['synonym', '01111022233'], ['active', 'true'], ['category', 'A']]);
});

test('$validate-code against the system: the 11-digit form is a code, answered as written', async () => {
expect(await validate('05555066677')).toEqual({ result: true, code: '05555066677', display: 'package 5555-666-77' });
expect((await validate('05555066678')).result).toBe(false);
});

test('code-type = 11-digit lists the 11-digit forms, in their concepts\' order; other filters cut them by their concept', async () => {
// (concept id order: the inactive package is numbered after the active concepts)
expect(await expand({ filter: [f('code-type', '=', '11-digit')] })).toEqual(['01111022233', '05555066677', '01111022244']);
expect(await expand({ filter: [f('code-type', '=', '11-digit'), f('inactive', '=', 'false')] })).toEqual(['01111022233', '05555066677']);
expect(await expand({ filter: [f('code-type', '=', '11-digit'), f('category', '=', 'B')] })).toEqual(['05555066677']);
// the other code types list the concepts' own codes only
expect(await expand({ filter: [f('code-type', '=', '10-digit')] })).toEqual(['1111-222-33', '5555-666-77', '1111-222-44']);
expect(await expand({ filter: [f('kind', '=', 'package'), f('inactive', '=', 'false')] })).toEqual(['1111-222-33', '5555-666-77']);
});

test('membership of an 11-digit form: the template decides code-type, its concept the rest', async () => {
expect((await validate('01111022233', { filter: [f('code-type', '=', '11-digit')] })).result).toBe(true);
expect((await validate('01111022233', { filter: [f('code-type', '=', '10-digit')] })).result).toBe(false);
expect((await validate('01111022233', { filter: [f('kind', '=', 'package')] })).result).toBe(true);
expect((await validate('01111022244', { filter: [f('code-type', '=', '11-digit'), f('inactive', '=', 'false')] })).result).toBe(false);
expect((await validate('1111-222-33', { filter: [f('code-type', '=', '11-digit')] })).result).toBe(false);
});

test('an include that lists an 11-digit form expands it as written', async () => {
expect(await expand({ concept: [{ code: '05555066677' }, { code: '1111-222' }] })).toEqual(['05555066677', '1111-222']);
expect((await validate('05555066677', { concept: [{ code: '05555066677' }] })).result).toBe(true);
});

test('whole code system $expand (#485): count=0, paged, and full walk list all products and 10-digit packages', async () => {
const counted = await expandRaw({}, [{ name: 'count', valueInteger: 0 }]);
expect(counted.total).toBe(5);
expect(counted.contains).toBeUndefined();

const page = await expandRaw({}, [{ name: 'count', valueInteger: 2 }]);
expect(page.total).toBe(5);
expect(page.contains.length).toBe(2);

const offsetPage = await expandRaw({}, [{ name: 'offset', valueInteger: 2 }, { name: 'count', valueInteger: 2 }]);
expect(offsetPage.total).toBe(5);
expect(offsetPage.contains.length).toBe(2);

const full = await expandRaw({});
expect(full.total).toBe(5);
expect(full.contains.map((c) => c.code).sort()).toEqual(['1111-222', '1111-222-33', '1111-222-44', '5555-666', '5555-666-77']);
});

test('combined category + code-type = 11-digit in either order (#484): expand, count=0, paging, and validate-code', async () => {
const catFirst = [f('category', '=', 'A'), f('code-type', '=', '11-digit')];
const typeFirst = [f('code-type', '=', '11-digit'), f('category', '=', 'A')];
for (const filter of [catFirst, typeFirst]) {
const exp = await expandRaw({ filter });
expect(exp.total).toBe(2);
expect(exp.contains.map((c) => c.code)).toEqual(['01111022233', '01111022244']);
const counted = await expandRaw({ filter }, [{ name: 'count', valueInteger: 0 }]);
expect(counted.total).toBe(2);
const page = await expandRaw({ filter }, [{ name: 'count', valueInteger: 1 }]);
expect(page.total).toBe(2);
expect(page.contains.map((c) => c.code)).toEqual(['01111022233']);
// 11-digit form is in, 10-digit form is not
expect((await validate('01111022233', { filter })).result).toBe(true);
expect((await validate('1111-222-33', { filter })).result).toBe(false);
}
// contradictory 10-digit and 11-digit together: empty
const both = [f('code-type', '=', '10-digit'), f('code-type', '=', '11-digit')];
const empty = await expandRaw({ filter: both });
expect(empty.total).toBe(0);
expect(empty.contains).toBeUndefined();
expect((await validate('01111022233', { filter: both })).result).toBe(false);
expect((await validate('1111-222-33', { filter: both })).result).toBe(false);
});

test('$expand with property=* on code-type = 11-digit reports template code-type and synonym', async () => {
const exp = await expandRaw({ filter: [f('category', '=', 'B'), f('code-type', '=', '11-digit')] }, [{ name: 'property', valueCode: '*' }]);
expect(exp.contains.length).toBe(1);
const props = new Map(exp.contains[0].property.map((p) => [p.code, p.valueString ?? p.valueCode]));
expect(props.get('code-type')).toBe('11-digit');
expect(props.get('synonym')).toBe('5555-666-77');
expect(props.get('category')).toBe('B');
});
Loading
Loading