Skip to content

c_store does not convert to big endian explicit #1053

@kwijk

Description

@kwijk

Describe the bug

Created an scu that on association offers the default 4 transfer syntaxes. The peer selects explicit big endian. But at cstore time pynetdicom does not convert the dataset to explicit big endian:

_File "pynetdicom\association.py", line 490, in get_valid_context
"ValueError: No presentation context for 'MR Image Storage' has been accepted by the peer with 'Explicit VR Little Endian' transfer syntax for the SCU role ".

ae = AE(ae_title="DICOM")
ae.add_requested_context(abstract_syntax='1.2.840.10008.5.1.4.1.1.4') 
ae.associae(...)  # association is accepted. peer chooses 'explicit big endian'

ds = some_dataset_in_little_endian_explicit  # e.g.  MR_small.dcm
assoc.send_c_store(dataset=ds)  # ValueError in get_valid_context

The low level association logs say:

  Context ID:        1 (Accepted) [_handlers.py:479]
    Abstract Syntax: =MR Image Storage [_handlers.py:479]
    Accepted SCP/SCU Role: Default [_handlers.py:479]
    Accepted Transfer Syntax: =Explicit VR Big Endian [_handlers.py:479]
Accepted Extended Negotiation: None [_handlers.py:479]
Accepted Asynchronous Operations Window Negotiation: None [_handlers.py:479]
User Identity Negotiation Response: None [_handlers.py:479]

Context ID:        1 (Proposed) [_handlers.py:902]
  Abstract Syntax: =MR Image Storage [_handlers.py:902]
  Proposed SCP/SCU Role: Default [_handlers.py:902]
  Proposed Transfer Syntaxes: [_handlers.py:902]
    =Implicit VR Little Endian [_handlers.py:902]
    =Explicit VR Little Endian [_handlers.py:902]
    =Deflated Explicit VR Little Endian [_handlers.py:902]
    =Explicit VR Big Endian [_handlers.py:902]
...
  Context ID:        1 (Accepted) [_handlers.py:479]
    Abstract Syntax: =MR Image Storage [_handlers.py:479]
    Accepted SCP/SCU Role: Default [_handlers.py:479]
    Accepted Transfer Syntax: =Explicit VR Big Endian [_handlers.py:479]
Accepted Extended Negotiation: None [_handlers.py:479]
Accepted Asynchronous Operations Window Negotiation: None [_handlers.py:479]
User Identity Negotiation Response: None [_handlers.py:479]
========================== END A-ASSOCIATE-AC PDU ========================== [_handlers.py:479]
Association Accepted [acse.py:518]

Expected behavior

I would expect pynetdicom to do the (little to big endian) conversion automatically.

To be more precise in class Association._get_valid_context there will be no match if a conversion from little_endian to big_endian needs to take place. I think this is unfortunate as in Association.send_c_store the call to encode would have worked fine when converting little endian to big endian. That is for me the following code works:

    ds_explicit_little_endian = pydicom.data.get_testdata_file("CT_small.dcm", read=True)
    assert False == ds_explicit_little_endian.is_implicit_VR
    assert True == ds_explicit_little_endian.is_little_endian

    from io import BytesIO
    from pynetdicom.dsutils import encode

    data = encode(ds=ds_explicit_little_endian, is_implicit_vr=False, is_little_endian=False, deflated=False)
    ds_explicit_big_endian = pydicom.dcmread(BytesIO(data), force=True)
    assert False == ds_explicit_big_endian.is_implicit_VR
    assert False == ds_explicit_big_endian.is_little_endian

Steps To Reproduce
See above

Your environment

Linux-6.16.8-arch3-1-x86_64-with-glibc2.42
Python 3.12.8 (main, Jan 2 2025, 10:00:11) [GCC 14.2.1 20240910]
pydicom 2.4.4
pynetdicom 2.1.0 (actually 2.1.1 according to pip show)

(I also suspect the issue to occur with latest pynetdicom 3.0.4, but could not verify)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions