Code: Mapping HL7 to HL7

Introduction

Remember that the code we supply here is intended as a basis for you to adapt, rather than a boilerplate solution.

Please contact support at support@interfaceware.com if you need further help.

Sample Code [top]

This code uses the demo.vmd file which you can download and import into your project if needed.

Map a complete HL7 message:

function main(Data)
   -- Parse an HL7 message
   local Msg, Name = hl7.parse{vmd = 'demo.vmd', data = Data}
   local Out = hl7.message{vmd = 'demo.vmd', name = Name}
      
   -- Map a complete message
   Out:mapTree(Msg)
           
   -- remove fields that you don't want to transmit 
   -- (change the ID number to remove the desired field)
   Out.PID:remove(9)  -- Patient Alias
   Out.PID:remove(10) -- Race
      
   -- Push the outgoing message into the Iguana queue
   queue.push{data = Out}
end

Map part of an HL7 message:

function main(Data)
   -- Parse an HL7 message
   local Msg, Name = hl7.parse{vmd = 'demo.vmd', data = Data}
   local Out = hl7.message{vmd = 'demo.vmd', name = Name}
      
   -- Map part of a message
   Out.MSH:mapTree(Msg.MSH)
   Out.PID:mapTree(Msg.PID)
      
   -- remove fields that you don't want to transmit 
   -- (change the ID number to remove the desired field)
   Out.PID:remove(9)  -- Patient Alias
   Out.PID:remove(10) -- Race
      
   -- Push the outgoing message into the Iguana queue
   queue.push{data = Out}
end

Tip: For mapping a contiguous range of segments then using mapRange() is more concise than mapTree(), for example:

Using the code [top]

  • This code would usually be used in a Filter component script
  • Use your own VMD file
  • Uncomment the mapping method you want to use (and delete the rest)
  • To use X12 uncomment the X12 parsing code (and delete HL7 parsing code)
  • Use node:Remove() to delete any fields that you don’t want to transmit

Tip: The mapping functions will works with all node types, so you can adapt the code for other messages. However it is unlikely that you will need to use the node:MapTree() and node:MapRange() functions with other message types than HL7 and X12.

How it works [top]

The node:MapTree() function maps a single node, the node:MapRange() function maps a range of nodes. Both functions simply map the elements in a node sequentially. Because of this you should only use these functions to map messages with identical structures (identical fields and identical order).

If there are some fields that you do not wish to transmit then you can delete them using node:Remove(). When you are using an HL7 or X12 message this will empty the node, i.e., before removal “|xxx|” and after”||”.

For example if we map the complete message but don’t want to transmit the Race of the patient (field 10 in the PID segment):

Tip: The exact behaviour of the node:remove() function is customized to suit the type of node tree. Basically the HL7 and X12 node trees behave a little differently to conform to the HL7 standards.

See this FAQ for details: How node:remove() behaviour varies depending on node type.

Best Practices [top]

  • Do your mapping in the Filter component :
    • Sample data is available to make coding and debugging easier
      Note: Sample data is not available in a From Translator script
    • Allows you to do (optional) pre-processing in the source component (i.e., in a From LLP script)
    • Exception: When writing to a database do the mapping in a To Translator destination component
  • Refactoring code: In the other examples we recommend breaking the code up into several mapping functions, however there is little value to be gained for this example.
    Note: If you need to do more than just mapping in main() then refactoring could make sense.

What not to do [top]

  • Do not map use node:MapTree() and node:MapRange() to map between node trees with different structures. The mapTree() function copies data sequentially from the first source field to the first target field, and second to second, etc. This means you will end up with the target data mapped to incorrect fields (unless the target structure matches the source).
    This example mapping from HL7 to a Database Table node indicates what can go wrong:

    Warning: We strongly recommend that you do not use node:MapTree() and node:MapRange() to map between different types of node trees (even if they have the same structure). Two reasons: It makes the code obscure and difficult to understand, and it makes maintenance harder if either structure changes in the future (which is not uncommon).

Leave A Comment?

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