From 457a25b8eb8ea3b178ba080959333f976033e695 Mon Sep 17 00:00:00 2001 From: gacou54 Date: Tue, 5 Sep 2023 09:22:39 -0400 Subject: [PATCH 1/2] short modification for index --- docs/index.md | 54 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/docs/index.md b/docs/index.md index f266f0f..7254159 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3,19 +3,56 @@ # 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. -Python library that wraps the Orthanc REST API and facilitates the manipulation of data with several cool utilities. -What for ? -The aim of the PyOrthanc module is to easy use the Orthanc Dicom server API. +--- +Install PyOrthanc +```bash +pip install pyorthanc +``` +--- +Then use the client: +```python +import pyorthanc -It has access to the full available Orthanc API and get the useful return without dealing with http requests. +client = pyorthanc.Orthanc('https://demo.orthanc-server.com') +patient_ids = client.get_patients() +``` +Interact with connected modalities -It also allows you to find specifics series/studies/patients according to complex filters +```python +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 +```python +patients = pyorthanc.find_patients(client, {'PatientID': '*P001'}) +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() +``` ## [First steps](tutorial/quickstart.md#first-steps) -### [Requirements](tutorial/quickstart.md#requirements) -### [Installation](tutorial/quickstart.md#installation) ### [Getting started](tutorial/quickstart.md#getting-started) * [Import pyorthanc library](tutorial/quickstart.md#import-pyorthanc-library) * [Connect to Orthanc](tutorial/quickstart.md#connect-to-orthanc) @@ -25,14 +62,11 @@ It also allows you to find specifics series/studies/patients according to comple * [Query (C-Find) and Retrieve (C-Move) from remote modality:](tutorial/quickstart.md#query-c-find-and-retrieve-c-move-from-remote-modality) ### [Full basic examples](tutorial/quickstart.md#full-basic-examples) * [Access instance informations](tutorial/quickstart.md#access-instance-informations) -### [Some useful commands](tutorial/quickstart.md#some-useful-commands) -* [Docker commands](tutorial/quickstart.md#docker-commands) ### [Advanced examples](tutorial/advanced.md) * [Transfer data from a PACS to a Orthanc server](tutorial/advanced.md#transfer-data-from-a-pacs-to-a-orthanc-server) ### [Releases](releases/releases.md) * [Lastest release : 1.12.1](releases/releases.md#lastest-release-1121) * [Release 1.11.5](releases/releases.md#release-1115) -## [Contribute](contributing.md#contribute) ## [Contacts](contacts.md#contacts) * [Maintainers Team](contacts.md#maintainers-team) * [Useful links](contacts.md#useful-links) From c9354f698ff07367acdb31f83bb9129c0919d92d Mon Sep 17 00:00:00 2001 From: gacou54 Date: Tue, 5 Sep 2023 09:23:23 -0400 Subject: [PATCH 2/2] Stop instanciating an client at each example --- docs/tutorial/quickstart.md | 80 +++++-------------------------------- 1 file changed, 10 insertions(+), 70 deletions(-) diff --git a/docs/tutorial/quickstart.md b/docs/tutorial/quickstart.md index 2d69ac2..1e21320 100644 --- a/docs/tutorial/quickstart.md +++ b/docs/tutorial/quickstart.md @@ -1,68 +1,37 @@ # First steps -## Requirements - -- [x] Python3.8 - ## Installation - ```bash -python3 -m venv .venv -source .venv/bin/activate pip install pyorthanc ``` ## Getting started -### Import pyorthanc library -```python -import pyorthanc -``` - ### Connect to Orthanc Here are some quick how to examples to use pyorthanc ```python from pyorthanc import Orthanc -orthanc = Orthanc(url='http://localhost:8042/', - username='username', - password='password') +orthanc = Orthanc(url='http://localhost:8042/', username='orthanc', password='orthanc') ``` ### Upload DICOM files to Orthanc: - ```python -from pyorthanc import Orthanc - -orthanc = Orthanc(url='http://localhost:8042/', - username='username', - password='password') - with open('A_DICOM_INSTANCE_PATH.dcm', 'rb') as file: - orthanc.post_instances(file.read()) + orthanc.post_instances(file.read()) ``` ### Getting list of connected remote modalities: ```python -from pyorthanc import Orthanc - -orthanc = Orthanc(url='http://localhost:8042/', - username='username', - password='password') - -orthanc.get_modalities() +modalities = orthanc.get_modalities() ``` - ### Find and download patients according to criteria: - ```python -from pyorthanc import Orthanc, find_patients, retrieve_and_write_patients - -orthanc = Orthanc(url='https://demo.orthanc-server.com', username='', password='') +from pyorthanc import find_patients, retrieve_and_write_patients patients = find_patients( client=orthanc, query={'PatientName': 'COMUNIX'} # Optional: filter with pyorthanc.Series object ) -retrieve_and_write_patients(patients, '.') +retrieve_and_write_patients(patients, './patients_path') ``` ### Query (C-Find) and Retrieve (C-Move) from remote modality: @@ -87,54 +56,25 @@ modality.move(query_response['ID'], {'TargetAet': 'target_modality'}) #### Anonymize patient: ```python -from pyorthanc import Orthanc, Patient - -orthanc = Orthanc('http://localhost:8042', 'username', 'password') +from pyorthanc import Patient patient_identifier = orthanc.get_patients()[0] +patient = Patient(patient_identifier, orthanc) -anonymized_patient = Patient(patient_identifier, orthanc).anonymize( +anonymized_patient = patient.anonymize( keep=['PatientName'], # You can keep/remove/replace the DICOM tags you want replace={'PatientID': 'TheNewPatientID'}, remove=['ReferringPhysicianName'], force=True # Needed when changing PatientID/StudyInstanceUID/SeriesInstanceUID/SOPInstanceUID ) -# Or directly with -orthanc.post_patients_id_anonymize(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'} ``` ## Full basic examples Be sure that Orthanc is running. The default URL (if running locally) is `http://localhost:8042`. -Here is a list of examples to helps you getting started with pyorthanc +Here is a list of examples to helps you getting started with pyorthanc. -### Access instance informations +### Access instance information [Get instance informations](https://github.com/ylemarechal/pyorthanc-examples/tree/main/basic/access_informations) - -## Some useful commands - -### Docker commands -Start Orthanc -```bash -docker compose up -d -``` -Stop Orthanc -```bash -docker compose stop -``` -Restart Orthanc -```bash -docker compose restart -``` -Delete Orthanc container -```bash -docker compose down -``` \ No newline at end of file