Skip to content

Commit

Permalink
Support for pydicom v3
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Oct 12, 2024
1 parent bc5f1ae commit 523e8ed
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 37 deletions.
14 changes: 6 additions & 8 deletions pynetdicom/dsutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ def create_file_meta(
file_meta.ImplementationClassUID = implementation_uid
file_meta.ImplementationVersionName = implementation_version

# File Meta Information is always encoded as Explicit VR Little Endian
file_meta.is_little_endian = True
file_meta.is_implicit_VR = False

return file_meta


Expand Down Expand Up @@ -268,11 +264,13 @@ def pretty_element(elem: DataElement) -> str:
value = "\\".join([str(ii) for ii in elem.value])
value = f"[{value}]"
elif elem.VR == "SQ":
# Sequence elements
if elem.VM == 1:
value = f"(Sequence with {len(elem.value)} item)"
# Sequence elements always have a VM of 1
assert elem.VM == 1
length = len(elem.value)
if length == 1:
value = f"(Sequence with {length} item)"
else:
value = f"(Sequence with {len(elem.value)} items)"
value = f"(Sequence with {length} items)"

except Exception:
value = "(pynetdicom failed to beautify value)"
Expand Down
3 changes: 0 additions & 3 deletions pynetdicom/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,6 @@ def _get_dataset(self, attr: str, exc_msg: str) -> Dataset:
t_syntax.is_deflated,
)

ds.is_little_endian = t_syntax.is_little_endian
ds.is_implicit_VR = t_syntax.is_implicit_VR

# Store the decoded dataset in case its accessed again
self._decoded = ds
else:
Expand Down
51 changes: 30 additions & 21 deletions pynetdicom/tests/test_assoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1882,42 +1882,51 @@ def handle_store(event):
assert ds.is_little_endian
assert not ds.is_implicit_VR
assert ds.file_meta.TransferSyntaxUID == ExplicitVRLittleEndian
ds.is_implicit_VR = True
with caplog.at_level(logging.WARNING, logger="pynetdicom"):
status = assoc.send_c_store(ds)
assert status.Status == 0x0000

is_implicit_vr_warning = (
"'FileDataset.is_implicit_VR' will be removed in v4.0, set the "
"Transfer Syntax UID or use the 'implicit_vr' argument with "
r"FileDataset.save_as\(\) or dcmwrite\(\) instead"
)

is_little_endian_warning = (
"'FileDataset.is_little_endian' will be removed in v4.0, set the "
"Transfer Syntax UID or use the 'little_endian' argument with "
r"FileDataset.save_as\(\) or dcmwrite\(\) instead"
)

with pytest.warns(DeprecationWarning, match=is_implicit_vr_warning):
ds.is_implicit_VR = True

status = assoc.send_c_store(ds)
assert status.Status == 0x0000

with pytest.warns(DeprecationWarning, match=is_implicit_vr_warning):
ds.is_implicit_VR = False
with pytest.warns(DeprecationWarning, match=is_little_endian_warning):
ds.is_little_endian = False
status = assoc.send_c_store(ds)
assert status.Status == 0x0000

ds.is_implicit_VR = False
ds.is_little_endian = True
status = assoc.send_c_store(ds)
assert status.Status == 0x0000

with pytest.warns(DeprecationWarning, match=is_implicit_vr_warning):
ds.is_implicit_VR = False
with pytest.warns(DeprecationWarning, match=is_little_endian_warning):
ds.is_little_endian = True
ds.file_meta.TransferSyntaxUID = ImplicitVRLittleEndian
msg = (

encoding_mismatch_msg = (
"'dataset' is encoded as explicit VR little endian but the file "
r"meta has a \(0002,0010\) Transfer Syntax UID of 'Implicit VR "
"Little Endian' - please set an appropriate Transfer Syntax"
)
with pytest.raises(AttributeError, match=msg):
with pytest.raises(AttributeError, match=encoding_mismatch_msg):
status = assoc.send_c_store(ds)

assoc.release()
assert assoc.is_released
scp.shutdown()

assert (
"'dataset' is encoded as implicit VR little endian but the file "
"meta has a (0002,0010) Transfer Syntax UID of 'Explicit VR "
"Little Endian' - using 'Implicit VR Little Endian' instead"
) in caplog.text
assert (
"'dataset' is encoded as explicit VR big endian but the file "
"meta has a (0002,0010) Transfer Syntax UID of 'Explicit VR "
"Little Endian' - using 'Explicit VR Big Endian' instead"
) in caplog.text

# Regression tests
def test_no_send_mismatch(self):
"""Test sending a dataset with mismatched transfer syntax (206)."""
Expand Down
8 changes: 4 additions & 4 deletions pynetdicom/tests/test_dsutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def test_seq_empty(self):
ds = Dataset()
ds.EventCodeSequence = []
assert (
"(0008,2135) SQ (Sequence with 0 items) # 0"
"(0008,2135) SQ (Sequence with 0 items) # 1"
" EventCodeSequence"
) == pretty_element(ds["EventCodeSequence"])

Expand All @@ -440,7 +440,7 @@ def test_seq_vm_multi(self):
ds = Dataset()
ds.EventCodeSequence = [Dataset(), Dataset()]
assert (
"(0008,2135) SQ (Sequence with 2 items) # 2"
"(0008,2135) SQ (Sequence with 2 items) # 1"
" EventCodeSequence"
) == pretty_element(ds["EventCodeSequence"])

Expand Down Expand Up @@ -570,7 +570,7 @@ def test_sequence_empty(self):
"""Test using a dataset with an empty sequence."""
ref = [
"(0010,0010) PN [Citizen^Jan] # 1 PatientName",
"(0014,2002) SQ (Sequence with 0 items) # 0 EvaluatorSequence",
"(0014,2002) SQ (Sequence with 0 items) # 1 EvaluatorSequence",
"(7FE0,0010) OB (no value available) # 0 PixelData",
]
ds = Dataset()
Expand Down Expand Up @@ -608,7 +608,7 @@ def test_sequence_multi(self):
"""Test using a dataset with a sequence with multiple items."""
ref = [
"(0010,0010) PN [Citizen^Jan] # 1 PatientName",
"(0014,2002) SQ (Sequence with 3 items) # 3 EvaluatorSequence",
"(0014,2002) SQ (Sequence with 3 items) # 1 EvaluatorSequence",
" (Sequence item #1)",
" (0010,0020) LO (no value available) # 0 PatientID",
" (0010,0030) DA [20011201] # 1 PatientBirthDate",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ name = "pynetdicom"
readme = "README.rst"
version = "2.2.0.dev0"
requires-python = ">=3.10"
dependencies = ["pydicom >=2.4, <3"]
dependencies = ["pydicom >=3, <4"]

[project.urls]
documentation = "https://pydicom.github.io/pynetdicom"
Expand Down

0 comments on commit 523e8ed

Please sign in to comment.