HL7 to HL7

Checking our Translation

The Translator is a very open platform. It doesn’t constrain you to a particular way of using it. For instance, we don’t have to use the built-in functions for parsing HL7. We can choose to use Lua code if it makes sense for the problem in hand.

In this section we’re going to do the following:

  • Add some code to check that our transformation using mapTree does not lose data, i.e., every field of data is being faithfully copied by mapTree
  • Explore error handling in Lua within Iguana
  • We will also learn more about how the functions we have used really work and their limitations

We need to add this function to the main workspace of our filter:

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

Then we can call it just after the mapTree call. We will take our Out node tree, convert it to a string and then compare it to the original Data message:
CheckTransform(Data, Out:S())

Intuitively they should be the same, but they are not.

The editor will most likely look like this:

So what is different?
We can open both the Orig and Copy arguments to CheckTransform and use the different views to really compare them. What is different? There are a couple of issues to look for, and both are symptoms of the same problem. This is a good time to test your own observation skills before going on to the next section and seeing the answer.

Hint: If you find scrolling the code over to the right is awkward a good trick is to put this code just after line 19:

trace(Orig)
trace(Copy)

This makes it easier to click and see the two strings.

This is what the code is so far if you need to paste it in:

function main(Data)
   local Orig = hl7.parse  {vmd='transform.vmd', data=Data}
   local Out =  hl7.message{vmd='transform.vmd', name=Orig:nodeName()}

   Out:mapTree(Orig)
   CheckTransform(Data, Out:S())

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

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

Leave A Comment?