diff --git a/src/app/ados2.spec.ts b/src/app/ados2.spec.ts new file mode 100644 index 0000000..5269e99 --- /dev/null +++ b/src/app/ados2.spec.ts @@ -0,0 +1,100 @@ +import type { Observation, ObservationComponent } from 'fhir/r4'; +import { describe, expect, it } from 'vitest'; +import { ados2Component, ados2Groups } from './ados2'; +import { EXT } from './fhir'; + +function item( + field: string, + domain: string, + subdomain: string, + code: string, + title: string, + value?: number, +): ObservationComponent { + return { + code: { + coding: [{ code: `ados2.${field}` }, { code, display: title }], + text: title, + }, + extension: [ + { url: EXT + 'ados2-domain', valueCoding: { code: domain[0], display: domain } }, + { url: EXT + 'ados2-subdomain', valueCoding: { code: subdomain, display: subdomain } }, + ], + valueQuantity: value == null ? undefined : { value }, + }; +} + +const AS = 'Afectación social (AS)'; +const CRR = 'Comportamiento restringido y repetitivo (CRR)'; + +const observation: Observation = { + resourceType: 'Observation', + status: 'final', + code: { coding: [{ code: 'ados2' }] }, + component: [ + { code: { coding: [{ code: 'ados2.module' }] }, valueCodeableConcept: { text: 'Módulo 1' } }, + item('pointing', AS, 'Comunicación', 'A-7', 'Señalar', 2), + item('gestures', AS, 'Comunicación', 'A-8', 'Gestos', 1), + item( + 'unusual_eye_contact', + AS, + 'Interacción social recíproca', + 'B-1', + 'Contacto visual inusual', + ), + item( + 'intonation', + CRR, + 'Comportamientos restringidos y repetitivos', + 'A-3', + 'Entonación de las vocalizaciones o verbalizaciones', + 3, + ), + { code: { coding: [{ code: 'ados2.response_to_name' }] } }, + ], +}; + +describe('Ítems del ADOS-2', () => { + it('agrupa los ítems del módulo por dominio y subdominio en su orden', () => { + expect(ados2Groups(observation)).toEqual([ + { + domain: AS, + subdomains: [ + { + subdomain: 'Comunicación', + items: [ + { code: 'A-7', title: 'Señalar', score: 2 }, + { code: 'A-8', title: 'Gestos', score: 1 }, + ], + }, + { + subdomain: 'Interacción social recíproca', + items: [{ code: 'B-1', title: 'Contacto visual inusual', score: undefined }], + }, + ], + }, + { + domain: CRR, + subdomains: [ + { + subdomain: 'Comportamientos restringidos y repetitivos', + items: [ + { + code: 'A-3', + title: 'Entonación de las vocalizaciones o verbalizaciones', + score: 3, + }, + ], + }, + ], + }, + ]); + expect(ados2Groups(undefined)).toEqual([]); + }); + + it('encuentra el ítem de una asociación por su número', () => { + expect(ados2Component(observation, 2)?.code.text).toBe('Señalar'); + expect(ados2Component(observation, 8)?.code.coding?.[0].code).toBe('ados2.response_to_name'); + expect(ados2Component(observation, 0)).toBeUndefined(); + }); +}); diff --git a/src/app/ados2.ts b/src/app/ados2.ts new file mode 100644 index 0000000..657fabb --- /dev/null +++ b/src/app/ados2.ts @@ -0,0 +1,82 @@ +import type { Observation, ObservationComponent } from 'fhir/r4'; +import { code, ext } from './fhir'; + +export const ADOS2_ITEMS = [ + 'vocalization_directed', + 'pointing', + 'gestures', + 'unusual_eye_contact', + 'facial_expressions', + 'gaze_integration', + 'shared_enjoyment', + 'response_to_name', + 'ignoring', + 'requesting', + 'showing', + 'joint_attention_initiation', + 'joint_attention_response', + 'social_overtures_quality', + 'social_overtures_caregiver', + 'reciprocal_communication', + 'rapport_quality', + 'intonation', + 'stereotyped_language', + 'unusual_sensory_interest', + 'hand_finger_mannerisms', + 'repetitive_interests', +]; + +export interface Ados2Item { + code: string; + title: string; + score?: number; +} + +export interface Ados2Subdomain { + subdomain: string; + items: Ados2Item[]; +} + +export interface Ados2Domain { + domain: string; + subdomains: Ados2Subdomain[]; +} + +function coded(component: ObservationComponent, name: string): string { + const coding = ext(component, name)?.valueCoding; + return coding?.display ?? coding?.code ?? ''; +} + +export function ados2Groups(observation: Observation | undefined): Ados2Domain[] { + const groups: Ados2Domain[] = []; + for (const component of observation?.component ?? []) { + const item = component.code.coding?.[1]; + if (!ext(component, 'ados2-domain') || !item?.code) continue; + const domain = coded(component, 'ados2-domain'); + const subdomain = coded(component, 'ados2-subdomain'); + let group = groups.at(-1); + if (!group || group.domain !== domain) { + group = { domain, subdomains: [] }; + groups.push(group); + } + let sub = group.subdomains.at(-1); + if (!sub || sub.subdomain !== subdomain) { + sub = { subdomain, items: [] }; + group.subdomains.push(sub); + } + sub.items.push({ + code: item.code, + title: component.code.text ?? item.display ?? item.code, + score: component.valueQuantity?.value, + }); + } + return groups; +} + +export function ados2Component( + observation: Observation | undefined, + number: number, +): ObservationComponent | undefined { + const field = ADOS2_ITEMS[number - 1]; + return observation?.component?.find((c) => field && code(c.code) === `ados2.${field}`); +} diff --git a/src/app/indicadores/follow-up.ts b/src/app/indicadores/follow-up.ts index 5c7684b..e083bbe 100644 --- a/src/app/indicadores/follow-up.ts +++ b/src/app/indicadores/follow-up.ts @@ -1,4 +1,5 @@ import type { Bundle, DiagnosticReport, Observation, Patient, RiskAssessment } from 'fhir/r4'; +import { ados2Component, ados2Groups } from '../ados2'; import { code, ext, label, resources } from '../fhir'; /** One row of the follow-up list: what the list shows of a patient at the cut-off. */ @@ -212,31 +213,6 @@ export const TEA_STEPS = [ { code: 'eeg', label: 'EEG' }, ] as const; -const ADOS2_ITEMS = [ - 'vocalization_directed', - 'pointing', - 'gestures', - 'unusual_eye_contact', - 'facial_expressions', - 'gaze_integration', - 'shared_enjoyment', - 'response_to_name', - 'ignoring', - 'requesting', - 'showing', - 'joint_attention_initiation', - 'joint_attention_response', - 'social_overtures_quality', - 'social_overtures_caregiver', - 'reciprocal_communication', - 'rapport_quality', - 'intonation', - 'stereotyped_language', - 'unusual_sensory_interest', - 'hand_finger_mannerisms', - 'repetitive_interests', -]; - type Prediction = NonNullable[number]; function associationPair(p: Prediction) { @@ -257,11 +233,9 @@ function associationPair(p: Prediction) { function concordance(headline?: ReturnType, ados?: Observation): string { if (!headline || !ados || headline.probability == null || headline.reference == null) return '—'; const outcome = headline.pair?.split('|')[2]; - const item = ADOS2_ITEMS[Number(outcome?.match(/^ados2_item_(\d{2})$/)?.[1]) - 1]; + const item = Number(outcome?.match(/^ados2_item_(\d{2})$/)?.[1]); const score = - outcome === 'CSS' - ? ados.valueInteger - : ados.component?.find((c) => item && code(c.code) === `ados2.${item}`)?.valueQuantity?.value; + outcome === 'CSS' ? ados.valueInteger : ados2Component(ados, item)?.valueQuantity?.value; if (score == null) return '—'; const event = score >= (outcome === 'CSS' ? 8 : 1); const predicted = headline.probability >= headline.reference; @@ -348,6 +322,7 @@ export function teaRows(page: Bundle) { evaluation.component?.find((c) => code(c.code) === 'ados2.module')?.valueCodeableConcept, ), classification: label(evaluation.interpretation?.[0]), + groups: ados2Groups(evaluation), }, eegs: eegs.map((e) => ({ id: e.id, diff --git a/src/app/indicadores/tea-indicators.spec.ts b/src/app/indicadores/tea-indicators.spec.ts index 4b77310..09c293f 100644 --- a/src/app/indicadores/tea-indicators.spec.ts +++ b/src/app/indicadores/tea-indicators.spec.ts @@ -33,7 +33,17 @@ function fixture(): Bundle { effectiveDateTime: '2026-03-02', valueInteger: 8, component: [ - { code: { coding: [{ code: 'ados2.vocalization_directed' }] }, valueQuantity: { value: 1 } }, + { + code: { + coding: [{ code: 'ados2.vocalization_directed' }, { code: 'A-2' }], + text: 'Frecuencia de la vocalización espontánea dirigida a otros', + }, + extension: [ + { url: EXT + 'ados2-domain', valueCoding: { display: 'Afectación social (AS)' } }, + { url: EXT + 'ados2-subdomain', valueCoding: { display: 'Comunicación' } }, + ], + valueQuantity: { value: 1 }, + }, ], }; const risk: RiskAssessment = { @@ -178,7 +188,26 @@ describe('TEA indicators', () => { name: 'Ana', recordNumbers: ['123'], mchatScore: 9, - ados: { css: 8 }, + ados: { + css: 8, + groups: [ + { + domain: 'Afectación social (AS)', + subdomains: [ + { + subdomain: 'Comunicación', + items: [ + { + code: 'A-2', + title: 'Frecuencia de la vocalización espontánea dirigida a otros', + score: 1, + }, + ], + }, + ], + }, + ], + }, eegs: [{ quality: 'Bueno', channels: 19 }], headline: { pair: cssPair, or: 2, q: 0.01 }, concordance: 'Concordante', diff --git a/src/app/indicadores/tea-list.html b/src/app/indicadores/tea-list.html index e7b5a3c..dd4f73c 100644 --- a/src/app/indicadores/tea-list.html +++ b/src/app/indicadores/tea-list.html @@ -227,6 +227,36 @@
Clasificación
{{ ados.classification || '—' }}
+ @if (ados.groups.length) { + + + + + + + + + @for (group of ados.groups; track group.domain) { + + + + + @for (sub of group.subdomains; track sub.subdomain) { + + + + @for (item of sub.items; track item.code) { + + + + + + } + } + + } +
CódigoÍtemPuntaje
{{ group.domain }}
{{ sub.subdomain }}
{{ item.code }}{{ item.title }}{{ item.score ?? '—' }}
+ } } @else {

—

} diff --git a/src/app/paciente/tea-data.ts b/src/app/paciente/tea-data.ts index 34bb952..548fb8f 100644 --- a/src/app/paciente/tea-data.ts +++ b/src/app/paciente/tea-data.ts @@ -5,6 +5,7 @@ import type { Patient, RiskAssessment, } from 'fhir/r4'; +import { ados2Component, ados2Groups } from '../ados2'; import { code, ext, Fhir, label, resources } from '../fhir'; const steps: Record = { @@ -42,14 +43,6 @@ const biomarkers: Record = { gradient: 'anteroposterior_gradient', }; -const repetitive = new Set([ - 'ados2.intonation', - 'ados2.stereotyped_language', - 'ados2.unusual_sensory_interest', - 'ados2.hand_finger_mannerisms', - 'ados2.repetitive_interests', -]); - const classifications: Record = { non_spectrum: 'Fuera del espectro', autism_spectrum: 'Espectro autista', @@ -103,13 +96,17 @@ export function identity(patient: Patient): string[][] { } export function adosItems(observation: Observation): string[][] { - return (observation.component ?? []) - .filter((item) => code(item.code) !== 'ados2.module') - .map((item) => [ - shown(label(item.code)), - repetitive.has(code(item.code) ?? '') ? 'RRB' : 'SA', - observationValue(item), - ]); + return ados2Groups(observation).flatMap((group) => + group.subdomains.flatMap((sub) => + sub.items.map((item) => [ + group.domain, + sub.subdomain, + item.code, + item.title, + shown(item.score), + ]), + ), + ); } export function adosSummary(observation: Observation): string[][] { @@ -258,7 +255,6 @@ function associations( eeg: Study | undefined, ados: Observation[], ) { - const items = ados[0] ? adosItems(ados[0]) : []; return (risk?.prediction ?? []) .map((p): Pair => { const key = code(p.outcome) ?? ''; @@ -274,7 +270,7 @@ function associations( title: [ metric?.title ?? metrics[biomarkers[biomarker]] ?? biomarker, zoneLabel(zone), - item ? (items[Number(item[1]) - 1]?.[0] ?? outcome) : outcome, + item ? label(ados2Component(ados[0], Number(item[1]))?.code) || outcome : outcome, ].join(' · '), headline: ext(p, 'association-headline')?.valueBoolean === true, altered: site?.outside != null && site.outside !== 0, diff --git a/src/app/paciente/tea-patient.spec.ts b/src/app/paciente/tea-patient.spec.ts index 5d44476..fbff9c3 100644 --- a/src/app/paciente/tea-patient.spec.ts +++ b/src/app/paciente/tea-patient.spec.ts @@ -47,14 +47,32 @@ const ados: Observation = { valueInteger: 0, component: [ { code: { coding: [{ code: 'ados2.module' }] }, valueCodeableConcept: { text: 'Módulo 1' } }, - ...Array.from({ length: 21 }, (_, i) => ({ - code: { coding: [{ code: `ados2.item${i}` }], text: `Ítem ${i + 1}` }, - valueQuantity: i === 0 ? { value: 0 } : undefined, - })), { - code: { coding: [{ code: 'ados2.intonation' }], text: 'Entonación' }, + code: { coding: [{ code: 'ados2.pointing' }, { code: 'A-7' }], text: 'Señalar' }, + extension: [ + { url: EXT + 'ados2-domain', valueCoding: { display: 'Afectación social (AS)' } }, + { url: EXT + 'ados2-subdomain', valueCoding: { display: 'Comunicación' } }, + ], + valueQuantity: { value: 0 }, + }, + { + code: { + coding: [{ code: 'ados2.intonation' }, { code: 'A-3' }], + text: 'Entonación de las vocalizaciones o verbalizaciones', + }, + extension: [ + { + url: EXT + 'ados2-domain', + valueCoding: { display: 'Comportamiento restringido y repetitivo (CRR)' }, + }, + { + url: EXT + 'ados2-subdomain', + valueCoding: { display: 'Comportamientos restringidos y repetitivos' }, + }, + ], valueQuantity: { value: 2 }, }, + { code: { coding: [{ code: 'ados2.response_to_name' }], text: 'Respuesta al nombre' } }, ], }; @@ -134,7 +152,7 @@ describe('Figuras del paciente TEA', () => { }); describe('Expediente TEA', () => { - it('muestra los 22 ítems del ADOS-2 y sus dominios sin incluir el módulo', async () => { + it('muestra solo los ítems del módulo con dominio, subdominio, código y título', async () => { const fixture = TestBed.createComponent(TeaSection); fixture.componentRef.setInput( 'section', @@ -142,10 +160,10 @@ describe('Expediente TEA', () => { ); await fixture.whenStable(); const rows = fixture.nativeElement.querySelectorAll('tbody tr'); - expect(rows).toHaveLength(22); - expect(rows[0].textContent).toContain('SA'); - expect(rows[0].cells[2].textContent.trim()).toBe('0'); - expect(rows[21].textContent).toContain('RRB'); + expect(rows).toHaveLength(2); + const cells = Array.from(rows[0].cells, (c: HTMLTableCellElement) => c.textContent?.trim()); + expect(cells).toEqual(['Afectación social (AS)', 'Comunicación', 'A-7', 'Señalar', '0']); + expect(rows[1].cells[2].textContent.trim()).toBe('A-3'); }); it('exporta las secciones, tablas y figuras con un nombre sin identificador', async () => { @@ -166,7 +184,15 @@ describe('Expediente TEA', () => { expect.objectContaining({ text: 'Relación con el ADOS-2' }), expect.objectContaining({ table: expect.objectContaining({ - body: expect.arrayContaining([['Entonación', 'RRB', '2']]), + body: expect.arrayContaining([ + [ + 'Comportamiento restringido y repetitivo (CRR)', + 'Comportamientos restringidos y repetitivos', + 'A-3', + 'Entonación de las vocalizaciones o verbalizaciones', + '2', + ], + ]), }), }), expect.objectContaining({ image: 'data:image/png;base64,YQ==' }), diff --git a/src/app/paciente/tea-sections.ts b/src/app/paciente/tea-sections.ts index 446bdf7..17aea12 100644 --- a/src/app/paciente/tea-sections.ts +++ b/src/app/paciente/tea-sections.ts @@ -63,7 +63,10 @@ export function recordSections(patient: TeaPatient, norms: ReadonlyMap ({ title: shown(o.effectiveDateTime), fields: adosSummary(o), - table: { headers: ['Ítem', 'Dominio', 'Puntaje'], rows: adosItems(o) }, + table: { + headers: ['Dominio', 'Subdominio', 'Código', 'Ítem', 'Puntaje'], + rows: adosItems(o), + }, })), }, {