Skip to content

feat: add the DICOMweb JSON and dataset event sources - #532

Merged
awatson1978 merged 1 commit into
release/1.0-beta-corefrom
core/json-and-dict-sources
Sep 29, 2026
Merged

awatson1978 merged 1 commit into
release/1.0-beta-corefrom
core/json-and-dict-sources

Conversation

@awatson1978

@awatson1978 awatson1978 commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Second engine slice: the two event sources that don't involve bytes. A "source" here is a generator function that walks some representation of a DICOM dataset and pushes the event-stream contract — the callback vocabulary from #530 — into a listener. Landing two non-byte sources now is what proves the contract is genuinely source-agnostic before the Part 10 byte reader arrives.

Both live in src/eventStream/:

  • fromDicomWebJson.js walks DICOMweb JSON — the DICOM JSON model a DICOMweb server returns, an object keyed by tag with { vr, Value } entries — and emits events. Values pass through as-is: Person Names stay { Alphabetic } objects, numbers stay numbers. Canonicalizing values across sources is the naturalized listener's job in a later slice, not this one. Both binary forms are covered: a BulkDataURI entry becomes a bulkDataReference event without fetching anything, and an InlineBinary entry is base64-decoded into a binary fragment.
  • fromDataSet.js does the same walk over an in-memory { meta, dict } tree — the shape DicomMessage.readFile returns.

They arrive as a pair because fromDataSet borrows the base64 helper (base64ToArrayBuffer) from the JSON source, and each one's tests exercise the other. The deep-compare helper the tests share comes along too, in test/helper/equivalence.js.

Here's the JSON path end to end, feeding the reference collector from #530:

import { fromDicomWebJson, CollectorListener } from "dcmjs/src/eventStream";

const json = {
    "00100010": { vr: "PN", Value: [{ Alphabetic: "Doe^Jane" }] },
    "7FE00010": { vr: "OB", BulkDataURI: "https://server/studies/1.2.3/bulkdata/pixels" }
};

const collector = new CollectorListener();
await fromDicomWebJson(json, collector);

collector.result.dict["00100010"].Value; // → [{ Alphabetic: "Doe^Jane" }]
collector.result.dict["7FE00010"].Value; // → [{ BulkDataURI: "https://…/pixels" }]

fromDataSet(dataset, listener) works the same way from the other side. Both generators await listener.awaitDrain() at top-level element boundaries, so the backpressure checkpoints from the contract actually get exercised.

A note on size: this runs a little over the 500-line budget — about 830 authored lines — because splitting the pair would have landed code without its tests.

🤖 Generated with Claude Code

@awatson1978
awatson1978 merged commit 911b36a into release/1.0-beta-core Sep 29, 2026
8 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant