From e31c128991fcdc8fc3d63ab81aa020a2bc981bc1 Mon Sep 17 00:00:00 2001 From: edgar Date: Fri, 4 Dec 2026 05:49:56 -0600 Subject: [PATCH] =?UTF-8?q?Nombrar=20la=20detecci=C3=B3n=20anterior=20y=20?= =?UTF-8?q?encadenar=20los=20tiempos=20de=20CaMa=20hasta=20el=20tratamient?= =?UTF-8?q?o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/indicadores/bars.spec.ts | 13 ++++----- src/app/indicadores/bars.ts | 42 +++++++++------------------ src/app/indicadores/durations.spec.ts | 9 +++++- src/app/indicadores/durations.ts | 32 ++++++++++++++++---- src/app/indicadores/measures.ts | 4 +-- src/app/indicadores/pages-cacu.ts | 6 ++-- src/app/indicadores/pages.ts | 8 ++++- src/app/indicadores/route-card.ts | 15 ++++++---- 8 files changed, 75 insertions(+), 54 deletions(-) diff --git a/src/app/indicadores/bars.spec.ts b/src/app/indicadores/bars.spec.ts index b1d9cc1..ad1e7df 100644 --- a/src/app/indicadores/bars.spec.ts +++ b/src/app/indicadores/bars.spec.ts @@ -140,7 +140,7 @@ describe('bars', () => { const t = bars(mode, () => r)!; expect(t.rows.map((x) => x.label)).toEqual([ 'Detección inicial', - 'Detección subsecuente', + 'Con detección anterior', 'Sin dato', ]); expect(t.rows.map((x) => x.cells)).toEqual([ @@ -238,7 +238,7 @@ describe('bars', () => { c === 'initial' ? 'Detección inicial' : c === 'subsequent' - ? 'Detección subsecuente' + ? 'Con detección anterior' : 'Sin dato', ['initial', 'subsequent', 'no_data'], { fill: true }, @@ -251,14 +251,14 @@ describe('bars', () => { const y = (f.data[0] as any).y; expect(y).toEqual([ 'Detección inicial
Pacientes: 0', - 'Detección subsecuente
Pacientes: 8', + 'Con detección anterior
Pacientes: 8', 'Sin dato
Pacientes: 2', ]); expect((f.data[0] as any).x).toEqual([0, 75, 100]); }); it('leaves out a group that does not reconcile', () => { const f = draw(reading({ 'subsequent|NILM': 6 }, 10)); - expect((f.data[0] as any).y).toEqual(['Detección subsecuente
Pacientes: 6']); + expect((f.data[0] as any).y).toEqual(['Con detección anterior
Pacientes: 6']); }); }); }); @@ -375,7 +375,7 @@ describe('independent bars by group', () => { )!; expect(g.groups.map((x) => [x.label, x.total])).toEqual([ ['Detección inicial', 4], - ['Detección subsecuente', 6], + ['Con detección anterior', 6], ]); expect(g.groups[0].rows.map((r) => [r.label, r.text, r.percent, r.color])).toEqual([ ['Normal', '3/4 · 75.0 %', 75, '#408651'], @@ -530,7 +530,7 @@ describe('the subsequent round by last screening', () => { [25, 50, [50, 100]], ]); }); - it('splits the subsequent round by last screening, keeping those without an answer', () => { + it('splits the subsequent round by last screening, drawing only those with an answer', () => { const one = { 'initial-population': 1 }; const r: Reading = { populations: { 'initial-population': 3 }, @@ -554,7 +554,6 @@ describe('the subsequent round by last screening', () => { ['within_1_year', 1], ['2_years', 0], ['3_or_more_years', 0], - ['subsequent_without_last_screening', 1], ]); }); }); diff --git a/src/app/indicadores/bars.ts b/src/app/indicadores/bars.ts index 1c6c41a..07a12a7 100644 --- a/src/app/indicadores/bars.ts +++ b/src/app/indicadores/bars.ts @@ -1,4 +1,5 @@ import { CIE10 } from './cie10'; +import { chainStarts } from './durations'; import { NEUTRAL_DARK } from './cacu-palette'; import { name, Reading } from './measures'; @@ -186,7 +187,7 @@ export interface Bars { export const NOT_AVAILABLE = 'No disponible'; export const NO_PATIENTS = 'Sin pacientes en el periodo'; const NO_ROUND = - 'Ninguna paciente del periodo tiene clasificación de detección inicial o subsecuente: los grupos en cero reflejan información no registrada, no ausencia de pacientes.'; + 'Ninguna paciente del periodo tiene clasificación de detección inicial o anterior: los grupos en cero reflejan información no registrada, no ausencia de pacientes.'; const whole = (n: unknown): n is number => typeof n === 'number' && Number.isInteger(n) && n >= 0; @@ -482,14 +483,9 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined): /** The subsequent round split by the form's last screening, drawn in place of that round's group. */ const LAST_SCREENING: [string, string][] = [ - ['within_1_year', 'Subsecuente: última detección hace un año o menos'], - ['2_years', 'Subsecuente: última detección hace dos años'], - ['3_or_more_years', 'Subsecuente: última detección hace tres años o más'], -]; -/** Subsequent records whose form gives none of those answers: drawn only when there are some. */ -const NO_LAST_SCREENING: [string, string] = [ - 'subsequent_without_last_screening', - 'Subsecuente sin dato de última detección', + ['within_1_year', 'Detección anterior hace un año o menos'], + ['2_years', 'Detección anterior hace dos años'], + ['3_or_more_years', 'Detección anterior hace tres años o más'], ]; /** The groups of a grouped mode: each group (an age group, a follow-up status, a screening round) with @@ -507,14 +503,11 @@ export function grouped( const history = mode.stratum === 'round' ? (r?.strata['subsequent_history-category'] ?? {}) : {}; const answers = LAST_SCREENING.map(([code]) => code); - const unanswered = Object.keys(history).filter((k) => !answers.includes(k.split('|')[0])); /** the cells that make up a group, with their category */ const cellsOf = (g: string): [string, Record][] => - g === NO_LAST_SCREENING[0] - ? unanswered.map((k) => [k.split('|')[1], history[k]]) - : Object.entries(answers.includes(g) ? history : cells) - .filter(([k]) => k.split('|')[0] === g) - .map(([k, c]) => [k.split('|')[1], c]); + Object.entries(answers.includes(g) ? history : cells) + .filter(([k]) => k.split('|')[0] === g) + .map(([k, c]) => [k.split('|')[1], c]); const n = (g: string, c: string) => cellsOf(g).reduce((t, [category, cell]) => (category === c ? t + size(cell) : t), 0); const reconciled = reconciles( @@ -532,19 +525,14 @@ export function grouped( const at = codes.indexOf('subsequent'); const drawn = mode.stratum === 'round' && at >= 0 && r?.strata['subsequent_history-category'] - ? [ - ...codes.slice(0, at), - ...answers, - ...(unanswered.length ? [NO_LAST_SCREENING[0]] : []), - ...codes.slice(at + 1), - ] + ? [...codes.slice(0, at), ...answers, ...codes.slice(at + 1)] : codes; const groups: Group[] = drawn.map((code) => { const den = total(code); return { code, label: - [...LAST_SCREENING, NO_LAST_SCREENING].find(([answer]) => answer === code)?.[1] ?? + LAST_SCREENING.find(([answer]) => answer === code)?.[1] ?? (mode.stratum === 'age_group' && code === '<25' && ['CACU_EU7', 'CACU_VPH_GENOTIPO'].includes(mode.measure) @@ -667,13 +655,9 @@ function medians( staggered?: boolean, ): Bars | undefined { if (!rows.some((r) => r.score?.score !== undefined)) return undefined; - // a step without a median moves nothing after it - let elapsed = 0; - const starts = rows.map((r) => { - const start = elapsed; - if (staggered) elapsed += r.score?.score ?? 0; - return start; - }); + const starts = staggered + ? chainStarts(rows.map((r) => ({ median: r.score?.score }))) + : rows.map(() => 0); const ends = rows.map( (r, i) => starts[i] + Math.max(r.score?.score ?? 0, r.score?.high ?? 0), ); diff --git a/src/app/indicadores/durations.spec.ts b/src/app/indicadores/durations.spec.ts index 78e8a58..c55b5f5 100644 --- a/src/app/indicadores/durations.spec.ts +++ b/src/app/indicadores/durations.spec.ts @@ -1,4 +1,4 @@ -import { durationMax, durationRows } from './durations'; +import { chainStarts, durationMax, durationRows } from './durations'; import { Reading } from './measures'; const reading = (score?: number, n = 0, low?: number, high?: number): Reading => ({ @@ -53,3 +53,10 @@ describe('durationRows', () => { expect(durationMax([])).toBe(0); }); }); + +describe('chainStarts', () => { + it('starts each step where the one it follows ends, two of them sharing a start', () => { + expect(chainStarts([{ median: 4 }, { median: 6 }, { median: 2, after: 0 }])).toEqual([0, 4, 4]); + expect(chainStarts([{ median: 4 }, {}, { median: 2 }])).toEqual([0, 4, 4]); + }); +}); diff --git a/src/app/indicadores/durations.ts b/src/app/indicadores/durations.ts index df24851..ff4bf69 100644 --- a/src/app/indicadores/durations.ts +++ b/src/app/indicadores/durations.ts @@ -5,6 +5,8 @@ import { Reading } from './measures'; export interface RouteStep { label: string; measure?: string; + /** the step (its position) this one starts after; the previous one by default */ + after?: number; } /** One row of a duration table: the median days, how many measurements and the quartiles. @@ -17,6 +19,25 @@ export interface DurationRow { observations?: number; low?: number; high?: number; + after?: number; + /** where its bar starts, in days, when the steps are chained */ + start?: number; +} + +/** Where each step's bar starts when drawn as a schematic sequence (a Gantt chart): where the + * step it follows ends. A step without a median moves nothing after it. */ +export function chainStarts(steps: { median?: number; after?: number }[]): number[] { + const starts: number[] = []; + steps.forEach(({ after }, i) => { + const j = after ?? i - 1; + starts.push(j < 0 ? 0 : starts[j] + (steps[j].median ?? 0)); + }); + return starts; +} + +export function chained(rows: DurationRow[]): DurationRow[] { + const starts = chainStarts(rows); + return rows.map((row, i) => ({ ...row, start: starts[i] })); } /** The rows of a route in one reading; every step keeps its row. `published` says which @@ -26,12 +47,13 @@ export function durationRows( read: (measure: string) => Reading | undefined, published: (measure: string) => boolean, ): DurationRow[] { - return steps.map(({ label, measure }) => { - if (!measure || !published(measure)) return { label, status: 'unpublished' }; + return steps.map(({ label, measure, after }) => { + if (!measure || !published(measure)) return { label, after, status: 'unpublished' }; const r = read(measure); - if (r?.score === undefined) return { label, status: 'empty' }; + if (r?.score === undefined) return { label, after, status: 'empty' }; return { label, + after, status: 'value', median: r.score, observations: r.populations['measure-observation'], @@ -41,6 +63,6 @@ export function durationRows( }); } -/** The scale of a table of durations, from zero: the largest median or third quartile shown. */ +/** The scale of a table of durations, from zero: the farthest median or third quartile shown. */ export const durationMax = (rows: DurationRow[]): number => - Math.max(0, ...rows.map((r) => Math.max(r.median ?? 0, r.high ?? 0))); + Math.max(0, ...rows.map((r) => (r.start ?? 0) + Math.max(r.median ?? 0, r.high ?? 0))); diff --git a/src/app/indicadores/measures.ts b/src/app/indicadores/measures.ts index 4d5dec2..9d77f4c 100644 --- a/src/app/indicadores/measures.ts +++ b/src/app/indicadores/measures.ts @@ -142,7 +142,7 @@ export const LABELS: Record = { bad: 'Malo', not_analyzed: 'Sin analizar', initial: 'Detección inicial', - subsequent: 'Detección subsecuente', + subsequent: 'Con detección anterior', positive: 'Positivo', negative: 'Negativo', hpv_16: 'VPH 16', @@ -188,7 +188,7 @@ export const STRATA: Record = { cytology: 'Citología previa', hpv: 'VPH de la citología previa', level: 'Histología confirmada', - round: 'Tamizaje inicial o subsecuente', + round: 'Detección inicial o anterior', hpv_16: 'VPH 16', hpv_18: 'VPH 18', }; diff --git a/src/app/indicadores/pages-cacu.ts b/src/app/indicadores/pages-cacu.ts index 080fc4f..00fae4c 100644 --- a/src/app/indicadores/pages-cacu.ts +++ b/src/app/indicadores/pages-cacu.ts @@ -74,13 +74,13 @@ const TINT = { bar: DURATION, mark: QUARTILE }; const ROUNDS = ['initial', 'subsequent', 'no_data']; const ROUND_CAPTION = 'Cada paciente está en un solo grupo, según su muestra (fecha de toma): detección inicial (primera vez en la vida), ' + - 'subsecuente (detección previa registrada, o ya con colposcopía o tratamiento) o «Sin dato». ' + + 'con detección anterior (registrada, o ya con colposcopía o tratamiento) o «Sin dato». ' + 'Un grupo sin pacientes se muestra en cero; sin porcentaje.'; /** The views the cytology and HPV-by-genotype cards share (one selector for both). */ const GENERAL = 'General'; const BY_AGE = 'Por grupo de edad'; -const BY_ROUND = 'Por detección inicial y subsecuente'; +const BY_ROUND = 'Por detección inicial y anterior'; const AGE_GROUPS = ['<25', '25-34', '35-44', '45-54', '55-64', '65+', 'no_data']; /** HPV categories the cards do not draw (their reports stay in the total and the percentages). */ const HPV_HIDDEN = { @@ -156,7 +156,7 @@ const ppv = ( }, { kind: 'shares', - label: 'Por detección inicial y subsecuente', + label: 'Por detección inicial y anterior', caption: ROUND_CAPTION, measure, stratum: 'round', diff --git a/src/app/indicadores/pages.ts b/src/app/indicadores/pages.ts index 8e35b9f..f0626d5 100644 --- a/src/app/indicadores/pages.ts +++ b/src/app/indicadores/pages.ts @@ -286,7 +286,7 @@ export const PAGES: Record = { opportunity: [ { kind: 'route', - title: 'Tiempo de tamizaje a diagnóstico', + title: 'Tiempo de tamizaje a diagnóstico y tratamiento', // from the mammography: only the two measures that start at it sample: [ { label: 'Interpretación radiológica', measure: 'CAMA_EU38A' }, @@ -301,9 +301,15 @@ export const PAGES: Record = { label: 'Interpretación radiológica a diagnóstico', measure: 'CAMA_DIAS_RESULTADO_DIAGNOSTICO', }, + { + label: 'Diagnóstico tras biopsia a tratamiento', + measure: 'CAMA_DIAS_DIAGNOSTICO_TRATAMIENTO', + }, { label: 'Interpretación radiológica a resultado de biopsia', measure: 'CAMA_DIAS_RESULTADO_BIOPSIA', + // from the interpretation, as the diagnosis: not after it + after: 0, }, ], }, diff --git a/src/app/indicadores/route-card.ts b/src/app/indicadores/route-card.ts index 6e5f19c..bd58705 100644 --- a/src/app/indicadores/route-card.ts +++ b/src/app/indicadores/route-card.ts @@ -2,7 +2,7 @@ import { Component, input, signal } from '@angular/core'; import { MatButtonToggleModule } from '@angular/material/button-toggle'; import { MatCardModule } from '@angular/material/card'; import { Loading } from '../loading'; -import { DurationRow, durationMax } from './durations'; +import { chained, DurationRow, durationMax } from './durations'; /** A screening route as one compact card: a bar per step with its median, its observations * and its quartiles, read step by step or cumulatively from the sample. A step that is not @@ -29,15 +29,16 @@ import { DurationRow, durationMax } from './durations'; @if (loading()) { } @else { - @let rows = mode() === 'sample' ? sample() : step(); + @let rows = mode() === 'sample' ? sample() : chain(step()); @let max = scale(rows);

@if (mode() === 'sample') { Mediana de días desde la toma de la mastografía hasta cada etapa; cada medida se calcula por separado. } @else { - Cada barra es la mediana de su paso, desde cero y por separado; los pasos pueden - corresponder a poblaciones diferentes, por lo que las medianas no se suman. + Esquema: cada barra es la mediana de su paso y empieza donde termina el paso del que + parte. Los pasos pueden corresponder a poblaciones diferentes, por lo que las + medianas no se suman. } Las marcas indican el primer y tercer cuartil. @if (max) { @@ -62,16 +63,17 @@ import { DurationRow, durationMax } from './durations'; @@ -180,4 +182,5 @@ export class RouteCard { protected readonly mode = signal<'sample' | 'step'>('step'); protected readonly scale = durationMax; + protected readonly chain = chained; }