Status: 📝 Planned
Last Updated: 2026-03-27
Spec (Phase 1): PM-15 Clearinghouse Integration
Spec (Phase 2): PM-15-P2 Production Clearinghouse Transport
Constitution Reference: Section 1.3 (Integration Patterns), Section 2.1 (Integration points documented in
/docs/architecture/integrations/)
Quick Reference
Decision Tree
-
Need to submit a claim electronically?
→ Use PM-15
ClearinghouseAdapter.submitClaim()via PM-08 claim workflow. → Credentials resolved from vault refs at runtime; never stored in code. -
Need to process an ERA/835?
→ Use
ClearinghouseAdapter.fetchRemittance()→ parse → feed PM-09 payment posting. → 835 SVC segments map topm_claim_lines. -
Need to check eligibility in real-time?
→ Use
ClearinghouseAdapter.checkEligibility()for 270/271 (PM-02 integration).
Common Mistakes
Pre-Flight Checklist
- PM-08 and PM-09 schemas exist (claims, claim_lines, payments)
- Vault refs configured for clearinghouse credentials
- RLS enabled with FORCE on all four tables
- UPDATE policies include WITH CHECK
- No secrets in code, migrations, or docs
Overview
PM-15 provides clearinghouse connectivity for ANSI X12 transactions (837P/I, 835, 270/271, 276/277, 278, 999/277CA). It defines the data model (pm_clearinghouse_config with clearinghouse_provider, sender_id, receiver_id, connection_type, vault refs, host/port/paths or api_endpoint; pm_transaction_batches, pm_transaction_log, pm_payer_enrollments), RLS, and the generic ClearinghouseAdapter interface. Implementations (Waystar first, then Availity, Change Healthcare, etc.) are configured per organization; credentials are stored in vault only.
Integration Points
API / Adapter Contract
Clearinghouse adapter interface is defined in X12 EDI Technical Design.Phase 1 methods (adapter interface)
Phase 2a additions (transport layer)
Phase 2b additions (X12 utilities — shared, pure TypeScript)
835 parser → PM-09 interface
The Phase 2b 835 parser writes to PM-09-owned tables:- Creates
pm_era_filesrecord:file_name,received_date,payer_id(from GS/TRN),check_eft_number,total_paid,claim_count,status = 'received' - Emits
clearinghouse_era_receivedevent (payload below) for PM-09 to pick up - PM-09 payment posting pipeline consumes the event and creates
pm_payments+pm_payment_applications
era_file_id.
Pattern Library
- Adapter abstraction pattern: PM workflows call
ClearinghouseAdaptermethods, not vendor SDKs directly. - Vault reference pattern: runtime credential resolution from
pm_clearinghouse_config, never plaintext secrets in code. - Append-only ledger pattern:
pm_transaction_logis immutable and used for traceability.
Event Contracts
Events are defined in EVENT_CONTRACTS.md. Phase 2 adds the following:Note:clearinghouse_batch_submittedandclearinghouse_batch_errorwere defined in Phase 1 (PM-15 Errata F-5).clearinghouse_era_receivedandclearinghouse_health_changedare new in Phase 2.
Phase 2c: Connection Health Monitoring
Theclearinghouse-health-check edge function runs every 30 minutes (Supabase cron) and performs a connection test (SFTP handshake via validateCredentials() or Waystar API ping):
- On status change → updates
pm_clearinghouse_config.health_statusandlast_health_check_at - On
downordegraded→ emitsclearinghouse_health_changedimmediately; PF-10 alert fired - On recovery to
healthy→ requires 2 consecutive healthy checks before emitting recovery event (anti-flap throttle) - Health badge in UI is gated by
pm.clearinghouse.view
Security & Tenant Isolation
- All clearinghouse tables are scoped by
organization_id; RLS and SECURITY DEFINER helpers enforce isolation. - Credentials stored in vault only; config holds vault refs; resolution at runtime in edge function or backend.
- PHI in 837/835: encrypt in transit (TLS); audit access to batch and transaction log.
References
- PM-15: Clearinghouse Integration — Phase 1 (tables, RLS, adapter interface, UI stubs)
- PM-15-P2: Production Clearinghouse Transport — Phase 2 (transport, X12, health monitoring)
- PM-15: Clearinghouse Vendor Selection & Waystar-First Integration
- PM-09: Payment Posting & ERA Processing —
pm_era_files,pm_payments,pm_payment_applicationsschema - X12 EDI Technical Design
- REGULATORY_COMPLIANCE_TRACKER.md — PM-15-P2 HIPAA EDI Transport row