Index 1 is out of bounds

If entire field, say PID[11], has no data,

PID|||583220^^^ADT1||DOE^J2|||M||AI||||||||20-98-3210|

then using auto-completion and selecting PID[11] and trying to reference any sub-field of it, results with referencing to non-existing index. Iguana attempts to resolve this empty (non-existing) reference and reports an error “Index 1 is out of bounds”

Below code can be written in Translator using auto-completion but gives error:

function MapPatient(T, PID)
  if PID[11][1]:isNull() then
         T.address = 'NA'
      else   
         T.address = PID[11][1]
      end
  return T
end

This code doesn’t give error:

function MapPatient(T, PID, PV1)
  if not PID[11].isNull() then
     if PID[11][1]:isNull() then
            T.address = 'NA'
         else   
            T.address = PID[11][1]
         end
  end
  return T
end

Which shows that test for null has to be performed at parent level, prior to referencing any of sub-fields.

Leave A Comment?