Versions Compared

Key

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

...

Lua Code

Code Block
languagelua
-- Compare two msgIds and see if id1 > id2
local function compareMsgIds(id1, id2)
   local isBigger = false
   local id1List = id1:split("-")
   local id2List = id2:split("-")
   if id1List[1] > id2List[1] then 
      isBigger = true
   elseif id1List[1] == id2List[1] then
      if tonumber(id1List[2]) >= tonumber(id2List[2]) then
         isBigger = true
      end
   end
   return isBigger
end

-- The main function is the first function called from Iguana.
function main()
   -- 1) Define Queued Channel Name and Message Count 
   local CHANNEL_NAME = '01-FileHL7 to Database Socket4'
   local QUEUED_COUNT = 37
   local LOG_COUNT = 20 --Adjust QUERY COUNT if not all queued messages have been queried
   
   -- 2) Query Queued and Ignored Data Msg Messages
   local LogResults = net.http.post{
      url = 'http://localhost:6543/api_query',
      auth = {username = 'admin',password = 'password'},
      parameters = {
         source= CHANNEL_NAME,
         limit = LOG_COUNT,
         type="messages",
         deleted = 'false',
         reverse = true
      }, live=true
   }
   local logXML = xml.parse{data=LogResults}.export
   
   -- 3) Filter and validate only Queued Messages
   local filteredLogMsgs = {}
   for i= 1, logXML:childCount("message") do
      if logXML:child("message", i).type:nodeValue() == "Message" then
         table.insert(filteredLogMsgs, logXML:child("message", i))
      end
   end
   
   -- 4) Get last Processed Message
   LogResults = net.http.post{
      url = 'http://localhost:6543/log_browse_get_dequeue_position',
      auth = {username = 'admin',password = 'password'},
      body = "Source="..CHANNEL_NAME,
      live=true
   }
   logXML = json.parse{data=LogResults}
   local processedMsg = logXML[CHANNEL_NAME]
   local msgId = processedMsg.Date:gsub("/", "").."-"..processedMsg.Position
   trace(msgId)
   
   -- 5) Filter out processed Message
   local queuedMsgs = {}
   for i=1, #filteredLogMsgs do
      if compareMsgIds(msgId, filteredLogMsgs[i].message_id:nodeValue() ==) msgId then
         break
      else
         table.insert(queuedMsgs,filteredLogMsgs[i].data)
      end
   end
   
   -- 6) Validate queued messages
   trace(queuedMsgs)
   if #queuedMsgs ~= QUEUED_COUNT then
      error("Not all queued messages have been queried, increase LOG_COUNT")
   end
   trace(queuedMsgs)
end