From 61867ff973839986ceace2c6a3f9d271feef832c Mon Sep 17 00:00:00 2001 From: edgar Date: Sun, 22 Nov 2026 18:40:34 -0600 Subject: [PATCH] Patient risk: survival is 1 at 0 years, at the index date --- .../paciente-riesgo-estimando.spec.ts | 12 +++++++----- .../paciente-detalle/paciente-riesgo.validation.ts | 9 +++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/app/features/indicadores/paciente-detalle/paciente-riesgo-estimando.spec.ts b/src/app/features/indicadores/paciente-detalle/paciente-riesgo-estimando.spec.ts index a0d0257..06052bc 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-riesgo-estimando.spec.ts +++ b/src/app/features/indicadores/paciente-detalle/paciente-riesgo-estimando.spec.ts @@ -135,16 +135,18 @@ describe('Riesgo individual: qué se estima y su curva', () => { .toHaveLength(1); }); - it('una supervivencia se muestra como 1 − la probabilidad de morir, con el IC invertido', () => { + it('una supervivencia se muestra como 1 − la probabilidad de morir, con el IC invertido, y es 1 a los 0 años', () => { const data = riesgoCacuConEstimando(); const r = data.entry[0].resource; r.extension[0].extension.push({ url: 'complement', valueString: 'supervivencia' }); r.prediction.forEach((p: any) => { p.outcome.coding[0].code = 'muerte'; }); const lote = riesgoPacienteResponse(data, '42')!.riesgo; - expect(lote.horizontes[0]).toMatchObject({ horizonte_anios: 1 }); - expect(lote.horizontes[0].probabilidad).toBeCloseTo(0.92); - expect(lote.horizontes[0].ic_bajo).toBeCloseTo(0.88); - expect(lote.horizontes[0].ic_alto).toBeCloseTo(0.95); + // at the index date every patient is alive + expect(lote.horizontes[0]).toEqual({ horizonte_anios: 0, probabilidad: 1, ic_bajo: 1, ic_alto: 1 }); + expect(lote.horizontes[1]).toMatchObject({ horizonte_anios: 1 }); + expect(lote.horizontes[1].probabilidad).toBeCloseTo(0.92); + expect(lote.horizontes[1].ic_bajo).toBeCloseTo(0.88); + expect(lote.horizontes[1].ic_alto).toBeCloseTo(0.95); expect(encabezado(lote)).toBe('Probabilidad de supervivencia'); }); diff --git a/src/app/features/indicadores/paciente-detalle/paciente-riesgo.validation.ts b/src/app/features/indicadores/paciente-detalle/paciente-riesgo.validation.ts index 46e826d..e3b246f 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-riesgo.validation.ts +++ b/src/app/features/indicadores/paciente-detalle/paciente-riesgo.validation.ts @@ -139,14 +139,19 @@ function simulated(resource: Record): boolean { } /** A model whose estimand asks for its complement (survival from a probability of dying): each horizon becomes - * 1 − p, and its interval 1 − high to 1 − low. */ + * 1 − p, and its interval 1 − high to 1 − low; survival at 0 years is 1. */ function complemento(lote: LoteRiesgoCacu): void { if (lote.estimando?.complement !== 'supervivencia') return; - lote.horizontes = lote.horizontes.map(h => ({ + const horizontes = lote.horizontes.map(h => ({ ...h, probabilidad: 1 - h.probabilidad, ic_bajo: h.ic_alto == null ? h.ic_alto ?? null : 1 - h.ic_alto, ic_alto: h.ic_bajo == null ? h.ic_bajo ?? null : 1 - h.ic_bajo, })); + // At its index date every patient is alive: survival at 0 years is 1, whether or not the model gives it. + if (horizontes.length && !horizontes.some(h => h.horizonte_anios === 0)) { + horizontes.unshift({ horizonte_anios: 0, probabilidad: 1, ic_bajo: 1, ic_alto: 1 }); + } + lote.horizontes = horizontes; } /** Where an outcome goes among the patient's risks: CIN2+ first, then cancer, then any other. */