Mostrar factores usados en cada estimación

This commit is contained in:
2026-12-02 23:13:59 -06:00
parent 5f92c49ed4
commit a92515eb4d
4 changed files with 59 additions and 3 deletions
+36 -3
View File
@@ -49,13 +49,16 @@ export interface RiskGroup {
scenario?: string;
index?: string;
survival?: boolean;
inputs?: Record<string, unknown>;
scales: { label: string; risk?: Prediction }[];
}
/** Stored survival-model probabilities are mortality: complement them to obtain S(t). */
export function survivalGroups(models: { index: string; predictions: Prediction[] }[]): RiskGroup[] {
export function survivalGroups(models: { index: string; predictions: Prediction[];
scenarios?: string[]; inputs?: Record<string, unknown> }[]): RiskGroup[] {
return models.map((m) => ({
title: 'Supervivencia', index: m.index, survival: true,
title: 'Supervivencia', index: m.index, survival: true, inputs: m.inputs,
scenario: m.scenarios?.join(' · '),
scales: m.predictions.flatMap((p) => {
const v = horizon(m.predictions, p.years);
return v ? [{ label: `Supervivencia a ${p.years} ${p.years === 1 ? 'año' : 'años'}`,
@@ -80,7 +83,8 @@ export function titleParts(text: string): { title: string; scenario?: string } {
/** The scales the page draws: both horizons of every model, or, with no model, both horizons
* unavailable. */
export function riskGroups(
models: { text: string; index: string; predictions: Prediction[] }[],
models: { text: string; index: string; predictions: Prediction[];
inputs?: Record<string, unknown> }[],
): RiskGroup[] {
const scales = (predictions: Prediction[]) =>
HORIZONS.map(([years, label]) => ({ label, risk: horizon(predictions, years) }));
@@ -88,6 +92,7 @@ export function riskGroups(
? models.map((m) => ({
...titleParts(m.text),
index: m.index,
inputs: m.inputs,
scales: scales(m.predictions),
}))
: [{ scales: scales([]) }];
@@ -149,6 +154,20 @@ export function riskGroups(
{{ g.scenario ? 'Escenario: ' + g.scenario + ' · ' : '' }}Fecha índice {{ g.index }}
</p>
}
@if (g.title) {
<section>
<h4>Factores de riesgo considerados</h4>
@if (g.inputs) {
<dl>
@for (item of entries(g.inputs); track item[0]) {
<div><dt>{{ inputName(item[0]) }}</dt><dd>{{ inputValue(item[0], item[1]) }}</dd></div>
}
</dl>
} @else {
<p class="muted">Los valores utilizados no están disponibles para esta estimación.</p>
}
</section>
}
}
`,
styles: `
@@ -235,4 +254,18 @@ export function riskGroups(
})
export class RiskScales {
readonly groups = input.required<RiskGroup[]>();
protected readonly entries = Object.entries;
protected readonly inputName = (name: string) => ({
age_group: 'Edad al diagnóstico', cytology: 'Citología', hpv: 'VPH',
hpv_positive: 'VPH', hpv_16_18: 'VPH 16/18', referral_grade: 'Referencia',
bethesda: 'Citología', hpv_16: 'VPH 16', hpv_18: 'VPH 18',
} as Record<string, string>)[name] ?? name;
protected readonly inputValue = (name: string, value: unknown) => {
if (value === null || value === undefined) return 'No documentado';
if (name.startsWith('hpv') && (value === 0 || value === 1 || typeof value === 'boolean'))
return value ? 'Positivo' : 'Negativo';
if (name.startsWith('hpv') && value === 'positive') return 'Positivo';
if (name.startsWith('hpv') && value === 'negative') return 'Negativo';
return String(value);
};
}