import React, { useMemo, useState } from 'react'; import { Sheet, SheetContent, SheetTitle } from '../../../components/ui/sheet'; import type { ClinicalTier } from '../../../utils/roleTier'; import type { PatientTaskCount } from '../../../utils/patientTaskCount'; import type { PatientNameResolution } from '../../../utils/appointmentParticipants'; import { useOrgAuthorizationStatusByPatient } from '../ReceptionistHomePage/useOrgAuthorizationStatusByPatient'; import type { BucketKey, QueueItem } from './encounterLifecycle'; import { groupQueueByBucket, queueBucketsFor, QueueBucketRows, type QueueBucket } from './EncounterQueue'; import './QueueCountCards.css'; interface Props { items: QueueItem[]; tier: ClinicalTier; selectedKey?: string; onSelect: (item: QueueItem) => void; taskCountByRowKey?: Record; patientNames?: PatientNameResolution; /** The practice's virtual Location, so a booked video visit is marked before it has an Encounter. */ virtualLocationId?: string; // The bucket the panel beside the cards is showing, drawn as the selected card. currentKey?: BucketKey; /** Whether this practice rooms patients. */ rooming?: boolean; } interface SheetBodyProps extends Omit { bucket: QueueBucket; list: QueueItem[]; } // Mounted only while the sheet is open, so the authorization read covers one bucket, not the day. const BucketSheetBody: React.FC = ({ bucket, list, selectedKey, onSelect, taskCountByRowKey = {}, patientNames, virtualLocationId, }) => { const authorizationByPatientId = useOrgAuthorizationStatusByPatient( useMemo(() => list.map((item) => item.patientId), [list]), ); return ( <> {bucket.title} ); }; /** * The overview's day as counts. Each card is a heading and a number; pressing one opens that bucket's * patients in a side sheet. A zero still opens and says so, because a count that refuses to open reads * as broken. */ export const QueueCountCards: React.FC = ({ items, tier, selectedKey, onSelect, taskCountByRowKey, patientNames, currentKey, rooming: roomsInUse = true, virtualLocationId, }) => { const buckets = queueBucketsFor(tier, roomsInUse); const byBucket = useMemo(() => groupQueueByBucket(items, buckets, tier), [items, buckets, tier]); const [openKey, setOpenKey] = useState(); const openBucket = buckets.find((bucket) => bucket.key === openKey); return ( <>
    {buckets.map((bucket) => (
  • ))}
{ if (!open) setOpenKey(undefined); }}> {openBucket && ( { setOpenKey(undefined); onSelect(item); }} taskCountByRowKey={taskCountByRowKey} patientNames={patientNames} virtualLocationId={virtualLocationId} /> )} ); };