# luisuriarte/oe-module-coverage-latam architecture

> Architecture diagram of the GitHub repository luisuriarte/oe-module-coverage-latam, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/luisuriarte/oe-module-coverage-latam
- Repository: https://github.com/luisuriarte/oe-module-coverage-latam

## Overview

#### Purpose and host integration
This is a PHP 8.1+ custom module for OpenEMR 8+ that adds LATAM insurance-coverage workflows without modifying OpenEMR tables: prior authorizations, procedure-frequency checks, time-bounded provider/payer agreements, and periodic settlement batches. It runs inside the OpenEMR session, ACL, database, and module lifecycle.
- `openemr.bootstrap.php`
- `moduleConfig.php`
- `index.php`

#### Entry points and UI/API boundary
OpenEMR loads the module bootstrap, which registers module behavior/menu and triggers initial country-pack setup. The operational UI is a single dashboard with tab-specific JavaScript. Browser actions call PHP JSON endpoints; these endpoints require the OpenEMR session and bridge UI requests to repositories/services.
- `pages/dashboard.php`
- `pages/api/auth_rules.php`
- `pages/api/batches.php`

#### Persistence model and OpenEMR boundary
Installation creates 12 isolated `covl_*` tables, while foreign keys/references connect to OpenEMR’s patients, encounters, billing, insurers, providers, facilities, and code catalogs. The module uses native OpenEMR SQL access rather than an ORM. Settlement items enforce separation from the native claim flow; both systems can coexist.
- `sql/install.sql`
- `src/Repository/AuthorizationRepository.php`
- `src/Repository/SettlementBatchRepository.php`

#### Authorization and integration pipeline
`AuthorizationService` evaluates payer/code/plan rules, resolves a payer-specific integration adapter, persists the authorization and state history, and can later link it to a clinical encounter. Adapter contracts isolate external insurer APIs; the included manual adapter provides an always-available operational fallback. Results cross this boundary through typed DTO/contracts.
- `src/Service/AuthorizationService.php`
- `src/Service/AdapterRegistry.php`
- `src/Adapter/ManualFallbackAdapter.php`

#### Coverage validation stages
Frequency validation combines configured rules with native billed procedures and still-active, unlinked authorizations, returning whether the procedure is allowed plus violation severity/timing. Provider coverage independently validates a provider × insurer agreement for a requested date, supporting agenda/check-in integration points.
- `src/Service/FrequencyCheckService.php`
- `src/Service/ProviderCoverageService.php`
- `src/Repository/FrequencyRulesRepository.php`

#### Settlement and administration workflows
Administrative APIs manage authorization/frequency rules, provider agreements, and settlement batches. Batch progression groups native `billing` items by insurer/period and supports controlled status transitions, payments, disputes, and item-level management. Insurer data remains owned by OpenEMR’s `insurance_companies`.
- `pages/api/frequency_rules.php`
- `pages/api/providers.php`
- `src/Repository/SettlementBatchRepository.php`

#### Country-pack and code-catalog provisioning
Country JSON packs define localized code types, authorization/frequency defaults, and local-to-standard code mappings. Import is transactional and idempotent; Argentina is auto-imported on first active access. A separate SQL catalog provisions Spanish CPT4 descriptions used by code search, alongside supported native terminology sources.
- `src/Service/CountryPackInstaller.php`
- `src/Service/CountryPackImporter.php`
- `packs/ar.json`

Main entry points: [`sql/install.sql`](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/sql/install.sql) (covl_* schema), [`pages/api/auth_rules.php`](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/pages/api/auth_rules.php) (Administration APIs), [`src/Service/FrequencyCheckService.php`](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Service/FrequencyCheckService.php) (Frequency check service), [`openemr.bootstrap.php`](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/openemr.bootstrap.php) (Module bootstrap)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["OpenEMR host"]
  node_openemr{{"OpenEMR runtime<br/>host platform"}}
  node_native_data[("Native clinical &amp; insurer data<br/>OpenEMR tables")]
end

subgraph group_ui["Module UI &amp; APIs"]
  node_bootstrap["Module bootstrap<br/>PHP entrypoint"]
  node_dashboard["Coverage dashboard<br/>PHP UI<br/>[dashboard.php]"]
  node_admin_apis["Administration APIs<br/>JSON endpoints<br/>[auth_rules.php]"]
  node_batch_api["Settlement batch API<br/>JSON endpoint<br/>[batches.php]"]
end

subgraph group_services["Coverage workflows"]
  node_authorization_service["Authorization service<br/>workflow service"]
  node_adapter_registry["Adapter registry<br/>integration resolver"]
  node_frequency_service["Frequency check service<br/>validation service"]
  node_provider_coverage["Provider coverage service<br/>validation service"]
  node_settlement_workflow["Settlement workflow<br/>batch process"]
end

subgraph group_data["Module persistence"]
  node_module_schema[("covl_* schema<br/>module tables<br/>[install.sql]")]
  node_authorization_repo["Authorization repository<br/>SQL repository"]
  node_frequency_rules_repo["Frequency rules repository<br/>SQL repository"]
  node_settlement_repo["Settlement batch repository<br/>SQL repository"]
end

subgraph group_external["Payer integration &amp; provisioning"]
  node_manual_adapter["Manual fallback adapter<br/>payer adapter"]
  node_country_installer["Country-pack installer<br/>provisioning service"]
  node_country_importer["Country-pack importer<br/>provisioning service"]
  node_argentina_pack["Argentina country pack<br/>localized JSON pack<br/>[ar.json]"]
end

node_openemr -->|"loads module"| node_bootstrap
node_bootstrap -->|"registers UI"| node_dashboard
node_bootstrap -->|"initial setup"| node_country_installer
node_dashboard -->|"browser JSON actions"| node_admin_apis
node_dashboard -->|"batch actions"| node_batch_api
node_admin_apis -->|"authorization requests"| node_authorization_service
node_admin_apis -->|"frequency checks"| node_frequency_service
node_admin_apis -->|"agreement checks"| node_provider_coverage
node_batch_api -->|"batch progression"| node_settlement_workflow
node_authorization_service -->|"resolves adapter"| node_adapter_registry
node_adapter_registry -.->|"fallback"| node_manual_adapter
node_authorization_service -->|"persists state"| node_authorization_repo
node_frequency_service -->|"loads configured rules"| node_frequency_rules_repo
node_frequency_service -->|"checks active authorizations"| node_authorization_repo
node_frequency_service -->|"reads billed procedures"| node_native_data
node_provider_coverage -->|"reads agreements"| node_module_schema
node_settlement_workflow -->|"manages batches/items"| node_settlement_repo
node_settlement_workflow -->|"groups billing by insurer/period"| node_native_data
node_authorization_repo -->|"native SQL"| node_module_schema
node_frequency_rules_repo -->|"native SQL"| node_module_schema
node_settlement_repo -->|"native SQL"| node_module_schema
node_module_schema -.->|"references host records"| node_native_data
node_country_installer -->|"runs import"| node_country_importer
node_country_importer -->|"loads definitions"| node_argentina_pack
node_country_importer -->|"provisions defaults"| node_module_schema

