Skip to main content
Version: 2.0.0
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 to pm_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:
  1. Creates pm_era_files record: file_name, received_date, payer_id (from GS/TRN), check_eft_number, total_paid, claim_count, status = 'received'
  2. Emits clearinghouse_era_received event (payload below) for PM-09 to pick up
  3. PM-09 payment posting pipeline consumes the event and creates pm_payments + pm_payment_applications
Downstream consumers must resolve the Supabase storage object path from era_file_id.

Pattern Library

  • Adapter abstraction pattern: PM workflows call ClearinghouseAdapter methods, 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_log is immutable and used for traceability.

Event Contracts

Events are defined in EVENT_CONTRACTS.md. Phase 2 adds the following:
Note: clearinghouse_batch_submitted and clearinghouse_batch_error were defined in Phase 1 (PM-15 Errata F-5). clearinghouse_era_received and clearinghouse_health_changed are new in Phase 2.

Phase 2c: Connection Health Monitoring

The clearinghouse-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_status and last_health_check_at
  • On down or degraded → emits clearinghouse_health_changed immediately; 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