00f773dd75
The record asks GET /cacu/fhir/RiskAssessment?subject=Patient/<pac_id> and validates the searchset Bundle at the boundary (simulado tag, the patient asked for, one index date, probabilities and intervals); it shows the model, the risk's index date, the outcome, the evaluation and one row per horizon from each prediction's whenPeriod. The cohort's definition and the PIMM variables are no longer shown; an empty Bundle is a patient without a confirmed risk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
26 lines
1.3 KiB
TypeScript
26 lines
1.3 KiB
TypeScript
import { Injectable, inject, signal } from '@angular/core';
|
|
import { toObservable, toSignal } from '@angular/core/rxjs-interop';
|
|
import { catchError, defer, map, of, startWith, switchMap } from 'rxjs';
|
|
import { 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 estado = toSignal(toObservable(this.pacId).pipe(
|
|
switchMap(id => id === undefined ? of(CARGANDO) : id === null ? of<PacienteRiesgoEstado>({ tipo: 'no-disponible' }) : defer(() => this.provider.obtener(id)).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 });
|
|
}
|