Skip to content

Commit

Permalink
Merge pull request #1305 from girder/dicom-metadata-extract
Browse files Browse the repository at this point in the history
Harden dicom metadata extraction code.
  • Loading branch information
manthey authored Sep 19, 2023
2 parents 60dcc81 + 3551d98 commit c3885c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Improvements
- Frame selection presets have configurable defaults ([#1301](../../pull/1301))
- Improved DICOM metadata extraction ([#1305](../../pull/1305))

## 1.24.0

Expand Down
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 c3885c3

Please sign in to comment.