Spaces:
Sleeping
Sleeping
File size: 5,717 Bytes
6624dea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | 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<StudyDesign | "">(initial?.study_design ?? "");
const [ratings, setRatings] = useState<Record<number, RobRating>>(
Object.fromEntries((initial?.answers ?? []).map((a) => [a.question, a.rating]))
);
const [justifications, setJustifications] = useState<Record<number, string>>(
Object.fromEntries((initial?.answers ?? []).map((a) => [a.question, a.justification]))
);
const [note, setNote] = useState("");
const [error, setError] = useState<string | null>(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 (
<div className="rob-form">
<strong>{title}</strong>
<div className="rob-form-row">
<label>
Outcome{" "}
<input type="text" value={outcome} disabled={lockOutcome} onChange={(e) => setOutcome(e.target.value)} />
</label>
<label>
Study design{" "}
<select value={design} onChange={(e) => setDesign(e.target.value as StudyDesign)}>
<option value="">Choose…</option>
{reference.designs.map((d) => (
<option key={d.value} value={d.value}>
{d.label}
</option>
))}
</select>
</label>
</div>
{design && (
<p className="form-hint">
{questions.length} OHAT questions apply to this design. Key questions (marked ★) decide the tier.
Rate <strong>NR</strong> when the paper doesn't report enough to judge — OHAT treats it as probably high.
</p>
)}
{questions.map((q) => (
<div key={q.number} className={`rob-question${highlight.includes(q.number) ? " rob-question-conflict" : ""}`}>
<div className="rob-question-text">
<strong>
Q{q.number}
{keys.includes(q.number) ? " ★" : ""}
</strong>{" "}
<span className="rob-bias-type">{q.bias_type}</span> — {q.text}
</div>
<div className="rob-ratings" role="radiogroup" aria-label={`Rating for question ${q.number}`}>
{reference.ratings.map((r) => (
<label key={r.value} className={`rob-rating rob-${r.value}`} title={r.help}>
<input
type="radio"
name={`q${q.number}`}
checked={ratings[q.number] === r.value}
onChange={() => setRatings({ ...ratings, [q.number]: r.value })}
/>
{r.symbol} {r.label}
</label>
))}
</div>
<textarea
className="rob-justification"
placeholder="Justification — what in the paper supports this rating?"
value={justifications[q.number] ?? ""}
onChange={(e) => setJustifications({ ...justifications, [q.number]: e.target.value })}
/>
</div>
))}
{requireNote && (
<textarea
placeholder="How was the disagreement resolved? (required)"
value={note}
onChange={(e) => setNote(e.target.value)}
/>
)}
{error && <div className="form-error">{error}</div>}
<div className="form-actions">
<button className="secondary-btn" onClick={onCancel}>
Cancel
</button>
<button className="primary-btn" disabled={busy} onClick={submit}>
{busy ? "Saving…" : "Save assessment"}
</button>
</div>
</div>
);
}
|