import { useState } from "react"; import { AlertCircle, Loader2 } from "lucide-react"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "../../../components/ui/dialog.tsx"; import { Alert, AlertDescription } from "../../../components/ui/alert.tsx"; import { Button } from "../../../components/ui/button.tsx"; import { Input } from "../../../components/ui/input.tsx"; import { Label } from "../../../components/ui/label.tsx"; import { ToggleGroupControl, ToggleGroupControlOption } from "../../../components/ui/toggle-group-control.tsx"; import { relayServerFailure } from "../../../utils/fetchFailureMessage"; import type { DiagnosticOrderQueueRow, OutsideRead } from "../../../hooks/useDiagnosticOrderQueue.ts"; import { useImagingReadHandoff } from "../../../hooks/useImagingReadHandoff.ts"; import { SEP } from "./ImagingWorklist.tsx"; import "./RecordRefusalDialog.css"; // WHAT THE OUTSIDE READER SAID ABOUT THE STUDY ARRIVING, recorded once, by a person, apart from the send. // Sending it was never delivery; this is the only thing that says they have it. const OutsideReadArrivalDialog = ({ row, onClose, onRecorded, }: { row?: DiagnosticOrderQueueRow; onClose: () => void; onRecorded: (orderId: string, outside: OutsideRead) => void; }) => { const { confirmOutsideRead } = useImagingReadHandoff(); const [outcome, setOutcome] = useState<"received" | "not-received" | "">(""); const [note, setNote] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(); if (!row?.orderId || !row.outsideRead) return null; const reader = row.outsideRead.reader; const submit = async () => { setBusy(true); setError(undefined); try { const response = await confirmOutsideRead(row.orderId as string, { outcome: outcome as "received" | "not-received", ...(note.trim() ? { note: note.trim() } : {}), }); if (response?.outsideRead?.confirmation) onRecorded(row.orderId as string, response.outsideRead); onClose(); } catch (failure) { console.error("Error recording what the outside reader said:", failure); setError(relayServerFailure(failure, "That could not be saved. Nothing was recorded.")); } finally { setBusy(false); } }; return ( { if (!open && !busy) onClose(); }}> Did {reader} get the study? {[row.accession, row.test ?? "This study", row.patientDisplay].filter(Boolean).join(SEP)} {error && ( {error} )}
setOutcome(value === "not-received" ? "not-received" : "received")}>
setNote(e.target.value)} />
); }; export default OutsideReadArrivalDialog;