feat(tea): seguimiento con resumen por paciente y resumen por periodo
- Pestaña Seguimiento de TEA: tabla de pacientes con filtro de alteraciones EEG y fila desplegable con ADOS-2 por reactivo, calidad del EEG y mapa topográfico (GET /tea/seguimiento/<id>). - Indicadores destacados: M21 y M22 (pacientes con TEA con y sin EEG). - Con un solo periodo elegido, TEA muestra un párrafo de resumen en lugar de las tarjetas.
This commit is contained in:
@@ -10,10 +10,12 @@ 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 { TeaPacienteResumen } from './tea-paciente-resumen';
|
||||
|
||||
@Component({
|
||||
selector: 'app-indicadores-tracking',
|
||||
imports: [FormsModule, MatButtonModule, PacienteDetalleComponent],
|
||||
imports: [FormsModule, MatButtonModule, PacienteDetalleComponent, TeaPacienteResumen],
|
||||
providers: [PacienteDetalleState],
|
||||
templateUrl: './indicadores-tracking.html',
|
||||
styleUrl: './indicadores-tracking.scss',
|
||||
@@ -24,6 +26,7 @@ export class IndicadoresTracking implements OnChanges {
|
||||
@Input() active = false;
|
||||
private readonly service = inject(CacuSeguimientoService);
|
||||
private readonly indicators = inject(IndicadoresService);
|
||||
private readonly teaService = inject(TeaSeguimientoService);
|
||||
private readonly destroy = inject(DestroyRef);
|
||||
private readonly changeDetector = inject(ChangeDetectorRef);
|
||||
private readonly injector = inject(Injector);
|
||||
@@ -31,11 +34,15 @@ export class IndicadoresTracking implements OnChanges {
|
||||
readonly fichaPacienteAbierta = output<boolean>();
|
||||
private controlPaciente?: HTMLElement;
|
||||
private readonly requests = new Subject<SeguimientoQuery | null>();
|
||||
private readonly teaRequests = new Subject<SeguimientoQuery | null>();
|
||||
private initialized = false;
|
||||
private previousDomain?: Dominio;
|
||||
status: 'idle' | 'loading' | 'ready' | 'pending' | 'error' = 'idle';
|
||||
message = '';
|
||||
data?: SeguimientoResponse;
|
||||
teaData?: TeaSeguimientoResponse;
|
||||
// One open summary at a time, like an accordion.
|
||||
teaAbierto?: string;
|
||||
statuses: SeguimientoStatus[] = [];
|
||||
private metadataLoaded = false;
|
||||
categories: Record<string, { etiqueta: string; color?: string | null }> = {};
|
||||
@@ -43,12 +50,13 @@ export class IndicadoresTracking implements OnChanges {
|
||||
private applied: SeguimientoQuery = { ...this.draft };
|
||||
readonly latestStudy = latestStudy;
|
||||
get provisional() { return this.data?.reglas.some(r => r.estado === 'provisional'); }
|
||||
get response() { return this.dominio === 'tea' ? this.teaData : this.data; }
|
||||
constructor() {
|
||||
const failure = (error: unknown, q: SeguimientoQuery) => of({ data: undefined, status: error instanceof HttpErrorResponse && error.status === 404 && q.page === 1 ? 'pending' as const : 'error' as const,
|
||||
message: error instanceof HttpErrorResponse && error.status === 400 ? 'Revisa la fecha, la ventana y los filtros seleccionados.'
|
||||
: error instanceof HttpErrorResponse && error.status === 404 ? 'El seguimiento aún no está disponible para esta consulta.' : 'No se pudo consultar el seguimiento. Intenta nuevamente.' });
|
||||
this.requests.pipe(switchMap(q => q ? defer(() => this.service.consultar(q)).pipe(
|
||||
map(data => ({ data, message: '', status: 'ready' as const })),
|
||||
catchError(error => of({ data: undefined, status: error instanceof HttpErrorResponse && error.status === 404 && q.page === 1 ? 'pending' as const : 'error' as const,
|
||||
message: error instanceof HttpErrorResponse && error.status === 400 ? 'Revisa la fecha, la ventana y los filtros seleccionados.'
|
||||
: error instanceof HttpErrorResponse && error.status === 404 ? 'El seguimiento aún no está disponible para esta consulta.' : 'No se pudo consultar el seguimiento. Intenta nuevamente.' }))) : of(null)), takeUntilDestroyed(this.destroy)).subscribe(result => {
|
||||
map(data => ({ data, message: '', status: 'ready' as const })), catchError(error => failure(error, q))) : of(null)), takeUntilDestroyed(this.destroy)).subscribe(result => {
|
||||
if (!result) return;
|
||||
this.changeDetector.markForCheck();
|
||||
this.status = result.status; this.data = result.data; this.message = result.message;
|
||||
@@ -66,25 +74,38 @@ export class IndicadoresTracking implements OnChanges {
|
||||
}
|
||||
}
|
||||
});
|
||||
this.teaRequests.pipe(switchMap(q => q ? defer(() => this.teaService.consultar(q)).pipe(
|
||||
map(data => ({ data, message: '', status: 'ready' as const })), catchError(error => failure(error, q))) : of(null)), takeUntilDestroyed(this.destroy)).subscribe(result => {
|
||||
if (!result) return;
|
||||
this.changeDetector.markForCheck();
|
||||
this.status = result.status; this.teaData = result.data; this.message = result.message; this.teaAbierto = undefined;
|
||||
if (result.data) {
|
||||
const data = result.data;
|
||||
this.applied = { corte: data.corte, meses: data.ventana.meses, estatus: data.filtros.alteraciones_eeg ?? undefined, page: data.paginacion.page, page_size: data.paginacion.page_size };
|
||||
this.draft = { ...this.applied };
|
||||
}
|
||||
});
|
||||
}
|
||||
ngOnChanges() {
|
||||
if (this.previousDomain !== this.dominio) {
|
||||
if (this.pacienteDetalle.estado().tipo !== 'cerrado') this.fichaPacienteAbierta.emit(false);
|
||||
this.pacienteDetalle.cerrar(); this.controlPaciente = undefined;
|
||||
this.previousDomain = this.dominio; this.requests.next(null); this.data = 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 };
|
||||
}
|
||||
if (this.dominio === 'cacu' && this.active && !this.initialized) { this.initialized = true; this.load(this.applied); }
|
||||
if (this.dominio === 'tea' && this.active && !this.initialized) { this.initialized = true; this.statuses = ALTERACIONES_EEG; this.load(this.applied); }
|
||||
}
|
||||
private load(q: SeguimientoQuery) {
|
||||
if (this.dominio !== 'cacu') return;
|
||||
if (this.dominio !== 'cacu' && this.dominio !== 'tea') return;
|
||||
if (!validSeguimientoQuery(q)) { this.message = 'Revisa la fecha, la ventana y el tamaño de página (1 a 200).'; return; }
|
||||
this.status = 'loading'; this.message = ''; this.data = undefined; this.applied = { ...q }; this.requests.next(q);
|
||||
this.status = 'loading'; this.message = ''; this.data = undefined; this.teaData = undefined; this.applied = { ...q };
|
||||
(this.dominio === 'tea' ? this.teaRequests : this.requests).next(q);
|
||||
}
|
||||
apply() { this.load({ ...this.draft, page: 1 }); }
|
||||
retry() { this.load(this.applied); }
|
||||
navigate(page: number) {
|
||||
if (!this.data || page < 1 || page > this.data.paginacion.total_pages) return;
|
||||
if (!this.response || page < 1 || page > this.response.paginacion.total_pages) return;
|
||||
this.load({ ...this.applied, page });
|
||||
}
|
||||
abrirPaciente(paciente: SeguimientoPaciente, evento: Event) {
|
||||
@@ -100,6 +121,12 @@ export class IndicadoresTracking implements OnChanges {
|
||||
this.pacienteDetalle.abrir(paciente, this.data.corte);
|
||||
this.fichaPacienteAbierta.emit(true);
|
||||
}
|
||||
alternarTea(id: string, evento: Event) {
|
||||
evento.stopPropagation();
|
||||
// Row clicks that land on a control are left to that control.
|
||||
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;
|
||||
}
|
||||
volverASeguimiento() {
|
||||
this.pacienteDetalle.cerrar();
|
||||
this.fichaPacienteAbierta.emit(false);
|
||||
|
||||
Reference in New Issue
Block a user