How to upload dicom images to XNAT using cURL

812 views Asked by At

I have the following script to upload dicom images to an XNAT instance. I would like to know if this is the correct way of doing it since is quite slow.

My data is structured as [someDir]/[patientID]/[sessionID]/scans/[scanName]/*.dcm

imageDir=$1
PROJECT=<projectId>
JSESSIONID=<cookie>

for patientDir in $(ls -d $imageDir/*/);
do 
    SUBJECT=$(basename ${patientDir##$imageDir})
    for session in $(ls -d $patientDir/*/)
    do
            SESSION=$(basename ${session##$patientDir})

            find $session -name "*.dcm" -exec curl  -H 'Content-Type: application/dicom' \
                                -X POST --cookie JSESSIONID=$JSESSIONID \ 
                                 "https://<XNAT URL>/data/services/import?inbody=true&PROJECT_ID=$PROJECT&SUBJECT_ID=$SUBJECT&EXPT_LABEL=$SESSION" \
                                --data-binary @'{}' \; 
    done
done
2

There are 2 answers

0
Juan On

This is a solution using zip files given by Chris Fahim. The data must be structured in the following manner: [patientID]/[sessionID]/scans/[scanName]/DICOM/*.dcm After the upload is done, the zip file will be uncompressed and mapped directly to the project, subject, session and scans.

curl -F "dest=/prearchive/projects/<projectId>" -F "import-handler=DICOM-zip" -F
"FILE=@$dcm" -u USERNAME:PASSWORD --insecure 
https://<xnat url>/data/services/import

I have a node app for xnat that can be used in the command line. xnat-rest

0
prototyp On

Also great instead of curl is the storescu command from the DCMTK package. The pkt is also available as deb pkt:

DCMTK includes a collection of libraries and applications for examining, constructing and converting DICOM image files, handling offline media, sending and receiving images over a network connection, as well as demonstrative image storage and worklist servers.

send recursive all dicom files via sorescu:

find . -name "*.dcm" -exec storescu -v --aetitle XNAT --call XNAT  ip.of.your.server 8104 {} \;