Repository navigation
fix(dictionary): keep nameMap current when a tag is registered - #625
Merged
Merged
Conversation
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]>
✅ Deploy Preview for dcmjs2 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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]>
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
approved these changes
Nov 24, 2026
|
🎉 This PR is included in version 0.53.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
wayfarer3130
added a commit
that referenced
this pull request
Nov 27, 2026
) (#674) * fix: registerTag and anonymizer fixes from 0.53.3 (port of #510 and #625) - registerTag() stores the tag in upper case and finds both cases, so a tag registered in lower case keeps its keyword when a file is read. - The first registration of a name keeps the name; a warning names both tags. - DicomMetaDictionary.entryForName() is the one lookup by name (standard keyword first, then a registerTag() name). It is used by denaturalizeDataset(), tagAsIntegerFromName(), entryFor() and cleanTags(), so cleanTags() empties a registered name in a custom list. - dcmjs.data exports registerTag and dictionary again, as in 0.53.3. - The anonymizer list has ResponsiblePersonRole, as in 0.53.3. - MIGRATION.md states the nameMap difference from 0.53.3. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: registerTag name rules and tag registry requirements (review of #674) - The tag of the first argument wins over entry.tag. - A name that is the keyword of a different tag throws. The keyword of the same tag is accepted with no warning. - When two tags use one name, the second tag gets its hex tag as its name and keeps its VR and VM, so a read and a write keep both values. - A new name for a registered tag removes the old name. - entryForName() reads only own entries of nameMap. - docs/specs/registries.md: REG-U-18 to REG-U-21 for the tag registry; registries-implementation.md: REG-I-23 to REG-I-26. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[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 bug
registerTag()adds an entry to the dictionary but not toDicomMetaDictionary.nameMap, which is whatdenaturalizeDataset()looks a name up in. So a registered tag can be read but never written — the value is dropped, with nothing but a[warn] Unknown name in datasetto show for it. A silent write failure, which is why it was easy to miss.Why nameMap could not just be regenerated
nameMapis built once at module load, and the loop that was meant to pick up dictionary additions walksObject.keys(DicomMetaDictionary.dictionary). The dictionary is aProxywith noownKeystrap over its cache, so that loop sees only entries assigned directly onto the Proxy — never anythingregisterTag()put in the module's cache.That loop stays: assigning onto the dictionary is the documented custom-dictionary pattern from #215, and
test_custom_dictionarycovers it. (I removed it at first and that test caught me.) Registered entries are now contributed alongside it, from a map kept for the purpose, and a registrar callback keepsnameMapcurrent for anything registered after load.Two more fixes needed to make the feature usable
getAllStandardTagEntries()carries upper case andTag.toCleanString()upper-cases when reading a file, so a tag registered in lower case denaturalized to key4d431001while a reader produces4D431001— the two never line up. Lookups still accept either case, as they already do for the standard dictionary.registerTaganddictionaryfromindex.js. They were reachable only by importingsrc/dictionary.fast.jsdirectly, so this was not part of the public API at all.What is deliberately unchanged
The shipped private dictionary stays out of
nameMap. Those names are vendor-specific and collide, and writing one because a caller's field happened to match the name would be wrong. Entries fromregisterTag()default toversion: "User"and are included;version: "PrivateTag"is still filtered out. There is a test for that, so the distinction does not get lost later.This also leaves the
[warn] Unknown name in dataset 20011003warnings in the suite output alone — those are Philips private tags naturalized to numeric keys, a separate problem closer to #388.Tests
New
test/dictionary-register.test.js: reachability from the entry point, write-and-read-back of a private creator plus a block element, upper-case normalization through a real file, both tag spellings, thePrivateTagexclusion, and malformed input. Two of them fail with the registrar removed.Full suite: 26 suites / 360 tests.
Disclosure
AI-assisted (Claude), per the process in #517. Motivated by needing to write a registered private block in a downstream project, but the fix is general.