Repository navigation
fix: preserve private elements through denaturalize in a writable shape - #546
Merged
awatson1978 merged 1 commit intoSep 30, 2026
Merged
Conversation
naturalizeDataset now records the original VR of dictionary-less elements in _vrMap, and denaturalizeDataset rebuilds a writable element from that VR instead of dropping the element with an Unknown-name warning. A hex key with no recorded VR is still skipped, so no element is ever emitted in a shape the writer cannot serialize. Review finding 4 from the PR #512 review map; unskips the #388/#215 known-gap tests in test/issues/issue388-private-tags.test.js. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🎉 This PR is included in version 1.0.0-beta.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This was referenced Oct 30, 2026
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.
Private elements now survive
naturalizeDataset→denaturalizeDataset→write()— in a shape the writer can actually serialize.Some background. When
naturalizeDatasetmeets an element that has no dictionary entry — a private tag, typically — it keeps the raw 8-hex-digit tag as the key. On the way back,denaturalizeDatasetlooked that key up innameMap, found nothing, logged "Unknown name in dataset", and dropped the element. So a plain read → naturalize → denaturalize → write round trip silently destroyed every unregistered private element in the file. That's the classic vendor-tag workflow: read a GE or Philips file, touch one standard attribute, write it back — and all the private calibration data is gone.The review of PR #512 flagged this exact spot as finding 4. That branch had tried to fix the drop with a
vr: "UN"fallback, but it leftValueas an array of strings — UN carries bytes, soDicomDict.write()then threwFirst argument to DataView constructor must be an ArrayBuffer. Preserving the element is right (PS3.5 6.2.2); building an unwritable element is not. This PR implements the preservation correctly.The mechanics: the VR is already known at naturalize time — the reader put it on the element. So
naturalizeDatasetnow records it in the dataset's existing_vrMapside-table whenever there's no dictionary entry, anddenaturalizeDatasetuses that recorded VR to rebuild the element through the normal path. No guessing, no UN coercion: an LO comes back as an LO with its string value intact, and the writer serializes it exactly as it would any known element.When no VR was ever recorded — a hand-built dataset like
denaturalizeDataset({ "00291010": ["ACME"] })with no_vrMap— the element is still skipped with the existing warning, per the review's guidance: skip when no VR is known, rather than emit something the writer chokes on.The regression tests are the two known-gap skips in
test/issues/issue388-private-tags.test.js, now green and unskipped: the #388 case (private elements inside a SQ item survive denaturalize → write → re-read) and the #215 case (unregistered top-level private tags survive static denaturalize and write). A third new test pins the no-recorded-VR skip. This is review finding 4 from the PR #512 review map; the defective UN fallback itself never landed on this branch, so what lands here is the intended behavior done right. For the record,master(0.52) has the silent-drop behavior, not the unwritable-element defect — that was new code in the #512 development branch.🤖 Generated with Claude Code