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
+4
View File
@@ -566,6 +566,10 @@
<app-loading what="las curvas de supervivencia" [figure]="true" />
} @else if (domain() === 'cacu') {
<p class="muted">No disponible: el informe no contiene la curva para esta combinación.</p>
<details>
<summary>Métodos</summary>
<p class="muted">No hay un método publicado para esta combinación.</p>
</details>
} @else if (survival.value(); as s) {
<h3>Escenario clínico de la paciente</h3>
<ul class="scenarios">
+12
View File
@@ -79,6 +79,17 @@ function methods(figures: { figure: { data: unknown[] } }[]): string[] {
return [...new Set(names.filter((n): n is string => !!n))];
}
function modelInputs(value: string | undefined): Record<string, unknown> | undefined {
if (!value) return undefined;
try {
const parsed: unknown = JSON.parse(value);
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
? parsed as Record<string, unknown> : undefined;
} catch {
return undefined;
}
}
@Component({
selector: 'app-paciente',
imports: [
@@ -348,6 +359,7 @@ export class Paciente {
version: Number(/v(\d+)$/.exec(r.method?.text ?? '')?.[1] ?? 0),
index: r.occurrenceDateTime ?? '',
measure: ext(r, 'prediction-measure')?.valueCode,
inputs: modelInputs(ext(r, 'model-inputs')?.valueString),
// the clinical scenarios of the model's report she falls in
scenarios: (r.extension ?? [])
.filter((e) => e.url === EXT + 'escenario-clinico')
+7
View File
@@ -94,4 +94,11 @@ describe('survival scales', () => {
expect(g.scales[0].risk?.low).toBeCloseTo(0.7);
expect(g.scales[0].risk?.high).toBeCloseTo(0.9);
});
it('keeps the inputs attached to the estimate and leaves old estimates without them', () => {
const inputs = { age_group: '45-54', cytology: 'HSIL+', hpv: 'positive' };
expect(survivalGroups([{ index: '2026-01-01', predictions: [at(1, 0.2)], inputs }])[0].inputs)
.toEqual(inputs);
expect(riskGroups([{ text: 'Riesgo', index: '2026-01-01', predictions: [at(5, 0.2)] }])[0].inputs)
.toBeUndefined();
});
});
+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);
};
}