|
@@ -46,9 +46,16 @@ ofb=orthancFileBrowser.orthancFileBrowser(onet)
|
|
|
|
|
|
hi=0
|
|
hi=0
|
|
project='iPNUMMretro/Study'
|
|
project='iPNUMMretro/Study'
|
|
-dataset='Imaging'
|
|
|
|
|
|
+#for prospective, set
|
|
|
|
+project='IPNUMMprospektiva/Study'
|
|
|
|
+dataset='Imaging1'
|
|
tempBase=os.path.join(fhome,'temp')
|
|
tempBase=os.path.join(fhome,'temp')
|
|
|
|
|
|
|
|
+
|
|
|
|
+participantField='PatientId'
|
|
|
|
+#for prospective set
|
|
|
|
+participantField='ParticipantId'
|
|
|
|
+
|
|
#all images from database
|
|
#all images from database
|
|
ds=db.selectRows(project,'study',dataset,[])
|
|
ds=db.selectRows(project,'study',dataset,[])
|
|
#imageSelector={"CT":"CT","PET":"PETWB"};
|
|
#imageSelector={"CT":"CT","PET":"PETWB"};
|
|
@@ -59,14 +66,14 @@ imageResampledField={"CT":"ctResampled","PET":"petResampled"}
|
|
#use webdav to transfer file (even though it is localhost)
|
|
#use webdav to transfer file (even though it is localhost)
|
|
|
|
|
|
|
|
|
|
-def getPatientLabel(row):
|
|
|
|
- return row['PatientId'].replace('/','_')
|
|
|
|
|
|
+def getPatientLabel(row,participantField='PatientId'):
|
|
|
|
+ return row[participantField].replace('/','_')
|
|
|
|
|
|
def getVisitLabel(row):
|
|
def getVisitLabel(row):
|
|
return 'VISIT_'+str(int(row['SequenceNum']))
|
|
return 'VISIT_'+str(int(row['SequenceNum']))
|
|
|
|
|
|
-def getStudyLabel(row):
|
|
|
|
- return getPatientLabel(row)+'-'+getVisitLabel(row)
|
|
|
|
|
|
+def getStudyLabel(row,participantField='PatientId'):
|
|
|
|
+ return getPatientLabel(row,participantField)+'-'+getVisitLabel(row)
|
|
|
|
|
|
def runPreprocess_DM(matlab,generalCodes,niftiTools,studyDir):
|
|
def runPreprocess_DM(matlab,generalCodes,niftiTools,studyDir):
|
|
|
|
|
|
@@ -86,7 +93,8 @@ def runPreprocess_DM(matlab,generalCodes,niftiTools,studyDir):
|
|
return True
|
|
return True
|
|
|
|
|
|
|
|
|
|
-def getDicom(ofb,row,zipDir,rawDir,im,imageSelector):
|
|
|
|
|
|
+def getDicom(ofb,row,zipDir,rawDir,im,imageSelector,\
|
|
|
|
+ participantField='PatientId'):
|
|
|
|
|
|
#Load the dicom zip file and unzips it. If zip file is already at the expected path, it skips the loading step
|
|
#Load the dicom zip file and unzips it. If zip file is already at the expected path, it skips the loading step
|
|
|
|
|
|
@@ -97,7 +105,8 @@ def getDicom(ofb,row,zipDir,rawDir,im,imageSelector):
|
|
return False
|
|
return False
|
|
|
|
|
|
print("{}: {}".format(im,seriesId))
|
|
print("{}: {}".format(im,seriesId))
|
|
- fname=os.path.join(zipDir,getStudyLabel(row)+'_'+im+".zip");
|
|
|
|
|
|
+ fname=os.path.join(zipDir,\
|
|
|
|
+ getStudyLabel(row,participantField)+'_'+im+".zip");
|
|
|
|
|
|
#copy data from orthanc
|
|
#copy data from orthanc
|
|
if os.path.isfile(fname):
|
|
if os.path.isfile(fname):
|
|
@@ -127,8 +136,9 @@ def getDicom(ofb,row,zipDir,rawDir,im,imageSelector):
|
|
|
|
|
|
return True
|
|
return True
|
|
|
|
|
|
-def updateRow(project,dataset,row,imageResampledField,gzFileNames):
|
|
|
|
- row['patientCode']=getPatientLabel(row)
|
|
|
|
|
|
+def updateRow(project,dataset,row,imageResampledField,gzFileNames,\
|
|
|
|
+ participantField='PatientId'):
|
|
|
|
+ row['patientCode']=getPatientLabel(row,participantField)
|
|
row['visitCode']=getVisitLabel(row)
|
|
row['visitCode']=getVisitLabel(row)
|
|
for im in imageResampledField:
|
|
for im in imageResampledField:
|
|
row[imageResampledField[im]]=gzFileNames[im]
|
|
row[imageResampledField[im]]=gzFileNames[im]
|
|
@@ -142,14 +152,15 @@ for row in ds["rows"]:
|
|
#interesting files are processedDir/studyName_CT_notCropped_2mmVoxel.nii
|
|
#interesting files are processedDir/studyName_CT_notCropped_2mmVoxel.nii
|
|
#asn processedDir/studyName_PET_notCropped_2mmVoxel.nii
|
|
#asn processedDir/studyName_PET_notCropped_2mmVoxel.nii
|
|
volumeFileNames={im:\
|
|
volumeFileNames={im:\
|
|
- getStudyLabel(row)+'_'+im+
|
|
|
|
|
|
+ getStudyLabel(row,participantField)+'_'+im+
|
|
'_notCropped_2mmVoxel.nii'\
|
|
'_notCropped_2mmVoxel.nii'\
|
|
for im in imageSelector}
|
|
for im in imageSelector}
|
|
gzFileNames={im:f+".gz" \
|
|
gzFileNames={im:f+".gz" \
|
|
for (im,f) in volumeFileNames.items()}
|
|
for (im,f) in volumeFileNames.items()}
|
|
|
|
|
|
#build/check remote directory structure
|
|
#build/check remote directory structure
|
|
- remoteDir=fb.buildPathURL(project,['preprocessedImages',getPatientLabel(row),getVisitLabel(row)])
|
|
|
|
|
|
+ remoteDir=fb.buildPathURL(project,['preprocessedImages',\
|
|
|
|
+ getPatientLabel(row,participantField),getVisitLabel(row)])
|
|
|
|
|
|
gzRemoteFiles={im:remoteDir+'/'+f\
|
|
gzRemoteFiles={im:remoteDir+'/'+f\
|
|
for (im,f) in gzFileNames.items()}
|
|
for (im,f) in gzFileNames.items()}
|
|
@@ -164,12 +175,12 @@ for row in ds["rows"]:
|
|
if all(remoteFilePresent):
|
|
if all(remoteFilePresent):
|
|
print("Entry for row done.")
|
|
print("Entry for row done.")
|
|
updateRow(project,dataset,row,imageResampledField,\
|
|
updateRow(project,dataset,row,imageResampledField,\
|
|
- gzFileNames)
|
|
|
|
|
|
+ gzFileNames,participantField)
|
|
continue
|
|
continue
|
|
|
|
|
|
|
|
|
|
#setup the directory structure for preprocess_DM
|
|
#setup the directory structure for preprocess_DM
|
|
- studyDir=os.path.join(tempBase,getStudyLabel(row))
|
|
|
|
|
|
+ studyDir=os.path.join(tempBase,getStudyLabel(row,participantField))
|
|
if not os.path.isdir(studyDir):
|
|
if not os.path.isdir(studyDir):
|
|
os.mkdir(studyDir)
|
|
os.mkdir(studyDir)
|
|
|
|
|
|
@@ -198,7 +209,8 @@ for row in ds["rows"]:
|
|
|
|
|
|
for im in imageSelector:
|
|
for im in imageSelector:
|
|
#checks if raw files are already loaded
|
|
#checks if raw files are already loaded
|
|
- getDicom(ofb,row,zipDir,rawDir,im,imageSelector)
|
|
|
|
|
|
+ getDicom(ofb,row,zipDir,rawDir,im,imageSelector,\
|
|
|
|
+ participantField)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -224,7 +236,8 @@ for row in ds["rows"]:
|
|
|
|
|
|
|
|
|
|
#update row and let it know where the processed files are
|
|
#update row and let it know where the processed files are
|
|
- updateRow(project,dataset,row,imageResampledField,gzFileNames)
|
|
|
|
|
|
+ updateRow(project,dataset,row,imageResampledField,gzFileNames,\
|
|
|
|
+ participantField)
|
|
|
|
|
|
|
|
|
|
#cleanup
|
|
#cleanup
|