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

### Added

- IPS: clinical profiles have guided input - questions for the people filling a document in, about a section. A profile with any contains a Questionnaire (`#Q`) and has an `input-guide` extension (`http://www.healthintersections.com.au/fhir/StructureDefinition/input-guide`) for each guide: the Questionnaire, its questions' linkIds (made and kept by the server), the section (a Coding), and optionally the resource the answers make (`Condition:problem`, `Condition:diagnosis`, `Observation:vitals`, `MedicationStatement`, `AllergyIntolerance`) and its code. A question is text, a type (`display`, `boolean`, `quantity` with optional units, `date`, `choice` with its answer Codings) and optionally a definition (a path in a resource). The profile page shows them as a table grouped by section (IPS order, then the others), and the administrator adds, edits, deletes and moves them within a section a guide at a time, in a dialog. Uploads keep their guided input, and are refused if it is more than this or names a question the Questionnaire doesn't have
- Keys: a key store for the whole server (`keystore`, off unless enabled; [library/keystore/README.md](library/keystore/README.md)). `/keys` lists public keys for anyone, and as a JWKS (`/keys/jwks.json`). A logged in user can upload public keys (PEM, a certificate, a JWK or JWKS, an OpenSSH line, DER), claiming a key id or not, and have the server make key pairs for them (EC P-256, EC P-384, RSA, Ed25519; one of each type), whose private keys the server keeps and signs with when a module asks; the administrator makes the system's own key pairs. Private keys are never uploaded (an upload with one is refused) and never given out. Owners revoke their keys, administrators revoke, delete and change key ids. A key is shown only as uploaded or created by its owner's display name. Limits: 10 uploads, then one a day; one key pair a day of each type. Private keys are in a database of their own (`keystore-private.db`, 0600). The daily report has a paragraph on them. Modules sign with `keystore.sign`/`signJws` and check with `verify`/`verifyJws`; there is no endpoint that signs what it is given
- IPS: a first processing step, signatures, checks the document's signatures, with keys from the key store (by key id, or by the key a signature's certificate carries, which may have been revoked here), and shows what it found at the top of the analysis view. The check itself (`ips/signatures.js`) is not written yet, and says so
- IPS: a document's source view has a banner with what can be done with the copy shown (the original, or the modified copy): download it as JSON, a ZIP, or a PDF with the document attached, and share it as an SHL or a VHL. The Download link at the top of the document page has moved there. `?download=1&source=modified` (and `?_format=json&source=modified`) gives the modified copy
Expand All @@ -25,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- IPS: a Patient Comments tab on a document, for any comments the patient wishes to make about the accuracy or appropriateness of its content (a diagnosis in the problems section, say). One comment per document, in pure markdown (CommonMark): a comment with any HTML in it is refused; everyone can see it, anyone logged in can write, replace or remove it. It is kept apart from the document and its processing results, so processing again leaves it alone; deleting the document deletes it. To keep the document's tabs on one line, National Profiles is now Jurisdictions and AI Assessment is AI Check, and the tabs are a little closer together
- IPS: when a document has patient comments, the source view's banner offers "Include Patient Comments", which, like the Sign choices, applies to every download (JSON, ZIP, PDF) and share (SHL, VHL). Any patient notes section (LOINC 51855-5) in the document is removed before signing; after signing, the comments go in as the Composition's first section - code LOINC 51855-5, title "Patient's Comments", the patient as author, and the comments as narrative (status `additional`), nothing else - so they are not signed. The signatures step checks a document's signatures with any patient notes section removed, for the same reason; and a patient notes section a document arrives with becomes its patient comment, converted to markdown (new dependency: turndown), when it has none yet. `{document}/signed` and `{document}/share` take `comments`
- IPS: the source view's banner also offers "Regenerate narrative": the server generates the narrative of the copy downloaded or shared as the narrative step does (the narrative tab's Generated), before it is signed. `{document}/signed` and `{document}/share` take `narrative`
- IPS: `$document` on a stored document (`GET {project}/Bundle/{id}/$document`, or POST a Parameters resource) gives the API what the source view's banner gives a browser. Parameters `source` (original | modified), `user-sign` (as the owner of the API token; 401 without one, 409 with no key pair), `system-sign`, `patient-notes` (nothing added, and no error, when there are none) and `regenerate-narrative`. By `Accept` or `_format`: the JSON (the default), `application/zip`, `application/pdf`, or an SHL (`application/smart-health-link`) or VHL (`application/verified-health-link`) - the QR code as a PNG, with the link, manifest and expiry in `X-Health-Link*` headers. The ZIP and PDF are made on the server (`ips/export.js`; the PDF is the browser's content laid out as text in the standard fonts, with the document attached). Same rate limit as sharing. Its OperationDefinition is `ips/OperationDefinition-ips-document.json`, which the CapabilityStatement refers to on GitHub
- IPS: `$document` on a stored document (`GET {project}/Bundle/{id}/$document`, or POST a Parameters resource) gives the API what the source view's banner gives a browser. Parameters `source` (original | modified), `format-type`, `user-sign` (as the owner of the API token; 401 without one, 409 with no key pair), `system-sign`, `patient-notes` (nothing added, and no error, when there are none) and `regenerate-narrative`. What comes back: `format-type` (`json`, `pdf`, `zip`, `shl`, `vhl`) when given, whatever `Accept` says; otherwise `Accept` (or `_format`): the JSON (the default), `application/zip`, `application/pdf`, or `image/png` - a VHL's QR code. An SHL or VHL answer is the QR code (`image/png`), with the link, manifest and expiry in `X-Health-Link*` headers. The ZIP and PDF are made on the server (`ips/export.js`; the PDF is the browser's content laid out as text in the standard fonts, with the document attached). Same rate limit as sharing. Its OperationDefinition is `ips/OperationDefinition-ips-document.json`, which the CapabilityStatement refers to on GitHub
- Registry: a code system resolution that finds nothing says, with `unknown-host`, when no server hosts any code system on the url's host, so clients needn't ask about each of that host's code systems (the tx ecosystem IG's Unknown Hosts)
- tx: the ecosystem resolver remembers an `unknown-host` answer from the registry, and doesn't ask the registry about other code systems on that host for as long as it remembers a code system it was told nothing about; the cached answers viewer shows the hosts
- tx: `$validate-code` on a CodeableConcept says what the ConceptMaps the server can find say about its codings together: for each coding, the maps from its code system to the code system of another coding (packages, libraries, tx-resources, and the maps code systems imply), read forwards, both ways round. A map that says the code is `not-related-to` the other coding, or that it has no map (`noMap`), is a warning; a map that relates it only to other codes is a hint (`TRANSLATION_WARNING_*`). Several maps that say the same thing are named in one message. This is the server side of the core validator's check, with the same messages
Expand All @@ -34,6 +35,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- IPS: clinical profiles no longer have a full editor (Edit all, and the New profile page): a new profile is made from its title on the list page, renamed on its own page, and its rules and guided input edited there a row at a time
- IPS: the FHIRPath function `section(system, code)` without min and max is `1..1`, as it is in the Java `DocumentFunctions` (the validator's): a document with two of the same section has none, for a rule. It was no bounds. `entry()` and `entryIn()` are still `0..*`
- IPS: clinical profiles' required section rules no longer give the section a cardinality (a `section()` with bounds is now an other rule); instead three checkboxes say what the section must be - must be asked/known (`isKnown()`), must have supporting entries (`hasData()`), about the same Patient (`sameSubject()`). One check on its own is the rule (`Bundle.section(...).isKnown()`); more than one, or any with entries, go in a `where()`. `isKnown()`: no emptyReason, or a nil known one; `hasData()`: an emptyReason, or else entries; `sameSubject()` on a section: no focus, or the focus is the Composition's subject - in `ips/fhirpath-ips.js` (with `sameSubject([other])` on resources too), as in the Java `DocumentFunctions`
- IPS: clinical profiles' section choices include the Patient Story (LOINC 81338-6), and the editor lists the sections alphabetically, with "Another code..." last
- tx: LOINC `$lookup` gives a property whose value is a LOINC code (COMPONENT and the other axes, parent, child, AnswerList, Answer, answers-for) the display of that code as its `description`
- tx: the HTML view of a `$lookup` response puts its properties and designations in tables of their own, Properties and Designations, below the other parameters, with a column for each part (code, value, description, language, use and so on) instead of a bulleted list in each row. Its `name` parameter is shown as Code System name; a designation's use is shown as its display (Synonym, Fully specified name...), linked to `$lookup` on its code where the server has it, with the system and code in its title; and a Coding's code (a designation's use, say) is linked to `$lookup` on it in whatever code system it is from, if the server has that code system and the code is in it - not only in the code system the response is about
- Home page and dashboard graphs: in a cluster, requests per minute, turnaround time, client cache and node blocking are one line for the cluster instead of one per process: requests and client concepts summed (the shared cache counted once), turnaround averaged over the requests, node blocking the worst process's. Private memory is still drawn per process
Expand Down
4 changes: 3 additions & 1 deletion CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ with `--role`). Their settings are in `server.cluster`, documented with the arra
[cluster.md](cluster.md): the launcher's (`workers`, `maxOutstanding`, `queueSeconds`,
`recycleSeconds`, the fast lane, ...) under
[The launcher](cluster.md#the-launcher-clusterjs), and what the processes share
(`sharedCache`, `cacheAffinity`, `sharedCacheMaxMB`, `sharedClosure`) under
(`sharedCache`, `cacheAffinity`, `sharedCacheMaxMB`, `sharedClosure`, and `workerModules`, for
workers that serve the rest module too) under
[Options](cluster.md#options). With no role, `server.cluster` is ignored.
The status panel's snapshot of every process (`statusSeconds`) is under
[Status](cluster.md#status).
Expand Down Expand Up @@ -288,6 +289,7 @@ Each module has its own entry under `modules`, documented with the module:
| `packages` - package server | [packages/readme.md](packages/readme.md) |
| `shl` - SMART Health Links | [shl/readme.md](shl/readme.md) |
| `ips` - IPS documents | [ips/readme.md](ips/readme.md) |
| `rest` - FHIR REST servers | [rest/README.md](rest/README.md#configuration) |
| `testing` - test reports | [testing/readme.md](testing/readme.md) |
| `folder` | [folder/readme.md](folder/readme.md) |
| `npmprojector` | [npmprojector/readme.md](npmprojector/readme.md) |
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This server provides a set of server-side services that are useful for the FHIR
## Under development, prototyping

* [IPS](ips/readme.md) (`ips`) - collections of International Patient Summary documents, each with its own FHIR endpoint, processing (validation, terminology checks, translation, narrative, clinical profiles) and web pages
* [REST](rest/README.md) (`rest`) - database-backed FHIR RESTful servers (SQLite or MySQL): the interactions, search, batch and transaction, AuditEvents, each endpoint configured on its own

## On the back-burner

Expand Down
19 changes: 17 additions & 2 deletions cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
const http = require('http');
const path = require('path');
const { spawn } = require('child_process');
const { checkInstanceCode, bindAddress, connectAddress, ROLE_TRIM_ALLOCATOR, READY } = require('./library/role');
const { checkInstanceCode, bindAddress, connectAddress, ROLE_TRIM_ALLOCATOR, READY, workerModules } = require('./library/role');
const { ClusterMetrics, METRIC, SNAPSHOT } = require('./library/cluster-metrics');
const { PendingCounts, COUNTS, COUNTS_INTERVAL_MS } = require('./library/cluster-counts');
const { CacheFanout, ASK: CACHES_ASK, DONE: CACHES_DONE } = require('./library/cluster-caches');
Expand Down Expand Up @@ -178,7 +178,9 @@
return {
port,
procs,
txPaths: (tx.endpoints || []).map(e => String(e.path).replace(/\/+$/, '')),
// the paths the workers serve: the tx endpoints, and the rest module's when the workers run
// it too (server.cluster.workerModules). Every other path goes to the master
txPaths: [...(tx.endpoints || []).map(e => String(e.path).replace(/\/+$/, '')), ...restPaths(config)],
drainMs: Number(cluster.drainSeconds ?? DRAIN_MS / 1000) * 1000,
maxOutstanding: Number(cluster.maxOutstanding ?? MAX_OUTSTANDING),
queueMs: Number(cluster.queueSeconds ?? QUEUE_MS / 1000) * 1000,
Expand All @@ -201,6 +203,19 @@
};
}

/**
* The rest module's endpoint paths, when the workers run it (server.cluster.workerModules):
* any process can serve any rest request, since all its state is in the database.
* @param {Object} config
*/
function restPaths(config) {
const rest = config.modules && config.modules.rest;
if (!rest || !rest.enabled || !workerModules(config).includes('rest')) {
return [];
}
return (rest.endpoints || []).map(e => String(e.path).replace(/\/+$/, '')).filter(p => p);
}

// the path after the tx endpoint ('' for the endpoint itself), or null if not a tx path
function txRest(url, txPaths) {
let p = String(url).split('?')[0];
Expand Down Expand Up @@ -626,7 +641,7 @@
}
const delay = Math.min(MAX_BACKOFF_MS, 1000 * 2 ** (proc.failures - 1));
log(`${proc.name} exited (${signal || code}); restarting in ${delay / 1000} s`);
proc.restartTimer = setTimeout(() => startProcess(proc), delay);

Check warning on line 644 in cluster.js

View workflow job for this annotation

GitHub Actions / Code Quality

Promise returned in function argument where a void return was expected
});
// ready: the process says so from its listen callback (server.js), on its own channel,
// so an old process still shutting down on the same port can't answer for it
Expand Down Expand Up @@ -1217,8 +1232,8 @@
process.exit(1);
}
const shutdown = () => launcher.stop().then(() => process.exit(0));
process.on('SIGTERM', shutdown);

