Update a database table

Added by iNTERFACEWARE

How to update a database using data from an HL7 message (similar principles apply to other message types)

Source Code
function main(Data)
   -- Parse the HL7 message
   local Msg, Name = hl7.parse{vmd = 'example/demo.vmd', data = Data}
   
   -- (1) Connect to the database
   if not Conn or not Conn:check() then
      Conn = db.connect{
         api=db.SQLITE,
         name='test',
         user='',
         password='',
         live=true
      }
   end
   
   -- (2) Create update query string      
   local SqlUpdate =
   "   UPDATE patient SET"..
   "\n   LastName = '"..Msg.PID[5][1][1][1].."',"..
   "\n   GivenName = '"..Msg.PID[5][1][2].."',"..
   "\n   Ssn = '"..Msg.PID[19].."'"..
   "\n   WHERE Id = '"..Msg.PID[3][1][1].."'"
   
   -- (3) Update database
   Conn:execute{sql=SqlUpdate, live=true}
end
Description
How to update a database using data from an HL7 message (similar principles apply to other message types)