Skip to content

Commit

Permalink
Merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
scaramallion committed Nov 25, 2024
2 parents f869515 + 37ccf38 commit ba13905
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 36 deletions.
15 changes: 11 additions & 4 deletions pynetdicom/association.py
Original file line number Diff line number Diff line change
Expand Up @@ -1892,10 +1892,17 @@ def send_c_store(
tsyntax.is_little_endian,
)
# `dataset` might also be created from scratch
ds_encoding = getattr(
dataset,
"original_encoding",
(dataset.is_implicit_VR, dataset.is_little_endian),
ds_encoding: tuple[bool | None, bool | None] = (
(
dataset.is_implicit_VR
if dataset.original_encoding[0] is None
else dataset.original_encoding[0]
),
(
dataset.is_little_endian
if dataset.original_encoding[1] is None
else dataset.original_encoding[1]
),
)
if None not in ds_encoding and ts_encoding != ds_encoding:
s = ("explicit VR", "implicit VR")[cast(bool, ds_encoding[0])]
Expand Down
11 changes: 5 additions & 6 deletions pynetdicom/dsutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def create_file_meta(
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
file_meta.set_original_encoding(False, True)

return file_meta

Expand Down Expand Up @@ -268,11 +267,11 @@ 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)"
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: 1 addition & 2 deletions pynetdicom/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,7 @@ 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
ds.set_original_encoding(t_syntax.is_implicit_VR, t_syntax.is_little_endian)

# Store the decoded dataset in case its accessed again
self._decoded = ds
Expand Down
37 changes: 18 additions & 19 deletions pynetdicom/tests/test_assoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pydicom import dcmread
from pydicom.dataset import Dataset, FileMetaDataset
from pydicom.uid import (
generate_uid,
ImplicitVRLittleEndian,
ExplicitVRLittleEndian,
JPEGBaseline8Bit,
Expand Down Expand Up @@ -1876,24 +1877,33 @@ def handle_store(event):
ae.add_requested_context(CTImageStorage, ImplicitVRLittleEndian)
ae.add_requested_context(CTImageStorage, ExplicitVRBigEndian)
assoc = ae.associate("localhost", 11112)

assert assoc.is_established

ds = dcmread(DATASET_PATH)
assert ds.is_little_endian
assert not ds.is_implicit_VR
assert ds.original_encoding == (False, True)
assert ds.file_meta.TransferSyntaxUID == ExplicitVRLittleEndian
ds.is_implicit_VR = True

with caplog.at_level(logging.WARNING, logger="pynetdicom"):
ds.set_original_encoding(True, True)
status = assoc.send_c_store(ds)
assert status.Status == 0x0000

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

ds.is_implicit_VR = False
ds.is_little_endian = True
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

ds.set_original_encoding(False, True)
ds.file_meta.TransferSyntaxUID = ImplicitVRLittleEndian
msg = (
"'dataset' is encoded as explicit VR little endian but the file "
Expand All @@ -1907,17 +1917,6 @@ def handle_store(event):
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 @@ -33,7 +33,7 @@ name = "pynetdicom"
readme = "README.rst"
version = "2.2.0.dev0"
requires-python = ">=3.10"
dependencies = ["pydicom >=3.0"]
dependencies = ["pydicom >=3, <4"]

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

0 comments on commit ba13905

Please sign in to comment.