> ## 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.

# Integration Contract: Group Encounter Generation

> Version: 1.0.0 Last Updated: 2026-04-08 Constitution Reference: Section 1.2 (Core Independence), Section 1.3 (Integration Patterns) Source: CL-14-EN-01 Spec Re…

**Version:** 1.0.0
**Last Updated:** 2026-04-08
**Constitution Reference:** Section 1.2 (Core Independence), Section 1.3 (Integration Patterns)
**Source:** CL-14-EN-01 Spec Review

***

## Overview

CL-14-EN-01 automates the generation of individual encounter records and charge entries from group session attendance. It extends the existing `cl_group_session_documented` event contract (CL-PM-GROUP-SESSIONS.md) with a batch review workflow and publishes `cl_group_encounters_approved` for downstream charge creation.

***

## Ownership Boundaries

| Concern                                   | Owner               | Table/Event                                        |
| ----------------------------------------- | ------------------- | -------------------------------------------------- |
| Group session documentation & attendance  | CL-14               | `cl_group_sessions`, `cl_group_attendance`         |
| Encounter generation tracking             | CL-14-EN-01         | `cl_group_encounter_generations`                   |
| CPT code proposal (advisory)              | CL-14-EN-01         | `cl_group_encounter_generations.proposed_cpt_code` |
| Authoritative CPT determination           | PM-07               | `pm_charges` (at charge capture time)              |
| Encounter records                         | PM (pm\_encounters) | `pm_encounters`                                    |
| Charge creation from approved generations | PM-07               | Triggered by `cl_group_encounters_approved` event  |

**Key Principle:** CL-14-EN-01 proposes CPT codes; PM-07 retains final authority for CPT/modifier/unit determination at charge capture. The `proposed_cpt_code` is advisory and may be overridden by PM-07 fee schedule rules.

***

## Event Contracts

### Consumed Events

**`cl_group_session_documented`** (existing — defined in CL-PM-GROUP-SESSIONS.md)

* **Publisher:** CL-14
* **Existing Subscriber:** PM-07
* **New Subscriber:** CL-14-EN-01 (encounter generation handler)
* **Purpose:** Triggers creation of `cl_group_encounter_generations` records per present/partial attendee
* **Idempotency:** Insert-once by `(organization_id, group_session_id, patient_id)` using `ON CONFLICT (organization_id, group_session_id, patient_id) DO NOTHING`; replayed events are skipped and existing rows are not mutated.

### Published Events

**`cl_group_encounters_approved`** (new — 📝 Planned)

* **Publisher:** CL-14-EN-01
* **Subscriber:** PM-07
* **Channel:** `cl_events`
* **Payload Schema:**
  ```typescript theme={null}
  {
    session_id: string; // UUID
    approved_generations: Array<{
      generation_id: string; // UUID
      encounter_id: string; // UUID
      patient_id: string; // UUID
      proposed_cpt_code: string;
      duration_minutes: number;
      modifiers: string[];
    }>;
    organization_id: string; // UUID
  }
  ```
* **Purpose:** Triggers charge creation in PM-07 for approved encounter generations
* **Trigger:** Batch approval action in review UI (single or bulk)

***

## Platform Integration Layer Usage

| Layer                | Import Path               | Usage                                                                                      |
| -------------------- | ------------------------- | ------------------------------------------------------------------------------------------ |
| PF-70 (Code Library) | `@/platform/code-library` | CPT code lookup and validation                                                             |
| PF-96 (Jurisdiction) | `@/platform/jurisdiction` | `useJurisdictionProfile()` for state-variable timed code thresholds and group CPT mappings |
| Platform Clinical    | `@/platform/clinical`     | Group session context, patient context                                                     |
| Platform Scheduling  | `@/platform/scheduling`   | Encounter context for PM encounter creation                                                |

***

## Data Flow

```
CL-14 group note submitted
  → cl_group_session_documented event (existing)
    → CL-14-EN-01 handler:
       1. For each present/partial attendee:
          a. Create pm_encounters record (encounter_type: 'group')
          b. Propose CPT code (PF-96 jurisdiction + group type)
          c. Insert cl_group_encounter_generations row (status: pending_review)
       2. Absent attendees: tracked but no encounter generated
    → Batch review UI (CL-14-EN-01)
       1. Supervisor/billing coordinator reviews generated encounters
       2. Approve → status: approved → publish cl_group_encounters_approved
       3. Reject → status: rejected (with reason); no charge created
    → PM-07 consumes cl_group_encounters_approved
       1. Creates charges per approved generation
       2. Final CPT/modifier/units determined by PM-07 fee schedule
```

***

## Cross-Core References

| Spec                          | Relationship                                                                  |
| ----------------------------- | ----------------------------------------------------------------------------- |
| CL-14                         | Parent spec — group therapy documentation and attendance                      |
| PM-07                         | Downstream — charge capture from approved generations                         |
| PM-08                         | Indirectly downstream — charges flow to claims                                |
| CL-39                         | Integration pattern provider — platform hooks                                 |
| CL-PM-GROUP-SESSIONS.md       | Existing integration contract — extended by this spec                         |
| CL-PM-ENCOUNTER-TO-BILLING.md | Encounter-to-billing pipeline — followed for pm\_encounters schema            |
| PF-96                         | Jurisdiction profiles — state-variable CPT mappings and timed code thresholds |

***

## Security & Compliance

* **RLS:** `cl_group_encounter_generations` has RLS with `pf_has_org_access` SECURITY DEFINER helper
* **42 CFR Part 2:** SUD group encounters inherit Part 2 protections; consent verification before display in batch review
* **PHI Minimization:** Generation tracking stores `patient_id` reference only; no clinical content
* **Permission Keys:** `cl.group-encounter-generation.view`, `.approve`, `.edit`

***

## Related Documents

* [CL-14-EN-01 Spec](../../../specs/cl/specs/CL-14-EN-01-group-note-encounter-charge-generation.md)
* [CL-PM-GROUP-SESSIONS.md](./CL-PM-GROUP-SESSIONS.md)
* [CL-PM-ENCOUNTER-TO-BILLING.md](./CL-PM-ENCOUNTER-TO-BILLING.md)
* [CROSS\_CORE\_INTEGRATIONS.md](./CROSS_CORE_INTEGRATIONS.md)
