HL7 to HL7

Filtering Out Messages

Filtering out messages is easy: we just need to make sure we don’t push them into the queue. It’s also nice to log why a message is being filtered. If we use an iguana.logInfo() statement in we can put in some helpful information about the reason a message was filtered.

   if Orig:nodeName() == 'Catchall' then
      iguana.logInfo('Filtered '..Orig.MSH[9][1]..'^'..Orig.MSH[9][2])
      return
   end

If you are wondering what the colon syntax means see this page.

Now the editor should look like:

As you can see the Translator makes the path of execution of the script very clear.

Now do the following:

  1. Save the milestone
  2. Restart the channel

The channel can now process the transaction that had the problem. We can verify that this happened by clicking on the error and viewing the related messages:

It really gives you peace of mind as an integration engineer that you can see the correct handling of the message in question.

To make the error disappear you can either:

  1. Clear errors for the Sender channel from the dashboard
  2. Clear them from the control panel side bar for the channel properties
  3. Mark the error as deleted on the detail screen for the error

The next thing we will look at is the structure of the transform.vmd file to understand why the ORM^O01 message was identified as Catchall.

And if you need to catch up, here is the code:

require 'split'
require 'zsegment'

local function trace(a,b,c,d) return end

function main(Data)
   local Orig = hl7.parse  {vmd = 'transform.vmd', data = Data}

   if Orig:nodeName() == 'Catchall' then
      iguana.logInfo('Filtered '..Orig.MSH[9][1]..'^'..Orig.MSH[9][2])
      return
   end

   local Out  = hl7.message{vmd = 'transform.vmd', name = Orig:nodeName()}

   Out:mapTree(Orig)
   local Copy = zsegment.copyZSegments(Data, Out:S())
   CheckTransform(Data:StripLastReturns(), Copy:StripLastReturns())

   Out.MSH[3][1] = 'Acme'
   Out.MSH[4][1] = 'Lab'
   trace(Out)
   local DataOut = Out:S()
   DataOut = zsegment.copyZSegments(Data, DataOut)
   DataOut = DataOut:StripLastReturns()
   trace(DataOut)
   queue.push{data = DataOut}
end

function CheckTransform(Orig, Copy)
   if Orig ~= Copy then
      trace(Orig)
      trace(Copy)
      error('Copy of HL7 message does not match the original')
   end   
end

function string.StripLastReturns(S)
   -- strip return(s) "\r" & "\n" from the end of a string
   local i = #S
   while S:byte(i) == 10 or S:byte(i) == 13 do
      i = i - 1
   end
   return S:sub(1,i)
end