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
| Consumer | Action | Status |
|---|
| FW-03 Automation | Trigger intake workflow (intake form, orientation checklist, initial assessment) | π |
| FW-03 Automation | Schedule initial phase assessment (date_relative trigger) | π |
| FA | Create billing account / initial invoice | π |
| PF-10 Notification | Notify 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
| Consumer | Action | Status |
|---|
| FW-03 Automation | Trigger discharge workflow (exit survey, asset return, room inspection) | π |
| FW-03 Automation | Release bed assignment | π |
| FA | Generate final invoice, close billing | π |
| PF-10 Notification | Notify 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
| Consumer | Action | Status |
|---|
| FW-03 Automation | Schedule phase assessment form | π |
| FW-03 Automation | Update privileges based on new phase | π |
| PF-10 Notification | Notify 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
| Consumer | Action | Status |
|---|
| FW-45 Decision Table | Route based on severity (type Γ severity β response workflow) | π |
| FW-03 Automation | Trigger investigation workflow (checklist, witness interviews, corrective actions) | π |
| GR | Governance incident notification (if critical) | π |
| PF-10 Notification | Alert 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
| Consumer | Action | Status |
|---|
| FW-03 Automation | Fetch RH test detail via consent-gated read, then create significant event record | π |
| FW-03 Automation | Trigger relapse plan creation workflow after consent-safe detail fetch | π |
| FW-03 Automation | Schedule follow-up UDS test (date_relative trigger) | π |
| PF-10 Notification | Send 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
| Consumer | Action | Status |
|---|
| FW-03 Automation | Send reminders at 90/60/30/7 days (date_relative trigger) | π |
| PF-10 Notification | Alert 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
| Step | Approver Type | Condition | Timeout | Escalation |
|---|
| 1 | role: house_manager | Always | 48h | role: program_manager |
| 2 | role: program_manager | Critical phases (e.g., final phase) | 72h | role: program_director |
Pass Request Approval
Chain ID: rh-pass-request-approval
Entity Type: rh_passes
Based On: RH-03
| Step | Approver Type | Condition | Timeout | Escalation |
|---|
| 1 | role: housing_tech | Always (initial screening) | 24h | role: house_manager |
| 2 | role: house_manager | Always | 24h | role: program_manager |
| 3 | role: program_manager | Overnight or extended passes | 48h | role: program_director |
Decision Table for Routing:
| Pass Type | Resident Risk Level | β Approval Steps |
|---|
| Day | Low | Housing Tech β House Manager |
| Day | High | Housing Tech β House Manager β Program Manager |
| Overnight | Any | Housing Tech β House Manager β Program Manager |
| Weekend | Any | Housing Tech β House Manager β Program Manager |
| Extended | Any | Housing 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
| Step | Approver Type | Condition | Timeout | Escalation |
|---|
| 1 | role: investigator (assigned) | Always | 7 business days | role: program_manager |
| 2 | role: program_manager | Always | 3 business days | role: compliance_officer |
| 3 | role: compliance_officer | Critical severity | 3 business days | role: program_director |
Discharge Approval
Chain ID: rh-discharge-approval
Entity Type: rh_discharges
Based On: RH-01
| Step | Approver Type | Condition | Timeout | Escalation |
|---|
| 1 | role: case_manager | Always | 48h | role: program_manager |
| 2 | role: program_director | Administrative or involuntary discharge | 72h | β |
Decision Tables
Safety Event Severity Routing
Table ID: rh-safety-event-severity-routing
Hit Policy: FIRST
| Event Type | Severity | β Response Workflow |
|---|
| Any | Critical | Immediate escalation β Program Director + Compliance + GR notification |
| Medical | High | Medical response β Nurse notification β Investigation |
| Behavioral | High | Behavioral intervention β Case manager β Investigation |
| Property | Any | Property report β House manager β Maintenance |
| Significant Event | Medium | Investigation β Case manager β Corrective action plan |
| Significant Event | Low | Documentation β House manager review |
| Any | Low | Documentation only |
Pass Approval Routing
Table ID: rh-pass-approval-routing
Hit Policy: FIRST
| Pass Duration | Resident Phase | Risk Level | β Approval Chain |
|---|
| Day (< 12h) | Phase 3+ | Low | Housing Tech only |
| Day (< 12h) | Phase 1-2 | Any | Housing Tech β House Manager |
| Overnight | Phase 3+ | Low | Housing Tech β House Manager |
| Overnight | Any | High | Housing Tech β House Manager β Program Manager |
| Weekend | Any | Any | Housing Tech β House Manager β Program Manager |
| Extended (> 3 days) | Any | Any | Full chain (Housing Tech β House Manager β PM β PD) |
Existing Templates
| Template ID | Type | Spec Location | Description |
|---|
gr-incident-report-form | Form | specs/fw/templates/forms/gr-incident-report-form.md | Safety event / incident reporting |
gr-incident-notification | Workflow | specs/fw/templates/workflows/gr-incident-notification.md | Incident escalation and notification |
gr-incident-report-bundle | Bundle | specs/fw/templates/bundles/gr-incident-report-bundle.md | Form + notification workflow |
| Template ID | Priority | Description |
|---|
rh-intake-assessment-form | P0 | Multi-page intake form (demographics, history, needs assessment) |
rh-phase-assessment-form | P1 | Phase transition assessment with scoring |
rh-exit-survey-form | P1 | Discharge exit survey |
rh-uds-test-form | P1 | UDS test documentation (date, result, witness) |
rh-pass-request-form | P1 | Pass request with destination, dates, emergency contact |
rh-room-inspection-form | P2 | Room inspection checklist |
rh-house-meeting-notes-form | P2 | House meeting agenda and notes |
rh-relapse-plan-form | P2 | Relapse prevention plan documentation |
Workflow Templates
Planned Workflow Templates (From Recommended Templates)
| Template ID | Priority | Description |
|---|
rh-resident-intake | P0 | Admission β intake form β orientation β initial assessment β bed assignment |
rh-discharge-planning | P1 | Discharge request β approval β exit survey β room inspection β billing close |
rh-phase-progression | P1 | Assessment β score evaluation β approval chain β phase update β privilege update |
rh-incident-investigation | P1 | Report β assign investigator β checklist β witness interviews β corrective action β closure approval |
rh-pass-approval | P1 | Request β risk assessment β approval chain β notification β return check-in |
rh-compliance-reminder | P2 | Deadline monitoring β reminders at 90/60/30/7 days β escalation |
RH exposes these data sources for FW form field lookups (FW-15):
| Lookup Source | Table | Value Column | Label Column | Filter | Used By |
|---|
| Residents | rh_residents | id | display_name | status = 'active' | Incident forms, UDS forms |
| Programs | rh_programs | id | name | status = 'active' | Intake, assessment forms |
| Phases | rh_phases | id | name | program_id | Phase assessment forms |
| Houses | rh_houses | id | name | status = 'active' | Incident forms, inspection forms |
| Beds | rh_beds | id | bed_number | house_id, status = 'available' | Intake form |
| Staff | hr_employees | id | full_name | is_active = true | Investigation assignment |
| Incident Types | (enum/picklist) | value | label | β | 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)
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
Integration Tests
E2E Tests
RLS Tests
Implementation Status
| Integration | Status | Notes |
|---|
RH events in KnownEventName | β
Partial | rh_resident_admitted, rh_resident_discharged, rh_phase_advanced, rh_bed_assigned/released registered; safety, pass, compliance events pending |
| Intake workflow | π Planned | Program β form FK linkage exists; workflow template needed |
| Phase progression approval | π Planned | Events and chain not yet registered |
| Pass request approval | π Planned | Events, chain, and decision table needed |
| Safety event workflow | π Planned | Events, severity decision table, and investigation workflow needed |
| Incident report form | β
Ready | GR incident report form template exists |
| Compliance reminders | π Planned | date_relative automation trigger needed |
| Form field lookups | π Planned | RH table lookup configs not yet registered |
| Discharge workflow | π Planned | Template and approval chain needed |