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.

Version: 1.0.0 Status: πŸ“ Planned Created: 2026-03-21 Last Updated: 2026-03-21 Constitution Reference: Section 1.3 (Integration Patterns β€” Pattern 1: Platform Integration Layer, Pattern 2: Event-Based)

Overview

This document defines the integration contract between the RH (Recovery Housing) core and the FW (Forms & Workflow) core. RH uses FW for resident intake forms, phase progression approvals, safety event investigation workflows, pass request approvals, compliance automations, and drug testing documentation. Related Specifications:
  • RH-01: Census & Beds (resident admission/discharge)
  • RH-02: Programs & Phases (phase progression, intake/exit forms)
  • RH-03: Safety Events & Compliance (incidents, UDS testing, pass requests)
  • RH-04: Participation & Attendance (attendance threshold monitoring)
  • RH-06: Compliance & Staff Operations (regulatory deadlines)
FW Features Consumed:
  • FW-01/FW-05: Forms (intake assessments, incident reports, UDS documentation, multi-page)
  • FW-03: Automation Engine (compliance reminders, escalation triggers)
  • FW-15: Form Field Lookups (residents, programs, phases, houses/beds)
  • FW-16: Event-Based Workflow Triggers
  • FW-33: Signature Capture (consent forms, pass agreements)
  • FW-34: Approval Workflows (phase progression, pass requests, incident closure)
  • FW-45: Decision Tables (safety event severity routing)
Cross-cutting guide: See FW Cross-Core Integration Guide for shared patterns, platform layer imports, and testing requirements.

Integration Pattern

Primary Pattern: Pattern 1 β€” Platform Integration Layer Secondary Pattern: Pattern 2 β€” Event-Based Integration RH accesses FW capabilities through:
  • @/platform/forms β€” intake assessments, incident reports, phase assessments, exit surveys
  • @/platform/approvals β€” phase progression and pass request approval chains
  • @/platform/events β€” publishing RH events for FW automation triggers
  • @/platform/data-lookup β€” resident, program, phase, and staff lookups in forms
  • @/platform/signatures β€” consent forms and pass agreement signatures
Database FK References: RH programs store direct references to FW forms:
  • rh_programs.intake_form_id β†’ fw_forms.id
  • rh_programs.assessment_form_id β†’ fw_forms.id
  • rh_programs.exit_survey_form_id β†’ fw_forms.id

Event Contracts (RH β†’ FW)

Events published by RH that trigger FW automations and workflows.

RH-01: Resident Lifecycle Events

Event: rh_resident_admitted

Event: rh_resident_admitted Channel: domain_events Publisher: RH (RH-01 Census & Beds) Subscribers: FW-03 (intake workflow), FA (billing trigger), PF-10 (notification) Status: βœ… Implemented (registered in KnownEventName)
Purpose
Triggers intake workflow when a new resident is admitted to a recovery housing program.
Payload Schema
interface RhResidentAdmittedPayload {
  organization_id: string;
  resident_id: string;          // UUID - rh_residents.id
  program_id: string;           // UUID - rh_programs.id
  house_id: string;             // UUID - rh_houses.id
  bed_id?: string;              // UUID - rh_beds.id
  admission_date: string;       // ISO date
  admission_type: string;       // 'new' | 'readmission' | 'transfer'
  referral_source?: string;     // 'self' | 'court' | 'provider' | 'insurance'
  site_id?: string;
  timestamp: string;
}
Consumer Actions
ConsumerActionStatus
FW-03 AutomationTrigger intake workflow (intake form, orientation checklist, initial assessment)πŸ“
FW-03 AutomationSchedule initial phase assessment (date_relative trigger)πŸ“
FACreate billing account / initial invoiceπŸ“
PF-10 NotificationNotify program manager, house manager, case managerπŸ“

Event: rh_resident_discharged

