Mostrar métodos y escenarios sin curva en la supervivencia de la ficha

This commit is contained in:
2026-12-02 18:13:33 -06:00
parent 09e5f4dd34
commit 1260e0ff2a
2 changed files with 40 additions and 14 deletions
+25 -9
View File
@@ -69,6 +69,12 @@ function facts(observations: Observation[]): Fact[] {
/** One patient: her history (conditions, procedures), her tests and results, and the
* champion models' risks with their curves. Everything read from the FHIR API. */
/** The names of the methods the figures draw, each once. */
function methods(figures: { figure: { data: unknown[] } }[]): string[] {
const names = figures.flatMap((f) => f.figure.data.map((t) => (t as { name?: string }).name));
return [...new Set(names.filter((n): n is string => !!n))];
}
@Component({
selector: 'app-paciente',
imports: [
@@ -347,6 +353,8 @@ export class Paciente {
return {
factors: mine(summary?.['filas'] ?? []) as ScenarioFactors[],
scenarios: m.scenarios,
unavailable: [] as string[],
methods: [] as string[],
figures: mine(r['escenarios'] ?? []).map((e) =>
scenarioFigure(
`${e.escenario} (n = ${e.n.toLocaleString('es-MX')}, recaídas = ${e.recaidas.toLocaleString('es-MX')})`,
@@ -357,17 +365,22 @@ export class Paciente {
),
};
}
const drawn = mine((report?.['escenarios'] ?? []) as any[]);
const figures = drawn.map((e) =>
scenarioFigure(
`${e.escenario} (n = ${e.n.toLocaleString('es-MX')}, fallecidos = ${e.fallecidos.toLocaleString('es-MX')})`,
e,
e.horizons_months,
'Supervivencia S(t)',
),
);
return {
factors: mine((report?.['factores_escenarios'] ?? []) as any[]) as ScenarioFactors[],
scenarios: m.scenarios,
figures: mine((report?.['escenarios'] ?? []) as any[]).map((e) =>
scenarioFigure(
`${e.escenario} (n = ${e.n.toLocaleString('es-MX')}, fallecidos = ${e.fallecidos.toLocaleString('es-MX')})`,
e,
e.horizons_months,
'Supervivencia S(t)',
),
),
figures,
// her scenarios the report draws no curve for
unavailable: m.scenarios.filter((s) => !drawn.some((e) => e.escenario === s)),
methods: methods(figures),
};
},
});
@@ -484,7 +497,10 @@ export class Paciente {
protected readonly curve = computed<Figure>(() => curveFigure(this.riskModels(), this.top()));
protected readonly curveText = computed(() => curveText(this.riskModels()));
private top(): number {
return Math.max(0, ...this.riskModels().flatMap((m) => m.predictions.map((p) => p.high ?? p.p)));
return Math.max(
0,
...this.riskModels().flatMap((m) => m.predictions.map((p) => p.high ?? p.p)),
);
}
protected readonly name = name;
protected readonly levelNames = LEVEL_NAMES;