Skip to content

feat(core): private blocks of a DICOM JSON dict by block key (1.0 port of #626) - #641

Merged
wayfarer3130 merged 1 commit into
1.0-betafrom
feat/1.0-beta-private-block-dict
Nov 24, 2026
Merged

wayfarer3130 merged 1 commit into
1.0-betafrom
feat/1.0-beta-private-block-dict

Conversation

@wayfarer3130

Copy link
Copy Markdown
Contributor

Summary

This PR is the 1.0-beta equivalent of #626. It adds the private block API of a DICOM JSON dict, with the names of the 1.0 naturalized form. It also changes the block key of a creator that has a line break.

// write: the code finds the block of the creator, or reserves the first free block
dicomDict.privateBlock("4D43:ACME 1.0").set("x01", "CS", ["HYBRID"]);

// read: find the block by creator, never by block number
dcmjs.data.findPrivateBlock(dict, "4D43:ACME 1.0")?.get("x01").Value;

Changes

  • packages/core/src/utilities/privateBlockDict.js (new): findPrivateBlock(dict, groupOrKey, creator?) and reservePrivateBlock(dict, groupOrKey, creator?).
    • A caller names a block by the block key "gggg:creator", or by the group number and the creator.
    • A caller names an element by "xEE" or by the number 0x00–0xFF.
    • The accessor gives key, group, creator, reservedBlock, tag(), has(), get() and set().
    • The functions use creatorText and firstFreeBlock of privateBlocks.js. They do not copy those rules.
  • packages/legacy/src/DicomDict.js: privateBlock(groupOrKey, creator?, { create }). The default create: true writes the creator element when the creator has no block.
  • privateBlockKey(group, creator) in privateBlocks.js builds every block key. In the key, a line feed in the creator is the text \n, and a carriage return is the text \r. parsePrivateBlockKey changes the text back. An LO value holds no backslash, so the escape is not ambiguous.
  • The exports: @dcmjs-org/core and dcmjs.data export findPrivateBlock, reservePrivateBlock and privateBlockKey.
  • docs/specs/naturalized-dataset.md: NAT-U-PRIV-1 gets the escape rule. NAT-U-PRIV-11 (new) is the user requirement of the dict-level API. NAT-I-CODE-1 lists the new functions.
  • docs/MIGRATION.md, item 6: the escape rule and the dict-level API.

A change to a user expectation

#639 gave the block key of a creator "AC\nME" as "0029:AC + line feed + ME". This PR changes that key to "0029:AC\\nME" (the backslash and the letter n). The creator value of the block keeps the line feed, and the written creator element does not change. The four #639 tests in test/core/privateBlocks.test.js now expect the new key. A line separator (
) does not change.

Tests

  • test/privateBlock.test.js (new) is the same file as in feat: private block reservation per PS3.5 Section 7.8.1 #626 on master. git hash-object gives the same blob on the two branches. The file tests the dict-level API on 0.x and on 1.0 with one definition format.

  • test/core/privateBlocks.test.js: one new test makes sure that a block that the dict API reserves naturalizes under the same key, and that a new naturalized block is found by the dict API after denaturalize.

  • test/bundle-size.test.js: the dcmjs.js ceiling changes from ×1.066 to ×1.075. The bundle is not minified, and the new API adds about 8.7 KB (×1.0713). dcmjs.es.js stays below its ×1.06 ceiling (×1.055).

  • Local result: 1248 tests pass. test/data.test.js has 3 failures because a local test-data cache is missing a file (ENOENT). One test of test/async-data.test.js failed under the load of the full suite, and it passes when it runs alone.

Relation to #626

#626 targets master (0.x). It now has the same API, the same block key, and the same test file. Merge this PR before or with #626, so that the 0.x names stay valid in 1.0.

🤖 Generated with Claude Code

The 1.0 port of #626. findPrivateBlock() and reservePrivateBlock() in
@dcmjs-org/core, and DicomDict#privateBlock() in legacy, name a block by
the naturalized block key "gggg:creator" (or group and creator) and an
element by "xEE" (or its number). They reuse creatorText and
firstFreeBlock of privateBlocks.js.

privateBlockKey() now builds every block key: a line break in the
creator is the text \n (and \r) in the key, and parsePrivateBlockKey
reverses it. The #639 tests expect the escaped key.

test/privateBlock.test.js is the same file as on master. NAT-U-PRIV-1
gets the escape rule, NAT-U-PRIV-11 is new, and the dcmjs.js bundle
ceiling moves to x1.075.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wayfarer3130
wayfarer3130 marked this pull request as ready for review November 12, 2026 15:57
@wayfarer3130
wayfarer3130 requested a review from pieper November 12, 2026 15:59
@wayfarer3130
wayfarer3130 merged commit 2b74aa3 into 1.0-beta Nov 24, 2026
4 checks passed
@wayfarer3130
wayfarer3130 deleted the feat/1.0-beta-private-block-dict branch November 24, 2026 16:48
@github-actions

Copy link
Copy Markdown

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

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