Overview

In Tutorial #5A, the requirement to translate the PID segment of the message was discussed. The identifier associated with the PAS system needs to be selected from the first component of the first occurrence of PID-3, and placed into PID-2. PID-3 is not to appear in the translated message. Our original message is:

MSH|^~\&|ADT1|MCM|LABADT|MCM|198808181126|SECURITY|ADT^A01|MSG00001|P|2.3.1|
EVN|A01|198808181123||
PID|1||123456^^^^MR^PAS~123456789^^^USSSA^SS~4321234^^^DL^NTA||JONES^WILLIAM^A^III||19610615|M||C|1200 N ELM STREET^^GREENSBORO^NC^27401-1020|GL|(91-9)379-1212|(919)271-3434||S||PATID12345001^2^M10^ADT1^AN^A|123456789|987654^NC|
NK1|1|JONES^BARBARA^K|WI^WIFE||||NK^NEXT OF KIN
PV1|1|I|2000^2012^01||||004777^LEBAUER^SIDNEY^J.|||SUR||||ADM|A0|||||PRIV||||||

In PID-3, we have the following three separate patient identifiers:

  1. 123456^^^^MR^PAS
  2. 123456789^^^USSSA^SS
  3. 4321234^^^DL^NTA

A script will be required that carries out the following steps (this is provided in the next section):

  1. Select field PID-3: 123456^^^^MR^PAS~123456789^^^USSSA^SS~4321234^^^DL^NTA
  2. Select the repeat with PAS as component 6: 123456^^^^MR^PAS
  3. Select component 1 as the identifier: 123456
  4. Place the identifier into PID-2.
  5. Clear PID-3.

The translated message will appear as follows:

MSH|^~\&|ADT1|MCM|LABADT|MCM|198808181126|SECURITY|ADT^A01|MSG00001|P|2.3.1|
EVN|A01|198808181123||
PID|1|123456|||JONES^WILLIAM^A^III||19610615|M||C|1200 N ELM STREET^^GREENSBORO^NC^27401-1020|GL|(91-9)379-1212|(919)271-3434||S||PATID12345001^2^M10^ADT1^AN^A|123456789|987654^NC|
NK1|1|JONES^BARBARA^K|WI^WIFE||||NK^NEXT OF KIN
PV1|1|I|2000^2012^01||||004777^LEBAUER^SIDNEY^J.|||SUR||||ADM|A0|||||PRIV||||||

Scripts

Select the script you are using then cut/paste the following code into your translate5.vbs OR translate5.js editor window.

Language    Script
VBScript  
    function translatepid(aEvent) 
      On Error Resume Next   ' All errors will be ignored
      rep = Nothing          ' If error occurs at next line
      set rep = aEvent.message.hl7.element("PID-3").ChooseRepeat("6", "PAS")
      if rep is Nothing then
        aEvent.UseReplyMessage = True
        aEvent.ReplyMessage.hl7.SetExceptionMessage "No Patient ID found by script", True
        SendEmail "10.10.1.1",                                            +_
                  "HL7Tutorial Interface Error",                          +_
                  "myname@myplace.com",                                   +_
                  "myname@myplace.com",                                   +_
                  "Unknown patient ID for Message " & aEvent.message.hl7.MsgID
        if LastErrorMessage <> "" then
           Kernel.WriteToLog DBG_WARNING, "SendEmail - SCRIPT EXCEPTION: " & LastErrorMessage
        end if
        translatepid = False
        exit function
      end if
      aEvent.message.hl7.element("PID-2").AsString = rep("1").AsString
      aEvent.message.hl7.element("PID-3").ClearAll
      translatepid = True
    end function
   
Javascript  
    function translatepid(aEvent) {
      var rep;
      rep = aEvent.message.hl7.element('PID-3').ChooseRepeat('6', 'PAS');
      if (rep == null) {
        aEvent.UseReplyMessage = true;
        aEvent.ReplyMessage.hl7.SetExceptionMessage('No Patient ID found by script', true);
        try {
          SendEmail('10.10.1.1',
                    'HL7Tutorial Interface Error',
                    'myname@myplace.com',
                    'myname@myplace.com',
                    'Unknown patient ID for Message '+aEvent.message.hl7.MsgID);
          }
        catch(e) {
          Kernel.WriteToLog(DBG_WARNING,'SendEmail - SCRIPT EXCEPTION: ' + LastErrorMessage);
          }
        return(false);
        };
      aEvent.message.hl7.element('PID-2-1').AsString = rep('1').AsString;
      aEvent.message.hl7.element('PID-3').ClearAll;
      return(true);
    }
   

Testing the script

We will now test the script. To do this take the following steps:

  1. Adjust the host name in the SendEmail procedure (1st parameter) to be the mail server on your site. If you do not have a mail server then you might like to comment out the email code and replace it with a WriteToLog command.
  2. Change the sendto and sendfrom email addresses (3rd and 4th parameters respectively) in the SendEmail procedure to your own email address.
  3. Change the procedure selected in testcase5.tci to translatepid.

It is suggested that you try the following scenarios:

  1. A translation that works. The existing HL7 message in testcase5.tci should be ok.
  2. A translation that does not work. Paste the following HL7 message in the HL7 Message window of testcase5.tci and retest. (Note: PAS is now changed to PAX in the PID segment.) If possible, check both a case where the SendEmail procedure is invoked, and a case where it is not.

       MSH|^~\&|ADT1|MCM|LABADT|MCM|198808181126|SECURITY|ADT^A01|MSG00001|P|2.3.1|EVN|A01|198808181123||
       PID|1||123456^^^^MR^PAX~123456789^^^USSSA^SS~4321234^^^DL^NTA||JONES^WILLIAM^A^III||19610615|M||C|1200 N ELM STREET^^GREENSBORO^NC^27401-1020|GL|(91-9)379-1212|(919)271-3434||S||PATID12345001^2^M10^ADT1^AN^A|123456789|987654^NC|
       NK1|1|JONES^BARBARA^K|WI^WIFE||||NK^NEXT OF KIN
       PV1|1|I|2000^2012^01||||004777^LEBAUER^SIDNEY^J.|||SUR||||ADM|A0|||||PRIV||||||
      


© Kestral Computing P/L 2000-2010.