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

# Clinical Decision Support — Integration

> Feature ID: CL-08 Status: 📝 Planned Spec Reference: CL-08-clinical-decision-support.md Last Updated: 2026-02-18

**Feature ID:** CL-08\
**Status:** 📝 Planned\
**Spec Reference:** [CL-08-clinical-decision-support.md](../../../specs/cl/specs/CL-08-clinical-decision-support.md)\
**Last Updated:** 2026-02-18

***

## Table of Contents

* [Overview](#overview)
* [Quick Reference](#quick-reference)
* [Integration Points (from Spec)](#integration-points-from-spec)
* [API / Data Contracts](#api--data-contracts)
* [Event Contracts](#event-contracts)
* [Security and RLS](#security-and-rls)
* [Related Docs](#related-docs)

***

## Overview

CL-08 provides clinical decision support (CDS): drug-drug and drug-allergy alerts, medication monitoring reminders (e.g. lithium, clozapine), documentation completeness and overdue alerts, and quality measure gap detection (HEDIS: FUH, FUM, IET, AMM). Alerts are configurable per organization (severity, hard stop vs soft), with override tracking for alert fatigue management. Delivery uses PF-10 (notifications).

***

## Quick Reference

| Category                 | Value                                                                                                                                                                                                                                          |
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Tables**               | `cl_cds_rules`, `cl_cds_alerts`                                                                                                                                                                                                                |
| **Rule types**           | drug\_interaction, drug\_allergy, monitoring, documentation, quality\_measure, custom                                                                                                                                                          |
| **Trigger events**       | medication\_add, prescription\_submit, document\_save, chart\_open, assessment\_due, quality\_measure\_eval                                                                                                                                    |
| **Condition/action**     | JSONB structure per spec Errata E-3 (CdsRuleCondition, CdsRuleAction)                                                                                                                                                                          |
| **RLS helpers**          | `cl_has_org_access(organization_id)`; rule CRUD via `cl_can_manage_cds_rules(organization_id, auth.uid())` — delegates to `pf_is_org_admin(user, org)` at SQL level; finer-grained access (compliance role) via PF-30 permissions at app layer |
| **SECURITY DEFINER**     | `create_cl_cds_rule()`, `acknowledge_cl_cds_alert()`, `override_cl_cds_alert()` — `SET search_path = public`                                                                                                                                   |
| **Notification pattern** | Direct insert into `pf_notifications` (client-side with org\_id filter) or via `createNotificationIfNew()` from `supabase/functions/_shared/` in edge functions                                                                                |

***

## Integration Points (from Spec)

| Dependency                    | Pattern     | Purpose                                                                                                                                               |
| ----------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| CL-01 (Patient Chart)         | Data        | Alerts scoped to chart; `cl_cds_alerts.chart_id` → `cl_patient_charts.id`                                                                             |
| CL-05 (Medication Management) | API         | Drug interaction checking from medication list; CDS evaluates at medication add/reconciliation                                                        |
| CL-06 (E-Prescribing)         | API         | Prescribing alerts during e-prescribing workflow (e.g. at prescription\_submit)                                                                       |
| CL-10 (Outcomes Tracking)     | API / Data  | Quality measure gap data; CL-08 rules consume or react to HEDIS gap data from CL-10 or platform measure logic. Exact contract (events/APIs) TBD here. |
| PF-10 (Notifications)         | Event / API | Alert delivery via notifications system (in-app; email/push per PF-10)                                                                                |
| PF-70 (Code Libraries)        | API         | ICD-10-CM, CPT, HCPCS, LOINC for rule conditions and display (e.g. lab LOINC in monitoring rules)                                                     |

**Drug interaction data source:** CL-05/CL-06/CL-08 do not specify the interaction database (First Databank, Medi-Span, RxNav/NLM, etc.). Per CL-PM-SPEC-REVIEW: define data source and update process in a PF-level or CL-08 integration contract. CL-05 integration doc currently references RxNav/NLM for MVP with interface abstracted for future FDB swap; CL-08 should use the same abstraction.

***

## API / Data Contracts

### `cl_cds_rules`

* **Scope:** `organization_id`; rule types and trigger\_event per spec Data Model.
* **Condition/action:** JSONB schemas per spec Errata E-3.
* **Audit:** `created_at`, `updated_at`; add `created_by`, `updated_by` per Errata E-1.
* **Custom fields:** `custom_fields JSONB NOT NULL DEFAULT '{}'`.

### `cl_cds_alerts`

* **Scope:** `organization_id`, `chart_id`; optional `rule_id` linking to rule that fired.
* **Lifecycle:** triggered\_at → acknowledged\_by/acknowledged\_at; overridden + override\_reason when user proceeds despite alert.
* **Audit:** `created_at`, `updated_at`; add `created_by`, `updated_by` per Errata E-1.

### CDS invocation (inbound)

* **Callers:** CL-05 (medication list + allergies → interaction check), CL-06 (prescription submit → interaction/allergy check), documentation/chart flows (documentation\_gap, quality\_measure\_eval).
* **Response:** List of alerts with severity and is\_hard\_stop; caller blocks or shows modal per config.

### Outbound to PF-10

* **Payload:** Alert title, message, severity, chart\_id, user context; optional deep link to chart/medication.
* **When:** On insert of `cl_cds_alerts` (or via application logic that creates alert then notifies).

***

## Event Contracts

| Event                 | Channel     | Direction            | Purpose                                                                                                             |
| --------------------- | ----------- | -------------------- | ------------------------------------------------------------------------------------------------------------------- |
| `cds_alert_triggered` | `cl_events` | CL-08 → PF-10, PF-04 | Alert created; triggers in-app notification via direct `pf_notifications` insert and audit log                      |
| `cds_rule_overridden` | `cl_events` | CL-08 → PF-10, PF-04 | Alert overridden with reason; audit event for compliance review                                                     |
| (TBD)                 | `cl_events` | CL-10 → CL-08        | Quality measure gap data available for CDS rules (optional; may be pull/API). Blocked until CL-10 Phase 1 complete. |

**Registration:** Both `cds_alert_triggered` and `cds_rule_overridden` must be inserted into `fw_workflow_events` with `category = 'operational'` during Phase 1 migration.

***

## Security and RLS

* **RLS:** Enabled on `cl_cds_rules` and `cl_cds_alerts`; org isolation via `cl_has_org_access(organization_id)` (per Errata E-2). Do not use `current_setting('app.current_org')`.
* **Rule CRUD:** Restrict INSERT/UPDATE/DELETE on `cl_cds_rules` to users with org access and permitted role (e.g. admin, compliance) via SECURITY DEFINER helper `cl_can_manage_cds_rules(organization_id, auth.uid())`.
* **Alerts:** SELECT/UPDATE for clinicians in same org; UPDATE for acknowledgement/override only (clinician or prescriber roles). Compliance may manage rules; may have read-only access to alert history for audit.
* **SECURITY DEFINER:** All helpers use `SET search_path = public`. UPDATE policies include WITH CHECK (§5.2.4).

***

## Related Docs

* [CL-08 Spec](../../../specs/cl/specs/CL-08-clinical-decision-support.md)
* [CL-05 Medication Management Integration](./medication-management-integration.md) — drug interaction request/response
* [CL-06 E-Prescribing Integration](./e-prescribing-epcs-integration.md) — prescribing-time CDS
* [CROSS\_CORE\_INTEGRATIONS](./CROSS_CORE_INTEGRATIONS.md) — matrix entry for CL-08
