import { useState } from "react"; import type { RobAnswer, RobAssessmentEntry, RobRating, RobReference, StudyDesign } from "../types"; import "./review-fixes.css"; export interface RobFormValues { outcome: string; study_design: StudyDesign; answers: RobAnswer[]; note: string; } interface RobFormProps { reference: RobReference; title: string; defaultOutcome: string; /** Pre-fill from an earlier assessment (own revision, or a reviewer's when resolving). */ initial?: RobAssessmentEntry; keyQuestionsFor: (design: StudyDesign) => number[]; /** Questions to highlight (reviewers disagreed). */ highlight?: number[]; requireNote?: boolean; lockOutcome?: boolean; busy: boolean; onCancel: () => void; onSubmit: (values: RobFormValues) => void; } /** One OHAT assessment: study design, then a rating + justification per applicable question. */ export function RobForm({ reference, title, defaultOutcome, initial, keyQuestionsFor, highlight = [], requireNote, lockOutcome, busy, onCancel, onSubmit, }: RobFormProps) { const [outcome, setOutcome] = useState(initial?.outcome ?? defaultOutcome); const [design, setDesign] = useState(initial?.study_design ?? ""); const [ratings, setRatings] = useState>( Object.fromEntries((initial?.answers ?? []).map((a) => [a.question, a.rating])) ); const [justifications, setJustifications] = useState>( Object.fromEntries((initial?.answers ?? []).map((a) => [a.question, a.justification])) ); const [note, setNote] = useState(""); const [error, setError] = useState(null); const questions = design ? reference.questions.filter((q) => q.applies_to.includes(design)) : []; const keys = design ? keyQuestionsFor(design) : []; function submit() { setError(null); if (!outcome.trim()) return setError("Enter the outcome this assessment is for."); if (!design) return setError("Choose the study design."); const missing = questions.filter((q) => !ratings[q.number]).map((q) => `Q${q.number}`); if (missing.length) return setError(`Rate every question (missing: ${missing.join(", ")}).`); const unjustified = questions.filter((q) => !justifications[q.number]?.trim()).map((q) => `Q${q.number}`); if (unjustified.length) return setError(`Every rating needs a justification (missing: ${unjustified.join(", ")}).`); if (requireNote && !note.trim()) return setError("Explain how the disagreement was resolved."); onSubmit({ outcome: outcome.trim(), study_design: design, answers: questions.map((q) => ({ question: q.number, rating: ratings[q.number], justification: justifications[q.number].trim(), })), note: note.trim(), }); } return (
{title}
{design && (

{questions.length} OHAT questions apply to this design. Key questions (marked ★) decide the tier. Rate NR when the paper doesn't report enough to judge — OHAT treats it as probably high.

)} {questions.map((q) => (
Q{q.number} {keys.includes(q.number) ? " ★" : ""} {" "} {q.bias_type} — {q.text}
{reference.ratings.map((r) => ( ))}