Skip to content

feat: add the @dcmjs/schemas package with the naturalized-rules catalog generator - #522

Merged
awatson1978 merged 2 commits into
release/1.0-beta-schemasfrom
schemas/catalog-toolchain
Sep 29, 2026
Merged

awatson1978 merged 2 commits into
release/1.0-beta-schemasfrom
schemas/catalog-toolchain

Conversation

@awatson1978

@awatson1978 awatson1978 commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

This PR starts the @dcmjs/schemas package. It's step 3 of section 6 in RELEASE_PLAN.md, and it covers the naturalized-rules half of the schema work. Quick context for anyone who hasn't been following the branch: the "naturalized" representation is the plain-JavaScript view of a DICOM dataset — dataset.PatientName instead of raw tag numbers. This package builds a machine-readable catalog that says, for every standard DICOM attribute, what its keyword is, what type it holds (its VR, or value representation), and how many values it can carry (its VM, or value multiplicity).

Three pieces land here, all under packages/schemas/generate/:

  • buildCatalog.mjs — the catalog builder. It's deliberately pure (no file I/O, no import.meta) so jest can import it directly, which the CI reproducibility gates in the next PR rely on. It reads the packed data dictionary already in src/ via getAllStandardTagEntries() and fails loudly on anything it can't classify.
  • schemaRules.mjs — the rule tables: parseVm() for VM patterns like 1-n and 3-3n, the VR-to-JS-type maps (VR_SCALAR, MULTI_VR), the Part 5 value-format constraints (VR_FORMATS), and the excluded structural tags (EXCLUDED_TAGS).
  • generate-schema.mjs — the CLI shell that owns the filesystem writes. It emits three artifacts: the rules catalog (src/schema/naturalizedRules.js), a JSON Schema (schema/naturalized.schema.json), and TypeScript typings (types/dcmjs-schema.d.ts).

Here's the shape of it — the builder returns the whole catalog as one object, and the CLI just serializes it three ways:

import { buildCatalog, typesSource, jsonSchemaSource } from "./buildCatalog.mjs";

const catalog = buildCatalog();
// catalog.attributes["00100010"] -> { keyword: "PatientName", vr: "PN", vm: "1" }
// catalog.dictionaryHash         -> short sha256 of the sorted attribute table

writeFileSync("types/dcmjs-schema.d.ts", typesSource(catalog));
writeFileSync("schema/naturalized.schema.json", jsonSchemaSource(catalog));

Two things worth flagging. First, this PR does not commit the generated artifacts — I verified the generator's output is byte-identical to the artifacts on the rewrite branch, and those committed artifacts arrive in the next PR together with a CI check that regeneration reproduces them exactly. Second, getting jest to transform files under packages/ needed a root babel.config.js with babelrcRoots, so that's included; each package keeps its own presets in its .babelrc.

The rule tables are covered by a new suite, test/schema/schemaRules.test.js, which pins the VM parsing and the VR maps. The IOD catalog half of the schema work is deferred — it'll land with the validation package that consumes it.

🤖 Generated with Claude Code

@awatson1978
awatson1978 merged commit 1c1ee9f into release/1.0-beta-schemas Sep 29, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant