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

# Behavioral Health Program Scheduling Templates — Integration

> Feature ID: CL-27 Status: ✅ Implemented Spec Reference: CL-27-behavioral-health-program-scheduling-templates.md Last Updated: 2026-02-25

**Feature ID:** CL-27\
**Status:** ✅ Implemented\
**Spec Reference:** [CL-27-behavioral-health-program-scheduling-templates.md](../../../specs/cl/specs/CL-27-behavioral-health-program-scheduling-templates.md)\
**Last Updated:** 2026-02-25

***

## Overview

CL-27 defines program schedule templates (IOP, PHP, residential, outpatient), patient program enrollment, group session auto-creation from templates, attendance compliance, and conflict detection with individual appointments. Integrations: CL-14 (group sessions), PM-03/PM-04 (scheduling), RH (census).

***

## Integration Points (from Spec)

| Dependency                | Pattern              | Purpose                                                                       |
| ------------------------- | -------------------- | ----------------------------------------------------------------------------- |
| CL-14 (Group Therapy)     | Internal / Event     | Group sessions created from program templates; attendance may feed from CL-14 |
| PM-03, PM-04 (Scheduling) | Platform Layer / API | Appointments and scheduling; conflict check with program blocks               |
| RH (Recovery Housing)     | Event / Data         | Residential census and program alignment                                      |

***

## API / Data Contracts

* **CL-14 session creation:** `useProgramSessionGeneration` hook reads `schedule_definition.blocks` where `service_type === 'group'`, inserts into `cl_group_sessions` with `custom_fields.program_schedule_id` for linkage. Fire-and-forget; exception dates skipped. Batch insert for N weeks.
* **PM-03/PM-04 conflict check:** Deferred to PM-03/PM-04 implementation. When available, query PM schedule for patient appointments overlapping program blocks and surface warning in enrollment dialog.

***

## Event Contracts

* **Deferred:** Events for program enrollment start/end or template changes to be added when workflow automation (FW-16) consumes them. No events published in MVP.

***

## Security and RLS

* All CL-27 tables use `organization_id` (and `site_id` on `cl_program_schedules`); RLS via SECURITY DEFINER (e.g. `cl_has_org_access`); UPDATE policies include WITH CHECK (§5.2.4). Enrollment/chart linkage is PHI; no RLS policy may query RLS-protected tables directly (§5.7).

***

## Related Docs

* [CL-14-group-therapy-documentation-INTEGRATION.md](./group-therapy-documentation-integration.md)
* [CL-PM-GROUP-SESSIONS.md](./CL-PM-GROUP-SESSIONS.md) — PM-04 / CL-14 group scheduling
* [CROSS\_CORE\_INTEGRATIONS.md](./CROSS_CORE_INTEGRATIONS.md) — Integration matrix
