Want to download/retrive DICOM files to my local file system.

2,462 views
Skip to first unread message

Manoj Solanki

unread,
May 22, 2018, 6:11:48 AM5/22/18
to Orthanc Users

Thanks ORTHANC team for the valuable PACS server. 


I am very new to Medical terminologies and DICOM related task.

I have a requirement to download the DICOM images of ORTHANC server to my local machine file system from python. Currently, I am using one python library which is “pynetdicom3” but facing lots of issues. If you have any specific library or any sample code through which I can achieve my goal, please let me know.


Thanks in advance.

John Roberts

unread,
May 22, 2018, 5:51:11 PM5/22/18
to Orthanc Users
I've used python with the requests module to run Orthanc API requests against the server.

For example, you can request a particular study download as a zip archive:

            query = orthanc_url + '/studies/' + orthanc_study_id + '/archive'
            response_study = requests.get(query, verify=False, \
                                          auth=(orthanc_user, orthanc_password))
            if response_study.status_code != 200:
                print 'Problem retrieving study: ' + orthanc_study_id
                print response_study.status, response_study.reason
                continue
            print '   Retrieved: %s' % orthanc_study_id
            zip_content = response_study.content

I then use the io and zipfile modules to extract the DICOM:

            file_like_object = io.BytesIO(zip_content)
            zip_object = zipfile.ZipFile(file_like_object)
            for zip_name in zip_object.namelist():
                zip_object.extract(zip_name, some_destination_dir)

Note that the above snippets are cut/paste from working code.  I haven't confirmed that the above code works by itself.  Obviously, you need to define the variable values.  My Orthanc is behind an Apache proxy, so I have to use the auth option in requests to send a login and password.

John.

Manoj Solanki

unread,
May 23, 2018, 12:47:55 AM5/23/18
to Orthanc Users
Hi John,

Thanks for the help.

Actually, I need to connect with only "TCP/IP address" and "port number" as I may have many other PACS as well like "Conquest" etc. Currently, I am using following code snippets on "pynetdicom3" to fetch DICOM files but getting an error: "No accepted Presentation Context for 'dataset'". I am bit confused what should be the Presentation context for the Orthanc server.


Here is my code:

/**********************START******************************/

from pynetdicom3 import AE
from pydicom import read_file
from pydicom import Dataset
from pynetdicom3 import AE
from pynetdicom3 import StorageSOPClassList
from pynetdicom3 import QueryRetrieveSOPClassList
from pydicom.uid import UID

# The Verification SOP Class has a UID of 1.2.840.10008.1.1


# List of presentation context :
http://dicom.nema.org/medical/dicom/2014c/output/chtml/part02/sect_F.4.2.2.4.html Which presentation context I should use?

ct_storage_uid = UID('1.2.840.10008.1.1')
ae = AE(scu_sop_class=[ct_storage_uid])

# Try and associate with the peer AE
# Returns the Association thread
print('Requesting Association with the peer')
assoc = ae.associate("localhost", 4242)

print (assoc)

if assoc.is_established:
print('Association accepted by the peer')

# Creat a new DICOM dataset with the attributes to match against
# In this case match any patient's name at the PATIENT query
# level. See PS3.4 Annex C.6 for the complete list of possible
# attributes and query levels.
dataset = Dataset()
dataset.PatientID = '*'
dataset.QueryRetrieveLevel = "PATIENT"

# Send a DIMSE C-FIND request to the peer
# query_model is the Query/Retrieve Information Model to use
# and is one of 'W', 'P', 'S', 'O'
# 'W' - Modality Worklist (1.2.840.10008.5.1.4.31)
# 'P' - Patient Root (1.2.840.10008.5.1.4.1.2.1.1)
# 'S' - Study Root (1.2.840.10008.5.1.4.1.2.2.1)
# 'O' - Patient/Study Only (1.2.840.10008.5.1.4.1.2.3.1)
responses = assoc.send_c_get(dataset, query_model='P')


print ( responses)

for (status, dataset) in responses:
# While status is pending we should get the matching datasets
if status == 'Pending':
print(dataset)
elif status == 'Success':
print('C-FIND finished, releasing the association')
elif status == 'Cancel':
print('C-FIND cancelled, releasing the association')
elif status == 'Failure':
print('C-FIND failed, releasing the association')

# Release the association
assoc.release()


/***********************END********************************/


Thanks,
Manoj Solanki

Alain Mazy

unread,
May 24, 2018, 4:17:55 AM5/24/18
to Manoj Solanki, Orthanc Users
This is not a pynetdicom support forum !

FYI, you're actually using send_c_get, not send_c_find.  C-GET is not supported by Orthanc.
--

Alain Mazy / CTO 
a...@osimis.io / +32 494 31 67 27

Osimis

OSIMIS S.A. 
Rue bois Saint-Jean 15/1BE-4102 Seraing 
www.osimis.io

Twitter LinkedIn


PS

unread,
Jun 18, 2018, 10:28:37 AM6/18/18
to Orthanc Users
Hi Manoj, 

Were you able to solve your issue? I'm currently facing a similar problem

Alain Mazy

unread,
Jun 19, 2018, 4:04:38 AM6/19/18
to PS, Orthanc Users
As mentioned in another thread, instead of send_c_get, you should use send_c_move.
Reply all
Reply to author
Forward
0 new messages