feat(tea): ficha propia para la mitad de los pacientes de Seguimiento

Los pacientes con número impar abren su propia ventana, como la ficha de
cáncer cervicouterino (con «Regresar» y un resumen arriba); los pares
conservan el resumen desplegable en la fila. El encabezado de la ficha ya
nombra el dominio en lugar de decir siempre cáncer cervicouterino.
This commit is contained in:
2026-11-03 19:58:30 +00:00
parent b74f188b15
commit 1771cb7ec6
9 changed files with 116 additions and 28 deletions
@@ -2,7 +2,7 @@
<header>
@if (fichaPacienteAbierta()) {
<h1 id="dashboard-title">Ficha del paciente</h1>
<p>Consulta individual de seguimiento de cáncer cervicouterino</p>
<p>Consulta individual de seguimiento de {{ domainLabels[dominio] }}</p>
} @else {
<span class="domain">{{ domainTitles[dominio] }}, investigación</span>
<h1 id="dashboard-title">Indicadores</h1>
@@ -58,7 +58,7 @@ describe('UX-06E.D.3.A catálogo permanentemente desplegado', () => {
expect(fixture.nativeElement.querySelectorAll('.section-tabs [role="tab"]')).toHaveLength(3);
fixture.debugElement.query(By.directive(IndicadoresTracking)).componentInstance.fichaPacienteAbierta.emit(true); fixture.detectChanges();
expect(fixture.nativeElement.querySelector('#dashboard-title')?.textContent.trim()).toBe('Ficha del paciente');
expect(fixture.nativeElement.textContent).toContain('Consulta individual de seguimiento de cáncer cervicouterino');
expect(fixture.nativeElement.textContent).toContain('Consulta individual de seguimiento de TEA');
expect(fixture.nativeElement.querySelector('.section-tabs')).toBeNull();
expect(fixture.nativeElement.querySelector('#panel-seguimiento')?.getAttribute('aria-labelledby')).toBe('dashboard-title');
fixture.debugElement.query(By.directive(IndicadoresTracking)).componentInstance.fichaPacienteAbierta.emit(false); fixture.detectChanges();
@@ -3,7 +3,25 @@
[registrosTemporales]="pacienteDetalle.registrosTemporales()"
(registroAgregado)="pacienteDetalle.agregarRegistro($event)" (volver)="volverASeguimiento()" />
}
<div [hidden]="pacienteDetalle.estado().tipo !== 'cerrado'">
@if (teaFicha; as p) {
<section class="tea-ficha" aria-labelledby="tea-ficha-titulo">
<button class="back-button" mat-stroked-button type="button" (click)="cerrarTea()"><mat-icon aria-hidden="true">arrow_back</mat-icon><span>Regresar</span></button>
<header>
<h2 id="tea-ficha-titulo" tabindex="-1">Paciente {{ p.id_seudonimo }}</h2>
@if (teaData; as d) { <p>Fecha de corte: {{ d.corte }}.</p> }
<dl class="summary">
<div><dt>Identificador seudónimo</dt><dd>{{ p.id_seudonimo }}</dd></div>
<div><dt>Grupo de edad</dt><dd>{{ p.grupo_edad }}</dd></div>
<div><dt>Último EEG</dt><dd>{{ p.ultimo_eeg ?? 'No disponible' }}</dd></div>
<div><dt>Puntaje M-CHAT</dt><dd>{{ p.mchat ?? 'No disponible' }}</dd></div>
<div><dt>CSS ADOS-2</dt><dd>{{ p.css_ados2 ?? 'No disponible' }}</dd></div>
<div><dt>Alteraciones EEG</dt><dd>{{ p.alteraciones_eeg === 'anormal' ? 'Anormal' : p.alteraciones_eeg === 'normal' ? 'Normal' : 'No disponible' }}</dd></div>
</dl>
</header>
<app-tea-paciente-resumen [id]="p.id_seudonimo" [amplio]="true" />
</section>
}
<div [hidden]="pacienteDetalle.estado().tipo !== 'cerrado' || !!teaFicha">
<h2>Seguimiento de {{ domainLabel }}</h2>
@if (dominio !== 'cacu' && dominio !== 'tea') {
<p>El seguimiento aún no está disponible.</p>
@@ -43,10 +61,16 @@
<thead><tr><th scope="col">Identificador seudónimo</th><th scope="col">Grupo de edad</th><th scope="col">Último EEG</th><th scope="col">Puntaje M-CHAT</th><th scope="col">CSS ADOS-2</th><th scope="col">Alteraciones EEG</th></tr></thead>
<tbody>
@for (item of response.items; track item.id_seudonimo) {
<tr class="tea-row" [class.abierta]="teaAbierto === item.id_seudonimo" (click)="alternarTea(item.id_seudonimo, $event)">
<td><button class="row-toggle" type="button" [attr.aria-expanded]="teaAbierto === item.id_seudonimo" [attr.aria-controls]="'tea-detalle-' + item.id_seudonimo"
[attr.aria-label]="(teaAbierto === item.id_seudonimo ? 'Ocultar' : 'Ver') + ' resumen del paciente ' + item.id_seudonimo" (click)="alternarTea(item.id_seudonimo, $event)">
<span class="chevron" aria-hidden="true"></span>{{ item.id_seudonimo }}</button></td><td>{{ item.grupo_edad }}</td><td>{{ item.ultimo_eeg ?? 'No disponible' }}</td>
<tr class="tea-row" [class.abierta]="teaAbierto === item.id_seudonimo" [class.ventana]="teaVentana(item)" (click)="abrirTea(item, $event)">
<td>@if (teaVentana(item)) {
<button class="row-toggle" type="button" [attr.aria-label]="'Abrir ficha del paciente ' + item.id_seudonimo" (click)="abrirTea(item, $event)">
<mat-icon class="window-icon" aria-hidden="true">open_in_new</mat-icon>{{ item.id_seudonimo }}</button>
} @else {
<button class="row-toggle" type="button" [attr.aria-expanded]="teaAbierto === item.id_seudonimo" [attr.aria-controls]="'tea-detalle-' + item.id_seudonimo"
[attr.aria-label]="(teaAbierto === item.id_seudonimo ? 'Ocultar' : 'Ver') + ' resumen del paciente ' + item.id_seudonimo" (click)="abrirTea(item, $event)">
<span class="chevron" aria-hidden="true"></span>{{ item.id_seudonimo }}</button>
}</td>
<td>{{ item.grupo_edad }}</td><td>{{ item.ultimo_eeg ?? 'No disponible' }}</td>
<td>{{ item.mchat ?? 'No disponible' }}</td><td>{{ item.css_ados2 ?? 'No disponible' }}</td>
<td>@if (item.alteraciones_eeg; as eeg) { <span class="eeg" [class.eeg-anormal]="eeg === 'anormal'">{{ eeg === 'anormal' ? 'Anormal' : 'Normal' }}</span> } @else { No disponible }</td></tr>
@if (teaAbierto === item.id_seudonimo) {
@@ -31,3 +31,12 @@ tbody tr.tea-row:hover, tbody tr.tea-row.abierta { background-color: color-mix(i
.row-toggle[aria-expanded=true] .chevron { transform: rotate(45deg); }
@media (prefers-reduced-motion: reduce) { .chevron, tbody tr.tea-row { transition: none; } }
tbody tr.tea-detalle > td { padding: 1rem; border-top: 0; background: var(--issste-background); }
// TEA patient window (mock: odd-numbered patients), laid out like CaCu's patient page.
.window-icon { width: 1.1rem; height: 1.1rem; font-size: 1.1rem; color: var(--issste-accent); }
.tea-ficha header { margin-block: 1.5rem; }
.tea-ficha h2 { margin-block: .5rem 1rem; font-size: 1.65rem; }
.tea-ficha .back-button { display: inline-flex; align-items: center; gap: .35rem; min-height: 40px; padding-inline: .65rem; }
.tea-ficha .back-button mat-icon { width: 1.15rem; height: 1.15rem; font-size: 1.15rem; }
.tea-ficha .summary { display: flex; flex-wrap: wrap; gap: 1.25rem 2rem; margin: 0; }
.tea-ficha dt { color: var(--issste-text-secondary); font-size: .9rem; }
.tea-ficha dd { margin: .4rem 0 0; font-weight: 600; }
@@ -6,16 +6,17 @@ import { catchError, defer, map, of, Subject, switchMap } from 'rxjs';
import { CacuSeguimientoService, validSeguimientoQuery } from './cacu-seguimiento.service';
import { latestStudy, SeguimientoPaciente, SeguimientoQuery, SeguimientoResponse, SeguimientoStatus } from './cacu-seguimiento.models';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { PacienteDetalleComponent } from './paciente-detalle/paciente-detalle';
import { PacienteDetalleState } from './paciente-detalle/paciente-detalle.state';
import { Dominio } from './indicadores.models';
import { IndicadoresService } from './indicadores.service';
import { ALTERACIONES_EEG, TeaSeguimientoResponse, TeaSeguimientoService } from './tea-seguimiento.service';
import { ALTERACIONES_EEG, TeaSeguimientoPaciente, TeaSeguimientoResponse, TeaSeguimientoService } from './tea-seguimiento.service';
import { TeaPacienteResumen } from './tea-paciente-resumen';
@Component({
selector: 'app-indicadores-tracking',
imports: [FormsModule, MatButtonModule, PacienteDetalleComponent, TeaPacienteResumen],
imports: [FormsModule, MatButtonModule, MatIconModule, PacienteDetalleComponent, TeaPacienteResumen],
providers: [PacienteDetalleState],
templateUrl: './indicadores-tracking.html',
styleUrl: './indicadores-tracking.scss',
@@ -43,6 +44,8 @@ export class IndicadoresTracking implements OnChanges {
teaData?: TeaSeguimientoResponse;
// One open summary at a time, like an accordion.
teaAbierto?: string;
// Patient shown in its own window, like CaCu's patient page.
teaFicha?: TeaSeguimientoPaciente;
statuses: SeguimientoStatus[] = [];
private metadataLoaded = false;
categories: Record<string, { etiqueta: string; color?: string | null }> = {};
@@ -89,7 +92,8 @@ export class IndicadoresTracking implements OnChanges {
ngOnChanges() {
if (this.previousDomain !== this.dominio) {
if (this.pacienteDetalle.estado().tipo !== 'cerrado') this.fichaPacienteAbierta.emit(false);
this.pacienteDetalle.cerrar(); this.controlPaciente = undefined;
if (this.teaFicha) this.fichaPacienteAbierta.emit(false);
this.pacienteDetalle.cerrar(); this.controlPaciente = undefined; this.teaFicha = undefined;
this.previousDomain = this.dominio; this.requests.next(null); this.teaRequests.next(null); this.data = undefined; this.teaData = undefined;
this.status = 'idle'; this.statuses = []; this.initialized = false; this.draft = { meses: 3, page: 1, page_size: 50 }; this.applied = { ...this.draft };
}
@@ -127,6 +131,25 @@ export class IndicadoresTracking implements OnChanges {
if (evento.currentTarget instanceof HTMLTableRowElement && evento.target instanceof HTMLElement && evento.target.closest('button, a, input, select, textarea')) return;
this.teaAbierto = this.teaAbierto === id ? undefined : id;
}
// Mock: to show both ideas side by side, odd-numbered patients open their own window and
// even-numbered ones expand in place.
teaVentana(item: TeaSeguimientoPaciente) { return Number(item.id_seudonimo.replace(/\D/g, '')) % 2 === 1; }
abrirTea(item: TeaSeguimientoPaciente, evento: Event) {
evento.stopPropagation();
if (!this.teaVentana(item)) { this.alternarTea(item.id_seudonimo, evento); return; }
if (evento.currentTarget instanceof HTMLTableRowElement && evento.target instanceof HTMLElement
&& evento.target.closest('button, a, input, select, textarea')) return;
this.controlPaciente = evento.currentTarget instanceof HTMLElement ? evento.currentTarget : undefined;
this.teaAbierto = undefined; this.teaFicha = item;
this.fichaPacienteAbierta.emit(true);
afterNextRender(() => document.getElementById('tea-ficha-titulo')?.focus(), { injector: this.injector });
}
cerrarTea() {
this.teaFicha = undefined;
this.fichaPacienteAbierta.emit(false);
const control = this.controlPaciente;
afterNextRender(() => { if (control?.isConnected) control.focus({ preventScroll: true }); }, { injector: this.injector });
}
volverASeguimiento() {
this.pacienteDetalle.cerrar();
this.fichaPacienteAbierta.emit(false);
@@ -4,7 +4,7 @@
<button type="button" (click)="load()">Reintentar resumen</button>
}
@if (status() === 'ready' && detalle(); as d) {
<div class="resumen">
<div class="resumen" [class.amplio]="amplio">
<section class="panel" aria-label="Resumen ADOS-2">
<h3>ADOS-2</h3>
@if (d.ados2; as a) {
@@ -1,5 +1,6 @@
:host { display: block; }
.resumen { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: .75rem; }
.resumen.amplio { grid-template-columns: repeat(auto-fit, minmax(26rem, 1fr)); gap: 1rem; }
.panel { min-width: 0; padding: .75rem; border: 1px solid var(--issste-border); border-radius: var(--issste-radius); background: var(--issste-surface); }
h3 { margin: 0 0 .15rem; font-size: 1rem; }
.meta { margin: 0 0 .5rem; font-size: .8rem; color: var(--issste-text-secondary); }
@@ -51,6 +51,8 @@ export function mapaFigure(eeg: TeaEeg): PlotlyFigure {
})
export class TeaPacienteResumen implements OnInit {
@Input({ required: true }) id = '';
// In its own window there is room for two wide columns instead of four narrow ones.
@Input() amplio = false;
private readonly service = inject(TeaSeguimientoService);
private readonly destroy = inject(DestroyRef);
readonly status = signal<'loading' | 'ready' | 'error'>('loading');
@@ -94,17 +94,21 @@ describe('Seguimiento TEA', () => {
expect(fixture.nativeElement.querySelector('tbody')).toBeNull();
expect(fixture.nativeElement.textContent).toContain('No se pudo consultar');
});
it('despliega un resumen por fila, uno a la vez, y lo pide al abrirlo', () => {
// Mock: odd-numbered patients open their own window; even-numbered ones expand in place.
const tres = { ...data, paginacion: { ...data.paginacion, total_items: 3 },
items: [item, { ...item, id_seudonimo: 'T-0002' }, { ...item, id_seudonimo: 'T-0004' }] };
it('los pacientes pares despliegan su resumen en la fila, uno a la vez, y lo piden al abrirlo', () => {
const fixture = open();
request().flush(data); fixture.detectChanges();
request().flush(tres); fixture.detectChanges();
const root: HTMLElement = fixture.nativeElement;
const toggles = root.querySelectorAll<HTMLButtonElement>('button.row-toggle');
expect(toggles).toHaveLength(2);
expect(toggles[0].getAttribute('aria-expanded')).toBe('false');
toggles[0].click(); fixture.detectChanges();
expect(toggles[0].getAttribute('aria-expanded')).toBe('true');
http.expectOne('/tea/seguimiento/T-0001').flush(detalle); fixture.detectChanges();
const panel = root.querySelector('#tea-detalle-T-0001')!;
expect(toggles).toHaveLength(3);
expect(toggles[0].hasAttribute('aria-expanded')).toBe(false);
expect(toggles[1].getAttribute('aria-expanded')).toBe('false');
toggles[1].click(); fixture.detectChanges();
expect(toggles[1].getAttribute('aria-expanded')).toBe('true');
http.expectOne('/tea/seguimiento/T-0002').flush({ ...detalle, id_seudonimo: 'T-0002' }); fixture.detectChanges();
const panel = root.querySelector('#tea-detalle-T-0002')!;
expect(panel.textContent).toContain('CSS 3');
expect(panel.textContent).toContain('Afecto social (AS)');
expect(panel.textContent).toContain('Buena');
@@ -118,21 +122,46 @@ describe('Seguimiento TEA', () => {
expect(metricas.textContent).toContain('Espectro más plano de lo esperado para la edad.');
expect(metricas.textContent).toContain('Sin registro de sueño en el estudio.');
expect(metricas.textContent).not.toContain('Sin alteraciones en las métricas evaluadas.');
(root.querySelectorAll('tbody tr.tea-row')[1] as HTMLElement).click(); fixture.detectChanges();
expect(root.querySelector('#tea-detalle-T-0001')).toBeNull();
http.expectOne('/tea/seguimiento/T-0002').flush({ ...detalle, id_seudonimo: 'T-0002', ados2: null, eeg: null }); fixture.detectChanges();
expect(root.querySelector('#tea-detalle-T-0002')?.textContent).toContain('Sin evaluación ADOS-2 registrada.');
toggles[1].click(); fixture.detectChanges();
(root.querySelectorAll('tbody tr.tea-row')[2] as HTMLElement).click(); fixture.detectChanges();
expect(root.querySelector('#tea-detalle-T-0002')).toBeNull();
http.expectOne('/tea/seguimiento/T-0004').flush({ ...detalle, id_seudonimo: 'T-0004', ados2: null, eeg: null }); fixture.detectChanges();
expect(root.querySelector('#tea-detalle-T-0004')?.textContent).toContain('Sin evaluación ADOS-2 registrada.');
toggles[2].click(); fixture.detectChanges();
expect(root.querySelector('tr.tea-detalle')).toBeNull();
http.verify();
});
it('los pacientes impares abren su propia ventana y Regresar vuelve a la lista', async () => {
const fixture = open();
const ficha = vi.fn(); fixture.componentInstance.fichaPacienteAbierta.subscribe(ficha);
request().flush(tres); fixture.detectChanges();
const root: HTMLElement = fixture.nativeElement;
const toggle = root.querySelector<HTMLButtonElement>('button.row-toggle')!;
expect(toggle.getAttribute('aria-label')).toBe('Abrir ficha del paciente T-0001');
toggle.click(); fixture.detectChanges(); await fixture.whenStable();
expect(ficha).toHaveBeenLastCalledWith(true);
expect(root.querySelector('tr.tea-detalle')).toBeNull();
const ventana = root.querySelector<HTMLElement>('section.tea-ficha')!;
expect(ventana.querySelector('h2')!.textContent).toBe('Paciente T-0001');
expect(document.activeElement).toBe(ventana.querySelector('h2'));
expect(ventana.textContent).toContain('Fecha de corte: 2026-09-30.');
expect(ventana.querySelector('.summary')!.textContent).toContain('18-23 meses');
expect((root.querySelector('.tracking-table')!.closest('[hidden]'))).not.toBeNull();
http.expectOne('/tea/seguimiento/T-0001').flush(detalle); fixture.detectChanges();
expect(ventana.querySelector('app-tea-paciente-resumen .resumen.amplio')!.textContent).toContain('CSS 3');
ventana.querySelector<HTMLButtonElement>('.back-button')!.click(); fixture.detectChanges(); await fixture.whenStable();
expect(ficha).toHaveBeenLastCalledWith(false);
expect(root.querySelector('section.tea-ficha')).toBeNull();
expect(root.querySelector('.tracking-table')!.closest('[hidden]')).toBeNull();
expect(document.activeElement).toBe(root.querySelector('button.row-toggle'));
http.verify();
});
it('muestra un error recuperable si el resumen no es válido', () => {
const fixture = open();
request().flush(data); fixture.detectChanges();
request().flush(tres); fixture.detectChanges();
const root: HTMLElement = fixture.nativeElement;
root.querySelector<HTMLButtonElement>('button.row-toggle')!.click(); fixture.detectChanges();
http.expectOne('/tea/seguimiento/T-0001').flush({ ...detalle, id_seudonimo: 'T-0099' }); fixture.detectChanges();
expect(root.querySelector('#tea-detalle-T-0001')?.textContent).toContain('No se pudo cargar el resumen del paciente.');
root.querySelectorAll<HTMLButtonElement>('button.row-toggle')[1].click(); fixture.detectChanges();
http.expectOne('/tea/seguimiento/T-0002').flush({ ...detalle, id_seudonimo: 'T-0099' }); fixture.detectChanges();
expect(root.querySelector('#tea-detalle-T-0002')?.textContent).toContain('No se pudo cargar el resumen del paciente.');
http.verify();
});
it('valida que los puntajes ADOS-2 sumen y que el mapa sea rectangular', () => {