/** One field of a study's form as the report's Observation carries it: the catalog's field * (`cervical_cytology.screening_history`), its title and its value as the screens say it. */ export interface Fact { study: string; field: string; title: string; value: string; } /** What the cytology's form declares of her before and at the sample: her screening history, the * gynecologic condition she reports, what she presents and what the exploration observed. These are * statements of the form (not diagnoses), each with its form and day. */ export const ANTECEDENTS: { field: string; title: string }[] = [ { field: 'screening_history', title: 'Detección de cáncer de cérvix' }, { field: 'gynecologic_condition', title: 'Condición ginecoobstétrica a la detección' }, { field: 'presenting_symptom', title: 'Actualmente presenta' }, { field: 'cervix_appearance', title: 'A la exploración se observa' }, ]; /** `cervical_cytology.hpv` as its study and its field. */ export function split(code: string): { study: string; field: string } { const at = code.indexOf('.'); return at < 0 ? { study: '', field: code } : { study: code.slice(0, at), field: code.slice(at + 1) }; } /** A report's facts by what they are: the form's antecedents (by field), the results of the study * itself, and the extra findings (collapsible): the cytologist's text and each stated finding. */ export function group(facts: Fact[]) { const antecedents: Record = {}; const results: string[] = []; const findings: string[] = []; for (const f of facts) { const cytology = f.study === 'cervical_cytology'; if (cytology && ANTECEDENTS.some((a) => a.field === f.field)) antecedents[f.field] = f.value; else if (cytology && f.field === 'findings') findings.unshift(`Texto del informe: ${f.value}`); else if (cytology && f.field.startsWith('finding_')) { const named = f.title.replace(/^Hallazgo: /, ''); const text = named.charAt(0).toUpperCase() + named.slice(1); findings.push(f.value === 'positivo' ? text : `${text}: ${f.value}`); } else { // "BI-RADS 4C", not "BI-RADS: BI-RADS 4C" results.push(f.value.startsWith(f.title) ? f.value : `${f.title}: ${f.value}`); } } return { antecedents, results, findings }; } const HPV_FIELDS = ['hpv', 'hpv_16', 'hpv_18']; /** The cytology report's HPV results, apart from the cytology's own facts. */ export function hpvApart(facts: Fact[]) { const isHpv = (f: Fact) => f.study === 'cervical_cytology' && HPV_FIELDS.includes(f.field); return { hpv: facts.filter(isHpv), rest: facts.filter((f) => !isHpv(f)) }; }