Version: 1.1 Last Updated: 2026-03-20 Spec: RH-01 Census, Beds & Episodes · RH-01.1 Bed Board & Facility Types Constitution Reference: Section 1.2 (Core Independence), Section 1.3 (Integration Patterns)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.
Overview
The RH Bed Board and census system provides real-time occupancy data for all facility types:facility_type | Setting | POS |
|---|---|---|
recovery_housing | NARR Level 2/3 recovery housing | 55 |
psychiatric_residential | Behavioral health residential (RTC/BHRF) | 56 |
inpatient_unit | Inpatient psychiatric | 51 |
/rh/bed-board) is owned by RH. Other cores consume census and admission/discharge data via the Platform Integration Layer and domain events — no direct core-to-core imports.
Quick Reference
| I need to… | Pattern | Location |
|---|---|---|
| View the real-time bed board | Navigate to /rh/bed-board UI | src/cores/rh/pages/BedBoardPage.tsx |
| Fetch census data in another core | Platform Census Layer (useCensusData) | src/platform/census |
| React to admission/discharge in FA or PM | Read rh_resident_admitted / rh_resident_discharged from fw_domain_events (canonical; legacy resident_* deprecated) | EVENT_CONTRACTS.md |
| Read current residence for a patient in CL | GET /api/v1/rh/current-residence?patient_id= via Platform Integration Layer | API_CONTRACTS.md — RH-01 |
| Derive POS from facility type in PM | Map facility_type from event payload using PM-07 rules | Facility Type → POS Mapping section below |
Decision Tree
-
Fetch census data (HR workload, PM census reporting)?
→ Use
useCensusDatafromsrc/platform/census(Platform Integration Layer, Pattern 1). → Filter byfacilityTypeif needed; do NOT queryrh_residencesorrh_bedsdirectly from outside RH. -
React to admission or discharge (FA billing, PM charge capture)?
→ Consume
rh_resident_admitted/rh_resident_dischargedfromfw_domain_events(FW-16 / automation-compatible). → Checkfacility_typein event payload → map to POS (55/56/51) for PM-07. → Do NOT call RH hooks or import from@/cores/rh/.... -
Show current residence/bed on patient chart (CL)?
→ Call Platform Integration Layer API:
GET /api/v1/rh/current-residence?patient_id=. → Returnsnullif patient is not currently admitted. -
Assign or release a bed (within RH)?
→ Use
useBedBoardhook inside RH only. → After mutation, emitrh_bed_assigned/rh_bed_released(📋 when registered) tofw_domain_eventsso HR can update census. -
Handle inpatient_unit grouping?
→ Check
facility_type === 'inpatient_unit'→ useunit_labelfor bed grouping on the board. → Forrecovery_housingandpsychiatric_residential, useroom_numberinstead.
Pattern Library
| Pattern | Usage | Constraints | Example |
|---|---|---|---|
| Real-time census via Platform Integration Layer | HR/PM read census counts by facility_type without querying RH tables directly | Do not import @/cores/rh/...; use src/platform/census only | Example: Census Query below |
| Event-driven admission/discharge (Pattern 2) | FA creates billing account; PM derives POS; HR updates staffing census | Subscribers must be idempotent; episode_id is the deduplication key | Example: Event Payload sections below |
| Platform API for cross-core read (Pattern 3) | CL reads current residence/bed on patient chart | Read-only; no direct DB join; returns null if not admitted | GET /api/v1/rh/current-residence |
| Facility type → POS mapping | PM-07 uses facility_type from event payload to derive Place of Service code | Mapping is static: recovery_housing→55, psychiatric_residential→56, inpatient_unit→51 | Facility Type → POS Mapping section |
| Bed board auto-refresh | useBedBoard polls every 30 s via refetchInterval: 30_000 for near-real-time accuracy. 30 s was chosen as a tradeoff between data freshness and resource usage based on expected occupancy and bed-assignment change frequency (typical update cadence and acceptable staleness for the board). staleTime: 5 min and gcTime: 10 min still apply; refetchInterval runs in the background so the board stays reasonably fresh without over-querying. | staleTime: 5 min, gcTime: 10 min; manual Refresh button available | src/cores/rh/hooks/useBedBoard.ts |
Common Mistakes
| Mistake | Impact | Mitigation |
|---|---|---|
Importing from @/cores/rh/... in another core | Couples cores; breaks Core Independence (constitution Section 1.2) | Use Platform Census Layer, rh_events, or Platform API instead |
Reading rh_residences.facility_type directly from FA/PM/HR | Schema changes in RH silently break consumers; bypasses RLS | Consume facility_type from event payload or Platform Census Layer only |
Using stale census data without refetchInterval | Bed count shown to HR/PM may lag after admissions/discharges | Set refetchInterval: 30_000 in any census-consuming hook; rely on rh_events for immediate triggers |
Mis-mapping facility_type to POS | Wrong POS on claims → denials or incorrect reimbursement | Always use the canonical mapping table in this doc; do not hard-code POS without checking |
Omitting organization_id filter on bed queries | Multi-tenant data leakage; cross-org bed records may be returned | Always .eq('organization_id', currentOrganization.id) as defense-in-depth alongside RLS |
Pre-Flight Checklist
Before releasing any change to the RH bed board or census integration:- End-to-end test: Admit a resident → verify
rh_resident_admittedrow infw_domain_eventswithfacility_typeand actor UUIDs (no PHI). - Event emission: Confirm
rh_bed_assigned/rh_bed_released(when implemented) after bed assignment mutations; HR census updates correctly. - Schema compatibility: Run
supabase db diffto confirm migration is applied; regeneratetypes.tsviabash scripts/utils/generate-types.shand verify noas never/as unknown ascasts remain in RH hooks. - RBAC: Verify
rh.beds.viewpermission is required to access/rh/bed-board; confirmPermissionGaterenders access-denied for unpermitted users. - POS mapping: Spot-check PM-07 charge capture for one episode per
facility_type; confirm POS codes 55, 56, 51 are derived correctly.
Integration Points
| Dependency | Pattern | Purpose |
|---|---|---|
| FA | Event (Pattern 2) | Resident admission/discharge events trigger billing account creation and finalization |
| PM | Event / Census Data (Pattern 2 / Platform Layer) | facility_type in events allows PM to derive POS (51/55/56) for charge capture and prior auth |
| HR | Platform Census Layer (Pattern 1) | Census count (by facility_type) drives HR workload and staffing calculations |
| CL | Platform Integration Layer / API (Pattern 3 — optional) | Optional: current residence/bed read-only on patient chart |
| PF-10 | Platform Layer (Pattern 1) | Notifications for bed availability, admission alerts, license expiry |
| PF-11 | Platform Layer (Pattern 1) | Resident agreement document storage |
Event Contracts
Event: rh_resident_admitted
Publisher: RH (RH-01)Subscribers: FA (billing account creation), PM (POS context)
Persistence:
fw_domain_events (event_source = trigger_rh_episodes_domain_events)Status: 🟡 Persistence implemented; FA/PM batch consumers 📋 Planned Deprecated alias:
resident_admitted
Example: Event Payload
Event: rh_resident_discharged
Publisher: RH (RH-01)Subscribers: FA (billing finalization)
Persistence:
fw_domain_events (trigger_rh_episodes_domain_events)Status: 🟡 Persistence implemented; FA consumer 📋 Planned Deprecated alias:
resident_discharged
Example: Event Payload
Event: rh_bed_assigned (planned)
Publisher: RH (RH-01)Subscribers: HR (workload/census update)
Persistence: 📋 Planned (
fw_domain_events)Status: 📝 Planned (RH-01.1 Implementation) Deprecated alias:
bed_assigned
Example: Event Payload
Event: rh_bed_released (planned)
Publisher: RH (RH-01)Subscribers: HR (workload/census update)
Persistence: 📋 Planned (
fw_domain_events)Status: 📝 Planned (RH-01.1 Implementation) Deprecated alias:
bed_released
Example: Event Payload
Event: rh_invoice_creation_requested
Publisher: RH (RH-01)
Subscribers: FA (invoice creation)
Channel: rh_events
Status: 📝 Planned (RH-01 Implementation)
Example: Event Payload
API Contracts
RH → FA: Episode Balance Query
Consumer: RH (episode detail page, bed board payment status) Provider: FA Method: GET URL:/api/v1/fa/episode-balance?episode_id={episodeId}
Status: 📝 Planned
Example: Query Response
Platform Census → HR/PM: Census by Facility Type
Consumer: HR (workload drivers), PM (census reporting) Provider: Platform Census Layer (src/platform/census)
Pattern: Platform Integration Layer (Pattern 1)
Status: 📝 Planned — requires facility_type on rh_residences (migration added 2026-02-22)
Example: Census Query
CL → RH: Current Residence/Bed (Optional)
Consumer: CL (patient chart — current residence/bed read-only) Provider: RH via Platform Integration Layer Pattern: Platform Integration Layer / API (Pattern 3) — optional enhancement Status: 📝 Planned (CL-01 chart enhancements) Example: QueryIntegration Matrix
| From | To | Pattern | Doc |
|---|---|---|---|
| RH (RH-01) | FA | Event — rh_resident_admitted, rh_resident_discharged, rh_invoice_creation_requested | This doc |
| RH (RH-01) | HR | Event — bed_assigned, bed_released | This doc |
| RH (RH-01) | PM | Events include facility_type for POS derivation | This doc |
| RH (RH-01) | Platform Census Layer | Data source — rh_beds, rh_residences with facility_type | This doc |
| Platform Census | HR | Platform Layer — census by facility_type | This doc |
| Platform Census | PM | Platform Layer — bed-day census for billing | This doc |
| RH (RH-01) | CL | Platform Integration Layer / API — current residence/bed (optional) | This doc |
Facility Type → POS Mapping (PM-07)
PM derives place of service fromfacility_type in event payloads. No direct RH → PM import.
| facility_type | POS Code | Description |
|---|---|---|
recovery_housing | 55 | Residential SUD |
psychiatric_residential | 56 | Psychiatric residential (RTC/BHRF) |
inpatient_unit | 51 | Inpatient psychiatric |
psychiatric_residential; standard inpatient PA rules apply to inpatient_unit.
References
- RH-01 Spec
- RH-01.1 Spec (Bed Board & Facility Types)
- EVENT_CONTRACTS.md — RH-01 event sections
- CROSS_CORE_INTEGRATIONS.md — Integration matrix
- API_CONTRACTS.md — FA Episode Balance Query
- Platform Census
- PM-07 Charge Capture
- PM-10 Prior Authorization