Skip to content

Commit d3d8a45

Browse files
committed
BUG: Fix XML loading to convert numeric VR values to proper Python types
1 parent b5540b7 commit d3d8a45

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/dicomweb_client/web.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
)
3030

3131
import pydicom
32+
from pydicom.valuerep import INT_VR, FLOAT_VR, VR
3233
import requests
3334
import retrying
3435

@@ -74,6 +75,26 @@ def _load_xml_dataset(dataset: Element) -> pydicom.dataset.Dataset:
7475
value = [v.text.strip() for v in value]
7576
else:
7677
value = None
78+
79+
# Convert string values to appropriate Python types for
80+
# numeric VRs to satisfy pydicom 3.0+ stricter type validation
81+
if value is not None:
82+
try:
83+
vr_enum = VR(vr)
84+
if vr_enum in INT_VR:
85+
if isinstance(value, list):
86+
value = [int(v) for v in value]
87+
else:
88+
value = int(value)
89+
elif vr_enum in FLOAT_VR:
90+
if isinstance(value, list):
91+
value = [float(v) for v in value]
92+
else:
93+
value = float(value)
94+
except ValueError:
95+
# VR not recognized, leave value as-is
96+
pass
97+
7798
setattr(ds, keyword, value)
7899
return ds
79100

0 commit comments

Comments
 (0)