CaCu indicators: HPV genotype, biopsy results, diagnosis timing by ICD-10 and referral PPV cards

The HPV genotype and biopsy distributions, the biopsy request confirmation and the
timing by ICD-10 code are placed beside cytology. The referral PPV cards are titled as
registered procedures and say that a colposcopy may be inferred from notes and that the
preceding cytology is a date association, not a confirmed referral. The new strata and
their values have Spanish labels.
This commit is contained in:
Angel Capetillo Zavala
2026-11-27 18:42:41 -06:00
parent 07212a2083
commit 31400c77b1
8 changed files with 441 additions and 13 deletions
+92 -7
View File
@@ -8,6 +8,7 @@ import type { Measure, MeasureReport } from 'fhir/r4';
import { Fhir, resources } from '../fhir';
import { Figure, Plot } from '../plot';
import { LAYOUTS } from './layout';
import { biopsyDistribution, cytologyDistribution, hpvDistribution } from './cacu-results';
import {
detail,
donut,
@@ -21,6 +22,8 @@ import {
Reading,
scoring,
STRATA,
PPV_NOTES,
measureTitle,
strataBars,
} from './measures';
@@ -49,7 +52,7 @@ export class TabIndicadores {
protected readonly chosen = signal<string | undefined>(undefined);
/** The period the figures show (set by Aplicar). */
protected readonly applied = signal<string | undefined>(undefined);
protected readonly routeView = signal<'sample' | 'step'>('sample');
protected readonly routeView = signal<'sample' | 'step' | 'icd10'>('sample');
protected readonly layout = computed(
() => LAYOUTS[this.domain()] ?? { kpis: [], route: [], anchor: '' },
@@ -64,6 +67,7 @@ export class TabIndicadores {
const placed = new Set([
...this.layout().kpis,
...this.layout().route.flatMap((s) => [s.fromSample, s.fromStep]),
...(this.domain() === 'cacu' ? ['CACU_VPH_GENOTIPO', 'CACU_BIOPSIA_RESULTADOS', 'CACU_BIOPSIA_SOLICITUD_CONFIRMACION', 'CACU_TIEMPO_DIAGNOSTICO_CIE10'] : []),
]);
return this.measures().filter((m) => !placed.has(m.name!));
});
@@ -94,11 +98,19 @@ export class TabIndicadores {
if (!params.period) return new Map<string, Reading | undefined>();
const found = await Promise.all(
params.measures.map(async (m) => {
const page = await this.fhir.search(params.domain, 'MeasureReport', {
measure: m.id!,
'reporting-period': params.period,
});
return [m.name!, reading(resources<MeasureReport>(page, 'MeasureReport')[0])] as const;
try {
const page = await this.fhir.search(params.domain, 'MeasureReport', {
measure: m.id!,
'reporting-period': params.period,
});
return [m.name!, reading(resources<MeasureReport>(page, 'MeasureReport')[0])] as const;
} catch (error) {
if (params.domain === 'cacu' && m.name === 'CACU_BIOPSIA_SOLICITUD_CONFIRMACION')
return [m.name, { populations: {}, strata: {}, error: true } as Reading] as const;
if (params.domain === 'cacu' && ['CACU_VPH_GENOTIPO', 'CACU_BIOPSIA_RESULTADOS', 'CACU_BIOPSIA_SOLICITUD_CONFIRMACION', 'CACU_TIEMPO_DIAGNOSTICO_CIE10'].includes(m.name!))
return [m.name!, undefined] as const;
throw error;
}
}),
);
return new Map(found);
@@ -141,6 +153,64 @@ export class TabIndicadores {
}),
);
});
protected readonly routeRows = computed(() => {
const view = this.routeView();
return this.layout().route.map((s) => {
const m = this.byName().get(view === 'sample' ? s.fromSample : s.fromStep);
return { label: view === 'sample' ? s.label : s.step, reading: m && this.r(m) };
});
});
protected readonly routeMax = computed(() => Math.max(0, ...this.routeRows().map(({reading}) =>
Math.max(reading?.score ?? 0, reading?.high ?? 0))));
/** Illustrative cascade of the published step medians; missing steps do not advance the offset. */
protected readonly stepRoute = computed<Figure>(() => {
const rows = this.routeRows().filter(row => row.reading?.score !== undefined);
let offset = 0;
const bars = rows.map((row, index) => {
const score = row.reading!.score!;
const base = offset;
offset += score;
return { label: row.label, count: row.reading!.populations['measure-observation'] ?? 0, score, base,
color: index === 0 ? '#C9CDD2' : '#A8C243' };
});
const max = Math.max(1, offset);
return {
data: [{ type: 'bar', orientation: 'h', y: bars.map(row => `${row.label}<br>n = ${row.count}`),
x: bars.map(row => row.score), base: bars.map(row => row.base),
marker: { color: bars.map(row => row.color) }, text: bars.map(row => `+${row.score} d`),
textposition: 'inside', insidetextanchor: 'start', textfont: { color: '#081839' },
cliponaxis: false, hovertemplate: '%{y}<br>Mediana del tramo: %{x} días<extra></extra>' }],
layout: { autosize: true, showlegend: false, bargap: 0.48,
height: Math.max(210, bars.length * 76 + 94), margin: { t: 12, l: 8, r: 28, b: 52 },
xaxis: { title: { text: 'Días' }, range: [0, max * 1.12], nticks: 5, fixedrange: true, zeroline: false },
yaxis: { autorange: 'reversed', type: 'category', automargin: true, fixedrange: true } },
};
});
protected readonly stepRouteHeight = computed(() => Math.max(210,
this.routeRows().filter(row => row.reading?.score !== undefined).length * 76 + 94));
protected readonly icd = computed(() => this.reports.value()?.get('CACU_TIEMPO_DIAGNOSTICO_CIE10'));
protected readonly icdRows = computed(() => {
const r = this.icd();
return Object.entries(r?.stratumScores?.['diagnosis_code'] ?? {}).map(([label, score]) => ({
label: label.replace('sin_codigo', 'Sin código disponible').replace('ambiguo', 'Diagnóstico ambiguo'),
count: r?.strata['diagnosis_code']?.[label]?.['measure-observation'] ?? 0, ...score,
}));
});
protected readonly icdMax = computed(() => Math.max(0, ...this.icdRows().map(r => Math.max(r.median, r.high ?? 0))));
protected readonly requestsMeasure = computed(() => this.byName().has('CACU_BIOPSIA_SOLICITUD_CONFIRMACION'));
protected readonly requests = computed(() => this.reports.value()?.get('CACU_BIOPSIA_SOLICITUD_CONFIRMACION'));
protected readonly validRequests = computed(() => {
const r = this.requests();
const total = r?.populations['initial-population'];
const cells = r?.strata['category'];
if (!r || r.error || total === undefined || !cells) return false;
const counts = Object.values(cells).map((cell) => cell['initial-population']);
return Number.isInteger(total) && total >= 0 && counts.every((n) => Number.isInteger(n) && n >= 0)
&& counts.reduce((sum, n) => sum + n, 0) === total;
});
protected category(r: Reading, key: string): number {
return r.strata['category']?.[key]?.['initial-population'] ?? 0;
}
/** Each clinical card's figures, built once per loaded period. */
protected readonly figureSets = computed(
@@ -150,6 +220,15 @@ export class TabIndicadores {
),
);
protected readonly cytology = computed(() =>
cytologyDistribution(this.reports.value()?.get('CACU_EU7')),
);
protected readonly hasCytologyMeasure = computed(() => this.byName().has('CACU_EU7'));
protected readonly hpv = computed(() => hpvDistribution(this.reports.value()?.get('CACU_VPH_GENOTIPO')));
protected readonly biopsy = computed(() => biopsyDistribution(this.reports.value()?.get('CACU_BIOPSIA_RESULTADOS')));
protected readonly hasHpvMeasure = computed(() => this.byName().has('CACU_VPH_GENOTIPO'));
protected readonly hasBiopsyMeasure = computed(() => this.byName().has('CACU_BIOPSIA_RESULTADOS'));
/** A clinical card's figures: the overall split, then one per stratum. */
private build(m: Measure, r: Reading | undefined): { title: string; figure: Figure }[] {
if (!r || !(r.populations['initial-population'] ?? 0)) return [];
@@ -160,7 +239,9 @@ export class TabIndicadores {
if (kind === 'continuous-variable')
return [{ title: 'Mediana y cuartiles', figure: medians([{ label: m.title!, r }]) }];
return [
{ title: kind === 'proportion' ? 'Numerador y resto' : 'Por categoría', figure: donut(m, r) },
...(this.domain() === 'cacu' && m.name === 'CACU_EU7' && this.cytology()
? []
: [{ title: kind === 'proportion' ? 'Numerador y resto' : 'Por categoría', figure: donut(m, r) }]),
...strata.map((s) => ({
title: `Por ${STRATA[s]?.toLowerCase() ?? s}`,
figure: strataBars(m, r, s),
@@ -168,4 +249,8 @@ export class TabIndicadores {
];
}
protected readonly name = name;
protected readonly measureTitle = measureTitle;
protected ppvNote(m: Measure): string | undefined {
return PPV_NOTES[m.name ?? '']?.note;
}
}