From 5f92c49ed40cdbe24ac759e4d644d6c4a0d779a2 Mon Sep 17 00:00:00 2001 From: edgar Date: Wed, 2 Dec 2026 23:00:06 -0600 Subject: [PATCH] Mostrar escalas de supervivencia publicadas --- src/app/paciente/paciente.html | 2 +- src/app/paciente/paciente.ts | 13 ++++++++++--- src/app/paciente/risk-scales.spec.ts | 13 ++++++++++++- src/app/paciente/risk-scales.ts | 21 ++++++++++++++++++++- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/app/paciente/paciente.html b/src/app/paciente/paciente.html index 799bb61..8ed9910 100644 --- a/src/app/paciente/paciente.html +++ b/src/app/paciente/paciente.html @@ -301,7 +301,7 @@ } } - @if (!riskModels().length && !riskExclusion()) { + @if (!riskModels().length && !groups()[0]?.survival && !riskExclusion()) {

Sin evaluación de un modelo en producción.

} diff --git a/src/app/paciente/paciente.ts b/src/app/paciente/paciente.ts index 23fe2e5..3b79aca 100644 --- a/src/app/paciente/paciente.ts +++ b/src/app/paciente/paciente.ts @@ -32,7 +32,7 @@ import { eligibilityFailure, eligibilityView, type EligibilityState } from './el import { ineligibility } from './ineligibility'; import { parseSeries, RiskSeries, Series } from './risk-series'; 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 { ageAt, ageGroup, CAMA_AGE_GROUPS, camaRows, CURP } from '../indicadores/follow-up'; import { LABELS, name, PRIORITY } from '../indicadores/measures'; @@ -183,13 +183,19 @@ export class Paciente { return this.domain() === 'cacu' ? route(shown, this.cutoff()) : undefined; }); /** 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(() => this.domain() === 'cacu' ? riskScales(this.riskModels()) : [], ); /** CaCu: both horizons of every model, or both unavailable (the PDF keeps `scales`). */ 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. */ protected readonly riskSeries = resource({ @@ -341,6 +347,7 @@ export class Paciente { text: r.method?.text ?? '', version: Number(/v(\d+)$/.exec(r.method?.text ?? '')?.[1] ?? 0), index: r.occurrenceDateTime ?? '', + measure: ext(r, 'prediction-measure')?.valueCode, // the clinical scenarios of the model's report she falls in scenarios: (r.extension ?? []) .filter((e) => e.url === EXT + 'escenario-clinico') diff --git a/src/app/paciente/risk-scales.spec.ts b/src/app/paciente/risk-scales.spec.ts index 6c113f6..63503f0 100644 --- a/src/app/paciente/risk-scales.spec.ts +++ b/src/app/paciente/risk-scales.spec.ts @@ -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 }); @@ -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); + }); +}); diff --git a/src/app/paciente/risk-scales.ts b/src/app/paciente/risk-scales.ts index a2a91ed..7bea171 100644 --- a/src/app/paciente/risk-scales.ts +++ b/src/app/paciente/risk-scales.ts @@ -48,9 +48,24 @@ export interface RiskGroup { title?: string; scenario?: string; index?: string; + survival?: boolean; 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][] = [ [0, 'Riesgo inmediato (al índice)'], [5, 'Riesgo a 5 años'], @@ -105,7 +120,7 @@ export function riskGroups( · No disponible }

-
+
@if (s.risk; as r) { @if (r.low !== undefined && r.high !== undefined) { @@ -170,6 +185,10 @@ export function riskGroups( #fff 25% ); } + .survival .risk-line { + background: linear-gradient(to right, #c24269 0 25%, #df8640 25% 50%, + #a8c243 50% 75%, #42a77e 75% 100%); + } .risk-interval { border-left: 2px solid #17324d; border-right: 2px solid #17324d;