3aba7fe329
How: CaCu's confirmation view (rates per row with their horizontal Wilson interval, and a donut of biopsy results whose buttons choose what the rates count) takes a VistaConfirmacion: indicator id, stratum, fixed rows (most severe on top), the grade whose group is the base view, the grade read as a false positive, and its words. CONFIRMACION_CACU reproduces the previous behaviour exactly; CONFIRMACION_CAMA reads cama_histopatologia_birads by BI-RADS 6, 5, 4C, 4B and 4A, with "Maligno" (the group of INVASOR) as the base, so the base rate is the cancer detection rate, and "Benigno" alone reads as false positives. The catalog card chooses the view with vistaConfirmacion(dominio, indicador). Implications: the backend must publish cama_histopatologia_birads stratified by `birads`, with exactly two groups of results (plus SIN_DATO/SIN_BIOPSIA kept apart), as cacu_confirmacion_citologia is. The EU7-style view stays available through the catalog's `escenario` field but no CaMa indicator uses it now.
208 lines
12 KiB
TypeScript
208 lines
12 KiB
TypeScript
import { ChangeDetectorRef, Component, effect, ElementRef, inject, Input, OnChanges, OnDestroy, output, untracked, ViewChild } from '@angular/core';
|
|
import { catchError, of, Subscription } from 'rxjs';
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
import { MatCardModule } from '@angular/material/card';
|
|
import { MatIconModule } from '@angular/material/icon';
|
|
import { Dominio, Indicador, IndicadorMetadatos, Tema } from './indicadores.models';
|
|
import { GlobalApplied, IndicadoresMemory } from './indicadores-memory';
|
|
import { indicatorIdentity, figureIdentity, identityElementId } from './indicadores-identities';
|
|
import { IndicadorFigurePanel } from './indicador-figure-panel';
|
|
import { figureDisplayName } from './indicadores-figure-labels';
|
|
import { READABLE_VISUAL_PROFILE, FigureVisualProfile } from './indicadores-visual-profile';
|
|
import { dualFigures } from './indicadores-dual-figures';
|
|
import { IndicadoresSnapshots, snapshotKey } from './indicadores-snapshots';
|
|
import { filterCompatibility } from './indicadores-memory';
|
|
import { DonutSelection } from './indicadores-donut-drilldown';
|
|
import { IndicadoresService } from './indicadores.service';
|
|
import { IndicadorEu7Escenario } from './indicador-eu7-escenario';
|
|
import { vistaEscenario } from './indicadores-eu7-escenario';
|
|
import { IndicadorTiemposPareados } from './indicador-tiempos-pareados';
|
|
import { IndicadorConfirmacionCitologia } from './indicador-confirmacion-citologia';
|
|
import { vistaConfirmacion } from './indicadores-confirmacion-citologia';
|
|
import { parTiempos } from './indicadores-tiempos-pareados';
|
|
|
|
@Component({
|
|
selector: 'app-indicador-catalog-card',
|
|
host: { '[class.dual-card]': 'isDual || isEu7 || isConfirmacion || !!tiempos' },
|
|
imports: [MatButtonModule, MatCardModule, MatIconModule, IndicadorFigurePanel, IndicadorEu7Escenario, IndicadorTiemposPareados, IndicadorConfirmacionCitologia],
|
|
template: `
|
|
<mat-card>
|
|
<header>
|
|
<div class="card-identity">
|
|
<h2 [id]="titleId" tabindex="-1">{{ indicador.titulo }}</h2>
|
|
</div>
|
|
</header>
|
|
<button class="pin-toggle" mat-button type="button" [attr.aria-pressed]="pinned"
|
|
[attr.aria-label]="(pinned ? 'Desfijar indicador' : 'Fijar indicador') + ', ' + indicador.titulo"
|
|
(click)="pinChanged.emit()">
|
|
<mat-icon aria-hidden="true">push_pin</mat-icon>{{ pinned ? 'Desfijar indicador' : 'Fijar indicador' }}
|
|
</button>
|
|
<div class="catalog-content" [id]="contentId" [attr.aria-labelledby]="titleId">
|
|
<p class="catalog-metadata">{{ indicador.figuras.length }} figuras publicadas</p>
|
|
@if (isEu7) {
|
|
<div #visibilityRegion class="eu7-region">
|
|
<app-indicador-eu7-escenario [dominio]="dominio" [indicador]="indicador" [tema]="tema" [applied]="applied" [visible]="visible" [metadata]="metadata" (metadataRequested)="loadMetadata()" />
|
|
</div>
|
|
} @else if (isConfirmacion) {
|
|
<div #visibilityRegion class="confirmacion-region">
|
|
<app-indicador-confirmacion-citologia [dominio]="dominio" [indicador]="indicador" [tema]="tema" [applied]="applied" [visible]="visible" [metadata]="metadata" (metadataRequested)="loadMetadata()" />
|
|
</div>
|
|
} @else if (tiempos; as par) {
|
|
<div #visibilityRegion class="tiempos-region">
|
|
<app-indicador-tiempos-pareados [dominio]="dominio" [par]="par" [indicador]="indicador" [tema]="tema" [applied]="applied" [visible]="visible" [metadata]="metadata" (metadataRequested)="loadMetadata()" />
|
|
</div>
|
|
} @else if (selectedFigure) {
|
|
<div #visibilityRegion class="graphic-region" [class.dual-panels]="isDual">
|
|
@for (figure of displayFigures; track panelIdentity(figure)) {
|
|
<div class="representation-panel">
|
|
@if (isDual) { <h3>{{ figureDisplayName(figure, indicador.figuras) }}</h3> }
|
|
<app-indicador-figure-panel [dominio]="dominio" [indicador]="indicador" [metadata]="metadata" [figuraId]="figure" [tema]="tema" [applied]="applied" [independentPeriods]="independentPeriods" [visible]="visible" [visualProfile]="visualProfile" [localSelection]="localSelection" (metadataRequested)="loadMetadata()" (hierarchySelected)="localSelection = $event" />
|
|
</div>
|
|
}
|
|
</div>
|
|
} @else { <p role="status">El indicador no tiene figuras disponibles.</p> }
|
|
</div>
|
|
</mat-card>
|
|
`,
|
|
styles: `
|
|
:host { display: flex; min-width: 0; margin: 0; }
|
|
mat-card { flex: 1; min-width: 0; padding: clamp(.75rem, 2vw, 1.5rem); background: var(--issste-surface);
|
|
color: var(--issste-text); border: 1px solid var(--issste-border); border-radius: var(--issste-radius); box-shadow: none; }
|
|
header { display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; gap: var(--issste-space-3); }
|
|
.catalog-content { display: flex; flex-direction: column; flex: 1; min-width: 0; }
|
|
.graphic-region { flex: 1; min-width: 0; }
|
|
:host(.dual-card) { grid-column: 1 / -1; }
|
|
.graphic-region { display: grid; grid-template-columns: minmax(0, 1fr); }
|
|
.representation-panel { display: grid; min-width: 0; grid-template-rows: auto minmax(0, 1fr); }
|
|
.representation-panel > h3 { margin: 1rem 0 0; overflow-wrap: anywhere; }
|
|
app-indicador-figure-panel { grid-row: 2; }
|
|
// Nine shared tracks: name, controls, help, title, legend, plot, notes,
|
|
// full labels and stratified detail. Content determines their height.
|
|
@supports (grid-template-rows: subgrid) {
|
|
.graphic-region { grid-auto-rows: auto; grid-template-rows: auto auto auto auto auto minmax(0, 1fr) auto auto auto; }
|
|
.representation-panel { grid-row: span 9; grid-template-rows: subgrid; }
|
|
app-indicador-figure-panel { grid-row: 2 / span 8; }
|
|
.graphic-region:has(app-indicador-figure-card.methodology-expanded) { grid-template-rows: none; align-items: start; }
|
|
.graphic-region:has(app-indicador-figure-card.methodology-expanded) .representation-panel { grid-row: auto; grid-template-rows: auto auto; }
|
|
.graphic-region:has(app-indicador-figure-card.methodology-expanded) app-indicador-figure-panel { grid-row: auto; grid-template-rows: auto auto auto; }
|
|
.graphic-region:has(app-indicador-figure-card.methodology-expanded) app-indicador-figure-card { grid-row: auto; grid-template-rows: auto auto auto auto auto auto; }
|
|
}
|
|
@media (min-width: 901px) {
|
|
.dual-panels { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--issste-space-4); }
|
|
}
|
|
.card-identity { min-width: 0; }
|
|
h2, p { overflow-wrap: anywhere; }
|
|
h2 { margin: 0; font-family: var(--issste-font-heading); font-weight: 500; font-size: 1.125rem; line-height: 1.3; }
|
|
.pin-toggle { align-self: start; margin-top: var(--issste-space-1); max-width: 100%; height: auto;
|
|
min-width: 48px; min-height: 48px; color: var(--issste-text); }
|
|
.pin-toggle mat-icon { flex-shrink: 0; }
|
|
button:focus-visible { outline: 2px solid var(--issste-text); outline-offset: 3px; }
|
|
mat-form-field { width: 100%; margin-top: var(--issste-space-4); }
|
|
.catalog-metadata { margin: var(--issste-space-4) 0 0; padding-top: var(--issste-space-4);
|
|
border-top: 1px solid var(--issste-border); color: var(--issste-text-secondary); font: var(--mat-sys-body-small); }
|
|
@media (max-width: 550px) { h2 { font-size: 1.25rem; } header { gap: var(--issste-space-2); } }
|
|
`,
|
|
})
|
|
export class IndicadorCatalogCard implements OnChanges, OnDestroy {
|
|
localSelection: DonutSelection = {};
|
|
private selectionContext = '';
|
|
private readonly snapshots = inject(IndicadoresSnapshots);
|
|
private numericSubscription?: Subscription;
|
|
private numericKey = '';
|
|
private readonly indicators = inject(IndicadoresService);
|
|
private metadataSubscription?: Subscription;
|
|
private metadataKey = '';
|
|
metadata?: IndicadorMetadatos;
|
|
private activatedKey = '';
|
|
constructor() {
|
|
effect(() => {
|
|
this.snapshots.expanded(); this.snapshots.retries();
|
|
if (this.indicador && this.applied) untracked(() => this.updateNumeric());
|
|
});
|
|
}
|
|
get pair() { return dualFigures(this.indicador); }
|
|
get isEu7() { return !!vistaEscenario(this.dominio, this.indicador); }
|
|
get isConfirmacion() { return !!vistaConfirmacion(this.dominio, this.indicador); }
|
|
// Connected time pairs replace the diagnosis card with one coordinated box plot.
|
|
get tiempos() { return parTiempos(this.dominio, this.indicador.id); }
|
|
get isDual() { return this.pair.includes(this.selectedFigure ?? ''); }
|
|
get displayFigures() { return this.isDual ? this.pair : this.selectedFigure ? [this.selectedFigure] : []; }
|
|
private updateNumeric() {
|
|
const key = snapshotKey(this.dominio, this.indicador, this.applied);
|
|
if (key !== this.activatedKey) {
|
|
this.numericSubscription?.unsubscribe(); this.numericKey = '';
|
|
if (this.visible) this.activatedKey = key;
|
|
}
|
|
if (this.activatedKey !== key || !this.snapshots.expanded()
|
|
|| !filterCompatibility(this.applied, this.indicador.tipos_periodo).compatible) return;
|
|
const attempt = JSON.stringify([key, this.snapshots.retries()]);
|
|
if (this.numericKey === attempt) return;
|
|
this.numericKey = attempt;
|
|
this.numericSubscription?.unsubscribe();
|
|
this.numericSubscription = this.snapshots.read(this.dominio, this.indicador, this.applied).subscribe();
|
|
}
|
|
ngOnDestroy() { this.numericSubscription?.unsubscribe(); this.metadataSubscription?.unsubscribe(); }
|
|
readonly figureDisplayName = figureDisplayName;
|
|
@Input({ required: true }) dominio!: Dominio;
|
|
@Input({ required: true }) indicador!: Indicador;
|
|
@Input({ required: true }) tema!: Tema;
|
|
@Input({ required: true }) applied!: GlobalApplied;
|
|
@Input() independentPeriods = false;
|
|
@Input() pinned = false;
|
|
@Input() visualProfile: FigureVisualProfile = READABLE_VISUAL_PROFILE;
|
|
readonly pinChanged = output<void>();
|
|
@ViewChild('visibilityRegion') visibilityRegion?: ElementRef<HTMLElement>;
|
|
readonly host = inject<ElementRef<HTMLElement>>(ElementRef);
|
|
private readonly changeDetector = inject(ChangeDetectorRef);
|
|
private readonly memory = inject(IndicadoresMemory);
|
|
private identity = '';
|
|
visible = false;
|
|
titleId = '';
|
|
contentId = '';
|
|
panelIdentity(figure: string) { return figureIdentity(this.dominio, this.indicador.id, figure); }
|
|
selectedFigure?: string;
|
|
selectFigure(figure: string) {
|
|
if (!this.indicador.figuras.includes(figure) || figure === this.selectedFigure) return;
|
|
this.selectedFigure = this.pair.includes(figure) ? this.pair[0] : figure;
|
|
this.memory.rememberFigure(this.dominio, this.indicador.id, figure);
|
|
this.changeDetector.markForCheck();
|
|
}
|
|
ngOnChanges() {
|
|
const context = JSON.stringify([this.dominio, this.indicador.id, this.indicador.version, this.applied, this.tema]);
|
|
if (context !== this.selectionContext) { this.localSelection = {}; this.selectionContext = context; }
|
|
const remembered = this.memory.figure(this.dominio, this.indicador.id);
|
|
const selected = remembered && this.indicador.figuras.includes(remembered) ? remembered : this.pair[0] ?? this.indicador.figuras[0];
|
|
this.selectedFigure = this.pair.includes(selected) ? this.pair[0] : selected;
|
|
const identity = indicatorIdentity(this.dominio, this.indicador.id);
|
|
if (identity === this.identity) { this.updateNumeric(); return; }
|
|
this.identity = identity;
|
|
this.metadataSubscription?.unsubscribe();
|
|
this.metadata = undefined;
|
|
this.metadataKey = '';
|
|
const id = identityElementId(identity);
|
|
this.titleId = id + '-title';
|
|
this.contentId = id + '-content';
|
|
this.visible = false;
|
|
this.updateNumeric();
|
|
}
|
|
setVisible(visible: boolean) {
|
|
if (this.visible === visible) return;
|
|
this.visible = visible;
|
|
this.updateNumeric();
|
|
this.changeDetector.markForCheck();
|
|
}
|
|
loadMetadata() {
|
|
const key = JSON.stringify([this.dominio, this.indicador.id]);
|
|
if (this.metadataKey === key) return;
|
|
this.metadataKey = key;
|
|
this.metadataSubscription?.unsubscribe();
|
|
this.metadataSubscription = this.indicators.metadatos(this.dominio, this.indicador.id)
|
|
.pipe(catchError(() => of(undefined))).subscribe(value => {
|
|
if (this.metadataKey !== key) return;
|
|
if (!value) this.metadataKey = '';
|
|
this.metadata = value;
|
|
this.changeDetector.markForCheck();
|
|
});
|
|
}
|
|
}
|