123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- 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.plugin=slicer.modules.dicomPlugins['DicomRtImportExportPlugin']()
- #self.volumePlugin=slicer.modules.dicomPlugins['DICOMScalarVolumePlugin']()
- 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)
|