juggernautsei / oe-auto-claim-batch-generator
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
Requires
- php: >=8.1
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
- openemr/openemr: <8.0.0
Replaces
None
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
- Package: https://packagist.org/packages/juggernautsei/oe-auto-claim-batch-generator
- OpenEMR 8.x →
^2.0.0 - OpenEMR 7.0.x →
^1.1.0
What it does
- Selects recent encounters with unbilled (or reprocessable) billing lines.
- Validates each CPT4 line for minimum claim readiness (justify, fee, payer, X12 partner).
- Builds a payload compatible with OpenEMR’s core
BillingProcessor. - Runs as an OpenEMR background service (or optional CLI) on a schedule.
- 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\QueryUtilsinstead of legacysqlQuery/sqlStatement/sqlFetchArrayOEGlobalsBag/OeContextinstead of direct$GLOBALSaccess for site paths and kernelSessionUtil/ session wrapper for CLI automation identity (no raw$_SESSIONwrites 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.phpwith$ignoreAuth/$sessionAllowWritewhere 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
-
Copy or clone this directory into:
<openemr>/interface/modules/custom_modules/oe-auto-claim-batch-generator -
In OpenEMR, open Modules → Module Manager.
-
Register then Install the module so
table.sqlruns. -
Open the module Config page and select any forms that must be completed before batching (optional).
-
Enable the module. Enabling activates the
claimsBatchingbackground 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(excludingnewpatient,misc_billing_options,procedure_order,fee_sheet). - Lists Layout Based Forms (
layout_group_propertieswheregrp_form_idLIKELBF%). - 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.idviainsurance_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
billingwhere:billing.activity = 1billing.code_type LIKE '%'(all code types in the join filter)billed = 0or (billed = 1andbill_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:
code_type === 'CPT4'justifyis non-empty (ICD linkage on the CPT line)feeis non-empty- Primary payer company id can be resolved for the encounter patient
- That company has
x12_default_partner_idset
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=billbn_x12= trueunbilled= 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:
- Confirm each active payer has X12 default partner set.
- Confirm billing lines use CPT4 with justify and fee.
- Decide whether the 5-day window matches your billing lag; adjust
ClaimsBatchQueryif needed. - If you select required forms, ensure encounters complete those forms before batch day (gate is enforced).
- Ensure the site
documents/tempdirectory is writable by the web/PHP user (created automatically when possible). - Prefer background services or CLI cron—not both—unless you intentionally dual-run with non-overlapping schedules.
- 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) requiresacct/rep_aoradmin/superplus CSRF on save. - Manual batch UI (
callProcess.php) requiresacct/rep_aand CSRF on POST. - Batch output can include claim identifiers; logs live under the site
documents/temptree—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:
- Make lookback days configurable from the module config UI.
- Prefer OpenEMR mail/MyMailer over raw
mail()if available in target versions. - Add automated tests around ClaimValidator form matching and payer resolution.
- GitHub release
v2.0.0published 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