loadPatient.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import slicer
  2. import loadDicom
  3. import re
  4. import slicerNetwork
  5. import os
  6. import subprocess
  7. import importDicom
  8. #get access to importDicom and loadDicom at runtime
  9. def getOICode(db, project, label):
  10. idFilter={"variable":"EMBRACE_ID",
  11. "oper":"eq",
  12. "value":label}
  13. fSet=db.selectRows(project,'PopisneStevilke',[idFilter])
  14. try:
  15. row=fSet["rows"][0]
  16. except:
  17. print("OI code for {} not found").format(label)
  18. return None
  19. return row["OICode"]
  20. def load(db,fb,fbDMR,iDicom,lDicom,project,label):
  21. idFilter={'variable':'EMBRACE_ID','value':label,'oper':'eq'}
  22. ctFilter={'variable':'type','value':'CT','oper':'eq'}
  23. dsCT=db.selectRows(project,'study','ImagingVisitsManaged',[idFilter,ctFilter])
  24. returnObj={}
  25. try:
  26. ctRow=dsCT['rows'][0]
  27. except IndexError:
  28. return returnObj
  29. oiCode=getIOCode(db,project,label)
  30. #load ct
  31. seqNum=ctRow['pseudoTransverseID']
  32. oiFilter={'variable':'PatientId','value':oiCode,'oper':'eq'}
  33. sFilter={'variable':'SequenceNum','value':'{:.0f}'.format(seqNum),'oper':'eq'}
  34. dsDicom=db.selectRows('Test/Transfer','study','Imaging',[oiFilter,sFilter])
  35. try:
  36. rDicom=dsDicom['rows'][0]
  37. except IndexError:
  38. return returnObj
  39. iPath=['dicom',rDicom['Study'],rDicom['Series']]
  40. dicomReadFilter={'seriesNumber':"SeriesLabel",
  41. 'studyInstanceUid':None,
  42. 'frameOfReferenceInstanceUid':None}
  43. ctVolumes=iDicom.loadVolumes(fb,'Test/Transfer',iPath,dicomReadFilter)
  44. ctNode=ctVolumes[0]['node']
  45. ctNode.SetName(label+'_CT')
  46. #load dmr
  47. #uses different server!!!
  48. dmrFilter={'variable':'type','value':'DMR','oper':'eq'}
  49. dsDMR=db.selectRows(project,'study','ImagingVisitsManaged',[idFilter,dmrFilter])
  50. try:
  51. dmrRow=dsDMR['rows'][0]
  52. except IndexError:
  53. return returnObj
  54. dmrName=dmrRow['Name']
  55. iPath=['PRETVORJENE',dmrName,'DICOM']
  56. dicomReadFilter={'seriesNumber':"SeriesLabel",
  57. 'sequenceName':"*tse2d1_3",
  58. 'percentPhaseFieldOfView':90,
  59. 'studyInstanceUid':None,
  60. 'frameOfReferenceInstanceUid':None}
  61. dmrVolumes=iDicom.loadVolumes(fbDMR,project,iPath,dicomReadFilter)
  62. dmrNode=dmrVolumes[0]['node']
  63. dmrNode.SetName(label+'_DMR')
  64. #load CT-RS
  65. ctrsFilter={'variable':'type','value':'CT-RS','oper':'eq'}
  66. dsCTRS=db.selectRows(project,'study','ImagingVisitsManaged',[idFilter,ctrsFilter])
  67. try:
  68. ctrsRow=dsCTRS['rows'][0]
  69. except IndexError:
  70. return returnObj
  71. seqNum=ctrsRow['pseudoTransverseID']
  72. sFilter={'variable':'SequenceNum','value':'{:.0f}'.format(seqNum),'oper':'eq'}
  73. dsDicomRT=db.selectRows('Test/Transfer','study','Imaging',[oiFilter,sFilter])
  74. try:
  75. rDicomRT=dsDicomRT['rows'][0]
  76. except IndexError:
  77. return returnObj
  78. iPath=['dicom',rDicomRT['Study'],rDicomRT['Series']]
  79. dicomReadFilter={'seriesNumber':"SeriesLabel",
  80. 'studyInstanceUid':None,
  81. 'frameOfReferenceInstanceUid':None}
  82. rtSeg=lDicom.loadSegmentations(fb,'Test/Transfer',iPath,dicomReadFilter)
  83. rtNode=rtSeg[0]['node']
  84. rtNode.SetName(label+'_CTRS')
  85. return {'CT':ctNode,'DMR':dmrNode,'CTRS':rtNode}