Event: rh_resident_discharged Channel: domain_events Publisher: RH (RH-01 Census & Beds) Subscribers: FW-03 (discharge workflow), FA (final billing), PF-10 (notification) Status: βœ… Implemented (registered in KnownEventName)
Purpose
Triggers discharge workflow when a resident leaves the program.
Payload Schema
interface RhResidentDischargedPayload {
  organization_id: string;
  resident_id: string;
  program_id: string;
  house_id: string;
  bed_id?: string;              // UUID - bed to release
  discharge_date: string;       // ISO date
  discharge_type: string;       // 'completed' | 'ama' | 'administrative' | 'transfer' | 'relapse'
  timestamp: string;
}
Consumer Actions
ConsumerActionStatus
FW-03 AutomationTrigger discharge workflow (exit survey, asset return, room inspection)πŸ“
FW-03 AutomationRelease bed assignmentπŸ“
FAGenerate final invoice, close billingπŸ“
PF-10 NotificationNotify staff, update censusπŸ“

RH-02: Phase Progression Events

Event: rh_phase_advanced

Event: rh_phase_advanced Channel: domain_events Publisher: RH (RH-02 Programs & Phases) Subscribers: FW-03 (new phase automation), PF-10 (notification) Status: βœ… Implemented (registered in KnownEventName)
Purpose
Triggers new-phase automation when a resident advances to the next phase of their program.
Payload Schema
interface RhPhaseAdvancedPayload {
  organization_id: string;
  resident_id: string;
  program_id: string;
  previous_phase_id: string;    // UUID - rh_phases.id
  new_phase_id: string;         // UUID - rh_phases.id
  progression_type: string;     // 'automatic' | 'manual_approved'
  approved_by?: string;         // UUID - approver (if manual)
  timestamp: string;
}
Consumer Actions
ConsumerActionStatus
FW-03 AutomationSchedule phase assessment formπŸ“
FW-03 AutomationUpdate privileges based on new phaseπŸ“
PF-10 NotificationNotify resident, case manager, house managerπŸ“

Event: rh_phase_progression_requested

Event: rh_phase_progression_requested Channel: domain_events Publisher: RH (RH-02 Programs & Phases) Subscribers: FW-34 (phase progression approval chain) Status: πŸ“ Planned (not yet in KnownEventName)
Purpose
Triggers phase progression approval workflow when manual approval is required for phase advancement.
Payload Schema
interface RhPhaseProgressionRequestedPayload {
  organization_id: string;
  resident_id: string;
  program_id: string;
  current_phase_id: string;
  requested_phase_id: string;
  requested_by: string;         // UUID - staff member requesting progression
  assessment_score?: number;    // Phase assessment result
  timestamp: string;
}

RH-03: Safety Event & Compliance Events

Event: rh_safety_event_created

Event: rh_safety_event_created Channel: domain_events Publisher: RH (RH-03 Safety Events) Subscribers: FW-03 (investigation workflow), GR (governance notification), PF-10 (alert) Status: πŸ“ Planned (not yet in KnownEventName)
Purpose
Triggers investigation workflow and escalation based on safety event severity.
Payload Schema
interface RhSafetyEventCreatedPayload {
  organization_id: string;
  safety_event_id: string;      // UUID - rh_safety_events.id
  event_type: string;           // 'significant_event' | 'behavioral' | 'medical' | 'property' | 'other'
  severity: string;             // 'low' | 'medium' | 'high' | 'critical'
  resident_id?: string;         // UUID - involved resident (if applicable)
  house_id: string;
  site_id?: string;
  reported_by: string;          // UUID - staff member
  timestamp: string;
}
Consumer Actions
ConsumerActionStatus
FW-45 Decision TableRoute based on severity (type Γ— severity β†’ response workflow)πŸ“
FW-03 AutomationTrigger investigation workflow (checklist, witness interviews, corrective actions)πŸ“
GRGovernance incident notification (if critical)πŸ“
PF-10 NotificationAlert program manager, compliance officerπŸ“

Event: rh_uds_test_positive

