Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a straightforward index documentation and simplify quickstart #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 44 additions & 10 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
80 changes: 10 additions & 70 deletions docs/tutorial/quickstart.md
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
```
Loading