|
@@ -16,36 +16,50 @@ sys.path.insert(0,setup['paths']['labkeyInterface'])
|
|
|
import labkeyInterface
|
|
|
import labkeyDatabaseBrowser
|
|
|
|
|
|
+sys.path.insert(0,setup['paths']['analysisInterface'])
|
|
|
+import analysisInterface
|
|
|
+
|
|
|
fconfig=os.path.join(fhome,'.labkey','network.json')
|
|
|
|
|
|
net=labkeyInterface.labkeyInterface()
|
|
|
net.init(fconfig)
|
|
|
db=labkeyDatabaseBrowser.labkeyDB(net)
|
|
|
+fb=labkeyFileBrowser.labkeyFileBrowser(net)
|
|
|
+
|
|
|
+parameterFile=sys.argv[1]
|
|
|
+runid=sys.argv[2];
|
|
|
+
|
|
|
+ana=analysisInterface.analysisInterface(db,fb,runid)
|
|
|
+ana.updateStatus(2)
|
|
|
+pars=ana.getParameters(parameterFile)
|
|
|
+
|
|
|
+if pars==None:
|
|
|
+ sys.exit()
|
|
|
+
|
|
|
|
|
|
|
|
|
i=0
|
|
|
#from orthancDatabase/Imaging dataset
|
|
|
-projectOrthanc='Orthanc/Database'
|
|
|
-inputDataset='Imaging'
|
|
|
+projectOrthanc=pars['Orthanc']['project']
|
|
|
+inputQuery=pars['Orthanc']['queryName']
|
|
|
+inputSchema=pars['Orthanc']['schemaName']
|
|
|
+inputParticipantField=pars['Orthanc']['participantField']
|
|
|
+
|
|
|
#to target project dataset
|
|
|
-projectStudy='iPNUMMretro/Study'
|
|
|
+projectStudy=pars['Database']['project']
|
|
|
+#'iPNUMMretro/Study'
|
|
|
#for prospective, set
|
|
|
-projectStudy='IPNUMMprospektiva/Study'
|
|
|
-outputDataset='Imaging1'
|
|
|
+#projectStudy='IPNUMMprospektiva/Study'
|
|
|
+outputQuery=pars['Database']['queryName']
|
|
|
+outputSchema=pars['Database']['schemaName']
|
|
|
#select patientId that are contained in the demographics dataset
|
|
|
-demographicDataset='ClinicalData'
|
|
|
-#for prospective
|
|
|
-demographicDataset='demographicData'
|
|
|
-
|
|
|
+listQuery=pars['Database']['listQuery']
|
|
|
+dbParticipantField=pars['Database']['participantField']
|
|
|
|
|
|
-orthancParticipantField='PatientId'
|
|
|
-participantField='PatientId'
|
|
|
-#for prospective
|
|
|
-participantField='ParticipantId'
|
|
|
|
|
|
#make a list of patients
|
|
|
-dsDemo=db.selectRows(projectStudy,'study',demographicDataset,[])
|
|
|
-patients=[row[participantField] for row in dsDemo['rows']]
|
|
|
+dsDemo=db.selectRows(projectStudy,outputSchema,listQuery,[])
|
|
|
+patients=[row[dbParticipantField] for row in dsDemo['rows']]
|
|
|
patients=list(set(patients))
|
|
|
|
|
|
patientListStr=""
|
|
@@ -55,15 +69,15 @@ for p in patients:
|
|
|
patientListStr+=p
|
|
|
|
|
|
|
|
|
-patientFilter={'variable':orthancParticipantField,
|
|
|
+patientFilter={'variable':inputParticipantField,
|
|
|
'value':patientListStr,'oper':'in'}
|
|
|
|
|
|
#takes orthanc as the baseline, selects from patient list
|
|
|
-ds=db.selectRows(projectOrthanc,'study',inputDataset,[patientFilter])
|
|
|
+ds=db.selectRows(projectOrthanc,inputSchema,inputQuery,[patientFilter])
|
|
|
|
|
|
|
|
|
#single entry for the patientId/dicomStudy pair
|
|
|
-selectVars={participantField:orthancParticipantField,\
|
|
|
+selectVars={dbParticipantField:inputParticipantField,\
|
|
|
'dicomStudy':'dicomStudy'}
|
|
|
|
|
|
dates=[datetime.datetime.strptime(row['studyDate'],'%Y/%m/%d %H:%M:%S') \
|
|
@@ -97,22 +111,22 @@ for j in range(len(dates)):
|
|
|
'value':row[selectVars[v]],'oper':'eq'})
|
|
|
|
|
|
#ds2 are all studies by patient from sorted dataset
|
|
|
- ds2=db.selectRows(projectStudy,'study',outputDataset,
|
|
|
- [{'variable':participantField,\
|
|
|
- 'value':row[orthancParticipantField],'oper':'eq'}])
|
|
|
+ ds2=db.selectRows(projectStudy,outputSchema,outputQuery,
|
|
|
+ [{'variable':dbParticipantField,\
|
|
|
+ 'value':row[inputParticipantField],'oper':'eq'}])
|
|
|
|
|
|
#ds1 is the matching row from output dataset
|
|
|
- ds1=db.selectRows(projectStudy,'study',outputDataset,filters)
|
|
|
+ ds1=db.selectRows(projectStudy,outputSchema,outputQuery,filters)
|
|
|
if len(ds1['rows'])>1:
|
|
|
print('ERROR: too many matches for {}/{}'.\
|
|
|
- format(row[orthancParticipantField],row['dicomStudy']))
|
|
|
+ format(row[inputParticipantField],row['dicomStudy']))
|
|
|
continue
|
|
|
|
|
|
mode='update'
|
|
|
outRow={}
|
|
|
if len(ds1['rows'])==0:
|
|
|
mode='insert'
|
|
|
- outRow[participantField]=row[orthancParticipantField]
|
|
|
+ outRow[dbParticipantField]=row[inputParticipantField]
|
|
|
|
|
|
#setting sequence number to length of already included studies
|
|
|
#sorted by date makes it historically incremental
|
|
@@ -125,7 +139,7 @@ for j in range(len(dates)):
|
|
|
outRow[outvar]=row['orthancSeries']
|
|
|
outRow['studyDate']=row['studyDate']
|
|
|
|
|
|
- status=db.modifyRows(mode,projectStudy,'study',outputDataset,[outRow])
|
|
|
+ status=db.modifyRows(mode,projectStudy,outputSchema,outputQuery,[outRow])
|
|
|
print('{}'.format(status))
|
|
|
if j==50:
|
|
|
break
|