Builds PaperTrail from the base skeleton into a full evidence-verification platform for the "Built with Claude: Life Sciences" hackathon (Builder Track). New named-user features (Build Beyond the Bench): - Lab Notebook Companion — rough bench notes -> structured, searchable, grounded experiment records (lib/labNotebook, /console/lab-notebook, migration 0059) - Clinical Trial Matcher — de-identified patient notes -> ranked eligible ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning (lib/trialMatcher, /console/trial-matcher, migrations 0060) Platform: - Deterministic verification moat (biostats recompute, exact-span grounding) - 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar, PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier) - Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise governance (RBAC, /api/v1 gateway, metering, audit chain, retention) - 17 OSS projects assimilated into native TypeScript on our stack (backend/engines retained + credited in NOTICE) - Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site - Next.js 16 upgrade, benchmark harness (honest smoke-test caveat) Licensing: Apache-2.0 (LICENSE + NOTICE).
72 lines
2.5 KiB
TypeScript
72 lines
2.5 KiB
TypeScript
"use client";
|
|
|
|
import { useCallback, useState } from "react";
|
|
import type { WorkbenchPayload } from "./types";
|
|
|
|
// Opens the deterministic Summary-of-Findings export for the current inputs. The
|
|
// export endpoint is a POST (it needs the study payload), so we submit via fetch,
|
|
// turn the returned HTML document into a blob URL, and open it in a new tab — the
|
|
// same document a medical writer would paste into a dossier. Baseline risk is not
|
|
// part of the export contract, so it is intentionally dropped from the request.
|
|
|
|
interface ExportButtonProps {
|
|
// Returns the validated payload, or an error string to surface instead of exporting.
|
|
buildPayload: () => { payload: WorkbenchPayload } | { error: string };
|
|
}
|
|
|
|
export function ExportButton({ buildPayload }: ExportButtonProps) {
|
|
const [busy, setBusy] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
const onExport = useCallback(async () => {
|
|
const built = buildPayload();
|
|
if ("error" in built) {
|
|
setError(built.error);
|
|
return;
|
|
}
|
|
setError(null);
|
|
setBusy(true);
|
|
try {
|
|
const res = await fetch("/api/evidence-report/export", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
claim: built.payload.claim,
|
|
studies: built.payload.studies,
|
|
}),
|
|
});
|
|
if (!res.ok) {
|
|
const body = (await res.json().catch(() => null)) as { error?: string } | null;
|
|
throw new Error(body?.error ?? "Export failed.");
|
|
}
|
|
const html = await res.text();
|
|
const url = URL.createObjectURL(new Blob([html], { type: "text/html" }));
|
|
window.open(url, "_blank", "noopener,noreferrer");
|
|
// Revoke shortly after the new tab has had time to load the document.
|
|
setTimeout(() => URL.revokeObjectURL(url), 60_000);
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : "Failed to export.");
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}, [buildPayload]);
|
|
|
|
return (
|
|
<div className="flex flex-col items-end gap-1">
|
|
<button
|
|
type="button"
|
|
onClick={() => void onExport()}
|
|
disabled={busy}
|
|
className="rounded-md border border-ink/20 px-3 py-2 text-sm font-medium text-ink/70 hover:border-accent hover:text-accent disabled:opacity-50"
|
|
>
|
|
{busy ? "Exporting…" : "Export Summary of Findings"}
|
|
</button>
|
|
{error ? (
|
|
<span className="text-xs text-red-700" role="alert">
|
|
{error}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|