Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a3a100450b | |||
| a92515eb4d | |||
| 5f92c49ed4 | |||
| a22ce12067 | |||
| a19874438b |
+1
-1
@@ -84,7 +84,7 @@ test("indicators: the KPIs are the API's MeasureReports, every tab and the patie
|
||||
).not.toContainText('Sin estudios');
|
||||
|
||||
await page.goto('/indicadores/cama');
|
||||
await expect(page.getByRole('tab', { name: 'Indicadores' })).toBeVisible();
|
||||
await expect(page.getByRole('tab', { name: 'Resumen' })).toBeVisible();
|
||||
await page.getByRole('tab', { name: 'Seguimiento' }).click();
|
||||
await page.locator('mat-form-field', { hasText: 'Ventana' }).click();
|
||||
await page.getByRole('option', { name: '12 meses' }).click();
|
||||
|
||||
@@ -36,7 +36,7 @@ import { Loading } from '../loading';
|
||||
<p class="muted empty">Este dominio todavía no tiene indicadores publicados.</p>
|
||||
} @else {
|
||||
<mat-tab-group mat-stretch-tabs="false" mat-align-tabs="center" animationDuration="0ms">
|
||||
<mat-tab [label]="domain() === 'tea' ? 'Resumen' : 'Indicadores'">
|
||||
<mat-tab label="Resumen">
|
||||
<app-tab-indicadores [domain]="domain()" [measures]="measures.value()!" />
|
||||
</mat-tab>
|
||||
<mat-tab label="Histórico">
|
||||
|
||||
@@ -246,66 +246,68 @@
|
||||
</mat-card>
|
||||
}
|
||||
|
||||
<mat-card appearance="outlined" class="wide" data-section="riesgos">
|
||||
<mat-card-content>
|
||||
@if (riskExclusion(); as reason) {
|
||||
<p role="status">{{ reason }}</p>
|
||||
} @else {
|
||||
<app-risk-scales [groups]="groups()" />
|
||||
}
|
||||
@if (riskModels().length) {
|
||||
<details data-section="modelos">
|
||||
<summary>Modelos y valores</summary>
|
||||
<table class="plain">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Modelo</th>
|
||||
<th>Fecha índice</th>
|
||||
<th>Horizonte</th>
|
||||
<th>Probabilidad</th>
|
||||
<th>IC 95 %</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (m of riskModels(); track m.model) {
|
||||
@for (p of m.predictions; track p.years) {
|
||||
<tr>
|
||||
<td>{{ $first ? m.text : '' }}</td>
|
||||
<td>{{ $first ? m.index : '' }}</td>
|
||||
<td>{{ p.years }} {{ p.years === 1 ? 'año' : 'años' }}</td>
|
||||
<td>{{ p.p * 100 | number: '1.1-2' }} %</td>
|
||||
<td>
|
||||
@if (p.low !== undefined) {
|
||||
{{ p.low * 100 | number: '1.1-2' }}–{{
|
||||
p.high! * 100 | number: '1.1-2'
|
||||
}}
|
||||
%
|
||||
} @else {
|
||||
—
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
@if (riskExclusion() || groups().length || domain() !== 'cacu' || riskModels().length) {
|
||||
<mat-card appearance="outlined" class="wide" data-section="riesgos">
|
||||
<mat-card-content>
|
||||
@if (riskExclusion(); as reason) {
|
||||
<p role="status">{{ reason }}</p>
|
||||
} @else {
|
||||
<app-risk-scales [groups]="groups()" />
|
||||
}
|
||||
@if (riskModels().length) {
|
||||
<details data-section="modelos">
|
||||
<summary>Modelos y valores</summary>
|
||||
<table class="plain">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Modelo</th>
|
||||
<th>Fecha índice</th>
|
||||
<th>Horizonte</th>
|
||||
<th>Probabilidad</th>
|
||||
<th>IC 95 %</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (m of riskModels(); track m.model) {
|
||||
@for (p of m.predictions; track p.years) {
|
||||
<tr>
|
||||
<td>{{ $first ? m.text : '' }}</td>
|
||||
<td>{{ $first ? m.index : '' }}</td>
|
||||
<td>{{ p.years }} {{ p.years === 1 ? 'año' : 'años' }}</td>
|
||||
<td>{{ p.p * 100 | number: '1.1-2' }} %</td>
|
||||
<td>
|
||||
@if (p.low !== undefined) {
|
||||
{{ p.low * 100 | number: '1.1-2' }}–{{
|
||||
p.high! * 100 | number: '1.1-2'
|
||||
}}
|
||||
%
|
||||
} @else {
|
||||
—
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</details>
|
||||
}
|
||||
@if (!riskExclusion() && (riskModels().length || riskSeries.value()?.length)) {
|
||||
<details class="curves" open data-section="curvas">
|
||||
<summary>Curvas de probabilidad con su intervalo</summary>
|
||||
@if (riskSeries.value()?.length) {
|
||||
<app-risk-series [series]="riskSeries.value()!" />
|
||||
} @else {
|
||||
<app-plot [figure]="curve()" [height]="300" />
|
||||
}
|
||||
</details>
|
||||
}
|
||||
@if (!riskModels().length && !riskExclusion()) {
|
||||
<p class="muted">Sin evaluación de un modelo en producción.</p>
|
||||
}
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</tbody>
|
||||
</table>
|
||||
</details>
|
||||
}
|
||||
@if (!riskExclusion() && (riskModels().length || riskSeries.value()?.length)) {
|
||||
<details class="curves" open data-section="curvas">
|
||||
<summary>Curvas de probabilidad con su intervalo</summary>
|
||||
@if (riskSeries.value()?.length) {
|
||||
<app-risk-series [series]="riskSeries.value()!" />
|
||||
} @else {
|
||||
<app-plot [figure]="curve()" [height]="300" />
|
||||
}
|
||||
</details>
|
||||
}
|
||||
@if (!riskModels().length && !riskExclusion()) {
|
||||
<p class="muted">Sin evaluación de un modelo en producción.</p>
|
||||
}
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
@if (domain() === 'tea') {
|
||||
<mat-card appearance="outlined" class="wide" data-section="tea">
|
||||
<mat-card-header><mat-card-title>ADOS-2</mat-card-title></mat-card-header>
|
||||
@@ -557,19 +559,36 @@
|
||||
<mat-card appearance="outlined" class="wide" data-section="supervivencia">
|
||||
<mat-card-header>
|
||||
<mat-card-title>{{
|
||||
domain() === 'cacu' ? 'Supervivencia por escenario clínico' : 'Riesgo de muerte'
|
||||
domain() === 'cacu' ? 'Supervivencia' : 'Riesgo de muerte'
|
||||
}}</mat-card-title>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<h3>Análisis de supervivencia</h3>
|
||||
@if (domain() === 'cacu') {
|
||||
<p class="muted" data-note="grupo">
|
||||
Las curvas son estimaciones del grupo de pacientes del escenario clínico
|
||||
correspondiente (S(t), probabilidad de supervivencia); no son predicciones
|
||||
individuales.
|
||||
</p>
|
||||
@if (domain() !== 'cacu') {
|
||||
<h3>Análisis de supervivencia</h3>
|
||||
}
|
||||
@if (survival.isLoading()) {
|
||||
@if (domain() === 'cacu') {
|
||||
<app-risk-scales [groups]="survivalScales()" />
|
||||
<h3>Curva de supervivencia</h3>
|
||||
@if (combination.isLoading()) {
|
||||
<app-loading what="la curva de supervivencia" [figure]="true" />
|
||||
} @else if (combination.error()) {
|
||||
<p class="muted" role="alert">No se pudo leer el informe del modelo.</p>
|
||||
} @else if (combination.value(); as c) {
|
||||
@if (c.figure) {
|
||||
<p class="muted">
|
||||
Kaplan-Meier de pacientes con sus mismos valores (IC 95 % Greenwood log-log; n =
|
||||
{{ c.n }}, fallecidos = {{ c.fallecidos }}).
|
||||
</p>
|
||||
<app-plot [figure]="c.figure" [height]="340" />
|
||||
} @else {
|
||||
<p class="muted">{{ c.missing }}</p>
|
||||
}
|
||||
} @else {
|
||||
<p class="muted">
|
||||
No disponible: la estimación no conserva los valores usados para elegir la curva.
|
||||
</p>
|
||||
}
|
||||
} @else if (survival.isLoading()) {
|
||||
<app-loading what="las curvas de supervivencia" [figure]="true" />
|
||||
} @else if (survival.value(); as s) {
|
||||
<h3>Escenario clínico de la paciente</h3>
|
||||
@@ -579,12 +598,14 @@
|
||||
}
|
||||
</ul>
|
||||
@if (s.methods.length) {
|
||||
<h3>Métodos</h3>
|
||||
<ul class="scenarios methods">
|
||||
@for (name of s.methods; track name) {
|
||||
<li>{{ name }}</li>
|
||||
}
|
||||
</ul>
|
||||
<details>
|
||||
<summary>Métodos</summary>
|
||||
<ul class="scenarios methods">
|
||||
@for (name of s.methods; track name) {
|
||||
<li>{{ name }}</li>
|
||||
}
|
||||
</ul>
|
||||
</details>
|
||||
}
|
||||
@for (f of s.figures; track f.title) {
|
||||
<h4>{{ f.title }}</h4>
|
||||
@@ -608,14 +629,7 @@
|
||||
} @else if (survival.error()) {
|
||||
<p class="muted" role="alert">No se pudo leer el informe del modelo.</p>
|
||||
} @else {
|
||||
<p class="muted" data-state="sin-informe">
|
||||
@if (domain() === 'cacu') {
|
||||
No disponible: no hay un informe de supervivencia para los escenarios de la
|
||||
paciente.
|
||||
} @else {
|
||||
No disponible: datos insuficientes.
|
||||
}
|
||||
</p>
|
||||
<p class="muted" data-state="sin-informe">No disponible: datos insuficientes.</p>
|
||||
}
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
@@ -32,7 +32,8 @@ import { eligibilityFailure, eligibilityView, type EligibilityState } from './el
|
||||
import { ineligibility } from './ineligibility';
|
||||
import { parseSeries, RiskSeries, Series } from './risk-series';
|
||||
import { curveFigure } from './risk-curve';
|
||||
import { isRiskModel, riskGroups, riskScales, RiskScales } from './risk-scales';
|
||||
import { riskGroups, riskScales, RiskScales, survivalGroups } from './risk-scales';
|
||||
import { combinationFigure, combinationOf, noCurveText } from './survival-combination';
|
||||
import { route, Stages } from './stages';
|
||||
import { ageAt, ageGroup, CAMA_AGE_GROUPS, camaRows, CURP } from '../indicadores/follow-up';
|
||||
import { LABELS, name, PRIORITY } from '../indicadores/measures';
|
||||
@@ -79,6 +80,25 @@ function methods(figures: { figure: { data: unknown[] } }[]): string[] {
|
||||
return [...new Set(names.filter((n): n is string => !!n))];
|
||||
}
|
||||
|
||||
/** The day of an instant in the hospital's time zone (America/Monterrey). */
|
||||
function localDay(instant: string | undefined): string | undefined {
|
||||
return instant
|
||||
? new Date(instant).toLocaleDateString('en-CA', { timeZone: 'America/Monterrey' })
|
||||
: undefined;
|
||||
}
|
||||
|
||||
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: [
|
||||
@@ -183,14 +203,42 @@ export class Paciente {
|
||||
return this.domain() === 'cacu' ? route(shown, this.cutoff()) : undefined;
|
||||
});
|
||||
/** The models whose estimate is a risk (scales, curves, PDF): not survival or recurrence. */
|
||||
protected readonly riskModels = computed(() => this.models().filter((m) => isRiskModel(m.model)));
|
||||
protected readonly riskModels = computed(() => this.models().filter((m) => m.measure === 'risk'));
|
||||
protected readonly scales = computed(() =>
|
||||
this.domain() === 'cacu' ? riskScales(this.riskModels()) : [],
|
||||
);
|
||||
/** CaCu: both horizons of every model, or both unavailable (the PDF keeps `scales`). */
|
||||
/** CaCu: both horizons of every risk model, or both unavailable (the PDF keeps `scales`). With
|
||||
* survival only there is nothing to draw here: its scales are in the survival section. */
|
||||
protected readonly groups = computed(() =>
|
||||
this.domain() === 'cacu' ? riskGroups(this.riskModels()) : [],
|
||||
this.domain() === 'cacu' && (this.riskModels().length || !this.survivalScales().length)
|
||||
? riskGroups(this.riskModels())
|
||||
: [],
|
||||
);
|
||||
protected readonly survivalScales = computed(() =>
|
||||
this.domain() === 'cacu'
|
||||
? survivalGroups(this.models().filter((m) => m.measure === 'mortality'))
|
||||
: [],
|
||||
);
|
||||
/** CaCu: the one Kaplan-Meier curve of the patients who share all her values, from the report of
|
||||
* the model version that scored her. */
|
||||
protected readonly combination = resource({
|
||||
params: () => {
|
||||
const m = this.models().find((x) => x.model === 'cacu.survival' && x.version && x.inputs);
|
||||
return this.domain() === 'cacu' && m ? { version: m.version, inputs: m.inputs! } : undefined;
|
||||
},
|
||||
loader: async ({ params: { version, inputs } }) => {
|
||||
const report = await this.api.invoke(readReport$Json, {
|
||||
domain: 'cacu' as Domain,
|
||||
name: 'survival',
|
||||
version,
|
||||
report: 'interpretability',
|
||||
});
|
||||
const found = combinationOf(report as Record<string, unknown>, inputs);
|
||||
return found?.km
|
||||
? { n: found.n, fallecidos: found.fallecidos, figure: combinationFigure(found.km) }
|
||||
: { missing: noCurveText(report as Record<string, unknown>, found) };
|
||||
},
|
||||
});
|
||||
/** CaCu, experimental: the series her record can compare; none while the API has it off. */
|
||||
protected readonly riskSeries = resource({
|
||||
params: () =>
|
||||
@@ -341,6 +389,9 @@ export class Paciente {
|
||||
text: r.method?.text ?? '',
|
||||
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),
|
||||
evaluated: localDay(r.meta?.lastUpdated),
|
||||
// the clinical scenarios of the model's report she falls in
|
||||
scenarios: (r.extension ?? [])
|
||||
.filter((e) => e.url === EXT + 'escenario-clinico')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { horizon, isRiskModel, riskGroups, riskScales } from './risk-scales';
|
||||
import { horizon, isRiskModel, riskGroups, riskScales, survivalGroups } from './risk-scales';
|
||||
|
||||
const at = (years: number, p: number, low?: number, high?: number) => ({ years, p, low, high });
|
||||
|
||||
@@ -84,3 +84,21 @@ describe('which models feed the risk scales', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('survival scales', () => {
|
||||
it('complements mortality and reverses interval bounds at every published horizon', () => {
|
||||
const [g] = survivalGroups([{ index: '2026-01-01', predictions: [at(1, 0.2, 0.1, 0.3)] }]);
|
||||
expect(g.survival).toBe(true);
|
||||
expect(g.index).toBe('2026-01-01');
|
||||
expect(g.scales[0].risk?.p).toBeCloseTo(0.8);
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -48,9 +48,54 @@ export interface RiskGroup {
|
||||
title?: string;
|
||||
scenario?: string;
|
||||
index?: string;
|
||||
survival?: boolean;
|
||||
inputs?: Record<string, unknown>;
|
||||
/** the model and version that scored her, and the day it did */
|
||||
model?: string;
|
||||
evaluated?: string;
|
||||
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[];
|
||||
scenarios?: string[];
|
||||
inputs?: Record<string, unknown>;
|
||||
text?: string;
|
||||
evaluated?: string;
|
||||
}[],
|
||||
): RiskGroup[] {
|
||||
return models
|
||||
.map((m) => ({
|
||||
title: 'Supervivencia',
|
||||
index: m.index,
|
||||
survival: true,
|
||||
inputs: m.inputs,
|
||||
model: m.text,
|
||||
evaluated: m.evaluated,
|
||||
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'}`,
|
||||
risk: {
|
||||
years: p.years,
|
||||
p: 1 - v.p,
|
||||
low: v.high === undefined ? undefined : 1 - v.high,
|
||||
high: v.low === undefined ? undefined : 1 - v.low,
|
||||
},
|
||||
},
|
||||
]
|
||||
: [];
|
||||
}),
|
||||
}))
|
||||
.filter((g) => g.scales.length);
|
||||
}
|
||||
|
||||
const HORIZONS: [number, string][] = [
|
||||
[0, 'Riesgo inmediato (al índice)'],
|
||||
[5, 'Riesgo a 5 años'],
|
||||
@@ -65,7 +110,13 @@ 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>;
|
||||
evaluated?: string;
|
||||
}[],
|
||||
): RiskGroup[] {
|
||||
const scales = (predictions: Prediction[]) =>
|
||||
HORIZONS.map(([years, label]) => ({ label, risk: horizon(predictions, years) }));
|
||||
@@ -73,6 +124,9 @@ export function riskGroups(
|
||||
? models.map((m) => ({
|
||||
...titleParts(m.text),
|
||||
index: m.index,
|
||||
inputs: m.inputs,
|
||||
model: m.text,
|
||||
evaluated: m.evaluated,
|
||||
scales: scales(m.predictions),
|
||||
}))
|
||||
: [{ scales: scales([]) }];
|
||||
@@ -105,7 +159,7 @@ export function riskGroups(
|
||||
· No disponible
|
||||
}
|
||||
</p>
|
||||
<div class="risk-plot" [class.unavailable]="!s.risk">
|
||||
<div class="risk-plot" [class.unavailable]="!s.risk" [class.survival]="g.survival">
|
||||
<div class="risk-line" aria-hidden="true"></div>
|
||||
@if (s.risk; as r) {
|
||||
@if (r.low !== undefined && r.high !== undefined) {
|
||||
@@ -134,6 +188,52 @@ export function riskGroups(
|
||||
{{ g.scenario ? 'Escenario: ' + g.scenario + ' · ' : '' }}Fecha índice {{ g.index }}
|
||||
</p>
|
||||
}
|
||||
@if (g.title && !g.survival) {
|
||||
<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>
|
||||
}
|
||||
@if (g.model) {
|
||||
<details data-section="metodos">
|
||||
<summary>Métodos</summary>
|
||||
<dl>
|
||||
<div>
|
||||
<dt>Modelo y versión</dt>
|
||||
<dd>{{ g.model }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Fecha índice</dt>
|
||||
<dd>{{ g.index }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Fecha de evaluación</dt>
|
||||
<dd>{{ g.evaluated ?? 'No disponible' }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Covariables</dt>
|
||||
<dd>
|
||||
@for (item of entries(g.inputs ?? {}); track item[0]) {
|
||||
<div>{{ inputName(item[0]) }}: {{ inputValue(item[0], item[1]) }}</div>
|
||||
} @empty {
|
||||
No disponibles para esta estimación.
|
||||
}
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</details>
|
||||
}
|
||||
}
|
||||
`,
|
||||
styles: `
|
||||
@@ -170,6 +270,15 @@ export function riskGroups(
|
||||
#fff 25%
|
||||
);
|
||||
}
|
||||
.survival .risk-line {
|
||||
background: linear-gradient(
|
||||
to right,
|
||||
#c24269 0 25%,
|
||||
#df8640 25% 50%,
|
||||
#a8c243 50% 75%,
|
||||
#42a77e 75% 100%
|
||||
);
|
||||
}
|
||||
.risk-interval {
|
||||
border-left: 2px solid #17324d;
|
||||
border-right: 2px solid #17324d;
|
||||
@@ -216,4 +325,27 @@ 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);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { Component, computed, input, signal } from '@angular/core';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import type { Parameters, ParametersParameter } from 'fhir/r4';
|
||||
import { Plot } from '../plot';
|
||||
import { curveFigure } from './risk-curve';
|
||||
import { REASON_TEXT } from './reference-risk';
|
||||
|
||||
export interface SeriesPoint {
|
||||
years: number;
|
||||
@@ -32,10 +28,6 @@ const OUTCOME_TEXT: Record<string, string> = {
|
||||
'CIN3+': 'CIN3+',
|
||||
cancer: 'Cáncer',
|
||||
};
|
||||
const REASONS: Record<string, string> = {
|
||||
...REASON_TEXT,
|
||||
history_is_registered: 'Tiene antecedentes registrados: no corresponde la tabla de ingreso.',
|
||||
};
|
||||
|
||||
export const seriesName = (s: Series) => `${s.source} · ${OUTCOME_TEXT[s.outcome] ?? s.outcome}`;
|
||||
|
||||
@@ -61,11 +53,10 @@ export function parseSeries(answer: Parameters): Series[] {
|
||||
}));
|
||||
}
|
||||
|
||||
/** The chosen series as bars at one horizon and as curves. Series are shown side by side; no
|
||||
* difference between them is computed. */
|
||||
/** The chosen series as curves. Series are shown side by side; no difference is computed. */
|
||||
@Component({
|
||||
selector: 'app-risk-series',
|
||||
imports: [DecimalPipe, MatCheckboxModule, MatFormFieldModule, MatSelectModule, Plot],
|
||||
imports: [MatCheckboxModule, Plot],
|
||||
template: `
|
||||
<p class="muted">Cada serie tiene su propio desenlace y población: no se restan entre sí.</p>
|
||||
<div class="choices">
|
||||
@@ -76,44 +67,15 @@ export function parseSeries(answer: Parameters): Series[] {
|
||||
}
|
||||
</div>
|
||||
@if (selected().length) {
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Horizonte</mat-label>
|
||||
<mat-select [value]="horizon()" (selectionChange)="picked.set($event.value)">
|
||||
@for (h of horizons(); track h) {
|
||||
<mat-option [value]="h">{{ h === 0 ? 'Al índice' : h + ' años' }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<ul class="bars">
|
||||
@for (b of bars(); track b.series.id) {
|
||||
<li>
|
||||
<span>{{ name(b.series) }}</span>
|
||||
<small class="muted">{{ b.series.label }}</small>
|
||||
@if (b.point; as p) {
|
||||
<span class="track"><span class="fill" [style.width.%]="p.p * 100"></span></span>
|
||||
<span>
|
||||
{{ p.p * 100 | number: '1.1-2' }} %
|
||||
@if (p.low !== undefined && p.high !== undefined) {
|
||||
(IC 95 %: {{ p.low * 100 | number: '1.1-2' }}–{{
|
||||
p.high * 100 | number: '1.1-2'
|
||||
}})
|
||||
} @else {
|
||||
(IC 95 % no publicado)
|
||||
}
|
||||
</span>
|
||||
} @else {
|
||||
<span class="muted">No disponible en este horizonte.</span>
|
||||
}
|
||||
@for (a of b.series.assumptions; track a) {
|
||||
<small class="muted">{{ a }}</small>
|
||||
}
|
||||
</li>
|
||||
@for (s of selected(); track s.id) {
|
||||
@for (assumption of s.assumptions; track assumption) {
|
||||
<p class="muted">{{ name(s) }}: {{ assumption }}</p>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
<app-plot [figure]="figure()" [height]="340" />
|
||||
}
|
||||
@for (s of unavailable(); track s.id) {
|
||||
<p class="muted">{{ name(s) }}: no disponible. {{ why(s) }}</p>
|
||||
@if (!available().length) {
|
||||
<p class="muted">No disponible: datos insuficientes.</p>
|
||||
}
|
||||
`,
|
||||
styles: `
|
||||
@@ -126,31 +88,12 @@ export function parseSeries(answer: Parameters): Series[] {
|
||||
gap: 0 16px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.bars {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
}
|
||||
.bars li {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.track {
|
||||
background: var(--color-action-hover, #f1f6f6);
|
||||
height: 10px;
|
||||
}
|
||||
.fill {
|
||||
background: #4269a0;
|
||||
display: block;
|
||||
height: 100%;
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class RiskSeries {
|
||||
readonly series = input.required<Series[]>();
|
||||
protected readonly name = seriesName;
|
||||
protected readonly available = computed(() => this.series().filter((s) => s.points.length));
|
||||
protected readonly unavailable = computed(() => this.series().filter((s) => !s.points.length));
|
||||
/** what the user toggled away from the default (the institutional series) */
|
||||
private readonly toggled = signal(new Set<string>());
|
||||
protected readonly chosen = computed(
|
||||
@@ -164,21 +107,6 @@ export class RiskSeries {
|
||||
protected readonly selected = computed(() =>
|
||||
this.available().filter((s) => this.chosen().has(s.id)),
|
||||
);
|
||||
protected readonly horizons = computed(() =>
|
||||
[...new Set(this.selected().flatMap((s) => s.points.map((p) => p.years)))].sort(
|
||||
(a, b) => a - b,
|
||||
),
|
||||
);
|
||||
protected readonly picked = signal(5);
|
||||
protected readonly horizon = computed(() =>
|
||||
this.horizons().includes(this.picked()) ? this.picked() : this.horizons().at(-1)!,
|
||||
);
|
||||
protected readonly bars = computed(() =>
|
||||
this.selected().map((series) => ({
|
||||
series,
|
||||
point: series.points.find((p) => p.years === this.horizon()),
|
||||
})),
|
||||
);
|
||||
protected readonly figure = computed(() => {
|
||||
const shown = this.selected().map((s) => ({
|
||||
model: s.id,
|
||||
@@ -198,8 +126,4 @@ export class RiskSeries {
|
||||
if (!next.delete(id)) next.add(id);
|
||||
this.toggled.set(next);
|
||||
}
|
||||
|
||||
protected why(s: Series) {
|
||||
return s.reasons.map((r) => REASONS[r] ?? r).join(' ');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { combinationOf, noCurveText } from './survival-combination';
|
||||
|
||||
describe('combinationOf', () => {
|
||||
const values = { age_group: '<30', cytology: 'NA', hpv: 'positive' };
|
||||
const report = { km_combinaciones: [{ valores: values, n: 9, fallecidos: 6 }] };
|
||||
|
||||
it('takes only the entry with all her values, a missing one as NA', () => {
|
||||
expect(combinationOf(report, { age_group: '<30', cytology: null, hpv: 'positive' })?.n).toBe(9);
|
||||
expect(combinationOf(report, { age_group: '<30', cytology: null, hpv: 'negative' })).toBe(
|
||||
undefined,
|
||||
);
|
||||
expect(combinationOf(report, { age_group: '<30' })).toBe(undefined);
|
||||
expect(combinationOf({}, values)).toBe(undefined);
|
||||
});
|
||||
|
||||
it('tells an old report apart from a combination with too few deaths', () => {
|
||||
expect(noCurveText({}, undefined)).toContain('no publica esta curva');
|
||||
expect(
|
||||
noCurveText(
|
||||
{ ...report, min_fallecidos_escenario: 5 },
|
||||
{ valores: values, n: 9, fallecidos: 2 },
|
||||
),
|
||||
).toContain('n = 9, fallecidos = 2; mínimo requerido: 5');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
import { Figure, PALETTE } from '../plot';
|
||||
|
||||
/** One entry of the survival report's `km_combinaciones`: the patients who share every value. */
|
||||
export interface Combination {
|
||||
valores: Record<string, string>;
|
||||
n: number;
|
||||
fallecidos: number;
|
||||
km?: { months: number[]; S: number[]; low: number[]; high: number[] };
|
||||
}
|
||||
|
||||
/** The entry with exactly her values (a missing one is the report's "NA"); never a partial match. */
|
||||
export function combinationOf(
|
||||
report: Record<string, unknown> | null | undefined,
|
||||
inputs: Record<string, unknown>,
|
||||
): Combination | undefined {
|
||||
const all = report?.['km_combinaciones'];
|
||||
return (Array.isArray(all) ? (all as Combination[]) : []).find((c) => {
|
||||
const keys = Object.keys(c.valores);
|
||||
return (
|
||||
keys.length === Object.keys(inputs).length &&
|
||||
keys.every((k) => k in inputs && c.valores[k] === String(inputs[k] ?? 'NA'))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/** Why there is no curve for her: these are not the same thing, so each is said apart. (A patient
|
||||
* outside the survival scenario has no survival section at all.) */
|
||||
export function noCurveText(
|
||||
report: Record<string, unknown> | null | undefined,
|
||||
found: Combination | undefined,
|
||||
): string {
|
||||
if (!Array.isArray(report?.['km_combinaciones']))
|
||||
return 'No disponible: la versión del modelo que la evaluó no publica esta curva.';
|
||||
const minimum = report['min_fallecidos_escenario'];
|
||||
const counts = `n = ${found?.n ?? 0}, fallecidos = ${found?.fallecidos ?? 0}`;
|
||||
return `No disponible: datos insuficientes para su combinación de valores (${counts}${
|
||||
typeof minimum === 'number' ? `; mínimo requerido: ${minimum} fallecidos` : ''
|
||||
}).`;
|
||||
}
|
||||
|
||||
export function combinationFigure(km: NonNullable<Combination['km']>): Figure {
|
||||
const line = (y: number[], more: object) => ({
|
||||
type: 'scatter',
|
||||
mode: 'lines',
|
||||
x: km.months,
|
||||
y,
|
||||
line: { shape: 'hv', color: PALETTE[0], width: 0 },
|
||||
...more,
|
||||
});
|
||||
return {
|
||||
data: [
|
||||
line(km.low, { showlegend: false, hoverinfo: 'skip' }),
|
||||
line(km.high, { name: 'IC 95 %', fill: 'tonexty', fillcolor: 'rgba(23, 50, 77, 0.15)' }),
|
||||
line(km.S, { name: 'Kaplan-Meier', line: { shape: 'hv', color: PALETTE[0], width: 2 } }),
|
||||
],
|
||||
layout: {
|
||||
xaxis: { title: { text: 'Meses desde el índice' } },
|
||||
yaxis: { title: { text: 'Supervivencia S(t)' }, range: [0, 1.02], tickformat: '.0%' },
|
||||
},
|
||||
} as Figure;
|
||||
}
|
||||
Reference in New Issue
Block a user