Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Presumes the following environment variables are set:
- #
- # $SERVER
- # $PROJECT
- # $AETITLE
- # $AEPORT
- #
- # This also presumes that:
- #
- # * Every folder name within the current directory maps to a subject ID
- # * Every folder within the current directory contains only other folders or DICOM files
- # * Each imported session should be named $SUBJECT_MR1
- #
- # Any function beyond that will require customization, but this does demonstrate walking
- # a folder structure, finding all DICOM, anonymizing the data on the fly, and pushing the
- # DICOM data to the XNAT server.
- function createIfDoesntExist {
- URL=$1
- RESPONSE=$(curl --write-out %{http_code} --silent --output /dev/null -X GET -u admin:admin $URL)
- if [ "$RESPONSE" -eq "404" ]; then
- echo Creating object for $URL
- RESPONSE=$(curl --write-out %{http_code} --silent --output /dev/null -X PUT -u admin:admin $URL)
- if [ "$RESPONSE" != "200" -a "$RESPONSE" != "201" ]; then
- echo Something went wrong creating $URL, bailing out.
- exit
- fi
- fi
- }
- for SUBJECT in $(find . -mindepth 1 -maxdepth 1 -type d -printf "%P ")
- do
- createIfDoesntExist http://${SERVER}/data/projects/$PROJECT/subjects/$SUBJECT
- echo Working directory $SUBJECT
- echo -e \(0008,1030\) := \""${PROJECT}"\" > script.das
- echo \(0010,0010\) := \""${SUBJECT}"\" >> script.das
- echo \(0010,0020\) := \""${SUBJECT}_MR1"\" >> script.das
- IMPORT=$(find $SUBJECT -mindepth 1 -maxdepth 1 -type d -printf "$SUBJECT/%P/ " | sed 's# #* #g')
- DicomRemap -d script.das -o dicom://$AETITLE@${SERVER}:$AEPORT/$AETITLE "$IMPORT"
- done
- # Clean up
- [ -e script.das ] && { rm script.das; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement