> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
> Use this file to discover all available pages before exploring further.

# JSONB Schema Definitions (CL & PM)

> This document defines JSONB column shapes for critical CL and PM tables. Implementations MUST validate or document deviations.

**Version:** 1.0.0
**Last Updated:** 2026-02-18
**Source:** CL-PM-SPEC-REVIEW Finding 8.6

This document defines JSONB column shapes for critical CL and PM tables. Implementations MUST validate or document deviations.

***

## CL-11: Consent Management

### `cl_consents.consent_scope` (if JSONB)

```json theme={null}
{
  "purposes": ["treatment", "payment", "healthcare_operations", "other"],
  "entities_allowed": ["array of entity names or IDs"],
  "expiration_type": "date|event|none",
  "expiration_date": "ISO8601 date or null",
  "sud_notes_included": false
}
```

### `cl_consents.revocation_reason` (if JSONB)

```json theme={null}
{
  "reason_code": "string",
  "revoked_at": "ISO8601",
  "revoked_by": "profile_id UUID"
}
```

***

## PM-02: Insurance & Eligibility

### `pm_insurance_policies.bh_benefits` (if JSONB)

```json theme={null}
{
  "mental_health_visits_per_year": 20,
  "substance_use_visits_per_year": 30,
  "deductible_met": 100.00,
  "copay_amount": 25.00,
  "prior_auth_required": true
}
```

### `pm_eligibility_checks.benefit_details` (if JSONB)

```json theme={null}
{
  "response_raw": "string or truncated",
  "active": true,
  "service_type": "30",
  "coverage_level": "individual",
  "dates": { "effective": "ISO8601", "termination": "ISO8601" }
}
```

***

## PM-08: Claims

### `pm_claims.denial_codes` (JSONB — array of objects)

> **Canonical format** per PM-08 Clarifications (2026-02-19) and X12-EDI-TECHNICAL-DESIGN.md CAS segment mapping. Preserves per-adjustment amounts and group codes required for ERA 835 posting (PM-09).

```json theme={null}
[
  {
    "carc": "CO-45",
    "rarc": "N362",
    "group_code": "CO",
    "amount": -25.00
  },
  {
    "carc": "PR-3",
    "rarc": null,
    "group_code": "PR",
    "amount": -15.00
  }
]
```

### `pm_claim_lines.adjustment_reason` (JSONB — array of objects)

> Same structure as claim-level `denial_codes`, applied per line.

```json theme={null}
[
  {
    "group_code": "CO",
    "reason_code": "45",
    "amount": -10.00
  }
]
```

***

## CL-04: Progress Notes

### `cl_progress_notes.sections` or note body (if JSONB)

```json theme={null}
{
  "subjective": "string",
  "objective": "string",
  "assessment": "string",
  "plan": "string",
  "interventions": "string",
  "member_response": "string"
}
```

Use consistent keys per template; validate required sections before finalize.

***

## CL-08: Clinical Decision Support

### `cl_cds_rules.rule_config` (if JSONB)

```json theme={null}
{
  "condition": { "field": "diagnosis", "operator": "includes", "value": ["F32.1"] },
  "action": "alert",
  "message_template": "string",
  "severity": "warning|error|info"
}
```

***

## Unlinked FK Resolution (Reference)

| Spec  | Column                                        | Target               | Resolution                                                                                           |
| ----- | --------------------------------------------- | -------------------- | ---------------------------------------------------------------------------------------------------- |
| CL-12 | `cl_transitions.discharge_summary_id`         | Document or CL table | Define in CL-12: e.g. `REFERENCES pf_documents(id)` or `cl_discharge_summaries(id)` when spec exists |
| CL-12 | `cl_transitions.medication_reconciliation_id` | CL-05                | Add `cl_medication_reconciliations` in CL-05 or reference by ID with doc                             |
| PM-07 | `pm_charges.encounter_id`                     | pm\_encounters       | FK to `pm_encounters(id)` per CL-PM-ENCOUNTER-TO-BILLING                                             |
| CL-14 | `cl_group_sessions.curriculum_id`             | Curriculum entity    | PF or CL picklist/reference table; document in CL-14                                                 |
| CL-14 | `cl_group_sessions.program_id`                | rh\_programs or PF   | FK to `rh_programs(id)` or `pf_programs(id)` when defined                                            |
| PM-04 | `pm_group_definitions.program_id`             | Same as above        | Align with CL-14 program reference                                                                   |

Implement migrations with FKs when target tables exist; otherwise document as "intentionally unlinked until \[spec]."
