Record: Relación con el ADOS-2 and Análisis de recurrencia; Gobernanza draws the association

This commit is contained in:
Roberto Treviño
2026-11-28 21:28:42 -06:00
parent 6ea54d6e6d
commit 133092f8c8
9 changed files with 473 additions and 31 deletions
+124
View File
@@ -36,6 +36,14 @@
"title": "Metrics",
"type": "array"
},
"relation": {
"default": [],
"items": {
"$ref": "#/components/schemas/Relation"
},
"title": "Relation",
"type": "array"
},
"valid": {
"anyOf": [
{
@@ -1413,6 +1421,122 @@
"title": "Rejection",
"type": "object"
},
"Relation": {
"description": "One pair of the champion EEG\u2013ADOS-2 association, for this EEG (models.tea.association).",
"properties": {
"biomarker": {
"title": "Biomarker",
"type": "string"
},
"ci_high": {
"anyOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "Ci High"
},
"ci_low": {
"anyOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "Ci Low"
},
"event": {
"title": "Event",
"type": "string"
},
"kind": {
"title": "Kind",
"type": "string"
},
"metric": {
"title": "Metric",
"type": "string"
},
"model": {
"title": "Model",
"type": "string"
},
"n": {
"title": "N",
"type": "number"
},
"observed": {
"anyOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "Observed"
},
"odds_ratio": {
"title": "Odds Ratio",
"type": "number"
},
"outcome_code": {
"title": "Outcome Code",
"type": "string"
},
"probability": {
"title": "Probability",
"type": "number"
},
"q": {
"anyOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"title": "Q"
},
"reference_probability": {
"title": "Reference Probability",
"type": "number"
},
"z": {
"title": "Z",
"type": "number"
},
"zone": {
"title": "Zone",
"type": "string"
}
},
"required": [
"biomarker",
"metric",
"zone",
"outcome_code",
"kind",
"event",
"z",
"probability",
"reference_probability",
"odds_ratio",
"ci_low",
"ci_high",
"q",
"n",
"model"
],
"title": "Relation",
"type": "object"
},
"Route": {
"additionalProperties": false,
"description": "Only the rows where every condition holds (e.g. reports titled \"Citolog\u00eda\"). An\n`otherwise` route takes the rows of its input that none of the other routes on that\ninput take (documents nobody recognises, for a reviewer), then its own conditions.",
+1
View File
@@ -31,6 +31,7 @@ export type { Position } from './models/position';
export type { Provider } from './models/provider';
export type { Read } from './models/read';
export type { Rejection } from './models/rejection';
export type { Relation } from './models/relation';
export type { Route } from './models/route';
export type { RunRequest } from './models/run-request';
export type { SavedPipeline } from './models/saved-pipeline';
+2
View File
@@ -2,10 +2,12 @@
/* Code generated by ng-openapi-gen DO NOT EDIT. */
import { Metric } from '../models/metric';
import { Relation } from '../models/relation';
export interface Analysis {
age_months: (number | null);
id: string;
level: (string | null);
metrics: Array<Metric>;
relation?: Array<Relation>;
valid: (boolean | null);
}
+25
View File
@@ -0,0 +1,25 @@
/* eslint-disable */
/* Code generated by ng-openapi-gen DO NOT EDIT. */
/**
* One pair of the champion EEG–ADOS-2 association, for this EEG (models.tea.association).
*/
export interface Relation {
biomarker: string;
ci_high: (number | null);
ci_low: (number | null);
event: string;
kind: string;
metric: string;
model: string;
n: number;
observed?: (number | null);
odds_ratio: number;
outcome_code: string;
probability: number;
q: (number | null);
reference_probability: number;
z: number;
zone: string;
}
+37
View File
@@ -19,6 +19,43 @@ export const ZONE_NAMES: Record<string, string> = {
temporal_left: 'Temporal izquierda',
temporal_right: 'Temporal derecha',
occipital: 'Occipital',
posterior: 'Posterior',
global: 'Global',
};
/** The association's biomarkers (core.tea.association.BIOMARKERS). */
export const BIOMARKER_NAMES: Record<string, string> = {
spikes: 'Picos paroxísticos',
spindles: 'Husos de sueño N2',
posterior_rhythm: 'Ritmo posterior',
gradient: 'Gradiente anteroposterior',
};
/** ADOS-2 items by their number (core.tea.association.ITEMS), and the CSS. */
export const OUTCOME_NAMES: Record<string, string> = {
ados2_item_01: 'Vocalización espontánea dirigida a otros',
ados2_item_02: 'Señalar',
ados2_item_03: 'Gestos',
ados2_item_04: 'Contacto visual inusual',
ados2_item_05: 'Expresiones faciales dirigidas a otros',
ados2_item_06: 'Integración de la mirada con otras conductas',
ados2_item_07: 'Disfrute compartido en la interacción',
ados2_item_08: 'Respuesta al nombre',
ados2_item_09: 'Búsqueda de atención cuando se le ignora',
ados2_item_10: 'Pedir',
ados2_item_11: 'Mostrar',
ados2_item_12: 'Iniciación espontánea de la atención conjunta',
ados2_item_13: 'Respuesta a la atención conjunta',
ados2_item_14: 'Calidad de los acercamientos sociales',
ados2_item_15: 'Cantidad de acercamientos sociales al cuidador',
ados2_item_16: 'Cantidad de comunicación social recíproca',
ados2_item_17: 'Calidad general de la relación',
ados2_item_18: 'Entonación de vocalizaciones o verbalizaciones',
ados2_item_19: 'Uso estereotipado o idiosincrático de palabras',
ados2_item_20: 'Interés sensorial inusual',
ados2_item_21: 'Manierismos de manos y dedos',
ados2_item_22: 'Intereses repetitivos o conductas estereotipadas',
CSS: 'Puntuación de severidad (CSS)',
};
/** Where each electrode of the 10-20 system sits on a head seen from above (nose up). */
+57
View File
@@ -1,5 +1,6 @@
import type { Figure } from '../plot';
import { PALETTE } from '../plot';
import { BIOMARKER_NAMES, OUTCOME_NAMES, ZONE_NAMES } from '../eeg-labels';
/** A curve with its band, as the reports give them. */
interface Band {
@@ -197,6 +198,62 @@ export function interpretabilityFigures(
},
];
}
case 'associations': {
// Each estimated pair's odds ratio with its 95 % interval, clearest first.
const rows = (report['rows'] as any[])
.filter((r) => r.odds_ratio !== null)
.sort((a, b) => (a.q ?? 1) - (b.q ?? 1));
const label = (r: any) =>
`${BIOMARKER_NAMES[r.biomarker] ?? r.biomarker} · ${ZONE_NAMES[r.zone] ?? r.zone} → ${
OUTCOME_NAMES[r.outcome_code] ?? r.outcome_code
}`;
return [
{
title: `Asociaciones con el ADOS-2 (${report['children']} niños, nivel ${
report['level'] === 'item' ? 'reactivo' : 'dominio'
})`,
figure: {
data: [
{
type: 'scatter',
mode: 'markers',
x: rows.map((r) => r.odds_ratio),
y: rows.map(label),
error_x: {
type: 'data',
symmetric: false,
array: rows.map((r) => (r.ci_high ?? r.odds_ratio) - r.odds_ratio),
arrayminus: rows.map((r) => r.odds_ratio - (r.ci_low ?? r.odds_ratio)),
},
marker: {
color: rows.map((r) => ((r.q ?? 1) < 0.05 ? PALETTE[2] : '#9aa0a6')),
size: 9,
},
customdata: rows.map((r) => r.q),
hovertemplate: 'OR %{x:.2f} · q %{customdata:.3f}<extra>%{y}</extra>',
showlegend: false,
},
],
layout: {
xaxis: { title: { text: 'Razón de momios (escala log)' }, type: 'log' },
yaxis: { automargin: true, autorange: 'reversed' },
shapes: [
{
type: 'line',
x0: 1,
x1: 1,
yref: 'paper',
y0: 0,
y1: 1,
line: { color: '#9aa0a6', dash: 'dot' },
},
],
height: Math.max(320, 22 * rows.length + 80),
},
},
},
];
}
default:
return [];
}
+132 -1
View File
@@ -259,6 +259,92 @@
} @else {
<p>Sin alteraciones: todas sus métricas están dentro de la norma por edad.</p>
}
@if (st.valid && scored()) {
<section
class="relation"
aria-label="Relación de las alteraciones del EEG con el ADOS-2"
>
<h3>Relación con el ADOS-2</h3>
@if (!eeg.value()?.analysis?.relation?.length) {
<p class="muted">
Ningún modelo de asociación vigente ha evaluado este EEG (se promueven en
Gobernanza).
</p>
} @else if (!related().length) {
<p>
Ninguna zona alterada de este paciente (|z| ≥ 2) tiene una asociación clara
con el ADOS-2 en la cohorte.
</p>
} @else {
<p class="muted">
Modelo de asociación ajustado en la cohorte ({{ related()[0].n }} niños, por
edad y módulo del ADOS-2): qué tanto se asocia cada alteración del EEG por
zona con un aspecto del ADOS-2. No es un diagnóstico ni indica qué causa qué.
</p>
<table class="plain">
<thead>
<tr>
<th>Zona del EEG</th>
<th>Aspecto del ADOS-2</th>
<th>Asociación en la cohorte</th>
<th>Probabilidad para este paciente</th>
<th>Lo que muestra su ADOS-2</th>
</tr>
</thead>
<tbody>
@for (f of related(); track f.biomarker + f.zone + f.outcome_code) {
<tr>
<td>
<strong>{{ biomarkerNames[f.biomarker] ?? f.biomarker }}</strong>
<small
>{{ zoneNames[f.zone] ?? f.zone }} · z =
{{ f.z | number: '1.1-2' }}</small
>
</td>
<td>
{{ outcomeNames[f.outcome_code] ?? f.outcome_code }}
<small>{{ f.kind === 'item' ? 'Reactivo' : 'Dominio' }}</small>
</td>
<td>
OR {{ f.odds_ratio | number: '1.2-2' }}
<small
>IC 95 % {{ f.ci_low | number: '1.2-2' }}–{{
f.ci_high | number: '1.2-2'
}}
· q {{ qText(f.q) }}</small
>
<small>{{
f.odds_ratio >= 1
? 'A mayor z, mayor probabilidad'
: 'A menor z, mayor probabilidad'
}}</small>
</td>
<td>
<strong>{{ f.probability * 100 | number: '1.0-0' }} %</strong>
<small
>{{ f.event }} · con z = 0:
{{ f.reference_probability * 100 | number: '1.0-0' }} %</small
>
</td>
<td>
{{ observed(f) }}
@if (matches(f); as m) {
<small>{{ m }}</small>
}
</td>
</tr>
}
</tbody>
</table>
<p class="muted">
OR mayor que 1: a mayor z en esa zona, más probable que el aspecto salga
alterado; menor que 1, al revés. Solo se muestran las zonas alteradas del
paciente (|z| ≥ 2) con una asociación clara en la cohorte (q &lt; 0.05).
Versión del modelo: {{ related()[0].model }}.
</p>
}
</section>
}
} @else {
<p class="muted">Sin EEG analizado.</p>
}
@@ -266,7 +352,7 @@
</mat-card>
}
@if (models().some((m) => m.scenarios.length)) {
@if (models().some((m) => m.model.endsWith('.survival') && m.scenarios.length)) {
<mat-card appearance="outlined" class="wide" data-section="supervivencia">
<mat-card-header
><mat-card-title>Análisis de supervivencia</mat-card-title></mat-card-header
@@ -295,6 +381,51 @@
</mat-card-content>
</mat-card>
}
@if (recurrenceModel(); as rm) {
<mat-card appearance="outlined" class="wide" data-section="recurrencia">
<mat-card-header
><mat-card-title>Análisis de recurrencia</mat-card-title></mat-card-header
>
<mat-card-content>
<table class="plain">
<thead>
<tr>
<th>Horizonte</th>
<th>Probabilidad de recurrencia</th>
</tr>
</thead>
<tbody>
@for (p of rm.predictions; track p.years) {
<tr>
<td>{{ p.years | number: '1.0-1' }} {{ p.years === 1 ? 'año' : 'años' }}</td>
<td class="num">{{ p.p * 100 | number: '1.1-1' }} %</td>
</tr>
}
</tbody>
</table>
@if (recurrence.isLoading()) {
<app-loading what="las curvas de recurrencia" [figure]="true" />
} @else if (recurrence.value(); as s) {
<h3>Escenario clínico de la paciente</h3>
<ul class="scenarios">
@for (name of s.scenarios; track name) {
<li>{{ name }}</li>
}
</ul>
@for (f of s.figures; track f.title) {
<h4>{{ f.title }}</h4>
<app-plot [figure]="f.figure" [height]="340" />
} @empty {
<p class="muted">
Sus escenarios tienen menos recaídas de las necesarias para trazar curvas.
</p>
}
} @else if (recurrence.error()) {
<p class="muted" role="alert">No se pudo leer el informe del modelo.</p>
}
</mat-card-content>
</mat-card>
}
</div>
} @else if (loading()) {
<app-loading what="el expediente" />
+9
View File
@@ -79,3 +79,12 @@ mat-card-content {
tr.chosen td {
background: var(--mat-sys-surface-container);
}
.relation {
margin-top: 16px;
td small {
display: block;
color: var(--mat-sys-on-surface-variant);
font-size: 0.8em;
}
}
+86 -30
View File
@@ -21,7 +21,15 @@ import { code, EXT, ext, Fhir, label, resources } from '../fhir';
import { scenarioFigure } from '../gobernanza/figures';
import { CURP } from '../indicadores/follow-up';
import { name } from '../indicadores/measures';
import { byDeviation, headMap, METRIC_NAMES, ZONE_NAMES } from '../eeg-labels';
import {
BIOMARKER_NAMES,
byDeviation,
headMap,
METRIC_NAMES,
OUTCOME_NAMES,
ZONE_NAMES,
} from '../eeg-labels';
import type { Relation } from '../api/models/relation';
import { Figure, PALETTE, Plot } from '../plot';
import { Loading } from '../loading';
@@ -137,36 +145,58 @@ export class Paciente {
})),
}));
});
/** "Análisis de supervivencia": the curves of her clinical scenarios, from the report of
* the model version that scored her. */
protected readonly survival = resource({
params: () => {
const m = this.models().find((x) => x.scenarios.length && x.version);
return m ? { m, domain: this.domain() } : undefined;
},
loader: async ({ params: { m, domain } }) => {
const report = await this.api.invoke(readReport$Json, {
domain: domain as Domain,
name: m.model.replace(`${domain}.`, ''),
version: m.version,
report: 'interpretability',
});
const drawn = ((report?.['escenarios'] ?? []) as any[]).filter((e) =>
m.scenarios.includes(e.escenario),
);
return {
scenarios: m.scenarios,
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)',
/** "Análisis de supervivencia" and "Análisis de recurrencia": the curves of her clinical
* scenarios, from the report of the model version that scored her. */
protected readonly survival = this.analysis('survival');
protected readonly recurrence = this.analysis('recurrence');
protected readonly recurrenceModel = computed(() =>
this.models().find((m) => m.model.endsWith('.recurrence') && m.version),
);
private analysis(name: 'survival' | 'recurrence') {
return resource({
params: () => {
const m = this.models().find(
(x) => x.model === `${this.domain()}.${name}` && x.scenarios.length && x.version,
);
return m ? { m, domain: this.domain() } : undefined;
},
loader: async ({ params: { m, domain } }) => {
const report = await this.api.invoke(readReport$Json, {
domain: domain as Domain,
name,
version: m.version,
report: 'interpretability',
});
const mine = (all: any[]) => all.filter((e) => m.scenarios.includes(e.escenario));
if (name === 'recurrence') {
const r = (report?.['recurrencia'] ?? {}) as any;
return {
scenarios: m.scenarios,
figures: mine(r['escenarios'] ?? []).map((e) =>
scenarioFigure(
`${e.escenario} (n = ${e.n.toLocaleString('es-MX')}, recaídas = ${e.recaidas.toLocaleString('es-MX')})`,
e,
r['horizons_months'],
'Supervivencia libre de recaída',
),
),
};
}
return {
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)',
),
),
),
};
},
});
};
},
});
}
/** TEA: her latest ADOS-2 (an encounter whose observations are the catalog's
* `ados2.*` fields), item by item, and its totals. */
protected readonly ados2 = computed(() => {
@@ -247,6 +277,32 @@ export class Paciente {
(s) => s.z !== null && s.z !== undefined,
),
);
protected readonly biomarkerNames = BIOMARKER_NAMES;
protected readonly outcomeNames = OUTCOME_NAMES;
/** "Relación con el ADOS-2": her altered zones (|z| ≥ 2) with a clear association in the
* cohort (q < 0.05), clearest first, as the old summary showed them. */
protected readonly related = computed(() =>
(this.eeg.value()?.analysis?.relation ?? [])
.filter((f) => Math.abs(f.z) >= 2 && f.q !== null && f.q !== undefined && f.q < 0.05)
.sort((a, b) => (a.q ?? 1) - (b.q ?? 1)),
);
protected qText(q?: number | null): string {
return q === null || q === undefined ? '—' : q < 0.001 ? '< 0.001' : `= ${q.toFixed(3)}`;
}
protected observed(f: Relation): string {
if (f.observed === null || f.observed === undefined) return 'Sin dato';
if (f.kind === 'item')
return f.observed >= 1 ? `Alterado (${f.observed})` : 'Sin anormalidad (0)';
return `CSS ${f.observed}`;
}
/** Whether what she shows is what the model leans to (above or below one half). */
protected matches(f: Relation): string | undefined {
if (f.observed === null || f.observed === undefined) return undefined;
const present = f.kind === 'item' ? f.observed >= 1 : f.observed >= 8;
return present === f.probability >= 0.5
? 'Coincide con lo que el modelo esperaba'
: 'No coincide con lo que el modelo esperaba';
}
protected readonly zoneOrder = computed(() => byDeviation(this.zoned()?.zones ?? []));
protected readonly head = computed(() => headMap(this.zoned()?.electrodes ?? []));
protected readonly curve = computed<Figure>(() => {