Event: rh_uds_test_positive Channel: domain_events Publisher: RH (RH-03 UDS Testing) Subscribers: FW-03 (relapse plan workflow) Status: πŸ“ Planned (not yet in KnownEventName)
Purpose
Triggers relapse plan workflow when a resident tests positive on a urine drug screen.
Payload Schema
interface RhUdsTestPositivePayload {
  organization_id: string;
  uds_test_id: string;          // UUID - rh_uds_tests.id
  episode_id: string;           // UUID - context for downstream workflows
  tested_at: string;            // ISO 8601 timestamp
  correlation_id?: string;
}
Subscribers must treat this as an identifier-only contract and perform an RH-controlled, consent-gated read (RH-04 EN-4 / Part 2) before loading test detail.
Consumer Actions
ConsumerActionStatus
FW-03 AutomationFetch RH test detail via consent-gated read, then create significant event recordπŸ“
FW-03 AutomationTrigger relapse plan creation workflow after consent-safe detail fetchπŸ“
FW-03 AutomationSchedule follow-up UDS test (date_relative trigger)πŸ“
PF-10 NotificationSend generic positive-UDS alert using identifier-only payloadπŸ“

Event: rh_pass_requested

Event: rh_pass_requested Channel: domain_events Publisher: RH (RH-03 Pass System) Subscribers: FW-34 (pass approval chain) Status: πŸ“ Planned (not yet in KnownEventName)
Purpose
Triggers pass approval workflow when a resident requests a pass (temporary leave from the facility).
Payload Schema
interface RhPassRequestedPayload {
  organization_id: string;
  pass_id: string;              // UUID - rh_passes.id
  resident_id: string;
  pass_type: string;            // 'day' | 'overnight' | 'weekend' | 'extended'
  departure_date: string;
  return_date: string;
  destination: string;          // General area, not specific address
  house_id: string;
  timestamp: string;
}

RH-04: Attendance Events

Event: rh_attendance_threshold_breached

Event: rh_attendance_threshold_breached Channel: domain_events Publisher: RH (RH-04 Participation & Attendance) Subscribers: FW-03 (alert automation), PF-10 (notification) Status: πŸ“ Planned (referenced in EVENT_CONTRACTS.md)
Purpose
Triggers alert workflow when a resident’s attendance drops below the required threshold.
Payload Schema
interface RhAttendanceThresholdBreachedPayload {
  organization_id: string;
  resident_id: string;
  program_id: string;
  activity_type: string;        // 'group' | 'meeting' | 'counseling' | 'community_service'
  attendance_rate: number;       // 0-100 percentage
  threshold: number;             // Required minimum percentage
  period_start: string;
  period_end: string;
  timestamp: string;
}

RH-06: Compliance Events

Event: rh_compliance_deadline_approaching

Event: rh_compliance_deadline_approaching Channel: domain_events Publisher: RH (RH-06 Compliance & Staff Operations) Subscribers: FW-03 (reminder automation) Status: πŸ“ Planned (not yet in KnownEventName)
Purpose
Triggers reminder automation when a regulatory compliance deadline approaches (e.g., fire inspection, license renewal, staff training).
Payload Schema
interface RhComplianceDeadlinePayload {
  organization_id: string;
  compliance_item_id: string;
  compliance_type: string;      // 'fire_inspection' | 'license_renewal' | 'staff_training' | 'audit'
  deadline_date: string;
  days_until_deadline: number;
  house_id?: string;
  site_id?: string;
  timestamp: string;
}
Consumer Actions
ConsumerActionStatus
FW-03 AutomationSend reminders at 90/60/30/7 days (date_relative trigger)πŸ“
PF-10 NotificationAlert compliance officer, program managerπŸ“

Approval Chain Configurations

Phase Progression Approval

Chain ID: rh-phase-progression-approval Entity Type: rh_phase_progressions Based On: RH-02
StepApprover TypeConditionTimeoutEscalation
1role: house_managerAlways48hrole: program_manager
2role: program_managerCritical phases (e.g., final phase)72hrole: program_director

Pass Request Approval

Chain ID: rh-pass-request-approval Entity Type: rh_passes Based On: RH-03
StepApprover TypeConditionTimeoutEscalation
1role: housing_techAlways (initial screening)24hrole: house_manager
2role: house_managerAlways24hrole: program_manager
3role: program_managerOvernight or extended passes48hrole: program_director
Decision Table for Routing:
Pass TypeResident Risk Level→ Approval Steps
DayLowHousing Tech β†’ House Manager
DayHighHousing Tech β†’ House Manager β†’ Program Manager
OvernightAnyHousing Tech β†’ House Manager β†’ Program Manager
WeekendAnyHousing Tech β†’ House Manager β†’ Program Manager
ExtendedAnyHousing Tech β†’ House Manager β†’ Program Manager β†’ Program Director

