linkOrthanc.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import os
  2. import json
  3. import re
  4. import sys
  5. import datetime
  6. import re
  7. fhome=os.path.expanduser('~')
  8. sys.path.insert(1,fhome+'/software/src/labkeyInterface')
  9. import labkeyInterface
  10. import labkeyDatabaseBrowser
  11. fconfig=os.path.join(fhome,'.labkey','network.json')
  12. net=labkeyInterface.labkeyInterface()
  13. net.init(fconfig)
  14. db=labkeyDatabaseBrowser.labkeyDB(net)
  15. i=0
  16. projectOrthanc='Orthanc/Database'
  17. projectIPNU='iPNUMMretro/Study'
  18. ds=db.selectRows(projectIPNU,'study','Imaging',[])
  19. varList={'CT':['startswith','CT'],'PETWB':['eq','PET%20WB'],
  20. 'PETWBUncorrected':['eq','PET%20WB%20Uncorrected'],
  21. 'Topogram':['startswith','Topogram']}
  22. i=0
  23. for row in ds['rows']:
  24. for var in varList:
  25. print('Filtering for {}/{}'.format(var,varList[var][1]))
  26. qfilter={}
  27. qfilter['variable']='seriesDescription'
  28. qfilter['value']=varList[var][1]
  29. qfilter['oper']=varList[var][0]
  30. qfilter1={}
  31. qfilter1['variable']='PatientId'
  32. qfilter1['value']=row['PatientId']
  33. qfilter1['oper']='eq'
  34. qfilter2={}
  35. qfilter2['variable']='studyDate'
  36. qfilter2['oper']='dateeq'
  37. fdate=row['date']
  38. fdate=re.sub(r' (.*)$','',fdate)
  39. fdate=re.sub(r'/',r'-',fdate)
  40. qfilter2['value']=fdate
  41. tfilter=[qfilter,qfilter1,qfilter2]
  42. ds1=db.selectRows(projectOrthanc,'study','Imaging',tfilter)
  43. print('[{}][{}][{}]: {}'.format(\
  44. row['PatientId'],var,fdate,len(ds1['rows'])))
  45. for r1 in ds1['rows']:
  46. print("ID: {}, DESC: {}, DATE: {}".format(\
  47. r1['PatientId'],r1['seriesDescription'],r1['studyDate']))
  48. #print("Study date {}/{}".format(row['date'],r1['studyDate']))
  49. row[var]=len(ds1['rows'])
  50. if len(ds1['rows'])==1:
  51. row[var]=ds1['rows'][0]['orthancSeries']
  52. if len(ds1['rows'])>1:
  53. if var=='CT':
  54. varC=[r1['orthancSeries'] for r1 in ds1['rows']\
  55. if r1['seriesDescription'].find('fov')<0]
  56. if len(varC)==1:
  57. row[var]=varC[0]
  58. db.modifyRows('update',projectIPNU,'study','Imaging',[row])
  59. print("Done")