50 lines
2.7 KiB
TypeScript
50 lines
2.7 KiB
TypeScript
import { Component, computed, inject, input, signal } from '@angular/core';
|
|
import { toObservable, toSignal } from '@angular/core/rxjs-interop';
|
|
import { switchMap } from 'rxjs';
|
|
import { PlotlyChart } from '../../../../shared/plotly/plotly-chart';
|
|
import { CamaFactoresRiesgo } from './cama-factores-riesgo.component';
|
|
import { figuraRecurrencia } from './cama-recurrencia-figura';
|
|
import { CamaRecurrenciaService, FiguraRecurrencia } from './cama-recurrencia.service';
|
|
|
|
export const HORIZONTE_PREDETERMINADO = 60;
|
|
|
|
/**
|
|
* «Análisis de recurrencia» and its «Factores de riesgo» for one patient: the clinical scenarios her own age, tumor size, grade and
|
|
* receptors place her in, from either external cohort (METABRIC or SCAN-B, named with each scenario and never mixed in one figure).
|
|
* The scenario chosen decides the curve and the label at once; the label has a horizon (12, 36 or 60 months, 60 by default).
|
|
*/
|
|
@Component({
|
|
selector: 'app-cama-analisis-recurrencia',
|
|
imports: [PlotlyChart, CamaFactoresRiesgo],
|
|
templateUrl: './cama-analisis-recurrencia.component.html',
|
|
styleUrl: './cama-analisis.component.scss',
|
|
})
|
|
export class CamaAnalisisRecurrencia {
|
|
readonly pacId = input.required<string>();
|
|
private readonly service = inject(CamaRecurrenciaService);
|
|
/** The analysis; `undefined` while it loads, `null` when there is no recurrence model in production. */
|
|
readonly respuesta = toSignal(toObservable(this.pacId).pipe(switchMap(id => this.service.recurrencia(id))));
|
|
private readonly elegido = signal<string | null>(null);
|
|
readonly horizonte = signal<number>(HORIZONTE_PREDETERMINADO);
|
|
/** The figures of her scenarios, in the order the server ranked them. */
|
|
readonly escenarios = computed(() => {
|
|
const r = this.respuesta();
|
|
if (!r) return [];
|
|
return r.deLaPaciente.map(s => r.escenarios.find(f => f.cohorte === s.cohorte && f.escenario === s.escenario))
|
|
.filter((f): f is FiguraRecurrencia => !!f);
|
|
});
|
|
readonly escenario = computed(() => this.escenarios().find(f => clave(f) === this.elegido()) ?? this.escenarios()[0] ?? null);
|
|
readonly figura = computed(() => { const f = this.escenario(); return f ? figuraRecurrencia(f) : null; });
|
|
readonly horizontes = computed(() => this.respuesta()?.horizontes ?? []);
|
|
readonly factores = computed(() => {
|
|
const f = this.escenario();
|
|
return f ? this.respuesta()?.resumen.find(r => r.cohorte === f.cohorte && r.escenario === f.escenario && r.horizonte_meses === this.horizonte()) ?? null : null;
|
|
});
|
|
readonly clave = clave;
|
|
|
|
elegirEscenario(valor: string): void { this.elegido.set(valor); }
|
|
elegirHorizonte(meses: number): void { this.horizonte.set(meses); }
|
|
}
|
|
|
|
function clave(f: FiguraRecurrencia): string { return `${f.cohorte}|${f.escenario}`; }
|