cda-schematron-validator 1.1.11 → 2.0.0-preview.1

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 (48) hide show
  1. package/LICENSE.md +9 -9
  2. package/README.md +222 -239
  3. package/bin/cda-validate.js +36 -0
  4. package/docs/api.md +134 -0
  5. package/docs/architecture.md +102 -0
  6. package/docs/coverage.md +112 -0
  7. package/docs/deployment.md +126 -0
  8. package/docs/history.md +245 -0
  9. package/docs/legacy-api.md +70 -0
  10. package/lib/checkIfFileOrPath.js +27 -28
  11. package/lib/checkRule.js +97 -98
  12. package/lib/createClient.js +35 -0
  13. package/lib/getAssertionObject.js +23 -23
  14. package/lib/getErrorsAndWarnings.js +41 -41
  15. package/lib/getFailedAssertions.js +24 -25
  16. package/lib/getIgnored.js +27 -27
  17. package/lib/getResults.js +22 -22
  18. package/lib/getReturnObject.js +20 -20
  19. package/lib/getSchematronMap.js +34 -31
  20. package/lib/getSelectXmlChunk.js +27 -27
  21. package/lib/includeExternalDocument.js +113 -107
  22. package/lib/initializeProcess.js +34 -40
  23. package/lib/parseSchematron.js +122 -122
  24. package/lib/processFailedAssertions.js +17 -17
  25. package/lib/processRules.js +20 -20
  26. package/lib/processRulesAsync.js +18 -30
  27. package/lib/testAssertion.js +74 -74
  28. package/package.json +67 -59
  29. package/validateAsync.js +103 -117
  30. package/validateSync.js +51 -55
  31. package/validator.d.ts +87 -0
  32. package/validator.js +17 -16
  33. package/.eslintrc.js +0 -30
  34. package/.github/workflows/codeql-analysis.yml +0 -70
  35. package/.husky/pre-commit +0 -5
  36. package/.jshintrc +0 -96
  37. package/.vscode/launch.json +0 -37
  38. package/Gruntfile.js +0 -28
  39. package/SECURITY.md +0 -21
  40. package/test/CDAR2_IG_CCDA_CLINNOTES_R1_DSTU2.1_2015AUG_Vol2_2019JUNwith_errata.sch +0 -71
  41. package/test/VitalSigns.xml +0 -856
  42. package/test/async.test.js +0 -124
  43. package/test/asyncFileList.test.js +0 -61
  44. package/test/test.sch +0 -47
  45. package/test/test.xml +0 -80
  46. package/test/tests.js +0 -140
  47. package/test/vitalSigns.test.js +0 -34
  48. package/test/voc.xml +0 -44
