Medlea

Docs /Command-Line Client

Scripting and Automation

The client is built to be used from scripts: results go to the standard output, messages to the error stream, and the exit status says whether everything worked.

Output

CommandStandard output
import-dicomone line: <patient-id> <event-id> <series-name>
import-dicom-batchone line per patient loaded: <name> <patient-id> <event-id> <series-name>
create-projectone line: <project-id> <device-id> <version-id>
create-project-batchone line per project created: <name> <project-id> <device-id> <version-id>
add-geometryone line: the new geometry’s ID
patientsone line per CT series: <patient-id> <event-id> <series-id> <patient name>
segmentone line per anatomy: <anatomy> <group> created or existing; with --airways, a last line airways lungs created or existing
anatomiesone line per anatomy: <anatomy> <group> <name> (- when it has no group)
download-stlone line per file written: <anatomy> <path> <triangles>
virtual-spirometryone line: <run> <FEV1 L> <FVC L> <PEF L/s> [folder]
download-spirometryone line per run saved, like virtual-spirometry
databasesone database name per line

Progress, summaries and errors are written to the error stream, so they never mix with the result lines. Add --json to get JSON instead:

climed-client import-dicom --name "John Doe" --series /data/cts/john_doe --json
{"ID": "<patient-id>", "EID": "<event-id>", "AID": "CTscan", "SID": "PRE"}

With import-dicom-batch --json you get one such object per patient, each with the patient’s name and a status of ok.

Exit status

Command012
import-dicom, create-projectcreatederror (and nothing left behind)one with that name already exists
import-dicom-batch, create-project-batchnothing failed (skipped ones do not count)at least one failed, the input was invalid, or the run was interrupted—
add-geometryaddederror—
segmentdone (groups already there count as done)error, failure, or stopped waiting—
download-stlevery file written or already thereat least one file failed, or the selection was invalid—
virtual-spirometry, download-spirometrydoneerror, failure, or stopped waiting—

segment has one more: 3 when a group could not be segmented in this scan (the lungs on a scan too short for the chest); the other groups of the same command are done.

Examples

Load one patient and keep its identifiers:

read PATIENT EVENT SERIES < <(climed-client import-dicom --name "John Doe" --series /data/cts/john_doe)
echo "created $PATIENT"

Load a folder every night and keep a record (the sign-in comes from environment variables):

# CLIMED_EMAIL and CLIMED_PASSWORD are set in the environment of the job
climed-client login
climed-client import-dicom-batch --root /data/incoming -d demo_db > loaded.txt 2> loaded.log
echo "exit status: $?"

Segment the lungs of every CT series of a database, then save their STL files. patients puts the name last, so a name with spaces stays whole:

climed-client patients -d demo_db | while read PATIENT EVENT SERIES NAME; do
  climed-client segment --patient "$PATIENT" --series "$SERIES" --group lungs \
    && climed-client download-stl --patient "$PATIENT" --series "$SERIES" --group lungs \
                                  --out "stl/$NAME/$SERIES"
done

Run a virtual spirometry and keep FEV1, FVC and PEF in a table:

climed-client virtual-spirometry --patient "John Doe" --out spiro >> spirometry.txt

Stop on the first problem in a larger script:

set -e
climed-client import-dicom-batch --manifest patients.csv --dry-run -d demo_db
climed-client import-dicom-batch --manifest patients.csv -d demo_db

A long batch outlives the one-hour sign-in: it is renewed between patients, as long as the sign-in came from login. A token passed with --token is not renewed.

Troubleshooting

MessageWhat to do
not logged inRun climed-client login
no server: run climed-client login or pass --api-urlYou are not signed in and gave no address: sign in, or add --api-url https://…
login refusedCheck email and password. After several wrong attempts the account is locked for 15 minutes
this account must change its passwordChange it in the web app, then sign in again
no instance is assigned to this accountAsk your administrator to assign you an instance
your instance is switched offAsk your administrator to start it
plain http is refusedUse an address that starts with https://
pass -d <database>Your account has several databases: choose one with -d
a patient named … already exists, a project named … already existsIt is already there. The client skips it and changes nothing
is not a STL or VTP fileProjects and geometries accept .stl and .vtp only
geometry not added (HTTP 403)The project is not yours (or not shared with you): check --project
… contains no files, … does not existFix the path in the folder or list, then run again
expected one series, the backend stored NA ZIP holds more than one series: split it, one series per patient
the Segment and Reconstruct module (segmentation) is not enabled, the Respirology module (respirology) is not enabledAsk your administrator to enable the module on your account
not enough credits: … needed, … availableBuy credits in the web app, then run the command again
the computing quota of your account is used upToo many runs at once, or the daily GPU time is used: wait the time shown, then run it again
lungs not segmented: insufficient_thorax_coverageThe scan does not cover enough of the chest for the lungs (exit status 3)
segmentation failed: … OutOfMemoryErrorThe server ran out of memory: try one group at a time, or ask your administrator
the series has no lungs anatomiesRun climed-client segment --group lungs first
--airways goes with --group lungsAdd --group lungs: the airways are searched inside the lobes
no airways after … sThe server may still be working: check later with climed-client anatomies --group lungs; if they never appear, ask your administrator
missing --age, --height, --weight, --sexThe patient record lacks them: pass them on the command line for a personalised breathing effort
no report.pdf: install the PDF extraInstall the client with [pdf] (see Virtual Spirometry)
patient not created (HTTP 401), project not created (HTTP 401)The sign-in expired (or a --token ran out): run climed-client login and run the same command again; patients already loaded are skipped