Merge the TEA labels and sections branch into the TEA indicators branch

This commit is contained in:
ulises
2026-11-22 22:11:34 -06:00
23 changed files with 177 additions and 131 deletions
@@ -9,13 +9,14 @@ import { MatProgressBarModule } from '@angular/material/progress-bar';
import { defer, map, Subscription } from 'rxjs';
import { IndicadorAyuda } from './indicador-ayuda';
import { PlotlyChart } from '../../shared/plotly/plotly-chart';
import { cronologico, enProcesoFigura, etiquetaPeriodo, historicoFigura, HistoricoFigura, M30_RESULTADO_EEG } from './indicadores-historico-figures';
import { cronologico, etiquetaPeriodo, historicoFigura, HistoricoFigura, M30_RESULTADO_EEG } from './indicadores-historico-figures';
import { httpMessage } from './indicadores-http';
import { IndicadoresHistoricoPeriodos, PeriodosDialogoDatos } from './indicadores-historico-periodos';
import { IndicadoresPeriodos } from './indicadores-periodos';
import { Dominio, Indicador, IndicadorDatos, PlotlyFigure, Tema, TipoPeriodo } from './indicadores.models';
import { IndicadoresService } from './indicadores.service';
import { HISTORICO_CAMA, historicoDeDominio, PanelHistorico } from './indicadores-historico-config';
import { TEA_FIGURAS_CLINICAS, TEA_FIGURAS_OPORTUNIDAD } from './indicadores-kpi';
export { HISTORICO_CAMA };
@@ -32,8 +33,11 @@ type Panel = { item: Pick<Indicador, 'id' | 'titulo'> & { contrato?: Indicador['
{ estado: 'cargando' | 'vacio' | 'pendiente' | 'desarrollo' | 'error' }
| { estado: 'listo'; figura: HistoricoFigura; pasos?: { titulo: string; figura: HistoricoFigura }[] });
class ContratoHistoricoInvalido extends Error {}
const TIEMPOS = ['M26_dias_mchat_ados2', 'M27_dias_ados2_diagnostico', 'M25_dias_mchat_diagnostico'];
const CASOS = 'M28_casos_por_estado';
const TIEMPOS = TEA_FIGURAS_OPORTUNIDAD;
const TITULOS_TEA: Readonly<Record<string, string>> = {
M23_pacientes_evaluados: 'Progresión del proceso diagnóstico',
M28_casos_por_estado: 'Flujo del proceso diagnóstico y estudios de EEG',
};
const PERSONALIZADO = -1;
function unir(a: IndicadorDatos, b: IndicadorDatos): IndicadorDatos {
const nuevos = new Set(b.periodos.filter(p => !a.periodos.includes(p)));
@@ -44,8 +48,8 @@ function unir(a: IndicadorDatos, b: IndicadorDatos): IndicadorDatos {
...(reportes.length ? { reportes } : {}), ...(a['unidades_periodo'] || b['unidades_periodo'] ? { unidades_periodo: unidades } : {}) };
}
// The screening steps go together as small charts, and the case counts are followed by their in-process share.
function agrupar(paneles: (Panel & { datos?: IndicadorDatos })[], tema: Tema): Panel[] {
// Keep the individual cards available for loading, error and empty states.
function agruparTiempos(paneles: Panel[]): Panel[] {
const pasos = TIEMPOS.map(id => paneles.find(p => p.item.id === id));
const listos = pasos.every(p => p?.estado === 'listo');
return paneles.flatMap((panel): Panel[] => {
@@ -57,9 +61,6 @@ function agrupar(paneles: (Panel & { datos?: IndicadorDatos })[], tema: Tema): P
suprimidos: notas('suprimidos'), sinDato: notas('sinDato') } }];
}
if (listos && TIEMPOS.includes(panel.item.id)) return [];
if (panel.item.id === CASOS && panel.estado === 'listo' && panel.datos) {
return [panel, { item: { id: 'en_proceso', titulo: 'Porcentaje de niños en proceso', contrato: 'C1' }, rango: panel.rango, estado: 'listo', figura: enProcesoFigura(panel.datos, tema) }];
}
return [panel];
});
}
@@ -86,14 +87,7 @@ export function resaltarSerie(figura: PlotlyFigure, elegida: string): PlotlyFigu
}
// TEA's panels in the order of the request; whatever it does not name keeps the catalog's order after them.
const ORDEN_TEA = ['tiempos', 'M23_pacientes_evaluados', 'M24_confirmacion_diagnostico', 'M21_diagnosticados_con_eeg', 'M22_diagnosticados_sin_eeg',
CASOS, 'en_proceso', 'M29_calidad_eeg', M30_RESULTADO_EEG];
// TEA's history names three panels differently from the summary cards.
const TITULOS_TEA: Readonly<Record<string, string>> = {
M23_pacientes_evaluados: 'Progresión del proceso diagnóstico',
[CASOS]: 'Flujo del proceso diagnóstico y estudios de EEG',
};
const titularTea = (panel: Panel): Panel => TITULOS_TEA[panel.item.id] ? { ...panel, item: { ...panel.item, titulo: TITULOS_TEA[panel.item.id] } } : panel;
const ORDEN_TEA = [...TIEMPOS, ...TEA_FIGURAS_CLINICAS, M30_RESULTADO_EEG];
function ordenar(paneles: Panel[], orden: readonly string[]): Panel[] {
const lugar = (panel: Panel) => { const i = orden.indexOf(panel.item.id); return i < 0 ? orden.length : i; };
return paneles.map((panel, i) => ({ panel, i })).sort((a, b) => lugar(a.panel) - lugar(b.panel) || a.i - b.i).map(({ panel }) => panel);
@@ -128,7 +122,7 @@ function ordenar(paneles: Panel[], orden: readonly string[]): Panel[] {
@for (panel of paneles(); track panel.item.id) {
<article class="panel" [class.ancho]="panel.estado === 'listo' && panel.pasos" [attr.aria-busy]="panel.estado === 'cargando'">
@if (dominio() === 'tea' && panel.estado === 'listo' && panel.figura.comoLeer) {
<app-indicador-ayuda [etiqueta]="'Cómo leer: ' + panel.item.titulo"><p class="ayuda-texto">{{ panel.figura.comoLeer }}</p></app-indicador-ayuda>
<app-indicador-ayuda [etiqueta]="'Cómo leer: ' + panel.item.titulo"><p class="ayuda-texto">{{ panel.figura.comoLeer }}@if (panel.figura.notaMetodologica) { {{ panel.figura.notaMetodologica }} }</p></app-indicador-ayuda>
}
<h2>{{ panel.item.titulo }}</h2>
@if (panel.rango) { <p class="rango">{{ panel.rango }}</p> }
@@ -148,7 +142,7 @@ function ordenar(paneles: Panel[], orden: readonly string[]): Panel[] {
<div class="pasos">
@for (paso of pasos; track paso.titulo) {
<section><h3>{{ paso.titulo }}</h3>
<app-plotly-chart [style.--plot-height]="'340px'" [showNotes]="false" [figure]="paso.figura.figure" [label]="'Histórico de ' + paso.titulo + (panel.rango ? ', ' + panel.rango : '')" />
<app-plotly-chart [style.--plot-height]="'340px'" [showNotes]="false" [figure]="paso.figura.figure" [label]="etiquetaVista() + ' de ' + paso.titulo + (panel.rango ? ', ' + panel.rango : '')" />
</section>
}
</div>
@@ -165,7 +159,7 @@ function ordenar(paneles: Panel[], orden: readonly string[]): Panel[] {
}
}
<app-plotly-chart [style.--plot-height]="'400px'" [showNotes]="false" [figure]="vistas()[panel.item.id] ?? panel.figura.figure"
[label]="'Histórico de ' + panel.item.titulo + (panel.rango ? ', ' + panel.rango : '')" />
[label]="etiquetaVista() + ' de ' + panel.item.titulo + (panel.rango ? ', ' + panel.rango : '')" />
}
@if (panel.figura.comoLeer && dominio() !== 'tea') { <p class="nota">{{ panel.figura.comoLeer }}</p> }
@if (panel.figura.suprimidos.length) {
@@ -259,6 +253,7 @@ export class IndicadoresHistorico {
readonly catalogLoading = input(false);
readonly catalogError = input('');
readonly retryCatalog = output<void>();
readonly etiquetaVista = computed(() => 'Trazabilidad');
// What the domain declares for its history (`indicadores-historico-config`); none for a domain that draws its catalog.
private readonly config = computed(() => historicoDeDominio(this.dominio()));
// The indicators the tab draws: the domain's fixed list, where the catalog publishes it and the panel is active;
@@ -327,7 +322,7 @@ export class IndicadoresHistorico {
const visibles = this.recortar(carga.datos.periodos);
return carga.datos.filas.filter(f => visibles.includes(f['periodo'] as string)).map(f => (f['q3'] as number | null) ?? 0);
})) * 1.05;
const panelDe = (item: Indicador): Panel & { datos?: IndicadorDatos } => {
const panelDe = (item: Indicador): Panel => {
if (!item.tipos_periodo.includes(tipo)) return { item, estado: 'vacio' };
const carga = cargas?.[item.id];
if (!carga) return { item, estado: 'cargando' };
@@ -351,7 +346,7 @@ export class IndicadoresHistorico {
if (this.dominio() === 'cacu' && figura.sinDato.length === periodos.length) {
return { item, estado: mensaje ? 'error' : 'vacio', mensaje };
}
return { item, rango, estado: 'listo', figura, datos, mensaje };
return { item, rango, estado: 'listo', figura, mensaje };
} catch (error) {
return { item, rango, estado: 'error', mensaje: error instanceof Error ? error.message : 'Datos de histórico inválidos' };
}
@@ -370,8 +365,10 @@ export class IndicadoresHistorico {
return { ...panelDe(item), item: { ...visible, contrato: item.contrato } };
});
}
const paneles = agrupar(this.catalog().filter(item => item.tipos_periodo.includes(tipo)).map(panelDe), tema);
return this.dominio() === 'tea' ? ordenar(paneles, ORDEN_TEA).map(titularTea) : paneles;
const items = this.catalog().filter(item => item.tipos_periodo.includes(tipo));
if (this.dominio() !== 'tea') return items.map(panelDe);
const paneles = items.map(item => panelDe({ ...item, titulo: TITULOS_TEA[item.id] ?? item.titulo }));
return agruparTiempos(ordenar(paneles, ORDEN_TEA));
});
constructor() {