Download frontend/src/utils/protocolChanges.ts from Smart-Slate/Systematic-tool-review: direct link, hf CLI and curl.
- Browser
- Download file 2.38 kB
-
https://huggingface.co/spaces/Smart-Slate/Systematic-tool-review/resolve/main/frontend/src/utils/protocolChanges.ts
- Command line
-
hf download hf://spaces/Smart-Slate/Systematic-tool-review/frontend/src/utils/protocolChanges.ts
-
curl -L -o protocolChanges.ts https://huggingface.co/spaces/Smart-Slate/Systematic-tool-review/resolve/main/frontend/src/utils/protocolChanges.ts
2.38 kB
| // Helpers for editing and amending a protocol: which fields changed, and | |
| // which of those affect the search. | |
| import type { Protocol, ProtocolDraft } from "../types"; | |
| export const DRAFT_FIELDS: (keyof ProtocolDraft)[] = [ | |
| "title", | |
| "review_type", | |
| "review_domain", | |
| "population", | |
| "intervention", | |
| "comparator", | |
| "outcome", | |
| "intervention_terms", | |
| "outcome_terms", | |
| "inclusion_criteria", | |
| "exclusion_criteria", | |
| "sources", | |
| "reviewers_required", | |
| "rob_key_questions_observational", | |
| "rob_key_questions_experimental", | |
| "rob_criteria", | |
| ]; | |
| /** Fields whose change means the existing search no longer matches the protocol. */ | |
| export const SEARCH_FIELDS: (keyof ProtocolDraft)[] = [ | |
| "intervention", | |
| "outcome", | |
| "intervention_terms", | |
| "outcome_terms", | |
| "sources", | |
| ]; | |
| export function draftFromProtocol(protocol: Protocol): ProtocolDraft { | |
| return { | |
| title: protocol.title, | |
| review_type: protocol.review_type ?? null, | |
| review_domain: protocol.review_domain ?? null, | |
| population: protocol.population, | |
| intervention: protocol.intervention, | |
| comparator: protocol.comparator, | |
| outcome: protocol.outcome, | |
| inclusion_criteria: protocol.inclusion_criteria, | |
| exclusion_criteria: protocol.exclusion_criteria, | |
| intervention_terms: protocol.intervention_terms ?? [], | |
| outcome_terms: protocol.outcome_terms ?? [], | |
| sources: protocol.sources, | |
| reviewers_required: protocol.reviewers_required ?? 1, | |
| rob_key_questions_observational: protocol.rob_key_questions_observational ?? [4, 8, 9], | |
| rob_key_questions_experimental: protocol.rob_key_questions_experimental ?? [8, 9], | |
| rob_criteria: protocol.rob_criteria ?? null, | |
| }; | |
| } | |
| /** Only the fields the reviewer actually changed (an emptied comparator is null). */ | |
| export function changedFields(draft: ProtocolDraft, protocol: Protocol): Partial<ProtocolDraft> { | |
| const original = draftFromProtocol(protocol); | |
| const normalized: ProtocolDraft = { | |
| ...draft, | |
| comparator: draft.comparator?.trim() ? draft.comparator : null, | |
| rob_criteria: draft.rob_criteria?.trim() ? draft.rob_criteria : null, | |
| }; | |
| const changes: Partial<ProtocolDraft> = {}; | |
| for (const field of DRAFT_FIELDS) { | |
| if (JSON.stringify(normalized[field]) !== JSON.stringify(original[field])) { | |
| (changes as Record<string, unknown>)[field] = normalized[field]; | |
| } | |
| } | |
| return changes; | |
| } | |