Skip to content

Commit 3e49598

Browse files
committed
feat: add yield_child_fields to list child fields UIDs, bump version and changelog
1 parent d911d72 commit 3e49598

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
1414
Referenced versions in headers are tagged on Github, in parentheses are for pypi.
1515

1616
## [vxx](https://github.com/pydicom/deid/tree/master) (master)
17+
- Fix field removal and blanking to clean up child UID references [#293](https://github.com/pydicom/deid/pull/293) (0.4.9)
1718
- Fix UID lookup for nested sequence fields in DICOM datasets [#292](https://github.com/pydicom/deid/pull/292) (0.4.8)
1819
- Allow saving with a compressed transfer syntax [#290](https://github.com/pydicom/deid/pull/290) (0.4.7)
1920
- Improve performance of header deid with caching and lookup tables [#289](https://github.com/pydicom/deid/pull/289)

deid/dicom/parser.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ def get_nested_field(self, field, return_parent=False):
176176
return parent, desired
177177
return desired
178178

179+
def yield_child_fields(self, field):
180+
"""
181+
Return a list of child field UIDs for a given field.
182+
183+
This method identifies all field UIDs in self.fields that are nested under the provided field,
184+
based on the UID prefix convention (parent UID + '__').
185+
It is used to find and remove all child fields when blanking or deleting a parent field (e.g., a sequence).
186+
"""
187+
field_uid_prefix = field.uid + "__"
188+
child_uids = [uid for uid in self.fields if uid.startswith(field_uid_prefix)]
189+
return child_uids
190+
179191
def delete_field(self, field):
180192
"""
181193
Delete a field from the dicom.
@@ -191,11 +203,7 @@ def delete_field(self, field):
191203
# Remove the field itself from the lookup
192204
self.fields.remove(field.uid)
193205
# Also remove any child fields that were nested under this field
194-
field_uid_prefix = field.uid + "__"
195-
child_uids = [
196-
uid for uid in self.fields if uid.startswith(field_uid_prefix)
197-
]
198-
for child_uid in child_uids:
206+
for child_uid in self.yield_child_fields(field):
199207
self.fields.remove(child_uid)
200208

201209
def blank_field(self, field):
@@ -211,11 +219,7 @@ def blank_field(self, field):
211219
if parent and desired in parent:
212220
parent[desired].value = None
213221
# Also remove any child fields that were nested under this field
214-
field_uid_prefix = field.uid + "__"
215-
child_uids = [
216-
uid for uid in self.fields if uid.startswith(field_uid_prefix)
217-
]
218-
for child_uid in child_uids:
222+
for child_uid in self.yield_child_fields(field):
219223
self.fields.remove(child_uid)
220224

221225
def replace_field(self, field, value):

deid/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__copyright__ = "Copyright 2016-2025, Vanessa Sochat"
33
__license__ = "MIT"
44

5-
__version__ = "0.4.8"
5+
__version__ = "0.4.9"
66
AUTHOR = "Vanessa Sochat"
77
AUTHOR_EMAIL = "[email protected]"
88
NAME = "deid"

0 commit comments

Comments
 (0)