Browse Source

Correcting populateImagingFromTransferList to post studyDate to labkey

NIX User 2 years ago
parent
commit
de0e000713
1 changed files with 15 additions and 26 deletions
  1. 15 26
      pythonScripts/populateImagingFromTransferList.py

+ 15 - 26
pythonScripts/populateImagingFromTransferList.py

@@ -59,6 +59,11 @@ def main(parameterFile):
     missingSchema=pars['Database']['missingImagesSchema']
     missingSchema=pars['Database']['missingImagesSchema']
     missingQuery=pars['Database']['missingImagesQuery']
     missingQuery=pars['Database']['missingImagesQuery']
 
 
+    #delete all rows from missingQuery (should be rebuilt for every run)
+    dsMissing=db.selectRows(projectStudy,missingSchema,missingQuery,[])
+    db.modifyRows('delete',projectStudy,missingSchema,missingQuery,dsMissing['rows'])
+
+
     #make a list of images from transferQuery
     #make a list of images from transferQuery
     dsImage=db.selectRows(projectStudy,outputSchema,transferQuery,[])
     dsImage=db.selectRows(projectStudy,outputSchema,transferQuery,[])
 
 
@@ -136,32 +141,15 @@ def main(parameterFile):
         rowsPET=[r for r in rowsMatch if r['seriesDescription']=='PET WB']
         rowsPET=[r for r in rowsMatch if r['seriesDescription']=='PET WB']
         print('entry[{}/{}] rowsPET: {}'.format(im[dbParticipantField],seqNum,rowsPET))
         print('entry[{}/{}] rowsPET: {}'.format(im[dbParticipantField],seqNum,rowsPET))
         
         
-        dataRow={}
-        if len(rowsCT)==1:
-            dataRow=rowsCT[0]
-        if len(dataRow)==0:
-            if len(rowsPET)==1:
-                dataRows=rowsPET[0]
-        
-
         #deal with erroneous outcomes (ie- no CT, more then 1 CT, no PET, more than 1 PET)
         #deal with erroneous outcomes (ie- no CT, more then 1 CT, no PET, more than 1 PET)
         if len(rowsPET)!=1 or len(rowsCT)!=1:
         if len(rowsPET)!=1 or len(rowsCT)!=1:
-            #standard spiel - find if already present; if so, skip, if not, add
-            imFilter={'variable':'imagingVisitId',
-                    'value':'{}'.format(im['imagingVisitId']),
-                    'oper':'eq'}
-            dsMissing=db.selectRows(projectStudy,missingSchema,\
-                    missingQuery,[idFilter,imFilter])
-
-            #already recorded
-            vals=[dbParticipantField,'imagingVisitId','imageDate']
             mode='insert'
             mode='insert'
-            if len(dsMissing['rows'])>0:
-                mode='update'
-                orow=dsMissing['rows'][0]
-            else:
-                orow={v:im[v] for v in vals}
+            #copy values en mass
+            vals=[dbParticipantField,'imagingVisitId','imageDate']
+            orow={v:im[v] for v in vals}
             orow['imageDateMismatch']=','.join(dates)
             orow['imageDateMismatch']=','.join(dates)
+            
+            #generate description of failure
             failDesc=''
             failDesc=''
             if len(rowsPET)==0:
             if len(rowsPET)==0:
                 failDesc+='[MISSSING PET]'
                 failDesc+='[MISSSING PET]'
@@ -172,6 +160,8 @@ def main(parameterFile):
             if len(rowsCT)>1:
             if len(rowsCT)>1:
                 failDesc+='[MULTIPLE CT]'
                 failDesc+='[MULTIPLE CT]'
             orow['failureDescription']=failDesc
             orow['failureDescription']=failDesc
+
+            #generate fail entries
             db.modifyRows(mode,projectStudy,missingSchema,\
             db.modifyRows(mode,projectStudy,missingSchema,\
                     missingQuery,[orow])
                     missingQuery,[orow])
             #don't break, but fill only for singular outcomes
             #don't break, but fill only for singular outcomes
@@ -192,19 +182,18 @@ def main(parameterFile):
         
         
             outRow[dbParticipantField]=im[dbParticipantField]
             outRow[dbParticipantField]=im[dbParticipantField]
             outRow['SequenceNum']=seqNum
             outRow['SequenceNum']=seqNum
-            if len(dataRow)==1:
-                outRow['dicomStudy']=dataRow['dicomStudy']
         
         
         else:
         else:
             #never happens if we check for sd1 before matches are found
             #never happens if we check for sd1 before matches are found
             outRow=ds1['rows'][0]
             outRow=ds1['rows'][0]
         
         
         if len(rowsPET)==1:    
         if len(rowsPET)==1:    
-            outRow['PET_orthancId']=rowsPET[0]['orthancSeries']
+            outRow['PETWB_orthancId']=rowsPET[0]['orthancSeries']
+            outRow['studyDate']=rowsPET[0]['studyDate']
         if len(rowsCT)==1:
         if len(rowsCT)==1:
             outRow['CT_orthancId']=rowsCT[0]['orthancSeries']
             outRow['CT_orthancId']=rowsCT[0]['orthancSeries']
+            outRow['studyDate']=rowsCT[0]['studyDate']
         if len(dataRow)==1:
         if len(dataRow)==1:
-            outRow['studyDate']=dataRow['studyDate']
         outRow['imagingVisitId']=im['imagingVisitId']
         outRow['imagingVisitId']=im['imagingVisitId']
         outRow['visitCode']='VISIT_'+str(im['imagingVisitId'])
         outRow['visitCode']='VISIT_'+str(im['imagingVisitId'])