Repository navigation
feat: private block reservation per PS3.5 Section 7.8.1 - #626
Merged
Merged
Conversation
Writing a private element meant hand-managing the reservation: pick a
block, hope nothing else has it, write the creator element yourself, and
build each tag by string concatenation.
dicomDict.upsertTag("4D430010", "LO", ["ACME 1.0"]);
dicomDict.upsertTag("4D431001", "CS", ["HYBRID"]);
That hard-codes the block number, which is the one thing a caller must not
assume: which block a creator holds is decided by whoever wrote the file.
A reader that looks at (4D43,1001) because the writer happened to use
block 0x10 reads the wrong element as soon as the file came from somewhere
that used 0x11.
// writing - the block is allocated, not chosen
const block = dicomDict.privateBlock(0x4d43, "ACME 1.0");
block.set(0x01, "CS", ["HYBRID"]);
// reading, from any parsed dict - found by creator, never by block
const block = findPrivateBlock(dict, 0x4d43, "ACME 1.0");
block && block.get(0x01).Value;
findPrivateBlock() takes a plain dict, because that is what a reader has
after DicomMessage.readFile(); DicomDict#privateBlock() is the writing
side and reserves a block when the creator has none. Reservation finds the
creator if it is already there, otherwise takes the lowest free block, so
blocks another writer holds are left alone. Creator values are compared
trimmed, since LO pads an odd length with a space.
Validation follows the standard rather than the previous ad hoc checks: an
even group is rejected (private data elements are in odd groups), blocks
are 0x10 to 0xFF (0x00 to 0x0F are reserved), elements are 0x00 to 0xFF
within the block, and a creator must be a non-empty string within LO's 64
characters.
Note this does not touch Tag#isPrivateCreator(), which accepts elements
0x01 to 0x0F as creators and so disagrees with the block range used here -
that is #356, and worth its own change since it alters how existing files
parse.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
✅ Deploy Preview for dcmjs2 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
- The accessor gives key, group, creator and reservedBlock, as the 1.0 naturalized block does. Calls accept the block key or (group, creator), and an element as 0x00-0xFF or "xEE". - A line break in the creator is the text \n (and \r) in the block key. - A block that holds elements with no creator, or an empty creator, is not free. - The creator match strips leading spaces and trailing spaces and NULs, and reads a creator held as bytes (UN) as Latin-1. - set() adds the tag accessors, as upsertTag does. - Export privateBlockKey in place of privateTag. - Remove the two OB writer tests; they test the Part 10 writer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
wayfarer3130
approved these changes
Nov 12, 2026
wayfarer3130
left a comment
Contributor
There was a problem hiding this comment.
Made some changes so that this is compatible with 1.0-beta, and am creating the equivalent PR there with the same test code.
Contributor
Collaborator
Author
|
Thanks @wayfarer3130 - I'll be tied up for a week or so but hope to catch up later this month. |
wayfarer3130
added a commit
that referenced
this pull request
Nov 24, 2026
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]>
|
🎉 This PR is included in version 0.53.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This was referenced Nov 24, 2026
wayfarer3130
added a commit
that referenced
this pull request
Nov 24, 2026
Resolve the conflict in src/index.js: keep both export sets in the data namespace, dictionary and registerTag from this branch, and findPrivateBlock, reservePrivateBlock and privateBlockKey from #626. Co-Authored-By: Claude Opus 5.5 <[email protected]>
wayfarer3130
added a commit
that referenced
this pull request
Nov 24, 2026
registerTag() no longer replaces a name that nameMap already has for a different tag (a standard keyword or an earlier registration). The existing entry wins, as in 1.x, and a warning names both tags. One helper, addRegisteredToNameMap(), applies the rule at load and on each later registerTag() call. The registerTag() doc comment now says that a private element registered by position assumes block 0x10, and points to the private-block functions of #626. Co-Authored-By: Claude Opus 5.5 <[email protected]>
wayfarer3130
added a commit
that referenced
this pull request
Nov 24, 2026
* fix(dictionary): keep nameMap current when a tag is registered registerTag() added an entry to the dictionary but not to DicomMetaDictionary.nameMap, which is what denaturalizeDataset() looks a name up in. So a registered tag could be read but never written: the value was dropped with nothing but a "[warn] Unknown name in dataset", which is why this was easy to miss. nameMap could not simply be regenerated either. It is built once at module load, and the loop that was meant to pick up dictionary additions walks Object.keys(dictionary) - which sees only entries assigned directly onto the Proxy, never anything registerTag() put in the module's cache. That loop stays, because assigning onto the dictionary is the documented custom dictionary pattern (#215) and a test covers it; registered entries are now contributed alongside it, from a map kept for the purpose, and a registrar callback keeps nameMap current for anything registered later. Two further fixes needed to make the feature usable: - Normalize the tag to upper case. getAllStandardTagEntries() carries upper case, and Tag.toCleanString() upper-cases when reading a file, so a tag registered in lower case denaturalized to a key no reader ever produces. Lookups still accept either case, as they do for the standard dictionary. - Export registerTag and dictionary from index.js. They were reachable only by importing src/dictionary.fast.js directly, so the feature was not part of the public API at all. The shipped private dictionary is still kept out of nameMap: those names are vendor-specific and collide, and writing one because a caller's field happened to match would be wrong. Entries from registerTag() default to version "User" and are included. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * fix: a registered name never replaces an existing keyword registerTag() no longer replaces a name that nameMap already has for a different tag (a standard keyword or an earlier registration). The existing entry wins, as in 1.x, and a warning names both tags. One helper, addRegisteredToNameMap(), applies the rule at load and on each later registerTag() call. The registerTag() doc comment now says that a private element registered by position assumes block 0x10, and points to the private-block functions of #626. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[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.
The problem
Writing a private element means hand-managing the reservation — pick a block, hope nothing else has it, write the creator element yourself, build each tag by string concatenation:
That hard-codes the block number, which is the one thing a caller must not assume. Per PS3.5 §7.8.1 a creator at
(gggg,00xx)reserves(gggg,xx00)–(gggg,xxFF), and whichxxa creator holds is decided by whoever wrote the file. A reader that looks at(4D43,1001)because the writer happened to use block0x10reads the wrong element as soon as the file came from somewhere that used0x11.This PR
findPrivateBlock()takes a plain dict, because that is what a reader has afterDicomMessage.readFile().DicomDict#privateBlock()is the writing side and reserves a block when the creator has none — finding the creator if it is already present, otherwise taking the lowest free block, so blocks another writer holds are left alone. Creator values are compared trimmed, sinceLOpads an odd length with a space.Validation follows the standard rather than ad hoc checks: an even group is rejected (private data elements are in odd groups), blocks are
0x10–0xFF(0x00–0x0Fare reserved), elements are0x00–0xFFwithin the block, and a creator must be a non-empty string withinLO's 64 characters.Tests
12 in
test/privateBlock.test.js: allocation, idempotence for the same creator, skipping blocks another writer holds, lookup without reserving, a full file round trip found by creator, a creator pushed to block0x30, trailing-pad tolerance, and the validation cases.Two of them cover what a private block is usually for — carrying an opaque payload:
OBround-tripping byte-exact, so the 32-bit length path is exercised rather than assumed;OBcoming back one byte longer with a trailing pad, since DICOM value fields are even length (PS3.5 §7.1.1). That is worth pinning: it is why a payload needs its own length recorded alongside it rather than relying on the element length.Full suite: 26 suites / 366 tests.
Not included
This does not touch
Tag#isPrivateCreator(), which accepts elements0x01–0x0Fas creators and so disagrees with the block range used here. That is #356, and it deserves its own change because it alters how existing files parse.Disclosure
AI-assisted (Claude), per the process in #517. Motivated by needing to write a reserved private block in a downstream project, but the API is general. Pairs naturally with #625 (registering such a block's tags by name), though neither depends on the other.