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
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@ All notable changes to Health Intersections FHIRsmith will be documented in this
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.2] - 2026-mm-dd

### Security

-

### Added

-

### Changed

- TerminologyCapabilities lists only the code systems (and versions) that the server supports, i.e. can `$validate-code` against: CodeSystem resources with content `complete` or `fragment`, and code systems with a native provider. `not-present` stubs, examples and supplements are no longer listed. `codeSystem.content` is the best content of the versions listed
- Registry and ecosystem resolution: a server that lists a code system in its TerminologyCapabilities supports it, whatever content it reports (as Ontoserver means it). Candidates are no longer passed over for reporting `not-present`; a candidate with only a `fragment` comes after the others

### Fixed

- `$validate-code` on a CodeableConcept with codings from several code systems the server doesn't know reports all of them - an issue at each coding's system and an `x-caused-by-unknown-system` for each system - not just the first (CodeSystem and ValueSet `$validate-code`; reported by the Ontoserver team)
- CodeSystem `$validate-code` on a CodeableConcept, with no `url`: the code system is that of the first coding whose system is known, not always the first coding's. A CodeableConcept with a valid coding was invalid if an unknown-system coding came before it

### Removed

-

### Tx Conformance Statement

(paste)

## [1.1.1] - 2026-12-06

### Security
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,33 @@ Available tags:
- `vX.Y.Z`: Specific version (e.g., `v1.0.0`)
- `cibuild`: Latest build from the main branch

### Clone-and-Run

```bash
git clone https://github.com/HealthIntersections/FHIRsmith
cd FHIRsmith

# Install the dependencies a server needs
npm ci --omit=dev

# Create a data directory
mkdir -p /var/lib/fhirsmith
cp config-template.json /var/lib/fhirsmith/config.json
# Edit config.json as needed

export FHIRSMITH_DATA_DIR=/var/lib/fhirsmith
npm run check # check the configuration
npm start
```

To update: `git pull`, then `npm ci --omit=dev` again.

`npm ci` installs exactly what `package-lock.json` lists. `--omit=dev` leaves out the
devDependencies (jest, ESLint and what they bring in), which only the tests and the linter use.
A plain `npm install` works too, but installs all of those as well, and npm then warns about
install scripts in some of them (`allowScripts` in package.json says none of them need to run).
The npm global install and the Docker image never include the devDependencies.

### Windows Installation

