Search by

juggernautsei / oe-auto-claim-batch-generator

juggernautsei

OpenEMR 8.x module that automatically batches ready claims via BillingProcessor and background services

Package info

github.com/juggernautsei/oe-auto-claim-batch-generator

Type:openemr-module

pkg:composer/juggernautsei/oe-auto-claim-batch-generator

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.0 2026-12-01 11:50 UTC

This package is auto-updated.

Last update: 2026-12-01 12:19:36 UTC


README

Automates generation of X12 claim batches for encounters that are ready to bill, reducing manual work in OpenEMR’s billing workflow.

Module Manager name: Auto Claim Batching v2.0
Package version: 2.0.0 (version.php) — OpenEMR 8.x
Namespace: Juggernaut\Module\ClaimBatcher
Author: Sherwin Gaddis

Packagist

composer require juggernautsei/oe-auto-claim-batch-generator:^2.0.0

What it does

  1. Selects recent encounters with unbilled (or reprocessable) billing lines.
  2. Validates each CPT4 line for minimum claim readiness (justify, fee, payer, X12 partner).
  3. Builds a payload compatible with OpenEMR’s core BillingProcessor.
  4. Runs as an OpenEMR background service (or optional CLI) on a schedule.
  5. Optionally restricts batching to encounters that have required clinical forms completed (configured in Module Manager; enforced when forms are selected).

Compatibility

Target Status
OpenEMR 8.0+ (including 8.2.x) Supported — v2.0.x line
OpenEMR 7.0.x Use v1.1.x release / branch (legacy SQL + raw session)

OpenEMR 8.x runtime notes

This v2.0.0 line targets OpenEMR 8.x application patterns:

  • OpenEMR\Common\Database\QueryUtils instead of legacy sqlQuery / sqlStatement / sqlFetchArray
  • OEGlobalsBag / OeContext instead of direct $GLOBALS access for site paths and kernel
  • SessionUtil / session wrapper for CLI automation identity (no raw $_SESSION writes when the wrapper is available)
  • Core OpenEMR\Billing\BillingProcessor\BillingProcessor (verified present on current 8.x trees)
  • Entry scripts still bootstrap OpenEMR via interface/globals.php with $ignoreAuth / $sessionAllowWrite where required (background service + CLI)

Runtime notes

  • Install path: interface/modules/custom_modules/oe-auto-claim-batch-generator
  • PHP 8.1+ required
  • Multi-site: CLI requires -s <site_id> (no default site fallback); background service uses the runner’s site context

Installation

  1. Copy or clone this directory into:

    <openemr>/interface/modules/custom_modules/oe-auto-claim-batch-generator
    
  2. In OpenEMR, open Modules → Module Manager.

  3. Register then Install the module so table.sql runs.

  4. Open the module Config page and select any forms that must be completed before batching (optional).

  5. Enable the module. Enabling activates the claimsBatching background service.

Database objects (table.sql)

Object Purpose
background_services row name = claimsBatching Schedules doBatching() daily (execute_interval = 1440 minutes). Starts inactive until the module is enabled.
module_auto_claim_batch_selected_forms Stores form ids/names chosen on the config screen.

Background service entry (from table.sql):

  • Function: doBatching
  • Script: /interface/modules/custom_modules/oe-auto-claim-batch-generator/public/initiateClaimBatch.php
  • Interval: 1440 minutes (once per day)

On disable, the service is set inactive. On unregister, the claimsBatching background row is deleted.

Configuration

Module config UI (setup.php)

Path (when opened from Module Manager config):

.../oe-auto-claim-batch-generator/setup.php
  • Lists standard forms from registry (excluding newpatient, misc_billing_options, procedure_order, fee_sheet).
  • Lists Layout Based Forms (layout_group_properties where grp_form_id LIKE LBF%).
  • Saves selections into module_auto_claim_batch_selected_forms.
  • CSRF protected.
  • UI copy states: if no forms are selected, all claims are processed.

Payer / clearinghouse prerequisites

For a claim line to pass validation, the patient’s primary insurance company must have:

  • A resolvable insurance_companies.id via insurance_data
  • A non-empty x12_default_partner_id

Claims without an X12 partner are skipped and logged.

Email notifications

NotificationService is invoked from doBatching() for empty runs and completed batches. It emails users with users.abook_type = 'bill' and a non-empty email. Without recipients, content is appended under:

$OE_SITE_DIR/documents/temp/claim_notifications.log

How batching works

Entry points

Entry Use
public/initiateClaimBatch.php → doBatching() Production path used by OpenEMR background services
public/cronJobBatchClaimsCli.php -s <site_id> CLI / external cron; sets $ignoreAuth, site id, and a service session user
public/callProcess.php Manual UI trigger — requires login + acct/rep_a ACL and CSRF POST; runs the same doBatching() path

Pipeline (doBatching)

ClaimsBatchQuery::executeClaimsQuery()
        │
        ▼
ClaimValidator::validateClaims()
        │
        ▼
ProcessArrayGenerator::generateHeader() + claims[]
        │
        ▼
OpenEMR BillingProcessor::execute()
        │
        ▼
Log lines → site temp billingProcessorClaim.log

Claim selection window (ClaimsBatchQuery)

  • From: start of day, 5 days ago
  • To: end of today
  • Encounters joined to billing where:
    • billing.activity = 1
    • billing.code_type LIKE '%' (all code types in the join filter)
    • billed = 0 or (billed = 1 and bill_process = 3)
  • Ordered by provider, encounter, pid, code type, code

