Trazabilidad, Datos y definiciones and the risk lists as the old app: declared panels, old labels and order; page tests against the capture
This commit is contained in:
@@ -1,58 +1,92 @@
|
||||
import { Component, computed, inject, input, resource, signal } from '@angular/core';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import type { Measure, MeasureReport } from 'fhir/r4';
|
||||
import { Fhir, resources } from '../fhir';
|
||||
import { Figure, Plot } from '../plot';
|
||||
import { history, periods, PeriodType, periodTypes, reading } from './measures';
|
||||
import { Loading } from '../loading';
|
||||
import { Figure, Plot } from '../plot';
|
||||
import { historyFigure } from './figures';
|
||||
import { periodLabel, periods, PeriodType, reading } from './measures';
|
||||
import { HISTORY, HistoryPanel } from './pages';
|
||||
|
||||
/** Each measure over time: every period of the chosen kind, oldest first. */
|
||||
interface Drawn {
|
||||
panel: HistoryPanel;
|
||||
/** the group's heading, on the first panel of its run */
|
||||
heading?: string;
|
||||
figure?: Figure;
|
||||
}
|
||||
|
||||
/** Trazabilidad as the old tab: the domain's declared panels (pages.HISTORY), in their order,
|
||||
* each measure period by period. */
|
||||
@Component({
|
||||
selector: 'app-tab-trazabilidad',
|
||||
imports: [Loading, MatButtonToggleModule, MatCardModule, Plot],
|
||||
imports: [Loading, MatButtonToggleModule, Plot],
|
||||
template: `
|
||||
<div class="bar">
|
||||
<section class="card filters" aria-labelledby="history-filters">
|
||||
<h2 id="history-filters" class="filters-title">Filtros</h2>
|
||||
<mat-button-toggle-group
|
||||
[value]="type()"
|
||||
(change)="type.set($event.value)"
|
||||
aria-label="Intervalo"
|
||||
aria-label="Intervalo de análisis"
|
||||
>
|
||||
<mat-button-toggle value="month">Mensual</mat-button-toggle>
|
||||
<mat-button-toggle value="semester">Semestral</mat-button-toggle>
|
||||
</mat-button-toggle-group>
|
||||
</div>
|
||||
</section>
|
||||
@if (series.isLoading()) {
|
||||
<app-loading what="las series" text="Calculando las series del periodo…" />
|
||||
}
|
||||
<div class="grid">
|
||||
@for (item of figures(); track item.measure.id) {
|
||||
<mat-card appearance="outlined" [attr.data-measure]="item.measure.name">
|
||||
<mat-card-header
|
||||
><mat-card-title>{{ item.measure.title }}</mat-card-title></mat-card-header
|
||||
>
|
||||
<mat-card-content><app-plot [figure]="item.figure" [height]="280" /></mat-card-content>
|
||||
</mat-card>
|
||||
<app-loading what="la trazabilidad" text="Cargando trazabilidad…" />
|
||||
} @else if (series.error()) {
|
||||
<p class="muted" role="alert">
|
||||
No se pudo cargar la trazabilidad.
|
||||
<button type="button" class="retry" (click)="series.reload()">Reintentar</button>
|
||||
</p>
|
||||
} @else {
|
||||
@for (d of drawn(); track d.panel.measure) {
|
||||
@if (d.heading) {
|
||||
<h2 class="group-title">{{ d.heading }}</h2>
|
||||
}
|
||||
<section class="card panel" [attr.data-measure]="d.panel.measure">
|
||||
@if (d.panel.group) {
|
||||
<h3 class="panel-title">{{ d.panel.title }}</h3>
|
||||
} @else {
|
||||
<h2 class="panel-title">{{ d.panel.title }}</h2>
|
||||
}
|
||||
@if (d.figure) {
|
||||
<app-plot [figure]="d.figure" [height]="320" />
|
||||
} @else {
|
||||
<p class="muted">Sin datos para el periodo.</p>
|
||||
}
|
||||
</section>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
`,
|
||||
styles: `
|
||||
:host {
|
||||
display: block;
|
||||
padding-top: 16px;
|
||||
}
|
||||
.bar {
|
||||
.card {
|
||||
background: var(--mat-sys-surface);
|
||||
border: 1px solid var(--mat-sys-outline-variant);
|
||||
border-radius: 12px;
|
||||
padding: 16px 20px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.grid {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
grid-template-columns: 1fr;
|
||||
.filters-title {
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
@media (min-width: 1304px) {
|
||||
.grid {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
.panel-title,
|
||||
.group-title {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
h3.panel-title {
|
||||
font-size: 16px;
|
||||
}
|
||||
.group-title {
|
||||
margin: 24px 0 12px;
|
||||
}
|
||||
`,
|
||||
})
|
||||
@@ -60,31 +94,48 @@ export class TabTrazabilidad {
|
||||
private readonly fhir = inject(Fhir);
|
||||
readonly domain = input.required<string>();
|
||||
readonly measures = input.required<Measure[]>();
|
||||
protected readonly type = signal<PeriodType>('semester');
|
||||
protected readonly type = signal<PeriodType>('month');
|
||||
|
||||
protected readonly series = resource({
|
||||
params: () => ({ domain: this.domain(), type: this.type(), measures: this.measures() }),
|
||||
loader: async ({ params }) => {
|
||||
const history = HISTORY[params.domain];
|
||||
if (!history) return [];
|
||||
const asked = periods(params.type).reverse();
|
||||
const shown = params.measures.filter((m) => periodTypes(m).includes(params.type));
|
||||
return Promise.all(
|
||||
shown.map(async (measure) => {
|
||||
history.panels.map(async (panel) => {
|
||||
const measure = params.measures.find((m) => m.name === panel.measure);
|
||||
if (!measure) return { panel, points: [] };
|
||||
const pages = await this.fhir.all(params.domain, 'MeasureReport', {
|
||||
measure: measure.id!,
|
||||
'reporting-period': asked.join(','),
|
||||
});
|
||||
// One report per period asked, in the order asked.
|
||||
const found = resources<MeasureReport>(pages, 'MeasureReport');
|
||||
return { measure, points: asked.map((period, i) => ({ period, r: reading(found[i]) })) };
|
||||
return { panel, points: asked.map((period, i) => ({ period, r: reading(found[i]) })) };
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
protected readonly figures = computed<{ measure: Measure; figure: Figure }[]>(() =>
|
||||
(this.series.value() ?? []).map(({ measure, points }) => {
|
||||
// From the first period with data on.
|
||||
const first = points.findIndex((p) => (p.r?.populations['initial-population'] ?? 0) > 0);
|
||||
return { measure, figure: history(measure, first < 0 ? [] : points.slice(first)) };
|
||||
}),
|
||||
);
|
||||
protected readonly drawn = computed<Drawn[]>(() => {
|
||||
const history = HISTORY[this.domain()];
|
||||
const xTitle = this.type() === 'month' ? 'Mes y año' : 'Semestre';
|
||||
let group: string | undefined;
|
||||
if (!this.series.hasValue()) return [];
|
||||
return this.series.value().map(({ panel, points }) => {
|
||||
const heading = panel.group && panel.group !== group ? panel.group : undefined;
|
||||
group = panel.group;
|
||||
const has = (p: (typeof points)[number]) => (p.r?.populations['initial-population'] ?? 0) > 0;
|
||||
const first = points.findIndex(has);
|
||||
if (first < 0 || !history) return { panel, heading };
|
||||
const last = points.length - 1 - [...points].reverse().findIndex(has);
|
||||
const shown =
|
||||
history.months && this.type() === 'month'
|
||||
? points.slice(Math.max(first, last + 1 - history.months), last + 1)
|
||||
: points.slice(first, last + 1);
|
||||
const series = shown.map((p) => ({ label: periodLabel(p.period), r: p.r }));
|
||||
return { panel, heading, figure: historyFigure(panel, series, history.line, xTitle) };
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user