Merge the CaMa diagnostic pathway and biopsy results into the CaCu rounds, record and risk work
This commit is contained in:
@@ -6,8 +6,20 @@ import { name, Reading } from './measures';
|
||||
export type Category = { code: string; label: string; color: string };
|
||||
|
||||
/** One way of reading a card, as bars from the reports, or a figure. */
|
||||
export type Mode = { label: string; caption?: string } & (
|
||||
| { kind: 'counts'; measure: string; catalog: Category[]; hidden?: Hidden }
|
||||
export type Mode = {
|
||||
label: string;
|
||||
caption?: string;
|
||||
/** said above the table: what its rows count (patients, reported biopsies…) */
|
||||
heading?: string;
|
||||
} & (
|
||||
| {
|
||||
kind: 'counts';
|
||||
measure: string;
|
||||
catalog: Category[];
|
||||
hidden?: Hidden;
|
||||
/** every bar on a fixed scale of 0 to 100 %, so its length is the share shown */
|
||||
percent?: boolean;
|
||||
}
|
||||
| {
|
||||
kind: 'shares';
|
||||
measure: string;
|
||||
@@ -43,6 +55,18 @@ export type Mode = { label: string; caption?: string } & (
|
||||
}
|
||||
| { kind: 'days'; steps: { label: string; measure: string }[]; tint?: Tint }
|
||||
| { kind: 'days-by'; measure: string; stratum: string; tint?: Tint }
|
||||
/** A proportion as its two parts (what counted and what did not), in units, with the shares */
|
||||
| { kind: 'split'; measure: string; yes: string; no: string; colors?: [string, string] }
|
||||
/** Each row's units by result (a bar in segments), and the share of the row's units with a
|
||||
* result that are `malignant`; a row with units and no result is not a row with none */
|
||||
| {
|
||||
kind: 'outcomes';
|
||||
measure: string;
|
||||
stratum: string;
|
||||
rows: Category[];
|
||||
results: Category[];
|
||||
malignant: string[];
|
||||
}
|
||||
| {
|
||||
kind: 'figure';
|
||||
measure: string;
|
||||
@@ -104,6 +128,10 @@ export interface Bar {
|
||||
width: number;
|
||||
marks: number[];
|
||||
cells: string[];
|
||||
/** the bar in parts (in % of the bar), each with what it says when hovered */
|
||||
segments?: { width: number; color: string; title: string }[];
|
||||
/** said in place of the bar (a row with nothing to draw) */
|
||||
none?: string;
|
||||
}
|
||||
export interface Bars {
|
||||
head: string[];
|
||||
@@ -112,6 +140,8 @@ export interface Bars {
|
||||
markColor?: string;
|
||||
/** what the reader must know to take the rows right */
|
||||
note?: string;
|
||||
/** the colours of the segments */
|
||||
legend?: { label: string; color: string }[];
|
||||
}
|
||||
|
||||
export const NOT_AVAILABLE = 'No disponible';
|
||||
@@ -186,7 +216,7 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
|
||||
...mode.catalog.filter((c) => !hidden.includes(c.code)),
|
||||
...rest.map((code) => ({ code, label: name(code), color: NEUTRAL_DARK })),
|
||||
];
|
||||
const most = Math.max(...Object.values(cells).map(size));
|
||||
const most = mode.percent ? total : Math.max(...Object.values(cells).map(size));
|
||||
return {
|
||||
head: ['n', '%'],
|
||||
rows: all.map(({ code, label, color }) => {
|
||||
@@ -290,6 +320,66 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
|
||||
mode.tint,
|
||||
);
|
||||
}
|
||||
case 'split': {
|
||||
const { numerator = 0, denominator = 0 } = of(mode.measure)?.populations ?? {};
|
||||
if (!denominator) return undefined;
|
||||
const parts: [string, number][] = [
|
||||
[mode.yes, numerator],
|
||||
[mode.no, denominator - numerator],
|
||||
];
|
||||
return {
|
||||
head: ['n', '%'],
|
||||
rows: parts.map(([label, n], i) => ({
|
||||
label,
|
||||
color: mode.colors?.[i],
|
||||
width: (100 * n) / denominator,
|
||||
marks: [],
|
||||
cells: [`${n}`, pct(n, denominator)],
|
||||
})),
|
||||
};
|
||||
}
|
||||
case 'outcomes': {
|
||||
const r = of(mode.measure);
|
||||
const units = r?.strata[mode.stratum] ?? {};
|
||||
const cells = r?.strata[`${mode.stratum}-category`] ?? {};
|
||||
if (!Object.keys(units).length) return undefined;
|
||||
const graded = (i: number) => !['no_biopsy', 'no_data'].includes(mode.results[i].code);
|
||||
return {
|
||||
head: ['Pacientes', ...mode.results.map((x) => x.label), '% maligno'],
|
||||
legend: mode.results.map(({ label, color }) => ({ label, color })),
|
||||
rows: mode.rows.map(({ code, label }) => {
|
||||
const n = size(units[code]);
|
||||
const by = mode.results.map((x) => size(cells[`${code}|${x.code}`]));
|
||||
const den = by.reduce((t, k, i) => t + (graded(i) ? k : 0), 0);
|
||||
const bad = by.reduce(
|
||||
(t, k, i) => t + (mode.malignant.includes(mode.results[i].code) ? k : 0),
|
||||
0,
|
||||
);
|
||||
return {
|
||||
label,
|
||||
width: 100,
|
||||
marks: [],
|
||||
none: n ? undefined : 'Sin pacientes en el periodo',
|
||||
segments: mode.results.map((x, i) => ({
|
||||
width: n ? (100 * by[i]) / n : 0,
|
||||
color: x.color,
|
||||
title: `${x.label}: ${by[i]} de ${n} (${pct(by[i], n)})`,
|
||||
})),
|
||||
cells: [
|
||||
`${n}`,
|
||||
...by.map((k) => (n ? `${k}` : '—')),
|
||||
n
|
||||
? den
|
||||
? `${bad}/${den} (${pct(bad, den)})`
|
||||
: by[mode.results.findIndex((x) => x.code === 'no_data')]
|
||||
? 'Sin biopsias clasificables'
|
||||
: 'Sin biopsias'
|
||||
: '—',
|
||||
],
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user