import { useState } from "react"; import { AlertCircle } 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 { relayServerFailure } from "../../../utils/fetchFailureMessage"; import type { InboundRequisition } from "../../../hooks/useInboundRequisitions.ts"; import { testTermsOf } from "./requisitionTestTerms.ts"; import "./ReviewOrderDialog.css"; interface Props { requisition?: InboundRequisition; onClose: () => void; accept: (requisitionId: string) => Promise; } // Accepting is the laboratory agreeing to do the work, a separate act from naming the patient. const ReviewOrderDialog = ({ requisition, onClose, accept }: Props) => { const [busy, setBusy] = useState(false); const [error, setError] = useState(); if (!requisition?.requisitionId || !requisition.matchedPatient) return null; const who = requisition.matchedPatient.display ?? requisition.patientName ?? "Patient not named"; const sender = [requisition.from, requisition.theirOrderCode].filter(Boolean).join(" · "); // What was asked for in our own terms, so acceptance is of our test and not of the sender's wording. const terms = testTermsOf(requisition); const submit = async () => { setBusy(true); setError(undefined); try { await accept(requisition.requisitionId as string); onClose(); } catch (failure) { console.error("Error accepting an inbound requisition:", failure); setError(relayServerFailure(failure, "That order was not accepted. Nothing was ordered.")); } finally { setBusy(false); } }; return ( { if (!open && !busy) onClose(); }}> Review order for acceptance
{`${who} · ${requisition.test ?? "Test not named"}`} {`Patient matched · ${sender}`} {terms ? {terms} : null}
{requisition.kind === "imaging" ? "Accept this request for the imaging worklist. The study is scheduled there." : "Accept this request for laboratory processing. Specimen receipt is recorded separately."} {error ? ( {error} ) : null}
); }; export default ReviewOrderDialog;