X12 files aren't being generated correctly

Situation
x12 files are not being generated correctly. OpenEMR doesn’t through any errors but the x12 files are being rejected by the clearinghouse with errors.

OpenEMR Version
I’m using OpenEMR version 7.0.1.1

Browser:
I’m using: Chrome and Firefox

Operating System
I’m using: Ubuntu 20.04 and 22.04

Search
Did you search the forum for similar questions? yes

Logs
Did you check the logs?
Was there anything pertinent in them?
Please paste them here (surround with three backticks (```) for readability.
You can also turn on User Debugging under Administration->Globals->Logging User Debugging Options=>All

Clearinghouse Errors

  • HL01-HL COUNTER IS OUT SEQUENCE. IT SHOULD = 1
  • LINE: 50 LOOP: 2000A BILLING PROVIDER HIERARCHICAL LEVEL
  • INVALID PARENT ID SENT IN HL02. MUST = HL01 FROM PREVIOUS LOOP 2000A 2000A
  • LINE: 56 LOOP: 2000B SUBSCRIBER HIERARCHICAL PARENT ID NUMBER
  • HL01-HL COUNTER IS OUT SEQUENCE. IT SHOULD = 1
  • LINE: 56 LOOP: 2000B SUBSCRIBER HIERARCHICAL PARENT ID NUMBER

2023-06-19-092826-batch.txt (1.0 KB)

hi @darkdecoy, do you have Generate X-12 Based On Insurance Company enabled in
Config->Billing?

No that is not enabled

did you follow this advice?

I applied the first fix but not the zip code fix

I tried applying the zipcode fix but x12 file failed to upload to the clearinghouse. Any other ideas what to try and fix this? Thanks.

Could the zip code for the insurance and patient are just five digits instead of 9 cause this issue?

hi @darkdecoy , not the HL error.

hi @darkdecoy , there was a bug in the above fix, remove the $claim->getPartner() and it should work.

You’ll also want to have those zip fixes if you haven’t grabbed them. My apologies since there were a lot of moving parts but all will be well with patch 2.

I made both of those changes but we are stilling getting those errors.

protected function updateBatchFile(BillingClaim $claim)
    {
        // Generate the file
        $log = '';
        $hlCount = 1;
        $segs = explode(
            "~\n",
            X125010837P::genX12837P(
                $claim->getPid(),
                $claim->getEncounter(),
                $claim->getPartner(),
                $log,
                $this->encounter_claim,
                false,
                $hlCount
            )
        );
        $this->appendToLog($log);
        $this->batch->append_claim($segs);

        // Store the claims that are in this claims batch, because
        // if remote SFTP is enabled, we'll need the x12 partner ID to look up SFTP credentials
        $this->batch->addClaim($claim);
    }
} else {
                $log .= "*** Missing service facility street.\n";
            }

            ++$edicount;
            $out .= "N4" .
                "*";
            if ($claim->facilityCity()) {
                $out .= $claim->facilityCity();
            } else {
                $log .= "*** Missing service facility city.\n";
            }
            $out .= "*";
            if ($claim->facilityState()) {
                $out .= $claim->facilityState();
            } else {
                $log .= "*** Missing service facility state.\n";
            }
            $out .= "*";
            if (strlen($claim->facilityZip()) != 9) {
                $log .= "*** Service facility zip is not 9 digits.\n";
            }
            $out .= $claim->facilityZip();
            $out .= "~\n";
        }

hi @darkdecoy , remove

    $claim->getPartner(),

Removing that line solved part of the problem as we can now generate some x12 files that the clearinghouse can successfully process but there are some with secondary claims that are still failing. I took a look and there are some times when the secondary insurance doesn’t have a zip code in the x12 file even though one has been entered when I look in the OpenEMR webui. Thanks.
example-bad-2023-06-21-170639-batch.txt (2.2 KB)

hi @darkdecoy, let me check and see if we’re missing something there, thanks

yep, these lines should be

if (
                !(strlen($claim->payerZip($ins)) == 5)
                || (strlen($claim->payerZip($ins) == 9))
            ) {
                $log .= "*** Other payer zip is not 5 or 9 digits.\n";
            }

            $out .= $claim->x12Zip($claim->payerZip($ins));
            $out .= "~\n";

So I tried this and it doesn’t fix the issue. Also it causes the entire patient address to be blank.

sorry, it’s the other insco lines,

here’s the PR that will bring back to rel-701

that fixed the issue and we were able to submit the x12 to the clearinghouse successfully. One thing of note is that in the logs on openemr it still throws an error “*** Other payer zip is not 5 or 9 digits.”

nice, thanks for the feedback, it’s meant to log something that might be an issue for some payers there in the billing log and could be a potential error that a biller might want to fix