Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleLet's breakdown this example script:

If you’d like to try this out in the Translator, create a custom component and use the following files:

  • View file
    nameadt.vmd

  • View file
    namepatients.vdb

Code Block
function main(Data)
   local msg, name = hl7.parse{vmd='adt.vmd', data=Data}
   local outboundTable = db.tables{vdb='patients.vdb'}

   if name == 'ADT' then 
      processADT(outboundTable, msg)
   end 
end

function mapPatient(T, PID) 
   T.id        = PID[3][1]
   T.firstName = PID[5][2]
   T.lastName  = PID[5][1][1]
   T.birthdate = PID[7]
end 

function mapKin(T, NK1) 
   if not NK1:isNull() then
      T.firstName = NK1[2][2]
      T.lastName = NK1[2][1][1]
      T.relationship = NK1[3][1]
   end
end 

function processADT(T, msg) 
   for i=1, #msg.NK1 do
      mapPatient(T.Patients[1], msg.PID)
      mapKin(T.Kin[i], msg.NK1[i])
   end 
   trace(T)
end 

...

Expand
title3) Look at mapKin, notice we are checking if the optional NK1 segment exists before mapping

Using if statements and node:isNull(), we can add logic to say “if NK1 exists, (is not nulllnull), then map the following fields into the table.”

You can confirm the mappings by clicking on trace(T) in the annotations to see the resulting database Patient and Kin tables.

...