Skip to main content

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.

Spec: CL-39-platform-integration-layer-implementation.md Status: ✅ Complete Last Updated: 2026-03-29

Overview

CL-39 implements 5 core platform hooks that provide cross-core data access without direct CL↔PM imports per constitution §1.3. CL-41 adds billing override composition (useBillingOverrides, applyBillingOverrides, useBillingWithOverrides) that reads pm_billing_suggestion_rules and layers on top of useBillingAdapter—listed in the table below for a single integration view (6 hook rows total: five CL-39 + CL-41 composition).
HookLocationPatternConsumers
usePatientContext(chartId)@/platform/clinicalReact Query (read)PM-10, PM-12, CL-16, CL-13
useEncounterContext(encounterId)@/platform/schedulingReact Query (read)CL-04, CL-14, PM-07, PM-14
useBillingAdapter(input)@/platform/clinicalReact Query (pure logic)CL-04, CL-14, CL-13, PM-07
useBillingOverrides / useBillingWithOverrides@/platform/clinicalReact Query (read PM rules) + mergeCL-41; CL-04, CL-14 when wired
useDocumentExport()@/platform/clinicalReact MutationCL-16, CL-20, PM (claims attachments)
useExportStatus(exportId)@/platform/clinicalReact Query (polling)CL-16, CL-20

Platform Layer Usage

  • @/platform/clinical — Barrel export from src/platform/clinical/index.ts
  • @/platform/scheduling — Barrel export from src/platform/scheduling/index.ts
  • @/platform/types — Shared types: PatientContext, EncounterContextHookRow, BillingInput, BillingSuggestion, DocumentExportRequest, DocumentExportResult

Integration Points

Data Sources (Read)

HookTablesAccess Pattern
usePatientContextcl_patient_charts, cl_problems, cl_risk_screenings, cl_consentsSupabase RLS; parallel selects by chart_id + organization_id
useEncounterContextpm_encounters, pm_appointments, pf_profilesSupabase nested .select() join; FK per ADR-002
useDocumentExportcl_data_exchange_log (write)Wraps CL-20 export backend; writes audit row
useExportStatuscl_data_exchange_log (read)Single row by id

Dependencies

DependencyRole
CL-11 useConsentCheckConsent gate for all exports
CL-20 export backendDocument generation logic wrapped by useDocumentExport
ADR-002FK exception for pm_encounters.id references from CL

Event Contracts

No new events published or consumed. CL-39 hooks are synchronous React Query hooks.

API Contracts

No edge functions or REST APIs. All hooks are client-side React Query integrations.

Security

  • All DB-backed hooks enforce RLS via Supabase client (no service-role keys from browser)
  • PHI (demographics, diagnoses, risk level) accessed only through usePatientContext; never logged as raw field values
  • Export signed URLs: 15-minute TTL (EXPORT_URL_TTL_MINUTES)
  • Error sanitization: sanitizeErrorMessage on all error paths
  • Consent gate: useConsentCheck (CL-11) enforced before any export

Contract Validation Checklist

  • All CL-39 hooks (and CL-41 override hooks where in scope) exported from barrel files
  • Shared types in @/platform/types (no duplication in cores)
  • npm run check-architecture passes (0 cross-core violations)
  • RLS cross-org isolation verified (npm run test:rls)
  • Billing adapter unit tests cover all CPT mapping scenarios
  • Export audit log written to cl_data_exchange_log

References