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

# Accreditation Tracer Readiness Integration Contracts

> Version: 1.0 Last Updated: 2026-03-07 Status: 📝 Planned Spec Reference: GR-16-accreditation-tracer-readiness.md Constitution Reference: Section 1.3 (Integrati…

**Version:** 1.0\
**Last Updated:** 2026-03-07\
**Status:** 📝 Planned\
**Spec Reference:** [GR-16-accreditation-tracer-readiness.md](../../../specs/gr/specs/GR-16-accreditation-tracer-readiness.md)\
**Constitution Reference:** Section 1.3 (Integration Patterns)

***

## Overview

GR-16 integrates intra-core (GR) and with Platform Foundation (PF) layers. It does **not** integrate directly with any other non-PF core. All cross-core data is accessed via PF platform layers.

***

## Integration Summary

| Integration                 | Pattern                         | Direction                                       | Status     |
| --------------------------- | ------------------------------- | ----------------------------------------------- | ---------- |
| GR-08 (Accreditation Mgmt)  | Data / FK — tables in same core | GR-16 reads GR-08 tables                        | 📝 Planned |
| PF-11 (Documents)           | Platform Layer                  | GR-16 → PF-11 (document bundle export)          | 📝 Planned |
| PF-12 (Reporting)           | Platform Layer                  | GR-16 → PF-12 (readiness score report)          | 📝 Planned |
| PF-27 (Platform AI)         | Platform Layer                  | GR-16 → PF-27 (surveyor question simulator)     | 📝 Planned |
| PF-10 (Notifications)       | Platform Layer                  | GR-16 → PF-10 (CAP deadline alerts)             | 📝 Planned |
| GR-03 (Compliance Tracking) | Data — same core; query only    | GR-16 reads compliance records for gap evidence | 📝 Planned |
| GR-01 (Policy Management)   | Data — same core; query only    | GR-16 reads policy currency for readiness score | 📝 Planned |
| GR-09 (Incident Reporting)  | Data — same core; query only    | GR-16 reads incident rates for readiness score  | 📝 Planned |
| GR-07 (Quality Improvement) | Data — same core; query only    | GR-16 reads QI project data for readiness score | 📝 Planned |

***

## Platform Layer Usage

### PF-11 (Documents) — Tracer Pack Export

**Layer:** `@/platform/documents`\
**Purpose:** Creates a document bundle for tracer pack export.\
**API:**

```typescript theme={null}
import { useCreateDocumentBundle } from '@/platform/documents';

// Called when coordinator clicks "Export Pack"
const { mutate: createBundle } = useCreateDocumentBundle();
createBundle({
  organization_id,
  title: `Tracer Pack - ${domain}`,
  document_ids: evidenceDocumentIds,
  format: 'zip', // or 'navigable'
});
// Returns document_id which is stored on gr_accreditation_tracer_packs.document_id
```

**Tenant Isolation:** Enforced by PF-11 platform layer; passes `organization_id`.

***

### PF-27 (Platform AI) — Surveyor Question Simulator

**Layer:** `@/platform/ai`\
**Purpose:** Generates 3–5 likely surveyor questions for a given accreditation standard.\
**API:**

```typescript theme={null}
import { usePlatformAI } from '@/platform/ai';

// Called when coordinator invokes AI question simulator
const { mutate: generateQuestions } = usePlatformAI('accreditation-surveyor-questions');
generateQuestions({
  prompt_context: {
    standard_title: standard.title,
    standard_domain: standard.domain,
    evidence_summary: evidenceSummary,
  },
});
// Returns: { questions: string[], guidance: string[] }
```

**PHI Guardrail:** Do NOT pass patient-identifying data (names, DOBs, record IDs) to the AI prompt. Pass only standard metadata and evidence summary (counts, dates, domains).

***

### PF-12 (Reporting) — Readiness Score Report

**Layer:** `@/platform/reports`\
**Purpose:** Generates board-level readiness score report with trend data.\
**API:**

```typescript theme={null}
import { useGenerateReport } from '@/platform/reports';
```

**Output:** PDF/Excel report suitable for board meeting.

***

### PF-10 (Notifications) — CAP Deadline Alerts

**Layer:** `@/platform/notifications`\
**Purpose:** Sends deadline notifications to `responsible_party_id` and org admins.\
**Trigger:** Edge function `gr-cap-deadline-alerts` (daily cron).

**Notification payload (CAP due):**

```typescript theme={null}
{
  type: 'gr.cap.deadline_approaching',
  organization_id: string,
  recipient_id: string, // responsible_party_id
  metadata: {
    cap_id: string,
    cap_title: string,
    target_closure_date: string, // ISO date
    days_remaining: number,
    accreditation_name: string,
  }
}
```

**Notification payload (CAP overdue):**

```typescript theme={null}
{
  type: 'gr.cap.overdue',
  organization_id: string,
  recipient_id: string,
  metadata: {
    cap_id: string,
    cap_title: string,
    target_closure_date: string,
    days_overdue: number,
    accreditation_name: string,
  }
}
```

***

## Edge Function Contract

### `gr-cap-deadline-alerts`

**Function:** `/supabase/functions/gr-cap-deadline-alerts/index.ts`\
**Schedule:** Daily at 08:00 UTC (`0 8 * * *`)\
**Invocation:** Cron (server-to-server); `verify_jwt: false`\
**Auth:** Service role key; no JWT verification (cron invocation only)

**Processing logic:**

1. Load `gr_module_settings.cap_alert_lead_days` per org
2. Query `gr_accreditation_caps WHERE status <> 'verified_closed' AND target_closure_date <= now() + (cap_alert_lead_days || ' days')::INTERVAL`
3. For each CAP: send `gr.cap.deadline_approaching` notification via PF-10
4. For overdue CAPs (target\_closure\_date \< today): send `gr.cap.overdue` notification
5. Log results; retry failed notifications up to 3 times

**CORS:** Uses `getCorsHeaders(req.headers.get('origin'))` from `_shared/cors.ts`\
**Logger:** `createLogger('gr-cap-deadline-alerts')` from `_shared/logger.ts`

***

## Intra-Core Data Dependencies (GR-08 Tables)

GR-16 reads from GR-08 tables via direct DB queries (same core, not cross-core):

| Table                        | Usage                                               | Access Pattern                                        |
| ---------------------------- | --------------------------------------------------- | ----------------------------------------------------- |
| `gr_accreditations`          | FK target for tracer packs, CAPs, mock surveys      | Read via Supabase query with `organization_id` filter |
| `gr_accreditation_standards` | FK target for CAPs; source for gap analysis         | Read query                                            |
| `gr_accreditation_evidence`  | Source for tracer pack assembly and gap computation | Read query (evidence count, dates, quality rating)    |

**RLS:** All reads use existing GR-08 RLS policies; no policy changes to GR-08 tables required.

***

## Contract Validation Checklist

* [x] Integration doc exists at canonical path
* [x] All integration points from spec covered
* [x] PF-11 document bundle creation API documented with tenant isolation note
* [x] PF-27 AI prompt interface documented with PHI guardrail
* [x] PF-10 notification payloads defined
* [x] Edge function documented with `verify_jwt`, CORS, logger
* [x] Integration matrix updated in `CROSS_CORE_INTEGRATIONS.md`
* [ ] Event types added to `KnownEventName` in `src/platform/events/types.ts` (if events published — N/A; GR-16 does not publish events)

***

## Cross-Core Integration Matrix Entry

Add to `docs/architecture/integrations/CROSS_CORE_INTEGRATIONS.md`:

```markdown theme={null}
| GR-16 | GR-08, PF-11, PF-12, PF-27, PF-10 | Platform Layer + Intra-core | 📝 | GR-16-accreditation-tracer-readiness-INTEGRATION.md — Tracer packs, CAP lifecycle, mock surveys; PF-11 export, PF-27 AI, PF-10 alerts |
```