Safety Event Investigation Closure

Chain ID: rh-safety-event-closure-approval Entity Type: rh_safety_events Based On: RH-03
StepApprover TypeConditionTimeoutEscalation
1role: investigator (assigned)Always7 business daysrole: program_manager
2role: program_managerAlways3 business daysrole: compliance_officer
3role: compliance_officerCritical severity3 business daysrole: program_director

Discharge Approval

Chain ID: rh-discharge-approval Entity Type: rh_discharges Based On: RH-01
StepApprover TypeConditionTimeoutEscalation
1role: case_managerAlways48hrole: program_manager
2role: program_directorAdministrative or involuntary discharge72hβ€”

Decision Tables

Safety Event Severity Routing

Table ID: rh-safety-event-severity-routing Hit Policy: FIRST
Event TypeSeverity→ Response Workflow
AnyCriticalImmediate escalation β†’ Program Director + Compliance + GR notification
MedicalHighMedical response β†’ Nurse notification β†’ Investigation
BehavioralHighBehavioral intervention β†’ Case manager β†’ Investigation
PropertyAnyProperty report β†’ House manager β†’ Maintenance
Significant EventMediumInvestigation β†’ Case manager β†’ Corrective action plan
Significant EventLowDocumentation β†’ House manager review
AnyLowDocumentation only

Pass Approval Routing

Table ID: rh-pass-approval-routing Hit Policy: FIRST
Pass DurationResident PhaseRisk Level→ Approval Chain
Day (< 12h)Phase 3+LowHousing Tech only
Day (< 12h)Phase 1-2AnyHousing Tech β†’ House Manager
OvernightPhase 3+LowHousing Tech β†’ House Manager
OvernightAnyHighHousing Tech β†’ House Manager β†’ Program Manager
WeekendAnyAnyHousing Tech β†’ House Manager β†’ Program Manager
Extended (> 3 days)AnyAnyFull chain (Housing Tech β†’ House Manager β†’ PM β†’ PD)

Form Templates

Existing Templates

Template IDTypeSpec LocationDescription
gr-incident-report-formFormspecs/fw/templates/forms/gr-incident-report-form.mdSafety event / incident reporting
gr-incident-notificationWorkflowspecs/fw/templates/workflows/gr-incident-notification.mdIncident escalation and notification
gr-incident-report-bundleBundlespecs/fw/templates/bundles/gr-incident-report-bundle.mdForm + notification workflow

Planned Form Templates

Template IDPriorityDescription
rh-intake-assessment-formP0Multi-page intake form (demographics, history, needs assessment)
rh-phase-assessment-formP1Phase transition assessment with scoring
rh-exit-survey-formP1Discharge exit survey
rh-uds-test-formP1UDS test documentation (date, result, witness)
rh-pass-request-formP1Pass request with destination, dates, emergency contact
rh-room-inspection-formP2Room inspection checklist
rh-house-meeting-notes-formP2House meeting agenda and notes
rh-relapse-plan-formP2Relapse prevention plan documentation

Workflow Templates

Template IDPriorityDescription
rh-resident-intakeP0Admission β†’ intake form β†’ orientation β†’ initial assessment β†’ bed assignment
rh-discharge-planningP1Discharge request β†’ approval β†’ exit survey β†’ room inspection β†’ billing close
rh-phase-progressionP1Assessment β†’ score evaluation β†’ approval chain β†’ phase update β†’ privilege update
rh-incident-investigationP1Report β†’ assign investigator β†’ checklist β†’ witness interviews β†’ corrective action β†’ closure approval
rh-pass-approvalP1Request β†’ risk assessment β†’ approval chain β†’ notification β†’ return check-in
rh-compliance-reminderP2Deadline monitoring β†’ reminders at 90/60/30/7 days β†’ escalation

