Advertisement
rherrick

DICOM remap import script

Nov 6th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.70 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Presumes the following environment variables are set:
  4. #
  5. # $SERVER
  6. # $PROJECT
  7. # $AETITLE
  8. # $AEPORT
  9. #
  10. # This also presumes that:
  11. #
  12. # * Every folder name within the current directory maps to a subject ID
  13. # * Every folder within the current directory contains only other folders or DICOM files
  14. # * Each imported session should be named $SUBJECT_MR1
  15. #
  16. # Any function beyond that will require customization, but this does demonstrate walking
  17. # a folder structure, finding all DICOM, anonymizing the data on the fly, and pushing the
  18. # DICOM data to the XNAT server.
  19.  
  20. function createIfDoesntExist {
  21.     URL=$1
  22.     RESPONSE=$(curl --write-out %{http_code} --silent --output /dev/null -X GET -u admin:admin $URL)
  23.     if [ "$RESPONSE" -eq "404" ]; then
  24.         echo Creating object for $URL
  25.         RESPONSE=$(curl --write-out %{http_code} --silent --output /dev/null -X PUT -u admin:admin $URL)
  26.         if [ "$RESPONSE" != "200" -a "$RESPONSE" != "201" ]; then
  27.             echo Something went wrong creating $URL, bailing out.
  28.             exit
  29.         fi
  30.     fi
  31. }
  32.  
  33. for SUBJECT in $(find . -mindepth 1 -maxdepth 1 -type d -printf "%P ")
  34. do
  35.  
  36.     createIfDoesntExist http://${SERVER}/data/projects/$PROJECT/subjects/$SUBJECT
  37.  
  38.     echo Working directory $SUBJECT
  39.     echo -e \(0008,1030\) := \""${PROJECT}"\" > script.das
  40.     echo \(0010,0010\) := \""${SUBJECT}"\" >> script.das
  41.     echo \(0010,0020\) := \""${SUBJECT}_MR1"\" >> script.das
  42.  
  43.     IMPORT=$(find $SUBJECT -mindepth 1 -maxdepth 1 -type d -printf "$SUBJECT/%P/ " | sed 's# #* #g')
  44.  
  45.     DicomRemap -d script.das -o dicom://$AETITLE@${SERVER}:$AEPORT/$AETITLE "$IMPORT"
  46.  
  47. done
  48.  
  49. # Clean up
  50. [ -e script.das ] && { rm script.das; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement