TEA record: Zonas más afectadas (head map and zones by deviation); survival scenarios leave Gobernanza
This commit is contained in:
@@ -1065,6 +1065,14 @@
|
|||||||
"title": "Code",
|
"title": "Code",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"electrodes": {
|
||||||
|
"default": [],
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/Site"
|
||||||
|
},
|
||||||
|
"title": "Electrodes",
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
"median": {
|
"median": {
|
||||||
"anyOf": [
|
"anyOf": [
|
||||||
{
|
{
|
||||||
@@ -1134,6 +1142,14 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"title": "Z"
|
"title": "Z"
|
||||||
|
},
|
||||||
|
"zones": {
|
||||||
|
"default": [],
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/Site"
|
||||||
|
},
|
||||||
|
"title": "Zones",
|
||||||
|
"type": "array"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
@@ -1512,6 +1528,36 @@
|
|||||||
"title": "SignIn",
|
"title": "SignIn",
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
|
"Site": {
|
||||||
|
"properties": {
|
||||||
|
"site": {
|
||||||
|
"title": "Site",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
"title": "Value",
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"title": "Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"site",
|
||||||
|
"value",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "Site",
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
"Source": {
|
"Source": {
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"description": "One table, file set or API resource, copied as it is (dlt). Merged on the source's\nown primary key or `primary_key`; replaced whole when it has none.",
|
"description": "One table, file set or API resource, copied as it is (dlt). Merged on the source's\nown primary key or `primary_key`; replaced whole when it has none.",
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export type { Route } from './models/route';
|
|||||||
export type { RunRequest } from './models/run-request';
|
export type { RunRequest } from './models/run-request';
|
||||||
export type { SavedPipeline } from './models/saved-pipeline';
|
export type { SavedPipeline } from './models/saved-pipeline';
|
||||||
export type { SignIn } from './models/sign-in';
|
export type { SignIn } from './models/sign-in';
|
||||||
|
export type { Site } from './models/site';
|
||||||
export type { Source } from './models/source';
|
export type { Source } from './models/source';
|
||||||
export type { SourceRef } from './models/source-ref';
|
export type { SourceRef } from './models/source-ref';
|
||||||
export type { SourceType } from './models/source-type';
|
export type { SourceType } from './models/source-type';
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
/* Code generated by ng-openapi-gen DO NOT EDIT. */
|
/* Code generated by ng-openapi-gen DO NOT EDIT. */
|
||||||
|
|
||||||
|
import { Site } from '../models/site';
|
||||||
export interface Metric {
|
export interface Metric {
|
||||||
code: string;
|
code: string;
|
||||||
|
electrodes?: Array<Site>;
|
||||||
median?: (number | null);
|
median?: (number | null);
|
||||||
model: (string | null);
|
model: (string | null);
|
||||||
outside: (number | null);
|
outside: (number | null);
|
||||||
@@ -10,4 +12,5 @@ export interface Metric {
|
|||||||
p95?: (number | null);
|
p95?: (number | null);
|
||||||
value: number;
|
value: number;
|
||||||
z: (number | null);
|
z: (number | null);
|
||||||
|
zones?: Array<Site>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
/* Code generated by ng-openapi-gen DO NOT EDIT. */
|
||||||
|
|
||||||
|
export interface Site {
|
||||||
|
site: string;
|
||||||
|
value: number;
|
||||||
|
z: (number | null);
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
import type { Figure } from './plot';
|
||||||
|
|
||||||
|
/** The EEG metrics (models.tea.eeg.biomarkers.CODES), as the pages name them. */
|
||||||
|
export const METRIC_NAMES: Record<string, string> = {
|
||||||
|
posterior_rhythm: 'Ritmo posterior (Hz)',
|
||||||
|
spindles_n2: 'Husos de sueño N2 (por min)',
|
||||||
|
spindles_n3: 'Husos de sueño N3 (por min)',
|
||||||
|
paroxysmal_spikes: 'Picos paroxísticos (por min)',
|
||||||
|
anteroposterior_gradient: 'Gradiente anteroposterior',
|
||||||
|
};
|
||||||
|
|
||||||
|
/** The zones the metrics are summed over (models.tea.eeg.spindles.ZONES). */
|
||||||
|
export const ZONE_NAMES: Record<string, string> = {
|
||||||
|
frontal_left: 'Frontal izquierda',
|
||||||
|
frontal_right: 'Frontal derecha',
|
||||||
|
frontal_midline: 'Frontal media',
|
||||||
|
central: 'Central',
|
||||||
|
parietal: 'Parietal',
|
||||||
|
temporal_left: 'Temporal izquierda',
|
||||||
|
temporal_right: 'Temporal derecha',
|
||||||
|
occipital: 'Occipital',
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Where each electrode of the 10-20 system sits on a head seen from above (nose up). */
|
||||||
|
const AT: Record<string, [number, number]> = {
|
||||||
|
Fp1: [-0.31, 0.95], Fp2: [0.31, 0.95],
|
||||||
|
F7: [-0.81, 0.59], F3: [-0.4, 0.53], Fz: [0, 0.5], F4: [0.4, 0.53], F8: [0.81, 0.59],
|
||||||
|
T3: [-1, 0], C3: [-0.5, 0], Cz: [0, 0], C4: [0.5, 0], T4: [1, 0],
|
||||||
|
T5: [-0.81, -0.59], P3: [-0.4, -0.53], Pz: [0, -0.5], P4: [0.4, -0.53], T6: [0.81, -0.59],
|
||||||
|
O1: [-0.31, -0.95], O2: [0.31, -0.95],
|
||||||
|
}; // prettier-ignore
|
||||||
|
|
||||||
|
export interface Site {
|
||||||
|
site: string;
|
||||||
|
value: number;
|
||||||
|
z?: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Her electrodes on the head, coloured by how far each is from its age curve (z, blue
|
||||||
|
* below and red above), or by her own value where no curve scores electrodes. */
|
||||||
|
export function headMap(electrodes: Site[]): Figure {
|
||||||
|
const placed = electrodes.filter((e) => AT[e.site]);
|
||||||
|
const scored = placed.some((e) => e.z !== null && e.z !== undefined);
|
||||||
|
const colour = placed.map((e) => (scored ? (e.z ?? 0) : e.value));
|
||||||
|
const ring = Array.from({ length: 73 }, (_, i) => (i * 2 * Math.PI) / 72);
|
||||||
|
return {
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
x: ring.map((t) => 1.12 * Math.sin(t)),
|
||||||
|
y: ring.map((t) => 1.12 * Math.cos(t)),
|
||||||
|
mode: 'lines',
|
||||||
|
line: { color: '#9aa0a6', width: 1 },
|
||||||
|
hoverinfo: 'skip',
|
||||||
|
showlegend: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
x: [-0.12, 0, 0.12],
|
||||||
|
y: [1.1, 1.24, 1.1],
|
||||||
|
mode: 'lines',
|
||||||
|
line: { color: '#9aa0a6', width: 1 },
|
||||||
|
hoverinfo: 'skip',
|
||||||
|
showlegend: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
x: placed.map((e) => AT[e.site][0]),
|
||||||
|
y: placed.map((e) => AT[e.site][1]),
|
||||||
|
text: placed.map((e) => e.site),
|
||||||
|
customdata: colour,
|
||||||
|
mode: 'markers+text',
|
||||||
|
textposition: 'top center',
|
||||||
|
marker: {
|
||||||
|
size: 22,
|
||||||
|
color: colour,
|
||||||
|
colorscale: 'RdBu',
|
||||||
|
reversescale: true,
|
||||||
|
...(scored ? { cmin: -3, cmax: 3, cmid: 0 } : {}),
|
||||||
|
colorbar: { title: { text: scored ? 'z' : 'valor' }, thickness: 10 },
|
||||||
|
line: { color: '#ffffff', width: 1 },
|
||||||
|
},
|
||||||
|
hovertemplate: scored ? '%{text}: z = %{customdata:.2f}<extra></extra>'
|
||||||
|
: '%{text}: %{customdata:.3f}<extra></extra>', // prettier-ignore
|
||||||
|
showlegend: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
layout: {
|
||||||
|
xaxis: { visible: false, range: [-1.35, 1.35], scaleanchor: 'y' },
|
||||||
|
yaxis: { visible: false, range: [-1.25, 1.35] },
|
||||||
|
margin: { l: 10, r: 10, t: 10, b: 10 },
|
||||||
|
},
|
||||||
|
} as Figure;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The zones, most affected first: by how far from the age curve, else by value. */
|
||||||
|
export function byDeviation(zones: Site[]): Site[] {
|
||||||
|
const scored = zones.some((z) => z.z !== null && z.z !== undefined);
|
||||||
|
return [...zones].sort((a, b) =>
|
||||||
|
scored ? Math.abs(b.z ?? 0) - Math.abs(a.z ?? 0) : b.value - a.value,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -70,15 +70,7 @@ export function interpretabilityFigures(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Its clinical scenarios, those with enough deaths to draw.
|
// Its clinical scenarios are drawn in the patient record (Análisis de supervivencia).
|
||||||
...((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)',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
case 'subgroups':
|
case 'subgroups':
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { METRIC_NAMES } from '../eeg-labels';
|
||||||
import { HttpErrorResponse } from '@angular/common/http';
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
import { DatePipe, DecimalPipe } from '@angular/common';
|
import { DatePipe, DecimalPipe } from '@angular/common';
|
||||||
import { Component, computed, inject, input, resource, signal } from '@angular/core';
|
import { Component, computed, inject, input, resource, signal } from '@angular/core';
|
||||||
@@ -93,13 +94,7 @@ export class Gobernanza {
|
|||||||
params: () => this.eeg(),
|
params: () => this.eeg(),
|
||||||
loader: ({ params }) => this.api.invoke(study, { eeg_id: params }),
|
loader: ({ params }) => this.api.invoke(study, { eeg_id: params }),
|
||||||
});
|
});
|
||||||
protected readonly metricNames: Record<string, string> = {
|
protected readonly metricNames = METRIC_NAMES;
|
||||||
posterior_rhythm: 'Ritmo posterior (Hz)',
|
|
||||||
spindles_n2: 'Husos de sueño N2 (por min)',
|
|
||||||
spindles_n3: 'Husos de sueño N3 (por min)',
|
|
||||||
paroxysmal_spikes: 'Picos paroxísticos (por min)',
|
|
||||||
anteroposterior_gradient: 'Gradiente anteroposterior',
|
|
||||||
};
|
|
||||||
protected readonly asOf = signal('');
|
protected readonly asOf = signal('');
|
||||||
protected readonly run = signal<{ kind: string; status: string } | undefined>(undefined);
|
protected readonly run = signal<{ kind: string; status: string } | undefined>(undefined);
|
||||||
protected readonly message = signal('');
|
protected readonly message = signal('');
|
||||||
|
|||||||
@@ -202,8 +202,18 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@for (m of alterations(); track m.code) {
|
@for (m of alterations(); track m.code) {
|
||||||
<tr>
|
<tr [class.chosen]="zoned()?.code === m.code">
|
||||||
<td>{{ m.code }}</td>
|
<td>
|
||||||
|
<button
|
||||||
|
mat-button
|
||||||
|
type="button"
|
||||||
|
class="metric"
|
||||||
|
[attr.aria-expanded]="zoned()?.code === m.code"
|
||||||
|
(click)="zone.set(zoned()?.code === m.code ? undefined : m.code)"
|
||||||
|
>
|
||||||
|
{{ metricNames[m.code] ?? m.code }}
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
<td>{{ m.value | number: '1.0-3' }}</td>
|
<td>{{ m.value | number: '1.0-3' }}</td>
|
||||||
<td>{{ m.p5 | number: '1.0-3' }} – {{ m.p95 | number: '1.0-3' }}</td>
|
<td>{{ m.p5 | number: '1.0-3' }} – {{ m.p95 | number: '1.0-3' }}</td>
|
||||||
<td>{{ m.median | number: '1.0-3' }}</td>
|
<td>{{ m.median | number: '1.0-3' }}</td>
|
||||||
@@ -213,6 +223,39 @@
|
|||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<p class="muted">Elija una alteración para ver sus zonas más afectadas.</p>
|
||||||
|
@if (zoned(); as z) {
|
||||||
|
<section class="zones" aria-label="Zonas más afectadas">
|
||||||
|
<h3>Zonas más afectadas</h3>
|
||||||
|
<p class="muted">
|
||||||
|
{{ metricNames[z.code] ?? z.code }} ·
|
||||||
|
{{
|
||||||
|
zonesScored()
|
||||||
|
? 'desviación de cada zona frente a su norma por edad'
|
||||||
|
: 'valor de cada zona (sin norma por edad por zona)'
|
||||||
|
}}
|
||||||
|
</p>
|
||||||
|
@if (z.electrodes.length) {
|
||||||
|
<app-plot [figure]="head()" [height]="280" />
|
||||||
|
}
|
||||||
|
@if (z.zones.length) {
|
||||||
|
<ol class="regions" aria-label="Zonas ordenadas por desviación">
|
||||||
|
@for (r of zoneOrder(); track r.site) {
|
||||||
|
<li [class.marked]="(r.z ?? 0) >= 2 || (r.z ?? 0) <= -2">
|
||||||
|
<span>{{ zoneNames[r.site] ?? r.site }}</span>
|
||||||
|
<span>{{
|
||||||
|
r.z !== null && r.z !== undefined
|
||||||
|
? 'z = ' + (r.z | number: '1.1-2')
|
||||||
|
: (r.value | number: '1.0-3')
|
||||||
|
}}</span>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ol>
|
||||||
|
} @else if (!z.electrodes.length) {
|
||||||
|
<p class="muted">Esta métrica no se mide por zona.</p>
|
||||||
|
}
|
||||||
|
</section>
|
||||||
|
}
|
||||||
} @else {
|
} @else {
|
||||||
<p>Sin alteraciones: todas sus métricas están dentro de la norma por edad.</p>
|
<p>Sin alteraciones: todas sus métricas están dentro de la norma por edad.</p>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,3 +56,26 @@ mat-card-content {
|
|||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
gap: 16px;
|
gap: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.zones {
|
||||||
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
.regions {
|
||||||
|
list-style: none;
|
||||||
|
margin: 8px 0 0;
|
||||||
|
padding: 0;
|
||||||
|
max-width: 420px;
|
||||||
|
li {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-bottom: 1px solid var(--mat-sys-outline-variant);
|
||||||
|
}
|
||||||
|
li.marked {
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--mat-sys-error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tr.chosen td {
|
||||||
|
background: var(--mat-sys-surface-container);
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import { code, EXT, ext, Fhir, label, resources } from '../fhir';
|
|||||||
import { scenarioFigure } from '../gobernanza/figures';
|
import { scenarioFigure } from '../gobernanza/figures';
|
||||||
import { CURP } from '../indicadores/follow-up';
|
import { CURP } from '../indicadores/follow-up';
|
||||||
import { name } from '../indicadores/measures';
|
import { name } from '../indicadores/measures';
|
||||||
|
import { byDeviation, headMap, METRIC_NAMES, ZONE_NAMES } from '../eeg-labels';
|
||||||
import { Figure, PALETTE, Plot } from '../plot';
|
import { Figure, PALETTE, Plot } from '../plot';
|
||||||
import { Loading } from '../loading';
|
import { Loading } from '../loading';
|
||||||
|
|
||||||
@@ -233,6 +234,21 @@ export class Paciente {
|
|||||||
(this.eeg.value()?.analysis?.metrics ?? []).some((m) => m.z !== null && m.z !== undefined),
|
(this.eeg.value()?.analysis?.metrics ?? []).some((m) => m.z !== null && m.z !== undefined),
|
||||||
);
|
);
|
||||||
protected readonly shown = signal<string | undefined>(undefined);
|
protected readonly shown = signal<string | undefined>(undefined);
|
||||||
|
protected readonly metricNames = METRIC_NAMES;
|
||||||
|
protected readonly zoneNames = ZONE_NAMES;
|
||||||
|
/** "Zonas más afectadas": the alteration chosen, its zones and electrodes. */
|
||||||
|
protected readonly zone = signal<string | undefined>(undefined);
|
||||||
|
protected readonly zoned = computed(() => {
|
||||||
|
const m = this.alterations().find((a) => a.code === this.zone());
|
||||||
|
return m ? { code: m.code, zones: m.zones ?? [], electrodes: m.electrodes ?? [] } : undefined;
|
||||||
|
});
|
||||||
|
protected readonly zonesScored = computed(() =>
|
||||||
|
[...(this.zoned()?.zones ?? []), ...(this.zoned()?.electrodes ?? [])].some(
|
||||||
|
(s) => s.z !== null && s.z !== undefined,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
protected readonly zoneOrder = computed(() => byDeviation(this.zoned()?.zones ?? []));
|
||||||
|
protected readonly head = computed(() => headMap(this.zoned()?.electrodes ?? []));
|
||||||
protected readonly curve = computed<Figure>(() => {
|
protected readonly curve = computed<Figure>(() => {
|
||||||
const models = this.models().filter((m) => m.predictions.length > 1);
|
const models = this.models().filter((m) => m.predictions.length > 1);
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user