HL7 to HL7

Use the diff module

Include the diff module:

require 'diff'

The Translator environment is very extensible. A nice example of this is the diff module which is included in the project.

To use it add this line of code

diff.Compare(Orig, Out)

just after the MSH function.

This is what you should see:

The function returns a table array of differences:

The function works by using the self-describing methods of the node tree structures to compare the original and the modified HL7 node tree. The code gives a powerful example of how the Translator’s graphical environment can be leveraged.

One good use for this module is for recreating mappings from a different integration technology. The diff.Compare() function makes it easy to see quickly see what is different and might need to be changed. It is also handy being able to tweak comparison code to ignore unimportant differences.

This is the up-to-date code:

require 'split'
require 'zsegment'
require 'diff'

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():StripLastReturns())
   CheckTransform(Data:StripLastReturns(), Copy:StripLastReturns())

   AlterMSH(Out.MSH)
   trace(Out)

   local Diff = diff.Compare(Orig:S(), Out:S(), 'transform.vmd')
   trace(Diff)

   local DataOut = Out:S()
   DataOut = zsegment.copyZSegments(Data, DataOut)
   DataOut = DataOut:StripLastReturns()
   trace(DataOut)
   queue.push{data = DataOut}
end

function AlterMSH(MSH)
   MSH[3][1] = 'Acme'
   MSH[4][1] = 'Lab'
   return MSH
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

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.