import { useEffect, useState } from "react"; import { useHttpService } from "../../../../services/HttpService.tsx"; import { environment } from "../../../../environments/environment.ts"; import { relayServerFailure } from "../../../../utils/fetchFailureMessage"; import type { EnteredResult } from "../../../../hooks/useDiagnosticResult.ts"; // The report filed on the study's order, as imaging.html draws it under the measurements. Only a 404 // means none is filed, and then there is no card; any other failure, a refusal included, is shown. const StudyReportCard = ({ orderId }: { orderId?: string }) => { const { get } = useHttpService(); const [report, setReport] = useState(); const [failure, setFailure] = useState(); useEffect(() => { setReport(undefined); setFailure(undefined); if (!orderId) { setReport(null); return undefined; } let live = true; get(`${environment.fhirBaseApi}/diagnostic-order/${orderId}/result`) .then((read) => { if (live) setReport(read ?? null); }) .catch((error) => { if (!live) return; if ((error as { status?: number })?.status === 404) setReport(null); else setFailure(relayServerFailure(error, "The report could not be read.")); }); return () => { live = false; }; }, [get, orderId]); const written = report && (report.impression || report.findings); if (!failure && !written) return null; return (

Report

{failure || !report ? (

{failure}

) : ( <> {report.status === "preliminary" ? (

Preliminary: not yet released.

) : null} {report.impression ?

{report.impression}

: null} {report.findings ?

{report.findings}

: null} )}
); }; export default StudyReportCard;