Skip to content

Commit 33bedfb

Browse files
author
hackermd
committed
Fix parsing of PN data elements with empty value
1 parent 049287c commit 33bedfb

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

src/dicomweb_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '0.10.0'
1+
__version__ = '0.10.1'
22

33
from dicomweb_client.api import DICOMwebClient

src/dicomweb_client/api.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,20 @@ def _create_dataelement(tag, vr, value):
9494
elem_value = []
9595
for v in value:
9696
if not isinstance(v, dict):
97-
# Some DICOMweb services get this wrong, so we workaround it
98-
# and issue a warning rather than raising an error.
97+
# Some DICOMweb services get this wrong, so we workaround the
98+
# the issue and warn the user rather than raising an error.
9999
logger.warning(
100100
'attribute with VR Person Name (PN) is not '
101101
'formatted correctly'
102102
)
103103
elem_value.append(v)
104104
else:
105-
# TODO: How to handle "Ideographic" and "Phonetic"?
106-
elem_value.append(v['Alphabetic'])
105+
elem_value.extend(list(v.values()))
107106
if vm == '1':
108-
elem_value = elem_value[0]
107+
try:
108+
elem_value = elem_value[0]
109+
except IndexError:
110+
elem_value = None
109111
else:
110112
if vm == '1':
111113
if vr in binary_representations:

src/dicomweb_client/tests/test_api.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,24 +311,50 @@ def test_load_json_dataset_tm(httpserver, client, cache_dir):
311311

312312

313313
def test_load_json_dataset_pn_vm1(httpserver, client, cache_dir):
314-
value = ['Only^Person']
314+
name = 'Only^Person'
315+
value = [{'Alphabetic': name}]
315316
dicom_json = {
316317
'00080090': {
317318
'vr': 'PN',
318319
'Value': value,
319320
},
320321
}
321322
dataset = load_json_dataset(dicom_json)
322-
assert dataset.ReferringPhysicianName == value[0]
323+
assert dataset.ReferringPhysicianName == name
323324

324325

325326
def test_load_json_dataset_pn_vm2(httpserver, client, cache_dir):
326-
value = ['First^Person', 'Second^Person']
327+
names = ['First^Person', 'Second^Person']
328+
value = [{'Alphabetic': names[0]}, {'Alphabetic': names[1]}]
327329
dicom_json = {
328330
'0008009C': {
329331
'vr': 'PN',
330332
'Value': value,
331333
},
332334
}
333335
dataset = load_json_dataset(dicom_json)
334-
assert dataset.ConsultingPhysicianName == value
336+
assert dataset.ConsultingPhysicianName == names
337+
338+
339+
def test_load_json_dataset_pn_vm1_empty(httpserver, client, cache_dir):
340+
value = [{}]
341+
dicom_json = {
342+
'00080090': {
343+
'vr': 'PN',
344+
'Value': value,
345+
},
346+
}
347+
dataset = load_json_dataset(dicom_json)
348+
assert dataset.ReferringPhysicianName == ''
349+
350+
351+
def test_load_json_dataset_pn_vm2_empty(httpserver, client, cache_dir):
352+
value = [{}]
353+
dicom_json = {
354+
'0008009C': {
355+
'vr': 'PN',
356+
'Value': value,
357+
},
358+
}
359+
dataset = load_json_dataset(dicom_json)
360+
assert dataset.ConsultingPhysicianName == []

0 commit comments

Comments
 (0)