1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import os
- import json
- import re
- import sys
- import datetime
- import re
- fhome=os.path.expanduser('~')
- sys.path.insert(1,fhome+'/software/src/labkeyInterface')
- import labkeyInterface
- import labkeyDatabaseBrowser
- fconfig=os.path.join(fhome,'.labkey','network.json')
- net=labkeyInterface.labkeyInterface()
- net.init(fconfig)
- db=labkeyDatabaseBrowser.labkeyDB(net)
- i=0
- projectOrthanc='Orthanc/Database'
- projectIPNU='iPNUMMretro/Study'
- ds=db.selectRows(projectIPNU,'study','Imaging',[])
- varList={'CT':['startswith','CT%20WB'],'PETWB':['eq','PET%20WB'],
- 'PETWBUncorrected':['eq','PET%20WB%20Uncorrected'],
- 'Topogram':['startswith','Topogram']}
- i=0
- for row in ds['rows']:
- for var in varList:
- print('Filtering for {}/{}'.format(var,varList[var][1]))
- qfilter={}
- qfilter['variable']='seriesDescription'
- qfilter['value']=varList[var][1]
- qfilter['oper']=varList[var][0]
-
- qfilter1={}
- qfilter1['variable']='PatientId'
- qfilter1['value']=row['PatientId']
- qfilter1['oper']='eq'
- #don't have dates, so I have to poll
- qfilter2={}
- qfilter2['variable']='studyDate'
- qfilter2['oper']='dateeq'
- fdate=row['date']
- fdate=re.sub(r' (.*)$','',fdate)
- fdate=re.sub(r'/',r'-',fdate)
- qfilter2['value']=fdate
- tfilter=[qfilter,qfilter1,qfilter2]
- ds1=db.selectRows(projectOrthanc,'study','Imaging',tfilter)
- print('[{}][{}][{}]: {}'.format(\
- row['PatientId'],var,fdate,len(ds1['rows'])))
-
-
- for r1 in ds1['rows']:
- print("ID: {}, DESC: {}, DATE: {}".format(\
- r1['PatientId'],r1['seriesDescription'],r1['studyDate']))
- #print("Study date {}/{}".format(row['date'],r1['studyDate']))
-
- row[var]=len(ds1['rows'])
- if len(ds1['rows'])==1:
- row[var]=ds1['rows'][0]['orthancSeries']
- if len(ds1['rows'])>1:
- if var=='CT':
- varC=[r1['orthancSeries'] for r1 in ds1['rows']\
- if r1['seriesDescription'].find('fov')<0]
- if len(varC)==1:
- row[var]=varC[0]
-
- db.modifyRows('update',projectIPNU,'study','Imaging',[row])
-
- print("Done")
|