Separar la ronda subsecuente por última detección y encadenar los tiempos por paso
This commit is contained in:
@@ -510,25 +510,51 @@ describe('independent bars by group', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('the subsequent round by last screening', () => {
|
describe('the subsequent round by last screening', () => {
|
||||||
it('draws each answer as its own group after the subsequent one', () => {
|
it('chains the steps of a time window, quartiles moving with their bar', () => {
|
||||||
const cell = (n: number) => ({ 'initial-population': n });
|
const median = (score: number, low: number, high: number): Reading => ({
|
||||||
|
populations: { 'measure-observation': 1 },
|
||||||
|
strata: {},
|
||||||
|
score,
|
||||||
|
low,
|
||||||
|
high,
|
||||||
|
});
|
||||||
|
const steps = [
|
||||||
|
{ label: 'a', measure: 'A' },
|
||||||
|
{ label: 'b', measure: 'B' },
|
||||||
|
];
|
||||||
|
const table = bars({ kind: 'days', label: 'x', steps, staggered: true }, (m) =>
|
||||||
|
m === 'A' ? median(10, 5, 10) : median(20, 10, 30),
|
||||||
|
)!;
|
||||||
|
expect(table.rows.map((r) => [r.offset, r.width, r.marks])).toEqual([
|
||||||
|
[0, 25, [12.5, 25]],
|
||||||
|
[25, 50, [50, 100]],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
it('splits the subsequent round by last screening, keeping those without an answer', () => {
|
||||||
|
const one = { 'initial-population': 1 };
|
||||||
const r: Reading = {
|
const r: Reading = {
|
||||||
populations: { 'initial-population': 3 },
|
populations: { 'initial-population': 3 },
|
||||||
strata: {
|
strata: {
|
||||||
'round-category': { 'subsequent|NILM': cell(3) },
|
'round-category': { 'initial|a': one, 'subsequent|a': { 'initial-population': 2 } },
|
||||||
'subsequent_history-category': { 'within_1_year|NILM': cell(2) },
|
'subsequent_history-category': { 'within_1_year|a': one, 'no_data|a': one },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const catalog = [{ code: 'NILM', label: 'Normal', color: '#000' }];
|
const mode: Mode = {
|
||||||
const found = grouped(
|
kind: 'grouped',
|
||||||
{ kind: 'grouped', label: 'x', measure: 'M', catalog, unit: 'pacientes', stratum: 'round', order: ['subsequent'] },
|
label: 'x',
|
||||||
() => r,
|
measure: 'M',
|
||||||
)!;
|
stratum: 'round',
|
||||||
expect(found.groups.map((g) => [g.code, g.total])).toEqual([
|
order: ['initial', 'subsequent'],
|
||||||
['subsequent', 3],
|
unit: 'pacientes',
|
||||||
['within_1_year', 2],
|
catalog: [{ code: 'a', label: 'A', color: '#000' }],
|
||||||
|
};
|
||||||
|
const { groups } = grouped(mode, () => r)!;
|
||||||
|
expect(groups.map((g) => [g.code, g.total])).toEqual([
|
||||||
|
['initial', 1],
|
||||||
|
['within_1_year', 1],
|
||||||
['2_years', 0],
|
['2_years', 0],
|
||||||
['3_or_more_years', 0],
|
['3_or_more_years', 0],
|
||||||
|
['subsequent_without_last_screening', 1],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+49
-12
@@ -69,7 +69,13 @@ export type Mode = {
|
|||||||
ofAll?: boolean;
|
ofAll?: boolean;
|
||||||
hidden?: Hidden;
|
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 */
|
/** 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: 'ratio'; measure: string; colors?: Colors; percentLabel?: string }
|
||||||
| { kind: 'days-by'; measure: string; stratum: string; tint?: Tint }
|
| { 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 */
|
/** why the row has no figures: no patients in the group, or not available */
|
||||||
hint?: string;
|
hint?: string;
|
||||||
color?: string;
|
color?: string;
|
||||||
|
/** where the bar starts, in % of the scale */
|
||||||
|
offset?: number;
|
||||||
width: number;
|
width: number;
|
||||||
marks: number[];
|
marks: number[];
|
||||||
cells: string[];
|
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 };
|
return { label, n: r?.populations['measure-observation'] ?? 0, score: r };
|
||||||
}),
|
}),
|
||||||
mode.tint,
|
mode.tint,
|
||||||
|
mode.staggered,
|
||||||
);
|
);
|
||||||
case 'days-by': {
|
case 'days-by': {
|
||||||
const r = of(mode.measure);
|
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][] = [
|
const LAST_SCREENING: [string, string][] = [
|
||||||
['within_1_year', 'Subsecuente: última detección hace un año o menos'],
|
['within_1_year', 'Subsecuente: última detección hace un año o menos'],
|
||||||
['2_years', 'Subsecuente: última detección hace dos años'],
|
['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'],
|
['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
|
/** 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
|
* 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 =
|
const history =
|
||||||
mode.stratum === 'round' ? (r?.strata['subsequent_history-category'] ?? {}) : {};
|
mode.stratum === 'round' ? (r?.strata['subsequent_history-category'] ?? {}) : {};
|
||||||
const answers = LAST_SCREENING.map(([code]) => code);
|
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) =>
|
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(
|
const reconciled = reconciles(
|
||||||
Object.values(cells).map((c) => c['initial-population']),
|
Object.values(cells).map((c) => c['initial-population']),
|
||||||
patients(r),
|
patients(r),
|
||||||
@@ -505,21 +527,24 @@ export function grouped(
|
|||||||
];
|
];
|
||||||
const total = (g: string) =>
|
const total = (g: string) =>
|
||||||
mode.ofAll
|
mode.ofAll
|
||||||
? Object.entries(answers.includes(g) ? history : cells)
|
? cellsOf(g).reduce((t, [, c]) => t + size(c), 0)
|
||||||
.filter(([k]) => k.split('|')[0] === g)
|
|
||||||
.reduce((t, [, c]) => t + size(c), 0)
|
|
||||||
: mode.catalog.reduce((t, c) => t + n(g, c.code), 0);
|
: mode.catalog.reduce((t, c) => t + n(g, c.code), 0);
|
||||||
const at = codes.indexOf('subsequent');
|
const at = codes.indexOf('subsequent');
|
||||||
const drawn =
|
const drawn =
|
||||||
mode.stratum === 'round' && at >= 0 && r?.strata['subsequent_history-category']
|
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;
|
: codes;
|
||||||
const groups: Group[] = drawn.map((code) => {
|
const groups: Group[] = drawn.map((code) => {
|
||||||
const den = total(code);
|
const den = total(code);
|
||||||
return {
|
return {
|
||||||
code,
|
code,
|
||||||
label:
|
label:
|
||||||
LAST_SCREENING.find(([answer]) => answer === code)?.[1] ??
|
[...LAST_SCREENING, NO_LAST_SCREENING].find(([answer]) => answer === code)?.[1] ??
|
||||||
(mode.stratum === 'age_group' &&
|
(mode.stratum === 'age_group' &&
|
||||||
code === '<25' &&
|
code === '<25' &&
|
||||||
['CACU_EU7', 'CACU_VPH_GENOTIPO'].includes(mode.measure)
|
['CACU_EU7', 'CACU_VPH_GENOTIPO'].includes(mode.measure)
|
||||||
@@ -560,7 +585,7 @@ export function grouped(
|
|||||||
let note = hiddenNote(mode, of);
|
let note = hiddenNote(mode, of);
|
||||||
if (mode.complete) {
|
if (mode.complete) {
|
||||||
const unclassified = total('no_data');
|
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 none = classified.every((g) => !g.total);
|
||||||
const sentence = !reconciled
|
const sentence = !reconciled
|
||||||
? 'Los conteos del informe no concilian con el total: los grupos ausentes no se muestran como cero.'
|
? '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(
|
function medians(
|
||||||
rows: { label: string; n: number; score?: Score }[],
|
rows: { label: string; n: number; score?: Score }[],
|
||||||
tint?: Tint,
|
tint?: Tint,
|
||||||
|
staggered?: boolean,
|
||||||
): Bars | undefined {
|
): Bars | undefined {
|
||||||
if (!rows.some((r) => r.score?.score !== undefined)) return 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;
|
const at = (v: number) => (100 * v) / top;
|
||||||
return {
|
return {
|
||||||
head: ['Mediana', 'Observaciones', 'Q1–Q3'],
|
head: ['Mediana', 'Observaciones', 'Q1–Q3'],
|
||||||
markColor: tint?.mark,
|
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}`, '—'] };
|
if (s?.score === undefined) return { label, width: 0, marks: [], cells: ['—', `${n}`, '—'] };
|
||||||
const spread = s.low !== undefined && s.high !== undefined ? [s.low, s.high] : [];
|
const spread = s.low !== undefined && s.high !== undefined ? [s.low, s.high] : [];
|
||||||
return {
|
return {
|
||||||
label,
|
label,
|
||||||
color: tint?.bar,
|
color: tint?.bar,
|
||||||
|
offset: staggered ? at(starts[i]) : undefined,
|
||||||
width: at(s.score),
|
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('–') || '—'],
|
cells: [`${days(s.score)} días`, `${n}`, spread.map(days).join('–') || '—'],
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -227,7 +227,9 @@ export const CACU: Page = {
|
|||||||
kind: 'days',
|
kind: 'days',
|
||||||
tint: TINT,
|
tint: TINT,
|
||||||
label: 'Por ventana de tiempo',
|
label: 'Por ventana de tiempo',
|
||||||
caption: 'Cada paso mide a sus propias pacientes: las medianas no se suman.',
|
staggered: true,
|
||||||
|
caption:
|
||||||
|
'Esquema: cada barra empieza donde termina la anterior. Cada paso mide a sus propias pacientes: las medianas no se suman.',
|
||||||
steps: [
|
steps: [
|
||||||
{
|
{
|
||||||
label: 'Toma a resultado de citología',
|
label: 'Toma a resultado de citología',
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ import { Reading } from './measures';
|
|||||||
} @else {
|
} @else {
|
||||||
<span
|
<span
|
||||||
class="bar"
|
class="bar"
|
||||||
|
[style.margin-left.%]="row.offset"
|
||||||
[style.width.%]="row.width"
|
[style.width.%]="row.width"
|
||||||
[style.background]="row.color"
|
[style.background]="row.color"
|
||||||
></span>
|
></span>
|
||||||
|
|||||||
Reference in New Issue
Block a user