generateReport.py 1.2 KB

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