123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #basic python
- import os
- import subprocess
- import re
- import datetime
- import sys
- fhome=os.path.expanduser('~')
- sys.path.insert(1,fhome+'/software/src/labkeyInterface')
- import labkeyInterface
- import labkeyDatabaseBrowser
- def getValue(filename,tags):
- #extract value of tags (list of tags) from dcmdump-ed file
- #supply tags without braces ie. 0002,0008
- #rows is a list of lines from file
- with open(filename,"r") as f:
- out=f.read()
- lst=out.split('\n')
- for tag in tags.keys():
- tags[tag]=loadDicom.getTagValue(lst,tag)
- return True
- net=labkeyInterface.labkeyInterface()
- net.init(fhome+'/.labkey/network.json')
- db=labkeyDatabaseBrowser.labkeyDB(net)
- #by default uses .labkey/Remote.json configuration
- dicomBase='/data/dicom/database/dicom'
- project='IPNUMMretro/Study'
- schema='study'
- outputList='imageList'
- ds=db.selectRows(project,schema,'Imaging',{})
- dicomProject='Test/Transfer'
- dicomDataset='Imaging'
- for row in ds['rows']:
- print("ID: {}".format(row['PatientId']))
- nfilter=[{'variable':'PatientId','value':row['PatientId'],'oper':'eq'}]
- ds1=db.selectRows(dicomProject,'study',dicomDataset,nfilter)
- for fi in ds1['rows']:
- fdir=os.path.join(dicomBase,fi['Study'],fi['Series'])
- #print("Instance: {} ".format(fdir))
- files=os.listdir(fdir)
- for f in files:
- tfile=os.path.join(fdir,f)
- print("{}".format(tfile))
- #add files to orthanc via PACS
- #outText=subprocess.check_output([storescu,peer,port,tfile])
- oRow={'PatientId':row['PatientId'],'Series':fi['Series'],'Study':fi['Study'],'file':f,'statusFlag':'AVAILABLE'}
- ds2=db.selectRows(project,'lists',outputList,[{'variable':'file','value':f,'oper':'eq'}])
- if len(ds2['rows']):
- continue
- db.modifyRows('insert',project,'lists',outputList,[oRow])
-
- print("Done")
- quit()
|