diff --git a/src/app/app.ts b/src/app/app.ts index 50a8bfa..9f2123d 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -13,7 +13,7 @@ import { Auth } from './auth/auth'; export const DOMAINS: Record = { 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. */ diff --git a/src/app/indicadores/indicadores.ts b/src/app/indicadores/indicadores.ts index beec0a6..032b54f 100644 --- a/src/app/indicadores/indicadores.ts +++ b/src/app/indicadores/indicadores.ts @@ -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'; + } @else if (domain() === 'tea') { + + + + + } @else if (domain() === 'cama') { diff --git a/src/app/indicadores/tab-indicadores.html b/src/app/indicadores/tab-indicadores.html index b75f5e4..12362c8 100644 --- a/src/app/indicadores/tab-indicadores.html +++ b/src/app/indicadores/tab-indicadores.html @@ -32,6 +32,12 @@ } +@if (reports.error()) { + +} @if (page(); as pg) { @if (applied(); as period) {
diff --git a/src/app/indicadores/tab-indicadores.scss b/src/app/indicadores/tab-indicadores.scss index 31bbd11..1cb5d75 100644 --- a/src/app/indicadores/tab-indicadores.scss +++ b/src/app/indicadores/tab-indicadores.scss @@ -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; + } +} diff --git a/src/app/indicadores/tab-indicadores.ts b/src/app/indicadores/tab-indicadores.ts index 62b1042..f00806b 100644 --- a/src/app/indicadores/tab-indicadores.ts +++ b/src/app/indicadores/tab-indicadores.ts @@ -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 | 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; diff --git a/src/app/indicadores/tab-riesgos-tea.html b/src/app/indicadores/tab-riesgos-tea.html new file mode 100644 index 0000000..a034362 --- /dev/null +++ b/src/app/indicadores/tab-riesgos-tea.html @@ -0,0 +1,169 @@ +
+

Alteraciones de EEG relacionadas al TEA

+
+ + Fecha de corte + + + + Ventana de meses + + @for (m of [1, 3, 6, 12]; track m) { + {{ m }} {{ m === 1 ? 'mes' : 'meses' }} + } + + + + Estatus de EEG + + Todos + @for (s of eegStatuses | keyvalue; track s.key) { + {{ s.value }} + } + + + + Grupo de edad + + Todos + @for (a of ages(); track a) { + {{ ageLabel(a) }} + } + + + + Puntaje M-CHAT + + Todos + @for (b of mchatBands; track b.id) { + {{ b.label }} + } + + + + CSS ADOS-2 + + Todos + @for (l of cssLevels; track l.id) { + {{ l.label }} + } + + + + Estado del caso + + Todos + @for (c of cases | keyvalue; track c.key) { + {{ c.value }} + } + + + + Tipo de alteración + + Todas + @for (a of alterations(); track a) { + {{ alteration(a) }} + } + + + + Registros por página + + + +
+ + @if (loading()) { + + } @else { + @let s = summary(); +
+

EEG de los pacientes filtrados

+
+ {{ s.normal }} Normales + {{ s.abnormal }} Anormales + {{ s.none }} Sin EEG válido +
+ @if (s.alterations.length) { +
    + @for (a of s.alterations; track a[0]) { +
  • + {{ alteration(a[0]) }}: {{ a[1] }} +
  • + } +
+ } +
+ + + + + + + + + + + + + + + @for (r of shown(); track r.patient.id) { + + + + + + + + + + } @empty { + + + + } + +
PacienteGrupo de edadEstado del casoÚltimo EEGPuntaje M-CHATCSS ADOS-2Estatus de EEG
+ {{ + r.name + }} + {{ r.ageGroup ? ageLabel(r.ageGroup) : 'Sin dato' }}{{ cases[r.case] ?? r.case }}{{ r.lastEeg ?? '—' }}{{ r.mchat ?? '—' }}{{ r.css ?? '—' }}{{ eegStatuses[r.eegStatus] ?? r.eegStatus }}
Nadie en la lista con estos filtros.
+
+ + Página {{ pageIndex() + 1 }} de {{ pages() }} · {{ filtered().length }} pacientes + +
+ } +
diff --git a/src/app/indicadores/tab-riesgos-tea.scss b/src/app/indicadores/tab-riesgos-tea.scss new file mode 100644 index 0000000..d63c466 --- /dev/null +++ b/src/app/indicadores/tab-riesgos-tea.scss @@ -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; + } +} diff --git a/src/app/indicadores/tab-riesgos-tea.ts b/src/app/indicadores/tab-riesgos-tea.ts new file mode 100644 index 0000000..2cadbf0 --- /dev/null +++ b/src/app/indicadores/tab-riesgos-tea.ts @@ -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 = { + normal: 'Normal', + abnormal: 'Anormal', + no_valid_eeg: 'Sin EEG válido', +}; +const CASE: Record = { + 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(); + + 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(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(); + 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); + } +}