Skip to main content

HL7ORD Library

The HL7ORD library provides the hl7.parseOutOfOrder function, which adds an extra layer of processing to the standard hl7.parse to handle segments that unexpectedly occur out of order. As a best practice, it is still best to construct a message definition based on the expected inbound messages and use the standard hl7.parse. In the event the upstream system randomly sends messages with segments out of order, however, this library can be used to parse those messages and retain those segments.

The hl7.parseOutOfOrder function performs a few key operations:

  1. Parses the raw message (standard hl7.parse)

  2. Checks for any segments that occur out of order (compared to the matching message definition)

  3. Reconstructs and re-parses the message if out of order segments were identified. This ensures segments that were out of order are correctly parsed without impacting the other message segments.

Since extra steps are required to reconstruct the message, it is best to use a protected call when in Production to skip any problematic messages:

-- Parse the potentially out of order message   
local Status, Msg, Name = pcall(hl7.parseOutOfOrder,{data=Data,vmd='MyVMD.vmd'})

-- Log the error message and skip the message
if not Status then
iguana.logError("Failed to parse and reorder the message:\n"..Msg)
return
end

Note: when processing large messages, a SQLite database will be automatically generated in the <working_dir>/sqlite_databases/ folder to facilitate the message reconstruction process.