Download frontend/src/components/RobSection.tsx from Smart-Slate/Systematic-tool-review: direct link, hf CLI and curl.
- Browser
- Download file 10.3 kB
-
https://huggingface.co/spaces/Smart-Slate/Systematic-tool-review/resolve/main/frontend/src/components/RobSection.tsx
- Command line
-
hf download hf://spaces/Smart-Slate/Systematic-tool-review/frontend/src/components/RobSection.tsx
-
curl -L -o RobSection.tsx https://huggingface.co/spaces/Smart-Slate/Systematic-tool-review/resolve/main/frontend/src/components/RobSection.tsx
10.3 kB
| import { useState } from "react"; | |
| import { recordRobAssessment } from "../api/protocols"; | |
| import type { | |
| Protocol, | |
| RobAssessmentEntry, | |
| RobReference, | |
| RobSummaryItem, | |
| ScreeningRecordEntry, | |
| SearchResultItem, | |
| StudyDesign, | |
| } from "../types"; | |
| import { isFinallyIncluded, reviewerKey } from "../utils/screeningStatus"; | |
| import { RobForm, type RobFormValues } from "./RobForm"; | |
| import { useRobReference } from "./useRobReference"; | |
| import "./review-fixes.css"; | |
| interface RobSectionProps { | |
| protocol: Protocol; | |
| papers: SearchResultItem[]; | |
| screeningHistory: ScreeningRecordEntry[]; | |
| robEntries: RobAssessmentEntry[]; | |
| robSummary: RobSummaryItem[]; | |
| onRefresh: () => Promise<void>; | |
| } | |
| const outcomeKey = (o: string) => o.split(/\s+/).filter(Boolean).join(" ").toLowerCase(); | |
| export function keyQuestionsFor(protocol: Protocol, reference: RobReference, design: StudyDesign): number[] { | |
| const experimental = reference.designs.find((d) => d.value === design)?.experimental; | |
| const keys = experimental | |
| ? protocol.rob_key_questions_experimental ?? [8, 9] | |
| : protocol.rob_key_questions_observational ?? [4, 8, 9]; | |
| const applicable = new Set(reference.questions.filter((q) => q.applies_to.includes(design)).map((q) => q.number)); | |
| return keys.filter((q) => applicable.has(q)).sort((a, b) => a - b); | |
| } | |
| type Open = | |
| | { kind: "assess"; paperId: string; outcome?: string; initial?: RobAssessmentEntry } | |
| | { kind: "resolve"; paperId: string; outcome: string; initial: RobAssessmentEntry; highlight: number[] }; | |
| /** Risk of bias (OHAT) for every study included at full text. */ | |
| export function RobSection({ protocol, papers, screeningHistory, robEntries, robSummary, onRefresh }: RobSectionProps) { | |
| const { reference, error: refError } = useRobReference(); | |
| const [reviewer, setReviewer] = useState(""); | |
| const [open, setOpen] = useState<Open | null>(null); | |
| const [busy, setBusy] = useState(false); | |
| const [error, setError] = useState<string | null>(null); | |
| const mode = protocol.reviewers_required ?? 1; | |
| const included = papers.filter((p) => isFinallyIncluded(screeningHistory, p.id, mode)); | |
| const me = reviewerKey(reviewer); | |
| if (refError) return <div className="form-error">{refError}</div>; | |
| if (!reference) return null; | |
| const ref = reference; | |
| async function save(values: RobFormValues, paperId: string, adjudication: boolean) { | |
| setError(null); | |
| if (!me) { | |
| setError("Enter your name above first."); | |
| return; | |
| } | |
| setBusy(true); | |
| try { | |
| await recordRobAssessment(protocol.id, { | |
| paper_id: paperId, | |
| outcome: values.outcome, | |
| study_design: values.study_design, | |
| answers: values.answers, | |
| reviewer: reviewer.trim(), | |
| role: adjudication ? "adjudication" : "review", | |
| note: adjudication ? values.note : null, | |
| }); | |
| setOpen(null); | |
| await onRefresh(); | |
| } catch (err) { | |
| setError(err instanceof Error ? err.message : "Failed to save the assessment."); | |
| } finally { | |
| setBusy(false); | |
| } | |
| } | |
| /** Latest review entry per reviewer for one study/outcome. */ | |
| function reviewsFor(paperId: string, outcome: string): Map<string, RobAssessmentEntry> { | |
| const map = new Map<string, RobAssessmentEntry>(); | |
| [...robEntries] | |
| .filter((e) => e.paper_id === paperId && outcomeKey(e.outcome) === outcomeKey(outcome) && (e.role ?? "review") === "review") | |
| .sort((a, b) => a.assessed_at.localeCompare(b.assessed_at)) | |
| .forEach((e) => map.set(reviewerKey(e.reviewer), e)); | |
| return map; | |
| } | |
| const designLabel = (d: StudyDesign) => ref.designs.find((x) => x.value === d)?.label ?? d; | |
| const symbol = (rating: string) => ref.ratings.find((r) => r.value === rating)?.symbol ?? rating; | |
| function itemBlock(paper: SearchResultItem, item: RobSummaryItem) { | |
| const reviews = reviewsFor(paper.id, item.outcome); | |
| const mine = me ? reviews.get(me) : undefined; | |
| const others = reviews.size - (mine ? 1 : 0); | |
| const label = `Outcome: ${item.outcome}`; | |
| if (item.final) { | |
| return ( | |
| <div className="decision-tag included" key={item.outcome}> | |
| {label} — {designLabel(item.final.study_design)} ·{" "} | |
| <strong>{item.tier ? `Tier ${item.tier}` : "Tier not determined (no key question applies)"}</strong> | |
| {item.state === "agreed" && ` · agreed by ${item.reviewers.join(" and ")}`} | |
| {item.state === "adjudicated" && ` · resolved by ${item.final.reviewer}: “${item.final.note ?? ""}”`} | |
| {(mine || mode === 1) && ( | |
| <button | |
| className="change-btn" | |
| onClick={() => setOpen({ kind: "assess", paperId: paper.id, outcome: item.outcome, initial: mine ?? item.final ?? undefined })} | |
| > | |
| {mode === 1 ? "Revise" : "Change my assessment"} | |
| </button> | |
| )} | |
| </div> | |
| ); | |
| } | |
| if (item.state === "conflict") { | |
| const [a, b] = [...reviews.values()]; | |
| const questions = item.conflicting_questions.includes(0) ? [] : item.conflicting_questions; | |
| return ( | |
| <div className="conflict-box" key={item.outcome}> | |
| <strong>{label}: reviewers disagree</strong> | |
| {item.conflicting_questions.includes(0) && a && b && ( | |
| <div> | |
| Study design: {a.reviewer} chose {designLabel(a.study_design)}, {b.reviewer} chose {designLabel(b.study_design)}. | |
| </div> | |
| )} | |
| {questions.length > 0 && a && b && ( | |
| <ul className="history-change"> | |
| {questions.map((q) => { | |
| const ra = a.answers.find((x) => x.question === q); | |
| const rb = b.answers.find((x) => x.question === q); | |
| return ( | |
| <li key={q}> | |
| Q{q}: {a.reviewer} {symbol(ra?.rating ?? "")} vs {b.reviewer} {symbol(rb?.rating ?? "")} | |
| </li> | |
| ); | |
| })} | |
| </ul> | |
| )} | |
| <div className="screening-actions"> | |
| {a && ( | |
| <button | |
| className="primary-btn" | |
| onClick={() => setOpen({ kind: "resolve", paperId: paper.id, outcome: item.outcome, initial: a, highlight: questions })} | |
| > | |
| Resolve | |
| </button> | |
| )} | |
| {mine && ( | |
| <button className="change-btn" onClick={() => setOpen({ kind: "assess", paperId: paper.id, outcome: item.outcome, initial: mine })}> | |
| Change my assessment | |
| </button> | |
| )} | |
| </div> | |
| </div> | |
| ); | |
| } | |
| // pending / awaiting second reviewer (blinded) | |
| if (mine) { | |
| return ( | |
| <div className="decision-line" key={item.outcome}> | |
| {label} — your assessment is saved · waiting for a second reviewer | |
| <button className="change-btn" onClick={() => setOpen({ kind: "assess", paperId: paper.id, outcome: item.outcome, initial: mine })}> | |
| Change | |
| </button> | |
| </div> | |
| ); | |
| } | |
| return ( | |
| <div className="decision-line" key={item.outcome}> | |
| {label} — {others} of 2 reviewers assessed (hidden until you assess) | |
| <button className="secondary-btn" onClick={() => setOpen({ kind: "assess", paperId: paper.id, outcome: item.outcome })}> | |
| Assess | |
| </button> | |
| </div> | |
| ); | |
| } | |
| return ( | |
| <div className="rob-section"> | |
| <h2>Risk of bias (OHAT)</h2> | |
| <p className="form-hint"> | |
| Each study included at full text is assessed with the OHAT risk-of-bias tool, per outcome. Only the | |
| questions that apply to the study's design are shown, and every rating needs a justification. | |
| {mode === 2 && " Two reviewers assess independently; ratings stay hidden until both are done, and any difference must be resolved."} | |
| </p> | |
| {protocol.rob_criteria && ( | |
| <details className="rob-criteria"> | |
| <summary>Review-specific criteria for this protocol</summary> | |
| <p>{protocol.rob_criteria}</p> | |
| </details> | |
| )} | |
| <label className="field-label">Your name / initials</label> | |
| <input | |
| type="text" | |
| className="reviewer-input" | |
| value={reviewer} | |
| onChange={(e) => setReviewer(e.target.value)} | |
| placeholder="Your name or initials, e.g. AB" | |
| /> | |
| {included.length === 0 && ( | |
| <p className="empty-state">No studies are included at full text yet — finish screening first.</p> | |
| )} | |
| {error && <div className="form-error">{error}</div>} | |
| <div className="paper-screening-list"> | |
| {included.map((paper) => { | |
| const items = robSummary.filter((i) => i.paper_id === paper.id); | |
| const formOpen = open && open.paperId === paper.id; | |
| return ( | |
| <div key={paper.id} className="screening-row"> | |
| <p className="screening-title">{paper.title}</p> | |
| <p className="paper-meta"> | |
| {paper.authors} | |
| {paper.journal ? ` · ${paper.journal}` : ""} | |
| {paper.year ? ` (${paper.year})` : ""} | |
| </p> | |
| {items.map((item) => itemBlock(paper, item))} | |
| {!formOpen && ( | |
| <button className="secondary-btn" onClick={() => setOpen({ kind: "assess", paperId: paper.id })}> | |
| {items.length === 0 ? "Assess risk of bias" : "Assess another outcome"} | |
| </button> | |
| )} | |
| {formOpen && open && ( | |
| <RobForm | |
| reference={ref} | |
| title={open.kind === "resolve" ? "Resolve disagreement — record the final assessment" : "OHAT risk-of-bias assessment"} | |
| defaultOutcome={open.outcome ?? protocol.outcome} | |
| initial={open.initial} | |
| keyQuestionsFor={(d) => keyQuestionsFor(protocol, ref, d)} | |
| highlight={open.kind === "resolve" ? open.highlight : []} | |
| requireNote={open.kind === "resolve"} | |
| lockOutcome={!!open.outcome} | |
| busy={busy} | |
| onCancel={() => setOpen(null)} | |
| onSubmit={(values) => save(values, paper.id, open.kind === "resolve")} | |
| /> | |
| )} | |
| </div> | |
| ); | |
| })} | |
| </div> | |
| </div> | |
| ); | |
| } | |