fhirsmith 0.14.0 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +3 -2
  3. package/config-template.json +20 -0
  4. package/library/fhir-openapi-schema.js +441 -0
  5. package/library/html-server.js +9 -3
  6. package/library/languages.js +15 -0
  7. package/library/npm-audit.js +265 -0
  8. package/library/openapi-doc.js +557 -0
  9. package/library/same-origin.js +62 -0
  10. package/library/utilities.js +21 -0
  11. package/nginx.md +17 -9
  12. package/package.json +10 -4
  13. package/packages/openapi.js +13 -0
  14. package/packages/openapi.yaml +603 -0
  15. package/packages/packages-template.html +4 -2
  16. package/packages/packages.js +286 -81
  17. package/packages/readme.md +120 -0
  18. package/publisher/publisher-template.html +1 -0
  19. package/publisher/publisher.js +95 -42
  20. package/registry/api.js +117 -41
  21. package/registry/crawler.js +24 -0
  22. package/registry/fhirsmith-releases.js +170 -0
  23. package/registry/model.js +10 -0
  24. package/registry/openapi.js +13 -0
  25. package/registry/openapi.yaml +311 -0
  26. package/registry/readme.md +107 -208
  27. package/registry/registry-template.html +4 -1
  28. package/registry/registry.js +183 -20
  29. package/server.js +25 -6
  30. package/testing/openapi-schemas.config.js +58 -0
  31. package/testing/openapi-schemas.json +1920 -0
  32. package/testing/openapi.js +15 -0
  33. package/testing/openapi.yaml +273 -0
  34. package/testing/readme.md +75 -1
  35. package/testing/render.js +270 -29
  36. package/testing/search.js +1 -1
  37. package/testing/store.js +152 -8
  38. package/testing/testing-template.html +2 -0
  39. package/testing/testing.js +307 -9
  40. package/translations/Messages.properties +1 -0
  41. package/tx/README.md +58 -0
  42. package/tx/cm/cm-database.js +10 -1
  43. package/tx/cm/cm-package.js +8 -1
  44. package/tx/cs/cs-rxnorm.js +23 -6
  45. package/tx/cs/cs-snomed.js +3 -72
  46. package/tx/html/tx-template.html +2 -0
  47. package/tx/library/canonical-resource.js +50 -1
  48. package/tx/library/codesystem.js +1 -0
  49. package/tx/library/conceptmap.js +1 -0
  50. package/tx/library/valueset.js +16 -0
  51. package/tx/library.js +17 -2
  52. package/tx/openapi-operations.js +363 -0
  53. package/tx/openapi-schemas.config.js +118 -0
  54. package/tx/openapi-schemas.json +7903 -0
  55. package/tx/openapi.js +289 -0
  56. package/tx/openapi.yaml +151 -0
  57. package/tx/operation-context.js +15 -0
  58. package/tx/params.js +3 -12
  59. package/tx/provider.js +10 -1
  60. package/tx/sct/editions.js +70 -0
  61. package/tx/tx-html.js +6 -0
  62. package/tx/tx.js +55 -0
  63. package/tx/vs/vs-database.js +14 -5
  64. package/tx/vs/vs-package.js +10 -0
  65. package/tx/workers/expand.js +37 -18
  66. package/tx/workers/metadata.js +0 -13
  67. package/tx/workers/translate.js +25 -1
  68. package/tx/workers/validate.js +74 -24
  69. package/tx/workers/worker.js +32 -43
  70. package/utilities/extract-schema-json.js +167 -0
  71. package/utilities/generate-openapi-schemas.js +49 -0
  72. package/utilities/submit-test-report.js +1 -1
  73. package/xig/xig.js +2 -4
