null - Lua: String is nil after explicitly checking for nil -


i have made script patient data database.

it works first few hundreds of patients, @ random point error:

*** lua run error batchdicommove.lua:91: attempt compare nil string in 'dofile('batchdicommove.lua')'

even despite explicitly checking whether argument nil or not. furthermore when make changes in code (like adding empty line). error occur in place a. accessed.

what wrong?

-- execute script calling: dgate "--lua:dofile('batchdicommove.lua')"  -- mop: query=study|series move=study+studyinstanceuid -- gepacs_rsd: query=* move=series  inputfile       = 'patientlist.txt' srcaet          = 'nukalfa' destaet         = 'onco_pacs_rd' modalities      = {'ct','pt'} includestr      = {'standard','standard','ac'}  -- if non desired enter {} includeorand    = 'or'                          -- choose 'and', 'or' excludestr      = {'nac','ctac'}                -- if non desired enter {} excludeorand    = 'nor'                         -- choose 'neither', 'nor' select          = 'newest'                      -- choose 'newest', 'oldest', 'all' relativetotime  = 'before'                      -- choose 'before', 'after', 'exact'     line in io.lines(inputfile)     -- loop through patients      date = ''     date1 = ''     date2 = ''     stringsplit = string.find(line,' ')     if stringsplit == nil         ptid = line     else         ptid = string.sub(line,0,stringsplit-1)         date = string.sub(line,stringsplit+1)         if string.len(date) == 18             stringsplit = string.find(date,' ')             if stringsplit == nil                 date = ''             else                 date = ''                 date1 = string.sub(date,0,stringsplit-1)                 date2 = string.sub(line,stringsplit+1)             end         elseif string.len(date) ~= 9             date = ''         end     end     -- ptidalts ensures patient found nomater if '-' included in id or not     stringsplit = string.find(ptid,'-')     if stringsplit == nil         ptid = string.sub(ptid,0,7) .. '-' .. string.sub(ptid,8)     end     stringsplit = string.find(ptid,'-')     ptidalts = {ptid,string.sub(ptid,0,stringsplit-1) .. string.sub(ptid,stringsplit+1)}      print('  query: patient', ptidalts[1], 'from', srcaet, 'to', destaet)      -- loop have been added part of implementation of ptidalts     b = {}     key, ptid in ipairs(ptidalts)         key, modality in ipairs(modalities)              -- create query dicom move             q = newdicomobject()             q.patientid = ptid             q.modality = modality             -- values retrive should included in query             q.studyinstanceuid  = ''             q.seriesinstanceuid = ''             q.patientname = ''             q.seriesdescription = ''             q.studydate = ''              -- execute query infomation on patient data on source machine             = dicomquery(srcaet, 'series', q) -- sets queryretrievelevel @ call time             i=1,#a                  b[#b+1] = a[i-1]              end         end     end      -- remove unwanted resultes      c = {}     if date ~= ''         i, in ipairs(b)             if a.studydate ~= nil                 if relativetotime == 'exact'                     if a.studydate == date                         c[#c+1] =                     end                 elseif relativetotime == 'before'                     if a.studydate <= date                         c[#c+1] =                     end                 else                     if a.studydate >= date                         c[#c+1] =                     end                 end             end         end     elseif (date1 ~= '') , (date2 ~= '')         i, in ipairs(b)             if (a.studydate ~= nil) , (a.studydate >= date1) , (a.studydate <= date2)                 c[#c+1] =             end         end     else         c = b     end     b = c      c = {}     if #includestr ~= 0         key, in ipairs(b)             if a.seriesdescription ~= nil                 if includeorand == 'or'                     key, include in ipairs(includestr)                         if string.match(a.seriesdescription,include) ~= nil                             c[#c+1] =                             break                         end                     end                 else                     key, include in ipairs(includestr)                         if string.match(a.seriesdescription,include) == nil                             break                         end                         c[#c+1] =                     end                 end             end         end         b = c     end      c = {}     if #excludestr ~= 0         key, in ipairs(b)             if a.seriesdescription ~= nil                 if excludeorand == 'nor'                     key, exclude in ipairs(excludestr)                         if string.match(a.seriesdescription,exclude) ~= nil                             break                         end                         c[#c+1] =                     end                 else                     key, exclude in ipairs(excludestr)                         if string.match(a.seriesdescription,exclude) == nil                             c[#c+1] =                             break                         end                     end                 end             end         end         b = c     end      c = {}     if select == 'newest'         key, modality in ipairs(modalities)             i, in ipairs(b)                 if a.studydate ~= nil                     if c[key] == nil                         c[key] =                     elseif c[key].studydate < a.studydate                         c[key] =                     end                 end             end         end     elseif select == 'oldest'         key, modality in ipairs(modalities)             i, in ipairs(b)                 if a.studydate ~= nil                     if c[key] == nil                         c[key] =                     elseif c[key].studydate > a.studydate                         c[key] =                     end                 end             end         end     else         c = b     end     b = c      n = #b     print('  query results:', n)      key, in ipairs(b)         cmd = newdicomobject()         cmd.patientid = b.patientid         cmd.studyinstanceuid = b.studyinstanceuid         cmd.seriesinstanceuid = b.seriesinstanceuid          if srcaet == 'mop_scp'             cmd.queryretrievelevel = 'study' -- level supported mop dicom move             cmd.modality = b.modality         else             cmd.queryretrievelevel = 'series' -- tested on gepacs_rsd         end          -- execute move         --dicommove(srcaet, destaet, cmd);     end end print('  done.') 

there comparisons in file on line 90 , 94:

line 90: if a.studydate <= date line 94: if a.studydate >= date 

we can see a.studydate not nil because checked @ line 84. therefore, guess date nil.

another place on line 102:

if (a.studydate ~= nil) , (a.studydate >= date1) , (a.studydate <= date2) 

again, check date1 , date2 not nil.

in same vein, should check 'c[key].studydate' line 178.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -