Skip to content

How to download a study from Orthanc using C-MOVE (PynetDICOM)? #907

@Karam897

Description

@Karam897

Hello,
I am new to pynetdicom and I want to download a study from orthanc installed on my device, but I always get the error" Move SCP Result: 0xC000 (Failure)."
What should I add or modify for it to work correctly?
I have another question when downloading the study, where is it stored and is it possible to link it to my database?
here is my code
I hope you can help @scaramallion

from pydicom.dataset import Dataset
from pynetdicom import AE, evt, StoragePresentationContexts, debug_logger
from pynetdicom.sop_class import PatientRootQueryRetrieveInformationModelMove

debug_logger()
def handle_store(event):
    """Handle a C-STORE service request"""
    # Nothing fancy, just write to DICOM File Format
    ds = event.dataset
    ds.file_meta = event.file_meta
    ds.save_as(ds.SOPInstanceUID, write_like_original=False)

    return 0x0000

# Bind our C-STORE handler
handlers = [(evt.EVT_C_STORE, handle_store)]

# Initialise the Application Entity
ae = AE()
ae.add_requested_context(PatientRootQueryRetrieveInformationModelMove)
ae.supported_contexts = StoragePresentationContexts

#OUR_STORE_SCP = b'PYNETDICOM'
OUR_STORE_SCP = b'ORTHANC'
#ip11120 = 4242
#ip11120 = 11120
ip11120 = 11112
#ip11112 = 11112
ip11112 = 4242
# Start our Storage SCP in non-blocking mode, listening on port 11120
ae.ae_title = OUR_STORE_SCP
scp = ae.start_server(('127.0.0.1', ip11120), block=False, evt_handlers=handlers)

# Create out identifier (query) dataset
# Fill out your query as appropriate
ds = Dataset()
ds.QueryRetrieveLevel = 'PATIENT'
ds.PatientID = '301'

# Associate with peer AE at IP 127.0.0.1 and port 11112
assoc = ae.associate('127.0.0.1', ip11112)
i = 0
if assoc.is_established:
    # Use the C-MOVE service to send the identifier
    responses = assoc.send_c_move(ds, OUR_STORE_SCP, PatientRootQueryRetrieveInformationModelMove)

    for (status, identifier) in responses:
        if status and identifier:
            i += 1
            print('##############################')
            print('C-FIND query status: 0x{0:04x}'.format(status.Status))
            print('status = ', status)
            print('type(status) = ', type(status))
            print('status.Status = ', status.Status)
            print('type(identifier) = ', type(identifier))
            print('identifier = ',identifier)
            print('status.keys()  = ', status.keys() )
            print('identifier.keys()  = ', identifier.keys() )
            print('status.items()  = ', status.items() )
            for elem in identifier.elements():
                print('elem = ', elem)
            # If the status is 'Pending' then identifier is the C-FIND response
            if status.Status in (0xff00, 0xff01):
                print(identifier)
            print('##############################')
        else:
            print('Connection timed out, was aborted or received invalid response')


# Release the association
    assoc.release()
else:
    print('Association rejected, aborted or never connected')

# Stop our Storage SCP
    scp.shutdown()

thanks for everyone

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions