diff --git a/src/app/indicadores/bars.spec.ts b/src/app/indicadores/bars.spec.ts index d81128d..76e2464 100644 --- a/src/app/indicadores/bars.spec.ts +++ b/src/app/indicadores/bars.spec.ts @@ -93,6 +93,7 @@ describe('bars', () => { const aggregate = { label: 'Anormal', color: '#f00', codes: ['LSIL', 'HSIL'] }; const t = bars({ kind: 'counts', label: 'x', measure: 'M', catalog, aggregate }, () => r)!; expect(t.rows[1].cells).toEqual(['3', '30.0 %']); + expect(t.rows.map((row) => !!row.sub)).toEqual([false, false, true, true, false].slice(0, t.rows.length)); const g = grouped( { kind: 'grouped', diff --git a/src/app/indicadores/bars.ts b/src/app/indicadores/bars.ts index 6386a3c..5737c4a 100644 --- a/src/app/indicadores/bars.ts +++ b/src/app/indicadores/bars.ts @@ -123,6 +123,7 @@ export type Tint = { bar: string; mark: string }; /** One category of a group as an independent bar of 0 to 100 %: its records over the group's. */ export interface GroupRow { + sub?: boolean; label: string; color: string; count: number; @@ -149,6 +150,8 @@ export interface Groups { /** One bar: its length and quartile marks in % of the scale, and its cells of text. */ export interface Bar { + /** one of the categories the aggregate row above adds up */ + sub?: boolean; label: string; /** why the row has no figures: no patients in the group, or not available */ hint?: string; @@ -267,7 +270,8 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined): rows: all.flatMap(({ code, label, color }, index) => { const n = size(cells[code]); const cols = [`${n}`, pct(n, total)]; - const row = { label, color, width: (100 * n) / most, marks: [], cells: cols }; + const part = !!mode.aggregate?.codes.includes(code); + const row = { label, color, width: (100 * n) / most, marks: [], cells: cols, sub: part }; if (index !== 0 || !mode.aggregate) return [row]; const a = mode.aggregate; const sum = a.codes.reduce((total, key) => total + size(cells[key]), 0); @@ -467,6 +471,25 @@ 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 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 * drawn empty only when the listed ones add up to every record of the period (`complete`). */ @@ -515,6 +538,7 @@ export function grouped( count, of: den, percent, + sub: !!mode.aggregate?.codes.includes(c.code), text: `${count}/${den} · ${percent === undefined ? '—' : percent.toFixed(1) + ' %'}`, }; if (index !== 0 || !mode.aggregate) return [row]; diff --git a/src/app/indicadores/readings.ts b/src/app/indicadores/readings.ts index 36dcb28..77953d5 100644 --- a/src/app/indicadores/readings.ts +++ b/src/app/indicadores/readings.ts @@ -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, unavailable } from './bars'; +import { bars, grouped, hiddenNote, Mode, subsequentHistory, unavailable } from './bars'; import { Reading } from './measures'; /** A card read one mode at a time: its title, its headline, the toggle and the bars. */ @@ -60,7 +60,7 @@ import { Reading } from './measures'; } @for (row of group.rows; track row.label) { -