diff --git a/pynetdicom/association.py b/pynetdicom/association.py index b8b366a8d..6cf059932 100644 --- a/pynetdicom/association.py +++ b/pynetdicom/association.py @@ -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])] diff --git a/pynetdicom/dsutils.py b/pynetdicom/dsutils.py index eff927a52..6b630b87b 100644 --- a/pynetdicom/dsutils.py +++ b/pynetdicom/dsutils.py @@ -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 @@ -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)" diff --git a/pynetdicom/events.py b/pynetdicom/events.py index 778fe5a25..2cc26af63 100644 --- a/pynetdicom/events.py +++ b/pynetdicom/events.py @@ -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 diff --git a/pynetdicom/tests/test_assoc.py b/pynetdicom/tests/test_assoc.py index c5aecace0..b9c797e6f 100644 --- a/pynetdicom/tests/test_assoc.py +++ b/pynetdicom/tests/test_assoc.py @@ -21,6 +21,7 @@ from pydicom import dcmread from pydicom.dataset import Dataset, FileMetaDataset from pydicom.uid import ( + generate_uid, ImplicitVRLittleEndian, ExplicitVRLittleEndian, JPEGBaseline8Bit, @@ -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 " @@ -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).""" diff --git a/pynetdicom/tests/test_dsutils.py b/pynetdicom/tests/test_dsutils.py index d8351fe28..8a3b09358 100644 --- a/pynetdicom/tests/test_dsutils.py +++ b/pynetdicom/tests/test_dsutils.py @@ -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"]) @@ -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"]) @@ -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() @@ -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", diff --git a/pyproject.toml b/pyproject.toml index 42fa8b092..66f032e36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"