Form Field Lookups

RH exposes these data sources for FW form field lookups (FW-15):
Lookup SourceTableValue ColumnLabel ColumnFilterUsed By
Residentsrh_residentsiddisplay_namestatus = 'active'Incident forms, UDS forms
Programsrh_programsidnamestatus = 'active'Intake, assessment forms
Phasesrh_phasesidnameprogram_idPhase assessment forms
Housesrh_housesidnamestatus = 'active'Incident forms, inspection forms
Bedsrh_bedsidbed_numberhouse_id, status = 'available'Intake form
Staffhr_employeesidfull_nameis_active = trueInvestigation assignment
Incident Types(enum/picklist)valuelabelβ€”Incident report form

Database References (RH β†’ FW)

RH programs have direct FK references to FW forms:
-- rh_programs table references fw_forms for associated forms
ALTER TABLE rh_programs
  ADD COLUMN intake_form_id UUID REFERENCES fw_forms(id),
  ADD COLUMN assessment_form_id UUID REFERENCES fw_forms(id),
  ADD COLUMN exit_survey_form_id UUID REFERENCES fw_forms(id);
When a program is configured, the admin selects which FW forms to use for:
  • Intake: Filled during resident admission (RH-01)
  • Assessment: Filled during phase transition evaluation (RH-02)
  • Exit Survey: Filled during discharge (RH-01)

Platform Layer Usage

Hooks RH Components Import

// Forms
import { useFormTemplate, FormRenderer } from '@/platform/forms';

// Approvals
import { useSubmitApprovalRequest, useMyApprovalRequests } from '@/platform/approvals';

// Events
import { publishEvent } from '@/platform/events';
import type { KnownEventName } from '@/platform/events';

// Data lookups for form fields
import { useLookupOptions } from '@/platform/data-lookup';

// Signatures for consent forms
import { SignatureCapture, useFormSignature } from '@/platform/signatures';

Testing Requirements

Unit Tests

  • RH event payloads match documented schemas
  • Safety event severity decision table returns correct response workflow
  • Pass approval routing decision table handles all phase Γ— risk combinations
  • No PII/PHI in event payloads (resident names, DOBs, substance details)

Integration Tests

  • rh_resident_admitted event triggers intake workflow in FW
  • rh_phase_progression_requested event routes to phase approval chain
  • rh_safety_event_created event routes through severity decision table
  • rh_pass_requested event routes through pass approval chain
  • Phase assessment form linked to program via rh_programs.assessment_form_id
  • Form field lookups return correct residents, programs, houses

E2E Tests

  • Complete intake flow: admission β†’ intake form β†’ orientation β†’ assessment β†’ bed assignment
  • Phase progression flow: assessment β†’ score β†’ approval β†’ phase update β†’ privilege change
  • Incident flow: report β†’ severity routing β†’ investigation β†’ corrective action β†’ closure approval
  • Pass flow: request β†’ risk assessment β†’ approval chain β†’ departure β†’ return check-in
  • Discharge flow: request β†’ approval β†’ exit survey β†’ room inspection β†’ billing close

RLS Tests

  • RH events filtered by organization_id
  • Approval requests scoped to submitter’s organization
  • Form submissions isolated per tenant
  • Resident lookups filtered by organization

Implementation Status

IntegrationStatusNotes
RH events in KnownEventNameβœ… Partialrh_resident_admitted, rh_resident_discharged, rh_phase_advanced, rh_bed_assigned/released registered; safety, pass, compliance events pending
Intake workflowπŸ“ PlannedProgram β†’ form FK linkage exists; workflow template needed
Phase progression approvalπŸ“ PlannedEvents and chain not yet registered
Pass request approvalπŸ“ PlannedEvents, chain, and decision table needed
Safety event workflowπŸ“ PlannedEvents, severity decision table, and investigation workflow needed
Incident report formβœ… ReadyGR incident report form template exists
Compliance remindersπŸ“ Planneddate_relative automation trigger needed
Form field lookupsπŸ“ PlannedRH table lookup configs not yet registered
Discharge workflowπŸ“ PlannedTemplate and approval chain needed