Repository navigation
feat(fhir): port the ImagingStudy mapper and toFhir/toBundle surface (findings 17, 18) - #579
Merged
Merged
Conversation
…2.0-development imagingStudy.js comes over verbatim. The index keeps toFhir/toBundle unchanged but swaps the documentReference import for a null-returning placeholder until the DocumentReference mapper lands in the next slice (v2's index has no fromFhir re-export; the event-stream integration is a deferred slice of its own). The ported toFhir suite reads the sample-dicom.dcm fixture from packages/fixtures/dicom and naturalizes it through @dcmjs-org/parser instead of the umbrella, and the two umbrella-namespace tests are deferred with the facade slice. Co-Authored-By: Claude Fable 5 <[email protected]>
…riesInstanceUID Review findings 17 and 18 on PR #512. A missing (0008,0016) used to fabricate the CT Image Storage UID, asserting an unknown instance was a CT image; a missing (0020,000E) produced series.uid: null — invalid against R4B's 1..1 cardinality — and merged every such dataset under one "unknown" key. Both inputs are now skipped with a validationLog warning rather than emitted invalid, since instance.sopClass and series.uid are required elements a server would reject anyway. Co-Authored-By: Claude Fable 5 <[email protected]>
This was referenced Oct 2, 2026
Merged
wayfarer3130
added a commit
that referenced
this pull request
Oct 23, 2026
* feat(pdfs): scaffold the @dcmjs-org/pdfs workspace package The package manifest (publishable under the @dcmjs-org scope, main at src/index.js, repository directory set), a short README, and the lockfile entry linking the one dependency, @dcmjs-org/core. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(pdfs): port the encapsulated PDF builder and extractor from v2 A verbatim port of src/encapsulated/encapsulatedPdf.js from the v2 branch HEAD (including the { InlineBinary } unwrap that postdates the PR #512 review), with its core import rebased onto @dcmjs-org/core and the PDF half of the encapsulated index as the package surface. The video half stays on the v2 branch for the media wave. The eight-test v2 suite comes along, reworked for this branch's engine: the legacy datasetToBuffer / DicomMessage.readFile round-trip becomes denaturalize -> fromDataSet -> Part10Writer -> fromPart10 -> NaturalizedListener, and the last test's read of test/sample-dicom.dcm (provenance still being traced) is replaced by a synthetic MR instance round-tripped through the same pipeline, so neither the package nor its suite touches @dcmjs-org/legacy or the fixture. Co-Authored-By: Claude Fable 5 <[email protected]> * fix(pdfs): slice extraction to EncapsulatedDocumentLength (review finding 16) The pad-trim heuristic strips a real zero byte: the Part 10 writer pads only an odd-length OB value, so a stored even length is ambiguous — the old code trimmed a trailing 0x00 anyway, corrupting an even-length original that genuinely ends in a zero byte (a 10-byte payload ending 0x00 came back as 9 bytes). encapsulatePdf now records EncapsulatedDocumentLength (0042,0015) with the exact original length, and extractEncapsulatedPdf slices to the declared length when present, keeping the trailing-NUL heuristic only as the fallback for files written before the element existed. The four new tests were written first and observed failing against the ported-unfixed code: the even-length zero-tail round-trip (9 bytes back, red), the recorded length element, and the declared-length odd slice; the heuristic-fallback test passed before and after, pinning that files without 0042,0015 still extract exactly. Co-Authored-By: Claude Fable 5 <[email protected]> * chore: scaffold the @dcmjs-org/dicomdir package package.json modeled on @dcmjs-org/core's (version 0.0.0, publishable, MIT, main ./src/index.js, repository directory), depending on @dcmjs-org/core at runtime and on @dcmjs-org/legacy only as a devDependency for test readback. Plus a short README with a usage sample. Co-Authored-By: Claude Fable 5 <[email protected]> * feat: port the DICOMDIR builder from v2.0-development (verbatim) src/media/dicomdir.js, src/media/directoryOffsets.js, and src/media/index.js from the v2.0-development branch land as packages/dicomdir/src/{dicomdir,directoryOffsets,index}.js, and test/dicomdir.test.js as packages/dicomdir/test/dicomdir.test.js — byte-for-byte v2 content. Imports still point at the v2 tree; the next commit rewires them onto @dcmjs-org/core and replaces the DicomDict dependency. Co-Authored-By: Claude Fable 5 <[email protected]> * chore(fhir): scaffold the @dcmjs-org/fhir workspace package Co-Authored-By: Claude Fable 5 <[email protected]> * feat(fhir): port the Patient mappers and shared helpers from v2.0-development helpers.js, patient.js and patientToDataset.js come over verbatim from the v2 packages/fhir sources (prettier-normalized to this repo's config). The test imports are rewired to the concrete modules because the package index lands in a later slice. Co-Authored-By: Claude Fable 5 <[email protected]> * fix(fhir): fall back to HumanName.text when no structured name parts exist A text-only HumanName used to map to null, and patientToDataset's deterministic overwrite then erased the patient's name entirely (review finding 19 on PR #512). When family/given/prefix/suffix are all absent, the free-text form now survives as a single-component PN. Co-Authored-By: Claude Fable 5 <[email protected]> * refactor: rewire the DICOMDIR builder onto @dcmjs-org/core The two legacy imports the v2 code carried are gone, keeping the hard rule that this package never depends on @dcmjs-org/legacy: - directoryOffsets.js measured element sizes through DicomMessage.write and DicomMessage.writeTagObject; it now calls core's writeDataSet and writeTagObject directly — the exact functions those statics are one-line delegates to, so measured sizes are unchanged. - dicomdir.js built a DicomDict and called dicomDict.write(); the Part 10 envelope (preamble + DICM, meta group behind its group length, then the body) is now inlined as writePart10 on the same core primitives, minus the deflate branch a DICOMDIR can never take. Verified byte-identical against legacy DicomDict.write on the same denaturalized { meta, dict }. The test readback oracle rewires from the root dcmjs facade to DicomMessage from @dcmjs-org/legacy (devDependency) plus DicomMetaDictionary and validationLog from @dcmjs-org/core, and the local EXPLICIT_LITTLE_ENDIAN constant gives way to core's export. Full suite: 860 passed, 12 skipped, 872 total. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(video): scaffold the @dcmjs-org/video package The package shell for the video wave: name, entry point, MIT license, repository directory, and the @dcmjs-org/core workspace dependency. The image-module index exports only the header parsers for now; the dataset builder joins it in the next slice. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(video): port the JPEG and MP4 header parsers from v2 Verbatim from v2.0-development: src/image/jpegInfo.js (SOF geometry and the JPEG transfer syntax mapping), src/image/mp4Info.js (the ISO BMFF box walk over a random-access reader), the makeTinyMp4 synthesized-fixture helper, and the ported mp4Info suite. Only the test import paths moved with the files; no behavior changed in this commit — review findings 9 and 15 are fixed on top, each with its regression observed red first. Co-Authored-By: Claude Fable 5 <[email protected]> * fix(video): throw on a truncated SOF segment in parseJpegInfo Review finding 9 (HIGH): the marker-walk guard only required four readable bytes, but the SOF fields span bytes[offset+4 .. offset+9]. Out-of-range reads coerce to 0 in the bitwise math, so the review map's vector — a 480x640 JPEG cut one byte into the width field — returned columns 512 instead of throwing, and a file cut right after the length field returned rows 0, columns 0. The reader now validates that the declared SOF segment fits inside the input (and is at least 8 bytes) before reading any field. The new jpegInfo suite is hand-written (v2 carried no suite for this file): the exact review vector, the cut-after-length shape, and valid SOF0/SOF1/SOF2/SOF3 paths. Both finding tests were observed red against the ported-unfixed reader before this fix. Co-Authored-By: Claude Fable 5 <[email protected]> * fix(video): bound the stts entry count by its box size in parseMp4Info Review finding 15 (MED): the stts fallback loop trusted the raw uint32 entry_count. With stsz sample_count 0 and stts entry_count 0x00FFFFFF the parser spun 16.7 million iterations over zero-coerced reads past the box and fabricated numberOfFrames/frameRate from unrelated moov bytes; at 0xFFFFFFFF that is roughly 40 seconds of blocked thread. The loop now requires 16 + entryCount * 8 to fit inside the stts box and throws on the mismatch. The regression corrupts a synthesized MP4 exactly that way and asserts the parse rejects in under two seconds — observed red (the unfixed parser resolved with fabricated values) before this fix. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(video): port buildImageDataset from v2 Verbatim from v2.0-development src/image/buildImageDataset.js and its 21-test suite, with two mechanical adjustments for the package boundary: DicomMetaDictionary and validationLog now come from @dcmjs-org/core, and the test imports the builder from the package's image index (which now exports it alongside the header parsers). No behavior changed in this commit — review finding 10 is fixed on top with its regressions observed red first. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(fhir): port the ImagingStudy mapper and the package index from v2.0-development imagingStudy.js comes over verbatim. The index keeps toFhir/toBundle unchanged but swaps the documentReference import for a null-returning placeholder until the DocumentReference mapper lands in the next slice (v2's index has no fromFhir re-export; the event-stream integration is a deferred slice of its own). The ported toFhir suite reads the sample-dicom.dcm fixture from packages/fixtures/dicom and naturalizes it through @dcmjs-org/parser instead of the umbrella, and the two umbrella-namespace tests are deferred with the facade slice. Co-Authored-By: Claude Fable 5 <[email protected]> * fix(fhir): skip instances without SOPClassUID and datasets without SeriesInstanceUID Review findings 17 and 18 on PR #512. A missing (0008,0016) used to fabricate the CT Image Storage UID, asserting an unknown instance was a CT image; a missing (0020,000E) produced series.uid: null — invalid against R4B's 1..1 cardinality — and merged every such dataset under one "unknown" key. Both inputs are now skipped with a validationLog warning rather than emitted invalid, since instance.sopClass and series.uid are required elements a server would reject anyway. Co-Authored-By: Claude Fable 5 <[email protected]> * fix(video): derive NumberOfFrames from the encapsulated fragment list Review finding 10 (HIGH): numberOfFrames came only from decodedImage.numberOfFrames || 1 and was never derived from or checked against options.encapsulated.frames.length, and the attribute was only written when above 1. Three encapsulated fragments therefore produced an instance with no NumberOfFrames — a conformant reader showed frame 1 and the rest were unreachable — while an explicit numberOfFrames 7 over 2 fragments emitted the bogus claim unchecked. In encapsulated mode the fragment list is now the ground truth: the count defaults to frames.length and an explicit mismatch throws. Both regressions were observed red against the ported-unfixed builder before this fix; two companion tests pin that a matching explicit count is accepted and that a single fragment still omits the attribute. Co-Authored-By: Claude Fable 5 <[email protected]> * fix: let core's sequence writer run with no eager engine loaded Writing a DICOMDIR from @dcmjs-org/dicomdir alone threw: core's SequenceOfItems.writeBytes serialized each item through the late-bound DicomMessage, which only @dcmjs-org/legacy (or the dcmjs wrapper) registers — so the package's hard no-legacy rule held in its imports but not at runtime. The committed suite never saw it because its readback oracle imports legacy, wiring the seam as a side effect. core/writeCore.js now registers writeDataSet into ValueRepresentation at load (a direct import between the two files is a module-level CJS cycle that breaks Tag's registration, hence the seam), and the sequence writer calls that instead of DicomMessage.write — the exact function DicomMessage.write delegates to, so bytes are unchanged either way. The new packages/dicomdir/test/standalone.test.js imports nothing from legacy (jest's per-file module registry guarantees the seam stays unwired) and proves a full DICOMDIR write: DICM magic, four undefined-length item headers for PATIENT/STUDY/SERIES/IMAGE, deterministic bytes. Full suite: 861 passed, 12 skipped, 873 total. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(video): port the buffered video encapsulation layer from v2 Verbatim from v2.0-development src/encapsulated/encapsulatedVideo.js and its 8-test suite, with one mechanical adjustment for the package boundary: DicomMetaDictionary and isVideoTransferSyntax now come from @dcmjs-org/core instead of relative paths. buildVideoDataset shapes the Supplement 225 Video Photographic Image shell (XC modality, cine timing, the (7FE0,0003) uint64 total length as a BigInt), encapsulateVideo splits the MP4 into fragment-sized exact ArrayBuffer slices, and extractEncapsulatedVideo concatenates fragments and truncates to the declared length so the odd-fragment pad byte drops on extraction. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(video): export the encapsulated module from the package index The video half of v2's encapsulated index only — the PDF half (encapsulatedPdf) belongs to the media wave. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(fhir): port the DocumentReference mapper from v2.0-development documentReference.js comes over verbatim, and the package index swaps the slice-two placeholder for the real import and re-export, completing the toFhir three-key surface. The ported test builds its Encapsulated PDF datasets synthetically (v2 built them with dcmjs.encapsulated, which belongs to the pdfs wave and is not on this branch yet), keeps the Part 10 round trip through @dcmjs-org/legacy as a test-only devDependency, and naturalizes the image fixture through @dcmjs-org/parser like the toFhir suite. Co-Authored-By: Claude Fable 5 <[email protected]> * fix(fhir): unwrap InlineBinary payloads and honor EncapsulatedDocumentLength Review findings 8 and 16 on PR #512. The event-stream naturalizer wraps binary elements as { InlineBinary } (base64 string, ArrayBuffer, or view); payloadBytes never unwrapped that shape, and new Uint8Array of a plain object is empty, so every naturalized encapsulated document silently mapped to { size: 0, data: "" }. The unwrap block mirrors the one in v2's extractEncapsulatedPdf, kept as a local copy because this package must not depend on the pdfs package. The even-length pad-trim heuristic also stripped real trailing zero bytes, since an even stored length never carries a writer pad. When EncapsulatedDocumentLength (0042,0015) is present it now wins over the heuristic; the write side that emits it lands with the pdfs wave. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(video): declare the parser and generator dependencies @dcmjs-org/parser joins the dependencies — the video event source imports fromDataSet and EVENT_STREAM_VOCABULARY — and @dcmjs-org/generator the devDependencies (StreamingPart10Writer, tests only). Deliberately NOT @dcmjs-org/legacy: this package stays off the legacy surface. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(video): port the video event source from v2 createVideoEventSource — MP4 → contract events with the Supplement 225 dataset shell replayed first and the stream emitted as encapsulated PixelData fragments, one in memory at a time, backpressure between fragments via awaitDrain(). The run loop, exactFragment, withoutEndDataSet and sortDict are verbatim from v2.0-development src/eventStream/fromVideo.js. One seam is reworked and hand-written: v2 imported datasetToDict from what is now @dcmjs-org/legacy, which this package must not depend on, so a local datasetToMetaDict helper mints the same file meta group (element list and implementation UID copied from legacy's datasetToDict) and denaturalizes both halves via core's DicomMetaDictionary — returning the plain { meta, dict } shape, which is all parser's fromDataSet reads. The suite is the v2 fromVideo suite reworked off the DicomEventStream facade (media wave): the source drives StreamingPart10Writer directly and reads back through fromPart10/fromPart10Stream + NaturalizedListener + extractEncapsulatedVideo. All load-bearing assertions carried over: byte-identical round trips (buffered and streaming reader), the (7FE0,0003) UV uint64 pinned on the wire, the Sup 225 fragment layout, single-endDataSet ordering, per-fragment backpressure, and the ffmpeg corrective error. The facade-specific toVideo/fromPdf case stays with the media wave, as does fromImage.test.js. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(video): export createVideoEventSource from the package index Co-Authored-By: Claude Fable 5 <[email protected]> * feat(media): the @dcmjs-org/media bundle package Co-Authored-By: Claude Fable 5 <[email protected]> * feat(media): the DicomEventStream media factories (review finding 14) Port fromImage, fromPdf, fromVideo, fromVideoStream, toPdf, and toVideo from v2's src/eventStream/api.js, importing from @dcmjs-org/pdfs and @dcmjs-org/video. The video factories create their event source lazily on first consumption (cached across re-runs) instead of eagerly at factory time, so a bad input can no longer raise an unhandled promise rejection before anyone calls .process() — review finding 14. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(fhir): port the fromFhir event source from v2.0-development FHIR resources as an event-stream SOURCE, for the resources that carry content rather than context: a DocumentReference with an inline PDF becomes an Encapsulated PDF instance, and a Media with an inline JPEG (the key-image case) becomes an image instance with the JPEG bytes carried verbatim as encapsulated PixelData. Bundles are unwrapped (one content resource + an optional Patient for demographics), and context-only resources are rejected with corrective errors. The module stays at root src/eventStream/ — the same wrapper-level home as api.js — because it composes five packages (pdfs, video, fhir, parser, core) and belongs inside none of them; it moves into the step-7 wrapper package with the facade. Imports are rewired to the scoped packages, and the legacy datasetToDict call is replaced with a local copy of the video wave's datasetToMetaDict (not exported from @dcmjs-org/video), producing the plain { meta, dict } shape fromDataSet consumes. @dcmjs-org/core, fhir, and parser join the root workspace dependencies. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(fhir): add fromFhir and toFhir to the DicomEventStream facade fromFhir follows the media factories' lazy-source pattern (finding 14): the v2 original built the dataset eagerly at factory time, so garbage input threw from the factory before anyone called .process(). Here the dataset is built on first consumption and cached — the corrective error surfaces from the sink, and minted UIDs stay stable across re-runs. The regression test was red against the verbatim v2 port (5 failures: the finding-14 test plus the four corrective-error tests, all throwing at factory time) and is green with the lazy form. toFhir maps one instance to { patient, imagingStudy, documentReference } via @dcmjs-org/fhir over the naturalized dataset, ported verbatim from v2's api.js. The test suite is the v2 fhirPdfEventStream suite with import and fixture-path rework, minus the parseJpegInfo block (now owned by packages/video/test/jpegInfo.test.js, a superset), plus the facade form of the deferred 'dcmjs.fhir umbrella namespace' bytes-to-FHIR test: DicomEventStream.fromPart10(bytes).toFhir() over the committed sample-dicom.dcm fixture. The namespace tests themselves still wait for the step-7 wrapper package; the deferral comments in packages/fhir/test/toFhir.test.js now say exactly that. Co-Authored-By: Claude Fable 5 <[email protected]> * chore(audit): ignore GHSA-vfj7-8cjw-p6xm (braces) — no patched release exists The advisory (braces <=3.0.3, high, stack exhaustion) was published mid-flight on this PR: the identical lockfile passed audit on the staging branch twenty minutes before the PR run failed. Its stated patched range is >=3.0.4, but the registry has no such release (latest braces is 3.0.3, from 2024), so an override pin cannot resolve — verified: ERR_PNPM_NO_MATCHING_VERSION. Every path to braces is dev tooling (cpy-cli, lint-staged, jest); it never reaches the published package. The ignore is scoped to this one GHSA and commented for removal the moment a patched braces ships. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(dcmjs): the @dcmjs-org/dcmjs wrapper — the 0.52 surface plus the new engines The step-7 wrapper from the release plan. The root package renames from "dcmjs" to "@dcmjs-org/dcmjs" and drops "private": true in the same commit, as section 9 of RELEASE_PLAN.md specifies — the flag existed only to keep the unscoped name from publishing by accident before the wrapper existed. The unscoped dcmjs npm name stays untouched until GA. src/index.js keeps the entire 0.52 surface (the shims and the full suite prove it) and gains the new namespaces additively, following the v2 naming precedent but importing from the workspace packages: media, encapsulated (including DEFAULT_FRAGMENT_BYTES), and image come from @dcmjs-org/media; fhir spreads @dcmjs-org/fhir plus the fromPart10 convenience; eventStream was already here. The root package.json gains the workspace deps it now wraps (dicomdir, media, generator). The umbrella-namespace tests deferred by PR #579 return in packages/fhir/test/toFhir.test.js, red-green against the real wiring. test/bundle-size.test.js is the plan's bundle-size check against 0.52, with the honest numbers: the bundles are 27-30% over the 0.52 baseline because the new engines are in them; the 1.05 aspiration is logged as informational and a documented provisional ceiling of 1.35 is enforced, with the final threshold flagged as a maintainer decision. The same suite requires the built UMD bundle and touches every new namespace to prove rollup inlines the @dcmjs-org/* workspace packages. Co-Authored-By: Claude Fable 5 <[email protected]> * docs: retire the writing style guide now that authoring is done Per review on #542: the guide existed to hold the staged-landing PR descriptions to one standard, and every description is now written. Removed rather than kept stale; git history preserves it if the team wants it back later. The PR template keeps the one-line spirit of it. Co-Authored-By: Claude Fable 5 <[email protected]> (cherry picked from commit 2a5935e) * chore: update pnpm to 12.9.1 Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat: @dcmjs-org/dcmjs — the 0.52 default export and the subpath entries The default export of @dcmjs-org/dcmjs now has exactly the dcmjs 0.52 names. The new engines move to subpath entries, so the default bundles stay within x1.05 of 0.52: - @dcmjs-org/dcmjs/eventStream (moved from the default export) - @dcmjs-org/dcmjs/media, /encapsulated, /image (the v2 namespaces) - @dcmjs-org/dcmjs/fhir (the FHIR sink plus fromPart10) Build: one ESM build with six entries keeps the @dcmjs-org/* imports external (they stay in dependencies); the shared code goes in one dcmjs.shared-<hash>.js chunk, so each entry exports only its public names. The UMD builds inline everything and have the default entry only. Tests: the bundle-size suite builds only the bundles it measures, rebuilds a stale build/, spawns rollup through node (works on Windows), measures an entry with its chunks, and checks the export names. A new 0.52-compatibility test pins the 0.52 export names. Release tooling: the trusted-publishing bootstrap also prepares the root package; the publish workflow builds before it tests. RELEASE_PLAN.md gets the wrapper requirements (WRAP-USR-n, WRAP-IMP-n), the size policy and the measurements. The pnpm-workspace.yaml comments name pnpm 12. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat: one naturalized form for private blocks and binary values Both naturalizers (DicomMetaDictionary.naturalizeDataset and NaturalizedListener) now give the same object, and the spec in docs/specs/naturalized-dataset.md defines it. - A private creator (gggg,00xx) and its reserved block naturalize to one `${gggg}:${creator}` key: { creator, reservedBlock, xEE... }, with the VRs in _vrMap[blockKey][xEE]. The hex tags, registerTag() keywords and private dictionary keywords stay as non-enumerable aliases. - denaturalizeDataset accepts the block form and the hex-tag form. A block keeps its reservedBlock when it is free, and moves to the first free xx when it is not. - fromNaturalized / DicomEventStream.fromNaturalized() streams a naturalized dataset to any sink, for example Part10Writer. - NaturalizedListener outputs _vrMap, and gives binary values as a list of ArrayBuffer in place of { InlineBinary }. - Both naturalizers take { binaryAs: "Uint8Array" } for no-copy views. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: decode a private creator that was read as UN bytes An implicit-VR file, or a gateway that converts unknown VRs, can give a private creator as UN bytes. The block key was then "7FDD:[object ArrayBuffer]". The creator bytes now decode as LO text without the trailing padding (NAT-I-PLACE-3). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: the review findings on the private blocks - A delete of a hex alias (or a registerTag() keyword alias) removes the element from the denaturalized output again, and a delete of a creator alias removes the block. De-identification code that deletes private tags by hex key keeps working (NAT-U-HIST-7). - An alias reads the block through its key, also after the user replaces the block (NAT-U-HIST-8). - A creator for two blocks of one group gives a warning (NAT-U-PRIV-9). - A creator from DICOM JSON InlineBinary decodes like a UN creator, and a creator decodes with the chunked latin1 decoder, from at most 64 bytes. Creator padding is removed for every source (NAT-U-PRIV-10). - A flat element in the range of a block joins the block, and a flat registerTag() keyword holds its block number (NAT-U-RT-1, NAT-I-RT-1). - isPrivateTag uses the Tag methods; one recordVr and one registeredTagEntry helper serve both naturalizers. - Outdated comments about { InlineBinary } and the draft section 18. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: the published subpaths, and one copy of core in the ESM bundle - The packages published as source (dicomdir, encapsulated, fhir, imaging, media, video) get a files list. Without it, pnpm applied the root .npmignore, which excludes src/, and every subpath failed after an install (WRAP-IMP-6). - The src/ shims import @dcmjs-org/core and @dcmjs-org/parser in place of files in packages/<name>/src. The ESM shared chunk held a second copy of core: the consumer bundle was x1.49 of 0.52, and it is now x1.027 (WRAP-IMP-2). - The size check bundles build/dcmjs.es.js with its packages, as an application bundler does (WRAP-USR-2, WRAP-IMP-5). - core and parser get an exports map with a "source" condition, so Node runs the ESM entries in a built checkout (EXAMPLES.md, pnpm bench), and core lists its side-effect modules (WRAP-IMP-7). - The subpaths are import-only, so require() cannot load a second copy (WRAP-USR-3). - The UMD output has a fixed indent, and pnpm run build deletes build/. - bench/worker.mjs imports the eventStream subpath. - test/package-layout.test.js checks the files lists, the import-only subpaths, the sideEffects list and the source maps of build/. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: the third review round on the wrapper wave Private blocks: - fromNaturalized denaturalizes the dataset itself, not a rest-spread copy, so a delete of a private alias also reaches Part10Writer and the other sinks (NAT-U-HIST-7). - A deleted alias stays deleted: definePrivateAliases does not define it again, and a plain value set on the deleted name is a new flat element that replaces the deleted one in its block. - A write to an element alias after the block is deleted makes a flat element. - A creator that is not text or bytes ({ BulkDataURI }, an object) is no creator; a SharedArrayBuffer creator decodes as bytes. - A binary-VR element with non-buffer values (UN with a string Value) is a list in both naturalizers, and hex keys are uppercase in both. - naturalBinaryFragment copies a SharedArrayBuffer to an ArrayBuffer in the default mode. Wrapper: - core reads process.env.LOG_LEVEL only when process exists. The ESM entry now imports core's dist/, where nothing replaced the expression, so a browser bundle threw "process is not defined" (WRAP-USR-6). The bundle-size suite runs the consumer bundle in a vm with no process. - The ESM build removes the shared chunks of earlier builds. - RELEASE_PLAN: WRAP-USR-3 records the CommonJS and jest limits and the two-copy case of require() plus import; the four test-only shims, the source-based size check and the jest resolution are stated exactly. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: the fourth review round on the wrapper wave - A binary element with no value is null in both naturalizers (it was [] from NaturalizedListener after 86f998c), and NAT-U-BIN-1 records the binary list rule as a user requirement, without the conflict with NAT-U-VAL-4. - An alias delete removes the element while the block still holds the value that the alias last saw. The source value never survives a delete, also in a copied block object, and a different value written into the block after the delete is kept (it was lost). - A write to an element alias after the block key is deleted makes a flat element with the VR of the block element (it was skipped with no VR). - A number in a creator slot is no creator. - core reads process.env.LOG_LEVEL in a try block, so the UMD build applies the build-time level in a browser again. - One isBinaryData helper in core replaces four local byte checks. - The doc comment of creatorText, and the WRAP-USR-6 test reference (moved to WRAP-IMP-8). Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat: one value rule for unknown VMs, PN setters and the upsert utilities Naturalized values: - An attribute with no dictionary VM (a private or unknown element) is a list, also for one value, as for VM > 1 (NAT-U-VAL-4). A private or unknown sequence with one item is the array-like item object, as for a standard sequence (NAT-U-SQ-1). - A PN attribute of a dataset or item has a converting setter: an assigned PN string, object or list is stored in the component form, one object for VM 1 and a list otherwise (NAT-U-VAL-5). - A binary value whose fragments all have zero bytes (a Part 10 reader gives one empty fragment for an empty element) is null (NAT-U-BIN-1). Utilities in @dcmjs-org/core (NAT-U-UPS): - upsertAttribute(dataset, key, value, { vr, length }), upsertPersonName(dataset, key, value, length), and setVr(dataset, key, vr[, elementKey]), which creates _vrMap when it is missing. A private alias key stores into its block. Private aliases: - A delete of an alias always wins at the write, with no value check (the review's value-tracking rule had a new edge case in each round). - A write to an element alias after its creator alias is deleted makes a flat element, as after a delete of the block key. - A flat element that joins a block takes the VR of the block element when _vrMap has none for it. Also: DicomWebJsonWriter accepts a SharedArrayBuffer fragment, and the log.js comment no longer holds the text that the replace plugin rewrites. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat: the naturalized-dataset utilities on dcmjs.data, size ceiling x1.06 dcmjs.data now also gives setVr, upsertAttribute, upsertPersonName and definePrivateAliases. With them the UMD bundle is x1.051 of 0.52, so the ceiling of WRAP-USR-2 rises from x1.05 to x1.06 (a maintainer decision). The ESM consumer bundle is x1.036. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat: setAttribute and setPersonName, and the sixth review round - upsertAttribute and upsertPersonName are now setAttribute and setPersonName (NAT-U-SET); setVr keeps its name. - Without a length, the set utilities take the value count from the dictionary VM (setAttribute(ds, "PatientID", "X") stores "X"), and a hex key is uppercase, or the keyword for a standard tag. A VR other than PN replaces an earlier PN setter with plain data. - A private PN element converts a later string through its alias, when _vrMap gives PN for it. - Both producers store a PN value through setPersonName, so a value is converted once. - A present element with no Value is [] for a list VM and null for a scalar VM in naturalizeDataset too, as in the listener. - NaturalizedListener looks up a tag with the dictionary proxy, so the repeating groups (60xx OverlayRows ...) and registerTag() entries get their keywords, as in naturalizeDataset. - valueLength(entry) is the one value-count rule for both producers and the set utilities; a registerTag() entry with no VM is a list. - The isMultiVM and privateBlocks doc comments, a nested PN list, and the tests of the round-5 items that had none. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: the final review findings on the wrapper wave Should fix: - An invalid LOG_LEVEL (another library's level, such as "verbose" or "fatal") no longer stops the import: core uses the variable only when loglevel knows the level, else "warn". The proper fix is proposed upstream in pimterry/loglevel#210 (log.parseLevel and a tolerant setDefaultLevel). - setAttribute stores a sequence by NAT-U-SQ: [] with no item, the array-like item object for one item. - A hex key of a flat registerTag() private element sets its keyword, so the value is no longer lost on write. - A private PN element with no creator gets the converting setter. - The source-map guard in test/package-layout.test.js builds build/ when it is absent or stale, so it runs in PR CI. The build helper is shared with test/bundle-size.test.js and takes a lock for parallel workers. Reuse: naturalValues.js holds the sequence, binary and simple value rules for both producers and setAttribute; isHexTag is the one hex-key test. Nits: setVr ignores a creator alias, setAttribute on a creator alias throws a clear TypeError, the PN setter rules are in NAT-U-VAL-5, MIGRATION (PN, the wrapper, ESM-only subpaths, LOG_LEVEL) and RELEASE_PLAN (legacy and generator inlined, LOG_LEVEL, the size table, test references out of the user requirements) are current, the README gives the @beta install, and stale test names and comments are fixed. Tests: LOG_LEVEL values, the sequence, registerTag and flat PN cases, naturalizeDataset(readFile) in the cross-source matrix, and a private round trip on a real fixture. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: the round-8 review findings, and an empty DS value Should fix: - After a delete of a private hex alias, setAttribute on that hex name makes a new flat element, also when a registerTag() keyword names the same block element (the ceaf1b3 key mapping lost the value). - setAttribute treats the dictionary code "ox" (PixelData) as binary: a list of ArrayBuffer, and no "ox" in _vrMap. A binary value set through setAttribute is a list of ArrayBuffer, or Uint8Array with binaryAs. - The jest advice is a moduleNameMapper to build/<name>.es.js; jest resolves with the CommonJS conditions, so a transform alone does not find the import-only subpaths (WRAP-USR-3, MIGRATION, README). Also: - denaturalizeDataset keeps a null value entry, as a reader gives for an empty DS of VM 1-n (Value: [null]); it threw before (sample-op.dcm). - LOG_LEVEL accepts 0 to 5 as a string; WRAP-USR-7 records the run-time read of the ESM entries. - setPersonName on a creator alias throws the clear TypeError. - The listener converts binary fragments in one binaryValue call. - The PN delimiter text, MIGRATION intro, spec line wrap, a misleading comment, the source-map regex, and the real-file test parse once. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: the round-9 review findings - A null entry of a text VR (LO, LT, SH, ST, UC, UT) denaturalizes to an empty value. Since 7b8c26e accepted null entries, the writers wrote it as the text "null" (NAT-U-RT-7, recorded in MIGRATION). - The jest config maps the default entry to build/dcmjs.es.js too, so the default entry and the subpaths share one reader state in jest (WRAP-USR-3, MIGRATION, README). - setAttribute checks binaryAs (NAT-I-BIN-2), and isVrCode is the one VR-code test. - MIGRATION gives the 0 to 5 LOG_LEVEL values; the null-entry comment sits at the code it describes. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: null entries in the writer layer, for every write path - BufferStream.writeUTF8String writes null as empty text, as writeAsciiString does, so LO, SH, ST, LT, UC and UT no longer write the text "null" on any write path (DICOM JSON dicts and fromDicomWebJson included). The TEXT_VRS step in denaturalizeDataset is gone. - PN: a null name is an empty name that keeps its position (pnObjectToString, toPersonNameValue): [null, "C^D"] writes "\C^D". - A binary number VR (US, SS, UL, SL, FL, FD, UV, SV) writes null as 0 with a warning, because it has no empty value. - NAT-U-RT-7 and MIGRATION state these rules; NAT-I-NULL-1 places them. - isVrCode is no longer a public @dcmjs-org/core export; the jest docs name the babel.config.js that the ESM build files need; the size table is current. - test/core/nullEntries.test.js writes the bytes on three paths. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: the round-11 review findings on the null warning - The warning for a null binary number is in one method, ValueRepresentation.warnNullEntries, which uses isBinary() in place of a separate VR list (so AT is covered too). - It warns only for a null entry of a list. A null value that is not a list is an element with no value, which is written with zero length; the false "written as 0" warning for it is gone. - The UV writer calls warnNullEntries before it turns null into 0n, so a UV null now warns. - NAT-U-RT-7, NAT-I-NULL-1 and MIGRATION give the right VR list (SV is not a core VR; AT is in) and the no-value rule. - Tests: an element with no value is written with zero length and no warning, on the dict and naturalized paths; a UV null warns. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat: no /fhir subpath, FHIR marked preliminary, no plan IDs in code - @dcmjs-org/dcmjs no longer has the /fhir subpath (src/fhir.js and its test file are gone). FHIR is preliminary: a user imports the separate @dcmjs-org/fhir package. It stays a runtime dependency, because the preliminary DicomEventStream.fromFhir() and toFhir() use it. README, MIGRATION and WRAP-USR-3 say so (a maintainer decision). - The code and test comments of this wave no longer point to RELEASE_PLAN requirement IDs (WRAP-*); they keep the plain explanation. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat: no FHIR methods on DicomEventStream The wrapper no longer depends on @dcmjs-org/fhir. DicomEventStream drops fromFhir() and toFhir(); toFhir(await events.toNaturalized()) of @dcmjs-org/fhir replaces events.toFhir(). The fhir README withdraws the fromFhir requirements, and the PDF facade tests move to pdfEventStream.test.js. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]> Co-authored-by: Bill Wallace <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This ports the ImagingStudy mapper and the package index — the
toFhir/toBundlesurface — and fixes review findings 17 and 18 inside the port.imagingStudy.jsrestates the DICOM study/series/instance hierarchy as a FHIR R4B ImagingStudy (grouping instances by SeriesInstanceUID, unioning modalities at study level, carrying accession and referrer through), following the IHE MADO mapping. The index wires it together with the Patient mappers from the first slice:toFhir(dataset)gives the stable three-key shape,toBundle(datasets)gives one Patient plus one aggregated ImagingStudy as a collection Bundle.Two deliberate departures from a verbatim port, both scoped to the slicing. The index's
documentReferenceFromDatasetimport points at a file that arrives in slice three, so until then it is a null-returning placeholder with a comment —toFhir/toBundlethemselves are untouched, and the slice-three diff will be just the import swap plus the re-export. (v2's index has nofromFhirre-export to strip; the event-stream source and thedcmjs.fhirfacade are a deferred slice that waits on the pdfs/video/media waves.) And the portedtoFhirtest drops the v2 suite's two "umbrella namespace" tests (dcmjs.fhir.fromPart10), which exercise exactly that deferred facade.On fixtures and parsing: the v2 test read
test/sample-dicom.dcmthrough the dcmjs umbrella'sDicomMessage.readFile. Here it readspackages/fixtures/dicom/sample-dicom.dcm— same bytes, though that fixture's upstream provenance is still being traced — and naturalizes through@dcmjs-org/parser'sfromPart10+NaturalizedListener, so the package tests stay off the legacy engine entirely. That adds@dcmjs-org/parseras a workspace devDependency; the fix below adds@dcmjs-org/coreas the package's one runtime dependency (forvalidationLog).The findings, each with its regression written against the ported-but-unfixed code and observed failing before the fix:
uidToUrn(dataset.SOPClassUID) || "urn:oid:1.2.840.10008.5.1.4.1.1.2"asserted that an unknown instance was a CT image. A DICOMweb metadata response that omits (0008,0016) reaches this path. The fallback is gone; the instance is skipped with avalidationLogwarning. I chose skip over emit-invalid becauseinstance.sopClassis 1..1 in R4B — an instance without it fails validation on any FHIR server, so emitting it just moves the failure somewhere less observable. Flagging the choice for reviewers.series.uid: null— also invalid against R4B's 1..1 — and the grouping keyed every such dataset on the literal"unknown", so two genuinely different series merged into one entry. Consistent with 17, those datasets are now skipped with a warning; the regression pins that two uid-less datasets no longer merge and no null uid survives.The surface in use:
Twelve tests in the ported suite (ten v2 tests — the helpers, the MR fixture ground truth, subject passthrough, aggregation, bundling, strict fhirVersion, graceful degradation — plus the two finding regressions), 38 in the package, 882 passing overall on this branch, and
pnpm run buildis green.🤖 Generated with Claude Code