loadPatient.py 5.5 KB

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