Merge origin/dashboard-test: CaMa wired to the published catalog, with the mock's views kept

dashboard-test is the base for every CaMa feature both branches built; this
branch's TEA and CaCu work (from the TEA mock) and its later CaMa views are
kept on top of it.

How:
- From dashboard-test: the opportunity strip with pending cards
  (camaKpiCards, CAMA_OPORTUNIDAD_KPIS), the histopathology view drawn from
  the published BI-RADS matrix, the pending histopathology card, the
  follow-up table component (app-seguimiento-tabla), the paired BI-RADS
  counts, the deferred domain selector in the header, the compact filter row
  for CaMa, the quiet «Disponible» state and the stricter KPI rules (no rate
  without a denominator, no median without observations).
- Kept from this branch: the single-period filters and the indicator
  selector of every domain (instead of the side navigation and «Modalidad»),
  TEA's Histórico grouping and summary paragraph, CaCu's views, the
  catalog-driven scenario and confirmation pickers, the Análisis tab, no
  pins or figure count below five indicators, and no representation
  selector on the cards.
- Histórico: this branch's component, which serves TEA and CaMa, with
  dashboard-test's fixed CaMa panel list (HISTORICO_CAMA) and pending
  panels; figures merged (dashboard-test's stricter series rules plus the
  shared scales, EEG colours and in-process chart of TEA).
- Specs: this branch's for shared components; dashboard-test's for its CaMa
  components. Expectations that contradicted the kept design (TEA without
  Histórico, «Modalidad», side navigation, four entries in
  KPI_BY_DOMAIN.cama) now state the merged behaviour.

Implications:
- CaMa search and pins never show; its cards are what the summary draws.
- The four CaMa opportunity cards are pending until the catalog publishes
  their indicator; the mock publishes all four.
- The histopathology view still has its label buttons and inner labels;
  this branch's expandable donut for CaMa is no longer used.
This commit is contained in:
rockdrigo
2026-11-12 13:35:39 -06:00
98 changed files with 5383 additions and 1106 deletions
@@ -12,11 +12,11 @@ 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';
import { IndicadoresSeguimientoTabla } from './indicadores-seguimiento-tabla';
@Component({
selector: 'app-indicadores-tracking',
imports: [FormsModule, MatButtonModule, PacienteDetalleComponent, TeaPacienteResumen],
imports: [FormsModule, MatButtonModule, PacienteDetalleComponent, TeaPacienteResumen, IndicadoresSeguimientoTabla],
providers: [PacienteDetalleState],
templateUrl: './indicadores-tracking.html',
styleUrl: './indicadores-tracking.scss',
@@ -28,7 +28,6 @@ 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);
@@ -37,16 +36,12 @@ 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[] = [];
@@ -63,7 +58,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.dominio === 'cacu' ? this.data : this.tablaData; }
get response() { return this.dominio === 'tea' ? this.teaData : this.dominio === 'cacu' ? this.data : undefined; }
// CaMa's list announces its own filters and columns and is drawn by IndicadoresSeguimientoTabla.
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,
@@ -100,43 +96,25 @@ 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.tablaRequests.next(null);
this.data = undefined; this.teaData = undefined; this.tablaData = undefined; this.filtrosTabla = [];
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, 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 (!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.tablaData = undefined; this.applied = { ...q };
this.status = 'loading'; this.message = ''; this.data = undefined; this.teaData = 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, 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;