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).
94 lines
3.1 KiB
TypeScript
94 lines
3.1 KiB
TypeScript
"use client";
|
|
|
|
// Save button for a computed Evidence Workbench report. POSTs the already-computed
|
|
// composite object (no recompute) to the org-scoped /api/evidence-reports route and
|
|
// shows a saved confirmation with a link to the saved-reports list. Handles the
|
|
// unauthenticated (401), no-access (403), and generic error states inline.
|
|
|
|
import { useCallback, useState } from "react";
|
|
import Link from "next/link";
|
|
import { apiSend, type SavedEvidenceReportDto } from "../../evidence-reports/api";
|
|
import type { EvidenceReport } from "./types";
|
|
|
|
interface SaveReportButtonProps {
|
|
claim: string;
|
|
// Only the ok:true report is savable — the caller must not render this for an
|
|
// insufficient-evidence result.
|
|
report: EvidenceReport;
|
|
}
|
|
|
|
type SaveState =
|
|
| { status: "idle" }
|
|
| { status: "saving" }
|
|
| { status: "saved"; id: string }
|
|
| { status: "error"; message: string };
|
|
|
|
export function SaveReportButton({ claim, report }: SaveReportButtonProps) {
|
|
const [state, setState] = useState<SaveState>({ status: "idle" });
|
|
|
|
const onSave = useCallback(async () => {
|
|
setState({ status: "saving" });
|
|
// Denormalized summary fields for list/scan; the full composite is stored as
|
|
// `report`. These map to optional columns and are safe to omit.
|
|
const payload = {
|
|
claim,
|
|
verdict: report.verdict.verdict,
|
|
certainty: report.certainty.certainty,
|
|
pooled: report.pooled as unknown as Record<string, unknown>,
|
|
report: report as unknown as Record<string, unknown>,
|
|
};
|
|
const res = await apiSend<SavedEvidenceReportDto>(
|
|
"/api/evidence-reports",
|
|
"POST",
|
|
payload
|
|
);
|
|
if (!res.success || !res.data) {
|
|
setState({ status: "error", message: res.error ?? "Couldn't save the report." });
|
|
return;
|
|
}
|
|
setState({ status: "saved", id: res.data.id });
|
|
}, [claim, report]);
|
|
|
|
if (state.status === "saved") {
|
|
return (
|
|
<div className="flex flex-wrap items-center gap-3 rounded-md border border-green-300 bg-green-50 px-3 py-2 text-sm">
|
|
<span className="font-medium text-green-800">Report saved.</span>
|
|
<Link
|
|
href={`/console/evidence-reports/${state.id}`}
|
|
className="text-accent hover:underline"
|
|
>
|
|
View saved report
|
|
</Link>
|
|
<Link href="/console/evidence-reports" className="text-accent hover:underline">
|
|
All saved reports
|
|
</Link>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="flex flex-wrap items-center gap-3">
|
|
<button
|
|
type="button"
|
|
onClick={() => void onSave()}
|
|
disabled={state.status === "saving"}
|
|
className="rounded-md border border-accent px-4 py-2 text-sm font-medium text-accent hover:bg-accent hover:text-white disabled:opacity-50"
|
|
>
|
|
{state.status === "saving" ? "Saving…" : "Save report"}
|
|
</button>
|
|
{state.status === "error" ? (
|
|
<span className="text-sm text-red-700" role="alert">
|
|
{state.message}
|
|
</span>
|
|
) : (
|
|
<Link
|
|
href="/console/evidence-reports"
|
|
className="text-sm text-accent hover:underline"
|
|
>
|
|
Saved reports
|
|
</Link>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|