12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import os
- import json
- import re
- import subprocess
- import shutil
- import sys
- import numpy
- import pydicom
- import copy
- shome=os.path.expanduser('~nixUser')
- sys.path.insert(1,shome+'/software/src/labkeyInterface')
- import labkeyInterface
- import labkeyDatabaseBrowser
- fhome=os.path.expanduser('~')
- fconfig=os.path.join(fhome,'.labkey','network.json')
- net=labkeyInterface.labkeyInterface()
- net.init(fconfig)
- db=labkeyDatabaseBrowser.labkeyDB(net)
- fb=labkeyFileBrowser.labkeyFileBrowser(net)
- tempDir=os.path.join(os.path.expanduser('~'),'temp')
- #also need merlin credentials
- fconfigMerlin=os.path.join(fhome,'.labkey','merlin.json')
- netMerlin=labkeyInterface.labkeyInterface()
- netMerlin.init(fconfigMerlin)
- dbMerlin=labkeyDatabaseBrowser.labkeyDB(netMerlin)
- fbMerlin=labkeyFileBrowser.labkeyFileBrowser(netMerlin)
- project='iPNUMMretro/Study'
- merlinProject=project
- #project='Orthanc/Database'
- anonymousDataset='AnonymousClinicalData'
- merlinDataset='ClinicalData'
- #getNixID
- studyData=db.selectRows(project,'study','Study',[])
- nixID=studyData['rows'][0]['nixID']
- ds=db.selectRows(project,'study',anonymousDataset,[])
- for row in ds['rows']:
- outRow=copy.deepcopy(row)
- outRow['PatientId']='{}-{}'.format(nixID,row['PatientId'])
- dbMerlin.modifyRows('insert',merlinProject,'study',merlinDataset,[outRow])
-
- #
- print('Done')
- quit()
- imagingDataset="AnonymousImaging1?"
- merlinImagingDataset="Imaging1"
- imageDir="preprocessedImages"
- ds=db.selectRows(project,'study',imagingDataset,[],)
- for row in ds['rows']:
- ofiles=[row['preprocessedCT'],row['preprocessedPET']]
- pCode=row['PatientCode']
- vCode=row['visitCode']
- for ofile in ofiles:
- xPath=[imageDir,pCode,vCode]
- xPath.append(ofile)
- path='/'.join(xPath)
- localPath=os.path.join(tempDir,ofile)
- remotePath=fb.formatPathURL(project,path)
- fb.readFileToFile(remotePath,localPath)
- merlinPath=fbMerlin.buildPathURL(merlinProject,xPath)
- fbMerlin.writeFileToFile(localPath,merlinPath)
- outRow=copy.deepcopy(row)
- outRow['PatientId']='{}-{}'.format(nixID,row['PatientId'])
- dbMerlin.modifyRows('insert',merlinProject,'study',merlinImagingDataset,[outRow])
-
|