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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

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

Expand All @@ -26,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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
- tx: a request with no client side cache over uncachedMaxBodyMB, behind the cluster launcher, mostly got a 502 "the tx process did not answer (EPIPE)", not the 413 too-costly: the process answered and closed the connection with the body still coming. It now takes the rest of the body (without parsing it) and then answers (#461)
- tx: a JSON Bundle (a search page, say) was made in one go: a search for CodeSystems, 200 a page, with no _summary or _elements, made a page of 89 MB and held the server for 3 seconds (tx.fhir.org). A Bundle is now made an entry at a time, letting other requests run between, and written out in its parts (with no ETag: it isn't hashed)
- The shl module and the VSAC value set database turned on sqlite3's verbose mode, which is for the whole process: every query of every module (the XIG and packages on npm.fhir.org) then captured a stack trace and formatted its arguments, to make the stack of an error longer. It is no longer turned on

### Removed

Expand Down
3 changes: 1 addition & 2 deletions library/fhir/fhirpath/expression-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const FUNCTION_CODES = {
ConvertsToQuantity: 'convertsToQuantity', ConvertsToDateTime: 'convertsToDateTime',
ConvertsToDate: 'convertsToDate', ConvertsToTime: 'convertsToTime', ToBoolean: 'toBoolean',
ToInteger: 'toInteger', ToString: 'toString', ToDecimal: 'toDecimal', ToQuantity: 'toQuantity',
ToDateTime: 'toDateTime', ToTime: 'toTime', ConformsTo: 'conformsTo',
ToDateTime: 'toDateTime', ToDate: 'toDate', ToTime: 'toTime', ConformsTo: 'conformsTo',
Round: 'round', Sqrt: 'sqrt', Abs: 'abs', Ceiling: 'ceiling', Exp: 'exp', Floor: 'floor',
Ln: 'ln', Log: 'log', Power: 'power', Truncate: 'truncate',
// R3 functions
Expand Down Expand Up @@ -95,7 +95,6 @@ function functionFromCode(name) {

/**
* The name of a function in an expression ('?custom?' for Custom, which has none of its own).
* (Java's toCode gives 'isTime' for ConvertsToTime; this doesn't follow that.)
* @param {string} f
* @returns {string}
*/
Expand Down
8 changes: 6 additions & 2 deletions library/fhir/fhirpath/fhirpath-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ class IssueMessage {
}
}

/** Java's Function.toCode(): as functionToCode, but ConvertsToTime is 'isTime' */
/** Java's Function.toCode() */
function toCode(f) {
return f === Function.ConvertsToTime ? 'isTime' : functionToCode(f);
return functionToCode(f);
}

const uncapitalize = (s) => (s ? s.charAt(0).toLowerCase() + s.substring(1) : s);
Expand Down Expand Up @@ -1561,6 +1561,10 @@ class FHIRPathEngine {
case Function.ToBoolean:
this.checkContextPrimitive(focus, 'toBoolean', false, exp);
return S(FP_Boolean);
case Function.ToDate:
// the engines have no Date type of their own: a date is a DateTime, as @2015 and today() are
this.checkContextPrimitive(focus, 'toDate', false, exp);
return S(FP_DateTime);
case Function.ToDateTime:
this.checkContextPrimitive(focus, 'ToDateTime', false, exp);
return S(FP_DateTime);
Expand Down
10 changes: 4 additions & 6 deletions library/fhir/fhirpath/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
* was written.
*
* Where this differs from Java's parser:
* - a unary +/- applies to its operand, as the grammar says ("-a + b" is (-a) + b; Java's
* parser makes it -(a + b)). In an operator chain, it's a Group, since a Unary node has
* its own operation
* - an operator chain starts on the first node of its first operand, also when that operand
* starts with an indexer (Java's parser puts it on the indexer: "a[0] + b")
* - a unary +/- applies to its operand, as the grammar says ("-a + b" is (-a) + b; when the
* unary starts the expression, Java's parser makes it -(a + b)). In an operator chain, it's a
* Group, since a Unary node has its own operation (as Java's parser has it too)
* - a function's end is after its ')' (Java: after its name)
* - sort()'s arguments can have asc / desc after them: the parameter's `direction`
* - more than one indexer in a row ("a[0][1]") is allowed
Expand Down Expand Up @@ -65,7 +63,7 @@ const PARAM_COUNTS = {
HasValue: [0, 0], Encode: [1, 1], Decode: [1, 1], Escape: [1, 1], Unescape: [1, 1],
Trim: [0, 0], Split: [1, 1], Join: [0, 1], HtmlChecks1: [0, 0], HtmlChecks2: [0, 0],
Comparable: [1, 1], ToInteger: [0, 0], ToDecimal: [0, 0], ToString: [0, 0],
ToQuantity: [0, 0], ToBoolean: [0, 0], ToDateTime: [0, 0], ToTime: [0, 0],
ToQuantity: [0, 0], ToBoolean: [0, 0], ToDateTime: [0, 0], ToDate: [0, 0], ToTime: [0, 0],
ConvertsToInteger: [0, 0], ConvertsToDecimal: [0, 0], ConvertsToString: [0, 0],
ConvertsToQuantity: [0, 0], ConvertsToBoolean: [0, 0], ConvertsToDateTime: [0, 0],
ConvertsToDate: [0, 0], ConvertsToTime: [0, 0], ConformsTo: [1, 1], Round: [0, 1],
Expand Down
2 changes: 1 addition & 1 deletion library/server/config-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ function checkFile(file, where, report, what) {
}

const SOURCE_TYPES = ['internal', 'ucum', 'loinc', 'rxnorm', 'ndc', 'unii', 'snomed', 'cpt', 'omop', 'icd11',
'npm', 'npm/cs', 'url', 'url/cs', 'ocl', 'folder', 'file'];
'snomed-v2', 'loinc-v2', 'rxnorm-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
1 change: 1 addition & 0 deletions library/server/daily-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const MODULE_TITLES = {
tx: 'Terminology server',
registry: 'Terminology server registry',
packages: 'Packages',
rest: 'FHIR REST',
xig: 'XIG',
shl: 'SMART Health Links',
ips: 'IPS',
Expand Down
8 changes: 7 additions & 1 deletion rest/endpoint/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,13 @@ class Endpoint {
}
} finally {
if (this.options.stats) {
this.options.stats.countRequest(interaction, Date.now() - start);
// under the endpoint, for the daily report (rest.js); a bundle as what it is
let name = interaction;
if (name === 'bundle') {
const type = freq && freq.body && freq.body.type;
name = type === 'transaction' || type === 'batch' ? type : 'bundle';
}
this.options.stats.countRequest(name, Date.now() - start, this.path);
}
}
}
Expand Down
56 changes: 56 additions & 0 deletions rest/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,48 @@ class RestModule {
return this.endpoints.map(ep => ep.path);
}

/**
* The module's paragraph in the daily report (library/server/daily-report.js): for each
* endpoint, its reads, searches, writes and transactions over the period (and batches,
* and anything else, when there were any)
*/
dailyReport({ since, now }) {
if (!this.stats) {
return null;
}
const counts = this.stats.countsSince(since, now);
// the configured endpoints first, in order, then any counted that aren't configured now
const paths = this.endpoints.map(ep => ep.path);
for (const p of Object.keys(counts.endpoints || {})) {
if (!paths.includes(p)) {
paths.push(p);
}
}
if (!paths.length) {
return null;
}
const n = (count, word, plural) => `${count.toLocaleString('en-US')} ${count === 1 ? word : (plural || word + 's')}`;
const lines = paths.map(p => {
const ops = (counts.endpoints && counts.endpoints[p]) || {};
const k = { reads: 0, searches: 0, writes: 0, transactions: 0, batches: 0, other: 0 };
for (const [op, c] of Object.entries(ops)) {
k[categoryOf(op)] += c;
}
let line = `- ${p || '(no endpoint)'}: ${n(k.reads, 'read')}, ${n(k.searches, 'search', 'searches')}, ${n(k.writes, 'write')}, ${n(k.transactions, 'transaction')}`;
const more = [];
if (k.batches) {
more.push(n(k.batches, 'batch', 'batches'));
}
if (k.other) {
more.push(n(k.other, 'other request'));
}
return more.length ? `${line} (and ${more.join(', ')})` : line;
});
const total = counts.total || 0;
const head = total === 0 ? 'No requests were served.' : `${n(total, 'request')} ${total === 1 ? 'was' : 'were'} served.`;
return `${head}\n\n${lines.join('\n')}`;
}

getStatus() {
return { enabled: true, endpoints: this.endpoints.map(ep => ({ path: ep.path, fhirVersion: ep.settings && ep.settings.fhirVersion, database: ep.cfg.database.type })) };
}
Expand All @@ -162,4 +204,18 @@ class RestModule {
}
}

// what each counted interaction is, for the daily report: other is history, operations,
// capabilities, and requests that weren't a FHIR interaction
const CATEGORIES = {
read: 'reads', vread: 'reads',
'search-type': 'searches', 'search-system': 'searches',
create: 'writes', update: 'writes', patch: 'writes', delete: 'writes',
'conditional-update': 'writes', 'conditional-delete': 'writes', 'conditional-patch': 'writes',
transaction: 'transactions', batch: 'batches'
};

function categoryOf(interaction) {
return CATEGORIES[interaction] || 'other';
}

module.exports = RestModule;
2 changes: 1 addition & 1 deletion shl/shl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//

const express = require('express');
const sqlite3 = require('sqlite3').verbose();
const sqlite3 = require('sqlite3');
const path = require('path');
const crypto = require('crypto');
const cron = require('node-cron');
Expand Down
3 changes: 2 additions & 1 deletion tests/cs/cs-lang.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ describe('IETF Language CodeSystem Provider', () => {

await expect(
provider.filter(prep, true, 'language', 'exists', 'maybe')
).rejects.toThrow('Invalid exists value');
).rejects.toMatchObject({ cause: 'invalid', msgId: 'VALUESET_BAD_FILTER_VALUE_BOOLEAN', statusCode: 422,
message: 'The value for a filter based on property \'language\' must be either \'true\' or \'false\', not \'maybe\'' });
});

test('should reject unsupported properties', async () => {
Expand Down
19 changes: 19 additions & 0 deletions tests/cs/cs-loinc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,25 @@ describe('LOINC Provider', () => {
});
});

describe('Counting all the codes (count=0)', () => {
test('countAllCodes counts what the whole walk visits, and without the inactive codes what it doesn\'t call inactive (A9)', async () => {
const iter = await provider.iterator(null);
let all = 0;
let active = 0;
let c = await provider.nextContext(iter);
while (c) {
all++;
if (!await provider.isInactive(c)) {
active++;
}
c = await provider.nextContext(iter);
}
expect(all).toBeGreaterThan(active); // the test data has inactive codes
expect(await provider.countAllCodes(false)).toBe(all);
expect(await provider.countAllCodes(true)).toBe(active);
});
});

describe('Code Lookup', () => {
test('should locate known LOINC codes', async () => {
const testCodes = expectedResults.basic.knownCodes;
Expand Down
10 changes: 10 additions & 0 deletions tests/cs/cs-mimetypes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,16 @@ describe('MimeTypeServices', () => {
.rejects.toMatchObject({ cause: 'not-supported', message: 'The filter "base is-a text" is not understood or supported', msgId: 'FILTER_NOT_UNDERSTOOD', statusCode: 422 });
});

test('a bad filter value is the client\'s error: 422 invalid, not a server error', async () => {
for (const value of ['', 'text/plain; charset=utf-8', 'text/*', 'a/b/c']) {
await expect(provider.filter(await provider.getPrepContext(false), false, 'base', '=', value))
.rejects.toMatchObject({ cause: 'invalid', msgId: 'VALUESET_BAD_FILTER_VALUE_VALID_CODE', statusCode: 422 });
}
await expect(provider.filter(await provider.getPrepContext(false), false, 'registered', '=', 'maybe'))
.rejects.toMatchObject({ cause: 'invalid', msgId: 'VALUESET_BAD_FILTER_VALUE_BOOLEAN', statusCode: 422,
message: 'The value for a filter based on property \'registered\' must be either \'true\' or \'false\', not \'maybe\'' });
});

test('should handle null operation context', () => {
expect(() => provider._ensureOpContext(null)).toThrow();
});
Expand Down
Loading
Loading