@@ -0,0 +1,15 @@
1
+ //
2
+ // Copyright 2026, Health Intersections Pty Ltd (http://www.healthintersections.com.au)
3
+ //
4
+ // Licensed under BSD-3: https://opensource.org/license/bsd-3-clause
5
+ //
6
+
7
+ // The testing module's OpenAPI description: openapi.yaml (the paths, written by hand) plus
8
+ // openapi-schemas.json (the FHIR resource schemas, generated from the R5 StructureDefinitions
9
+ // by utilities/generate-openapi-schemas.js - see openapi-schemas.config.js).
10
+
11
+ const path = require('path');
12
+ const { createOpenApiDoc } = require('../library/openapi-doc');
13
+
14
+ module.exports = createOpenApiDoc(path.join(__dirname, 'openapi.yaml'), '/testing',
15
+ { schemasPath: path.join(__dirname, 'openapi-schemas.json') });
@@ -0,0 +1,273 @@
1
+ # OpenAPI description of the FHIRsmith testing module (/testing): a FHIR API for TestReports.
2
+ #
3
+ # The paths are maintained here by hand. The FHIR resource schemas (TestReport,
4
+ # OperationOutcome, Bundle, the datatypes they use, and TestReportSearchBundle) are generated
5
+ # from the R5 StructureDefinitions into openapi-schemas.json, and merged into
6
+ # components.schemas when the spec is served - see openapi-schemas.config.js.
7
+ #
8
+ # tests/testing/openapi.test.js keeps this honest: every route must be described here or
9
+ # explicitly excluded, the search parameters must be the ones search.js understands, and
10
+ # the TestReport schema must require everything validateReport() in testing.js requires.
11
+ #
12
+ # Administrative routes (DELETE, the login and admin pages) are deliberately not described.
13
+ # info.version is filled in from package.json when the spec is served.
14
+
15
+ openapi: 3.1.0
16
+ info:
17
+ title: FHIRsmith Test Reports
18
+ version: "0.0.0"
19
+ summary: A FHIR repository for TestReports
20
+ description: |
21
+ Receives FHIR TestReports - from TxTester, and from any other tool that produces them -
22
+ and makes them available for reading and searching. This is a small FHIR R5 server with
23
+ one resource type, TestReport, and three interactions: create, read and search.
24
+
25
+ * **R4 and R5** TestReports are accepted alike (they differ only in `testScript`).
26
+ * **Reports are immutable**: the server assigns the id and `meta.lastUpdated`, drops
27
+ `meta.versionId`, and each POST is a new report, even of the same report.
28
+ * **Contained resources are not accepted.**
29
+ * The server checks only what the TestReport schema marks as required (and that
30
+ `issued` is a valid dateTime and `score` a number). The schema describes a valid
31
+ report; reports that don't conform to it in other ways may still be accepted, but
32
+ shouldn't be sent.
33
+
34
+ **Content negotiation.** Read and search return an HTML page to a browser (an
35
+ `Accept` containing `text/html`); `_format=json` or `_format=html` overrides that.
36
+ license:
37
+ name: BSD-3-Clause
38
+ url: https://opensource.org/license/bsd-3-clause
39
+ externalDocs:
40
+ description: The TestReport resource (FHIR R5)
41
+ url: https://hl7.org/fhir/R5/testreport.html
42
+ servers:
43
+ - url: /testing
44
+
45
+ paths:
46
+ /TestReport:
47
+ post:
48
+ tags: [TestReport]
49
+ operationId: createTestReport
50
+ summary: Submit a report
51
+ description: |
52
+ Stores the report and returns it with its new id and `meta.lastUpdated`. Reports
53
+ are limited in size (500 KB by default) and submissions are rate limited.
54
+
55
+ If the server is configured with a token, every submission must carry it, in the
56
+ `Authorization` header by default (`Bearer <token>`; the header is configurable).
57
+ security:
58
+ - {}
59
+ - submitToken: []
60
+ parameters:
61
+ - name: Prefer
62
+ in: header
63
+ description: '`return=minimal` (no body), `return=representation` (the default), or `return=OperationOutcome`.'
64
+ schema: { type: string }
65
+ example: return=minimal
66
+ requestBody:
67
+ required: true
68
+ content:
69
+ application/fhir+json:
70
+ schema: { $ref: '#/components/schemas/TestReport' }
71
+ application/json:
72
+ schema: { $ref: '#/components/schemas/TestReport' }
73
+ responses:
74
+ '201':
75
+ description: Stored. The body is the stored report, nothing, or an OperationOutcome, as `Prefer` asks.
76
+ headers:
77
+ Location:
78
+ description: The new report's URL
79
+ schema: { type: string, format: uri }
80
+ Last-Modified:
81
+ schema: { type: string }
82
+ content:
83
+ application/fhir+json:
84
+ schema:
85
+ anyOf:
86
+ - $ref: '#/components/schemas/TestReport'
87
+ - $ref: '#/components/schemas/OperationOutcome'
88
+ '400': { $ref: '#/components/responses/Invalid' }
89
+ '401':
90
+ description: A token is required and wasn't supplied, or is wrong
91
+ content:
92
+ application/fhir+json:
93
+ schema: { $ref: '#/components/schemas/OperationOutcome' }
94
+ '413':
95
+ description: The report is too big
96
+ content:
97
+ application/fhir+json:
98
+ schema: { $ref: '#/components/schemas/OperationOutcome' }
99
+ '415':
100
+ description: The body isn't JSON
101
+ content:
102
+ application/fhir+json:
103
+ schema: { $ref: '#/components/schemas/OperationOutcome' }
104
+ '429':
105
+ description: Too many submissions; try again later
106
+ content:
107
+ application/fhir+json:
108
+ schema: { $ref: '#/components/schemas/OperationOutcome' }
109
+
110
+ get:
111
+ tags: [TestReport]
112
+ operationId: searchTestReports
113
+ summary: Search reports
114
+ description: |
115
+ Returns a searchset Bundle, newest received first unless `_sort` says otherwise.
116
+ `total` is always present.
117
+
118
+ Comma separated values are ORed; repeated parameters are ANDed. The search
119
+ parameters aren't yet formally defined as SearchParameter resources; their
120
+ behaviour is as described here. Modifiers are written after the name
121
+ (`name:exact=...`).
122
+
123
+ Unknown parameters are ignored, with a warning OperationOutcome entry
124
+ (`search.mode = outcome`) in the Bundle - unless the request has
125
+ `Prefer: handling=strict`, when they're a 400. Values that can't be understood (a
126
+ bad date or number) are always a 400.
127
+ parameters:
128
+ - name: _id
129
+ in: query
130
+ description: The report's id.
131
+ schema: { type: string }
132
+ - name: name
133
+ in: query
134
+ description: '`name` starts with this, case-insensitively. Modifiers: `:exact`, `:contains`, `:missing`.'
135
+ schema: { type: string }
136
+ example: tx-ecosystem
137
+ - name: tester
138
+ in: query
139
+ description: '`tester` starts with this, case-insensitively. Modifiers: `:exact`, `:contains`, `:missing`.'
140
+ schema: { type: string }
141
+ - name: status
142
+ in: query
143
+ description: '`status`, exactly (a `system|` prefix is ignored). Modifiers: `:not`, `:missing`.'
144
+ schema: { type: string }
145
+ example: completed
146
+ - name: result
147
+ in: query
148
+ description: '`result`, exactly. Modifiers: `:not`, `:missing`.'
149
+ schema: { type: string }
150
+ example: fail
151
+ - name: testscript
152
+ in: query
153
+ description: '`testScript` (the R5 canonical, or the R4 reference), exactly. Modifiers: `:below` (starts with), `:missing`.'
154
+ schema: { type: string }
155
+ - name: participant
156
+ in: query
157
+ description: 'The `uri` of any participant, exactly. Modifier: `:below` (starts with).'
158
+ schema: { type: string }
159
+ example: http://tx.fhir.org/r4
160
+ - name: score
161
+ in: query
162
+ description: '`score`, with a prefix (`eq` `ne` `gt` `lt` `ge` `le` `sa` `eb` `ap`); `eq` has implicit precision (`90` means 89.5 to 90.5). Modifier: `:missing`.'
163
+ schema: { type: string }
164
+ example: ge90
165
+ - name: issued
166
+ in: query
167
+ description: '`issued`, with a prefix; dates are ranges (`issued=2026-09` is all of September).'
168
+ schema: { type: string }
169
+ example: ge2026-09
170
+ - name: _lastUpdated
171
+ in: query
172
+ description: When the report was received, with a prefix.
173
+ schema: { type: string }
174
+ - name: _sort
175
+ in: query
176
+ description: Any of the parameters above except `_id`, comma separated, `-` for descending.
177
+ schema: { type: string }
178
+ example: -issued
179
+ - name: _count
180
+ in: query
181
+ description: Page size; defaults to 50, at most 500. `0` returns just the total.
182
+ schema: { type: integer, minimum: 0, maximum: 500 }
183
+ - name: _offset
184
+ in: query
185
+ description: Where the page starts. The Bundle has first, previous, next and last links.
186
+ schema: { type: integer, minimum: 0 }
187
+ - name: _summary
188
+ in: query
189
+ description: '`count` returns just the total.'
190
+ schema: { type: string, enum: [count] }
191
+ - name: _format
192
+ in: query
193
+ description: '`json` or `html`, overriding the `Accept` header.'
194
+ schema: { type: string }
195
+ - name: _total
196
+ in: query
197
+ description: Accepted, and has no effect - the total is always returned.
198
+ schema: { type: string }
199
+ - name: _pretty
200
+ in: query
201
+ description: Accepted, and has no effect - responses are always indented.
202
+ schema: { type: string }
203
+ - name: Prefer
204
+ in: header
205
+ description: '`handling=strict` makes unknown parameters an error.'
206
+ schema: { type: string }
207
+ responses:
208
+ '200':
209
+ description: The matching reports
210
+ content:
211
+ application/fhir+json:
212
+ schema: { $ref: '#/components/schemas/TestReportSearchBundle' }
213
+ text/html:
214
+ schema: { type: string }
215
+ '400': { $ref: '#/components/responses/Invalid' }
216
+
217
+ /TestReport/{id}:
218
+ get:
219
+ tags: [TestReport]
220
+ operationId: readTestReport
221
+ summary: Read a report
222
+ parameters:
223
+ - name: id
224
+ in: path
225
+ required: true
226
+ schema: { type: string }
227
+ responses:
228
+ '200':
229
+ description: The report, or a rendering of it for a browser
230
+ headers:
231
+ Last-Modified:
232
+ schema: { type: string }
233
+ content:
234
+ application/fhir+json:
235
+ schema: { $ref: '#/components/schemas/TestReport' }
236
+ text/html:
237
+ schema: { type: string }
238
+ '404':
239
+ description: No such report
240
+ content:
241
+ application/fhir+json:
242
+ schema: { $ref: '#/components/schemas/OperationOutcome' }
243
+
244
+ /metadata:
245
+ get:
246
+ tags: [server]
247
+ operationId: capabilities
248
+ summary: The server's CapabilityStatement
249
+ description: |
250
+ Lists the interactions and search parameters. The search parameters have no
251
+ definitions (see the search operation for what they do).
252
+ responses:
253
+ '200':
254
+ description: A CapabilityStatement
255
+ content:
256
+ application/fhir+json:
257
+ schema: { $ref: '#/components/schemas/AnyResource' }
258
+
259
+ components:
260
+ securitySchemes:
261
+ submitToken:
262
+ type: http
263
+ scheme: bearer
264
+ description: |
265
+ Required for submitting reports if the server is configured with a token. Sent in the
266
+ `Authorization` header by default; a server can be configured to use another header.
267
+
268
+ responses:
269
+ Invalid:
270
+ description: The request isn't acceptable - the issues say why
271
+ content:
272
+ application/fhir+json:
273
+ schema: { $ref: '#/components/schemas/OperationOutcome' }
package/testing/readme.md CHANGED
@@ -13,7 +13,9 @@ makes them available through a FHIR API and a set of web pages. It runs at `/tes
13
13
  R4 and R5 TestReports are treated the same. A report is accepted if it is JSON, has
14
14
  `resourceType: TestReport`, and has `name`, `status`, `result`, `tester`, `issued` (a valid
15
15
  dateTime) and at least one `participant` with a `uri`. `score`, if present, must be a number.
16
- Nothing else is checked.
16
+ Contained resources are not accepted. Nothing else is checked - but the TestReport schema in
17
+ the OpenAPI description (below) says what a valid report looks like, and reports should
18
+ conform to it.
17
19
 
18
20
  The server gives the report a new id (any id sent is ignored), sets `meta.lastUpdated` to the
19
21
  time it was received, and drops `meta.versionId`: reports can't be changed once received, so
@@ -65,6 +67,46 @@ Unknown parameters are ignored, with a warning OperationOutcome in the Bundle, u
65
67
  request has `Prefer: handling=strict`, in which case they're a 400. Values that can't be
66
68
  understood (a bad date or number) are always a 400.
67
69
 
70
+ ## OpenAPI description
71
+
72
+ The FHIR API (create, read, search, metadata) is described by an OpenAPI 3.1 spec:
73
+
74
+ | URL | |
75
+ |---|---|
76
+ | `/testing/openapi` | Browsable reference (HTML), with a "try it" form for each GET operation |
77
+ | `/testing/openapi.json` | The spec as JSON |
78
+ | `/testing/openapi.yaml` | The hand-written part, as YAML ([openapi.yaml](openapi.yaml)) |
79
+
80
+ Every response carries a `Link: </testing/openapi.json>; rel="service-desc"` header (RFC 8631),
81
+ and the HTML pages carry the matching `<link>` element. Deleting reports and the
82
+ administration pages are deliberately not described.
83
+
84
+ The spec is in two parts:
85
+
86
+ * [openapi.yaml](openapi.yaml) - the paths, parameters and responses, written by hand
87
+ * [openapi-schemas.json](openapi-schemas.json) - the FHIR schemas (TestReport, Bundle,
88
+ OperationOutcome, the datatypes they use, and `TestReportSearchBundle`), generated from the R5
89
+ StructureDefinitions by `library/fhir-openapi-schema.js`, as configured in
90
+ [openapi-schemas.config.js](openapi-schemas.config.js). The loader merges them into the spec.
91
+
92
+ The generated schemas are closed (no properties FHIR doesn't define), include the `_x`
93
+ siblings of primitive elements (so extensions on primitives, like `_name`, are allowed), and
94
+ use the codes of required bindings as enums. Recursion is cut at two boundaries: an extension's
95
+ value isn't described, and a resource inside another (`Bundle.entry.resource`) is "any resource"
96
+ unless the config narrows it. `contained` is left out, so it isn't allowed. The config's overlay
97
+ adds what this server requires beyond the base resource, and lets `testScript` be an R4
98
+ Reference.
99
+
100
+ After changing the config, regenerate (this needs `hl7.fhir.r5.core#5.0.0` in the
101
+ terminology cache):
102
+
103
+ node utilities/generate-openapi-schemas.js testing
104
+
105
+ `tests/testing/openapi.test.js` fails if the generated file is out of date, if a route or search
106
+ parameter isn't described (or excluded), or if the TestReport schema doesn't require everything
107
+ `validateReport()` requires. It also validates what the server actually returns (a stored
108
+ report, a search Bundle, an OperationOutcome) against the schemas, using ajv.
109
+
68
110
  ## Web pages
