Skip to main content
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)

Overview

The RH Bed Board and census system provides real-time occupancy data for all facility types: The bed board UI (/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


Decision Tree

  • Fetch census data (HR workload, PM census reporting)? → Use useCensusData from src/platform/census (Platform Integration Layer, Pattern 1). → Filter by facilityType if needed; do NOT query rh_residences or rh_beds directly from outside RH.
  • React to admission or discharge (FA billing, PM charge capture)? → Consume rh_resident_admitted / rh_resident_discharged from fw_domain_events (FW-16 / automation-compatible). → Check facility_type in 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=. → Returns null if patient is not currently admitted.
  • Assign or release a bed (within RH)? → Use useBedBoard hook inside RH only. → After mutation, emit rh_bed_assigned / rh_bed_released (📋 when registered) to fw_domain_events so HR can update census.
  • Handle inpatient_unit grouping? → Check facility_type === 'inpatient_unit' → use unit_label for bed grouping on the board. → For recovery_housing and psychiatric_residential, use room_number instead.

Pattern Library


Common Mistakes


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_admitted row in fw_domain_events with facility_type and 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 diff to confirm migration is applied; regenerate types.ts via bash scripts/utils/generate-types.sh and verify no as never / as unknown as casts remain in RH hooks.
  • RBAC: Verify rh.beds.view permission is required to access /rh/bed-board; confirm PermissionGate renders 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


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 → Dashboard: Bed Census Summary

Consumer: Platform dashboard widgets (e.g., BedCensusWidget) Provider: Platform Census Layer (src/platform/census) Pattern: Platform Integration Layer (Pattern 1) Status: ✅ Available Use fetchBedCensusSummary when you need a one-shot count of beds for a single organization — for example, a dashboard tile that mirrors the Bed Board totals without rendering the full grid. It applies the same scoping as useBedBoard: active residences only, non-deleted beds, filtered by organization_id. When to use it:
  • You need bed counts (total, occupied, available, reserved, maintenance) plus occupancy rate for a dashboard widget, report tile, or summary card.
  • You want the counts to match what the RH Bed Board shows (active residences, non-deleted beds).
  • You do not need the full bed grid or per-bed metadata — that’s what useBedBoard is for.
When not to use it:
  • For cross-core census by facility_type, use useCensusData instead.
  • For per-bed details or assignment, stay inside RH and use useBedBoard.
Return shape:
Example: Bed census summary in a widget
Pair it with useRealtimeSubscription on rh_beds to invalidate the query on inserts, updates, and deletes so the widget stays in sync with the Bed Board.

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: Query

Integration Matrix


Facility Type → POS Mapping (PM-07)

PM derives place of service from facility_type in event payloads. No direct RH → PM import. PM-10 prior authorization: the BHRF 5-day urgent rule applies to psychiatric_residential; standard inpatient PA rules apply to inpatient_unit.

References