Background

In Tutorial #5F, we translated the Financial Code with the function translatefincodedb. In this tutorial, we will look at a simplified table lookup command.

First we will use the Help facility to get details of the lookup command we want to use:

  1. Choose Help | HL7Connect Script Reference | Index tab. You should get a screen like the following:

    Screen Shot

  2. In the Index Tab, look for the keyword "lookup". You should a have screen like the following:

    Screen Shot

  3. Choose TDBConnPool.Lookup. You will get a help screen like the following:

    Screen Shot

  4. We will now develop a new function called translatefincodedblookup that uses this function.

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 translatefincodedblookup(aEvent)

      fcodein  = uppercase(aEvent.message.hl7.element("PV1-20").AsString)
      fcodeout = kernel.GetDB("HL7Tutorial").Lookup("PASFinCodes", "Code", fcodein, "LISCode", "")
      if fcodeout = "" then
        fcodeout = fcodein
        LastErrorMessage = ""
        On Error Resume Next
        SendEmail "10.10.1.1",                                               +_
                  "HL7Tutorial Interface Error",                             +_
                  "myname@myplace.com",                                      +_
                  "myname@myplace.com",                                      +_
                  "PAS Financial Code " & fcodein & " is unknown"
        if LastErrorMessage <> "" then
           Kernel.WriteToLog DBG_WARNING, "SendEmail Error " & LastErrorMessage
        end if
      end if
      aEvent.message.hl7.element("PV1-20").AsString = fcodeout
      translatefincodedblookup = True
    end function
   
Javascript   
    function translatefincodedblookup(aEvent)
    {
      var fcodein;
      var fcodeout;

      fcodein  = uppercase(aEvent.message.hl7.element('PV1-20').AsString);
      fcodeout = kernel.GetDB('HL7Tutorial').Lookup('PASFinCodes', 'Code', fcodein, 'LISCode', '');
      if (fcodeout == '')
        {
        fcodeout = fcodein;
        try
          {
          SendEmail('10.10.1.1',
                    'HL7Tutorial Interface Error',
                    'myname@myplace.com',
                    'myname@myplace.com',
                    'PAS Financial Code "'+fcodein+' " unknown');
          }
        catch(e)
          {
          Kernel.WriteToLog(DBG_WARNING,'SendEmail - SCRIPT EXCEPTION: ' + LastErrorMessage);
          }
        };
      aEvent.message.hl7.element('PV1-20').AsString = fcodeout;
      return(true);
    }
   

Testing translatefincodedblookup

To test the updated translation code, take the following steps:

  1. Using testcase5.tci, test the new function translatefincodedblookup.
  2. Update the function translate defined in Tutorial #5E to call translatefincodedblookup rather than translatefincodedb, and test this works.


© Kestral Computing P/L 2000-2010.