Separar la ronda subsecuente por última detección y encadenar los tiempos por paso
This commit is contained in:
+49
-12
@@ -69,7 +69,13 @@ export type Mode = {
|
||||
ofAll?: boolean;
|
||||
hidden?: Hidden;
|
||||
}
|
||||
| { kind: 'days'; steps: { label: string; measure: string }[]; tint?: Tint }
|
||||
| {
|
||||
kind: 'days';
|
||||
steps: { label: string; measure: string }[];
|
||||
tint?: Tint;
|
||||
/** each bar starts where the previous one ends (a schematic sequence, as a Gantt chart) */
|
||||
staggered?: boolean;
|
||||
}
|
||||
/** A proportion as one bar of 0 to 100 %, its 95 % interval as the two marks on it */
|
||||
| { kind: 'ratio'; measure: string; colors?: Colors; percentLabel?: string }
|
||||
| { kind: 'days-by'; measure: string; stratum: string; tint?: Tint }
|
||||
@@ -156,6 +162,8 @@ export interface Bar {
|
||||
/** why the row has no figures: no patients in the group, or not available */
|
||||
hint?: string;
|
||||
color?: string;
|
||||
/** where the bar starts, in % of the scale */
|
||||
offset?: number;
|
||||
width: number;
|
||||
marks: number[];
|
||||
cells: string[];
|
||||
@@ -372,6 +380,7 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
|
||||
return { label, n: r?.populations['measure-observation'] ?? 0, score: r };
|
||||
}),
|
||||
mode.tint,
|
||||
mode.staggered,
|
||||
);
|
||||
case 'days-by': {
|
||||
const r = of(mode.measure);
|
||||
@@ -471,12 +480,17 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
|
||||
}
|
||||
}
|
||||
|
||||
/** The subsequent round split by the form's last screening, drawn after that round's group. */
|
||||
/** 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',
|
||||
];
|
||||
|
||||
/** 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
|
||||
@@ -493,8 +507,16 @@ 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)
|
||||
.filter(([k]) => k.split('|')[0] === g)
|
||||
.map(([k, c]) => [k.split('|')[1], c]);
|
||||
const n = (g: string, c: string) =>
|
||||
size((answers.includes(g) ? history : cells)[`${g}|${c}`]);
|
||||
cellsOf(g).reduce((t, [category, cell]) => (category === c ? t + size(cell) : t), 0);
|
||||
const reconciled = reconciles(
|
||||
Object.values(cells).map((c) => c['initial-population']),
|
||||
patients(r),
|
||||
@@ -505,21 +527,24 @@ export function grouped(
|
||||
];
|
||||
const total = (g: string) =>
|
||||
mode.ofAll
|
||||
? Object.entries(answers.includes(g) ? history : cells)
|
||||
.filter(([k]) => k.split('|')[0] === g)
|
||||
.reduce((t, [, c]) => t + size(c), 0)
|
||||
? cellsOf(g).reduce((t, [, c]) => t + size(c), 0)
|
||||
: mode.catalog.reduce((t, c) => t + n(g, c.code), 0);
|
||||
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.slice(0, at),
|
||||
...answers,
|
||||
...(unanswered.length ? [NO_LAST_SCREENING[0]] : []),
|
||||
...codes.slice(at + 1),
|
||||
]
|
||||
: codes;
|
||||
const groups: Group[] = drawn.map((code) => {
|
||||
const den = total(code);
|
||||
return {
|
||||
code,
|
||||
label:
|
||||
LAST_SCREENING.find(([answer]) => answer === code)?.[1] ??
|
||||
[...LAST_SCREENING, NO_LAST_SCREENING].find(([answer]) => answer === code)?.[1] ??
|
||||
(mode.stratum === 'age_group' &&
|
||||
code === '<25' &&
|
||||
['CACU_EU7', 'CACU_VPH_GENOTIPO'].includes(mode.measure)
|
||||
@@ -560,7 +585,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' && !answers.includes(g.code));
|
||||
const classified = groups.filter((g) => g.code !== 'no_data');
|
||||
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.'
|
||||
@@ -639,21 +664,33 @@ type Score = { score?: number; low?: number; high?: number };
|
||||
function medians(
|
||||
rows: { label: string; n: number; score?: Score }[],
|
||||
tint?: Tint,
|
||||
staggered?: boolean,
|
||||
): Bars | undefined {
|
||||
if (!rows.some((r) => r.score?.score !== undefined)) return undefined;
|
||||
const top = Math.max(...rows.flatMap((r) => [r.score?.score ?? 0, r.score?.high ?? 0])) || 1;
|
||||
// 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 ends = rows.map(
|
||||
(r, i) => starts[i] + Math.max(r.score?.score ?? 0, r.score?.high ?? 0),
|
||||
);
|
||||
const top = Math.max(...ends) || 1;
|
||||
const at = (v: number) => (100 * v) / top;
|
||||
return {
|
||||
head: ['Mediana', 'Observaciones', 'Q1–Q3'],
|
||||
markColor: tint?.mark,
|
||||
rows: rows.map(({ label, n, score: s }) => {
|
||||
rows: rows.map(({ label, n, score: s }, i) => {
|
||||
if (s?.score === undefined) return { label, width: 0, marks: [], cells: ['—', `${n}`, '—'] };
|
||||
const spread = s.low !== undefined && s.high !== undefined ? [s.low, s.high] : [];
|
||||
return {
|
||||
label,
|
||||
color: tint?.bar,
|
||||
offset: staggered ? at(starts[i]) : undefined,
|
||||
width: at(s.score),
|
||||
marks: spread.map(at),
|
||||
marks: spread.map((v) => at(starts[i] + v)),
|
||||
cells: [`${days(s.score)} días`, `${n}`, spread.map(days).join('–') || '—'],
|
||||
};
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user