Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- tx: the `generalizes` filter on a code system resource (the code and its ancestors)
- tx: `vsacCfg.enabled: false` - a server whose library names VSAC (`internal:vsac`) doesn't load it, and needs no API key: a library such as tx.fhir.org.yml can be used by a server without a VSAC account. Before, the server wouldn't start

### Changed

- tx: the `cache-id` parameter is refused, wherever it is (a parameter, a part, a `$batch-validate-code` validation entry, the query): a 400 (`TX_PARAM_CACHE_ID_WITHDRAWN`) that says to start a cache with `$cache-control` and send its id in the `X-Cache-Id` header. The tx-ecosystem IG withdrew it (servers SHOULD NOT accept it); `$batch-validate-code` ignored it, so a bad cache-id went unnoticed. Clients from before June 2026 that send it already got 404 cache-id-unknown, as the server issues the ids
- tx: a media type (`urn:ietf:bcp:13`) is valid only if it follows the grammar of RFC 9110 section 8.3.1 / RFC 2045: a parameter with no name or no value, an unclosed quoted string, a value that isn't a token or a quoted string (an unquoted URI, say), and whitespace around the `/` or `=` or at the ends are invalid, and the issue says where (`MIMETYPE_INVALID`). A `;` in a quoted value is part of the value (it split the parameter, and broke the normal form)
- tx: `$subsumes` on a code system whose `hierarchyMeaning` is not is-a (part-of, grouped-by, classified-with) is refused (422, `SUBSUMPTION_CS_HIERARCHY_MEANING`), as core's: its hierarchy doesn't describe subsumption. `$closure` finds no subsumption in it
- tx: a display for a code with no display, only other designations (a synonym), that is none of them: the message says there is no known display, and names the designations (`NO_KNOWN_DISPLAY`), on every path. It was a warning with a garbled message ("one of 0 choices: ")
- tx: SNOMED CT ECL: an exclusion has one expression on each side, so `A MINUS B MINUS C` needs brackets (it was accepted); `<<125605004.363698007` (a dotted attribute with no spaces) is accepted - a number with a decimal point is only read as one after `#`
- tx: `check-system-version` never influences which version of a code system is used (community decision on Zulip, Terminology Service Test Cases, check-system-version semantics): the version is chosen as if it weren't there - from the coding, the value set, `system-version`/`force-system-version`, or the default - and the operation fails (`VALUESET_VERSION_CHECK`) if that version doesn't match. Before, when nothing else named a version, the check's version was used. This includes the edition of an implicit SNOMED CT value set, and `$closure` tables. It is no longer echoed in expansion parameters. `check-valueset-version` is unchanged
- tx-import: the sqlite-v2 importers (`loinc-v2`, `loinc-v2-classic`, `snomed-v2`, `snomed-v2-from-cache`, `rxnorm-v2`) take the classic importers' options: `-v, --version` for the release's version (`snomed-v2`'s was `--snomed-version`) and `-y, --yes` to replace an existing destination; without `-y` an existing destination is asked about. The earlier names (`--loinc-version`, `--rxnorm-version`, `--snomed-version`, `--overwrite`) still work. Documented in tx/importers/readme.md

### Fixed

- tx: a parameter whose value isn't what its value[x] says (`valueInteger: "x"`), or a known parameter with a value of the wrong kind (a `url` as a valueInteger), is a 400 (`TX_PARAM_INVALID_VALUE`, `TX_PARAM_WRONG_TYPE`), in the body or the query; it crashed, or echoed the invalid content back
- tx: a `system-version` (etc.) rule that isn't url|version is a 400 that says so (`TX_PARAM_VERSION_RULE_INVALID`)
- tx: `$expand` gave valueset-unclosed (0..1) and its reason once for each include that made the expansion unclosed (two includes of a fragment, say); now once, with the reasons together
- tx: SNOMED CT ECL `R 116680003 |Is a| = X` (reversed is-a: X's parents) matched nothing; is-a is an attribute in either direction. In sqlite-v2 files, a wildcard attribute (`* : * = X`) and `<< 246061005` include is-a, as in cs-snomed.js
- tx: SNOMED CT: a single concept written as an expression (`64572001 |Disease|`, `===64572001`) had no normal form (no `normalized-code`); it is the concept id. `<<<` (a subtype of) is kept in the normal form, of a simple expression and of a refined one (it was dropped)
- tx: SNOMED CT `$lookup` of a post-coordinated expression gave the refinement's attributes as properties when other properties were asked for; now only when they are asked for, or no property is
- tx: a designation whose use is `designation-usage#display` is a display: it is among the valid displays a wrong display is told about
- tx: a code that isn't in a fragment code system with no version said version 'null' (`UNKNOWN_CODE_IN_FRAGMENT_NO_VERSION`)
- tx: UCUM's unit `1`: a wrong display listed '1' (en) twice
- tx: a code system version that is known but can't be used for codes (content example or not-present) was listed among the valid versions when it was the one asked for; it is still listed, and says so (`CODESYSTEM_VERSION_NOT_USABLE`)
- tx: `$expand` with more than one version of a code system: the codes of an imported value set had no version, the others did
- tx: converting a ValueSet or CodeSystem to R3 treated the `generalizes` filter operator as one R3 doesn't have (a CodeSystem's was dropped, a ValueSet filter's put in the filter.op extension); STU3's filter-operator has it, as R4's does
- tx: ValueSet and ConceptMap `getFHIRVersion()` and `getInfo().fhirVersion` gave the resource's own version, not the FHIR version it was read as; ConceptMap `getInfo()` failed outright; ValueSet `getCode()`/`hasCode()` without a version didn't find a code whose expansion entry has one
- tests: the ValueSet, ConceptMap and NamingSystem library tests (tests/library/*.tests.js, 104 tests) were never run, as jest runs only *.test.js; renamed, and a test now fails when a file of tests is one jest won't run
Expand Down
85 changes: 40 additions & 45 deletions extension-tracker/extension-tracker.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const express = require('express');
const path = require('path');
const Database = require('better-sqlite3');
const sqlite3 = require('sqlite3');
const { SqlitePool } = require('../library/sql/sqlite-pool');
const { SqliteDatabase, SqliteWorkerPool } = require('../library/sql/node-sqlite');
const htmlServer = require('../library/html/html-server');
const escape = require('escape-html');
const packageJson = require('../package.json');
Expand Down Expand Up @@ -161,23 +159,24 @@ class ExtensionTrackerModule {
}

/**
* Submissions are written through one better-sqlite3 connection (a transaction, and quick).
* The pages read through a pool of sqlite3 connections (library/sql/sqlite-pool.js), so their
* queries - the unfiltered ones read whole tables - run off the event loop: better-sqlite3 is
* synchronous, and a page held the whole server while its query ran. Read-write connections
* that only read, so they see what the writer commits (WAL).
* Submissions are written through one connection on this thread (library/sql/node-sqlite.js
* SqliteDatabase: a transaction, and quick). The pages read through a pool of worker threads
* (SqliteWorkerPool), so their queries - the unfiltered ones read whole tables - run off the
* event loop: node:sqlite is synchronous, and a page's query on this thread would hold the
* whole server while it ran. Read-write connections that only read, so they see what the
* writer commits (WAL).
*/
async initialize(config, app) {
this.config = config;
const dbPath = config.database || path.join(config.folder || '.', 'extension-tracker.db');
this.db = new Database(dbPath);
this.db.pragma('journal_mode = WAL');
this.db.pragma('foreign_keys = ON');
// foreign keys on: deleting a package cascades to its extensions, profiles and usages
this.db = new SqliteDatabase(dbPath, { enableForeignKeyConstraints: true });
this.db.exec('PRAGMA journal_mode = WAL');
this.createSchema();
this.prepareStatements();
this.readDb = await SqlitePool.open(dbPath, {
this.readDb = await SqliteWorkerPool.open(dbPath, {
size: Number.isInteger(config.connections) && config.connections > 0 ? config.connections : 2,
mode: sqlite3.OPEN_READWRITE
readOnly: false
});

this.urlBase = config.url || '/ext-tracker';
Expand Down Expand Up @@ -266,24 +265,24 @@ class ExtensionTrackerModule {

prepareStatements() {
this.stmts = {
deletePackage: this.db.prepare('DELETE FROM packages WHERE package = ?'),
countSubmission: this.db.prepare(
deletePackage: this.db.statement('DELETE FROM packages WHERE package = ?'),
countSubmission: this.db.statement(
'INSERT INTO submissions (package, n, since, last_at) VALUES (?, 1, ?, ?) ' +
'ON CONFLICT (package) DO UPDATE SET n = n + 1, last_at = excluded.last_at'
),
insertPackage: this.db.prepare(
insertPackage: this.db.statement(
'INSERT INTO packages (package, version, fhir_version, jurisdiction, submitted_at) VALUES (?, ?, ?, ?, ?)'
),
insertExtension: this.db.prepare(
insertExtension: this.db.statement(
'INSERT INTO extensions (package_id, url, title) VALUES (?, ?, ?)'
),
insertExtensionType: this.db.prepare(
insertExtensionType: this.db.statement(
'INSERT INTO extension_types (extension_id, type) VALUES (?, ?)'
),
insertProfile: this.db.prepare(
insertProfile: this.db.statement(
'INSERT INTO profiles (package_id, resource_type, url, title) VALUES (?, ?, ?, ?)'
),
insertUsage: this.db.prepare(
insertUsage: this.db.statement(
'INSERT INTO usages (package_id, extension_url, location) VALUES (?, ?, ?)'
)
};
Expand Down Expand Up @@ -392,15 +391,11 @@ class ExtensionTrackerModule {
// ---- Reading (the pages) ----

all(sql, params = []) {
return new Promise((resolve, reject) => {
this.readDb.all(sql, params, (err, rows) => err ? reject(err) : resolve(rows));
});
return this.readDb.all(sql, params);
}

get(sql, params = []) {
return new Promise((resolve, reject) => {
this.readDb.get(sql, params, (err, row) => err ? reject(err) : resolve(row));
});
return this.readDb.get(sql, params);
}

// ---- Template rendering ----
Expand Down Expand Up @@ -459,32 +454,32 @@ class ExtensionTrackerModule {
}

ingestData(data) {
const ingest = this.db.transaction(() => {
this.db.transaction(() => {
// delete any existing entry for this package (cascade cleans children)
this.stmts.deletePackage.run(data.package);
this.stmts.deletePackage.run([data.package]);

// insert package
const now = new Date().toISOString();
const result = this.stmts.insertPackage.run(
const result = this.stmts.insertPackage.run([
data.package, data.version, data.fhirVersion,
data.jurisdiction || null, now
);
this.stmts.countSubmission.run(data.package, now, now);
const packageId = result.lastInsertRowid;
]);
this.stmts.countSubmission.run([data.package, now, now]);
const packageId = result.lastID;

// insert extensions
if (Array.isArray(data.extensions)) {
for (const ext of data.extensions) {
const extResult = this.stmts.insertExtension.run(packageId, ext.url, ext.title || null);
const extId = extResult.lastInsertRowid;
const extResult = this.stmts.insertExtension.run([packageId, ext.url, ext.title || null]);
const extId = extResult.lastID;

// deduplicate types
if (Array.isArray(ext.types)) {
const seen = new Set();
for (const type of ext.types) {
if (!seen.has(type)) {
seen.add(type);
this.stmts.insertExtensionType.run(extId, type);
this.stmts.insertExtensionType.run([extId, type]);
}
}
}
Expand All @@ -496,7 +491,7 @@ class ExtensionTrackerModule {
for (const [resourceType, profileList] of Object.entries(data.profiles)) {
if (Array.isArray(profileList)) {
for (const profile of profileList) {
this.stmts.insertProfile.run(packageId, resourceType, profile.url, profile.title || null);
this.stmts.insertProfile.run([packageId, resourceType, profile.url, profile.title || null]);
}
}
}
Expand All @@ -507,14 +502,13 @@ class ExtensionTrackerModule {
for (const [extUrl, locations] of Object.entries(data.usage)) {
if (Array.isArray(locations)) {
for (const location of locations) {
this.stmts.insertUsage.run(packageId, extUrl, location);
this.stmts.insertUsage.run([packageId, extUrl, location]);
}
}
}
}
});

ingest();
this.usageCache = null; // the aggregated usage page (handleUsage) is out of date now
this.generation++;
}
Expand Down Expand Up @@ -708,10 +702,10 @@ class ExtensionTrackerModule {

/**
* Usages, aggregated across packages: of one extension (?url=, as the package pages link
* to), or of all of them. The query is synchronous (better-sqlite3), and all of them is the
* whole table: 2 s and 800 KB on tx.fhir.org, which a spider following the package pages'
* links asked for 500 times a day, as the url was ignored. All of them is kept until the next
* submission (usageCache).
* to), or of all of them. All of them is the whole table: 2 s and 800 KB on tx.fhir.org (when
* the query still ran on the main thread, holding the server), which a spider following the
* package pages' links asked for 500 times a day, as the url was ignored. All of them is kept
* until the next submission (usageCache).
*/
async handleUsage(req, res) {
const startTime = Date.now();
Expand Down Expand Up @@ -908,10 +902,11 @@ class ExtensionTrackerModule {

// ---- Module lifecycle ----

shutdown() {
async shutdown() {
if (this.readDb) {
this.readDb.close();
const readDb = this.readDb;
this.readDb = null;
await readDb.close();
}
if (this.db) {
this.db.close();
Expand All @@ -925,7 +920,7 @@ class ExtensionTrackerModule {
return { status: 'closed' };
}
// synchronous (the server's status asks for it so), but the packages table is small
const count = this.db.prepare('SELECT COUNT(*) as count FROM packages').get().count;
const count = this.db.get('SELECT COUNT(*) as count FROM packages').count;
this.stats.countRequest('search', Date.now() - startTime);
return { status: 'running', packages: count };
}
Expand Down
3 changes: 2 additions & 1 deletion library/fhir/fhirpath/fhirpath-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,8 @@ class FHIRPathEngine {
this.checkParamTypes(exp, code, paramTypes, S(FP_String));
const p = exp.parameters[0];
if (p.kind === Kind.Constant && p.constant != null) {
const url = primitiveValue(p.constant);
// (a %constant as it was written, as Java has it - for the warning when it isn't known)
const url = p.constant.type === 'constant' ? javaConstant(primitiveValue(p.constant)) : primitiveValue(p.constant);
if (!isAbsoluteUrl(url) && focus.hasType('Extension')) {
const res = new TypeDetails(CollectionStatus.ORDERED);
const profiles = focus.getProfiles('Extension');
Expand Down
Loading
Loading