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
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
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_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
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
useBedBoardis for.
- For cross-core census by
facility_type, useuseCensusDatainstead. - For per-bed details or assignment, stay inside RH and use
useBedBoard.
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: QueryIntegration Matrix
Facility Type → POS Mapping (PM-07)
PM derives place of service fromfacility_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
- 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