HL7 to Database

Mapping: MapData() parsing

MapData() is a custom function that the main() function uses to execute a specific task. In this case the task is mapping the message data to a table node tree structure (that will later be merged into our database).

To do this it uses the built-in functions hl7.parse{} and db.tables{}, that are supplied with Iguana. It also uses three custom functions, FilterMessage(), ProcessLab() and ProcessADT(); in much the same way that main() calls MapData().

How It Works

The code calls hl7.parse{} to parse the incoming HL7 messages, and then db.tables{} to create a table node tree to map the data into.

Note: For simplicity this code uses a single VMD file for the message structure and the table mapping, we recommend using separate VMD files.

About hl7.parse():

MapData() calls the hl7.parse() function, which is built into the Iguana Translator:

hl7.parse() parses the message data and stores the results in the Msg and Name variables.

It requires two parameters:

  • vmd, which specifies the VMD file to use when parsing (described below)
  • data, which specifies the variable that contains the message to be parsed

To use hl7.parse(), you must supply a VMD template file that defines the structure of the incoming messages. VMD files can be edited or created using Chameleon.

Note: The parameter variable Data that contains the message provided to the mapping script is usually passed as the second (data) parameter.

It has three return values:

  • The first return is the parsed message as a read-only HL7 node tree, which is loaded into the Msg variable
  • The second return is the name of the message type, which is loaded into the Name variable
  • The third return is a table of warnings, that we do not use in this example

Note: The second return is the name of the message definition in the VMD file that matches the current message.

Tip: The table of warnings from the third return can be useful to track problems with parsing messages. See Using the Warnings returned from hl7.parse{}.

In the annotation for the hl7.parse() function, you can display the structure of the parsed message. To do this, click the ADT link:

The segments of the parsed message appear in a popup window:

Each of these segments can be expanded to display its fields.

Note: For a detailed explanation of what annotations are and how they work, see Working With Annotations.

About db.tables():

MapData() also calls the db.tables() function, which is another built-in Iguana function:

db.tables() creates an empty record table node tree, which can be used as a parameter for conn:merge{}.
It requires two parameters:
  • vmd, which is the VMD file containing the table definitions matching your database
  • name, which is the name of the message type that was returned by hl7.parse()

It has one return value:

  • This return is an empty record table node tree (derived from the supplied VMD), which is loaded into the Out variable

Once the HL7 message has been mapped, we will use Out and conn:merge{} to merge the data into our database.

Next Step?

Now you understand the purpose of the MapData() function. Next we will examine how to filter out unknown messages using the FilterMessage() function.

Leave A Comment?