@dcmjs-org/schemas 0.0.0-stage → 1.0.0-beta.10
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.
- package/License.txt +22 -0
- package/README.md +120 -2
- package/dist/index.cjs +929 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +917 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +30 -3
- package/schema/naturalized.schema.json +52282 -0
- package/types/dcmjs-schema.d.ts +10374 -0
package/License.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2017 Steve Pieper
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,121 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dcmjs-org/schemas
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The rules of the naturalized representation — the plain-JavaScript view of
|
|
4
|
+
a DICOM dataset that `DicomMetaDictionary.naturalizeDataset` returns —
|
|
5
|
+
published three ways: as a runtime rules module, as a JSON Schema, and as
|
|
6
|
+
TypeScript declarations.
|
|
7
|
+
|
|
8
|
+
## What this package is for
|
|
9
|
+
|
|
10
|
+
dcmjs turns a parsed dataset into natural JavaScript: `dataset.PatientID`
|
|
11
|
+
instead of raw tag numbers. The *shape* of that view follows rules — which
|
|
12
|
+
keyword a tag maps to, whether a value is a scalar or a list, what a
|
|
13
|
+
sequence or a person name or pixel data looks like, and when a value is
|
|
14
|
+
null. Those rules used to live implicitly in parser code. This package
|
|
15
|
+
states them explicitly, for three consumers:
|
|
16
|
+
|
|
17
|
+
- **validators** (any JSON Schema tool) use `schema/naturalized.schema.json`
|
|
18
|
+
to check that an object has the naturalized shape;
|
|
19
|
+
- **editors and TypeScript builds** use `types/dcmjs-schema.d.ts` for
|
|
20
|
+
the `NaturalizedDataset` property types;
|
|
21
|
+
- **runtime code** (a validator UI, an anonymizer checking its tag list, a
|
|
22
|
+
form generator) imports the rules module to look up one attribute's rule.
|
|
23
|
+
|
|
24
|
+
## How this differs from the dictionary dcmjs already has
|
|
25
|
+
|
|
26
|
+
It is not a copy of the dictionary. The per-attribute rules **derive on
|
|
27
|
+
demand** from the packed dictionary that `@dcmjs-org/core` already ships —
|
|
28
|
+
through the same `isMultiVM` rule the runtime uses, so the schema and the
|
|
29
|
+
runtime cannot drift apart. What this package adds is the *semantics* on
|
|
30
|
+
top of the raw `{tag, vr, vm}` table:
|
|
31
|
+
|
|
32
|
+
- the naturalized cardinality (`multi`: scalar vs list) per attribute,
|
|
33
|
+
- the resolution of ambiguous dictionary VR codes (`xs`, `ox`, `up`, `lt`)
|
|
34
|
+
into explicit VR unions,
|
|
35
|
+
- the contract decisions frozen in the `envelope` block (see below),
|
|
36
|
+
- the Part 5 value formats (`vrFormats`) as reference documentation,
|
|
37
|
+
- and the two static projections (JSON Schema, `.d.ts`) that ajv and tsc
|
|
38
|
+
need as files.
|
|
39
|
+
|
|
40
|
+
The package lives in this repository because the rules must change in the
|
|
41
|
+
same commit as the runtime behavior they describe — CI regenerates the
|
|
42
|
+
projections and fails when they drift. A consumer does not regenerate
|
|
43
|
+
anything: the two artifacts are committed, and the rules module computes
|
|
44
|
+
from the dictionary at require-time (about 5k rules, built once, cached).
|
|
45
|
+
|
|
46
|
+
## The value contract (`envelope`)
|
|
47
|
+
|
|
48
|
+
`envelope.values: "asReturned"` — the schema describes **what dcmjs
|
|
49
|
+
returns**, not what Part 5 permits. Concretely: a present-but-empty
|
|
50
|
+
element is `null` (every property type carries null), list entries can be
|
|
51
|
+
null, an empty date string or a malformed age passes through unchanged,
|
|
52
|
+
and `vrFormats` documents the Part 5 formats without enforcing them. A
|
|
53
|
+
separate Part 5 conformance check can use `vrFormats` to report them.
|
|
54
|
+
|
|
55
|
+
Other tokens: sequences are a dataset array or the single item itself
|
|
56
|
+
(`datasetArrayOrItem` — a one-item sequence naturalizes as the item, with
|
|
57
|
+
a hidden `[0]`, `length`, and iterator); binary values are a frame list or
|
|
58
|
+
one bulk reference (`{BulkDataURI}` / `{InlineBinary}`); person names are
|
|
59
|
+
component objects (`{Alphabetic, Ideographic, Phonetic}`). UV and SV
|
|
60
|
+
values are `bigint` — note `JSON.stringify` throws on bigint.
|
|
61
|
+
|
|
62
|
+
## Which artifact for which task
|
|
63
|
+
|
|
64
|
+
| Task | Artifact |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| Validate a naturalized dataset | `schema/naturalized.schema.json` with ajv |
|
|
67
|
+
| Type a dataset in TypeScript | `types/dcmjs-schema.d.ts` (`NaturalizedDataset`) |
|
|
68
|
+
| Look up one attribute's rule at runtime | `getAttributeRule(tag)` from the module |
|
|
69
|
+
| Check a keyword list / walk a dataset | `buildAttributeRules()` from the module |
|
|
70
|
+
| Cite a contract decision | `envelope` from the module |
|
|
71
|
+
| Report Part 5 format violations | `vrFormats` from the module |
|
|
72
|
+
|
|
73
|
+
## Usage
|
|
74
|
+
|
|
75
|
+
Validate a naturalized dataset (what `test/schema/naturalizedValidation.test.js`
|
|
76
|
+
does):
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
import { readFileSync } from "fs";
|
|
80
|
+
import Ajv2020 from "ajv/dist/2020";
|
|
81
|
+
import dcmjs from "dcmjs";
|
|
82
|
+
|
|
83
|
+
const schema = JSON.parse(
|
|
84
|
+
readFileSync("packages/schemas/schema/naturalized.schema.json", "utf8")
|
|
85
|
+
);
|
|
86
|
+
// strictSchema off: the schema carries x-dicom-* annotation keywords
|
|
87
|
+
const validate = new Ajv2020({ strictSchema: false }).compile(schema);
|
|
88
|
+
|
|
89
|
+
const { DicomMessage, DicomMetaDictionary } = dcmjs.data;
|
|
90
|
+
const dataset = DicomMetaDictionary.naturalizeDataset(
|
|
91
|
+
DicomMessage.readFile(arrayBuffer).dict
|
|
92
|
+
);
|
|
93
|
+
if (!validate(dataset)) {
|
|
94
|
+
console.log(validate.errors);
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Look up rules at runtime:
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
import {
|
|
102
|
+
getAttributeRule,
|
|
103
|
+
envelope
|
|
104
|
+
} from "@dcmjs-org/schemas";
|
|
105
|
+
|
|
106
|
+
getAttributeRule("00080008");
|
|
107
|
+
// { keyword: "ImageType", vr: "CS", vm: "2-n", multi: true }
|
|
108
|
+
envelope.values; // "asReturned"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Regeneration
|
|
112
|
+
|
|
113
|
+
`generate/` holds the generator; run `pnpm run generate-schema` from the
|
|
114
|
+
repository root to rebuild the two committed artifacts
|
|
115
|
+
(`schema/naturalized.schema.json`, `types/dcmjs-schema.d.ts`).
|
|
116
|
+
Regeneration is deterministic — CI fails when the committed artifacts do
|
|
117
|
+
not match the generator output.
|
|
118
|
+
|
|
119
|
+
The package is private until its package-merge review flips it; the
|
|
120
|
+
IOD catalog half of the schema work lands later with the validation
|
|
121
|
+
package that consumes it.
|