PyOrthanc
PyOrthanc is a python client for the Orthanc REST API, which fully wraps all the methods of the REST API. Additionally, it provides many utility functions to interact with an Orthanc instance.
Install PyOrthanc
pip install pyorthanc
Then use the client:
import pyorthanc
client = pyorthanc.Orthanc('https://demo.orthanc-server.com')
patient_ids = client.get_patients()
Interact with connected modalities
import pyorthanc
modality = pyorthanc.Modality(client, 'MY_MODALITY')
assert modality.echo()
# C-Find on modality
response = modality.query({'Level': 'Study', 'Query': {'PatientID': '*'}})
# C-Move to target modality
modality.move(response['ID'], {'TargetAet': 'target_modality'})
Find patients
patients = pyorthanc.find_patients(client, {'PatientName': '*Gabriel'})
for patient in patients:
patient.labels
patient.is_stable
patient.name
...
for study in patient.studies:
study.labels
study.date
...
for series in study.series:
...
for instance in series.instances:
pydicom_ds = instance.get_pydicom()
Use the orthanc_sdk
when developing with the Orthanc's Python Plugin
from pyorthanc import orthanc_sdk
def on_get(output: orthanc_sdk.RestOutput, *_, **__):
output.AnswerBuffer('ok', 'text/plain')
orthanc_sdk.RegisterRestCallback('/test', on_get)
First steps
Getting started
- Import pyorthanc library
- Connect to Orthanc
- Upload DICOM files to Orthanc:
- Getting list of connected remote modalities:
- Find and download patients according to criteria:
- Query (C-Find) and Retrieve (C-Move) from remote modality: