+ Probabilidad de recurrencia
+ @let r = respuesta();
+ @if (r === undefined) { Buscando los escenarios clínicos de recurrencia de la paciente…
}
+ @if (r === null) { Todavía no hay un modelo de recurrencia en producción.
}
+ @if (r) {
+ @if (r.escenarios.length === 0) { La paciente no cumple ninguno de los escenarios clínicos del análisis de recurrencia.
}
+ @for (f of r.escenarios; track f.cohorte + f.escenario) { }
+ }
+
diff --git a/src/app/features/indicadores/paciente-detalle/cama/cama-recurrencia-paciente.component.spec.ts b/src/app/features/indicadores/paciente-detalle/cama/cama-recurrencia-paciente.component.spec.ts
new file mode 100644
index 0000000..f0eda6e
--- /dev/null
+++ b/src/app/features/indicadores/paciente-detalle/cama/cama-recurrencia-paciente.component.spec.ts
@@ -0,0 +1,122 @@
+// Covers CaMa's recurrence figures in a patient's record: the boundary validation of `GET /cama/modelo/recurrencia` (a malformed
+// answer never draws a partial curve), the figure of a scenario in the pipeline's style (the Greenwood band, the Kaplan-Meier steps,
+// the solid and dotted Weibull, the diamonds with their interval, "Libre de recaída S(t)"), and the component's states. Fixtures: a
+// figure like the recurrence version publishes, and a stub of `CamaRecurrenciaService`.
+import { TestBed } from '@angular/core/testing';
+import { of } from 'rxjs';
+import { vi } from 'vitest';
+import { PLOTLY_LOADER } from '../../../../shared/plotly/plotly-runtime';
+import { CamaRecurrenciaPaciente } from './cama-recurrencia-paciente.component';
+import { CamaRecurrenciaService, respuestaRecurrencia } from './cama-recurrencia.service';
+import { COLORES_RECURRENCIA, ETIQUETAS_RECURRENCIA, figuraRecurrencia } from './cama-recurrencia-figura';
+
+const meses = Array.from({ length: 61 }, (_, i) => i);
+const decreciente = (fin: number) => meses.map(m => 1 - (1 - fin) * (m / 60));
+const grilla = Array.from({ length: 289 }, (_, i) => i * 0.25);
+function figura(escenario = 'RE− · grado 3', cohorte = 'metabric'): any {
+ return {
+ cohorte, cohorte_nombre: cohorte === 'scanb' ? 'SCAN-B' : 'METABRIC', escenario, condiciones: { Grado_histologico: ['3'] }, n: 300, recaidas: 180,
+ horizons_months: [12, 36, 60], observado_hasta: 60, months_max: 72,
+ km: { months: meses, S: decreciente(0.5), low: decreciente(0.45), high: decreciente(0.55) },
+ weibull: { t: grilla, S: grilla.map(t => Math.exp(-t / 90)) }, weibull_fractional: { t: grilla, S: grilla.map(t => Math.exp(-t / 85)) },
+ points: { COMB: { S: [0.9, 0.7, 0.55], low: [0.88, 0.67, 0.5], high: [0.92, 0.73, 0.6] } }, bootstrap_replicas: 200,
+ };
+}
+const respuesta = (escenarios = [figura()]): any => ({ modelo: { nombre: 'cama-recurrence', version: '1' }, horizontes: [12, 36, 60], escenarios });
+
+describe('Recurrencia CaMa: respuesta', () => {
+ // Fails if a record with an impossible value is accepted and drawn.
+ it('accepts an answer as published', () => {
+ expect(respuestaRecurrencia(respuesta()).escenarios[0].escenario).toBe('RE− · grado 3');
+ });
+
+ it.each([
+ ['a probability above 1', (d: any) => { d.escenarios[0].km.S[3] = 1.2; }],
+ ['an inverted interval', (d: any) => { d.escenarios[0].points.COMB.low[0] = 0.99; }],
+ ['a series with another number of horizons', (d: any) => { d.escenarios[0].points.COMB.S.pop(); }],
+ ['a missing curve', (d: any) => { delete d.escenarios[0].weibull_fractional; }],
+ ['no model version', (d: any) => { delete d.modelo.version; }],
+ ])('rejects %s', (_, estropear) => {
+ const d = respuesta();
+ estropear(d);
+ expect(() => respuestaRecurrencia(d)).toThrow('Respuesta de recurrencia inválida');
+ });
+});
+
+describe('Recurrencia CaMa: figura', () => {
+ const f = () => figuraRecurrencia(respuestaRecurrencia(respuesta()).escenarios[0]);
+ const traza = (nombre: string) => f().data.find((t: any) => t.name === nombre) as any;
+
+ // Fails if the figure loses a piece of the pipeline's chart.
+ it('has the Kaplan-Meier with its band, both Weibull and the diamonds with their interval', () => {
+ expect(f().data.some((t: any) => t.fill === 'tonexty')).toBe(true);
+ expect(traza(ETIQUETAS_RECURRENCIA.km).line).toMatchObject({ color: COLORES_RECURRENCIA.km, shape: 'hv' });
+ expect(traza(ETIQUETAS_RECURRENCIA.weibull).line.color).toBe(COLORES_RECURRENCIA.weibull);
+ expect(traza(ETIQUETAS_RECURRENCIA.weibull_fraccional).line).toMatchObject({ color: COLORES_RECURRENCIA.fraccional, dash: 'dash' });
+ const rombos = traza(ETIQUETAS_RECURRENCIA.puntos);
+ expect(rombos.x).toEqual([12, 36, 60]);
+ expect(rombos.error_y.array.map((v: number) => +v.toFixed(2))).toEqual([0.02, 0.03, 0.05]);
+ });
+
+ // Fails if the Weibull stops being dotted past the follow-up the cohort has, which would present an extrapolation as observed.
+ it('draws the Weibull dotted past the follow-up', () => {
+ const punteadas = f().data.filter((t: any) => t.line?.dash === 'dot') as any[];
+
+ expect(punteadas).toHaveLength(2);
+ expect(punteadas.every(t => Math.min(...t.x) >= 60)).toBe(true);
+ });
+
+ // Fails if the labels or the title leave the pipeline's: recurrence-free S(t), the scenario, the cohort, n and recurrences.
+ it('is titled with the scenario, the cohort, its patients and recurrences', () => {
+ const l = f().layout as any;
+
+ expect(l.title.text).toBe('RE− · grado 3