Mostrar escalas de supervivencia publicadas

This commit is contained in:
2026-12-02 23:00:06 -06:00
parent a22ce12067
commit 5f92c49ed4
4 changed files with 43 additions and 6 deletions
+1 -1
View File
@@ -301,7 +301,7 @@
} }
</details> </details>
} }
@if (!riskModels().length && !riskExclusion()) { @if (!riskModels().length && !groups()[0]?.survival && !riskExclusion()) {
<p class="muted">Sin evaluación de un modelo en producción.</p> <p class="muted">Sin evaluación de un modelo en producción.</p>
} }
</mat-card-content> </mat-card-content>
+10 -3
View File
@@ -32,7 +32,7 @@ import { eligibilityFailure, eligibilityView, type EligibilityState } from './el
import { ineligibility } from './ineligibility'; import { ineligibility } from './ineligibility';
import { parseSeries, RiskSeries, Series } from './risk-series'; import { parseSeries, RiskSeries, Series } from './risk-series';
import { curveFigure } from './risk-curve'; import { curveFigure } from './risk-curve';
import { isRiskModel, riskGroups, riskScales, RiskScales } from './risk-scales'; import { riskGroups, riskScales, RiskScales, survivalGroups } from './risk-scales';
import { route, Stages } from './stages'; import { route, Stages } from './stages';
import { ageAt, ageGroup, CAMA_AGE_GROUPS, camaRows, CURP } from '../indicadores/follow-up'; import { ageAt, ageGroup, CAMA_AGE_GROUPS, camaRows, CURP } from '../indicadores/follow-up';
import { LABELS, name, PRIORITY } from '../indicadores/measures'; import { LABELS, name, PRIORITY } from '../indicadores/measures';
@@ -183,13 +183,19 @@ export class Paciente {
return this.domain() === 'cacu' ? route(shown, this.cutoff()) : undefined; return this.domain() === 'cacu' ? route(shown, this.cutoff()) : undefined;
}); });
/** The models whose estimate is a risk (scales, curves, PDF): not survival or recurrence. */ /** The models whose estimate is a risk (scales, curves, PDF): not survival or recurrence. */
protected readonly riskModels = computed(() => this.models().filter((m) => isRiskModel(m.model))); protected readonly riskModels = computed(() => this.models().filter((m) => m.measure === 'risk'));
protected readonly scales = computed(() => protected readonly scales = computed(() =>
this.domain() === 'cacu' ? riskScales(this.riskModels()) : [], this.domain() === 'cacu' ? riskScales(this.riskModels()) : [],
); );
/** CaCu: both horizons of every model, or both unavailable (the PDF keeps `scales`). */ /** CaCu: both horizons of every model, or both unavailable (the PDF keeps `scales`). */
protected readonly groups = computed(() => protected readonly groups = computed(() =>
this.domain() === 'cacu' ? riskGroups(this.riskModels()) : [], this.domain() === 'cacu'
? (() => {
const survival = survivalGroups(this.models().filter((m) => m.measure === 'mortality'));
return this.riskModels().length ? [...riskGroups(this.riskModels()), ...survival]
: survival.length ? survival : riskGroups([]);
})()
: [],
); );
/** CaCu, experimental: the series her record can compare; none while the API has it off. */ /** CaCu, experimental: the series her record can compare; none while the API has it off. */
protected readonly riskSeries = resource({ protected readonly riskSeries = resource({
@@ -341,6 +347,7 @@ export class Paciente {
text: r.method?.text ?? '', text: r.method?.text ?? '',
version: Number(/v(\d+)$/.exec(r.method?.text ?? '')?.[1] ?? 0), version: Number(/v(\d+)$/.exec(r.method?.text ?? '')?.[1] ?? 0),
index: r.occurrenceDateTime ?? '', index: r.occurrenceDateTime ?? '',
measure: ext(r, 'prediction-measure')?.valueCode,
// the clinical scenarios of the model's report she falls in // the clinical scenarios of the model's report she falls in
scenarios: (r.extension ?? []) scenarios: (r.extension ?? [])
.filter((e) => e.url === EXT + 'escenario-clinico') .filter((e) => e.url === EXT + 'escenario-clinico')
+12 -1
View File
@@ -1,4 +1,4 @@
import { horizon, isRiskModel, riskGroups, riskScales } from './risk-scales'; import { horizon, isRiskModel, riskGroups, riskScales, survivalGroups } from './risk-scales';
const at = (years: number, p: number, low?: number, high?: number) => ({ years, p, low, high }); const at = (years: number, p: number, low?: number, high?: number) => ({ years, p, low, high });
@@ -84,3 +84,14 @@ describe('which models feed the risk scales', () => {
]); ]);
}); });
}); });
describe('survival scales', () => {
it('complements mortality and reverses interval bounds at every published horizon', () => {
const [g] = survivalGroups([{ index: '2026-01-01', predictions: [at(1, 0.2, 0.1, 0.3)] }]);
expect(g.survival).toBe(true);
expect(g.index).toBe('2026-01-01');
expect(g.scales[0].risk?.p).toBeCloseTo(0.8);
expect(g.scales[0].risk?.low).toBeCloseTo(0.7);
expect(g.scales[0].risk?.high).toBeCloseTo(0.9);
});
});
+20 -1
View File
@@ -48,9 +48,24 @@ export interface RiskGroup {
title?: string; title?: string;
scenario?: string; scenario?: string;
index?: string; index?: string;
survival?: boolean;
scales: { label: string; risk?: Prediction }[]; scales: { label: string; risk?: Prediction }[];
} }
/** Stored survival-model probabilities are mortality: complement them to obtain S(t). */
export function survivalGroups(models: { index: string; predictions: Prediction[] }[]): RiskGroup[] {
return models.map((m) => ({
title: 'Supervivencia', index: m.index, survival: true,
scales: m.predictions.flatMap((p) => {
const v = horizon(m.predictions, p.years);
return v ? [{ label: `Supervivencia a ${p.years} ${p.years === 1 ? 'año' : 'años'}`,
risk: { years: p.years, p: 1 - v.p,
low: v.high === undefined ? undefined : 1 - v.high,
high: v.low === undefined ? undefined : 1 - v.low } }] : [];
}),
})).filter((g) => g.scales.length);
}
const HORIZONS: [number, string][] = [ const HORIZONS: [number, string][] = [
[0, 'Riesgo inmediato (al índice)'], [0, 'Riesgo inmediato (al índice)'],
[5, 'Riesgo a 5 años'], [5, 'Riesgo a 5 años'],
@@ -105,7 +120,7 @@ export function riskGroups(
· No disponible · No disponible
} }
</p> </p>
<div class="risk-plot" [class.unavailable]="!s.risk"> <div class="risk-plot" [class.unavailable]="!s.risk" [class.survival]="g.survival">
<div class="risk-line" aria-hidden="true"></div> <div class="risk-line" aria-hidden="true"></div>
@if (s.risk; as r) { @if (s.risk; as r) {
@if (r.low !== undefined && r.high !== undefined) { @if (r.low !== undefined && r.high !== undefined) {
@@ -170,6 +185,10 @@ export function riskGroups(
#fff 25% #fff 25%
); );
} }
.survival .risk-line {
background: linear-gradient(to right, #c24269 0 25%, #df8640 25% 50%,
#a8c243 50% 75%, #42a77e 75% 100%);
}
.risk-interval { .risk-interval {
border-left: 2px solid #17324d; border-left: 2px solid #17324d;
border-right: 2px solid #17324d; border-right: 2px solid #17324d;