Comment in code says “yesterday”; implementation uses a 5-day lookback.

Validation rules (ClaimValidator)

A billing row is eligible only when all of the following hold:

  1. code_type === 'CPT4'
  2. justify is non-empty (ICD linkage on the CPT line)
  3. fee is non-empty
  4. Primary payer company id can be resolved for the encounter patient
  5. That company has x12_default_partner_id set

Output shape per valid encounter key pid-encounter:

[
  'pid-encounter' => [
    'payer'   => 'p' . $insuranceCompanyId,
    'partner' => $x12PartnerId,
    'bill'    => 0,
  ],
]

Required-forms checking (hasRequiredFormsCompleted) is enforced when one or more forms are selected. Standard forms are keyed by registry directory (matches forms.formdir); LBF forms by grp_form_id.

Billing processor header (ProcessArrayGenerator)

Builds the array OpenEMR’s billing UI would roughly post, including:

  • mode = bill
  • bn_x12 = true
  • unbilled = on
  • CSRF token
  • Margins and date fields used by the processor

Logging

Successful processor info lines are appended to:

$OE_SITE_DIR/documents/temp/billingProcessorClaim.log

claim_batch_log_file() creates documents/temp under the active site directory when missing. If the site path is unavailable, it falls back to the system temp directory.

CLI usage

From the OpenEMR web root (or with a correct path to the script):

php interface/modules/custom_modules/oe-auto-claim-batch-generator/public/cronJobBatchClaimsCli.php -s default

Replace default with your multi-site id. The -s argument is required.

The CLI sets:

  • $ignoreAuth = true
  • $sessionAllowWrite = true
  • $_SESSION['authUser'] = 'oe-system' (and related session keys)

Ensure the host’s PHP CLI can reach the same database and that SMTP/mail() works if you later wire notifications.

Directory layout

oe-auto-claim-batch-generator/
├── composer.json
├── info.txt
├── moduleConfig.php          # loads setup.php for Module Manager config
├── ModuleManagerListener.php # enable/disable/unregister background service
├── openemr.bootstrap.php     # namespace registration
├── setup.php                 # config UI: required forms
├── table.sql                 # background_services + selected_forms table
├── version.php
├── public/
│   ├── initiateClaimBatch.php    # doBatching() + site temp log helper
│   ├── cronJobBatchClaimsCli.php # CLI wrapper
│   └── callProcess.php           # manual run UI (ACL + CSRF)
└── src/
    ├── Bootstrap.php             # no menu events yet
    └── Services/
        ├── ClaimsBatchQuery.php
        ├── ClaimValidator.php
        ├── FormsCollection.php
        ├── NotificationService.php
        └── ProcessArrayGenerator.php

Operations checklist

Before enabling in production:

  1. Confirm each active payer has X12 default partner set.
  2. Confirm billing lines use CPT4 with justify and fee.
  3. Decide whether the 5-day window matches your billing lag; adjust ClaimsBatchQuery if needed.
  4. If you select required forms, ensure encounters complete those forms before batch day (gate is enforced).
  5. Ensure the site documents/temp directory is writable by the web/PHP user (created automatically when possible).
  6. Prefer background services or CLI cron—not both—unless you intentionally dual-run with non-overlapping schedules.
  7. Manual runs use callProcess.php (ACL + CSRF). Do not remove those guards.

Known limitations

Issue Detail
CLI auth bypass Expected for automation; protect OS-level access to the script
Notification delivery Uses PHP mail(); depends on host MTA/SMTP configuration
Failed count heuristic “Failed” stats approximate rows found minus validated encounter keys, not processor-level denials

Fixed

Issue Resolution
callProcess.php debug stub ACL (acct/rep_a) + CSRF manual runner calling doBatching()
Hardcoded reencuentro log path $OE_SITE_DIR/documents/temp/billingProcessorClaim.log
Invalid lookback time 00:00:00 in ClaimsBatchQuery
Form gate not enforced Required forms enforced; registry keyed by directory
Notifications unused Wired into doBatching() empty/complete paths
Config page ACL setup.php requires acct/rep_a or admin/super
No menu item Reports → Auto Claim Batch
composer / version / license juggernautsei/..., GPL-3.0-only, version 2.0.0
Legacy saveForm() Removed

Security notes

  • Background / CLI run with elevated automation context; treat host access as privileged.
  • Config UI (setup.php) requires acct/rep_a or admin/super plus CSRF on save.
  • Manual batch UI (callProcess.php) requires acct/rep_a and CSRF on POST.
  • Batch output can include claim identifiers; logs live under the site documents/temp tree—keep permissions appropriate (not world-readable).

Development

Namespace: Juggernaut\Module\ClaimBatcher\
Autoload:  composer PSR-4 → src/  (also registered in openemr.bootstrap.php)

Core integration point:

use OpenEMR\Billing\BillingProcessor\BillingProcessor;

Suggested next improvements:

  1. Make lookback days configurable from the module config UI.
  2. Prefer OpenEMR mail/MyMailer over raw mail() if available in target versions.
  3. Add automated tests around ClaimValidator form matching and payer resolution.
  4. GitHub release v2.0.0 published for OpenEMR 8.x.

License

GNU General Public License v3.0 (GPL-3.0-only). See LICENSE.

Support

Sherwin Gaddis / Juggernaut Systems Enterprise
https://github.com/juggernautsei/oe-auto-claim-batch-generator