KPIs page drawing CaCu's measures from the WebApi's FHIR MeasureReport bundles
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { Component, inject, OnInit, signal } from '@angular/core';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { forkJoin, map, of, switchMap } from 'rxjs';
|
||||
import { PlotlyChart } from '../../shared/plotly/plotly-chart';
|
||||
import { PlotlyFigure } from './indicadores.models';
|
||||
import { compositionFigure, proportionFigure } from './measure-report';
|
||||
import { MeasureReportService } from './measure-report.service';
|
||||
|
||||
const PERIODOS = ['2025-S1', '2025-S2'];
|
||||
|
||||
/** Every measure the WebApi answers on request, drawn from its FHIR `MeasureReport`s: one contract for all. */
|
||||
@Component({
|
||||
selector: 'app-kpis-page',
|
||||
imports: [MatProgressBarModule, PlotlyChart],
|
||||
template: `
|
||||
<h1>Indicadores</h1>
|
||||
@if (status() === 'loading') { <mat-progress-bar mode="indeterminate" aria-label="Cargando indicadores" /> }
|
||||
@if (status() === 'error') { <p role="alert">No se pudieron cargar los indicadores.</p> }
|
||||
@for (item of figures(); track item.id) {
|
||||
<section><app-plotly-chart [figure]="item.figure" [label]="item.id" /></section>
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class KpisPage implements OnInit {
|
||||
readonly status = signal<'loading' | 'ready' | 'error'>('loading');
|
||||
readonly figures = signal<{ id: string; figure: PlotlyFigure }[]>([]);
|
||||
private readonly service = inject(MeasureReportService);
|
||||
|
||||
ngOnInit() {
|
||||
this.service.list('cacu').pipe(
|
||||
switchMap(kpis => kpis.length === 0 ? of([]) : forkJoin(kpis.map(kpi => kpi.scoring === 'composition'
|
||||
? this.service.composition('cacu', kpi.id, PERIODOS).pipe(map(s => ({ id: kpi.id, figure: compositionFigure(s, kpi.id) })))
|
||||
: this.service.series('cacu', kpi.id, PERIODOS).pipe(map(s => ({ id: kpi.id, figure: proportionFigure(s, kpi.id) })))))),
|
||||
).subscribe({
|
||||
next: figures => { this.figures.set(figures); this.status.set('ready'); },
|
||||
error: () => this.status.set('error'),
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user