Quellcode durchsuchen

Adding loadPatient as a loadable module

Andrej vor 3 Jahren
Ursprung
Commit
dce8889144
2 geänderte Dateien mit 106 neuen und 174 gelöschten Zeilen
  1. 106 0
      loadPatient.py
  2. 0 174
      slicerModules/loadPatient.py

+ 106 - 0
loadPatient.py

@@ -0,0 +1,106 @@
+import slicer
+import loadDicom
+import re
+import slicerNetwork
+import os
+import subprocess
+import importDicom
+
+#get access to importDicom and loadDicom at runtime
+
+       
+def getOICode(db, project, label):
+        idFilter={"variable":"EMBRACE_ID",
+            "oper":"eq",
+            "value":label}
+        fSet=db.selectRows(project,'PopisneStevilke',[idFilter])
+        try:
+            row=fSet["rows"][0]
+        except:
+            print("OI code for {} not found").format(label)
+            return None
+        return row["OICode"]
+
+
+def load(db,fb,fbDMR,iDicom,lDicom,project,label):
+
+    idFilter={'variable':'EMBRACE_ID','value':label,'oper':'eq'}
+    ctFilter={'variable':'type','value':'CT','oper':'eq'}
+    dsCT=db.selectRows(project,'study','ImagingVisitsManaged',[idFilter,ctFilter])
+    returnObj={}
+
+    try:
+        ctRow=dsCT['rows'][0]
+    except IndexError:
+        return returnObj
+    
+    oiCode=getIOCode(db,project,label)
+    
+    #load ct
+    seqNum=ctRow['pseudoTransverseID']
+    oiFilter={'variable':'PatientId','value':oiCode,'oper':'eq'}
+    sFilter={'variable':'SequenceNum','value':'{:.0f}'.format(seqNum),'oper':'eq'}
+    
+    dsDicom=db.selectRows('Test/Transfer','study','Imaging',[oiFilter,sFilter])
+    try:
+        rDicom=dsDicom['rows'][0]
+    except IndexError:
+        return returnObj
+
+    iPath=['dicom',rDicom['Study'],rDicom['Series']]
+    dicomReadFilter={'seriesNumber':"SeriesLabel",
+                        'studyInstanceUid':None,
+                        'frameOfReferenceInstanceUid':None}
+
+    ctVolumes=iDicom.loadVolumes(fb,'Test/Transfer',iPath,dicomReadFilter)
+    ctNode=ctVolumes[0]['node']
+    ctNode.SetName(label+'_CT')
+
+    #load dmr
+    #uses different server!!!
+    dmrFilter={'variable':'type','value':'DMR','oper':'eq'}
+    dsDMR=db.selectRows(project,'study','ImagingVisitsManaged',[idFilter,dmrFilter])
+    try:
+        dmrRow=dsDMR['rows'][0]
+    except IndexError:
+        return returnObj
+    
+    dmrName=dmrRow['Name']
+    iPath=['PRETVORJENE',dmrName,'DICOM']
+    dicomReadFilter={'seriesNumber':"SeriesLabel",
+                        'sequenceName':"*tse2d1_3",
+                        'percentPhaseFieldOfView':90,
+                        'studyInstanceUid':None,
+                        'frameOfReferenceInstanceUid':None}
+
+    dmrVolumes=iDicom.loadVolumes(fbDMR,project,iPath,dicomReadFilter)
+    dmrNode=dmrVolumes[0]['node']
+    dmrNode.SetName(label+'_DMR')
+
+    #load CT-RS
+    ctrsFilter={'variable':'type','value':'CT-RS','oper':'eq'}
+    dsCTRS=db.selectRows(project,'study','ImagingVisitsManaged',[idFilter,ctrsFilter])
+    try:
+        ctrsRow=dsCTRS['rows'][0]
+    except IndexError:
+        return returnObj
+    seqNum=ctrsRow['pseudoTransverseID']
+    sFilter={'variable':'SequenceNum','value':'{:.0f}'.format(seqNum),'oper':'eq'}
+    
+    dsDicomRT=db.selectRows('Test/Transfer','study','Imaging',[oiFilter,sFilter])
+    try:
+        rDicomRT=dsDicomRT['rows'][0]
+    except IndexError:
+        return returnObj
+
+    iPath=['dicom',rDicomRT['Study'],rDicomRT['Series']]
+    dicomReadFilter={'seriesNumber':"SeriesLabel",
+                       'studyInstanceUid':None,
+                       'frameOfReferenceInstanceUid':None}
+
+    rtSeg=lDicom.loadSegmentations(fb,'Test/Transfer',iPath,dicomReadFilter)
+    rtNode=rtSeg[0]['node']
+    rtNode.SetName(label+'_CTRS')
+
+    return {'CT':ctNode,'DMR':dmrNode,'CTRS':rtNode}
+

+ 0 - 174
slicerModules/loadPatient.py

