TEA Análisis de Riesgo as the old page: its filters, the EEG summary of the filtered children and their list; the domain's full name; reports that fail to load can be retried

This commit is contained in:
Roberto Treviño
2026-11-28 10:47:22 -06:00
parent aeb2d4ec84
commit cb0403affb
8 changed files with 464 additions and 7 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ import { Auth } from './auth/auth';
export const DOMAINS: Record<Domain, string> = {
cacu: 'Cáncer cervicouterino',
cama: 'Cáncer de mama',
tea: 'TEA',
tea: 'Trastorno del espectro autista',
};
/** The shell: header (logo, the domain's title and switcher, or the section), page, footer. */
+8
View File
@@ -6,6 +6,7 @@ import { Fhir, resources } from '../fhir';
import { TabDefiniciones } from './tab-definiciones';
import { TabIndicadores } from './tab-indicadores';
import { TabRiesgos } from './tab-riesgos';
import { TabRiesgosTea } from './tab-riesgos-tea';
import { TabSeguimiento } from './tab-seguimiento';
import { TabTrazabilidad } from './tab-trazabilidad';
import { Loading } from '../loading';
@@ -19,6 +20,7 @@ import { Loading } from '../loading';
TabIndicadores,
TabTrazabilidad,
TabRiesgos,
TabRiesgosTea,
TabSeguimiento,
TabDefiniciones,
],
@@ -48,6 +50,12 @@ import { Loading } from '../loading';
<app-tab-riesgos [domain]="domain()" />
</ng-template>
</mat-tab>
} @else if (domain() === 'tea') {
<mat-tab label="Análisis de Riesgo">
<ng-template matTabContent>
<app-tab-riesgos-tea [domain]="domain()" />
</ng-template>
</mat-tab>
} @else if (domain() === 'cama') {
<mat-tab label="Análisis de riesgos">
<ng-template matTabContent>
+6
View File
@@ -32,6 +32,12 @@
<app-loading what="los indicadores" text="Calculando los indicadores…" />
}
@if (reports.error()) {
<div class="load-error" role="alert">
<p>No se pudieron leer los indicadores del periodo. Vuelve a intentar.</p>
<button mat-stroked-button (click)="reports.reload()">Reintentar</button>
</div>
}
@if (page(); as pg) {
@if (applied(); as period) {
<section class="card opportunity" aria-labelledby="opportunity-title">
+14
View File
@@ -283,3 +283,17 @@ h2.box-subtitle {
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
}
.load-error {
align-items: center;
border: 1px solid var(--color-border);
border-radius: 8px;
display: flex;
gap: 16px;
margin-bottom: 16px;
padding: 12px 16px;
p {
margin: 0;
}
}
+10 -6
View File
@@ -126,6 +126,12 @@ export class TabIndicadores {
},
});
/** The period's readings; none while they load or when reading them failed (an errored
* resource throws on `value()`). */
protected loaded(): Map<string, Reading | undefined> | undefined {
return this.reports.hasValue() ? this.reports.value() : undefined;
}
constructor() {
effect(() => {
const latest = this.latest.value();
@@ -139,7 +145,7 @@ export class TabIndicadores {
protected readonly label = periodLabel;
protected readonly strataNames = STRATA;
protected r(m: Measure): Reading | undefined {
return this.reports.value()?.get(m.name!);
return this.loaded()?.get(m.name!);
}
protected score(m: Measure): string {
return formatScore(m, this.r(m));
@@ -166,9 +172,7 @@ export class TabIndicadores {
/** Each clinical card's figures, built once per loaded period. */
protected readonly figureSets = computed(
() =>
new Map(
this.clinical().map((m) => [m.name!, this.build(m, this.reports.value()?.get(m.name!))]),
),
new Map(this.clinical().map((m) => [m.name!, this.build(m, this.loaded()?.get(m.name!))])),
);
/** A clinical card's figures: the overall split, then one per stratum. */
@@ -192,7 +196,7 @@ export class TabIndicadores {
/** A measure's reading in the applied period, by code. */
protected rd(code: string): Reading | undefined {
return this.reports.value()?.get(code);
return this.loaded()?.get(code);
}
protected kpi(code: string): Measure | undefined {
return this.byName().get(code);
@@ -220,7 +224,7 @@ export class TabIndicadores {
}
/** TEA's summary of the period: its numbers from the measures (none: no summary). */
protected readonly teaSummary = computed(() => {
const rd = (c: string) => this.reports.value()?.get(c);
const rd = (c: string) => this.loaded()?.get(c);
const status = rd('M28_CASOS_POR_ESTADO');
if (!status) return undefined;
const n = (r: Reading | undefined, pop: string) => r?.populations[pop] ?? 0;
+169
View File
@@ -0,0 +1,169 @@
<section class="card risk-tea" aria-labelledby="tea-risk-title">
<h2 id="tea-risk-title" class="risk-title">Alteraciones de EEG relacionadas al TEA</h2>
<div class="filters">
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<mat-label>Fecha de corte</mat-label>
<input matInput type="date" [ngModel]="cutoff()" (ngModelChange)="cutoff.set($event)" />
</mat-form-field>
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<mat-label>Ventana de meses</mat-label>
<mat-select [value]="window()" (selectionChange)="window.set($event.value)">
@for (m of [1, 3, 6, 12]; track m) {
<mat-option [value]="m">{{ m }} {{ m === 1 ? 'mes' : 'meses' }}</mat-option>
}
</mat-select>
</mat-form-field>
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<mat-label>Estatus de EEG</mat-label>
<mat-select [value]="eeg()" (selectionChange)="setFilter(eeg.set.bind(eeg), $event.value)">
<mat-option value="">Todos</mat-option>
@for (s of eegStatuses | keyvalue; track s.key) {
<mat-option [value]="s.key">{{ s.value }}</mat-option>
}
</mat-select>
</mat-form-field>
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<mat-label>Grupo de edad</mat-label>
<mat-select [value]="age()" (selectionChange)="setFilter(age.set.bind(age), $event.value)">
<mat-option value="">Todos</mat-option>
@for (a of ages(); track a) {
<mat-option [value]="a">{{ ageLabel(a) }}</mat-option>
}
</mat-select>
</mat-form-field>
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<mat-label>Puntaje M-CHAT</mat-label>
<mat-select
[value]="mchat()"
(selectionChange)="setFilter(mchat.set.bind(mchat), $event.value)"
>
<mat-option value="">Todos</mat-option>
@for (b of mchatBands; track b.id) {
<mat-option [value]="b.id">{{ b.label }}</mat-option>
}
</mat-select>
</mat-form-field>
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<mat-label>CSS ADOS-2</mat-label>
<mat-select [value]="css()" (selectionChange)="setFilter(css.set.bind(css), $event.value)">
<mat-option value="">Todos</mat-option>
@for (l of cssLevels; track l.id) {
<mat-option [value]="l.id">{{ l.label }}</mat-option>
}
</mat-select>
</mat-form-field>
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<mat-label>Estado del caso</mat-label>
<mat-select
[value]="caseState()"
(selectionChange)="setFilter(caseState.set.bind(caseState), $event.value)"
>
<mat-option value="">Todos</mat-option>
@for (c of cases | keyvalue; track c.key) {
<mat-option [value]="c.key">{{ c.value }}</mat-option>
}
</mat-select>
</mat-form-field>
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<mat-label>Tipo de alteración</mat-label>
<mat-select
[value]="altered()"
(selectionChange)="setFilter(altered.set.bind(altered), $event.value)"
>
<mat-option value="">Todas</mat-option>
@for (a of alterations(); track a) {
<mat-option [value]="a">{{ alteration(a) }}</mat-option>
}
</mat-select>
</mat-form-field>
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="narrow">
<mat-label>Registros por página</mat-label>
<input
matInput
type="number"
min="10"
max="200"
[ngModel]="size()"
(ngModelChange)="size.set(+$event || 50); pageIndex.set(0)"
/>
</mat-form-field>
<button mat-stroked-button (click)="consult()">Consultar</button>
</div>
@if (loading()) {
<app-loading what="el seguimiento" />
} @else {
@let s = summary();
<div class="eeg-summary" aria-label="EEG de los pacientes filtrados">
<h3>EEG de los pacientes filtrados</h3>
<div class="counts">
<span
><strong>{{ s.normal }}</strong> Normales</span
>
<span
><strong>{{ s.abnormal }}</strong> Anormales</span
>
<span
><strong>{{ s.none }}</strong> Sin EEG válido</span
>
</div>
@if (s.alterations.length) {
<ul class="by-alteration">
@for (a of s.alterations; track a[0]) {
<li>
{{ alteration(a[0]) }}: <strong>{{ a[1] }}</strong>
</li>
}
</ul>
}
</div>
<table class="worklist">
<thead>
<tr>
<th>Paciente</th>
<th>Grupo de edad</th>
<th>Estado del caso</th>
<th>Último EEG</th>
<th class="num">Puntaje M-CHAT</th>
<th class="num">CSS ADOS-2</th>
<th>Estatus de EEG</th>
</tr>
</thead>
<tbody>
@for (r of shown(); track r.patient.id) {
<tr>
<td>
<a [routerLink]="['/indicadores', domain(), 'pacientes', r.patient.id]">{{
r.name
}}</a>
</td>
<td>{{ r.ageGroup ? ageLabel(r.ageGroup) : 'Sin dato' }}</td>
<td>{{ cases[r.case] ?? r.case }}</td>
<td>{{ r.lastEeg ?? '—' }}</td>
<td class="num">{{ r.mchat ?? '—' }}</td>
<td class="num">{{ r.css ?? '—' }}</td>
<td>{{ eegStatuses[r.eegStatus] ?? r.eegStatus }}</td>
</tr>
} @empty {
<tr>
<td colspan="7" class="muted">Nadie en la lista con estos filtros.</td>
</tr>
}
</tbody>
</table>
<div class="pager">
<button mat-button [disabled]="pageIndex() === 0" (click)="pageIndex.set(pageIndex() - 1)">
Anterior
</button>
<span>Página {{ pageIndex() + 1 }} de {{ pages() }} · {{ filtered().length }} pacientes</span>
<button
mat-button
[disabled]="pageIndex() + 1 >= pages()"
(click)="pageIndex.set(pageIndex() + 1)"
>
Siguiente
</button>
</div>
}
</section>
+80
View File
@@ -0,0 +1,80 @@
.risk-tea {
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: 8px;
margin-top: 24px;
padding: 16px;
}
.risk-title {
font-family: var(--font-heading);
font-size: 24px;
font-weight: 700;
margin: 0 0 16px;
}
.filters {
align-items: center;
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
.narrow {
width: 160px;
}
}
.eeg-summary {
border: 1px solid var(--color-border);
border-radius: 8px;
margin-bottom: 16px;
padding: 12px 16px;
h3 {
font-size: 16px;
font-weight: 500;
margin: 0 0 8px;
}
.counts {
display: flex;
flex-wrap: wrap;
gap: 24px;
}
.by-alteration {
columns: 2;
margin: 8px 0 0;
padding-left: 18px;
}
}
.pager {
align-items: center;
display: flex;
gap: 12px;
justify-content: flex-end;
margin-top: 8px;
}
.worklist {
border-collapse: collapse;
width: 100%;
th,
td {
border-bottom: 1px solid var(--color-border);
padding: 8px 10px;
text-align: left;
}
th {
font-size: 14px;
font-weight: 600;
}
.num {
text-align: right;
}
}
+176
View File
@@ -0,0 +1,176 @@
import { KeyValuePipe } from '@angular/common';
import { Component, computed, inject, input, resource, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { RouterLink } from '@angular/router';
import type { Patient } from 'fhir/r4';
import { EXT, Fhir, resources } from '../fhir';
import { Loading } from '../loading';
import { ageLabel } from './figures';
import { name } from './measures';
/** One child on TEA's list, as the list shows her (core.tea.follow_up). */
export interface TeaRow {
patient: Patient;
name: string;
ageGroup: string;
case: string;
status: string;
eegStatus: string;
alterations: string[];
lastEeg?: string;
mchat?: number;
css?: number;
}
const has = (p: Patient, n: string) => (p.extension ?? []).filter((e) => e.url === EXT + n);
export function teaRow(p: Patient): TeaRow {
const coded = (n: string) => has(p, n)[0]?.valueCoding?.code ?? '';
return {
patient: p,
name: p.name?.[0]?.text ?? (p.id ?? '').slice(0, 8),
ageGroup: has(p, 'tea-age-group')[0]?.valueString ?? '',
case: coded('tea-case'),
status: coded('follow-up-status'),
eegStatus: coded('tea-eeg-status'),
alterations: has(p, 'tea-eeg-alteration').map((e) => e.valueCoding?.code ?? ''),
lastEeg: has(p, 'tea-last-eeg')[0]?.valueDate,
mchat: has(p, 'mchat-score')[0]?.valueInteger,
css: has(p, 'ados2-css')[0]?.valueInteger,
};
}
/** M-CHAT-R risk bands and ADOS-2 CSS levels, as the filters offer them. */
const MCHAT = [
{ id: 'low', label: 'Bajo (0 a 2)', test: (v: number) => v <= 2 },
{ id: 'medium', label: 'Medio (3 a 7)', test: (v: number) => v >= 3 && v <= 7 },
{ id: 'high', label: 'Alto (8 a 20)', test: (v: number) => v >= 8 },
];
const CSS = [
{ id: 'minimal', label: 'Mínimo (1 a 2)', test: (v: number) => v <= 2 },
{ id: 'low', label: 'Bajo (3 a 4)', test: (v: number) => v >= 3 && v <= 4 },
{ id: 'moderate', label: 'Moderado (5 a 7)', test: (v: number) => v >= 5 && v <= 7 },
{ id: 'high', label: 'Alto (8 a 10)', test: (v: number) => v >= 8 },
];
const EEG_STATUS: Record<string, string> = {
normal: 'Normal',
abnormal: 'Anormal',
no_valid_eeg: 'Sin EEG válido',
};
const CASE: Record<string, string> = {
confirmed: 'Diagnóstico confirmado',
in_process: 'En proceso',
not_confirmed: 'Sin TEA',
};
/** `theta_power:above` → "theta_power (aumentado)". */
export const alteration = (a: string) =>
a.replace(/:(above|below)$/, (_, s) => (s === 'above' ? ' (aumentado)' : ' (disminuido)'));
/** "Análisis de Riesgo" for TEA: the children active in the window, what their EEGs show,
* filtered as the old page filtered them. */
@Component({
selector: 'app-tab-riesgos-tea',
imports: [
FormsModule,
KeyValuePipe,
Loading,
MatButtonModule,
MatFormFieldModule,
MatInputModule,
MatSelectModule,
RouterLink,
],
templateUrl: './tab-riesgos-tea.html',
styleUrls: ['./tab-riesgos.scss', './tab-riesgos-tea.scss'],
})
export class TabRiesgosTea {
private readonly fhir = inject(Fhir);
readonly domain = input.required<string>();
protected readonly cutoff = signal('');
protected readonly window = signal(3);
protected readonly eeg = signal('');
protected readonly age = signal('');
protected readonly mchat = signal('');
protected readonly css = signal('');
protected readonly caseState = signal('');
protected readonly altered = signal('');
protected readonly size = signal(50);
protected readonly pageIndex = signal(0);
/** The query as last asked for ("Consultar"). */
private readonly asked = signal({ cutoff: '', window: 3 });
protected readonly mchatBands = MCHAT;
protected readonly cssLevels = CSS;
protected readonly eegStatuses = EEG_STATUS;
protected readonly cases = CASE;
protected readonly label = name;
protected readonly ageLabel = ageLabel;
protected readonly alteration = alteration;
private readonly list = resource({
params: () => ({ domain: this.domain(), ...this.asked() }),
loader: async ({ params: { domain, cutoff, window } }) => {
const pages = await this.fhir.all(domain, 'Patient', {
'follow-up-window': window,
...(cutoff ? { 'follow-up-cutoff': cutoff } : {}),
_count: 200,
});
return resources<Patient>(pages, 'Patient').map(teaRow);
},
});
protected readonly loading = computed(() => this.list.isLoading());
protected readonly all = computed(() => this.list.value() ?? []);
protected readonly ages = computed(() => [...new Set(this.all().map((r) => r.ageGroup))].sort());
protected readonly alterations = computed(() =>
[...new Set(this.all().flatMap((r) => r.alterations))].sort(),
);
/** The children the filters keep. */
protected readonly filtered = computed(() => {
const band = MCHAT.find((b) => b.id === this.mchat());
const level = CSS.find((l) => l.id === this.css());
return this.all().filter(
(r) =>
(!this.eeg() || r.eegStatus === this.eeg()) &&
(!this.age() || r.ageGroup === this.age()) &&
(!band || (r.mchat !== undefined && band.test(r.mchat))) &&
(!level || (r.css !== undefined && level.test(r.css))) &&
(!this.caseState() || r.case === this.caseState()) &&
(!this.altered() || r.alterations.includes(this.altered())),
);
});
protected readonly shown = computed(() =>
this.filtered().slice(this.pageIndex() * this.size(), (this.pageIndex() + 1) * this.size()),
);
protected readonly pages = computed(() =>
Math.max(1, Math.ceil(this.filtered().length / this.size())),
);
/** "EEG de los pacientes filtrados": how many normal, abnormal, without one, by alteration. */
protected readonly summary = computed(() => {
const rows = this.filtered();
const count = (s: string) => rows.filter((r) => r.eegStatus === s).length;
const by = new Map<string, number>();
for (const r of rows) for (const a of r.alterations) by.set(a, (by.get(a) ?? 0) + 1);
return {
normal: count('normal'),
abnormal: count('abnormal'),
none: count('no_valid_eeg'),
alterations: [...by.entries()].sort((a, b) => b[1] - a[1]),
};
});
protected consult(): void {
this.pageIndex.set(0);
this.asked.set({ cutoff: this.cutoff(), window: this.window() });
}
protected setFilter(set: (v: string) => void, value: string): void {
set(value);
this.pageIndex.set(0);
}
}