CaCu history: no reserved panels, no notice, and widening the periods twice no longer drops the second answer

The times to treatment and the risk by band had a reserved panel each, and the tab carried a notice about clinical
validation: both go. Widening the window from 5 to 10 to 'Todos' before the first answer arrived dropped the second
answer (it was compared with the load it started from), so the periods did not update. An answer now joins whatever
load is current, and a period two widenings asked for is kept once.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 03:54:00 -06:00
parent a15e37ed77
commit 3e3ec5fd03
8 changed files with 52 additions and 66 deletions
@@ -28,9 +28,12 @@ const CASOS = 'M28_casos_por_estado';
const PERSONALIZADO = -1;
// What two answers for the same indicator give together: the periods, rows and reports of both.
function unir(a: IndicadorDatos, b: IndicadorDatos): IndicadorDatos {
const reportes = [...(Array.isArray(a['reportes']) ? a['reportes'] : []), ...(Array.isArray(b['reportes']) ? b['reportes'] : [])];
// A period both have (two widenings asked for it) is kept once, from `a`.
const nuevos = b.periodos.filter(p => !a.periodos.includes(p));
const deNuevos = (fila: unknown) => !fila || typeof fila !== 'object' || !('periodo' in fila) || nuevos.includes(String((fila as { periodo: unknown }).periodo));
const reportes = [...(Array.isArray(a['reportes']) ? a['reportes'] : []), ...(Array.isArray(b['reportes']) ? b['reportes'].filter(deNuevos) : [])];
const unidades = { ...(a['unidades_periodo'] as object | undefined), ...(b['unidades_periodo'] as object | undefined) };
return { ...a, periodos: [...a.periodos, ...b.periodos.filter(p => !a.periodos.includes(p))], filas: [...a.filas, ...b.filas],
return { ...a, periodos: [...a.periodos, ...nuevos], filas: [...a.filas, ...b.filas.filter(deNuevos)],
...(reportes.length ? { reportes } : {}), ...(a['unidades_periodo'] || b['unidades_periodo'] ? { unidades_periodo: unidades } : {}) };
}
@@ -331,13 +334,19 @@ export class IndicadoresHistorico {
const faltan = this.necesarios(carga.disponibles).filter(p => !carga.datos.periodos.includes(p));
if (!faltan.length) continue;
this.service.datos(this.dominio(), item.id, tipo, faltan).pipe(takeUntilDestroyed(this.destruccion)).subscribe({
// The load may have been replaced by an earlier widening's answer: what counts is that the item is still ready, and
// `unir` keeps a period once if two widenings asked for it. Comparing with the load this request started from
// dropped the second answer when the first arrived before it (5 -> 10 -> Todos).
next: datos => this.cargas.update(actual => {
const vigente = actual[tipo]?.[item.id];
return vigente?.estado === 'listo' && vigente === carga
return vigente?.estado === 'listo'
? { ...actual, [tipo]: { ...actual[tipo], [item.id]: { ...vigente, datos: unir(vigente.datos, datos) } } } : actual;
}),
error: error => this.cargas.update(actual => actual[tipo]?.[item.id] === carga
? { ...actual, [tipo]: { ...actual[tipo], [item.id]: { estado: 'error', mensaje: httpMessage(error) } } } : actual),
error: error => this.cargas.update(actual => {
const vigente = actual[tipo]?.[item.id];
return vigente?.estado === 'listo' && faltan.some(p => !vigente.datos.periodos.includes(p))
? { ...actual, [tipo]: { ...actual[tipo], [item.id]: { estado: 'error', mensaje: httpMessage(error) } } } : actual;
}),
});
}
}