linkOrthanc.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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%20WB'],'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. #don't have dates, so I have to poll
  35. qfilter2={}
  36. qfilter2['variable']='studyDate'
  37. qfilter2['oper']='dateeq'
  38. fdate=row['date']
  39. fdate=re.sub(r' (.*)$','',fdate)
  40. fdate=re.sub(r'/',r'-',fdate)
  41. qfilter2['value']=fdate
  42. tfilter=[qfilter,qfilter1,qfilter2]
  43. ds1=db.selectRows(projectOrthanc,'study','Imaging',tfilter)
  44. print('[{}][{}][{}]: {}'.format(\
  45. row['PatientId'],var,fdate,len(ds1['rows'])))
  46. for r1 in ds1['rows']:
  47. print("ID: {}, DESC: {}, DATE: {}".format(\
  48. r1['PatientId'],r1['seriesDescription'],r1['studyDate']))
  49. #print("Study date {}/{}".format(row['date'],r1['studyDate']))
  50. row[var]=len(ds1['rows'])
  51. if len(ds1['rows'])==1:
  52. row[var]=ds1['rows'][0]['orthancSeries']
  53. if len(ds1['rows'])>1:
  54. if var=='CT':
  55. varC=[r1['orthancSeries'] for r1 in ds1['rows']\
  56. if r1['seriesDescription'].find('fov')<0]
  57. if len(varC)==1:
  58. row[var]=varC[0]
  59. db.modifyRows('update',projectIPNU,'study','Imaging',[row])
  60. print("Done")