First Steps: Building a Simple Interface

Modify a Code

Now it’s time to satisfy our last requirement:

5. We need to use HL7 standard codes (“F”, “M” and “U”) for the ‘Sex’ field.

Using annotations to revisit the ‘Out’ variable’s node tree, you’ll notice that we have male represented as “male” and female as “female”. To correct this, we will use an if statement to substitute “F”, “M” or “U”. We will also copy the ‘Sex’ field into a variable to simplify this logic.

Note: This procedure can be adjusted to fix many common interface requirements (like capitalizing names, converting dates, or reformatting addresses).

Add the following lines of code to your script:

Screen Shot 2014-06-11 at 12.42.59

What is happening here? We created the variable Sexto contain whatever value is currently stored in the message’s ‘Sex’ field (Out.PID[8]). We use the nodeValue() function to convert a leaf node value (in this case, the message’s ‘Sex’ field value) into a text value. We then plug the results into an if/else statement that checks for “male” and “female”, then returns “M”, “F” or “U” as needed.

Let’s examine the results! In the corresponding annotations, we can see that “female” has been changed to “F” successfully:

Screen Shot 2014-06-11 at 12.44.33

Tip: Want to learn more about nodeValue()? Check out this article: Which string conversion should I use, S() or nodeValue()?

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

   -- (3) Alter the MSH segment data
   Out.MSH[3][1] = "First Steps"
   Out.MSH[4][1] = "Administration"

   -- (4) Modify the PID data
   -- modify sex coding to use HL7 standard codes "M", "F", & "U"
   local Sex = Out.PID[8]:nodeValue()
   if Sex == 'female' then
      Out.PID[8] = 'F'
   elseif Sex == 'male' then
      Out.PID[8] = 'M'
      Out.PID[8] = 'U' -- Unknown

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

The last thing we need to do to create a working channel is to push the data onto the Iguana Queue.

Leave A Comment?