import { HttpClient, HttpParams } from '@angular/common/http';
import { Component, inject, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
interface Population { count?: number }
interface Stratum { value?: { coding?: { code?: string; display?: string }[] }; population?: Population[] }
interface Report { group?: { population?: Population[]; stratifier?: { stratum?: Stratum[] }[] }[] }
@Component({
selector: 'app-tea-status-page',
imports: [FormsModule],
template: `
Casos por estatus
Consulte la etapa alcanzada por las niñas y los niños en el periodo seleccionado.
@if (estado() === 'cargando') { Consultando información…
}
@if (estado() === 'error') { No fue posible consultar el periodo. Verifique el periodo e intente de nuevo.
}
@if (estado() === 'listo') {
Total: {{ total() }}
@if (filas().length === 0) { No hay casos para este periodo.
}
@else { @for (fila of filas(); track fila.codigo) { - {{ fila.nombre }}: {{ fila.cantidad }}
}
}
}
`,
})
export class TeaStatusPage {
private readonly http = inject(HttpClient);
periodo = '2025-S1';
readonly estado = signal<'inicial' | 'cargando' | 'listo' | 'error'>('inicial');
readonly total = signal(0);
readonly filas = signal<{ codigo: string; nombre: string; cantidad: number }[]>([]);
consultar() {
this.estado.set('cargando');
this.http.get('/tea/fhir/Measure/M28_casos_por_estado/$evaluate-measure', {
params: new HttpParams().set('periodo', this.periodo),
}).subscribe({
next: report => {
const group = report.group?.[0];
this.total.set(group?.population?.[0]?.count ?? 0);
const nombres: Record = { SOLO_MCHAT: 'M-CHAT', PSICOLOGIA: 'Psicología', NEUROPEDIATRIA: 'Neuropediatría', EEG: 'EEG' };
this.filas.set((group?.stratifier?.[0]?.stratum ?? []).map(s => {
const codigo = s.value?.coding?.[0]?.code ?? '';
return { codigo, nombre: nombres[codigo] ?? s.value?.coding?.[0]?.display ?? codigo, cantidad: s.population?.[0]?.count ?? 0 };
}));
this.estado.set('listo');
},
error: () => this.estado.set('error'),
});
}
}