Agrupar las tarjetas de CaMa y elegir el periodo en Trazabilidad

This commit is contained in:
2026-12-03 22:21:59 -06:00
parent 84769cb0f4
commit 2a84eb56ca
12 changed files with 142 additions and 120 deletions
+39 -15
View File
@@ -1,11 +1,13 @@
import { Component, computed, inject, input, resource, signal } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatButtonToggleModule } from '@angular/material/button-toggle';
import { MatSelectModule } from '@angular/material/select';
import type { Measure, MeasureReport } from 'fhir/r4';
import { Fhir, resources } from '../fhir';
import { Loading } from '../loading';
import { Figure, Plot } from '../plot';
import { historyFigure } from './figures';
import { periodLabel, periods, PeriodType, reading } from './measures';
import { historyPeriods, periodLabel, periods, PeriodType, reading } from './measures';
import { HISTORY, HistoryPanel } from './pages';
interface Drawn {
@@ -19,21 +21,30 @@ interface Drawn {
* each measure period by period. */
@Component({
selector: 'app-tab-trazabilidad',
imports: [Loading, MatButtonToggleModule, Plot],
imports: [Loading, MatButtonModule, MatButtonToggleModule, MatSelectModule, Plot],
template: `
<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)"
(change)="setType($event.value)"
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>
@if (domain() === 'cama' || domain() === 'cacu') {
<label>Fecha de corte <input type="date" [value]="chosenCutoff()" (input)="chosenCutoff.set($any($event.target).value)" /></label>
<button type="button" (click)="cutoff.set(chosenCutoff())">Aplicar</button>
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<mat-label>Periodo seleccionado</mat-label>
<mat-select [value]="chosen()" (selectionChange)="chosen.set($event.value)">
@for (p of options(); track p) {
<mat-option [value]="p">{{ p }}</mat-option>
}
</mat-select>
</mat-form-field>
<button mat-flat-button (click)="applied.set(chosen())" [disabled]="chosen() === applied()">
Aplicar
</button>
}
</section>
@if (series.isLoading()) {
@@ -75,6 +86,12 @@ interface Drawn {
padding: 16px 20px;
margin-bottom: 16px;
}
.filters {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 16px;
}
.filters-title {
font-size: 16px;
font-weight: 500;
@@ -99,16 +116,28 @@ export class TabTrazabilidad {
readonly domain = input.required<string>();
readonly measures = input.required<Measure[]>();
protected readonly type = signal<PeriodType>('month');
protected readonly chosenCutoff = signal('');
protected readonly cutoff = signal('');
protected readonly options = computed(() => periods(this.type()));
protected readonly chosen = signal(periods('month')[0]);
protected readonly applied = signal(periods('month')[0]);
protected setType(type: PeriodType): void {
this.type.set(type);
const latest = this.options()[0];
this.chosen.set(latest);
this.applied.set(latest);
}
protected readonly series = resource({
params: () => ({ domain: this.domain(), type: this.type(), measures: this.measures(), cutoff: this.cutoff() }),
params: () => ({
domain: this.domain(),
type: this.type(),
measures: this.measures(),
period: this.applied(),
}),
loader: async ({ params }) => {
const history = HISTORY[params.domain];
if (!history) return [];
const day = params.cutoff ? new Date(`${params.cutoff}T12:00:00`) : new Date();
const asked = periods(params.type, 6, day).reverse();
const asked = historyPeriods(params.type, params.period);
return Promise.all(
history.panels.map(async (panel) => {
const measure = params.measures.find((m) => m.name === panel.measure);
@@ -116,11 +145,6 @@ export class TabTrazabilidad {
const pages = await this.fhir.all(params.domain, 'MeasureReport', {
measure: measure.id!,
'reporting-period': asked.join(','),
...(params.cutoff ? {
'as-of': `${params.cutoff}T23:59:59.999999Z`,
'event-cutoff': params.cutoff,
'period-cutoff': params.cutoff,
} : {}),
});
// One report per period asked, in the order asked.
const found = resources<MeasureReport>(pages, 'MeasureReport');