Nombrar la detección anterior y encadenar los tiempos de CaMa hasta el tratamiento

This commit is contained in:
2026-12-04 05:49:56 -06:00
parent 972bdf0d8a
commit e31c128991
8 changed files with 75 additions and 54 deletions
+6 -7
View File
@@ -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<br>Pacientes: 0',
'Detección subsecuente<br>Pacientes: 8',
'Con detección anterior<br>Pacientes: 8',
'Sin dato<br>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<br>Pacientes: 6']);
expect((f.data[0] as any).y).toEqual(['Con detección anterior<br>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],
]);
});
});
+11 -27
View File
@@ -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,12 +503,9 @@ 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<string, number>][] =>
g === NO_LAST_SCREENING[0]
? unanswered.map((k) => [k.split('|')[1], history[k]])
: Object.entries(answers.includes(g) ? history : cells)
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) =>
@@ -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),
);
+8 -1
View File
@@ -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]);
});
});
+27 -5
View File
@@ -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)));
+2 -2
View File
@@ -142,7 +142,7 @@ export const LABELS: Record<string, string> = {
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<string, string> = {
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',
};
+3 -3
View File
@@ -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',
+7 -1
View File
@@ -286,7 +286,7 @@ export const PAGES: Record<string, Page> = {
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<string, Page> = {
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,
},
],
},
+9 -6
View File
@@ -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()) {
<app-loading what="los tiempos" [figure]="true" />
} @else {
@let rows = mode() === 'sample' ? sample() : step();
@let rows = mode() === 'sample' ? sample() : chain(step());
@let max = scale(rows);
<p class="state">
@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';
<span class="track" aria-hidden="true">
<span
class="bar"
[style.margin-left.%]="max ? (100 * (row.start ?? 0)) / max : 0"
[style.width.%]="max ? (100 * row.median!) / max : 0"
></span>
@if (row.low !== undefined && row.high !== undefined) {
<span
class="mark"
[style.left.%]="max ? (100 * row.low) / max : 0"
[style.left.%]="max ? (100 * ((row.start ?? 0) + row.low)) / max : 0"
></span>
<span
class="mark"
[style.left.%]="max ? (100 * row.high) / max : 0"
[style.left.%]="max ? (100 * ((row.start ?? 0) + row.high)) / max : 0"
></span>
}
</span>
@@ -180,4 +182,5 @@ export class RouteCard {
protected readonly mode = signal<'sample' | 'step'>('step');
protected readonly scale = durationMax;
protected readonly chain = chained;
}