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)