Patient risk: probabilities in percent, survival as such, covariates, and one row per model
The table says its probabilities are percentages (0 to 100 %) with their 95 % interval, and its covariates under it. A model whose estimand asks for its complement (survival from a probability of dying) shows 1 − p with its interval swapped. "Riesgo acumulado" reads "probabilidad". The models' details are a table of one row per model, without the version or the batch state.
This commit is contained in:
@@ -84,7 +84,7 @@ describe('Riesgo individual de la paciente CaMa', () => {
|
||||
expect(text).toContain('17.8 %');
|
||||
expect(text).toContain('25.1 %');
|
||||
expect(text).not.toMatch(/Información simulada|Entorno DEV|Sin evaluación clínica/);
|
||||
expect([...(f.nativeElement as HTMLElement).querySelectorAll('tbody th')].map(th => th.textContent!.trim())).toEqual(['0.5', '1', '1.5']);
|
||||
expect([...(f.nativeElement as HTMLElement).querySelectorAll('table.risk tbody th')].map(th => th.textContent!.trim())).toEqual(['0.5', '1', '1.5']);
|
||||
});
|
||||
|
||||
// Fails if the CaMa record goes back to showing the individual risk table, which its two analyses replace.
|
||||
|
||||
@@ -5,7 +5,7 @@ import { of } from 'rxjs';
|
||||
import { PLOTLY_LOADER } from '../../../shared/plotly/plotly-runtime';
|
||||
import { PACIENTE_RIESGO_PROVIDER } from './paciente-riesgo.provider';
|
||||
import { riesgoCacuCancerSinEstimar, riesgoCacuConEstimando, riesgoCacuDosDesenlaces, riesgoCacuEjemplo, riesgoCacuVista } from './paciente-riesgo.testing';
|
||||
import { conIntervalo, encabezado, fraseRiesgo, porcentaje } from './paciente-riesgo.presentacion';
|
||||
import { conIntervalo, covariables, encabezado, fraseRiesgo, porcentaje } from './paciente-riesgo.presentacion';
|
||||
import { riesgoPacienteResponse } from './paciente-riesgo.validation';
|
||||
import { figuraRiesgoPaciente } from './paciente-riesgo-figura';
|
||||
import { PacienteRiesgoTabla } from './paciente-riesgo-tabla';
|
||||
@@ -27,8 +27,8 @@ describe('Riesgo individual: qué se estima y su curva', () => {
|
||||
|
||||
it('lee el estimando conocido e ignora claves que no conoce (también el método del intervalo, que es del reporte); sin extensión queda en null', () => {
|
||||
expect(riesgoPacienteResponse(riesgoCacuConEstimando(), '42')!.riesgo.estimando).toEqual({
|
||||
quantity: 'Riesgo acumulado', description: 'Probabilidad de CIN2+ antes de cada horizonte.',
|
||||
outcome: 'CIN2+: biopsia LIEAG, CIS o carcinoma', horizons_unit: 'años' });
|
||||
quantity: 'Probabilidad', description: 'Probabilidad de CIN2+ antes de cada horizonte.',
|
||||
outcome: 'CIN2+: biopsia LIEAG, CIS o carcinoma', horizons_unit: 'años', covariates: 'VPH y citología índice' });
|
||||
expect(riesgoPacienteResponse(riesgoCacuEjemplo(), '42')).toEqual(riesgoCacuVista());
|
||||
});
|
||||
|
||||
@@ -40,7 +40,7 @@ describe('Riesgo individual: qué se estima y su curva', () => {
|
||||
|
||||
it('nombra el número, su desenlace y la unidad de los horizontes en la ficha', () => {
|
||||
const { root } = setup(riesgoCacuConEstimando());
|
||||
expect([...root.querySelectorAll('thead th')].map(th => th.textContent!.trim()))
|
||||
expect([...root.querySelectorAll('table.risk thead th')].map(th => th.textContent!.trim()))
|
||||
.toEqual(['Horizonte (años)', 'Probabilidad a LIEAG+ (%)', 'Probabilidad a cáncer (%)']);
|
||||
expect(root.querySelector('details.risk-details summary')!.textContent).toContain('Detalle del modelo');
|
||||
for (const value of ['Qué se estima', 'CIN2+: biopsia LIEAG, CIS o carcinoma']) {
|
||||
@@ -52,7 +52,7 @@ describe('Riesgo individual: qué se estima y su curva', () => {
|
||||
it('dibuja la curva solo al abrir su sección', async () => {
|
||||
const { fixture, root } = setup(riesgoCacuConEstimando());
|
||||
const details = root.querySelector('details.risk-curve') as HTMLDetailsElement;
|
||||
expect(details.querySelector('summary')!.textContent).toContain('Curva de riesgo acumulado');
|
||||
expect(details.querySelector('summary')!.textContent).toContain('Curva de probabilidad');
|
||||
expect(root.querySelector('app-plotly-chart')).toBeNull();
|
||||
details.open = true;
|
||||
details.dispatchEvent(new Event('toggle'));
|
||||
@@ -66,7 +66,7 @@ describe('Riesgo individual: qué se estima y su curva', () => {
|
||||
expect(banda.data).toHaveLength(3);
|
||||
expect(banda.data[2]['y']).toEqual([8, 21, 34]);
|
||||
expect(banda.data[1]['y']).toEqual([5, 15, 26]);
|
||||
expect((banda.layout['yaxis'] as any).title.text).toBe('Riesgo acumulado (%)');
|
||||
expect((banda.layout['yaxis'] as any).title.text).toBe('Probabilidad (%)');
|
||||
|
||||
const parcial = { ...riesgo, horizontes: riesgo.horizontes.map((h, i) => i === 0 ? { ...h, ic_bajo: null, ic_alto: null } : h) };
|
||||
const barras = figuraRiesgoPaciente([parcial]);
|
||||
@@ -76,9 +76,9 @@ describe('Riesgo individual: qué se estima y su curva', () => {
|
||||
|
||||
it('pone una columna por desenlace, LIEAG+ primero, con el IC entre paréntesis', () => {
|
||||
const { root } = setup(riesgoCacuDosDesenlaces());
|
||||
expect([...root.querySelectorAll('thead th')].map(th => th.textContent!.trim()))
|
||||
expect([...root.querySelectorAll('table.risk thead th')].map(th => th.textContent!.trim()))
|
||||
.toEqual(['Horizonte (años)', 'Probabilidad a LIEAG+ (%)', 'Probabilidad a cáncer (%)']);
|
||||
const fila = [...root.querySelectorAll('tbody tr')][2];
|
||||
const fila = [...root.querySelectorAll('table.risk tbody tr')][2];
|
||||
expect([...fila.querySelectorAll('td')].map(td => td.textContent!.replace(/\s+/g, ' ').trim()))
|
||||
.toEqual(['34 % (26 – 44 %)', '1.5 % (0.8 – 2.8 %)']);
|
||||
});
|
||||
@@ -86,8 +86,8 @@ describe('Riesgo individual: qué se estima y su curva', () => {
|
||||
it('la frase dice los resultados índice y los dos riesgos al horizonte más largo, respectivamente', () => {
|
||||
const { riesgos } = riesgoPacienteResponse(riesgoCacuDosDesenlaces(), '42')!;
|
||||
expect(riesgos.map(r => r.desenlace)).toEqual(['cin2_mas', 'cancer']);
|
||||
expect(fraseRiesgo(riesgos)).toBe('Un resultado de VPH positivo y una citología LIEBG (2026-06-01) tienen un riesgo '
|
||||
+ 'acumulado a 5 años de estar presente o de aparecer LIEAG+ y cáncer de 34 % (26 – 44 %) y 1.5 % (0.8 – 2.8 %), '
|
||||
expect(fraseRiesgo(riesgos)).toBe('Un resultado de VPH positivo y una citología LIEBG (2026-06-01) tienen una probabilidad '
|
||||
+ 'a 5 años de estar presente o de aparecer LIEAG+ y cáncer de 34 % (26 – 44 %) y 1.5 % (0.8 – 2.8 %), '
|
||||
+ 'respectivamente.');
|
||||
expect(fraseRiesgo(riesgoPacienteResponse(riesgoCacuEjemplo(), '42')!.riesgos)).toBeNull();
|
||||
});
|
||||
@@ -113,19 +113,19 @@ describe('Riesgo individual: qué se estima y su curva', () => {
|
||||
const muerte = { ...riesgos[1], desenlace: 'muerte', fecha_indice: '2024-03-01' };
|
||||
expect(encabezado(muerte, riesgos[0].fecha_indice)).toBe('Probabilidad a muerte desde 2024-03-01');
|
||||
expect(fraseRiesgo([riesgos[0], muerte])).toBe('Un resultado de VPH positivo y una citología LIEBG (2026-06-01) '
|
||||
+ 'tienen un riesgo acumulado a 5 años de estar presente o de aparecer LIEAG+ de 34 % (26 – 44 %).');
|
||||
+ 'tienen una probabilidad a 5 años de estar presente o de aparecer LIEAG+ de 34 % (26 – 44 %).');
|
||||
});
|
||||
|
||||
it('sin modelo de un desenlace su columna dice No disponible', () => {
|
||||
const { root } = setup(riesgoCacuConEstimando());
|
||||
const celdas = [...root.querySelectorAll('tbody tr')].map(tr => tr.querySelectorAll('td')[1].textContent!.trim());
|
||||
const celdas = [...root.querySelectorAll('table.risk tbody tr')].map(tr => tr.querySelectorAll('td')[1].textContent!.trim());
|
||||
expect(celdas).toEqual(['No disponible', 'No disponible', 'No disponible']);
|
||||
});
|
||||
|
||||
it('con un modelo que no la estima su columna lo dice, con el motivo, y no entra en la curva ni en la frase', () => {
|
||||
const data = riesgoCacuCancerSinEstimar();
|
||||
const { root } = setup(data);
|
||||
const celdas = [...root.querySelectorAll('tbody tr')].map(tr => tr.querySelectorAll('td')[1].textContent!.trim());
|
||||
const celdas = [...root.querySelectorAll('table.risk tbody tr')].map(tr => tr.querySelectorAll('td')[1].textContent!.trim());
|
||||
expect(celdas).toEqual(['No estimada para su grupo', 'No estimada para su grupo', 'No estimada para su grupo']);
|
||||
expect(root.querySelector('.unavailable-note')!.textContent).toContain('queda fuera de su población');
|
||||
const { riesgos, riesgo } = riesgoPacienteResponse(data, '42')!;
|
||||
@@ -134,4 +134,28 @@ describe('Riesgo individual: qué se estima y su curva', () => {
|
||||
expect(figuraRiesgoPaciente(riesgos.filter(r => r.horizontes.length)).data.filter(t => t['mode'] === 'lines+markers'))
|
||||
.toHaveLength(1);
|
||||
});
|
||||
|
||||
it('una supervivencia se muestra como 1 − la probabilidad de morir, con el IC invertido', () => {
|
||||
const data = riesgoCacuConEstimando();
|
||||
const r = data.entry[0].resource;
|
||||
r.extension[0].extension.push({ url: 'complement', valueString: 'supervivencia' });
|
||||
r.prediction.forEach((p: any) => { p.outcome.coding[0].code = 'muerte'; });
|
||||
const lote = riesgoPacienteResponse(data, '42')!.riesgo;
|
||||
expect(lote.horizontes[0]).toMatchObject({ horizonte_anios: 1 });
|
||||
expect(lote.horizontes[0].probabilidad).toBeCloseTo(0.92);
|
||||
expect(lote.horizontes[0].ic_bajo).toBeCloseTo(0.88);
|
||||
expect(lote.horizontes[0].ic_alto).toBeCloseTo(0.95);
|
||||
expect(encabezado(lote)).toBe('Probabilidad de supervivencia');
|
||||
});
|
||||
|
||||
it('pone las covariables al pie de la tabla y el detalle en una fila por modelo, sin versión ni estado', () => {
|
||||
const { root } = setup(riesgoCacuDosDesenlaces());
|
||||
expect(root.querySelector('.covariates-note')!.textContent).toBe('Covariables: VPH y citología índice.');
|
||||
expect(root.querySelectorAll('table.models tbody tr')).toHaveLength(2);
|
||||
expect(root.textContent).not.toMatch(/Versión del modelo|Estado del lote/);
|
||||
expect(root.querySelector('caption')!.textContent).toContain('Probabilidad en porcentaje (0 a 100 %)');
|
||||
const { riesgos } = riesgoPacienteResponse(riesgoCacuDosDesenlaces(), '42')!;
|
||||
riesgos[1].estimando = { ...riesgos[1].estimando, covariates: 'otras' };
|
||||
expect(covariables(riesgos)).toBe('Covariables: Probabilidad a LIEAG+: VPH y citología índice; Probabilidad a cáncer: otras.');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
@let filas = filasDe(lotesDe(columnas));
|
||||
@if (filas.length) {
|
||||
<div class="risk-scroll" role="region" aria-label="Riesgos por horizonte, tabla desplazable" tabindex="0">
|
||||
<table>
|
||||
<caption>{{ riesgo.estimando?.quantity ?? 'Probabilidad' }} por horizonte desde la fecha índice
|
||||
({{ riesgo.fecha_indice }}), con su intervalo de confianza entre paréntesis</caption>
|
||||
<table class="risk">
|
||||
<caption>Probabilidad en porcentaje (0 a 100 %) por horizonte desde la fecha índice
|
||||
({{ riesgo.fecha_indice }}), con su intervalo de confianza de 95 % entre paréntesis</caption>
|
||||
<thead><tr>
|
||||
<th scope="col">Horizonte ({{ riesgo.estimando?.horizons_unit ?? 'años' }})</th>
|
||||
@for (c of columnas; track c.encabezado) { <th scope="col">{{ c.encabezado }} (%)</th> }
|
||||
@@ -36,25 +36,31 @@
|
||||
@for (c of columnas; track c.encabezado) {
|
||||
@if (c.lote?.sin_estimacion; as motivo) { <p class="unavailable-note">{{ c.encabezado }}: {{ motivo }}.</p> }
|
||||
}
|
||||
@if (covariables(riesgos); as texto) { <p class="covariates-note">{{ texto }}</p> }
|
||||
<details class="risk-details">
|
||||
<summary>Detalle del modelo</summary>
|
||||
@for (r of riesgos; track r.id) {
|
||||
@if (riesgos.length > 1) { <h6>{{ encabezado(r) }}</h6> }
|
||||
<dl class="metadata">
|
||||
<div><dt>Modelo</dt><dd>{{ r.modelo_nombre }}</dd></div>
|
||||
<div><dt>Versión del modelo</dt><dd>{{ r.modelo_version }}</dd></div>
|
||||
<div><dt>Fecha índice</dt><dd>{{ r.fecha_indice }}</dd></div>
|
||||
<div><dt>Desenlace</dt><dd>{{ r.desenlace_texto ?? r.desenlace }}</dd></div>
|
||||
<div><dt>Evaluado en</dt><dd><time [attr.datetime]="r.evaluado_en">{{ instante(r.evaluado_en) }}</time></dd></div>
|
||||
<div><dt>Estado del lote</dt><dd>{{ r.estado_lote === 'final' ? 'Final (final)' : 'Preliminar (preliminary)' }}</dd></div>
|
||||
@if (r.estimando; as e) {
|
||||
@if (e.quantity) { <div><dt>Qué se estima</dt><dd>{{ e.quantity }}@if (e.description) {: {{ e.description }}}</dd></div> }
|
||||
@if (e.outcome) { <div><dt>Desenlace del modelo</dt><dd>{{ e.outcome }}</dd></div> }
|
||||
@if (e.index_date) { <div><dt>Desde</dt><dd>{{ e.index_date }}</dd></div> }
|
||||
@if (e.horizons_unit) { <div><dt>Horizontes en</dt><dd>{{ e.horizons_unit }}</dd></div> }
|
||||
}
|
||||
</dl>
|
||||
}
|
||||
<div class="risk-scroll" role="region" aria-label="Modelos de la ficha, tabla desplazable" tabindex="0">
|
||||
<table class="models">
|
||||
<thead><tr>
|
||||
<th scope="col">Probabilidad</th><th scope="col">Modelo</th><th scope="col">Qué se estima</th>
|
||||
<th scope="col">Desenlace</th><th scope="col">Desde</th><th scope="col">Fecha índice</th>
|
||||
<th scope="col">Evaluado en</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
@for (r of riesgos; track r.id) {
|
||||
<tr>
|
||||
<th scope="row">{{ encabezado(r) }}</th>
|
||||
<td>{{ r.modelo_nombre }}</td>
|
||||
<td>{{ r.estimando?.description ?? '—' }}</td>
|
||||
<td>{{ r.estimando?.outcome ?? r.desenlace_texto ?? r.desenlace }}</td>
|
||||
<td>{{ r.estimando?.index_date ?? '—' }}</td>
|
||||
<td>{{ r.fecha_indice }}</td>
|
||||
<td><time [attr.datetime]="r.evaluado_en">{{ instante(r.evaluado_en) }}</time></td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</details>
|
||||
@if (filas.length > 1) {
|
||||
<details class="risk-curve" (toggle)="curvaAbierta.set($any($event.target).open)">
|
||||
@@ -62,7 +68,7 @@
|
||||
@if (frase(riesgos); as texto) { <p class="risk-sentence">{{ texto }}</p> }
|
||||
@if (curvaAbierta()) {
|
||||
<app-plotly-chart [style.--plot-height]="'300px'" [showNotes]="false" [figure]="figura(riesgos)"
|
||||
[label]="'Curvas de riesgo individual ' + rotulo() + ' por horizonte'" />
|
||||
[label]="'Curvas de probabilidad individual ' + rotulo() + ' por horizonte'" />
|
||||
}
|
||||
</details>
|
||||
}
|
||||
|
||||
@@ -24,3 +24,5 @@ tbody tr:last-child > * { border-bottom: 0; }
|
||||
.risk-details h6 { margin: .75rem 0 .25rem; font-size: .95rem; }
|
||||
.unavailable { color: var(--issste-text-secondary); }
|
||||
.unavailable-note { color: var(--issste-text-secondary); font-size: .85rem; margin: .5rem 0 0; }
|
||||
.covariates-note { color: var(--issste-text-secondary); font-size: .85rem; margin: .5rem 0 0; }
|
||||
table.models { min-width: 48rem; }
|
||||
|
||||
@@ -3,7 +3,7 @@ import { LowerCasePipe } from '@angular/common';
|
||||
import { PlotlyChart } from '../../../shared/plotly/plotly-chart';
|
||||
import { PlotlyFigure } from '../indicadores.models';
|
||||
import { figuraRiesgoPaciente } from './paciente-riesgo-figura';
|
||||
import { ColumnaRiesgo, columnasRiesgo, conRiesgo, encabezado, etiquetaDesenlace, filasRiesgo, fraseRiesgo, porcentaje } from './paciente-riesgo.presentacion';
|
||||
import { ColumnaRiesgo, columnasRiesgo, conRiesgo, covariables, encabezado, etiquetaDesenlace, filasRiesgo, fraseRiesgo, porcentaje } from './paciente-riesgo.presentacion';
|
||||
import { DominioRiesgo, LoteRiesgoCacu } from './paciente-riesgo.models';
|
||||
import { PacienteRiesgoState } from './paciente-riesgo.state';
|
||||
import { tieneIntervalo } from './paciente-riesgo.validation';
|
||||
@@ -39,6 +39,7 @@ export class PacienteRiesgoTabla {
|
||||
readonly frase = fraseRiesgo;
|
||||
readonly filasDe = filasRiesgo;
|
||||
readonly conRiesgo = conRiesgo;
|
||||
readonly covariables = covariables;
|
||||
columnasDe(riesgos: LoteRiesgoCacu[]): ColumnaRiesgo[] { return columnasRiesgo(riesgos, this.dominio()); }
|
||||
lotesDe(columnas: ColumnaRiesgo[]) { return columnas.map(c => (c.lote?.horizontes.length ? c.lote : null)); }
|
||||
private figuraDe?: { riesgos: LoteRiesgoCacu[]; figura: PlotlyFigure };
|
||||
|
||||
@@ -16,13 +16,17 @@ export interface HorizonteRiesgoCacu {
|
||||
|
||||
/** What the model's number is (the scenario's `[estimand]`, extension `estimando`); each field may be missing. */
|
||||
export interface EstimandoRiesgo {
|
||||
/** e.g. "Riesgo acumulado"; also `method.text`. */
|
||||
/** e.g. "Probabilidad"; also `method.text`. */
|
||||
quantity?: string;
|
||||
description?: string;
|
||||
outcome?: string;
|
||||
index_date?: string;
|
||||
/** The unit the horizons are counted in, e.g. "años". */
|
||||
horizons_unit?: string;
|
||||
/** The variables the model uses, in words, as the record writes them under the table. */
|
||||
covariates?: string;
|
||||
/** `supervivencia`: the model gives the probability of the outcome (dying) and the record shows its complement. */
|
||||
complement?: string;
|
||||
}
|
||||
|
||||
/** The results of the cytology sampled on the risk's index date (extension `resultados-indice`), as recorded. */
|
||||
|
||||
@@ -5,7 +5,7 @@ import { tieneIntervalo } from './paciente-riesgo.validation';
|
||||
export function etiquetaDesenlace(lote: LoteRiesgoCacu): string {
|
||||
if (lote.desenlace.startsWith('cin2')) return 'LIEAG+';
|
||||
if (lote.desenlace === 'cancer') return 'cáncer';
|
||||
if (lote.desenlace === 'muerte') return 'muerte';
|
||||
if (lote.desenlace === 'muerte') return lote.estimando?.complement === 'supervivencia' ? 'supervivencia' : 'muerte';
|
||||
return lote.desenlace_texto ?? lote.desenlace;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ export function etiquetaDesenlace(lote: LoteRiesgoCacu): string {
|
||||
* `fechaComun` (a survival model counts from the invasive biopsy, not from the cytology). */
|
||||
export function encabezado(lote: LoteRiesgoCacu, fechaComun: string | null = null): string {
|
||||
const desde = fechaComun && lote.fecha_indice !== fechaComun ? ` desde ${lote.fecha_indice}` : '';
|
||||
return `Probabilidad a ${etiquetaDesenlace(lote)}${desde}`;
|
||||
const etiqueta = etiquetaDesenlace(lote);
|
||||
return `${etiqueta === 'supervivencia' ? 'Probabilidad de supervivencia' : `Probabilidad a ${etiqueta}`}${desde}`;
|
||||
}
|
||||
|
||||
/** A probability as a percentage with the decimals a small risk needs, without trailing zeros: 0.178 -> "17.8",
|
||||
@@ -110,6 +111,15 @@ export function fraseRiesgo(todos: LoteRiesgoCacu[]): string | null {
|
||||
const desenlaces = junta(riesgos.map(etiquetaDesenlace));
|
||||
const valores = junta(ultima.celdas.map(c => conIntervalo(c!)));
|
||||
const anios = ultima.horizonte_anios === 1 ? '1 año' : `${ultima.horizonte_anios} años`;
|
||||
return `${inicio} (${fecha}) tienen un riesgo acumulado a ${anios} de estar presente o de aparecer ${desenlaces} `
|
||||
return `${inicio} (${fecha}) tienen una probabilidad a ${anios} de estar presente o de aparecer ${desenlaces} `
|
||||
+ `de ${valores}${riesgos.length > 1 ? ', respectivamente' : ''}.`;
|
||||
}
|
||||
|
||||
/** The covariates under the table: each model's, by its column, or once when every model uses the same ones. */
|
||||
export function covariables(riesgos: LoteRiesgoCacu[]): string | null {
|
||||
const con = riesgos.filter(r => r.estimando?.covariates);
|
||||
if (!con.length) return null;
|
||||
const textos = [...new Set(con.map(r => r.estimando!.covariates!))];
|
||||
if (textos.length === 1) return `Covariables: ${textos[0]}.`;
|
||||
return `Covariables: ${con.map(r => `${encabezado(r)}: ${r.estimando!.covariates}`).join('; ')}.`;
|
||||
}
|
||||
|
||||
@@ -45,13 +45,14 @@ describe('RIESGO-CACU-02: presentación y aislamiento', () => {
|
||||
const f = setup({ obtener }), root: HTMLElement = f.nativeElement;
|
||||
expect(obtener).toHaveBeenCalledExactlyOnceWith('42');
|
||||
// horizon, CIN2+ (LIEAG+) and cancer (without a model here: "No disponible"), each risk with its interval
|
||||
expect(root.querySelectorAll('thead th')).toHaveLength(3);
|
||||
expect([...root.querySelectorAll('thead th')].every(th => th.getAttribute('scope') === 'col')).toBe(true);
|
||||
expect(root.querySelectorAll('tbody th[scope="row"]')).toHaveLength(3);
|
||||
expect(root.querySelectorAll('table.risk thead th')).toHaveLength(3);
|
||||
expect([...root.querySelectorAll('table.risk thead th')].every(th => th.getAttribute('scope') === 'col')).toBe(true);
|
||||
expect(root.querySelectorAll('table.risk tbody th[scope="row"]')).toHaveLength(3);
|
||||
expect([...root.querySelectorAll('.percentage')].map(c => c.textContent!.trim())).toEqual(['8 %', '21 %', '34 %']);
|
||||
expect(root.querySelector('.interval')!.textContent).toContain('(5 – 12 %)');
|
||||
expect(root.textContent).toContain('Final (final)');
|
||||
for (const value of ['modelo-cacu', '2.1.0', '2026-10-01 00:00 UTC', '2026-06-01', 'CIN2+ por biopsia']) {
|
||||
// the record names the model, its index date and outcome, not its version nor the batch's state
|
||||
expect(root.textContent).not.toMatch(/Final \(final\)|2\.1\.0/);
|
||||
for (const value of ['modelo-cacu', '2026-10-01 00:00 UTC', '2026-06-01', 'CIN2+ por biopsia']) {
|
||||
expect(root.textContent).toContain(value);
|
||||
}
|
||||
// The record no longer shows the cohort's internals (its definition, version or model variables).
|
||||
@@ -73,7 +74,7 @@ describe('RIESGO-CACU-02: presentación y aislamiento', () => {
|
||||
expect(getComputedStyle(scroll).overflow).toBe('auto');
|
||||
expect(getComputedStyle(scroll).maxWidth).toBe('100%');
|
||||
expect(getComputedStyle(root.querySelector('table')!).minWidth).toBe('36rem');
|
||||
expect(getComputedStyle(root.querySelector('thead th')!).position).toBe('sticky');
|
||||
expect(getComputedStyle(root.querySelector('table.risk thead th')!).position).toBe('sticky');
|
||||
});
|
||||
|
||||
it('renderiza horizontes parciales/dinámicos y extremos cero y uno con IC opcionales', () => {
|
||||
@@ -85,10 +86,10 @@ describe('RIESGO-CACU-02: presentación y aislamiento', () => {
|
||||
prediccion(0.00123, '2026-06-01', '2038-09-01'),
|
||||
];
|
||||
const f = setup({ obtener: () => of(data) }), root: HTMLElement = f.nativeElement;
|
||||
expect([...root.querySelectorAll('tbody th')].map(c => c.textContent!.trim())).toEqual(['0.5', '8', '12.25']);
|
||||
expect([...root.querySelectorAll('table.risk tbody th')].map(c => c.textContent!.trim())).toEqual(['0.5', '8', '12.25']);
|
||||
expect([...root.querySelectorAll('.percentage')].map(c => c.textContent!.trim())).toEqual(['0 %', '100 %', '0.123 %']);
|
||||
expect([...root.querySelectorAll('.interval')].map(c => c.textContent!.trim())).toEqual(['(0 – 0 %)', '(IC no disponible)', '(IC no disponible)']);
|
||||
expect(root.textContent).toContain('Preliminar (preliminary)');
|
||||
expect(root.textContent).not.toContain('Preliminar (preliminary)');
|
||||
});
|
||||
|
||||
it.each([[[]], [[{ code: 'real' }]], [undefined]])('no expone una respuesta no simulada (%j)', tag => {
|
||||
|
||||
@@ -57,9 +57,10 @@ export function riesgoCacuVista(): RiesgoPacienteCacu {
|
||||
export function riesgoCacuConEstimando(): any {
|
||||
const data = riesgoCacuEjemplo();
|
||||
const resource = data.entry[0].resource;
|
||||
resource.method.text = 'Riesgo acumulado';
|
||||
resource.method.text = 'Probabilidad';
|
||||
resource.extension = [{ url: ESTIMANDO, extension: [
|
||||
{ url: 'quantity', valueString: 'Riesgo acumulado' },
|
||||
{ url: 'quantity', valueString: 'Probabilidad' },
|
||||
{ url: 'covariates', valueString: 'VPH y citología índice' },
|
||||
{ url: 'description', valueString: 'Probabilidad de CIN2+ antes de cada horizonte.' },
|
||||
{ url: 'outcome', valueString: 'CIN2+: biopsia LIEAG, CIS o carcinoma' },
|
||||
{ url: 'horizons_unit', valueString: 'años' },
|
||||
|
||||
@@ -13,7 +13,7 @@ const ESTIMAND = 'https://isssteleon.org/fhir/StructureDefinition/estimando';
|
||||
const NOT_SCORED = 'https://isssteleon.org/fhir/StructureDefinition/sin-estimacion';
|
||||
const INDEX_RESULTS = 'https://isssteleon.org/fhir/StructureDefinition/resultados-indice';
|
||||
const INDEX_RESULT_KEYS: readonly (keyof ResultadosIndice)[] = ['escamosas', 'glandulares', 'vph'];
|
||||
const ESTIMAND_KEYS: readonly (keyof EstimandoRiesgo)[] = ['quantity', 'description', 'outcome', 'index_date', 'horizons_unit'];
|
||||
const ESTIMAND_KEYS: readonly (keyof EstimandoRiesgo)[] = ['quantity', 'description', 'outcome', 'index_date', 'horizons_unit', 'covariates', 'complement'];
|
||||
|
||||
function utcTimestamp(v: unknown): v is string {
|
||||
return typeof v === 'string'
|
||||
@@ -138,6 +138,17 @@ function simulated(resource: Record<string, unknown>): boolean {
|
||||
return record(meta) && Array.isArray(meta['tag']) && meta['tag'].some(t => record(t) && t['code'] === SIMULATED);
|
||||
}
|
||||
|
||||
/** A model whose estimand asks for its complement (survival from a probability of dying): each horizon becomes
|
||||
* 1 − p, and its interval 1 − high to 1 − low. */
|
||||
function complemento(lote: LoteRiesgoCacu): void {
|
||||
if (lote.estimando?.complement !== 'supervivencia') return;
|
||||
lote.horizontes = lote.horizontes.map(h => ({
|
||||
...h, probabilidad: 1 - h.probabilidad,
|
||||
ic_bajo: h.ic_alto == null ? h.ic_alto ?? null : 1 - h.ic_alto,
|
||||
ic_alto: h.ic_bajo == null ? h.ic_bajo ?? null : 1 - h.ic_bajo,
|
||||
}));
|
||||
}
|
||||
|
||||
/** Where an outcome goes among the patient's risks: CIN2+ first, then cancer, then any other. */
|
||||
export function ordenDesenlace(desenlace: string): number {
|
||||
return desenlace.startsWith('cin2') ? 0 : desenlace === 'cancer' ? 1 : 2;
|
||||
@@ -157,6 +168,7 @@ export function riesgoPacienteResponse(v: unknown, pacId: string | null = null):
|
||||
if (!record(resource) || !simulated(resource)) invalid();
|
||||
return riskAssessment(structuredClone(resource), pacId);
|
||||
});
|
||||
riesgos.forEach(complemento);
|
||||
riesgos.sort((a, b) => ordenDesenlace(a.desenlace) - ordenDesenlace(b.desenlace));
|
||||
return { simulado: true, riesgo: riesgos.find(r => r.horizontes.length) ?? riesgos[0], riesgos };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user