Patient risk: survival is 1 at 0 years, at the index date

This commit is contained in:
2026-11-22 18:40:34 -06:00
parent 8bca0fbcdf
commit 61867ff973
2 changed files with 14 additions and 7 deletions
@@ -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');
});
@@ -139,14 +139,19 @@ function simulated(resource: Record<string, unknown>): 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. */