import type { Patient } from "fhir/r4"; import { ArrowLeft, LoaderCircle } from "lucide-react"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "../../../components/ui/dialog.tsx"; import PatientProfileCard from "../../../components/PatientProfileCard/PatientProfileCard"; import PatientNotes from "../../../components/PatientNotes/PatientNotes.tsx"; import { usePatientServiceContext } from "../../../services"; import { useKeyedRead } from "../../../hooks/useKeyedRead.ts"; import { formatFhirHumanName } from "../../../utils/fhirHumanName.tsx"; import { calculateAge, patientAgeLabel } from "../../../utils/dateUtils.ts"; import { PatientMark } from "./PatientMark.tsx"; import "./ReceptionistPatientWorkspaceDialog.css"; interface DeskPatientQuickViewProps { /** The patient this quick view is for. The parent keys the component by it. */ patientId: string; onClose: () => void; onBack?: () => void; /** What the footer's way out says, such as "Back to appointment". */ backLabel?: string; } // The board's own quick view: internal notes first, then the read-only profile, over the board it was // opened from. The Patients directory keeps the seven-section workspace. export default function DeskPatientQuickView({ patientId, onClose, onBack, backLabel }: DeskPatientQuickViewProps) { const { fetchPatient } = usePatientServiceContext(); const read = useKeyedRead(patientId, async (id) => { const patient = await fetchPatient(id, false, undefined, true); if (patient?.id !== id) throw new Error("The patient read answered for another patient."); return patient; }); const patient = read.status === "ready" ? read.value : undefined; const name = patient ? formatFhirHumanName(patient.name, { emptyText: "Patient" }) : "Patient"; const age = patient?.birthDate ? patientAgeLabel(calculateAge(patient.birthDate)) : null; return ( { if (!open) onClose(); }}> {patient && }
Patient Quick View {[name, age].filter(Boolean).join(" · ")}
{read.status === "failed" ? (
Failed to load the patient profile.
) : !patient ? (
Loading patient…
) : (

Internal notes

)} {backLabel && onBack && (
)}
); }