Dibujar la ronda subsecuente por última detección y conectar diagnóstico a tratamiento de CaMa

This commit is contained in:
2026-12-04 01:23:41 -06:00
parent 94c3bb6d82
commit cbc41ca365
5 changed files with 60 additions and 43 deletions
+24
View File
@@ -508,3 +508,27 @@ describe('independent bars by group', () => {
expect(bars(mode as any, () => r)!.rows.map((x) => x.color)).toEqual(['#a', '#b']);
});
});
describe('the subsequent round by last screening', () => {
it('draws each answer as its own group after the subsequent one', () => {
const cell = (n: number) => ({ 'initial-population': n });
const r: Reading = {
populations: { 'initial-population': 3 },
strata: {
'round-category': { 'subsequent|NILM': cell(3) },
'subsequent_history-category': { 'within_1_year|NILM': cell(2) },
},
};
const catalog = [{ code: 'NILM', label: 'Normal', color: '#000' }];
const found = grouped(
{ kind: 'grouped', label: 'x', measure: 'M', catalog, unit: 'pacientes', stratum: 'round', order: ['subsequent'] },
() => r,
)!;
expect(found.groups.map((g) => [g.code, g.total])).toEqual([
['subsequent', 3],
['within_1_year', 2],
['2_years', 0],
['3_or_more_years', 0],
]);
});
});
+22 -24
View File
@@ -471,24 +471,12 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
}
}
/** The form's last-screening answers within the subsequent round, over that round's total. */
export function subsequentHistory(reading?: Reading) {
const values = reading?.strata['subsequent_history'];
const den = reading?.strata['round']?.['subsequent']?.['initial-population'] ?? 0;
if (!values) return undefined;
return [
['within_1_year', 'Un año o menos'],
['2_years', 'Dos años'],
['3_or_more_years', 'Tres o más años'],
['no_data', 'Sin dato'],
].map(([code, label]) => {
const count = values[code]?.['initial-population'] ?? 0;
return {
label,
text: `${count}/${den} · ${den ? ((100 * count) / den).toFixed(1) + ' %' : '—'}`,
};
});
}
/** The subsequent round split by the form's last screening, drawn after 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'],
];
/** The groups of a grouped mode: each group (an age group, a follow-up status, a screening round) with
* one independent bar per category over the group's own records. A group the report leaves out is
@@ -502,7 +490,11 @@ export function grouped(
const cells = r?.strata[`${mode.stratum}-category`] ?? {};
const found = [...new Set(Object.keys(cells).map((k) => k.split('|')[0]))];
if (!patients(r) || !found.length) return undefined;
const n = (g: string, c: string) => size(cells[`${g}|${c}`]);
const history =
mode.stratum === 'round' ? (r?.strata['subsequent_history-category'] ?? {}) : {};
const answers = LAST_SCREENING.map(([code]) => code);
const n = (g: string, c: string) =>
size((answers.includes(g) ? history : cells)[`${g}|${c}`]);
const reconciled = reconciles(
Object.values(cells).map((c) => c['initial-population']),
patients(r),
@@ -513,20 +505,26 @@ export function grouped(
];
const total = (g: string) =>
mode.ofAll
? Object.entries(cells)
? Object.entries(answers.includes(g) ? history : cells)
.filter(([k]) => k.split('|')[0] === g)
.reduce((t, [, c]) => t + size(c), 0)
: mode.catalog.reduce((t, c) => t + n(g, c.code), 0);
const groups: Group[] = codes.map((code) => {
const at = codes.indexOf('subsequent');
const drawn =
mode.stratum === 'round' && at >= 0 && r?.strata['subsequent_history-category']
? [...codes.slice(0, at + 1), ...answers, ...codes.slice(at + 1)]
: codes;
const groups: Group[] = drawn.map((code) => {
const den = total(code);
return {
code,
label:
mode.stratum === 'age_group' &&
LAST_SCREENING.find(([answer]) => answer === code)?.[1] ??
(mode.stratum === 'age_group' &&
code === '<25' &&
['CACU_EU7', 'CACU_VPH_GENOTIPO'].includes(mode.measure)
? '15-24'
: name(code),
: name(code)),
total: den,
hint: den ? undefined : `Sin ${mode.unit} en el grupo`,
rows: mode.catalog.flatMap((c, index) => {
@@ -562,7 +560,7 @@ export function grouped(
let note = hiddenNote(mode, of);
if (mode.complete) {
const unclassified = total('no_data');
const classified = groups.filter((g) => g.code !== 'no_data');
const classified = groups.filter((g) => g.code !== 'no_data' && !answers.includes(g.code));
const none = classified.every((g) => !g.total);
const sentence = !reconciled
? 'Los conteos del informe no concilian con el total: los grupos ausentes no se muestran como cero.'
@@ -0,0 +1,9 @@
import { HISTORY, PAGES } from './pages';
describe('tiempo de diagnóstico tras biopsia a tratamiento en CaMa', () => {
it('conecta la tarjeta y el histórico con la medida', () => {
const measure = 'CAMA_DIAS_DIAGNOSTICO_TRATAMIENTO';
expect(PAGES['cama'].kpis.some((card) => card.measure === measure)).toBe(true);
expect(HISTORY['cama'].panels.some((panel) => panel.measure === measure)).toBe(true);
});
});
+4 -3
View File
@@ -273,9 +273,9 @@ export const PAGES: Record<string, Page> = {
...CAMA_DAYS,
},
{
title: 'Tiempo de diagnóstico a tratamiento',
value: 'Indicador no disponible',
note: 'Indicador no publicado en el catálogo institucional.',
measure: 'CAMA_DIAS_DIAGNOSTICO_TRATAMIENTO',
title: 'Tiempo de diagnóstico tras biopsia a tratamiento',
...CAMA_DAYS,
},
{
measure: 'CAMA_DIAS_TOMA_DIAGNOSTICO',
@@ -522,6 +522,7 @@ export const HISTORY: Record<string, History> = {
cama: {
line: '#9C42C2',
panels: [
{ title: 'Tiempo de diagnóstico tras biopsia a tratamiento', measure: 'CAMA_DIAS_DIAGNOSTICO_TRATAMIENTO', kind: 'median' },
{
title: 'Días de la toma de la mastografía a su resultado',
measure: 'CAMA_EU38A',
+1 -16
View File
@@ -2,7 +2,7 @@ import { Component, computed, input, signal } from '@angular/core';
import { MatButtonToggleModule } from '@angular/material/button-toggle';
import { Loading } from '../loading';
import { Figure, Plot } from '../plot';
import { bars, grouped, hiddenNote, Mode, subsequentHistory, unavailable } from './bars';
import { bars, grouped, hiddenNote, Mode, unavailable } from './bars';
import { Reading } from './measures';
/** A card read one mode at a time: its title, its headline, the toggle and the bars. */
@@ -77,16 +77,6 @@ import { Reading } from './measures';
@if (g.note) {
<p class="state">{{ g.note }}</p>
}
@if (historyBreakdown(); as history) {
<section aria-label="Última detección en la ronda subsecuente">
<h4>Detección subsecuente por tiempo desde la última detección</h4>
<ul>
@for (item of history; track item.label) {
<li>{{ item.label }}: {{ item.text }}</li>
}
</ul>
</section>
}
} @else if (figure(); as f) {
<app-plot [figure]="f" [height]="height()" />
@if (hidden(); as why) {
@@ -387,11 +377,6 @@ export class Readings {
() => this.modes().find((m) => m.label === (this.view() || this.chosen())) ?? this.modes()[0],
);
protected readonly groups = computed(() => grouped(this.mode(), this.read()));
protected readonly historyBreakdown = computed(() => {
const mode = this.mode();
if (mode.kind !== 'grouped' || mode.stratum !== 'round') return undefined;
return subsequentHistory(this.read()(mode.measure));
});
protected readonly table = computed(() => bars(this.mode(), this.read()));
/** The bars of a scenarios figure need more room than a donut. */
protected readonly height = computed(() => {