Skip to main content

Orthanc REST API python wrapper with additional utilities

Project description

PyOrthanc

Python library that wrap the Orthanc REST API and facilitate the manipulation of data.

Link to Orthanc web site: https://www.orthanc-server.com/

Notes: Please note that this is an early version of the wrapper (version < 1.0), therefore some methods description (and maybe name) may change because they don't describe adequately the behavior of the corresponding Orthanc REST API route. Also note that this librairy is still under development. If the description of an Orthanc method does not correspond to the planned behavior, please do an issue.

However, 'PyOrthanc' contains objects and functions that may be useful for anyone writing python script to interact with Orthanc.

Also note that tests (python setup.py test) might only work on a linux machine.

Installation

$ pip install pyorthanc

Or from the repository:

pip install git+https://gitlab.physmed.chudequebec.ca/gacou54/pyorthanc.git

Or, if you do not have git installed, clone the repository:

pip install -e pyorthanc.zip

Specific version

If you are looking for a specific version, lookout the version with the desired tag ar https://gitlab.physmed.chudequebec.ca/gacou54/pyorthanc/tags.

Example of usage

Be sure that Orthanc is running. The default URL (if running locally) is http://localhost:8042.

With Orthanc server:

from pyorthanc import Orthanc


orthanc = Orthanc('http://localhost:8042')
orthanc.setup_credentials('username', 'password')  # If needed

# To get patients identifier and main information
patients_identifiers = orthanc.get_patients()

for patient_identifier in patients_identifiers:
    patient_information = orthanc.get_patient_information(patient_identifier)


# To get patient's studies identifier and main information
a_patient_identifier = patients_identifiers[0]
studies_identifiers = orthanc.get_studies(a_patient_identifier)

for study_identifier in studies_identifiers:
    study_information = orthanc.get_studies_information(study_identifier)

Upload DICOM files to Orthanc:

from pyorthanc import Orthanc


orthanc = Orthanc('http://localhost:8042')
orthanc.setup_credentials('username', 'password')  # If needed

with open('A_DICOM_INSTANCE_PATH.dcm', 'rb') as file_handler:
    orthanc.post_instances(file_handler.read())

Getting list of remote modalities:

from pyorthanc import Orthanc


orthanc = Orthanc('http://localhost:8042')
orthanc.setup_credentials('username', 'password')  # If needed

orthanc.get_modalities()

Query (C-Find) and Retrieve (C-Move) from remote modality:

from pyorthanc import RemoteModality, Orthanc


remote_modality = RemoteModality(Orthanc('http://localhost:8042'), 'modality')
remote_modality.setup_credentials('username', 'password')  # If needed

# Query (C-Find) on modality
data = {'Level': 'Study', 'Query': {'PatientID': '*'}}
query_response = remote_modality.query(data=data)

# Retrieve (C-Move) results of query on a target modality (AET)
remote_modality.move(query_response['QUERY_ID'], 'target_modality')

Build a patient tree structure of all patients in Orthanc instance:

Each patient is a tree. Layers in each tree are Patient -> Study -> Series -> Instance.

from pyorthanc import Orthanc, build_patient_forest


patient_forest = build_patient_forest(
    Orthanc('http://localhost:8042/')
)    

for patient in patient_forest:
    patient_info = patient.get_main_information()

    for study in patient.get_studies():
        ...

Anonymize patient and get file:

from pyorthanc import Orthanc


orthanc = Orthanc('http://localhost:8042')
orthanc.setup_credentials('username', 'password')  # If needed

A_PATIENT_IDENTIFIER = orthanc.get_patients()[0]

orthanc.anonymize_patient(A_PATIENT_IDENTIFIER)

# result is: (you can retrieve DICOM file from ID)
# {'ID': 'dd41f2f1-24838e1e-f01746fc-9715072f-189eb0a2',
#  'Path': '/patients/dd41f2f1-24838e1e-f01746fc-9715072f-189eb0a2',
#  'PatientID': 'dd41f2f1-24838e1e-f01746fc-9715072f-189eb0a2',
#  'Type': 'Patient'}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyorthanc-0.2.6.tar.gz (88.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyorthanc-0.2.6-py3-none-any.whl (103.3 kB view details)

Uploaded Python 3

File details

Details for the file pyorthanc-0.2.6.tar.gz.

File metadata

  • Download URL: pyorthanc-0.2.6.tar.gz
  • Upload date:
  • Size: 88.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.6.0.post20191030 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.5

File hashes

Hashes for pyorthanc-0.2.6.tar.gz
Algorithm Hash digest
SHA256 fc5716037a489b8b146a14a427224b191aa24c0c5912d500791439f76f7fd1f1
MD5 a7124593fb2c895177f4a30205862d12
BLAKE2b-256 fac804007cc0258306328a4191584c18d96d87e0ff99e2b46b6521fc8c515835

See more details on using hashes here.

File details

Details for the file pyorthanc-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: pyorthanc-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 103.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.6.0.post20191030 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.5

File hashes

Hashes for pyorthanc-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 84e03d1d3960e2d3fc46a76219b6cc1ae3aeefc13fced6499104ef5565b49ecb
MD5 09719308af9821d0c4abe4fcdb6158ab
BLAKE2b-256 91d226e0343e759b0960f8e8b6e7aa6c750d1174e1e4d5767563f2236aa42daf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page