@@ -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 ):
0 commit comments