click node_bootstrap "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/openemr.bootstrap.php"
click node_dashboard "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/pages/dashboard.php"
click node_admin_apis "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/pages/api/auth_rules.php"
click node_batch_api "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/pages/api/batches.php"
click node_module_schema "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/sql/install.sql"
click node_authorization_repo "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Repository/AuthorizationRepository.php"
click node_frequency_rules_repo "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Repository/FrequencyRulesRepository.php"
click node_settlement_repo "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Repository/SettlementBatchRepository.php"
click node_authorization_service "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Service/AuthorizationService.php"
click node_adapter_registry "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Service/AdapterRegistry.php"
click node_frequency_service "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Service/FrequencyCheckService.php"
click node_provider_coverage "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Service/ProviderCoverageService.php"
click node_settlement_workflow "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Repository/SettlementBatchRepository.php"
click node_manual_adapter "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Adapter/ManualFallbackAdapter.php"
click node_country_installer "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Service/CountryPackInstaller.php"
click node_country_importer "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Service/CountryPackImporter.php"
click node_argentina_pack "https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/packs/ar.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_openemr,node_native_data toneBlue
class node_bootstrap,node_dashboard,node_admin_apis,node_batch_api toneAmber
class node_authorization_service,node_adapter_registry,node_frequency_service,node_provider_coverage,node_settlement_workflow toneMint
class node_module_schema,node_authorization_repo,node_frequency_rules_repo,node_settlement_repo toneRose
class node_manual_adapter,node_country_installer,node_country_importer,node_argentina_pack toneIndigo
```

## Components

### OpenEMR host

Module runs within native OpenEMR runtime and data ownership.

- **OpenEMR runtime**: host platform · Provides session, ACL, lifecycle, SQL access, and native clinical data.
- **Native clinical & insurer data**: OpenEMR tables · Patients, encounters, billing, insurers, providers, facilities, and code catalogs remain host-owned.

### Module UI & APIs

- [Module bootstrap](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/openemr.bootstrap.php): PHP entrypoint · Registers module behavior and starts first-use provisioning. · `openemr.bootstrap.php`
- [Coverage dashboard](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/pages/dashboard.php): PHP UI · Single operational dashboard with tab-specific browser actions. · `pages/dashboard.php`
- [Administration APIs](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/pages/api/auth_rules.php): JSON endpoints · Manages authorization rules, frequency rules, provider agreements, and batches. · `pages/api/auth_rules.php`
- [Settlement batch API](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/pages/api/batches.php): JSON endpoint · `pages/api/batches.php`

### Coverage workflows

- [Authorization service](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Service/AuthorizationService.php): workflow service · Evaluates payer/code/plan rules, creates authorization state, and links encounters. · `src/Service/AuthorizationService.php`
- [Adapter registry](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Service/AdapterRegistry.php): integration resolver · Selects the payer-specific authorization adapter. · `src/Service/AdapterRegistry.php`
- [Frequency check service](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Service/FrequencyCheckService.php): validation service · Combines rules, billed procedures, and active unlinked authorizations. · `src/Service/FrequencyCheckService.php`
- [Provider coverage service](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Service/ProviderCoverageService.php): validation service · Validates provider × insurer agreements for a requested date. · `src/Service/ProviderCoverageService.php`
- [Settlement workflow](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Repository/SettlementBatchRepository.php): batch process · Groups native billing by insurer and period; supports payments, disputes, and item management. · `src/Repository/SettlementBatchRepository.php`

### Module persistence

- [covl_* schema](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/sql/install.sql): module tables · Twelve isolated tables for coverage workflows and settlement items. · `sql/install.sql`
- [Authorization repository](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Repository/AuthorizationRepository.php): SQL repository · Persists authorizations, links, and state history through native SQL. · `src/Repository/AuthorizationRepository.php`
- [Frequency rules repository](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Repository/FrequencyRulesRepository.php): SQL repository · `src/Repository/FrequencyRulesRepository.php`
- [Settlement batch repository](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Repository/SettlementBatchRepository.php): SQL repository · Manages batches, items, and controlled settlement state. · `src/Repository/SettlementBatchRepository.php`

### Payer integration & provisioning

- [Manual fallback adapter](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Adapter/ManualFallbackAdapter.php): payer adapter · Always-available operational fallback for insurer authorization. · `src/Adapter/ManualFallbackAdapter.php`
- [Country-pack installer](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Service/CountryPackInstaller.php): provisioning service · Triggers transactional, idempotent country-pack import on active access. · `src/Service/CountryPackInstaller.php`
- [Country-pack importer](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/src/Service/CountryPackImporter.php): provisioning service · Imports localized code types, defaults, and code mappings. · `src/Service/CountryPackImporter.php`
- [Argentina country pack](https://github.com/luisuriarte/oe-module-coverage-latam/blob/main/packs/ar.json): localized JSON pack · Auto-imported on first active access. · `packs/ar.json`

## Connections

- OpenEMR runtime → Module bootstrap: loads module
- Module bootstrap → Coverage dashboard: registers UI
- Module bootstrap → Country-pack installer: initial setup
- Coverage dashboard → Administration APIs: browser JSON actions
- Coverage dashboard → Settlement batch API: batch actions
- Administration APIs → Authorization service: authorization requests
- Administration APIs → Frequency check service: frequency checks
- Administration APIs → Provider coverage service: agreement checks
- Settlement batch API → Settlement workflow: batch progression
- Authorization service → Adapter registry: resolves adapter
- Adapter registry → Manual fallback adapter: fallback
- Authorization service → Authorization repository: persists state
- Frequency check service → Frequency rules repository: loads configured rules
- Frequency check service → Authorization repository: checks active authorizations
- Frequency check service → Native clinical & insurer data: reads billed procedures
- Provider coverage service → covl_* schema: reads agreements
- Settlement workflow → Settlement batch repository: manages batches/items
- Settlement workflow → Native clinical & insurer data: groups billing by insurer/period
- Authorization repository → covl_* schema: native SQL
- Frequency rules repository → covl_* schema: native SQL
- Settlement batch repository → covl_* schema: native SQL
- covl_* schema → Native clinical & insurer data: references host records
- Country-pack installer → Country-pack importer: runs import
- Country-pack importer → Argentina country pack: loads definitions
- Country-pack importer → covl_* schema: provisions defaults
