feat(cama): TEA tabs, follow-up list from announced columns and histopathology donut by BI-RADS category
This commit is contained in:
@@ -12,6 +12,7 @@ import { Dominio } from './indicadores.models';
|
||||
import { IndicadoresService } from './indicadores.service';
|
||||
import { ALTERACIONES_EEG, ESTADOS_CASO, GRUPOS_EDAD_TEA, RANGOS_CSS, RANGOS_MCHAT, TeaSeguimientoPaciente, TeaSeguimientoResponse, TeaSeguimientoService } from './tea-seguimiento.service';
|
||||
import { TeaPacienteResumen } from './tea-paciente-resumen';
|
||||
import { SeguimientoColumna, SeguimientoFiltro, SeguimientoTablaResponse, SeguimientoTablaService, SeguimientoValor } from './seguimiento-tabla.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-indicadores-tracking',
|
||||
@@ -27,6 +28,7 @@ export class IndicadoresTracking implements OnChanges {
|
||||
private readonly service = inject(CacuSeguimientoService);
|
||||
private readonly indicators = inject(IndicadoresService);
|
||||
private readonly teaService = inject(TeaSeguimientoService);
|
||||
private readonly tablaService = inject(SeguimientoTablaService);
|
||||
private readonly destroy = inject(DestroyRef);
|
||||
private readonly changeDetector = inject(ChangeDetectorRef);
|
||||
private readonly injector = inject(Injector);
|
||||
@@ -35,18 +37,22 @@ export class IndicadoresTracking implements OnChanges {
|
||||
private controlPaciente?: HTMLElement;
|
||||
private readonly requests = new Subject<SeguimientoQuery | null>();
|
||||
private readonly teaRequests = new Subject<SeguimientoQuery | null>();
|
||||
private readonly tablaRequests = new Subject<{ dominio: Dominio; q: SeguimientoQuery } | null>();
|
||||
private initialized = false;
|
||||
private previousDomain?: Dominio;
|
||||
status: 'idle' | 'loading' | 'ready' | 'pending' | 'error' = 'idle';
|
||||
message = '';
|
||||
data?: SeguimientoResponse;
|
||||
teaData?: TeaSeguimientoResponse;
|
||||
// Domains whose list announces its own filters and columns.
|
||||
tablaData?: SeguimientoTablaResponse;
|
||||
filtrosTabla: SeguimientoFiltro[] = [];
|
||||
// One open summary at a time, like an accordion.
|
||||
teaAbierto?: string;
|
||||
statuses: SeguimientoStatus[] = [];
|
||||
private metadataLoaded = false;
|
||||
categories: Record<string, { etiqueta: string; color?: string | null }> = {};
|
||||
draft: SeguimientoQuery = { meses: 3, page: 1, page_size: 50 };
|
||||
draft: SeguimientoQuery = { meses: 3, page: 1, page_size: 50, filtros: {} };
|
||||
private applied: SeguimientoQuery = { ...this.draft };
|
||||
readonly latestStudy = latestStudy;
|
||||
readonly gruposEdad = GRUPOS_EDAD_TEA;
|
||||
@@ -57,7 +63,8 @@ export class IndicadoresTracking implements OnChanges {
|
||||
// Kept from the last answer, so the filter doesn't empty while a query is running.
|
||||
tiposAlteracion: { codigo: string; etiqueta: string }[] = [];
|
||||
get provisional() { return this.data?.reglas.some(r => r.estado === 'provisional'); }
|
||||
get response() { return this.dominio === 'tea' ? this.teaData : this.data; }
|
||||
get response() { return this.dominio === 'tea' ? this.teaData : this.dominio === 'cacu' ? this.data : this.tablaData; }
|
||||
get propio() { return this.dominio === 'cacu' || this.dominio === 'tea'; }
|
||||
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.'
|
||||
@@ -93,24 +100,43 @@ export class IndicadoresTracking implements OnChanges {
|
||||
this.draft = { ...this.applied };
|
||||
}
|
||||
});
|
||||
this.tablaRequests.pipe(switchMap(r => r ? defer(() => this.tablaService.consultar(r.dominio, r.q)).pipe(
|
||||
map(data => ({ data, message: '', status: 'ready' as const })), catchError(error => failure(error, r.q))) : of(null)), takeUntilDestroyed(this.destroy)).subscribe(result => {
|
||||
if (!result) return;
|
||||
this.changeDetector.markForCheck();
|
||||
this.status = result.status; this.tablaData = result.data; this.message = result.message;
|
||||
if (result.data) {
|
||||
const data = result.data;
|
||||
this.filtrosTabla = data.filtros_disponibles;
|
||||
const filtros = Object.fromEntries(Object.entries(data.filtros).filter((e): e is [string, string] => e[1] !== null));
|
||||
this.applied = { corte: data.corte, meses: data.ventana.meses, filtros, page: data.paginacion.page, page_size: data.paginacion.page_size };
|
||||
this.draft = { ...this.applied, filtros: { ...filtros } };
|
||||
}
|
||||
});
|
||||
}
|
||||
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.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 };
|
||||
this.previousDomain = this.dominio; this.requests.next(null); this.teaRequests.next(null); this.tablaRequests.next(null);
|
||||
this.data = undefined; this.teaData = undefined; this.tablaData = undefined; this.filtrosTabla = [];
|
||||
this.status = 'idle'; this.statuses = []; this.initialized = false; this.draft = { meses: 3, page: 1, page_size: 50, filtros: {} }; 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); }
|
||||
if (!this.propio && this.active && !this.initialized) { this.initialized = true; this.load(this.applied); }
|
||||
}
|
||||
private load(q: SeguimientoQuery) {
|
||||
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.teaData = undefined; this.applied = { ...q };
|
||||
(this.dominio === 'tea' ? this.teaRequests : this.requests).next(q);
|
||||
this.status = 'loading'; this.message = ''; this.data = undefined; this.teaData = undefined; this.tablaData = undefined; this.applied = { ...q };
|
||||
if (this.dominio === 'tea') this.teaRequests.next(q);
|
||||
else if (this.dominio === 'cacu') this.requests.next(q);
|
||||
else this.tablaRequests.next({ dominio: this.dominio, q });
|
||||
}
|
||||
apply() { this.load({ ...this.draft, page: 1 }); }
|
||||
apply() { this.load({ ...this.draft, filtros: Object.fromEntries(Object.entries(this.draft.filtros ?? {}).filter(([, v]) => v)), page: 1 }); }
|
||||
valorTabla(v: SeguimientoValor | undefined) { return v === null || v === undefined || v === '' ? 'No disponible' : typeof v === 'number' ? v.toLocaleString('es-MX') : v; }
|
||||
detallesTabla(c: SeguimientoColumna) { return c.detalles ?? []; }
|
||||
get filtrosDraft() { return this.draft.filtros ??= {}; }
|
||||
retry() { this.load(this.applied); }
|
||||
navigate(page: number) {
|
||||
if (!this.response || page < 1 || page > this.response.paginacion.total_pages) return;
|
||||
|
||||
Reference in New Issue
Block a user