First Steps: Building a Simple Interface

Map the Message

Now we are ready to start adding code that will fulfill the remaining interface requirements! In this step, we will fulfill the second requirement:

2. We only need to deliver the PID segment information for each patient.

To achieve this, we need to create an outgoing version of each message, then copy (or “map”) whatever incoming data we want to it. Because we only need to pass personal information to meet this requirement, we will only map the MSH and PID segments of each message (and discard the rest).

Why must we create a copy of our parsed messages? Although the hl7.parse{} function as a great way to organize incoming data, it only produces read-only results. In order to manipulate this information, we must create a blank, writable copy and map the parsed message’s data to it.

Let’s get started!

Step 1: Build the new, outgoing message

Add the following line of code to your script:

Screen Shot 2014-06-11 at 10.43.43

What is happening here? The hl7.message{} function is a nifty little tool that builds blank, writable HL7 node trees using the following parameters:

  • vmd = the VMD file to reference for the correct structure
  • name = the message type (to help choose the right structure noted in the VMD file)

Step 2: Map the MSH segment data to the new message

Add the following lines to your script:

Screen Shot 2014-06-11 at 10.45.44

Note: As you type, notice that Iguana’s handy auto-completion tool attempts to guess what you are trying to enter. To learn more about this powerful feature, check out this wiki section: Understanding Auto-Completion.

What is happening here? The mapTree() function copies information from one node tree to another. In this case, we only want to map MSH information. As such, we’ve used Lua syntax to indicate that we want to copy the incoming message’s MSH node (Msg.MSH) to our new message’s MSH node (Out.MSH).

Tip: Wondering about the trace() function? It is just a convenient way to inspect the value of a Lua variable. Curious about how it works? You can check out this link: Using trace() to view data for debugging.

Let’s examine the results! In accompanying annotation window, click on ADT in the trace() section:

Screen Shot 2014-06-11 at 10.47.12

As you can see, the MSH segment has now been copied into the new message:

Screen Shot 2014-06-11 at 10.50.17

Step 3: Map the PID segment data to the new message

Mapping the PID segment is very similar! Add the following line to your script:

Screen Shot 2014-06-11 at 11.00.06

Examine the results following the same steps mentioned above. As you can see, the PID segment has also been copied:

Screen Shot 2014-06-11 at 11.00.25

Sample Code

Here is a copy-and-paste version of the code so far:

function main(Data)
   -- (1) Parse the HL7 message
   local Msg, Name = hl7.parse{vmd = 'demo.vmd', data = Data}
   local Out = hl7.message{vmd = 'demo.vmd', name = Name}

   -- (2) Map the incoming message to the outgoing message
   Out.MSH:mapTree(Msg.MSH)
   Out.PID:mapTree(Msg.PID)
   trace(Out) 

   -- (3) Alter the MSH segment data

   -- (4) Modify the PID data

   -- (5) Push the outgoing message into the Iguana queue
end

Now that we have mapped the data, let’s tackle the next two interface requirements by modifying the MSH segment data.

Leave A Comment?

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