You can install as a windows service using [windows-install.js](utilities/windows-install.js). You might need to
Expand Down
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
24 changes: 24 additions & 0 deletions library/security/auth/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ class Auth {
this.mailer = null;
this.roleDefs = new Map(); // module -> [{role, label, description, scope: {label, values()}}]
this.moduleInfo = new Map(); // module -> {title, path, adminPages: [{label, path, description}]}
// notes the login pages show when the page being returned to is under a path (addLoginNote)
this.loginNotes = []; // [{path, html, text}]
// the request a page is being made for, so the template's [%account%] can say who is logged in
this.pageRequests = new AsyncLocalStorage();
this.internalSecret = crypto.randomBytes(32).toString('base64url');
Expand Down Expand Up @@ -970,6 +972,25 @@ class Auth {
return (LOGIN_FOR[kind] || 'this').replace('{n}', this.anonymousMaxRows().toLocaleString('en-US')).replace('{old}', tools);
}

/**
* A note for the login pages (the page asking someone to log in, and /auth/login) when the page
* they'll come back to is under path: e.g. the XIG says the whole index can be downloaded instead.
* Software told to log in (refuseAnonymous, not HTML) gets the text
* @param {string} path - a path on this server ('/xig': /xig and everything under it)
* @param {string} html - the note, as HTML (the module's own text: not escaped)
* @param {string} text - the same as plain text, for software
*/
addLoginNote(path, html, text) {
this.loginNotes = this.loginNotes.filter(n => n.path !== path);
this.loginNotes.push({ path, html, text });
}

/** The login notes for a page on this server (addLoginNote) */
loginNotesFor(url) {
const path = String(url || '').split(/[?#]/)[0];
return this.loginNotes.filter(n => path === n.path || path.startsWith(n.path.endsWith('/') ? n.path : n.path + '/'));
}

/** Why a kind of request needs a login, in a sentence */
whyLoginFor(kind) {
if (kind === 'old-tool') {
Expand Down Expand Up @@ -1018,6 +1039,9 @@ class Auth {
text = `To get ${what} from this server, log in: send an API token (Authorization: Bearer {token}). ${this.whyLoginFor(kind)} ${how}`;
}
text += hint ? `. ${hint}` : '';
for (const n of this.loginNotesFor(req.originalUrl)) {
text += ` ${n.text}`;
}
if (as === 'fhir-xml') {
res.setHeader('Content-Type', 'application/fhir+xml');
return res.send('<?xml version="1.0" encoding="UTF-8"?>\n<OperationOutcome xmlns="http://hl7.org/fhir"><issue>' +
Expand Down
9 changes: 8 additions & 1 deletion library/security/auth/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,19 @@ function sendLogin(auth, req, res, status, error) {
'<button type="submit" class="btn btn-primary">Log in</button> &nbsp; ' +
`<a href="/auth/forgot${q}" rel="nofollow">Forgotten your password?</a></form>`;
h += `<p class="text-muted"><small><a href="${HELP_URL}">How logging in works</a></small></p>`;
h += loginNotes(auth, ret);
render(auth, req, res, 'Log in', h, status);
}

// ---- login for expensive operations (auth.loginForExpensive) ----

const WHY_LOGIN_PATH = '/auth/why-login';

/** The notes modules added for the page being returned to (Auth.addLoginNote), as HTML */
function loginNotes(auth, ret) {
return auth.loginNotesFor(ret).map(n => `<div class="alert alert-info" style="margin-top: 16px">${n.html}</div>`).join('');
}

/** The ways to log in, as buttons, coming back to `back` (a path on this server) */
function loginButtons(auth, back) {
const q = back ? `?return=${escape(encodeURIComponent(back))}` : '';
Expand All @@ -358,7 +364,8 @@ function sendLoginNeeded(auth, req, res, what, back) {
? `<p class="text-muted"><small>Any ${escape(providers.join(' or '))} account will do. The first time, it makes you an account here; nothing else is needed.</small></p>`
: '') +
(back ? `<p><a href="${escape(back)}">Back to what you can see without logging in</a></p>` : '') +
`<p class="text-muted"><small><a href="${WHY_LOGIN_PATH}">What needs a login, and why</a></small></p>`;
`<p class="text-muted"><small><a href="${WHY_LOGIN_PATH}">What needs a login, and why</a></small></p>` +
loginNotes(auth, ret);
render(auth, req, res, 'Please log in', h, 401);
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fhirsmith",
"version": "1.1.1",
"version": "1.1.2-snapshot",
"txVersion": "1.12.1-snapshot",
"description": "A Node.js server that provides a collection of tools to serve the FHIR ecosystem",
"main": "server.js",
Expand Down Expand Up @@ -122,5 +122,11 @@
"bugs": {
"url": "https://github.com/HealthIntersections/fhirsmith/issues"
},
"homepage": "https://github.com/HealthIntersections/fhirsmith#readme"
"homepage": "https://github.com/HealthIntersections/fhirsmith#readme",
"allowScripts": {
"@parcel/watcher": false,
"bcrypt": false,
"koffi": false,
"unrs-resolver": false
}
}
44 changes: 27 additions & 17 deletions registry/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,9 @@ class RegistryAPI {
* - language: only for language sensitive requests (see resolveCodeSystem).
*
* Differences from the Java code:
* - 'Does a candidate really have the code system' is answered from the content mode the
* server reported in its TerminologyCapabilities, not by searching the server. If it
* didn't report one, the candidate is assumed to be usable.
* - 'Does a candidate really have the code system' is answered by its TerminologyCapabilities:
* a server that lists a code system (version) there supports it, whatever content mode it
* reports. The content mode only ranks candidates: one with a fragment comes after the others.
* - The 'primary server' for the systems tx.fhir.org handles specially is the default.
* - The value set's source server is found by resolving the value set here.
* - Ties are broken by order (the first system, then registration order), not hash order.
Expand Down Expand Up @@ -721,16 +721,28 @@ class RegistryAPI {
}

// 4. a server that's a candidate for all of them (again, systems no server is known for
// don't constrain the choice), and that has a usable copy of the code systems
// don't constrain the choice). Being a candidate means it lists the code system in its
// TerminologyCapabilities, which says it supports it, whatever content it reports; but one
// with the whole of each code system is preferred over one that has only a fragment of some
let fragmentOnly = null;
for (const c of choices) {
for (const s of c.candidates) {
if (choices.every(t => unresolved(t) || t.candidates.includes(s)) &&
this._supportsAll(s, choices, unresolved, log)) {
log.push(`Found candidate server ${s}`);
return s;
if (choices.every(t => unresolved(t) || t.candidates.includes(s))) {
const fragment = this._fragmentOf(s, choices, unresolved);
if (!fragment) {
log.push(`Found candidate server ${s}`);
return s;
}
if (!fragmentOnly) {
fragmentOnly = { server: s, system: fragment };
}
}
}
}
if (fragmentOnly) {
log.push(`Found candidate server ${fragmentOnly.server} (it has only a fragment of ${fragmentOnly.system})`);
return fragmentOnly.server;
}

// 5. no agreement - take the one that is most authoritative
const counts = new Map();
Expand Down Expand Up @@ -766,24 +778,22 @@ class RegistryAPI {
}

/**
* Whether a candidate server has a usable copy (complete or fragment) of each code system
* it's a candidate for. Systems for which tx.fhir.org is a candidate aren't checked
* The first code system that a candidate server says it has only a fragment of, or null if
* there isn't one. Systems for which tx.fhir.org is a candidate aren't checked
*/
_supportsAll(server, choices, unresolved, log) {
_fragmentOf(server, choices, unresolved) {
if (isTxFhirOrg(server)) {
return true;
return null;
}
for (const t of choices) {
if (unresolved(t) || !t.candidates.includes(server) || t.candidates.some(isTxFhirOrg)) {
continue;
}
const content = t.content[server];
if (content && content !== 'complete' && content !== 'fragment') {
log.push(`Candidate server ${server} dropped for ${t.system}: its copy of the code system is '${content}'`);
return false;
if (t.content[server] === 'fragment') {
return t.system;
}
}
return true;
return null;
}

/**
Expand Down
33 changes: 33 additions & 0 deletions tests/cs/cs-cpt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,39 @@ describe('CPT Provider', () => {
});
});

describe('Locating expressions in filters (#486)', () => {
async function filterSet(prop, value) {
const filterContext = await provider.getPrepContext(false);
await provider.filter(filterContext, false, prop, '=', value);
return { filterContext, set: (await provider.executeFilters(filterContext))[0] };
}

test('modified = true: a valid expression is in', async () => {
const { filterContext, set } = await filterSet('modified', 'true');
for (const expression of testData.validExpressions) {
const located = await provider.filterLocate(filterContext, set, expression);
expect(located).toBeInstanceOf(CPTExpression);
expect(await provider.code(located)).toBe(expression);
}
});

test('modified = true: a plain code is not in', async () => {
const { filterContext, set } = await filterSet('modified', 'true');
expect(await provider.filterLocate(filterContext, set, testData.baseCodes[0])).toBeNull();
});

test('modified = true: an expression that does not parse gets the reason', async () => {
const { filterContext, set } = await filterSet('modified', 'true');
expect(await provider.filterLocate(filterContext, set, '99999:25')).toBe("Base CPT Code '99999' not found");
expect(await provider.filterLocate(filterContext, set, '99202:99')).toBe("Modifier CPT code '99' not found");
});

test.each([['modified', 'false'], ['modifier', 'true'], ['modifier', 'false']])('%s = %s: an expression is not in', async (prop, value) => {
const { filterContext, set } = await filterSet(prop, value);
expect(await provider.filterLocate(filterContext, set, testData.validExpressions[0])).toBeNull();
});
});

describe('Iterator Support', () => {
test('should iterate all codes', async () => {
const iterator = await provider.iterator(null);
Expand Down
88 changes: 88 additions & 0 deletions tests/cs/cs-ndc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,94 @@ describe('NDC Provider', () => {
});
});

describe('Combined filters (#484)', () => {
async function walk(set) {
const codes = [];
let c = await provider.filterConcept(null, set);
while (c) {
codes.push(c);
c = await provider.filterConcept(null, set);
}
return codes;
}

async function bla11() {
const db = new SqliteDatabase(testDbPath, { readOnly: true });
try {
return db.all(`SELECT pkg.Code11 FROM NDCPackages pkg JOIN NDCProducts p ON pkg.ProductKey = p.NDCKey
WHERE p.Category = 'BLA' ORDER BY pkg.NDCKey`).map(r => r.Code11);
} finally {
db.close();
}
}

test.each([
['category first', [['category', 'BLA'], ['code-type', '11-digit']]],
['code-type first', [['code-type', '11-digit'], ['category', 'BLA']]]
])('category and 11-digit, %s: the 11 digit codes of the category\'s packages', async (name, filters) => {
const ctxt = await provider.getPrepContext(true);
for (const [prop, value] of filters) {
await provider.filter(ctxt, true, prop, '=', value);
}
const sets = await provider.executeFilters(ctxt);
expect(sets.length).toBe(1);
const expected = await bla11();
expect(expected.length).toBeGreaterThan(0);
const codes = await walk(sets[0]);
expect(codes.map(c => c.code)).toEqual(expected);
expect(await provider.filterSize(ctxt, sets[0])).toBe(expected.length);
// membership: the 11 digit form is in, the 10 digit form isn't
const pkg = codes[0];
expect(await provider.filterLocate(ctxt, sets[0], pkg.code)).toBeInstanceOf(NdcConcept);
const db = new SqliteDatabase(testDbPath, { readOnly: true });
let tenDigit;
try {
tenDigit = db.get('SELECT Code FROM NDCPackages WHERE Code11 = ?', [pkg.code]).Code;
} finally {
db.close();
}
expect(tenDigit).toContain('-');
expect(await provider.filterLocate(ctxt, sets[0], tenDigit)).toBeNull();
});

test('10-digit and 11-digit together: nothing', async () => {
const ctxt = await provider.getPrepContext(true);
await provider.filter(ctxt, true, 'code-type', '=', '10-digit');
await provider.filter(ctxt, true, 'code-type', '=', '11-digit');
const sets = await provider.executeFilters(ctxt);
expect(await provider.filterSize(ctxt, sets[0])).toBe(0);
expect(await walk(sets[0])).toEqual([]);
});
});

describe('Iterator (#485)', () => {
test('walks every product and package, as many as it counts', async () => {
const total = await provider.totalCount();
const iter = await provider.iterator(null);
expect(iter.total).toBe(total);
const codes = new Set();
let products = 0;
let c = await provider.nextContext(iter);
while (c) {
expect(c).toBeInstanceOf(NdcConcept);
if (!c.isPackage) {
products++;
}
codes.add(c.code);
c = await provider.nextContext(iter);
}
expect(codes.size).toBe(total);
expect(products).toBe(factory._productCount);
expect(await provider.countAllCodes(false)).toBe(total);
});

test('a concept has nothing under it', async () => {
const iter = await provider.iterator((await provider.locate('0002-0152')).context);
expect(iter.total).toBe(0);
expect(await provider.nextContext(iter)).toBeNull();
});
});

describe('Error Handling', () => {

test('should handle unsupported filters', async () => {
Expand Down
Loading
Loading