feat(seguimiento): list opened on a group of the cohort, with its window, cut-off, cohort and revision

The follow-up list of breast cancer can now be opened on a selection that the analysis names: the
whole cohort (window 0, offered only while the selection is active), the cut-off the analysis was
computed at, the group's filter, and the cohort with its revision, which the server requires and
repeats.

- A cohort's list quotes `cohorte`, `escenario` and `revision` (not filters) on every page and in the
  export; an answer that loses a filter, changes the window or the cut-off, or is another cohort or
  revision is not drawn and cannot be exported.
- A new selection cancels the previous request; while it loads, and when it fails (403, 409, 503),
  no list of the previous query stays on screen.
- Inside the cohort the form refines the same cohort and says so; "Quitar selección" leaves it.
- "Volver al análisis" and a note when the list holds a different number of patients than the
  analysis counted.
- PDF and XLSX state the selection, the cut-off and "Toda la cohorte"; the file name tells a
  selection apart; an export in progress is cancelled, and a finished one discarded, when the query
  on screen changes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Angel Capetillo Zavala
2026-11-13 14:07:31 -06:00
parent ee75e7a2a0
commit eb92b99a1d
13 changed files with 618 additions and 51 deletions
@@ -1,6 +1,6 @@
import { concatWith, defer, from, map, mergeMap, Observable, of, startWith, switchMap, tap } from 'rxjs';
import { Dominio } from '../indicadores.models';
import { PAGE_SIZE_MAX, SeguimientoTablaQuery, SeguimientoTablaResponse, SeguimientoTablaService } from '../seguimiento-tabla.service';
import { consultaAplicada, contextoDe, PAGE_SIZE_MAX, SeguimientoTablaQuery, SeguimientoTablaResponse, SeguimientoTablaService } from '../seguimiento-tabla.service';
import { ExportInconsistent, ExportLimitExceeded, TrackingExportEvent, TrackingRow } from './tracking-export.models';
const CONCURRENCY = 3;
@@ -13,17 +13,14 @@ export function queryOf(response: SeguimientoTablaResponse): SeguimientoTablaQue
page: 1,
page_size: PAGE_SIZE_MAX,
filtros: Object.fromEntries(Object.entries(response.filtros).filter(([, v]) => v !== null).map(([k, v]) => [k, v as string])),
// A cohort's list is exported as that cohort, at the revision it was read at: another revision is refused by the server.
contexto: contextoDe(response),
};
}
// The server must report having applied the window and the filters that were asked for; otherwise the file would
// hold rows of another query under the title of this one.
function sameQuery(query: SeguimientoTablaQuery, answer: SeguimientoTablaResponse): boolean {
const entries = (filters: Record<string, string | null | undefined>) =>
JSON.stringify(Object.entries(filters).filter(([, v]) => !!v).sort(([a], [b]) => a.localeCompare(b)));
return answer.ventana.meses === query.meses && (!query.corte || answer.corte === query.corte)
&& entries(query.filtros ?? {}) === entries(answer.filtros);
}
const sameQuery = consultaAplicada;
/**
* Reads every row a follow-up query matches, page by page, with the cut-off fixed by the first answer.
@@ -44,7 +41,7 @@ export function fetchAllTracking(service: SeguimientoTablaService, dominio: Domi
mergeMap(page => ask({ ...pinned, page }).pipe(map(answer => ({ page, answer }))), CONCURRENCY),
tap(({ page, answer }) => {
if (answer.paginacion.page !== page || answer.paginacion.total_items !== total || answer.paginacion.total_pages !== pages
|| answer.corte !== first.corte) throw new ExportInconsistent('The list changed while it was being read');
|| answer.corte !== first.corte || !sameQuery(pinned, answer)) throw new ExportInconsistent('The list changed while it was being read');
collected.set(page, answer.items);
}),
map((): TrackingExportEvent => ({ kind: 'progress', fetched: count(), total })),