Check warning on line 1235 in cluster.js

View workflow job for this annotation

GitHub Actions / Code Quality

Promise returned in function argument where a void return was expected
process.on('SIGINT', shutdown);

Check warning on line 1236 in cluster.js

View workflow job for this annotation

GitHub Actions / Code Quality

Promise returned in function argument where a void return was expected
await launcher.start();
}

Expand Down
2 changes: 2 additions & 0 deletions cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ as before.
| | master | tx-worker |
|---|---|---|
| tx module (`/r4`, `/r5` and the other endpoints) | yes (may also serve tx requests) | yes |
| rest module (its endpoints), with `"workerModules": ["rest"]` | yes, and its background jobs (schema migrations, expired searches, the closure, reindexing) | yes: every request, since all its state is in its databases |
| Every other module (packages, xig, registry, publisher, shl, ips, ...) | yes | no |
| Logins (`/auth`, [library/auth](library/auth/README.md)) | yes | the users and sessions are in one database every process reads: a login on one is one on all (with `auth.sessionSecret` set) |
| `$closure` (the closure tables) | yes | no: routed to the master (yes, with [`sharedClosure`](#options)) |
Expand Down Expand Up @@ -525,6 +526,7 @@ both only apply with a role: `node server.js` with no role ignores them.
| `server.cluster.sharedCacheMaxMB` | 256 | With `sharedCache`: the most client resources (their JSON, in MB) the file holds, every endpoint's caches together. Past it, the caches least recently used are dropped whole, and a request with a dropped cache-id gets `404` `cache-id-unknown` (`CACHE_ID_EVICTED_SIZE`, which names the cap), so the client starts a new cache. 256: the largest IG Publisher cache session in a corpus of 2,817 from builds against tx.fhir.org held 3.5 MB of resources (p99 2.8 MB, median 55 KB), so this is about 70 times the largest; `cacheMaxTotalConcepts` gives one endpoint about 40 times the largest session's concepts, and this is that room for two busy endpoints. The file on disk is larger than what it holds (indexes, and the pages SQLite keeps for reuse). Each process logs the cap as it starts. 0: no cap. |
| `server.cluster.sharedClosure` | false | Every tx process answers `$closure`, on the one closure database. |
| `modules.tx.closure.writeRetries` | 10 | With `sharedClosure`: how many times an add is worked out again when another process changed the table first. |
| `server.cluster.workerModules` | `["tx"]` | The modules the workers run besides tx: `"rest"` is the only other one a worker can run. With it, the launcher sends the rest module's endpoints to any process, as it does tx requests. A rest endpoint on SQLite needs every process on this one machine (SQLite's locking is unreliable on network file systems); on MySQL the workers can be anywhere. See [rest/README.md](rest/README.md#clustering). |

### Shared cache

Expand Down
21 changes: 21 additions & 0 deletions config-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,27 @@
"autoLoadPackages": true
// , "profiles": ["http://hl7.org/fhir/uv/ips/StructureDefinition/Bundle-uv-ips"]
}
},
// Database-backed FHIR RESTful servers. See rest/README.md. config.json says only where
// each endpoint is and which database it uses: everything else about an endpoint is kept
// in its own database. Users get the rest read / write / manage roles per endpoint
"rest": {
"enabled": false,
"endpoints": [
{
"path": "/fhir/r4",
// fixed when the database is made
"fhirVersion": "4.0.1",
// a SQLite file (relative paths resolve under the databases directory), or MySQL:
// { "type": "mysql", "host": "localhost", "database": "fhir_r4", "user": "fhirsmith",
// "passwordEnv": "FHIR_R4_DB_PASSWORD" } - never a password here: passwordEnv names
// an environment variable, passwordFile a file only the server can read
"database": { "type": "sqlite", "file": "rest/fhir-r4.db" },
// settings written into a new database (rest/README.md, "Settings"); after that the
// database's own values are used
"initialSettings": { "name": "FHIRsmith R4 test server", "anonymous": "read", "txServer": "/tx/r4" }
}
]
}
}
}
Loading
Loading