Download frontend/src/components/ExtractionForm.tsx from Smart-Slate/Systematic-tool-review: direct link, hf CLI and curl.
- Browser
- Download file 12.6 kB
-
https://huggingface.co/spaces/Smart-Slate/Systematic-tool-review/resolve/main/frontend/src/components/ExtractionForm.tsx
- Command line
-
hf download hf://spaces/Smart-Slate/Systematic-tool-review/frontend/src/components/ExtractionForm.tsx
-
curl -L -o ExtractionForm.tsx https://huggingface.co/spaces/Smart-Slate/Systematic-tool-review/resolve/main/frontend/src/components/ExtractionForm.tsx
12.6 kB
| import { useState } from "react"; | |
| import type { EffectDirection, EvidenceStream, StudyFeatureKey } from "../types"; | |
| import { initialConfidenceFor } from "../utils/confidence"; | |
| import { useRobReference } from "./useRobReference"; | |
| import "./review-fixes.css"; | |
| export interface ExtractionFormData { | |
| species: string | null; | |
| route: string | null; | |
| duration: string | null; | |
| noael: string | null; | |
| loael: string | null; | |
| effect_finding: string | null; | |
| notes: string | null; | |
| outcome: string | null; | |
| evidence_stream: EvidenceStream | null; | |
| direction: EffectDirection | null; | |
| controlled_exposure: boolean | null; | |
| exposure_prior_to_outcome: boolean | null; | |
| individual_outcome_data: boolean | null; | |
| comparison_group: boolean | null; | |
| klimisch_score: 1 | 2 | 3 | 4 | null; | |
| klimisch_justification: string | null; | |
| guideline_followed: string | null; | |
| glp_compliant: boolean | null; | |
| substance_identity_reported: boolean | null; | |
| controls_reported: boolean | null; | |
| doses_group_sizes_reported: boolean | null; | |
| methods_source: "full_text" | "abstract_only" | null; | |
| } | |
| interface ExtractionFormProps { | |
| reviewer: string; | |
| busy: boolean; | |
| /** Pre-filled outcome (the protocol's outcome). */ | |
| defaultOutcome?: string; | |
| onCancel: () => void; | |
| onSubmit: (data: ExtractionFormData) => void; | |
| } | |
| const FEATURE_HELP: Record<StudyFeatureKey, string> = { | |
| controlled_exposure: "Investigators assigned the exposure (experimental animal study or human trial).", | |
| exposure_prior_to_outcome: "Exposure was measured before the outcome developed (rules out reverse causation).", | |
| individual_outcome_data: "Outcomes were recorded per individual, not only as group or population averages.", | |
| comparison_group: "There was an unexposed or lower-exposed group to compare with.", | |
| }; | |
| type YesNo = "" | "yes" | "no"; | |
| type KlimischScore = 1 | 2 | 3 | 4; | |
| type MethodsSource = "" | "full_text" | "abstract_only"; | |
| const KLIMISCH_LABELS: Record<KlimischScore, string> = { | |
| 1: "1 – reliable without restriction", | |
| 2: "2 – reliable with restrictions", | |
| 3: "3 – not reliable", | |
| 4: "4 – not assignable", | |
| }; | |
| function toBool(value: YesNo): boolean | null { | |
| return value === "" ? null : value === "yes"; | |
| } | |
| /** A suggestion only. The reviewer decides and must justify the final score. */ | |
| function suggestKlimisch(input: { | |
| methods: MethodsSource; | |
| guideline: string; | |
| glp: YesNo; | |
| identity: YesNo; | |
| controls: YesNo; | |
| doses: YesNo; | |
| }): { score: KlimischScore; reason: string } | null { | |
| if (input.methods === "abstract_only") { | |
| return { score: 4, reason: "Only the abstract was available, so the methods cannot be assessed." }; | |
| } | |
| if (input.methods === "") return null; | |
| const core = [input.identity, input.controls, input.doses]; | |
| if (core.includes("no")) { | |
| const missing = [ | |
| input.identity === "no" ? "substance identity/purity" : null, | |
| input.controls === "no" ? "controls" : null, | |
| input.doses === "no" ? "doses or group sizes" : null, | |
| ].filter(Boolean); | |
| return { score: 3, reason: `Key method details are missing: ${missing.join(", ")}.` }; | |
| } | |
| if (core.includes("")) return null; | |
| if (input.guideline.trim() && input.glp === "yes") { | |
| return { score: 1, reason: "Guideline followed, GLP compliant, and key details reported." }; | |
| } | |
| return { score: 2, reason: "Key details reported, but not both a guideline and GLP." }; | |
| } | |
| export function ExtractionForm({ reviewer, busy, defaultOutcome = "", onCancel, onSubmit }: ExtractionFormProps) { | |
| const { reference } = useRobReference(); | |
| const [species, setSpecies] = useState(""); | |
| const [route, setRoute] = useState(""); | |
| const [duration, setDuration] = useState(""); | |
| const [noael, setNoael] = useState(""); | |
| const [loael, setLoael] = useState(""); | |
| const [effectFinding, setEffectFinding] = useState(""); | |
| const [notes, setNotes] = useState(""); | |
| const [outcome, setOutcome] = useState(defaultOutcome); | |
| const [stream, setStream] = useState<EvidenceStream | "">(""); | |
| const [direction, setDirection] = useState<EffectDirection | "">(""); | |
| const [features, setFeatures] = useState<Record<StudyFeatureKey, boolean>>({ | |
| controlled_exposure: false, | |
| exposure_prior_to_outcome: false, | |
| individual_outcome_data: false, | |
| comparison_group: false, | |
| }); | |
| const [methods, setMethods] = useState<MethodsSource>(""); | |
| const [guideline, setGuideline] = useState(""); | |
| const [glp, setGlp] = useState<YesNo>(""); | |
| const [identity, setIdentity] = useState<YesNo>(""); | |
| const [controls, setControls] = useState<YesNo>(""); | |
| const [doses, setDoses] = useState<YesNo>(""); | |
| const [klimisch, setKlimisch] = useState<"" | "1" | "2" | "3" | "4">(""); | |
| const [klimischNote, setKlimischNote] = useState(""); | |
| const [error, setError] = useState<string | null>(null); | |
| const conf = reference?.confidence; | |
| const count = Object.values(features).filter(Boolean).length; | |
| const suggestion = suggestKlimisch({ methods, guideline, glp, identity, controls, doses }); | |
| function submit() { | |
| setError(null); | |
| if (!outcome.trim()) return setError("Enter the outcome these data are for."); | |
| if (!stream) return setError("Choose the evidence stream (human, animal or in vitro)."); | |
| if (!direction) return setError("Choose the direction of the finding."); | |
| if (klimisch && !klimischNote.trim()) { | |
| return setError("Explain the Klimisch score you chose."); | |
| } | |
| onSubmit({ | |
| species: species || null, | |
| route: route || null, | |
| duration: duration || null, | |
| noael: noael || null, | |
| loael: loael || null, | |
| effect_finding: effectFinding || null, | |
| notes: notes || null, | |
| outcome: outcome.trim(), | |
| evidence_stream: stream, | |
| direction, | |
| ...features, | |
| klimisch_score: klimisch ? (Number(klimisch) as KlimischScore) : null, | |
| klimisch_justification: klimisch ? klimischNote.trim() : null, | |
| guideline_followed: guideline.trim() || null, | |
| glp_compliant: toBool(glp), | |
| substance_identity_reported: toBool(identity), | |
| controls_reported: toBool(controls), | |
| doses_group_sizes_reported: toBool(doses), | |
| methods_source: methods || null, | |
| }); | |
| } | |
| const yesNoOptions = ( | |
| <> | |
| <option value="">Not answered</option> | |
| <option value="yes">Yes</option> | |
| <option value="no">No</option> | |
| </> | |
| ); | |
| return ( | |
| <div className="extraction-form"> | |
| <p className="form-hint"> | |
| Fill these from what this paper reports, for <strong>one outcome</strong>. Leave a field empty or | |
| write "Not reported" rather than guessing. You can add another extraction for each further outcome. | |
| </p> | |
| <div className="extraction-grid"> | |
| <input placeholder="Outcome" value={outcome} onChange={(e) => setOutcome(e.target.value)} /> | |
| <select value={stream} onChange={(e) => setStream(e.target.value as EvidenceStream)} aria-label="Evidence stream"> | |
| <option value="">Evidence stream…</option> | |
| {(conf?.streams ?? [ | |
| { value: "human", label: "Human" }, | |
| { value: "animal", label: "Animal" }, | |
| { value: "in_vitro", label: "In vitro" }, | |
| ]).map((s) => ( | |
| <option key={s.value} value={s.value}> | |
| {s.label} | |
| </option> | |
| ))} | |
| </select> | |
| <input placeholder="Species" value={species} onChange={(e) => setSpecies(e.target.value)} /> | |
| <input placeholder="Exposure route" value={route} onChange={(e) => setRoute(e.target.value)} /> | |
| <input placeholder="Duration" value={duration} onChange={(e) => setDuration(e.target.value)} /> | |
| <input placeholder="NOAEL" value={noael} onChange={(e) => setNoael(e.target.value)} /> | |
| <input placeholder="LOAEL" value={loael} onChange={(e) => setLoael(e.target.value)} /> | |
| <input | |
| placeholder="Effect / finding (direction, size, 95% CI)" | |
| value={effectFinding} | |
| onChange={(e) => setEffectFinding(e.target.value)} | |
| /> | |
| <select value={direction} onChange={(e) => setDirection(e.target.value as EffectDirection)} aria-label="Direction"> | |
| <option value="">Direction of the finding…</option> | |
| {(conf?.directions ?? []).map((d) => ( | |
| <option key={d.value} value={d.value}> | |
| {d.label} | |
| </option> | |
| ))} | |
| </select> | |
| </div> | |
| <div className="feature-box"> | |
| <strong>OHAT key study-design features</strong> (set the initial confidence for this study) | |
| {(conf?.features ?? []).map((f) => ( | |
| <label key={f.key} className="feature-option" title={FEATURE_HELP[f.key]}> | |
| <input | |
| type="checkbox" | |
| checked={features[f.key]} | |
| onChange={() => setFeatures({ ...features, [f.key]: !features[f.key] })} | |
| /> | |
| {f.label} <span className="rob-bias-type">— {FEATURE_HELP[f.key]}</span> | |
| </label> | |
| ))} | |
| <div className="form-hint"> | |
| {count} of 4 features → initial confidence{" "} | |
| <strong>{conf?.levels.find((l) => l.value === initialConfidenceFor(count))?.label ?? initialConfidenceFor(count)}</strong> | |
| </div> | |
| </div> | |
| <div className="feature-box klimisch-box"> | |
| <strong>Study reliability (Klimisch) — optional</strong> | |
| <div className="form-hint"> | |
| Answer from the paper's methods. Leave a question as "Not answered" if the paper does not say. | |
| </div> | |
| <div className="extraction-grid"> | |
| <select value={methods} onChange={(e) => setMethods(e.target.value as MethodsSource)} aria-label="Methods available"> | |
| <option value="">Methods available…</option> | |
| <option value="full_text">Full text</option> | |
| <option value="abstract_only">Abstract only</option> | |
| </select> | |
| <input | |
| placeholder="Test guideline followed (e.g. OECD 471), if any" | |
| value={guideline} | |
| onChange={(e) => setGuideline(e.target.value)} | |
| /> | |
| <label> | |
| GLP compliant{" "} | |
| <select value={glp} onChange={(e) => setGlp(e.target.value as YesNo)}> | |
| {yesNoOptions} | |
| </select> | |
| </label> | |
| <label> | |
| Substance identity and purity reported{" "} | |
| <select value={identity} onChange={(e) => setIdentity(e.target.value as YesNo)}> | |
| {yesNoOptions} | |
| </select> | |
| </label> | |
| <label> | |
| Controls reported{" "} | |
| <select value={controls} onChange={(e) => setControls(e.target.value as YesNo)}> | |
| {yesNoOptions} | |
| </select> | |
| </label> | |
| <label> | |
| Doses and group sizes reported{" "} | |
| <select value={doses} onChange={(e) => setDoses(e.target.value as YesNo)}> | |
| {yesNoOptions} | |
| </select> | |
| </label> | |
| </div> | |
| {suggestion ? ( | |
| <div className="form-hint"> | |
| Suggested: <strong>{KLIMISCH_LABELS[suggestion.score]}</strong> — {suggestion.reason}{" "} | |
| <button | |
| type="button" | |
| className="change-btn" | |
| onClick={() => setKlimisch(String(suggestion.score) as "1" | "2" | "3" | "4")} | |
| > | |
| Use suggestion | |
| </button> | |
| </div> | |
| ) : ( | |
| <div className="form-hint"> | |
| Answer the method questions to get a suggestion. A suggestion is only a starting point. | |
| </div> | |
| )} | |
| <select value={klimisch} onChange={(e) => setKlimisch(e.target.value as "" | "1" | "2" | "3" | "4")} aria-label="Klimisch score"> | |
| <option value="">Klimisch score (your decision)…</option> | |
| {([1, 2, 3, 4] as KlimischScore[]).map((s) => ( | |
| <option key={s} value={String(s)}> | |
| {KLIMISCH_LABELS[s]} | |
| </option> | |
| ))} | |
| </select> | |
| {klimisch && ( | |
| <textarea | |
| placeholder="Why this score? (required)" | |
| value={klimischNote} | |
| onChange={(e) => setKlimischNote(e.target.value)} | |
| /> | |
| )} | |
| </div> | |
| <textarea placeholder="Notes" value={notes} onChange={(e) => setNotes(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 || !reviewer.trim()} onClick={submit}> | |
| Save extraction | |
| </button> | |
| </div> | |
| </div> | |
| ); | |
| } | |