Skip to content

Example PACS APIs calls with chrisclient programatic interface

Jorge edited this page Jan 14, 2025 · 4 revisions

chrisclient Python programmatic interface example

This example illustrates the use of the client's PACS APIs.

Preconditions

Clone some necessary repos in your work directory

mkdir ~/pacs_example
cd ~/pacs_example
git clone https://github.com/FNNDSC/SAG-anon.git
git clone https://github.com/FNNDSC/ChRIS_ultron_backEnd.git

Instantiate a CUBE instance:

cd ChRIS_ultron_backEnd
just

Upload the SAG-anon DICOM (.dcm) files to the dev Orthanc server:

  1. In a web browser go to http://localhost:8042/app/explorer.html#upload and click Select files to upload ... button
  2. Navigate to ~/pacs_example/SAG-anon folder and select all the .dcm files in there
  3. Click Start the upload button

Create a new Python3 virtual environment and install the ChRIS client

mkvirtualenv test
pip install -U python-chrisclient

Python programmatic interface example for the PACS APIs

Instantiate the client:

from chrisclient import client, utils

cl = client.Client('http://localhost:8000/api/v1/', 'cube', 'cube1234')

Update the PACS list:

hits = cl.get_pacs_list()

Retrieve the id of the MINICHRISORTHANC PACS:

hits = cl.get_pacs_list({'identifier': 'MINICHRISORTHANC'})
pacs_id = hits['data'][0]['id']

Send a PACS query request to the MINICHRISORTHANC PACS:

data = {'title': 'Query1', 'query': '{"SeriesInstanceUID": "1.3.12.2.1107.5.2.19.45152.2013030808061520200285270.0.0.0"}'}
pacs_query = cl.create_pacs_query(pacs_id, data)
pacs_query_id = pacs_query['id']

Keep calling cl.get_pacs_query_by_id until the PACS query's status attribute is succeeded or errored:

pacs_query = cl.get_pacs_query_by_id(pacs_query_id)

Decode the PACS query's result attribute if its status is succeeded:

pacs_query_result = utils.b64zipstr2json(pacs_query['result'])

Send a PACS retrieve request to the MINICHRISORTHANC` PACS:

pacs_retrieve = cl.create_pacs_retrieve(pacs_query_id)

Decode the PACS retrieve's result attribute if its status is not errored:

pacs_retrieve_result = utils.b64zipstr2json(pacs_retrieve['result'])