fix(dicom-loader): Correctly merge shared and per-frame functional groups for wadouri imageLoader #2291
+51
−2
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.
Context
This change addresses a critical issue in the WADO-URI loader where DICOM metadata was being incorrectly merged, leading to data loss.
The root cause is the shallow merge strategy used in combineFrameInstanceDataset when combining SharedFunctionalGroupsSequence (x52009229) and PerFrameFunctionalGroupsSequence (x52009230).
When a nested sequence (e.g., PlaneOrientationSequence) exists in both the shared and per-frame groups, the per-frame version would completely overwrite the shared version.
If the per-frame sequence was missing some tags that were present in the shared one, those tags were lost.
This PR fixes the merging logic to ensure that no metadata is lost and that the frame-specific DataSet is correctly constructed.
Changes & Results
Changes
deepMergeElements
function: A new private function has been introduced toperform a recursive (deep) merge of DICOM element objects.
deepMergeElements. Instead of a shallow merge that overwrites entire sequences, the new
logic correctly merges nested elements within sequences.
PerFrameFunctionalGroupsSequence correctly override those from
SharedFunctionalGroupsSequence at every level of nesting, as intended by the DICOM
standard.
Results
overwrite the SharedFunctionalGroupsSequence for tags that existed in both. This led to
a loss of nested metadata attributes that were present only in the shared sequence.
groups. Attributes from the per-frame group augment and override the shared group's
attributes without data loss. The resulting DataSet for each frame is now complete and
accurate.
Testing
The changes were manually tested using a real-world DICOM file that originally exposed the
metadata merging bug.
Test Data:
SharedFunctionalGroupsSequence (x52009229) and PerFrameFunctionalGroupsSequence
(x52009230).
in both the shared and per-frame functional groups.
within this sequence in the SharedFunctionalGroupsSequence but was absent from the
sequence in the PerFrameFunctionalGroupsSequence, which caused it to be lost after
the previous shallow merge logic.
Test Procedure & Results:
loaded.
from the shared PixelValueTransformationSequence and is present in the final
merged metadata for the frame.
Regression Testing:
loaded successfully, confirming that these changes have not introduced any
regressions into the standard image loading process.
Checklist
PR
semantic-release format and guidelines.
Code
etc.)
Public Documentation Updates
additions or removals.
Tested Environment