loadPatient.py 3.3 KB

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