69
111
 
70
112
  * `/testing` - the list of reports, with filters (these map onto the search parameters above),
@@ -78,6 +120,38 @@ Everything in a report comes from whoever sent it, so all of it is escaped, and
78
120
  URLs become links. The narrative (`text.div`) is never rendered as HTML - it appears only as
79
121
  text in the raw JSON.
80
122
 
123
+ ## What the pages show
124
+
125
+ The list has a column each for the test engine, client and server participants (the client
126
+ column only appears once some report has a client; a participant of any other type is shown
127
+ as a server). **Tests** is the number of entries in `TestReport.test`. **Run Length** is how long the run took, from the earliest `test.period.start`
128
+ to the latest `test.period.end`; it is blank when the report's tests have no periods. Both are
129
+ worked out when the report is received, and for reports received before they existed, the
130
+ first time the server starts with this version.
131
+
132
+ Where a test script or participant URL, ignoring any `|version`, is one of the **named
133
+ links**, its name is shown instead of the URL - linked to the named link's link, with the
134
+ full URL in the tooltip and the version after the name.
135
+
136
+ ## Administration
137
+
138
+ `/testing/login`. The administrator logs in as `admin` with the `adminPassword` from the
139
+ configuration, and manages the other users at `/testing/admin/users`. A user can have either
140
+ or both of two rights:
141
+
142
+ * **edit named links** - `/testing/admin/links`: the canonical URLs that are shown by name
143
+ * **delete reports** - a Delete button on each report's page
144
+
145
+ Logins work as the publisher's do: a session cookie (set `sessionSecret`, and `cookieSecure:
146
+ false` if the server is reached over plain http), bcrypt password hashes, and a rate limited
147
+ login (`loginAttemptsPerWindow`, default 20 per 15 minutes). Rights are checked on every
148
+ request, so changing or deleting a user takes effect at once. Every form post must come from
149
+ the server's own pages: each form carries a per-session CSRF token (lusca) that the post must
150
+ return, the cookie is SameSite=Lax, and a post whose `Origin` is another host is refused
151
+ (behind a proxy, that needs the proxy to pass on `Host` or `X-Forwarded-Host`). The session
152
+ and CSRF checks are only on the web pages: the FHIR API is authenticated by the header
153
+ token, and sets no cookie.
154
+
81
155
  ## Deleting
82
156
 
83
157
  DELETE /testing/TestReport/{id}