loadPatient.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.dicomLoader=loadDicom.loadDicomLogic(self)
  22. self.dicomImporter=importDicom.importDicomLogic(self)
  23. self.dicomImporter.local=self.local
  24. self.dicomImporter.basePath=self.basePath
  25. self.dicomLoader.local=self.local
  26. self.dicomLoader.basePath=self.basePath
  27. self.project="EMBRACE/Studija"
  28. self.imagingDataset="ImagingVisitsManaged"
  29. self.idDataset="PopisneStevilke"
  30. self.dicomProject="Test/Transfer"
  31. self.dicomDataset="Imaging"
  32. self.dicomPath=self.dicomProject+'/%40files/dicom'
  33. #self.rtReader=slicer.vtkSlicerDicomRtReader()
  34. #start SSL/TLS configuration
  35. def setURIHandler(self, net):
  36. self.sNet=net
  37. def setLocal(self,basePath):
  38. self.dicomImporter.setLocal(basePath)
  39. self.dicomLoader.setLocal(basePath)
  40. def getOICode(self, label):
  41. filter=[]
  42. filterID={"variable":"EMBRACE_ID",
  43. "oper":"eq",
  44. "value":label}
  45. filter.append(filterID)
  46. fSet=self.sNet.filterDataset(self.project,self.idDataset,filter)
  47. try:
  48. row=fSet["rows"][0]
  49. except:
  50. print("OI code for {} not found").format(label)
  51. return None
  52. return row["OICode"]
  53. def load(self,label):
  54. #clear previous data
  55. debug=True
  56. loadDicom.clearNodes()
  57. dirUrl=self.project+"/@files"
  58. dir=dirUrl+'/'+label
  59. #load segmentations
  60. rs=dir+"/RS/DICOM";
  61. self.dicomLoader.load(self.sNet,rs)
  62. rsMatch='None'
  63. filter=[]
  64. filterID={"variable":"EMBRACE_ID",
  65. "oper":"eq",
  66. "value":label}
  67. filter.append(filterID)
  68. filterType={"variable":"Type",
  69. "oper":"eq",
  70. "value":"RS"}
  71. filter.append(filterType)
  72. fSet=self.sNet.filterDataset(self.project,self.dataset,filter)
  73. fData=fSet['rows']
  74. row=fData[0] #first match
  75. if row['rsMatch']==None:
  76. return
  77. if row['rsMatch']=='NONE':
  78. return
  79. dicomDir=dir+'/'+row['rsMatch']+'/DICOM'
  80. if debug:
  81. print "Loading {}".format(dicomDir)
  82. self.dicomLoader.load(self.sNet,dicomDir)
  83. def findEmbrace(self,embraceId,imageType):
  84. filter=[]
  85. filterID={"variable":"EMBRACE_ID",
  86. "oper":"eq",
  87. "value":embraceId}
  88. filter.append(filterID)
  89. filterType={"variable":"Type",
  90. "oper":"eq",
  91. "value":imageType}
  92. filter.append(filterType)
  93. fSet=self.sNet.filterDataset(self.project,self.imagingDataset,filter)
  94. try:
  95. seqNum=fSet["rows"][0]["pseudoTransverseID"]
  96. except:
  97. print("CT data for patient {} not found").format(label)
  98. return None
  99. OIcode=self.getOICode(embraceId)
  100. dicomFilter=[]
  101. filterID={"variable":"PatientId",
  102. "oper":"eq",
  103. "value":OIcode}
  104. dicomFilter.append(filterID)
  105. filterSeq={"variable":"SequenceNum",
  106. "oper":"eq",
  107. "value":str(seqNum)}
  108. dicomFilter.append(filterSeq)
  109. fSet=self.sNet.filterDataset(self.dicomProject,self.dicomDataset,dicomFilter)
  110. try:
  111. row=fSet['rows'][0]
  112. except:
  113. print("Dicom for patient {}/{} not found").format(label,OIcode)
  114. return None
  115. return {'Study':row['Study'],'Series':row['Series']}
  116. def loadCT(self,label):
  117. studySeries=self.findEmbrace(label,"CT")
  118. if studySeries==None:
  119. return
  120. relativePath=self.dicomPath+'/'+studySeries['Study']+'/'+studySeries['Series']
  121. dicomReadFilter={'seriesNumber':"SeriesLabel",
  122. 'studyInstanceUid':None,
  123. 'frameOfReferenceInstanceUid':None}
  124. return self.dicomImporter.loadVolumes(self.sNet,relativePath,dicomReadFilter)
  125. def loadCTRS(self,label):
  126. studySeries=self.findEmbrace(label,"CT-RS")
  127. if studySeries==None:
  128. return
  129. relativePath=self.dicomPath+'/'+studySeries['Study']+'/'+studySeries['Series']
  130. dicomReadFilter={'seriesNumber':"SeriesLabel",
  131. 'studyInstanceUid':None,
  132. 'frameOfReferenceInstanceUid':None}
  133. print("Loading segmentation: {}").format(relativePath)
  134. return self.dicomLoader.loadSegmentations(self.sNet,relativePath,dicomReadFilter)
  135. def loadDMR(self,label):
  136. #clear previous data
  137. debug=True
  138. dirUrl=self.project+"/@files"
  139. dir=dirUrl+'/'+label
  140. #load segmentations
  141. rs=dir+"/DMR/DICOM";
  142. dicomReadFilter={'seriesNumber':"SeriesLabel",
  143. 'sequenceName':"*tse2d1_3",
  144. 'percentPhaseFieldOfView':90,
  145. 'studyInstanceUid':None,
  146. 'frameOfReferenceInstanceUid':None}
  147. return self.dicomImporter.loadVolumes(self.sNet,rs,dicomReadFilter)