Repository navigation
feat(fhir): the FHIR event source and facade integration - #589
Merged
Merged
Conversation
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]>
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]>
…e 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]>
This was referenced Oct 3, 2026
awatson1978
added a commit
that referenced
this pull request
Oct 3, 2026
…ented GHSA-vfj7-8cjw-p6xm was published 2026-10-02 with a claimed fix range of >=3.0.4, but no such braces release exists on the registry, so there is nothing to override to. Every path is dev tooling; braces never reaches the published packages. Same entry the fhir staging branch already carries (#589) — remove it the moment a patched braces ships. Co-Authored-By: Claude Fable 5 <[email protected]> (cherry picked from commit 7261970)
awatson1978
added a commit
that referenced
this pull request
Oct 3, 2026
…ented GHSA-vfj7-8cjw-p6xm was published 2026-10-02 with a claimed fix range of >=3.0.4, but no such braces release exists on the registry, so there is nothing to override to. Every path is dev tooling; braces never reaches the published packages. Same entry the fhir staging branch already carries (#589) — remove it the moment a patched braces ships. Co-Authored-By: Claude Fable 5 <[email protected]> (cherry picked from commit 7261970)
awatson1978
added a commit
that referenced
this pull request
Oct 3, 2026
…ented GHSA-vfj7-8cjw-p6xm was published 2026-10-02 with a claimed fix range of >=3.0.4, but no such braces release exists on the registry, so there is nothing to override to. Every path is dev tooling; braces never reaches the published packages. Same entry the fhir staging branch already carries (#589) — remove it the moment a patched braces ships. Co-Authored-By: Claude Fable 5 <[email protected]> (cherry picked from commit 7261970)
awatson1978
added a commit
that referenced
this pull request
Oct 3, 2026
…ented GHSA-vfj7-8cjw-p6xm was published 2026-10-02 with a claimed fix range of >=3.0.4, but no such braces release exists on the registry, so there is nothing to override to. Every path is dev tooling; braces never reaches the published packages. Same entry the fhir staging branch already carries (#589) — remove it the moment a patched braces ships. Co-Authored-By: Claude Fable 5 <[email protected]> (cherry picked from commit 7261970)
wayfarer3130
pushed a commit
that referenced
this pull request
Oct 19, 2026
* 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]> * 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]> * 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]> * ci: ignore the unpatchable braces advisory in audit, scoped and documented GHSA-vfj7-8cjw-p6xm was published 2026-10-02 with a claimed fix range of >=3.0.4, but no such braces release exists on the registry, so there is nothing to override to. Every path is dev tooling; braces never reaches the published packages. Same entry the fhir staging branch already carries (#589) — remove it the moment a patched braces ships. Co-Authored-By: Claude Fable 5 <[email protected]> (cherry picked from commit 7261970) * 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) * test(dicomdir): add opt-in large-media round-trip; clarify multi-study support Addresses review on PR #575: - README: add a two-patient/two-study example and state that grouping by patient/study/series is automatic. The single-entry example read as single-series only. - standalone.test.js: reword the header so the no-legacy framing belongs to the test (which pins it), not to the package (whose purpose is building and writing DICOMDIRs). - Add mediaRoundTrip.long.test.js, gated on DCMJS_LONG_TESTS: stream a multi-GiB video to disk, index it in a DICOMDIR, then read the media back via fromPart10Stream with a zero-retention listener. Verified at 3 GiB under a 512 MB heap cap. Pulls in @dcmjs-org/parser as a devDependency. - README: link #611 for the follow-up read/index/QIDO API. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
wayfarer3130
added a commit
that referenced
this pull request
Oct 20, 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]> * ci: ignore the unpatchable braces advisory in audit, scoped and documented GHSA-vfj7-8cjw-p6xm was published 2026-10-02 with a claimed fix range of >=3.0.4, but no such braces release exists on the registry, so there is nothing to override to. Every path is dev tooling; braces never reaches the published packages. Same entry the fhir staging branch already carries (#589) — remove it the moment a patched braces ships. Co-Authored-By: Claude Fable 5 <[email protected]> (cherry picked from commit 7261970) * 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) * refactor(encapsulated): rename @dcmjs-org/pdfs -> @dcmjs-org/encapsulated; add sourceInstance compose path Addresses review on PR #577: - Rename the package to @dcmjs-org/encapsulated: it is the home for DICOM's encapsulated-document IODs, with PDF the first to land (CDA/STL/OBJ/MTL to follow). Video stays in @dcmjs-org/video — it is encapsulated pixel data, not a document. Updates package name/description, headers, README, and the RELEASE_PLAN table. - Add an additive options.sourceInstance path to encapsulatePdf: copy the Patient and General Study context off a naturalized instance (or the first of an array) instead of retyping it. Precedence is defaults < sourceInstance < explicit options; the document's own identity (SOP class, Modality, SOP/Series UIDs) is never inherited, so the report lands as a new series within the source study. De-novo stays the default. - 7 new tests cover the compose path (19 in the package suite). The generic module-extraction helper this hand-rolls belongs near core and is tracked separately in #612. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(encapsulated): generic encapsulate() decorator + core hierarchy helpers Addresses the PR #577 review / follow-up conversation with Bill, and closes #612. Core (@dcmjs-org/core): - Add utilities/copyAttributesByLevel.js: patientTags / studyTags / seriesTags / patientStudyTags as Sets (names + coverage mirror cornerstone3D's copyStudyTags.ts for portability), plus copyAttributesByLevel(source, dataLevel) which copies the attributes at or above a level (patient flows down to study / series / instance). Present + non-empty only; _meta/_vrMap not copied. - Export them from the core index. Encapsulated (@dcmjs-org/encapsulated): - Add encapsulate(bytes, options): the generic Encapsulated Document builder. Layered merge defaults < baseDicom < inherited < explicit overrides, then the document payload/encoding pinned on top. Identity guard: SOPClassUID / SOPInstanceUID / SeriesInstanceUID / Modality are never inherited, so a document can't impersonate the source even at series/instance level. A fluent chaining builder is noted as a deferred follow-up. - Add defaults/pdfBase.js: the PDF-identifying base defaults (factory). - encapsulatePdf is now a thin decorator over encapsulate: magic-check, then supply the PDF base + mime type. New instance + dataLevel options; sourceInstance kept as a back-compat alias (maps to instance, dataLevel 'study'). extractEncapsulatedPdf unchanged (finding-16 behavior preserved). - README + public exports updated. Tests: 10 new core tests, 8 new encapsulate tests; the 19 existing encapsulated tests stay green. Full suite 951 passed / 12 skipped / 0 failed. Co-Authored-By: Claude Fable 5 <[email protected]> * chore: ignore local temp/ and tmp/ output Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(core): createInstance with composable base blocks; encapsulate uses it Core (@dcmjs-org/core): - createInstance({ baseDicom, instance, dataLevel, levels, predecessor, ...overrides }): merge base < inherited < overrides. Logs a warning when an inherited Modality or SOPClassUID differs from the base. - Base blocks are objects, functions of a context, arrays, or combineBases(...items); a combined block keeps its parts on .items. Core blocks: patientBase, studyBase, seriesBase, instanceBase, equipmentBase (defaultInstanceBase), plus predecessorBase and nextSeriesNumberBase(seriesList, filter). - The level blocks create new identity only below dataLevel, so dataLevel "series" now joins the source series. The "instance" level is removed; instance values are overrides. - DATA_LEVELS is a list of { name, tags }; extendDataLevels adds tags and a custom list goes in the levels option. PatientAge, PatientSize and PatientWeight are study-level. - deepCloneInstance clones naturalized data, wraps functions, clones promise values, and shares binary unless copyBinary is set. Nothing is frozen. - hierarchicalReferences builds Hierarchical SOP Instance References; predecessorBase uses it for PredecessorDocumentsSequence. Encapsulated (@dcmjs-org/encapsulated): - encapsulate calls createInstance; the bases are compositions: encapsulatedBase = defaultInstanceBase + encapsulatedDocumentBase + predecessorBase, encapsulatedPdfBase adds pdfBase. - MIME type precedence: mimeType > dataset value > base. - The sourceInstance alias and NON_INHERITABLE are removed. - The README splits user and implementation requirements. Tests: the core suites own the level rules; low-value and duplicate tests are removed; the encapsulated suites share test/part10Helpers.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]>
wayfarer3130
added a commit
that referenced
this pull request
Oct 21, 2026
* 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]> * 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]> * 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(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]> * ci: ignore the unpatchable braces advisory in audit, scoped and documented GHSA-vfj7-8cjw-p6xm was published 2026-10-02 with a claimed fix range of >=3.0.4, but no such braces release exists on the registry, so there is nothing to override to. Every path is dev tooling; braces never reaches the published packages. Same entry the fhir staging branch already carries (#589) — remove it the moment a patched braces ships. Co-Authored-By: Claude Fable 5 <[email protected]> (cherry picked from commit 7261970) * 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) * feat(imaging): extract @dcmjs-org/imaging from @dcmjs-org/video PR #588 review (conversation with Bill): split the lightweight, codec-free image building out of video so a consumer that only needs to build image instances doesn't pull the heavy MP4/video machinery, and SOP-specific image info stays out of core. New @dcmjs-org/imaging (depends on core only): - buildImageDataset + SECONDARY_CAPTURE_SOP_CLASS_UID (moved from video/src/image) - parseJpegInfo (moved) - h264TransferSyntaxUID (extracted from video/src/image/mp4Info.js into src/h264.js) @dcmjs-org/video now depends on @dcmjs-org/imaging: - parseMp4Info stays (MP4 container parsing is video-domain) and imports h264TransferSyntaxUID from imaging - src/image/ and the public surface trimmed to parseMp4Info + the video encapsulation/streaming; descriptions/comments updated Tests moved with their code (buildImageDataset, jpegInfo); the h264TransferSyntaxUID describe block moved to packages/imaging/test/h264.test.js. RELEASE_PLAN gains an imaging row and notes the landing order (imaging with/before video). Full suite 954 passed / 11 skipped / 0 failed. Follow-ons (separate branches): media exports an imaging namespace and sources the image builders from imaging; fhir->imaging deferred until fhir builds images. Co-Authored-By: Claude Fable 5 <[email protected]> * feat(imaging,video): build image and video instances with createInstance buildImageDataset and buildVideoDataset now use createInstance from @dcmjs-org/core, the same creator pattern as @dcmjs-org/encapsulated: - New base blocks: imageBase / secondaryCaptureImageBase and videoBase / videoPhotographicBase, each with predecessorBase. - The instance, dataLevel, levels, predecessor and baseDicom options pass through to createInstance. Payload attributes (geometry, stream values, transfer syntax) are set after it. - createInstance writes only DICOM attributes (keywords, tags, _meta/_vrMap) from the overrides; other keys are dropped with a warning. Each builder removes its own control keys first. - The video base no longer sets StudyID 1; a new study gets the Type 2 empty StudyID from studyBase. - buildImageDataset reuses the core EXPLICIT_LITTLE_ENDIAN and merges _vrMap. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(core): createInstance keeps keywords added with registerTag The attribute filter now accepts a keyword that lookupRegisteredTagByName finds, as denaturalizeDataset does. Before this fix, such an override was dropped with a warning. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(core,imaging,video): one instance-creation model for all builders All builders (encapsulate, buildVideoDataset, buildImageDataset) take the same options: createInstance options, attribute overrides, and their own payload control keys. packages/core/README.md documents the shared model (CORE-USR/CORE-IMP); the package READMEs refer to it. core createInstance: - never copies the identity of `instance` (SOPInstanceUID, SOPClassUID, InstanceNumber, media storage UIDs), also with a custom `levels` - InstanceNumber at series level is the largest prior number + 1 - Type 2 empty StudyDate/StudyTime/SeriesNumber for an inherited level - skips undefined overrides; rejects a DICOM JSON `instance` - nextSeriesNumberBase counts only IS integers imaging: - remove the `metadata` option and the old `derivedFrom` shapes - new derivedImageAttributes / derivedImageBase: derivation from one or more naturalized instances, as a base block; lossy history is kept - ImageType ORIGINAL\PRIMARY is a base value video: README with VID requirements; control keys removed before the call. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(core,encapsulated,imaging,video): overrides provider and postProcess All builders take one option shape: the createInstance controls (baseDicom, instance, dataLevel, levels, predecessor, postProcess), their own control keys, and `overrides`. `overrides` is a naturalized DICOM provider with the same forms as baseDicom; its attributes go only into the result. An extra option key has no effect. core createInstance: - baseDicom resolves, then overrides; merge base < inherited < overrides, with a key merge of _meta; then postProcess (default removeUndefinedAttributes, top level only), so an undefined override removes the attribute - `instance` gives the attributes that `levels` lists; at dataLevel series the new InstanceNumber is the sample (first) instance's + 1 - Modality warning uses a presence check of the override - validation is part of the usage flow (CORE-IMP-11); pure type checks removed encapsulated: export PDF_MIME_TYPE; a builder sets only _meta.TransferSyntaxUID on a copy of _meta. imaging: geometry, HighBit and PixelRepresentation are written only when the decoded image gives them; ConversionType is a base value; a float pixel array throws. video: no attribute for a missing mp4Info field; createVideoEventSource keeps the returned _meta and the caller's file meta keys; normalizeFragmentBytes is no longer exported. eslint: no-unused-vars ignoreRestSiblings. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(imaging,video): predecessorBase only in the encapsulated bases predecessorBase is an optional base block in core, one more way to add default attributes. The encapsulated document bases include it. imageBase and videoBase no longer include it, so `predecessor: true` has no effect with those default bases. A caller can add the block, for example combineBases(imageBase, predecessorBase). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]> Co-authored-by: Bill Wallace <[email protected]>
wayfarer3130
added a commit
that referenced
this pull request
Oct 21, 2026
…m media factories (#588) * 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]> * 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]> * 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(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]> * ci: ignore the unpatchable braces advisory in audit, scoped and documented GHSA-vfj7-8cjw-p6xm was published 2026-10-02 with a claimed fix range of >=3.0.4, but no such braces release exists on the registry, so there is nothing to override to. Every path is dev tooling; braces never reaches the published packages. Same entry the fhir staging branch already carries (#589) — remove it the moment a patched braces ships. Co-Authored-By: Claude Fable 5 <[email protected]> (cherry picked from commit 7261970) * 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) --------- 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 is the deferred integration slice: the FHIR event source (
fromFhir) and the facade pair (DicomEventStream.fromFhir/toFhir). With it, the staging branch closes the loop that PRs #574, #579 and #582 opened — a FHIR DocumentReference or Media with inline base64 content goes IN and a DICOM instance comes out, and a parsed instance goes in and FHIR resources come back OUT, all through the sameDicomEventStreamfacade the core and media waves built.A placement decision to state up front:
fromFhir.jslands at rootsrc/eventStream/fromFhir.js, NOT inside the fhir package. It is wrapper-level glue — the same home asapi.js— because it composes five packages at once:encapsulatePdffrom@dcmjs-org/pdfs,buildImageDataset/parseJpegInfofrom@dcmjs-org/video,patientToDatasetfrom@dcmjs-org/fhir,base64ToArrayBufferfrom@dcmjs-org/parser, andDicomMetaDictionaryfrom@dcmjs-org/core. Putting it inside any one package would make that package depend on the other four for one file. It moves into the step-7 wrapper package together with the facade; the module header says so. To make the composition resolvable,@dcmjs-org/core,@dcmjs-org/fhir, and@dcmjs-org/parserjoin the root workspace dependencies alongside the pdfs/video entries the media wave added.The port is legacy-free where v2 was not: v2's
fromFhir.jscalled the legacydatasetToDict. Here that call is replaced with the same plain{ meta, dict }helper pattern the video wave used —datasetToMetaDict, a local copy of the one insidepackages/video/src/eventStream/fromVideo.js(it is not exported from the video package; the copy carries a comment saying both retire into the step-7 wrapper). Nothing in the new code touches@dcmjs-org/legacy.I did the finding-14 fix red-green, mirroring the media wave exactly. v2's
fromFhirfacade builds the dataset eagerly at factory time — synchronously, so for FHIR the failure shape is a factory throw rather than video's unhandled rejection, but it violates the same contract: errors surface from the sink, never the factory. The regression test (unhandledRejection capture + the assertion that the corrective error rejectstoPart10()) went in against the verbatim eager port first:all five failing with throws from
DicomEventStream.fromFhirat factory time. The lazy form (dataset built on first consumption, cached so minted UIDs stay stable across re-runs — pinned by its own test) turns all fourteen green.On the umbrella tests that #579/#582 deferred: the half that is really about the integration now runs. v2's "dcmjs.fhir umbrella namespace" block had two tests — bytes straight to FHIR, and the namespace re-exports. The first exists here as its facade form,
DicomEventStream.fromPart10(bytes).toFhir()over the committedsample-dicom.dcmfixture, asserting the same ground truth (PatientID 11791306742903, the urn:oid study identifier). The second — thedcmjs.fhirnamespace spread onto the default export — is the step-7 wrapper's surface and stays deferred; the comments inpackages/fhir/test/toFhir.test.jsnow say precisely that instead of "they return with fromFhir.js".Provenance, plainly:
fromFhir.jsis verbatim v2 except the import block, thedatasetToMetaDictreplacement fordatasetToDict, and the placement note in the header; the facadetoFhirand thefromFhirdoc comment are verbatim v2; hand-written are the lazyfromFhirthunk, the rootpackage.jsondependency entries, the finding-14 regression, the stable-identity test, the fixture-basedfromPart10 → toFhirtest, and the corrective-error tests' rework from sync throws to sink rejections (forced by the lazy contract). The ported suite drops v2's twoparseJpegInfotests becausepackages/video/test/jpegInfo.test.jsalready carries a superset of them next to the code.14 new tests (9 ported + 5 hand-written). Full suite on this branch: 1010 passing (1022 total, 12 skipped), up from 996 on the staging branch after the media merge; build green. Note the staging branch now contains
release/1.0-beta-mediamerged in (this slice needs the pdfs/video packages and the facade factories), with the lockfile conflict resolved by regeneration.One rider I did not plan: GHSA-vfj7-8cjw-p6xm (braces, high) was published mid-flight — the identical lockfile passed audit on the staging branch twenty minutes before this PR's first audit run failed. Its stated patched range is >=3.0.4, but no such release exists on the registry (pnpm refuses the override with ERR_PNPM_NO_MATCHING_VERSION), so the fix is a single-GHSA
auditConfig.ignoreGhsasentry in pnpm-workspace.yaml, commented for removal the moment a patched braces ships. Every path to braces is dev tooling (cpy-cli, lint-staged, jest); it never reaches the published package.🤖 Generated with Claude Code