package/LICENSE.md CHANGED
@@ -1,10 +1,10 @@
1
- License (MIT)
2
- Copyright © 2017 Eric Wadkins
3
-
4
- Copyright © 2022 Priyaranjan (Raj) Tokachichu
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
-
8
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
-
1
+ License (MIT)
2
+ Copyright © 2017 Eric Wadkins
3
+
4
+ Copyright © 2022 Priyaranjan (Raj) Tokachichu
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
10
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,239 +1,222 @@
1
- # [cda-schematron-validator](https://github.com/priyaranjan-tokachichu/cda-schematron-validator)
2
-
3
- ## Release History
4
-
5
- ### 1.1.11
6
-
7
- - License file added
8
-
9
- ### 1.1.10
10
-
11
- - Fix grunt race condition reported by github
12
-
13
- "file.copy operations in GruntJS are vulnerable to a TOCTOU race condition leading to arbitrary file write in GitHub repository gruntjs/grunt prior to 1.5.3. This vulnerability is capable of arbitrary file writes which can lead to local privilege escalation to the GruntJS user if a lower-privileged user has write access to both source and destination directories as the lower-privileged user can create a symlink to the GruntJS user's .bashrc file or replace /etc/shadow file if the GruntJS user is root."
14
-
15
- ### 1.1.9
16
-
17
- - Fix grunt vulnerability
18
-
19
- ### 1.1.8
20
-
21
- - jsdoc module added
22
- - parseSchematron.js moved to lib
23
-
24
- ### 1.1.7
25
-
26
- - Introduced a new method called `validateFileObjectAsync` which allows to supply an object with key, value pairs where key represents the identifier of the xml, and the value represents xml file content or path to validate
27
- - An array of results will be returned from the `validateFileObjectAsync` method
28
- - Test file `test/asyncFileList.test.js` has the example usage
29
- - The result object has the property `fileInfo` that would return the `key` the identifier of the xml to identify and debug issues
30
- - The result object of the array result from the method `validateFileListAsync` now has the property `fileIndex` that will give an indication of which xml file the result belongs to for debugging purposes
31
-
32
- ### 1.1.6
33
-
34
- - Methods have been moved to js files and relocated to lib directory
35
- - Introduced a new method called `validateFileListAsync` which allows to supply an array of xml file content or paths to validate
36
- - An array of results will be returned from the `validateFileListAsync` method
37
- - Test file `test/asyncFileList.test.js` has the example usage
38
- - Started to make use of Promise.all for async methods
39
- - Documentation of the methods completed by 40%
40
-
41
- ### 1.1.5
42
-
43
- - Major methods have been divided into multiple small methods to avoid redundancy across sync and async methods, and reduce maintenance
44
-
45
- ### 1.1.4 (Stable Release)
46
-
47
- - Major deviations from the source repository
48
-
49
- - By default the warning will be turned off in contrast to the parent repository
50
-
51
- - To get warnings, users have to explicitly specify the option `includeWarnings` with value boolean `true`
52
-
53
- - We also deviate from the previous behavior where all the checks for warnings were done at the assertion
54
- level just before testing the xpath. We now would not even parse the phase with @id="warnings" which should
55
- improve the performance.
56
-
57
- - Minor cosmetic changes to the code
58
-
59
- ### 1.1.1 to 1.1.3
60
-
61
- - Only keeping the necessary data in the test files taken from HL7 C-CDA schematron repository to avoid bloating the module
62
-
63
- - Added pre-commit hooks with husky
64
-
65
- - Added code standardization with prettier, ESLint, and lint-staged
66
-
67
- ### 1.1.0
68
-
69
- - Fix the issue with the rule check which was working in the original repository, but not in the fork
70
- - Added HL7 C-CDA schematron file and resource file from <https://github.com/HL7/CDA-ccda-2.1/releases/tag/2019JUN>
71
- - Added a test case vitalSigns.test.js that tests the resource file and sub assertions
72
- - Used resources <https://github.com/jddamore/ccda-samples> and <https://github.com/HL7/C-CDA-Examples/tree/master/Vital%20Signs> to create the test file vitalSigns.xml
73
-
74
- ### 1.0.10
75
-
76
- - Fix null context issue associated with assertions within assertions
77
- - Skip abstract rules associated with assertions within assertions
78
-
79
- ### 1.0.9
80
-
81
- - Fixed the bug introduced in 1.0.8 trying to adjust to different data types of the return value
82
- - Changed variable names to improve understanding of the process
83
-
84
- ### 1.0.8
85
-
86
- - Bug fix identifying the ignored errors
87
-
88
- ### 1.0.7
89
-
90
- - Added async validate function `validateAsync`
91
- - Added `testsAsync` to test `validateAsync`
92
- - Plan to use common functions between sync and async methods in the future release
93
-
94
- ### 1.0.0 to 1.0.6
95
-
96
- A fork to the original cda-schematron. All credit to Eric Wadkins. Visit the github <https://github.com/ewadkins/cda-schematron> for the original repo.
97
-
98
- This is just a cosmetic change with updated node modules, a couple of minor bugs observed, and esversion 6 changes.
99
-
100
- The changes are fully backward compatible. So, leaving the original documentation as is below.
101
-
102
- ### New option parameter parsedSchematronMap
103
-
104
- In addition to everything that was possible,
105
- you can now supply a new option parameter `parsedSchematronMap`. You can create a schematron map as follows.
106
-
107
- ```javascript
108
- const fs = require('fs');
109
- const dom = require('@xmldom/xmldom').DOMParser;
110
- const { parseSchematron, validate } = require('cda-schematron-validator');
111
- const schematronString = fs.readFileSync('SchematronFilePath', 'utf-8').toString();
112
- const schematronDoc = new dom().parseFromString(schematronString);
113
- const schematronMap = parseSchematron(schematronDoc);
114
- const options = {
115
- parsedSchematronMap: schematronMap
116
- };
117
- const results = validate('xml string or file path', 'schematron sting, file path or null', options);
118
- ```
119
-
120
- If a schematron map is provided, the schematron string or path will not be read.
121
-
122
- To install this npm module, it will be
123
-
124
- ```javascript
125
- npm i cda-schematron-validator
126
- ```
127
-
128
- Mocha VS Code configuratin added to directly execute the test file in `test/tests.js` using VS Code.
129
-
130
- ## Documentation of the parent repo [cda-schematron](https://github.com/ewadkins/cda-schematron)
131
-
132
- A javascript implementation of schematron testing for XML documents. This specifically resolves a need for a package that allows a quick, reliable install for validating HL7 clinical documents, such as C-CDA.
133
-
134
- Check out [cda-schematron-server](https://github.com/ewadkins/cda-schematron-server), a server wrapper of **cda-schematron**, for easy schematron validation.
135
-
136
- ### Validating xml
137
-
138
- ```javascript
139
- var validator = require('cda-schematron');
140
-
141
- var xmlPath = 'someFile.xml';
142
- var schematronPath = 'someFile.sch';
143
-
144
- var fs = require('fs');
145
- var xml = fs.readFileSync(xmlPath).toString();
146
- var schematron = fs.readFileSync(schematronPath).toString();
147
-
148
- var results = validator.validate(xml, schematron);
149
- ```
150
-
151
- File paths can also be passed to the validator directly. The following lines all return the same results:
152
-
153
- ```javascript
154
- var results = validator.validate(xml, schematronPath);
155
- ```
156
-
157
- ```javascript
158
- var results = validator.validate(xmlPath, schematron);
159
- ```
160
-
161
- ```javascript
162
- var results = validator.validate(xmlPath, schematronPath);
163
- ```
164
-
165
- ### Results
166
-
167
- ```results``` is an object containing arrays ```errors```, ```warnings```, and ```ignoreds```.
168
-
169
- **Errors** and **warnings** are reported as determined by the schematron and test descriptions. They are of the following form:
170
-
171
- ```javascript
172
- {
173
- type: type, // "error" or "warning"
174
- test: test, // xpath test
175
- simplifiedTest: simplifiedTest, // xpath test with resource values included, if applicable, null otherwise
176
- description: description, // schematron description of the test case
177
- line: line, // line number of the violating context
178
- path: path, // xpath path of the violating context
179
- patternId: patternId, // schematron-assigned pattern id
180
- ruleId: ruleId, // schematron-assigned rule id
181
- assertionId: assertionId, // schematron-assigned assertion id
182
- context: context, // xpath context of the rule
183
- xml: xml // xml snippet of the violating context
184
- }
185
- ```
186
-
187
- **Ignored** tests are those that resulted in an exception while running (eg. the test is invalid xpath and could not be parsed properly) and require manual inspection. They are of the following form:
188
-
189
- ```javascript
190
- {
191
- errorMessage: errorMessage, // reason for the exception/ignoring the test
192
- type: type, // "error" or "warning"
193
- test: test, // xpath test
194
- simplifiedTest: simplifiedTest, // xpath test with resource values included, if applicable, null otherwise
195
- description: description, // schematron description of the test case
196
- patternId: patternId, // schematron-assigned pattern id
197
- ruleId: ruleId, // schematron-assigned rule id
198
- assertionId: assertionId, // schematron-assigned assertion id
199
- context: context, // xpath context of the rule
200
- }
201
- ```
202
-
203
- ### Options
204
-
205
- The ```validate``` function takes in an ```options``` object as an optional third argument. The three fields that can be included in ```options``` are as follows:
206
-
207
- - **```includeWarnings```**: ```true``` or ```false```, this determines whether or not warnings should be tested and returned. Defaults to ```true```.
208
-
209
- - **```resourceDir```**: the path to a directory containing resource files (eg. voc.xml) which may be necessary for some schematron tests. Defaults to ```'./'```, the current directory.
210
-
211
- - **```xmlSnippetMaxLength```**: an integer, which is the maximum length of the ```xml``` field in validation results. Defaults to ```200```. Set to ```0``` for unlimited length.
212
-
213
- Here is an example with warnings disabled:
214
-
215
- ```javascript
216
- var results = validator.validate(xml, schematron, { includeWarnings: false });
217
- ```
218
-
219
- ### Cache
220
-
221
- The validator uses a cache to store parsed schematrons, an intermediate data structure used to store revelant schematron information. This reduces the runtime of the validator when validating against the same schematron multiple times. You can clear the cache at any time with:
222
-
223
- ```javascript
224
- validator.clearCache();
225
- ```
226
-
227
- ---
228
-
229
- ## License (MIT)
230
-
231
- Copyright &copy; 2017 [Eric Wadkins](http://www.ericwadkins.com/)
232
-
233
- Copyright &copy; 2022 [Priyaranjan (Raj) Tokachichu](https://github.com/priyaranjan-tokachichu)
234
-
235
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
236
-
237
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
238
-
239
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ <div align="center">
2
+
3
+ <h1>CDA Validator</h1>
4
+ <p><strong>Validate clinical XML. Understand every finding.</strong></p>
5
+ <p>A self-hosted API and browser workspace for CDA and C-CDA,<br>with the original JavaScript APIs preserved.</p>
6
+
7
+ <p>
8
+ <a href="#quick-start">Quick start</a> ·
9
+ <a href="docs/api.md">API reference</a> ·
10
+ <a href="docs/deployment.md">Deployment</a> ·
11
+ <a href="docs/architecture.md">Architecture</a> ·
12
+ <a href="docs/legacy-api.md">Legacy API</a>
13
+ </p>
14
+
15
+ </div>
16
+
17
+ ---
18
+
19
+ > [!NOTE]
20
+ > **Version 2.0.0-preview.1.** The container includes the validation API and browser UI. The npm package includes the preserved legacy APIs, a typed HTTP client, and the CLI. Node 22.12+ is required. This is a preview while C-CDA 5.0 coverage gaps are addressed; npm’s stable default remains 1.1.12. See the [release notes](https://github.com/priyaranjan-tokachichu/cda-schematron-validator/releases/tag/v2.0.0-preview.1) for artifacts and compatibility details.
21
+
22
+ <table>
23
+ <tr>
24
+ <td width="50%"><h3>Findings you can investigate</h3><p>XML parsing, CDA schema validation, and official HL7 Schematron checks. Reports include severity, rule identifiers, XPath, and available line/column locations.</p></td>
25
+ <td width="50%"><h3>A workspace anyone can use</h3><p>Upload or paste XML, choose an implementation guide, inspect errors and warnings, jump to a line, and download the JSON report.</p></td>
26
+ </tr>
27
+ <tr>
28
+ <td width="50%"><h3>Self-hosted and offline at runtime</h3><p>One container includes the UI, API, Java runtime, and pinned validation resources. Submitted documents are not persisted or sent to external validation services.</p></td>
29
+ <td width="50%"><h3>Existing integrations preserved</h3><p>The seven legacy npm exports remain available locally. A new typed HTTP client and CLI connect applications to the modern validation engine.</p></td>
30
+ </tr>
31
+ </table>
32
+
33
+ ## Quick start
34
+
35
+ Install Docker with Compose, then:
36
+
37
+ ```sh
38
+ git clone https://github.com/priyaranjan-tokachichu/cda-schematron-validator.git
39
+ cd cda-schematron-validator
40
+ ```
41
+
42
+ Start the service:
43
+
44
+ ```sh
45
+ docker compose up --build -d
46
+ ```
47
+
48
+ **Open [the validation workspace](http://localhost:17643).** Try the synthetic example, or upload a UTF-8 XML document. The example intentionally contains errors so you can explore the findings.
49
+
50
+ | Open locally | Purpose |
51
+ | --- | --- |
52
+ | [Workspace](http://localhost:17643/) | Upload, paste, validate, and inspect findings |
53
+ | [Architecture report](http://localhost:17643/architecture.html) | Design, sources, limitations, and verification evidence |
54
+ | [OpenAPI contract](http://localhost:17643/openapi.json) | Integrate the HTTP API |
55
+ | [Readiness](http://localhost:17643/health/ready) | Confirm the profiles have compiled |
56
+
57
+ The first build downloads checksum-verified resources and dependencies. Normal validation runs offline. You do not need to install Java, Maven, Python, or Node on the host to run the container.
58
+
59
+ <details>
60
+ <summary><strong>Change the port, inspect logs, or stop the service</strong></summary>
61
+
62
+ The default host port is **17643**, bound to loopback. Choose a different port if needed:
63
+
64
+ ```sh
65
+ CDA_VALIDATOR_PORT=17644 docker compose up -d
66
+ docker compose logs validator
67
+ docker compose down
68
+ ```
69
+
70
+ When changing the port, use the matching URL in browsers and API clients. See [deployment and configuration](docs/deployment.md).
71
+
72
+ </details>
73
+
74
+ ## Choose your integration
75
+
76
+ | Use case | Interface | Runtime |
77
+ | --- | --- | --- |
78
+ | Validate a document manually | Browser workspace | Docker |
79
+ | Integrate any application or language | `POST /v1/validate` | HTTP + JSON |
80
+ | Integrate a Node application | `createClient()` | Node 22.12+ and the service |
81
+ | Validate from a terminal or script | `cda-validate` | Node 22.12+ and the service |
82
+ | Keep an existing JavaScript integration | Original `validate*`, parser, and cache APIs | Node only; no Java or Docker |
83
+
84
+ The legacy API remains a partial Schematron interpreter. Use the service for CDA XSD validation and execution of the pinned full official Schematron packages.
85
+
86
+ ## Supported standards
87
+
88
+ | Profile | Official Schematron release | CDA schema |
89
+ | --- | --- | --- |
90
+ | **C-CDA 2.1** · `ccda-2.1` | `2025SEP`, with bundled vocabulary | CDA R2 + SDTC `20260205_SDTC` |
91
+ | **C-CDA 5.0** · `ccda-5.0` · default | `2026JUL` | CDA R2 + SDTC `20260205_SDTC` |
92
+
93
+ Sources are pinned by immutable release URL and SHA-256. The build verifies downloads; startup verifies extracted files. `GET /v1/profiles` exposes provenance, active limits, and known coverage gaps. [Inspect the source lock](profiles/sources.lock.json).
94
+
95
+ > [!IMPORTANT]
96
+ > **C-CDA 5.0 has known upstream conversion gaps:** 4 generation errors, 6 unhandled invariants across 4 categories, and 28 non-loaded value-set entries across 9 categories. Its embedded value-set expansions cover sets with fewer than 1,000 concepts. The service reports incomplete coverage even when execution succeeds. A supported document-level template is required for complete document validation; nested templates alone are insufficient.
97
+
98
+ Neither profile certifies clinical accuracy or every terminology requirement. See [standards, provenance, and coverage](docs/architecture.md#standards-and-coverage).
99
+
100
+ ## Call the API
101
+
102
+ Save this minimal example as `request.json`. It intentionally produces validation findings:
103
+
104
+ ```json
105
+ {
106
+ "xml": "<ClinicalDocument xmlns=\"urn:hl7-org:v3\"/>",
107
+ "profile": "ccda-2.1",
108
+ "includeWarnings": true
109
+ }
110
+ ```
111
+
112
+ ```sh
113
+ curl http://localhost:17643/v1/validate \
114
+ -H 'Content-Type: application/json' \
115
+ --data-binary @request.json
116
+ ```
117
+
118
+ | Report status | Meaning |
119
+ | --- | --- |
120
+ | `valid` | No errors; configured checks and document coverage completed without recorded generation gaps or truncation |
121
+ | `invalid` | Errors found; inspect completeness separately |
122
+ | `incomplete` | No errors found, but execution or coverage is incomplete; this is not a pass |
123
+
124
+ **HTTP 200 means a report was produced, not that the document passed.** Inspect `status`, `executionComplete`, `validationComplete`, and `findings`.
125
+
126
+ [Request/response examples, endpoints, authentication, and error codes →](docs/api.md)
127
+
128
+ ## JavaScript, TypeScript, and CLI
129
+
130
+ Install the package into your Node project:
131
+
132
+ ```sh
133
+ npm install cda-schematron-validator@next
134
+ ```
135
+
136
+ ```javascript
137
+ const { createClient } = require('cda-schematron-validator');
138
+ const { readFileSync } = require('node:fs');
139
+
140
+ async function main() {
141
+ const client = createClient({ baseUrl: 'http://localhost:17643' });
142
+ const report = await client.validate(readFileSync('document.xml', 'utf8'), {
143
+ profile: 'ccda-2.1',
144
+ includeWarnings: true
145
+ });
146
+ console.log(report.status, report.findings);
147
+ }
148
+
149
+ main().catch(error => {
150
+ console.error(error.message);
151
+ process.exitCode = 1;
152
+ });
153
+ ```
154
+
155
+ From the checkout, with the service running:
156
+
157
+ ```sh
158
+ node bin/cda-validate.js document.xml --profile ccda-2.1 --json
159
+ # After package installation:
160
+ cda-validate document.xml --profile ccda-2.1 --json
161
+ ```
162
+
163
+ CLI exit codes: **0** valid · **1** invalid · **2** incomplete or operational failure. Use `CDA_VALIDATOR_URL`, `CDA_VALIDATOR_TOKEN`, or `--url` for your deployment. The CLI accepts `-` for stdin. Type declarations are included; CI checks Node 22 and 24.
164
+
165
+ [Client configuration →](docs/api.md#node-client-and-cli) · [Legacy API and migration →](docs/legacy-api.md)
166
+
167
+ ## Capacity, queue, and privacy
168
+
169
+ | Default | Behavior |
170
+ | --- | --- |
171
+ | **20 MiB XML** | Configurable with `MAX_XML_MIB`; the API and UI advertise the active limit |
172
+ | **6 admitted requests** | Includes upload, queued, and validation work; 2 validation workers |
173
+ | **30-second upload queue wait** | Admitted uploads wait fairly for memory on their original HTTP request |
174
+ | **Shared upload memory budget** | Streaming decoding reserves memory before reading; serialized JSON is never retained in full |
175
+ | **No document persistence** | No patient-document/result cache, database, or application logging of submitted XML/findings |
176
+
177
+ **For more concurrent large uploads, increase Java heap and container memory together:**
178
+
179
+ ```sh
180
+ VALIDATOR_MEMORY_LIMIT=3g VALIDATOR_JAVA_OPTIONS=-Xmx2g docker compose up -d
181
+ ```
182
+
183
+ More heap can permit more large uploads concurrently. CPU and document complexity still affect validation speed. The UI's **Service capacity and queue** panel explains the active configuration. A full queue returns HTTP 429; an expired upload queue wait returns HTTP 503.
184
+
185
+ The isolated 1 GiB-heap regression processes **six simultaneous 20 MiB documents**, each encoded as roughly 120 MiB JSON, with both known-length and chunked uploads. All six complete without retries; health probes and post-load validation pass. [Recorded evidence](reports/upload-memory.json).
186
+
187
+ [Memory tuning, security, authentication, deadlines, and all limits →](docs/deployment.md)
188
+
189
+ ## Documentation
190
+
191
+ | Guide | What you will find |
192
+ | --- | --- |
193
+ | [HTTP API](docs/api.md) | Payloads, reports, endpoints, errors, Node client, and CLI |
194
+ | [Deployment](docs/deployment.md) | Docker, configuration, queueing, heap tuning, and secure shared access |
195
+ | [Architecture](docs/architecture.md) | Runtime design, standards, provenance, privacy, and verification |
196
+ | [Legacy API](docs/legacy-api.md) | Existing exports, defaults, examples, and migration boundaries |
197
+ | [Historical documentation](docs/history.md) | Original release history, inherited examples, and attribution |
198
+ | [Contributing](CONTRIBUTING.md) | Development checks and owner-managed contribution policy |
199
+ | [Security](SECURITY.md) | Reporting vulnerabilities and deployment responsibilities |
200
+
201
+ For the complete HTML engineering report, start the service and open [localhost:17643/architecture.html](http://localhost:17643/architecture.html). Its source and evidence are in [reports/](reports/).
202
+
203
+ ## Development
204
+
205
+ Local service development requires Java 21+, Maven 3.9+, and Python 3.11+. Node is required for the JavaScript library and its tests.
206
+
207
+ ```sh
208
+ npm ci --ignore-scripts
209
+ npm test
210
+ npm run service:build
211
+ npm run service:start
212
+ ```
213
+
214
+ `npm run service:test` exercises both official HL7 packages. `python3 scripts/check-upload-memory.py` runs the constrained-heap queue regression using Docker and curl. These checks run in CI alongside CodeQL. [Verification details](docs/architecture.md#verification).
215
+
216
+ Public issues are welcome. This repository accepts owner-authored PRs; changes reach `main` through review. See [CONTRIBUTING.md](CONTRIBUTING.md).
217
+
218
+ ---
219
+
220
+ **License and attribution** · [MIT](LICENSE.md) · [Third-party notices](THIRD_PARTY_NOTICES.md)
221
+
222
+ Original JavaScript implementation by **Eric Wadkins**, developed further by **Priyaranjan (Raj) Tokachichu**. John D'Amore's public clinical samples are credited in the source fixtures. This product includes software developed by Health Level Seven. HL7 resources and bundled dependencies retain their own licenses and notices.
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ const fs = require('node:fs');
4
+ const createClient = require('../lib/createClient');
5
+
6
+ async function main() {
7
+ const args = process.argv.slice(2);
8
+ let file, profile = 'ccda-5.0', baseUrl = process.env.CDA_VALIDATOR_URL || 'http://127.0.0.1:17643';
9
+ let json = false, includeWarnings = true;
10
+ for (let i = 0; i < args.length; i++) {
11
+ if (args[i] === '--help' || args[i] === '-h') {
12
+ console.log('Usage: cda-validate FILE|- [--profile ccda-5.0|ccda-2.1] [--url URL] [--json] [--no-warnings]\nSet CDA_VALIDATOR_TOKEN for authenticated services. Exit: 0 valid; 1 invalid; 2 incomplete or execution error.');
13
+ return;
14
+ }
15
+ if (args[i] === '--profile' || args[i] === '--url') {
16
+ const option = args[i], value = args[++i];
17
+ if (!value) throw new Error('Missing value for ' + option);
18
+ if (option === '--profile') profile = value; else baseUrl = value;
19
+ } else if (args[i] === '--json') json = true;
20
+ else if (args[i] === '--no-warnings') includeWarnings = false;
21
+ else if (!file && (args[i] === '-' || !args[i].startsWith('-'))) file = args[i];
22
+ else throw new Error('Unknown argument: ' + args[i]);
23
+ }
24
+ if (!file) throw new Error('An XML file or - for stdin is required. Use --help for usage.');
25
+ const data = fs.readFileSync(file === '-' ? 0 : file);
26
+ const xml = new TextDecoder('utf-8', { fatal: true }).decode(data);
27
+ const report = await createClient({ baseUrl, token: process.env.CDA_VALIDATOR_TOKEN }).validate(xml, { profile, includeWarnings });
28
+ if (json) console.log(JSON.stringify(report, null, 2));
29
+ else {
30
+ console.log(`${report.status.toUpperCase()} · ${report.profile.name} / ${report.profile.release} · ${report.summary.errors} errors · ${report.summary.warnings} warnings · ${report.durationMs} ms`);
31
+ for (const f of report.findings) console.log(`${f.severity.toUpperCase()} [${f.stage}]${f.line ? ' line ' + f.line : ''}: ${f.message}`);
32
+ if (!report.validationComplete) console.log('Coverage is incomplete; inspect the profile limitations and stage results.');
33
+ }
34
+ process.exitCode = report.status === 'invalid' ? 1 : report.validationComplete ? 0 : 2;
35
+ }
36
+ main().catch((error) => { console.error(error.message); process.exitCode = 2; });