F2b: No evaluable carries the reason ported from the tea library

eeg-labels.ts maps each reason code to its Spanish label: the metric
reasons, the study reasons and one label per window reason. The metric
shows "No evaluable · <label>" in Resultado where it showed a dash, and
only when it has no result; a metric with a result keeps it. The
study's reasons show as a Motivos row in the EEG quality summary.
Unknown codes show as the code. The patient spec covers the mapping and
the reading of both extensions from FHIR.
This commit is contained in:
2026-12-03 13:56:48 -06:00
parent 98eda5bc28
commit cc3f6b3e0d
4 changed files with 114 additions and 7 deletions
+25
View File
@@ -43,3 +43,28 @@ export const OUTCOME_NAMES: Record<string, string> = {
ados2_item_22: 'Intereses repetitivos o conductas estereotipadas', ados2_item_22: 'Intereses repetitivos o conductas estereotipadas',
CSS: 'Puntuación de severidad (CSS)', CSS: 'Puntuación de severidad (CSS)',
}; };
export const REASON_NAMES: Record<string, string> = {
'no-n2': 'sin N2',
'no-n3': 'sin N3',
'few-wake-windows': 'pocas ventanas en vigilia',
'no-dominant-peak': 'sin ritmo dominante',
'no-sleep': 'sin sueño',
'few-electrodes': 'pocos electrodos',
'no-age': 'sin edad',
'age-out-of-range': 'edad fuera de la curva',
'no-exposure': 'sin minutos de exposición',
'invalid-eeg': 'EEG no válido',
'few-clean-minutes': 'pocos minutos limpios',
'triage-not-analyzable': 'triage no analizable',
'invalid-file': 'archivo no válido',
gap: 'hueco de grabación',
state: 'estado excluido',
'mixed-states': 'ventana entre dos estados',
muscle: 'músculo',
frozen: 'señal congelada',
};
export function reasonLabel(reason: string): string {
return REASON_NAMES[reason] ?? reason;
}
+8 -4
View File
@@ -7,8 +7,8 @@ import type {
RiskAssessment, RiskAssessment,
} from 'fhir/r4'; } from 'fhir/r4';
import { ados2Component, ados2Groups } from '../ados2'; import { ados2Component, ados2Groups } from '../ados2';
import { ZONE_NAMES } from '../eeg-labels'; import { reasonLabel, ZONE_NAMES } from '../eeg-labels';
import { code, CURP, ext, Fhir, label, resources } from '../fhir'; import { code, CURP, ext, extensions, Fhir, label, resources } from '../fhir';
export const TEA_STEPS = [ export const TEA_STEPS = [
{ code: 'mchat_only', label: 'M-CHAT' }, { code: 'mchat_only', label: 'M-CHAT' },
@@ -216,6 +216,7 @@ function metric(o: Observation) {
unit: o.valueQuantity?.unit, unit: o.valueQuantity?.unit,
z: ext(o, 'eeg-z')?.valueDecimal, z: ext(o, 'eeg-z')?.valueDecimal,
outside: ext(o, 'eeg-outside')?.valueInteger, outside: ext(o, 'eeg-outside')?.valueInteger,
reason: ext(o, 'eeg-reason')?.valueCode,
model: ext(o, 'eeg-model')?.valueString, model: ext(o, 'eeg-model')?.valueString,
sites: (o.component ?? []).map((site): Site => ({ sites: (o.component ?? []).map((site): Site => ({
name: code(site.code) ?? '', name: code(site.code) ?? '',
@@ -232,6 +233,7 @@ function study(report: DiagnosticReport, observations: Map<string | undefined, O
const results = (report.result ?? []) const results = (report.result ?? [])
.map((r) => observations.get(r.reference?.split('/').pop())) .map((r) => observations.get(r.reference?.split('/').pop()))
.filter((o): o is Observation => !!o); .filter((o): o is Observation => !!o);
const reasons = extensions(report, 'eeg-reason').flatMap((e) => e.valueCode ?? []);
return { return {
id: report.id, id: report.id,
date: shown(report.effectiveDateTime), date: shown(report.effectiveDateTime),
@@ -241,6 +243,7 @@ function study(report: DiagnosticReport, observations: Map<string | undefined, O
['Validez', shown(quality[code(report.conclusionCode?.[1]) ?? ''])], ['Validez', shown(quality[code(report.conclusionCode?.[1]) ?? ''])],
['Duración (min)', shown(ext(report, 'eeg-duration-min')?.valueDecimal)], ['Duración (min)', shown(ext(report, 'eeg-duration-min')?.valueDecimal)],
['Canales', shown(ext(report, 'eeg-channels')?.valueInteger)], ['Canales', shown(ext(report, 'eeg-channels')?.valueInteger)],
...(reasons.length ? [['Motivos', reasons.map(reasonLabel).join(' · ')]] : []),
], ],
checks: results checks: results
.filter((o) => o.code.coding?.[0]?.system?.endsWith('tea-eeg-check')) .filter((o) => o.code.coding?.[0]?.system?.endsWith('tea-eeg-check'))
@@ -266,8 +269,9 @@ export type Pair = {
export type Study = ReturnType<typeof study>; export type Study = ReturnType<typeof study>;
export function alteration(outside: number | undefined): string { export function alteration(outside: number | undefined, reason?: string): string {
return outside == null ? '—' : outside < 0 ? 'Bajo' : outside > 0 ? 'Alto' : 'En rango'; if (outside == null) return reason ? `No evaluable · ${reasonLabel(reason)}` : '—';
return outside < 0 ? 'Bajo' : outside > 0 ? 'Alto' : 'En rango';
} }
function associations( function associations(
+80 -2
View File
@@ -1,7 +1,16 @@
import type { Observation, Patient } from 'fhir/r4'; import type { Observation, Patient } from 'fhir/r4';
import { describe, expect, it } from 'vitest'; import { describe, expect, it } from 'vitest';
import { EXT } from '../fhir'; import { EXT, Fhir } from '../fhir';
import { identityRows, Metric, Pair, pairTitle, TeaStep, zoneLabel } from './tea-data'; import {
alteration,
identityRows,
loadTeaPatient,
Metric,
Pair,
pairTitle,
TeaStep,
zoneLabel,
} from './tea-data';
import { import {
ageNorm, ageNorm,
forest, forest,
@@ -28,6 +37,7 @@ const metric: Metric = {
model: 'tea.eeg-spindles-n2/1', model: 'tea.eeg-spindles-n2/1',
z: 0.3, z: 0.3,
outside: 0, outside: 0,
reason: undefined,
sites: [ sites: [
{ kind: 'zone', name: 'central', z: 2.4, outside: 1 }, { kind: 'zone', name: 'central', z: 2.4, outside: 1 },
{ kind: 'electrode', name: 'O1', z: -1.2, outside: 0 }, { kind: 'electrode', name: 'O1', z: -1.2, outside: 0 },
@@ -324,6 +334,74 @@ describe('Expediente TEA', () => {
expect(without?.blocks).toHaveLength(1); expect(without?.blocks).toHaveLength(1);
}); });
it('muestra "No evaluable" con el motivo donde antes había un guion', () => {
expect(alteration(undefined, 'no-n3')).toBe('No evaluable · sin N3');
expect(alteration(undefined, 'age-out-of-range')).toBe('No evaluable · edad fuera de la curva');
expect(alteration(undefined, 'unknown-code')).toBe('No evaluable · unknown-code');
expect(alteration(undefined)).toBe('—');
expect(alteration(1, 'no-n3')).toBe('Alto');
const unmeasured = { ...metric, z: undefined, outside: undefined, reason: 'invalid-eeg' };
const section = recordSections(
{ ...record, studies: [{ ...eeg, metrics: [unmeasured] }] },
new Map(),
).find((s) => s.title === 'Alteraciones');
expect(section?.blocks[0].fields).toEqual([
['z', '—'],
['Resultado', 'No evaluable · EEG no válido'],
]);
});
it('lee los motivos de la métrica y del estudio desde FHIR', async () => {
const reason = (valueCode: string) => ({ url: EXT + 'eeg-reason', valueCode });
const bundle = {
resourceType: 'Bundle',
type: 'searchset',
entry: [
{
search: { mode: 'match' },
resource: { resourceType: 'Patient', id: 'child' },
},
{
search: { mode: 'include' },
resource: {
resourceType: 'DiagnosticReport',
id: 'eeg-1',
status: 'final',
code: { coding: [{ code: 'eeg' }] },
effectiveDateTime: '2025-11-30',
conclusionCode: [{ coding: [{ code: 'bad' }] }, { coding: [{ code: 'not_valid' }] }],
extension: [reason('few-clean-minutes'), reason('triage-not-analyzable')],
result: [{ reference: 'Observation/n3' }],
},
},
{
search: { mode: 'include' },
resource: {
resourceType: 'Observation',
id: 'n3',
status: 'final',
code: {
coding: [
{
system: 'https://isssteleon.org/fhir/CodeSystem/tea-eeg-metric',
code: 'spindles_n3',
},
],
},
extension: [reason('no-n3')],
},
},
],
};
const fhir = { search: async () => bundle } as unknown as Fhir;
const { studies } = await loadTeaPatient(fhir, 'child');
expect(studies[0].metrics[0]).toMatchObject({ key: 'spindles_n3', reason: 'no-n3' });
expect(studies[0].summary).toContainEqual([
'Motivos',
'pocos minutos limpios · triage no analizable',
]);
});
it('exporta las secciones, tablas y figuras con un nombre sin identificador', () => { it('exporta las secciones, tablas y figuras con un nombre sin identificador', () => {
const sections = [ const sections = [
...recordSections(record, new Map()), ...recordSections(record, new Map()),
+1 -1
View File
@@ -71,7 +71,7 @@ export function recordSections(patient: TeaPatient, norms: ReadonlyMap<string, C
title: `${eeg.date} · ${m.title}`, title: `${eeg.date} · ${m.title}`,
fields: [ fields: [
['z', shown(m.z)], ['z', shown(m.z)],
['Resultado', alteration(m.outside)], ['Resultado', alteration(m.outside, m.reason)],
], ],
chart: m.sites.length chart: m.sites.length
? { title: 'Mapa de la cabeza', figure: headMap(m.sites) } ? { title: 'Mapa de la cabeza', figure: headMap(m.sites) }