Skip to content

Commit

Permalink
Use set_original_encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Oct 15, 2024
1 parent 32ef447 commit aefbb72
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
5 changes: 3 additions & 2 deletions pynetdicom/dsutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ 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.set_original_encoding(False, True)

return file_meta


Expand Down Expand Up @@ -264,8 +267,6 @@ def pretty_element(elem: DataElement) -> str:
value = "\\".join([str(ii) for ii in elem.value])
value = f"[{value}]"
elif elem.VR == "SQ":
# 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)"
Expand Down
2 changes: 2 additions & 0 deletions pynetdicom/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,8 @@ def _get_dataset(self, attr: str, exc_msg: str) -> Dataset:
t_syntax.is_deflated,
)

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
else:
Expand Down
21 changes: 6 additions & 15 deletions pynetdicom/tests/test_assoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1879,23 +1879,16 @@ def handle_store(event):
assoc = ae.associate("localhost", 11112)
assert assoc.is_established

ds = Dataset()
ds.SOPClassUID = CTImageStorage
ds.SOPInstanceUID = generate_uid()
file_meta = FileMetaDataset()
file_meta.TransferSyntaxUID = ExplicitVRLittleEndian
ds.file_meta = file_meta
ds = dcmread(DATASET_PATH)
assert ds.original_encoding == (False, True)
assert ds.file_meta.TransferSyntaxUID == ExplicitVRLittleEndian

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

with pytest.warns(DeprecationWarning):
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

Expand All @@ -1910,9 +1903,7 @@ def handle_store(event):
"Little Endian' - using 'Explicit VR Big Endian' instead"
) in caplog.text

with pytest.warns(DeprecationWarning):
ds.is_implicit_VR = False
ds.is_little_endian = True
ds.set_original_encoding(False, True)
ds.file_meta.TransferSyntaxUID = ImplicitVRLittleEndian
msg = (
"'dataset' is encoded as explicit VR little endian but the file "
Expand Down

0 comments on commit aefbb72

Please sign in to comment.