365 lines
26 KiB
TypeScript
365 lines
26 KiB
TypeScript
import { afterNextRender, Component, DestroyRef, inject, Injector, Input, OnChanges, output, signal } from '@angular/core';
|
|
import { FormsModule } from '@angular/forms';
|
|
import { HttpErrorResponse } from '@angular/common/http';
|
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
import { catchError, map, Observable, of, startWith, Subject, switchMap } from 'rxjs';
|
|
import { Dominio } from './indicadores.models';
|
|
import { columnaEnlace, IdentidadPaciente, identidadDe } from './paciente-identidad';
|
|
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 {
|
|
consultaAplicada, ContextoLista, contextoDe, etiquetaVentana, MESES_VENTANA, MesesVentana, acotarTamano, 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; etiqueta?: string; estatus?: number };
|
|
/** 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, the window of months it was computed over (0: the whole cohort), 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; meses?: number; 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. 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',
|
|
imports: [FormsModule, TrackingExportBar, CamaPatientCard],
|
|
template: `
|
|
@if (ficha(); as patient) {
|
|
<app-cama-patient-card [summary]="patient" (back)="cerrarFicha()" />
|
|
}
|
|
<div [hidden]="!!ficha()">
|
|
<div class="title-row">
|
|
<h2>Análisis de riesgos</h2>
|
|
@if (data(); as respuesta) {
|
|
<app-seguimiento-exportar [dominio]="dominio" [respuesta]="respuesta" [habilitado]="estado() === 'ready' && !diferencia()" [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="alert">{{ 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">{{ 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]">
|
|
<option [ngValue]="undefined">Todos</option>
|
|
@for (o of filtro.opciones; track o.codigo) { <option [value]="o.codigo">{{ o.etiqueta }}</option> }
|
|
</select></label>
|
|
}
|
|
<label>Registros por página <input name="size" type="number" min="1" [max]="tamanoMaximo" required [(ngModel)]="draft.page_size" (change)="draft.page_size = acotar(draft.page_size)" /></label>
|
|
<button type="submit" [disabled]="estado() === 'loading'">Consultar</button>
|
|
</form>
|
|
@switch (estado()) {
|
|
@case ('loading') { <p role="status">Cargando seguimiento…</p> }
|
|
@case ('pending') {
|
|
<p role="status">El seguimiento aún no está disponible para esta consulta. Funcionalidad pendiente de publicación.</p>
|
|
<button type="button" (click)="reintentar()">Reintentar seguimiento</button>
|
|
}
|
|
@case ('error') {
|
|
<p role="alert">{{ mensaje() }}</p>
|
|
<button type="button" (click)="reintentar()">Reintentar seguimiento</button>
|
|
}
|
|
}
|
|
@if (data(); as respuesta) {
|
|
<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>
|
|
<thead><tr>@for (c of respuesta.columnas; track c.clave) { <th scope="col">{{ c.etiqueta }}</th> }</tr></thead>
|
|
<tbody>
|
|
@for (item of respuesta.items; track identidad(item).id) {
|
|
<tr tabindex="-1" [attr.data-paciente]="identidad(item).id" (click)="abrirFicha(item, $event)">
|
|
@for (c of respuesta.columnas; track c.clave) {
|
|
<td>@if (c.clave === claveEnlace(respuesta, item)) { <button class="patient-link" type="button" [attr.aria-label]="'Ver ficha del paciente ' + identidad(item).id" (click)="abrirFicha(item, $event)">{{ texto(item[c.clave]) }}</button> } @else { {{ texto(item[c.clave]) }} }@for (d of detalles(c); track d.clave) { @if (item[d.clave] !== null && item[d.clave] !== undefined) { <small>{{ d.etiqueta }}: {{ texto(item[d.clave]) }}</small> } }</td>
|
|
}
|
|
</tr>
|
|
} @empty { <tr><td [attr.colspan]="respuesta.columnas.length">{{ textoVacio(respuesta) }}</td></tr> }
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<nav aria-label="Paginación de seguimiento">
|
|
<button type="button" [disabled]="respuesta.paginacion.page <= 1 || estado() === 'loading'" (click)="ir(respuesta.paginacion.page - 1)">Anterior</button>
|
|
<span>Página {{ respuesta.paginacion.page }} de {{ respuesta.paginacion.total_pages }}, {{ respuesta.paginacion.total_items }} registros</span>
|
|
<button type="button" [disabled]="respuesta.paginacion.page >= respuesta.paginacion.total_pages || estado() === 'loading'" (click)="ir(respuesta.paginacion.page + 1)">Siguiente</button>
|
|
</nav>
|
|
}
|
|
</div>
|
|
`,
|
|
styles: `
|
|
:host { display: block; min-width: 0; }
|
|
p { color: var(--issste-text-secondary); }
|
|
.title-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-bottom: 1rem; }
|
|
.title-row h2 { margin: 0; margin-inline-end: auto; }
|
|
form { display: flex; flex-wrap: wrap; align-items: end; gap: 1rem; margin-bottom: 1rem; }
|
|
label { display: flex; flex-direction: column; gap: .5rem; max-width: 100%; }
|
|
input, select, button { color: inherit; background: var(--issste-surface); border: 1px solid var(--issste-border); border-radius: 4px;
|
|
padding: .6rem; min-height: 44px; box-sizing: border-box; font: inherit; max-width: 100%; }
|
|
button { cursor: pointer; } button:disabled { opacity: .5; cursor: default; }
|
|
input:focus-visible, select:focus-visible, button:focus-visible, .tracking-table:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
|
|
.tracking-table { overflow-x: auto; border: 1px solid var(--issste-border); border-radius: var(--issste-radius); }
|
|
table { width: 100%; min-width: 60rem; border-collapse: collapse; background: var(--issste-surface); }
|
|
caption { text-align: start; padding: 1rem; }
|
|
th, td { text-align: start; vertical-align: top; padding: 1rem; border-top: 1px solid var(--issste-border); }
|
|
th { background: var(--issste-background); font-weight: 600; }
|
|
small { display: block; margin-top: .35rem; }
|
|
nav { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; margin-top: 1rem; }
|
|
tbody tr[data-paciente] { cursor: pointer; transition: background-color 120ms ease; }
|
|
tbody tr[data-paciente]:hover { background-color: color-mix(in srgb, var(--issste-accent) 7%, transparent); }
|
|
.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 {
|
|
@Input({ required: true }) dominio!: Dominio;
|
|
@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<Consulta | null>();
|
|
readonly etiquetaVentana = etiquetaVentana;
|
|
readonly tamanoMaximo = PAGE_SIZE_MAX;
|
|
readonly acotar = acotarTamano;
|
|
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. With the same
|
|
* cohort revision, cut-off and filter the server counts both from the same rows, so a difference breaks the contract:
|
|
* the list stays visible, but it is not exported as if it were the group that was counted.
|
|
*/
|
|
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 y la lista muestra ${total}. No coinciden, por lo que este resultado no se puede exportar.`;
|
|
}
|
|
|
|
// The cut-off of the cohort's revision: another cut-off is another cohort at that date, so its revision is not quoted.
|
|
private contextoCorte?: string;
|
|
// A cohort that changed under a plain list is read again once, without the old revision, before it is reported.
|
|
private reintentoHecho = false;
|
|
|
|
/** The list of one query, as the server answers it (without the loading state). */
|
|
private lista(c: Consulta): Observable<Resultado> {
|
|
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(
|
|
// 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))));
|
|
}
|
|
|
|
constructor() {
|
|
this.consultas.pipe(
|
|
switchMap((c): Observable<Resultado> => {
|
|
if (!c) return of({ estado: 'idle', mensaje: '' });
|
|
return this.lista(c).pipe(startWith<Resultado>({ estado: 'loading', mensaje: '' }));
|
|
}),
|
|
takeUntilDestroyed(inject(DestroyRef)),
|
|
).subscribe(r => {
|
|
// The cohort changed under a plain list: the same query is asked again, once, without the old revision, before the user hears of it.
|
|
if (r.estatus === 409 && !this.activa && this.contextoActivo && !this.reintentoHecho) {
|
|
this.reintentoHecho = true;
|
|
this.consultas.next({ q: { ...this.applied, contexto: undefined }, etiqueta: this.appliedEtiqueta });
|
|
return;
|
|
}
|
|
if (r.estado === 'ready') this.reintentoHecho = false;
|
|
this.estado.set(r.estado);
|
|
this.mensaje.set(r.mensaje);
|
|
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); }
|
|
});
|
|
}
|
|
|
|
ngOnChanges() {
|
|
if (this.previo !== this.dominio) {
|
|
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.contextoCorte = undefined; this.reintentoHecho = false;
|
|
this.seleccionMostrada.set(undefined); this.seleccionExacta.set(false); this.corteSeleccion.set(undefined); this.etiquetaDatos.set(undefined);
|
|
}
|
|
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; this.contextoCorte = sel.corte;
|
|
this.reintentoHecho = false;
|
|
// 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: (sel.meses ?? 0) as MesesVentana, 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 {
|
|
return { ...this.falloBase(error, q), estatus: error instanceof HttpErrorResponse ? error.status : undefined };
|
|
}
|
|
private falloBase(error: unknown, q: SeguimientoTablaQuery): Resultado {
|
|
if (error instanceof HttpErrorResponse && error.status === 404 && this.dominio === 'cama') return { estado: 'error', mensaje: 'La cohorte no está disponible en este momento. Intenta nuevamente más tarde.' };
|
|
// 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.' };
|
|
}
|
|
// The answer says which filters exist and what was applied: the form follows it.
|
|
private recibir(data: SeguimientoTablaResponse) {
|
|
this.data.set(data); this.filtros.set(data.filtros_disponibles);
|
|
const claves = new Set(data.filtros_disponibles.map(f => f.clave));
|
|
this.draft = { ...this.draft, corte: data.corte, filtros: Object.fromEntries(Object.entries(this.draft.filtros).filter(([k]) => claves.has(k))) };
|
|
this.applied = { ...this.applied, corte: data.corte, meses: data.ventana.meses, page: data.paginacion.page, page_size: data.paginacion.page_size,
|
|
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;
|
|
// A list read from the cohort says which one (and its revision): the next pages and the files quote it.
|
|
this.contextoActivo = contextoDe(data); this.contextoCorte = data.corte;
|
|
this.applied = { ...this.applied, contexto: this.contextoActivo };
|
|
}
|
|
// 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 activa = this.activa, contexto = this.contextoActivo;
|
|
const exacta = !!seleccion || (!!activa && this.draft.meses === (activa.meses ?? 0) && mismosFiltros(filtros, activa.filtros) && (!activa.corte || this.draft.corte === activa.corte));
|
|
// In the cohort the form refines the same cohort (and quotes its revision); outside it, a plain query has a window of months.
|
|
// The banner names the analysis' selection, or the cohort of the analysis once the user has refined it.
|
|
const etiqueta = seleccion ?? (exacta ? activa!.etiqueta : contexto && activa ? 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;
|
|
// Another cut-off is another cohort at that date: its revision is not quoted, the answer brings the new one.
|
|
const otroCorte = !!contexto && !seleccion && !!this.draft.corte && this.draft.corte !== this.contextoCorte;
|
|
const q: SeguimientoTablaQuery = { corte: this.draft.corte || undefined, meses: this.draft.meses, page: 1, page_size: acotarTamano(this.draft.page_size), filtros,
|
|
contexto: otroCorte ? undefined : 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, etiqueta });
|
|
}
|
|
// Leaving the analysis' selection returns to the habitual list: the regular window, no filters, the cohort's new revision.
|
|
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.
|
|
if (evento.currentTarget instanceof HTMLTableRowElement && origen?.closest('button, a, input, select, textarea')) return;
|
|
const corte = this.data()?.corte;
|
|
const resumen = corte ? toCamaPatientSummary(item, corte, this.data()?.columnas) : null;
|
|
if (!resumen || this.estado() !== 'ready') return;
|
|
evento.stopPropagation();
|
|
this.controlFicha = evento.currentTarget instanceof HTMLElement ? evento.currentTarget : undefined;
|
|
this.ficha.set(resumen);
|
|
this.fichaAbierta.emit(true);
|
|
}
|
|
cerrarFicha() {
|
|
this.ficha.set(undefined);
|
|
this.fichaAbierta.emit(false);
|
|
const control = this.controlFicha;
|
|
afterNextRender(() => { if (control?.isConnected) control.focus({ preventScroll: true }); }, { injector: this.injector });
|
|
}
|
|
// The cohort answers an empty page only for a whole cohort without filters that has no patient at the cut-off.
|
|
textoVacio(r: SeguimientoTablaResponse) {
|
|
const sinFiltros = Object.values(r.filtros).every(v => !v);
|
|
return r.cohorte && r.ventana.meses === 0 && sinFiltros ? 'Sin pacientes para el corte seleccionado.' : 'No hay registros para los filtros aplicados.';
|
|
}
|
|
detalles(c: SeguimientoColumna) { return c.detalles ?? []; }
|
|
// Every row of a shown answer has an identity: the answer is validated before it reaches the view.
|
|
identidad(item: Record<string, SeguimientoValor>): IdentidadPaciente { return identidadDe(item)!; }
|
|
claveEnlace(r: SeguimientoTablaResponse, item: Record<string, SeguimientoValor>) { return columnaEnlace(r.columnas, this.identidad(item).campo); }
|
|
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.';
|