> ## 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.

# Attendance

> View and record resident attendance records for scheduled activities with real-time connection status at /rh/attendance.

The Attendance screen at `/rh/attendance` displays a table of resident attendance records for scheduled activity instances and allows staff to record new attendance entries. The page includes a real-time connection badge indicating whether live updates are active.

## Overview

The page loads attendance records via `useAttendanceRecords`, which queries the `rh_attendance_records` table joined to `rh_episodes` and `rh_schedule_instances`, filtered by `organization_id` and ordered by `created_at` descending. The hook subscribes to real-time events on `rh_attendance_records` via `useRealtimeSubscription`; when an event fires, the query is refetched. The connection status (`useConnectionStatus`) drives the `RealtimeConnectionBadge` displayed next to the page heading. The table shows the first 20 records. Columns displayed are: activity date (from `schedule_instance.activity_date`), Episode ID (first 8 characters), `attendance_status` rendered as an `AttendanceStatusBadge`, `arrival_time`, and `notes`. If loading fails, a destructive `Alert` is shown with the message "Unable to load attendance data. Please try refreshing the page." The **Record Attendance** button opens the `AttendanceRecordDialog`.

## Who it's for

No route-level `RequirePermission` beyond the outer `RHViewGuard`, which requires `RH_PERMISSIONS.DASHBOARD_VIEW` (`rh.dashboard.view`). The `ATTENDANCE_CREATE` (`rh.attendance.create`) and `ATTENDANCE_EDIT` (`rh.attendance.edit`) permissions exist in `RH_PERMISSIONS` but are not applied as a route-level guard on this path.

## Before you start

* Hold `rh.dashboard.view` to access the RH module.

## Steps

<Steps>
  <Step title="Open the Attendance screen">
    Navigate to `/rh/attendance`. The table loads the most recent attendance records ordered by creation time.
  </Step>

  <Step title="Check the real-time connection">
    The `RealtimeConnectionBadge` next to the heading shows whether live updates are active (driven by `health.activeChannels > 0`).
  </Step>

  <Step title="Review attendance records">
    The table shows activity date, episode ID, attendance status badge, arrival time, and notes for up to 20 records.
  </Step>

  <Step title="Record a new attendance entry">
    Click **Record Attendance** in the page header. The `AttendanceRecordDialog` opens. Complete the form and save.
  </Step>
</Steps>

## Key concepts

<AccordionGroup>
  <Accordion title="Real-time updates">
    `useAttendanceRecords` subscribes to all events on `rh_attendance_records` via `useRealtimeSubscription`. When a change arrives, the query refetches automatically. The `RealtimeConnectionBadge` reflects whether there is at least one active channel.
  </Accordion>

  <Accordion title="Error state">
    When `useAttendanceRecords` returns an error, a destructive alert banner is shown and the data table is hidden.
  </Accordion>

  <Accordion title="Empty state">
    When no records exist, the `DataTable` renders the empty state with title "No attendance records found".
  </Accordion>

  <Accordion title="Record limit">
    The table renders at most 20 records (`records.slice(0, 20)`).
  </Accordion>
</AccordionGroup>

## Related

<Columns cols={2}>
  <Card title="Recovery Housing" icon="house" href="/rh/references">
    Recovery Housing references and overview.
  </Card>

  <Card title="Governance & parity" icon="scale-balanced" href="/governance/index">
    Documentation coverage and governance.
  </Card>
</Columns>

<Note>
  This page documents shipped product behavior. It is not medical, legal, or
  billing advice. Verify against your organization's policies and applicable
  regulations before using it for clinical, compliance, or billing decisions.
  Protected health information (PHI) shown in the product is governed by your
  tenant's access controls and is never exposed in this documentation.
</Note>

<Accordion title="Documentation sources">
  * src/routes/rh.tsx
  * src/cores/rh/pages/AttendancePage.tsx
  * src/cores/rh/hooks/useAttendanceRecords.ts
</Accordion>
