Procedure Oder HL7 results import process debugging "No Lab Match File"

Hi I am trying to figure out this debug message from the debug file.

 Retrieved and Saved File #1: FCC_{77774CD5-F9A9-4AFB-A72B-B34172941EA6}.txt
 No Lab Match File #1: Account: 
 unmatched file document deleted end of Run Debug Log is:
 Array
 (
     [select] => Array
         (
      )

     [match] => Array
      (
      )

     [Bon Secours/4/FCC_{77774CD5-F9A9-4AFB-A72B-B34172941EA6}.txt] => Array
      (
       )

     )

What is this being matched to? The lab’s NPI number?

/**
 * Look for a lab matching the given XCN field from some segment.
 *
 * @param array $seg MSH seg identifying a provider.
 * @return mixed        TRUE, or FALSE if no match.
 */
function match_lab(&$hl7, $send_acct, $lab_acct = '', $lab_app = '', $lab_npi = '')
{
    if (empty($hl7)) {
        return false;
    }
    $d0 = "\r";
    $d1 = substr($hl7, 3, 1); // typically |

    $segs = explode($d0, $hl7);
    $a = explode($d1, $segs[0]);
    if ($a[0] != 'MSH') {
        unset($segs);
        return false;
    }

    unset($segs);
    if ($lab_npi == '1891752424' || strtoupper($lab_npi) == 'AMMON') {
        if (strtoupper(trim($a[5])) == strtoupper(trim($send_acct))) {
            $srch = '|' . strtoupper(trim($send_acct)) . '-';
            $hl7 = str_replace($srch, "|", $hl7);
            return true;
        }
        return false;
    }

    if (
        strtoupper(trim($a[5])) == strtoupper(trim($send_acct)) ||
        strtoupper(trim($a[3])) == strtoupper(trim($lab_acct)) ||
        strtoupper(trim($a[2])) == strtoupper(trim($lab_app))
    ) {
        return true;
    }

    return false;
}

In the MSH section, is the lab NPI 7th segment?

image

Is the fragment you pasted from standard code? Does it have lab_npi hardcoded?

HL7 Standard meaning for MSH segment is MVA-BSLAB system sent this package of results from SMH location/installation. Not sure what the emr code is doing. But usually you want to look at OBR(?) for the facility submitting the sample and OBX for the facility that performed analysis and generated the results.

@mdsupport Thanks for writing back.
Yes, the fragment does have the hardcoded NPI. If I am reading the code right, the MSH section contains the NPI number that should be matched to a lab company in the address book.

I dumped the inbound variables of the function to see what the code was trying to match. What I found is that the code is trying to match the NPI number of the first lab entry in the address book. Which does not match the test results sent.

I commented out the match_lab function. I got this response from the system.

That caused an orphan file situation. Then I manually matched the Bon Secours to the patient but still to results were parsed into the system.

Backing up to the match NPI. It seems that if there are multiple labs in the address book. The code only grabs the first one instead of generating an array. It would seem better to me if $lab_npi was an array of the NPI numbers in the system. But if the match_lab is being called from inside a loop it is fine. Line 510 only gives one opportunity for matching $lab_npi and it is hardcoded.

 if ($lab_npi == '1891752424' || strtoupper($lab_npi) == 'AMMON')

Neither of those will match any lab results that are coming into the system. I am going to assume that the match_lab is called in a loop and change the if statement to this.

I need to dump the $a to see what is in the array. Then I should be able to build a conditional that matches the NPI to a one in the system. Does this sound reasonable?

Array
(
  [0] => MSH
  [1] => ^~\&
  [2] => MVA-BSLAB
  [3] => DMC
  [4] => FFC
  [5] => FFC
  [6] => 20211216084647
  [7] => 
  [8] => ORU^R01
  [9] => 1217PATH01
  [10] => P
  [11] => 2.4
)

The NPI number is in $a[6]. Currently, the match_lab code does not match on that segment. Now I can return a true response with a simple.

 if ($lab_npi == $a[6]) {
      return true;
   }

Those matches are taken from the procedure providers NPI.
Once a procedure provider is created using an address book entry, any further reference in lab result processing is tied to the providers id which is also used in the compendium to reference test.
After that, address book is moot. Note compendium import.

Any hard coded NPIs in result processing is for when a particular lab needs special or addition processing.

So what is important in this case is that your procedure provider has a NPI that matches the expected results MSH segment. If a match for a provider is not found then results won’t be processed. If a match is found but there is not a matching order then result is considered an orphan.
For orphans, an encounter and order will be created and a notification sent to user via a pnote.

Generally many labs follow the HL7 spec and special processing is not required like for say Quest and LabCorp.

1 Like

I am trying to make sure I understand that the procedure providers is the lab company. Is that right?

As you can see from my dumping the header MSH the NPI is in segment 6. Also, the orphan trigger was caused by me. I commented out code that triggered that response. I removed the comments.

Thanks @sjpadgett

Yes and the provider is setup as openemr looking out to lab when setting up Sender and Receiver Ids

If I remember correctly MSH3.1 and/or MSH.4.1 from result MSH should match what the values are in the procedure provider Receiver IDs. i.e top nav menu Procedures->Provider

@mdsupport Thanks, in my examination of this code. I have learned a new term for myself. Recursive Function.

Anyway, I have been having a fun time deciphering the code. I have sent the document you posted to the lab result company to see if they can match that format and include the NPI number in the result set.

I just got off the phone with the lab company and they never put the NPI in their results file. I removed the NPI from the system and now it has to match the file on the patients’ data. As you can see below, the arrays don’t have enough common data in them for the system to make a match from the orphan file that has no NPI information. I asked the lab company to add the patients’ DOB and gender to the HL7 file.

[select] => Array
    (
        [a:11:{s:2:%22ss%22;s:0:%22%22;s:5:%22fname%22;s:5:%22Sally%22;s:5:%22lname%22;s:4:%22Test%22;s:5:%22mname%22;s:0:%22%22;s:3:%22DOB%22;s:10:%222001-01-12%22;s:3:%22sex%22;s:6:%22Female%22;s:6:%22street%22;s:0:%22%22;s:4:%22city%22;s:0:%22%22;s:5:%22state%22;s:0:%22%22;s:11:%22postal_code%22;s:0:%22%22;s:10:%22phone_home%22;s:0:%22%22;}] => 71729
    )

[orphaned_order] => R
[match] => Array
    (
        [a:11:{s:2:"ss";s:0:"";s:5:"fname";s:5:"Sally";s:5:"lname";s:4:"Test";s:5:"mname";s:0:"";s:3:"DOB";s:10:"2001-01-12";s:3:"sex";s:6:"Female";s:6:"street";s:0:"";s:4:"city";s:0:"";s:5:"state";s:0:"";s:11:"postal_code";s:0:"";s:10:"phone_home";s:0:"";}] => 1
    )

My dear friend Sherwin. I thought this made clear what you need to match on in result file.