downloadPatient.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import os
  2. import sys
  3. import json
  4. import pathlib
  5. def main(configFile):
  6. with open(configFile) as f:
  7. config=json.load(f)
  8. fsetup=os.path.join(os.path.expanduser('~'),'.labkey','setup.json')
  9. with open(fsetup) as f:
  10. setup=json.load(f)
  11. sys.path.append(setup['paths']['labkeyInterface'])
  12. import labkeyInterface
  13. import labkeyFileBrowser
  14. net=labkeyInterface.labkeyInterface()
  15. fnet=os.path.join(os.path.expanduser('~'),'.labkey','network.json')
  16. net.init(fnet)
  17. fb=labkeyFileBrowser.labkeyFileBrowser(net)
  18. [files]=readPatient(fb,config['localDir'],config['project'],config['PatientId'])
  19. def readPatient(fb,localDir,project,patientId):
  20. rDir=fb.formatPathURL(project,'/'.join([patientId]))
  21. lDir=os.path.join(localDir,patientId)
  22. if not os.path.isdir(lDir):
  23. os.makedirs(lDir)
  24. ok,files=fb.listRemoteDir(rDir)
  25. locFiles=[]
  26. for f in files:
  27. print(f)
  28. p=pathlib.Path(f)
  29. localFile=os.path.join(lDir,p.name)
  30. fb.readFileToFile(f,localFile)
  31. locFiles.append(localFile)
  32. print('Done')
  33. return locFiles
  34. if __name__=='__main__':
  35. main(sys.argv[1])