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 { Label } from "../../../components/ui/label.tsx"; import { Textarea } from "../../../components/ui/textarea.tsx"; import { ReportAddenda } from "../../../components/LabReports/ReportAddenda.tsx"; import { useDiagnosticPublicationOperation } from "../../../hooks/useDiagnosticPublicationOperation"; import { useAddReportAddendum } from "../../../hooks/useAddReportAddendum.ts"; import { useDiagnosticResult } from "../../../hooks/useDiagnosticResult.ts"; import "./AddAddendumDialog.css"; // SOMETHING SEEN AFTER THE REPORT WAS SIGNED. // // IT SAYS THE SIGNED WORDS DO NOT CHANGE, because that is the question somebody has before they type: // a radiologist who believes this rewrites the report will not use it, and one who believes it does // and it does not will write as though the first version is gone. // // THE QUEUE IS NOT REFRESHED AFTERWARDS, and that is deliberate twice over: an addendum changes // nothing the row shows, and refreshing from inside an open dialog destroys it -- the queue's load // raises `loading`, and the screen draws its sections only while that is false. // // WHAT IS ALREADY THERE IS SHOWN BEFORE ANYTHING IS TYPED. A second addendum written without seeing // the first repeats it, and two addenda saying the same thing is a record that reads as though // somebody found the finding twice. interface Props { withdrawn?: boolean; orderId?: string; test?: string; patient?: string; onClose: () => void; onAdded?: (version: number, returned?: { outcome: string; version: number; at?: string }) => void; } const AddAddendumDialog = ({ orderId, test, patient, onClose, onAdded, withdrawn }: Props) => { const addAddendum = useAddReportAddendum(); const { result, reload, loadMore, loading, error: readError } = useDiagnosticResult(orderId); const [text, setText] = useState(""); const [added, setAdded] = useState(false); const operation = useDiagnosticPublicationOperation('addendum', orderId, patient, result, !withdrawn, addAddendum, (saved, closed) => { setAdded(true); if (saved.clinical?.addendumCount !== undefined) onAdded?.(saved.clinical.addendumCount, saved.returned ? { ...saved.returned, version: saved.returned.version ?? saved.clinical.addendumCount } : undefined); if (closed) { setText(''); reload(); } }); const { busy, notice } = operation; const error = notice ?? readError; if (!orderId) return null; const shown = result?.addenda; const submit = async () => { await operation.run({ text: text.trim() }); }; return ( { if (!open && !busy) onClose(); }}> Add to this report {test ?? "This result"} {patient ? ` for ${patient}` : ""} {". The signed report does not change; this is added beside it, dated and in "} {"your name."} {error ? ( {error} ) : null} {shown && shown.length > 0 ? (
) : null}