CaCu Indicadores as the old page: its cards and words, the route, cytology and biopsy donuts, results by clinical scenario, confirmation rates; the page test compares with the capture; the guard injects before it waits
This commit is contained in:
@@ -8,6 +8,15 @@ import type { Measure, MeasureReport } from 'fhir/r4';
|
||||
import { Fhir, resources } from '../fhir';
|
||||
import { Figure, Plot } from '../plot';
|
||||
import { LAYOUTS } from './layout';
|
||||
import {
|
||||
FigureSpec,
|
||||
nestedDonut,
|
||||
PAGES,
|
||||
rateDots,
|
||||
routeFigure,
|
||||
scenarioBars,
|
||||
Section,
|
||||
} from './pages';
|
||||
import {
|
||||
detail,
|
||||
donut,
|
||||
@@ -56,6 +65,8 @@ export class TabIndicadores {
|
||||
protected readonly layout = computed(
|
||||
() => LAYOUTS[this.domain()] ?? { kpis: [], route: [], anchor: '' },
|
||||
);
|
||||
/** The old app's page for this domain, when it is rebuilt as it was (else today's). */
|
||||
protected readonly page = computed(() => PAGES[this.domain()]);
|
||||
private readonly byName = computed(() => new Map(this.measures().map((m) => [m.name!, m])));
|
||||
protected readonly kpis = computed(() =>
|
||||
this.layout()
|
||||
@@ -74,7 +85,7 @@ export class TabIndicadores {
|
||||
private readonly latest = resource({
|
||||
params: () => ({
|
||||
domain: this.domain(),
|
||||
anchor: this.byName().get(this.layout().anchor) ?? this.measures()[0],
|
||||
anchor: this.byName().get(this.page()?.anchor ?? this.layout().anchor) ?? this.measures()[0],
|
||||
all: this.options(),
|
||||
}),
|
||||
loader: async ({ params }) => {
|
||||
@@ -156,7 +167,7 @@ export class TabIndicadores {
|
||||
private build(m: Measure, r: Reading | undefined): { title: string; figure: Figure }[] {
|
||||
if (!r || !(r.populations['initial-population'] ?? 0)) return [];
|
||||
const strata = Object.keys(r.strata).filter(
|
||||
(s) => s !== 'category' && Object.keys(r.strata[s]).length,
|
||||
(s) => s !== 'category' && !s.includes('-') && Object.keys(r.strata[s]).length,
|
||||
);
|
||||
const kind = scoring(m);
|
||||
if (kind === 'continuous-variable')
|
||||
@@ -170,4 +181,50 @@ export class TabIndicadores {
|
||||
];
|
||||
}
|
||||
protected readonly name = name;
|
||||
|
||||
/** A measure's reading in the applied period, by code. */
|
||||
protected rd(code: string): Reading | undefined {
|
||||
return this.reports.value()?.get(code);
|
||||
}
|
||||
protected kpi(code: string): Measure | undefined {
|
||||
return this.byName().get(code);
|
||||
}
|
||||
/** A KPI card's value as the old cards wrote it. */
|
||||
protected kpiValue(code: string): string {
|
||||
const m = this.kpi(code);
|
||||
const r = this.rd(code);
|
||||
if (!m || !r || r.score === undefined) return '';
|
||||
if (scoring(m) === 'continuous-variable') return `${Math.round(r.score)} días (mediana)`;
|
||||
if (scoring(m) === 'proportion') return `${(r.score * 100).toFixed(1)} %`;
|
||||
const n = r.populations['initial-population'] ?? 0;
|
||||
return `${n.toLocaleString('es-MX')} pacientes`;
|
||||
}
|
||||
protected kpiNote(code: string, note?: string): string {
|
||||
const m = this.kpi(code);
|
||||
const r = this.rd(code);
|
||||
if (!m || !r || r.score === undefined) return 'Sin valor disponible';
|
||||
if (scoring(m) === 'continuous-variable') {
|
||||
const n = (r.populations['measure-observation'] ?? 0).toLocaleString('es-MX');
|
||||
return `${n} citologías; primer cuartil: ${Math.round(r.low ?? r.score)} días; tercer cuartil: ${Math.round(r.high ?? r.score)} días.`;
|
||||
}
|
||||
return note ?? detail(m, r);
|
||||
}
|
||||
/** A clinical section's route or figures, drawn from the applied period's reports. */
|
||||
protected routeOf(section: Section): Figure | undefined {
|
||||
if (section.kind !== 'route') return undefined;
|
||||
const steps = section.steps.map((s) => ({ label: s.label, r: this.rd(s.measure) }));
|
||||
return steps.some((s) => s.r?.score !== undefined) ? routeFigure(steps) : undefined;
|
||||
}
|
||||
protected figureOf(spec: FigureSpec): Figure | undefined {
|
||||
const r = this.rd(spec.measure);
|
||||
if (!r || !(r.populations['initial-population'] ?? 0)) return undefined;
|
||||
switch (spec.kind) {
|
||||
case 'donut':
|
||||
return nestedDonut(r, spec.catalog, spec.center);
|
||||
case 'scenario-bars':
|
||||
return scenarioBars(r, spec.catalog, spec.stratum, name);
|
||||
case 'rates':
|
||||
return rateDots(r, spec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user