loadPatient.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import slicer
  2. import loadDicom
  3. import re
  4. import slicerNetwork
  5. import os
  6. import subprocess
  7. import importDicom
  8. fValue=loadDicom.dicomValue
  9. dicomModify="/afs/f9.ijs.si/home/studen/software/install/"
  10. dicomModify+="dicomModify/bin/dicomModify"
  11. class loadPatient(slicer.ScriptedLoadableModule.ScriptedLoadableModule):
  12. def __init__(self,parent):
  13. slicer.ScriptedLoadableModule.ScriptedLoadableModule.__init__(self, parent)
  14. self.className="loadPatient"
  15. self.parent.title="loadPatient"
  16. self.parent.categories = ["EMBRACE"]
  17. self.parent.contributors = ["Andrej Studen (UL/FMF)"]
  18. class loadPatientLogic(slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic):
  19. def __init__(self,parent):
  20. slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic.__init__(self, parent)
  21. #self.plugin=slicer.modules.dicomPlugins['DicomRtImportExportPlugin']()
  22. #self.volumePlugin=slicer.modules.dicomPlugins['DICOMScalarVolumePlugin']()
  23. self.dicomLoader=loadDicom.loadDicomLogic(self)
  24. self.dicomImporter=importDicom.importDicomLogic(self)
  25. self.dicomImporter.local=self.local
  26. self.dicomImporter.basePath=self.basePath
  27. self.dicomLoader.local=self.local
  28. self.dicomLoader.basePath=self.basePath
  29. self.project="EMBRACE/Studija"
  30. self.imagingDataset="ImagingVisitsManaged"
  31. self.idDataset="PopisneStevilke"
  32. self.dicomProject="Test/Transfer"
  33. self.dicomDataset="Imaging"
  34. self.dicomPath=self.dicomProject+'/%40files/dicom'
  35. #self.rtReader=slicer.vtkSlicerDicomRtReader()
  36. #start SSL/TLS configuration
  37. def setURIHandler(self, net):
  38. self.sNet=net
  39. def setLocal(self,basePath):
  40. self.dicomImporter.setLocal(basePath)
  41. self.dicomLoader.setLocal(basePath)
  42. def getOICode(self, label):
  43. filter=[]
  44. filterID={"variable":"EMBRACE_ID",
  45. "oper":"eq",
  46. "value":label}
  47. filter.append(filterID)
  48. fSet=self.sNet.filterDataset(self.project,self.idDataset,filter)
  49. try:
  50. row=fSet["rows"][0]
  51. except:
  52. print("OI code for {} not found").format(label)
  53. return None
  54. return row["OICode"]
  55. def load(self,label):
  56. #clear previous data
  57. debug=True
  58. loadDicom.clearNodes()
  59. dirUrl=self.project+"/@files"
  60. dir=dirUrl+'/'+label
  61. #load segmentations
  62. rs=dir+"/RS/DICOM";
  63. self.dicomLoader.load(self.sNet,rs)
  64. rsMatch='None'
  65. filter=[]
  66. filterID={"variable":"EMBRACE_ID",
  67. "oper":"eq",
  68. "value":label}
  69. filter.append(filterID)
  70. filterType={"variable":"Type",
  71. "oper":"eq",
  72. "value":"RS"}
  73. filter.append(filterType)
  74. fSet=self.sNet.filterDataset(self.project,self.dataset,filter)
  75. fData=fSet['rows']
  76. row=fData[0] #first match
  77. if row['rsMatch']==None:
  78. return
  79. if row['rsMatch']=='NONE':
  80. return
  81. dicomDir=dir+'/'+row['rsMatch']+'/DICOM'
  82. if debug:
  83. print "Loading {}".format(dicomDir)
  84. self.dicomLoader.load(self.sNet,dicomDir)
  85. def findEmbrace(self,embraceId,imageType):
  86. filter=[]
  87. filterID={"variable":"EMBRACE_ID",
  88. "oper":"eq",
  89. "value":embraceId}
  90. filter.append(filterID)
  91. filterType={"variable":"Type",
  92. "oper":"eq",
  93. "value":imageType}
  94. filter.append(filterType)
  95. fSet=self.sNet.filterDataset(self.project,self.imagingDataset,filter)
  96. try:
  97. seqNum=fSet["rows"][0]["pseudoTransverseID"]
  98. except:
  99. print("CT data for patient {} not found").format(label)
  100. return None
  101. OIcode=self.getOICode(embraceId)
  102. dicomFilter=[]
  103. filterID={"variable":"PatientId",
  104. "oper":"eq",
  105. "value":OIcode}
  106. dicomFilter.append(filterID)
  107. filterSeq={"variable":"SequenceNum",
  108. "oper":"eq",
  109. "value":str(seqNum)}
  110. dicomFilter.append(filterSeq)
  111. fSet=self.sNet.filterDataset(self.dicomProject,self.dicomDataset,dicomFilter)
  112. try:
  113. row=fSet['rows'][0]
  114. except:
  115. print("Dicom for patient {}/{} not found").format(label,OIcode)
  116. return None
  117. return {'Study':row['Study'],'Series':row['Series']}
  118. def loadCT(self,label):
  119. studySeries=self.findEmbrace(label,"CT")
  120. if studySeries==None:
  121. return
  122. relativePath=self.dicomPath+'/'+studySeries['Study']+'/'+studySeries['Series']
  123. dicomReadFilter={'seriesNumber':"SeriesLabel",
  124. 'studyInstanceUid':None,
  125. 'frameOfReferenceInstanceUid':None}
  126. return self.dicomImporter.loadVolumes(self.sNet,relativePath,dicomReadFilter)
  127. def loadCTRS(self,label):
  128. studySeries=self.findEmbrace(label,"CT-RS")
  129. if studySeries==None:
  130. return
  131. relativePath=self.dicomPath+'/'+studySeries['Study']+'/'+studySeries['Series']
  132. dicomReadFilter={'seriesNumber':"SeriesLabel",
  133. 'studyInstanceUid':None,
  134. 'frameOfReferenceInstanceUid':None}
  135. print("Loading segmentation: {}").format(relativePath)
  136. return self.dicomLoader.loadSegmentations(self.sNet,relativePath,dicomReadFilter)
  137. def loadDMR(self,label):
  138. #clear previous data
  139. debug=True
  140. dirUrl=self.project+"/@files"
  141. dir=dirUrl+'/'+label
  142. #load segmentations
  143. rs=dir+"/DMR/DICOM";
  144. dicomReadFilter={'seriesNumber':"SeriesLabel",
  145. 'sequenceName':"*tse2d1_3",
  146. 'percentPhaseFieldOfView':90,
  147. 'studyInstanceUid':None,
  148. 'frameOfReferenceInstanceUid':None}
  149. return self.dicomImporter.loadVolumes(self.sNet,rs,dicomReadFilter)