@@ -1,174 +0,0 @@
-import slicer
-import loadDicom
-import re
-import slicerNetwork
-import os
-import subprocess
-import importDicom
-
-fValue=loadDicom.dicomValue
-dicomModify="/afs/f9.ijs.si/home/studen/software/install/"
-dicomModify+="dicomModify/bin/dicomModify"
-
-class loadPatient(slicer.ScriptedLoadableModule.ScriptedLoadableModule):
-    def __init__(self,parent):
-        slicer.ScriptedLoadableModule.ScriptedLoadableModule.__init__(self, parent)
-        self.className="loadPatient"
-        self.parent.title="loadPatient"
-        self.parent.categories = ["EMBRACE"]
-        self.parent.contributors = ["Andrej Studen (UL/FMF)"] 
-
-class loadPatientLogic(slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic):
-    def __init__(self,parent):
-       slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic.__init__(self, parent)
-
-       self.dicomLoader=loadDicom.loadDicomLogic(self)
-       self.dicomImporter=importDicom.importDicomLogic(self)
-       self.dicomImporter.local=self.local
-       self.dicomImporter.basePath=self.basePath
-       self.dicomLoader.local=self.local
-       self.dicomLoader.basePath=self.basePath
-       self.project="EMBRACE/Studija"
-       self.imagingDataset="ImagingVisitsManaged"
-       self.idDataset="PopisneStevilke"
-       self.dicomProject="Test/Transfer"
-       self.dicomDataset="Imaging"
-       self.dicomPath=self.dicomProject+'/%40files/dicom'
-
-
-       #self.rtReader=slicer.vtkSlicerDicomRtReader()
-
-       #start SSL/TLS configuration
-
-    def setURIHandler(self, net):
-        self.sNet=net
-
-    def setLocal(self,basePath):
-        self.dicomImporter.setLocal(basePath)
-        self.dicomLoader.setLocal(basePath)
-       
-    def getOICode(self, label):
-        filter=[]
-        filterID={"variable":"EMBRACE_ID",
-            "oper":"eq",
-            "value":label}
-        filter.append(filterID)
-        fSet=self.sNet.filterDataset(self.project,self.idDataset,filter)
-        try:
-            row=fSet["rows"][0]
-        except:
-            print("OI code for {} not found").format(label)
-            return None
-        return row["OICode"]
-
-
-    def load(self,label):
-        #clear previous data
-        debug=True
-        loadDicom.clearNodes()
-
-        dirUrl=self.project+"/@files"
-        dir=dirUrl+'/'+label
-        #load segmentations
-        rs=dir+"/RS/DICOM";
-        self.dicomLoader.load(self.sNet,rs)
-
-
-        rsMatch='None'
-        filter=[]
-        filterID={"variable":"EMBRACE_ID",
-            "oper":"eq",
-            "value":label}
-        filter.append(filterID)
-        filterType={"variable":"Type",
-                "oper":"eq",
-                "value":"RS"}
-        filter.append(filterType)
-        fSet=self.sNet.filterDataset(self.project,self.dataset,filter)
-        fData=fSet['rows']
-        row=fData[0] #first match
-
-        if row['rsMatch']==None:
-            return
-
-        if row['rsMatch']=='NONE':
-            return
-
-        dicomDir=dir+'/'+row['rsMatch']+'/DICOM'
-        if debug:
-            print "Loading {}".format(dicomDir)
-        self.dicomLoader.load(self.sNet,dicomDir)
-
-    def findEmbrace(self,embraceId,imageType):
-        filter=[]
-        filterID={"variable":"EMBRACE_ID",
-            "oper":"eq",
-            "value":embraceId}
-        filter.append(filterID)
-        filterType={"variable":"Type",
-                "oper":"eq",
-                "value":imageType}
-        filter.append(filterType)
-        fSet=self.sNet.filterDataset(self.project,self.imagingDataset,filter)
-        try:
-            seqNum=fSet["rows"][0]["pseudoTransverseID"]
-        except:
-            print("CT data for patient {} not found").format(label)
-            return None
-
-        OIcode=self.getOICode(embraceId)
-        dicomFilter=[]
-        filterID={"variable":"PatientId",
-            "oper":"eq",
-            "value":OIcode}
-        dicomFilter.append(filterID)
-        filterSeq={"variable":"SequenceNum",
-            "oper":"eq",
-            "value":str(seqNum)}
-        dicomFilter.append(filterSeq)
-        fSet=self.sNet.filterDataset(self.dicomProject,self.dicomDataset,dicomFilter)
-        try:
-            row=fSet['rows'][0]
-        except:
-            print("Dicom for patient {}/{} not found").format(label,OIcode)
-            return None
-        return {'Study':row['Study'],'Series':row['Series']}
-
-    def loadCT(self,label):
-        studySeries=self.findEmbrace(label,"CT")
-        if studySeries==None:
-            return
-        relativePath=self.dicomPath+'/'+studySeries['Study']+'/'+studySeries['Series']
-        dicomReadFilter={'seriesNumber':"SeriesLabel",
-                        'studyInstanceUid':None,
-                        'frameOfReferenceInstanceUid':None}
-        return self.dicomImporter.loadVolumes(self.sNet,relativePath,dicomReadFilter)
-
-    def loadCTRS(self,label):
-        studySeries=self.findEmbrace(label,"CT-RS")
-        if studySeries==None:
-            return
-        relativePath=self.dicomPath+'/'+studySeries['Study']+'/'+studySeries['Series']
-        dicomReadFilter={'seriesNumber':"SeriesLabel",
-                        'studyInstanceUid':None,
-                        'frameOfReferenceInstanceUid':None}
-        print("Loading segmentation: {}").format(relativePath)
-        return self.dicomLoader.loadSegmentations(self.sNet,relativePath,dicomReadFilter)
-
-
-    def loadDMR(self,label):
-        #clear previous data
-        debug=True
-
-        dirUrl=self.project+"/@files"
-        dir=dirUrl+'/'+label
-        #load segmentations
-        rs=dir+"/DMR/DICOM";
-
-        dicomReadFilter={'seriesNumber':"SeriesLabel",
-                        'sequenceName':"*tse2d1_3",
-                        'percentPhaseFieldOfView':90,
-                        'studyInstanceUid':None,
-                        'frameOfReferenceInstanceUid':None}
-
-        return self.dicomImporter.loadVolumes(self.sNet,rs,dicomReadFilter)