e74e3d8fd4
The risk table takes a domain (CaCu by default); the CaMa record shows the mortality at 6, 12 and 18 months from the model's index date. The Supervivencia tab draws the cohort's Kaplan-Meier with its band, the adjusted curve, the fractional Weibull and the model's survival with its bootstrap interval; its wording comes from the model's settings.
29 lines
1.7 KiB
TypeScript
29 lines
1.7 KiB
TypeScript
import { Injectable, computed, inject, signal } from '@angular/core';
|
|
import { toObservable, toSignal } from '@angular/core/rxjs-interop';
|
|
import { catchError, defer, map, of, startWith, switchMap } from 'rxjs';
|
|
import { DominioRiesgo, PacienteRiesgoEstado } from './paciente-riesgo.models';
|
|
import { PACIENTE_RIESGO_PROVIDER } from './paciente-riesgo.provider';
|
|
import { riesgoPacienteResponse } from './paciente-riesgo.validation';
|
|
|
|
const CARGANDO: PacienteRiesgoEstado = { tipo: 'cargando' };
|
|
|
|
@Injectable()
|
|
export class PacienteRiesgoState {
|
|
private readonly provider = inject(PACIENTE_RIESGO_PROVIDER);
|
|
// `undefined` until the input is set; `null` is a patient without `pac_id`.
|
|
readonly pacId = signal<string | null | undefined>(undefined);
|
|
readonly dominio = signal<DominioRiesgo>('cacu');
|
|
// The patient and her domain are one query, so changing both never asks for the patient in the wrong domain.
|
|
private readonly consulta = computed(() => ({ id: this.pacId(), dominio: this.dominio() }));
|
|
readonly estado = toSignal(toObservable(this.consulta).pipe(
|
|
switchMap(({ id, dominio }) => id === undefined ? of(CARGANDO) : id === null ? of<PacienteRiesgoEstado>({ tipo: 'no-disponible' }) : defer(() => dominio === 'cacu' ? this.provider.obtener(id) : this.provider.obtener(id, dominio)).pipe(
|
|
map((respuesta): PacienteRiesgoEstado => {
|
|
const datos = respuesta === null ? null : riesgoPacienteResponse(respuesta, id);
|
|
return datos === null ? { tipo: 'no-disponible' } : { tipo: 'disponible', datos };
|
|
}),
|
|
catchError(() => of<PacienteRiesgoEstado>({ tipo: 'error' })),
|
|
startWith(CARGANDO),
|
|
)),
|
|
), { initialValue: CARGANDO });
|
|
}
|