Using trace() to view data for debugging

Tracing an HL7 message

In this example we have created an Out message and we want to check it its contents:

  • When it is created to confirm it is empty.

    Note: we did not need to use trace() as clicking on ADT at the end of line 6 will open the same message.

  • After we used mapTree() to copy the Msg to Out, trace() shows that the whole message was copied.
  • When we use mapRange() to copy part of Msg to Out2, trace() shows that only the first two segments were copied.

 

Here is the code if you want to try it out:

function main(Data)
   local Msg = hl7.parse{vmd = 'demo.vmd', data = Data}
   local Out = hl7.message{vmd = 'demo.vmd', name = Msg.MSH[9][1]:nodeValue()}
   -- the first trace() shows the empty message
   trace(Out)
   -- NOTE: you can also click ADT at the end of line 6 to view this message

   -- Map the all segments from the incoming message to the outgoing message
   Out:mapTree(Msg)
   trace(Out)

   -- However if you only want to see demographic info for patient
   local Out2 = hl7.message{vmd = 'demo.vmd', name = Msg.MSH[9][1]:nodeValue()}
   Out2:mapRange(Msg, 1, 2)
   trace(Out2)  
end

Leave A Comment?

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