Selaa lähdekoodia

Removing syntax error in applyFilter, add useDicomModify flag to set loadDicom to use dicomModify script to correct incorrectly formed dicoms (EMBRACE mostly)

NIX User 5 vuotta sitten
vanhempi
commit
e3c6bba6c3
1 muutettua tiedostoa jossa 35 lisäystä ja 17 poistoa
  1. 35 17
      DICOMtools/loadDicom.py

+ 35 - 17
DICOMtools/loadDicom.py

@@ -96,7 +96,7 @@ class loadDicomLogic(slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic):
         slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic.__init__(self, parent)
 
         self.tag={
-              'SOPInstanceUID' : {'tag':"0008,0018",'VR','UI'},
+              'SOPInstanceUID' : {'tag':"0008,0018",'VR':'UI'},
               'studyDate': {'tag':"0008,0020",'VR':'DA'},
               'studyTime': {'tag':"0008,0030",'VR':'TM'},
               'seriesTime': {'tag':"0008,0031",'VR':'TM'},
@@ -168,6 +168,10 @@ class loadDicomLogic(slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic):
       #}
       #dicom.datadict.add_dict_entries(new_dict_items)
         self.local=False
+        self.useDicomModify=False
+
+    def enableDicomModify(self):
+        self.useDicomModify=True
 
     def setLocal(self,basePath):
         self.local=True
@@ -188,14 +192,19 @@ class loadDicomLogic(slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic):
         filelist=[]
         for f in dicomFiles:
                 localPath=self.getfile(sNet,f)
+                filelist.append(localPath)
+                if not self.useDicomModify:
+                    continue:
+                if dicomModify==None:
+                    continue
                 f0=localPath
                 f1=f0+"1"
-                if not dicomModify==None:
-                    try:
-                        subprocess.call(dicomModify+" "+f0+" "+f1+" && mv "+f1+" "+f0+";", shell=True)
-                    except OSError:
-                        print("dicomModify failed")
-                filelist.append(localPath)
+                try:
+                   subprocess.call(\
+                           dicomModify+" "+f0+" "+f1+" && mv "+f1+" "+f0+";", 
+                           shell=True)
+                except OSError:
+                   print("dicomModify failed")
 
         try:
             loadables=self.volumePlugin.examineForImport([filelist])
@@ -243,7 +252,7 @@ class loadDicomLogic(slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic):
         #if value is set, a match is attempted and result reported in return value
         #all filters should match for true output
 
-        return applyFilterFile(self,loadable.files[0],filter,nodeMetadata)
+        return self.applyFilterFile(loadable.files[0],filter,nodeMetadata)
     
     def applyFilterFile(self,file,filter,nodeMetadata,shell=False):
         #apply filter to file. Return true if file matches prescribed filter and
@@ -269,8 +278,8 @@ class loadDicomLogic(slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic):
 
             if not filter[key]==None:
                 if not fileValue==filter[key]:
-                    print("File {} failed for tag {}: {}/{}").format(
-                        file,key,fileValue,filter[key])
+                    #print("File {} failed for tag {}: {}/{}").format(\
+                    #    file,key,fileValue,filter[key])
                     filterOK=False
                     break
 
@@ -331,17 +340,26 @@ class loadDicomLogic(slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic):
         for loadable in loadables:
             #TODO check if it makes sense to load a particular loadable
 
-            print "Loading {} number of files: {}".format(loadable.name,len(loadable.files))
-            for f in loadable.files:
-                print "\t {}".format(f)
+            print "{}: Checking number of files: {}".format(\
+                    loadable.name,len(loadable.files))
+            
             #perform checks
-            nodeMetadata={}
-            filterOK=self.applyFilter(loadable,filter,nodeMetadata)
-
-            if not filterOK:
+            fileMetadata={}
+            loadable.files[:]=[f for f in loadable.files \
+                    if self.applyFilterFile(f,filter,fileMetadata)]
+            
+            if len(loadable.files)<1:
                 #skip this loadable
                 continue
 
+            print "{}: Final number of files: {}".format(\
+                    loadable.name,len(loadable.files))
+            
+            nodeMetadata={}
+            self.applyFilterFile(loadable.files[0],filter,nodeMetadata)
+
+
+
             volumeNode=self.volumePlugin.load(loadable,"DCMTK")
             if volumeNode != None:
                 vName='Series'+nodeMetadata['seriesLabel']