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:
@@ -8,17 +8,34 @@ import { TrackingExportBar } from './export/tracking-export-bar';
|
||||
import { CamaPatientCard } from './paciente-detalle/cama/cama-patient-card';
|
||||
import { CamaPatientSummary, toCamaPatientSummary } from './paciente-detalle/cama/cama-patient.models';
|
||||
import {
|
||||
MESES_VENTANA, PAGE_SIZE_MAX, SeguimientoColumna, SeguimientoInvalido, SeguimientoTablaQuery, SeguimientoTablaResponse,
|
||||
SeguimientoTablaService, SeguimientoValor,
|
||||
consultaAplicada, ContextoLista, etiquetaVentana, MESES_VENTANA, MesesVentana, PAGE_SIZE_MAX, SeguimientoColumna, SeguimientoInvalido, SeguimientoTablaQuery,
|
||||
SeguimientoTablaResponse, SeguimientoTablaService, SeguimientoValor,
|
||||
} from './seguimiento-tabla.service';
|
||||
|
||||
type Estado = 'idle' | 'loading' | 'ready' | 'pending' | 'error';
|
||||
type Resultado = { estado: Estado; data?: SeguimientoTablaResponse; mensaje: string };
|
||||
interface Borrador { corte?: string; meses: 1 | 3 | 6 | 12; page_size: number; filtros: Record<string, string | undefined>; }
|
||||
type Resultado = { estado: Estado; data?: SeguimientoTablaResponse; mensaje: string; etiqueta?: string };
|
||||
/** A request with the name of the selection it belongs to, so the answer and its name can never be told apart. */
|
||||
type Consulta = { q: SeguimientoTablaQuery; etiqueta?: string };
|
||||
// What the analysis sends: the whole published group, the cut-off it was computed at, the cohort (and its revision) the
|
||||
// list must quote back, how to name it, how many patients the analysis counts there and an id that changes with each click.
|
||||
export interface SeleccionSeguimiento {
|
||||
filtros: Record<string, string>; etiqueta: string; corte?: string; esperados?: number | null; contexto?: ContextoLista; id: number;
|
||||
}
|
||||
const ETIQUETA_COHORTE = 'Cohorte del análisis epidemiológico';
|
||||
/** The answer does not apply the cut-off, window or filters that were asked for: it is neither shown nor exported. */
|
||||
export class SeguimientoNoCoincide extends Error {}
|
||||
|
||||
interface Borrador { corte?: string; meses: MesesVentana; page_size: number; filtros: Record<string, string | undefined>; }
|
||||
|
||||
const mismosFiltros = (a: Record<string, string | undefined>, b: Record<string, string | undefined>) => {
|
||||
const f = (x: Record<string, string | undefined>) => JSON.stringify(Object.entries(x).filter(([, v]) => !!v).sort(([k], [l]) => k.localeCompare(l)));
|
||||
return f(a) === f(b);
|
||||
};
|
||||
|
||||
/**
|
||||
* Follow-up list of a domain, drawn from what `GET /<dominio>/seguimiento` announces: the filters, the columns
|
||||
* and their details come with the answer. Nothing is requested until the tab is opened.
|
||||
* and their details come with the answer. Nothing is requested until the tab is opened. The analysis can open it
|
||||
* on a selection (a published group, whole cohort); the list keeps it until it is removed or the domain changes.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-seguimiento-tabla',
|
||||
@@ -31,13 +48,25 @@ interface Borrador { corte?: string; meses: 1 | 3 | 6 | 12; page_size: number; f
|
||||
<div class="title-row">
|
||||
<h2>Seguimiento de {{ domainLabel }}</h2>
|
||||
@if (data(); as respuesta) {
|
||||
<app-seguimiento-exportar [dominio]="dominio" [respuesta]="respuesta" [habilitado]="estado() === 'ready'" />
|
||||
<app-seguimiento-exportar [dominio]="dominio" [respuesta]="respuesta" [habilitado]="estado() === 'ready'" [seleccion]="etiquetaDatos()" />
|
||||
}
|
||||
</div>
|
||||
@if (seleccionMostrada(); as sel) {
|
||||
<div class="seleccion" role="status">
|
||||
@if (seleccionExacta()) {
|
||||
<span>Pacientes de la selección del análisis epidemiológico: <strong>{{ sel }}</strong>. {{ etiquetaVentana(0) }}@if (corteSeleccion()) {, corte {{ corteSeleccion() }}}.</span>
|
||||
} @else {
|
||||
<span>Pacientes de la cohorte del análisis epidemiológico@if (corteSeleccion()) {, corte {{ corteSeleccion() }}}. Los filtros y la ventana son los de esta consulta.</span>
|
||||
}
|
||||
<button type="button" class="volver" (click)="volverAlAnalisis.emit()">Volver al análisis</button>
|
||||
<button type="button" (click)="quitarSeleccion()">Quitar selección</button>
|
||||
</div>
|
||||
@if (diferencia(); as d) { <p class="diferencia" role="status">{{ d }}</p> }
|
||||
}
|
||||
<form (ngSubmit)="aplicar()">
|
||||
<label>Fecha de corte <input name="corte" type="date" [(ngModel)]="draft.corte" /></label>
|
||||
<label>Ventana de meses <select name="meses" [(ngModel)]="draft.meses">
|
||||
@for (m of ventanas; track m) { <option [ngValue]="m">{{ m }} {{ m === 1 ? 'mes' : 'meses' }}</option> }
|
||||
@for (m of ventanas(); track m) { <option [ngValue]="m">{{ etiquetaVentana(m) }}</option> }
|
||||
</select></label>
|
||||
@for (filtro of filtros(); track filtro.clave) {
|
||||
<label>{{ filtro.etiqueta }} <select [name]="'filtro-' + filtro.clave" [(ngModel)]="draft.filtros[filtro.clave]">
|
||||
@@ -60,7 +89,7 @@ interface Borrador { corte?: string; meses: 1 | 3 | 6 | 12; page_size: number; f
|
||||
}
|
||||
}
|
||||
@if (data(); as respuesta) {
|
||||
<p>Ventana consultada: {{ respuesta.ventana.desde }} al {{ respuesta.ventana.hasta }}.</p>
|
||||
<p>Ventana consultada: {{ respuesta.ventana.meses === 0 ? etiquetaVentana(0) + ', al ' + respuesta.ventana.hasta : respuesta.ventana.desde + ' al ' + respuesta.ventana.hasta }}.</p>
|
||||
<div class="tracking-table" role="region" aria-label="Lista de seguimiento" tabindex="0">
|
||||
<table>
|
||||
<caption>Resultados disponibles por paciente</caption>
|
||||
@@ -107,6 +136,11 @@ interface Borrador { corte?: string; meses: 1 | 3 | 6 | 12; page_size: number; f
|
||||
.patient-link { min-height: 44px; padding: .35rem .5rem; border: 0; border-radius: var(--issste-radius); background: transparent; color: var(--issste-accent);
|
||||
font: inherit; font-weight: 600; text-align: left; text-decoration: underline; text-underline-offset: .15em; cursor: pointer; }
|
||||
.patient-link:focus-visible { outline: 2px solid var(--issste-accent); outline-offset: 2px; }
|
||||
.seleccion { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1rem; padding: .5rem .75rem;
|
||||
border-left: 4px solid var(--issste-accent); background: var(--issste-surface); color: var(--issste-text); }
|
||||
.seleccion span { overflow-wrap: anywhere; min-width: 0; }
|
||||
.diferencia { margin: 0 0 1rem; overflow-wrap: anywhere; }
|
||||
@media (max-width: 600px) { .title-row { gap: .5rem; } form label, form input, form select { width: 100%; } }
|
||||
`,
|
||||
})
|
||||
export class IndicadoresSeguimientoTabla implements OnChanges {
|
||||
@@ -114,34 +148,65 @@ export class IndicadoresSeguimientoTabla implements OnChanges {
|
||||
@Input() active = false;
|
||||
/** Domain name for the section title, which sits in the same row as the export buttons. */
|
||||
@Input() domainLabel = '';
|
||||
// The patients of a curve or a heatmap cell of the analysis; a new `id` applies it again.
|
||||
@Input() seleccion?: SeleccionSeguimiento;
|
||||
private readonly service = inject(SeguimientoTablaService);
|
||||
private readonly injector = inject(Injector);
|
||||
/** Tells the page that an individual record replaced the list, so it can retitle itself. */
|
||||
readonly fichaAbierta = output<boolean>();
|
||||
/** The way back to the analysis the selection came from. */
|
||||
readonly volverAlAnalisis = output<void>();
|
||||
readonly ficha = signal<CamaPatientSummary | undefined>(undefined);
|
||||
private controlFicha?: HTMLElement;
|
||||
private readonly consultas = new Subject<SeguimientoTablaQuery | null>();
|
||||
readonly ventanas = MESES_VENTANA;
|
||||
private readonly consultas = new Subject<Consulta | null>();
|
||||
readonly etiquetaVentana = etiquetaVentana;
|
||||
readonly tamanoMaximo = PAGE_SIZE_MAX;
|
||||
readonly estado = signal<Estado>('idle');
|
||||
readonly mensaje = signal('');
|
||||
readonly data = signal<SeguimientoTablaResponse | undefined>(undefined);
|
||||
/** The name of the selection the list on screen was asked for; it is set with the answer, never ahead of it. */
|
||||
readonly etiquetaDatos = signal<string | undefined>(undefined);
|
||||
/** The selection of the query now applied (what the banner says). */
|
||||
readonly seleccionMostrada = signal<string | undefined>(undefined);
|
||||
/** Whether the list is still exactly the analysis' group (its filters, whole cohort, its cut-off) and not a refinement of the cohort. */
|
||||
readonly seleccionExacta = signal(false);
|
||||
readonly corteSeleccion = signal<string | undefined>(undefined);
|
||||
readonly filtros = signal<SeguimientoTablaResponse['filtros_disponibles']>([]);
|
||||
draft: Borrador = { meses: 3, page_size: 50, filtros: {} };
|
||||
// The last query that was sent: the pages and the retry go from it, not from what is being edited.
|
||||
private applied: SeguimientoTablaQuery = { meses: 3, page: 1, page_size: 50 };
|
||||
private appliedEtiqueta?: string;
|
||||
private activa?: SeleccionSeguimiento;
|
||||
/** The cohort the list is read from while the analysis' selection is active; every query quotes it. */
|
||||
private contextoActivo?: ContextoLista;
|
||||
private seleccionAplicada?: number;
|
||||
private iniciado = false;
|
||||
private previo?: Dominio;
|
||||
|
||||
/** «Toda la cohorte» is offered while the analysis' cohort is active (or the form still holds it), never as a plain window. */
|
||||
ventanas() { return this.contextoActivo || this.draft.meses === 0 ? MESES_VENTANA : MESES_VENTANA.filter(m => m !== 0); }
|
||||
/** What the list says when it does not hold as many patients as the analysis counted for the selection. */
|
||||
diferencia() {
|
||||
const esperados = this.activa?.esperados, total = this.data()?.paginacion.total_items;
|
||||
if (!this.seleccionExacta() || this.estado() !== 'ready' || esperados == null || total === undefined || esperados === total) return undefined;
|
||||
return `El análisis cuenta ${esperados} pacientes en esta selección; la lista muestra ${total}.`;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.consultas.pipe(
|
||||
switchMap((q): Observable<Resultado> => {
|
||||
if (!q) return of({ estado: 'idle', mensaje: '' });
|
||||
switchMap((c): Observable<Resultado> => {
|
||||
if (!c) return of({ estado: 'idle', mensaje: '' });
|
||||
const { q, etiqueta } = c;
|
||||
let peticion: Observable<SeguimientoTablaResponse>;
|
||||
// An invalid query never leaves the browser; it reads like the server's own 400.
|
||||
try { peticion = this.service.consultar(this.dominio, q); } catch { return of({ estado: 'error', mensaje: 'Revisa la fecha, la ventana, el tamaño de página y los filtros seleccionados.' }); }
|
||||
return peticion.pipe(
|
||||
map((data): Resultado => ({ estado: 'ready', data, mensaje: '' })),
|
||||
// A selection names its patients: an answer that does not apply its window, cut-off and every filter is dropped,
|
||||
// because its rows would pass for the analysis' group. A plain query shows what the answer says it applied.
|
||||
map((data): Resultado => {
|
||||
if ((etiqueta || q.contexto) && !consultaAplicada(q, data)) throw new SeguimientoNoCoincide('La respuesta no corresponde a la consulta');
|
||||
return { estado: 'ready', data, mensaje: '', etiqueta };
|
||||
}),
|
||||
catchError(error => of(this.fallo(error, q))),
|
||||
startWith<Resultado>({ estado: 'loading', mensaje: '' }));
|
||||
}),
|
||||
@@ -149,8 +214,11 @@ export class IndicadoresSeguimientoTabla implements OnChanges {
|
||||
).subscribe(r => {
|
||||
this.estado.set(r.estado);
|
||||
this.mensaje.set(r.mensaje);
|
||||
if (r.estado === 'idle') { this.data.set(undefined); this.filtros.set([]); }
|
||||
if (r.data) this.recibir(r.data);
|
||||
if (r.estado === 'idle') { this.data.set(undefined); this.etiquetaDatos.set(undefined); this.filtros.set([]); }
|
||||
// In the analysis' cohort a query that fails (or whose answer does not match) leaves no list on screen: the rows
|
||||
// of the previous query would pass for the one the banner names.
|
||||
if ((r.estado === 'error' || r.estado === 'pending') && (this.contextoActivo || r.mensaje === MENSAJE_NO_COINCIDE)) { this.data.set(undefined); this.etiquetaDatos.set(undefined); }
|
||||
if (r.data) { this.recibir(r.data); this.etiquetaDatos.set(r.etiqueta); }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -159,14 +227,32 @@ export class IndicadoresSeguimientoTabla implements OnChanges {
|
||||
if (this.ficha()) { this.ficha.set(undefined); this.controlFicha = undefined; this.fichaAbierta.emit(false); }
|
||||
this.previo = this.dominio; this.iniciado = false; this.consultas.next(null);
|
||||
this.draft = { meses: 3, page_size: 50, filtros: {} }; this.applied = { meses: 3, page: 1, page_size: 50 };
|
||||
// The selection belongs to the domain it was made in.
|
||||
this.appliedEtiqueta = undefined; this.activa = undefined; this.contextoActivo = undefined; this.seleccionAplicada = undefined;
|
||||
this.seleccionMostrada.set(undefined); this.seleccionExacta.set(false); this.corteSeleccion.set(undefined); this.etiquetaDatos.set(undefined);
|
||||
}
|
||||
if (this.active && !this.iniciado) { this.iniciado = true; this.consultas.next(this.applied); }
|
||||
const sel = this.seleccion;
|
||||
if (this.active && sel && sel.id !== this.seleccionAplicada) {
|
||||
this.seleccionAplicada = sel.id; this.iniciado = true; this.activa = sel; this.contextoActivo = sel.contexto;
|
||||
// Whatever was on screen belongs to another query: it goes before the selection is asked for.
|
||||
this.data.set(undefined); this.etiquetaDatos.set(undefined);
|
||||
if (this.ficha()) { this.ficha.set(undefined); this.controlFicha = undefined; this.fichaAbierta.emit(false); }
|
||||
this.draft = { ...this.draft, meses: 0, corte: sel.corte ?? this.draft.corte, filtros: { ...sel.filtros } };
|
||||
this.aplicar(sel.etiqueta);
|
||||
return;
|
||||
}
|
||||
if (this.active && !this.iniciado) { this.iniciado = true; this.consultas.next({ q: this.applied }); }
|
||||
}
|
||||
|
||||
private fallo(error: unknown, q: SeguimientoTablaQuery): Resultado {
|
||||
// A first page that does not exist yet is the list's own pending state; a later page that fails is an error.
|
||||
if (error instanceof HttpErrorResponse && error.status === 404 && q.page === 1) return { estado: 'pending', mensaje: '' };
|
||||
if (error instanceof HttpErrorResponse && error.status === 400) return { estado: 'error', mensaje: 'Revisa la fecha, la ventana y los filtros seleccionados.' };
|
||||
// A cohort's list: the group was too small to publish or access was not granted; the cohort changed after the count; or it is not configured.
|
||||
if (error instanceof HttpErrorResponse && error.status === 403) return { estado: 'error', mensaje: 'Esta lista no está disponible: no hay acceso, o la selección tiene muy pocos pacientes para publicarse.' };
|
||||
if (error instanceof HttpErrorResponse && error.status === 409) return { estado: 'error', mensaje: 'La cohorte cambió desde que se calculó el análisis. Vuelve al análisis, consúltalo de nuevo y abre otra vez el grupo.' };
|
||||
if (error instanceof HttpErrorResponse && error.status === 503) return { estado: 'error', mensaje: 'La cohorte no está disponible en este momento. Intenta nuevamente más tarde.' };
|
||||
if (error instanceof SeguimientoNoCoincide) return { estado: 'error', mensaje: MENSAJE_NO_COINCIDE };
|
||||
if (error instanceof SeguimientoInvalido) return { estado: 'error', mensaje: 'La respuesta del servicio no tiene el formato esperado.' };
|
||||
return { estado: 'error', mensaje: 'No se pudo consultar el seguimiento. Intenta nuevamente.' };
|
||||
}
|
||||
@@ -179,14 +265,32 @@ export class IndicadoresSeguimientoTabla implements OnChanges {
|
||||
filtros: Object.fromEntries(Object.entries(data.filtros).filter(([, v]) => v !== null).map(([k, v]) => [k, v as string])) };
|
||||
this.draft.meses = data.ventana.meses; this.draft.page_size = data.paginacion.page_size;
|
||||
}
|
||||
aplicar() {
|
||||
// The form applies what it holds. The banner stays only while that is still the analysis' selection, whole cohort
|
||||
// included; anything else is the user's own query, with a window of months.
|
||||
aplicar(seleccion?: string) {
|
||||
const filtros = Object.fromEntries(Object.entries(this.draft.filtros).filter(([, v]) => !!v)) as Record<string, string>;
|
||||
const q: SeguimientoTablaQuery = { corte: this.draft.corte || undefined, meses: this.draft.meses, page: 1, page_size: Number(this.draft.page_size), filtros };
|
||||
const activa = this.activa, contexto = this.contextoActivo;
|
||||
const exacta = !!seleccion || (!!activa && this.draft.meses === 0 && mismosFiltros(filtros, activa.filtros) && (!activa.corte || this.draft.corte === activa.corte));
|
||||
// In the analysis' cohort the form refines the same cohort (and quotes its revision); outside it, a plain query has a window of months.
|
||||
const etiqueta = seleccion ?? (exacta ? activa!.etiqueta : contexto ? ETIQUETA_COHORTE : undefined);
|
||||
if (!contexto && this.draft.meses === 0) this.draft = { ...this.draft, meses: 3 };
|
||||
this.seleccionMostrada.set(etiqueta);
|
||||
this.seleccionExacta.set(!!etiqueta && exacta);
|
||||
this.corteSeleccion.set(etiqueta ? this.draft.corte || activa?.corte : undefined);
|
||||
this.appliedEtiqueta = etiqueta;
|
||||
const q: SeguimientoTablaQuery = { corte: this.draft.corte || undefined, meses: this.draft.meses, page: 1, page_size: Number(this.draft.page_size), filtros, contexto };
|
||||
// A new query of the cohort starts from nothing on screen: what was there belongs to the previous one.
|
||||
if (contexto) { this.data.set(undefined); this.etiquetaDatos.set(undefined); }
|
||||
this.applied = q;
|
||||
this.consultas.next(q);
|
||||
this.consultas.next({ q, etiqueta });
|
||||
}
|
||||
ir(page: number) { if (page >= 1) this.consultas.next(this.applied = { ...this.applied, page }); }
|
||||
reintentar() { this.consultas.next(this.applied); }
|
||||
quitarSeleccion() {
|
||||
this.draft = { ...this.draft, meses: 3, filtros: {} };
|
||||
this.activa = undefined; this.contextoActivo = undefined;
|
||||
this.aplicar();
|
||||
}
|
||||
ir(page: number) { if (page >= 1) this.consultas.next({ q: this.applied = { ...this.applied, page }, etiqueta: this.appliedEtiqueta }); }
|
||||
reintentar() { this.consultas.next({ q: this.applied, etiqueta: this.appliedEtiqueta }); }
|
||||
abrirFicha(item: Record<string, SeguimientoValor>, evento: Event) {
|
||||
const origen = evento.target instanceof HTMLElement ? evento.target : null;
|
||||
// A click on the row opens the record unless it landed on another control; the id button always does.
|
||||
@@ -208,3 +312,5 @@ export class IndicadoresSeguimientoTabla implements OnChanges {
|
||||
detalles(c: SeguimientoColumna) { return c.detalles ?? []; }
|
||||
texto(v: SeguimientoValor | undefined) { return v === null || v === undefined ? 'No disponible' : String(v); }
|
||||
}
|
||||
|
||||
const MENSAJE_NO_COINCIDE = 'La respuesta del servicio no corresponde a la selección consultada, por lo que no se muestra. Intenta nuevamente.';
|
||||
|
||||
Reference in New Issue
Block a user