Skip to content

Commit

Permalink
Harden dicom metadata extraction code.
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Sep 19, 2023
1 parent 60dcc81 commit 1c19930
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions sources/dicom/large_image_source_dicom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,19 @@ def dicom_to_dict(ds, base=None):
key = pydicom.datadict.keyword_for_tag(k)
except Exception:
pass
if v.get('vr') in {None, 'OB'}:
continue
if not len(v.get('Value', [])):
continue
if isinstance(v['Value'][0], dict):
val = [dicom_to_dict(ds, entry) for entry in v['Value']]
elif len(v['Value']) == 1:
val = v['Value'][0]
if isinstance(v, str):
val = v
else:
val = v['Value']
if v.get('vr') in {None, 'OB'}:
continue
if not len(v.get('Value', [])):
continue
if isinstance(v['Value'][0], dict):
val = [dicom_to_dict(ds, entry) for entry in v['Value']]
elif len(v['Value']) == 1:
val = v['Value'][0]
else:
val = v['Value']
info[key] = val
return info

Expand Down

0 comments on commit 1c19930

Please sign in to comment.