diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index 2249119..feed61d 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -6,6 +6,12 @@ const loadIndicadores = () => import('./features/indicadores/indicadores-page'). export const routes: Routes = [ { path: '', component: Home, title: 'Análisis de información | ISSSTELEON' }, + { + path: 'indicadores/tea-estatus', + title: 'Casos por estatus | ISSSTELEON', + loadComponent: () => import('./features/indicadores/tea-status-page').then(m => m.TeaStatusPage), + data: { workspace: true, breadcrumb: 'Casos por estatus' }, + }, { path: 'conectar', title: 'Conectar datos | ISSSTELEON', diff --git a/src/app/features/indicadores/tea-status-page.spec.ts b/src/app/features/indicadores/tea-status-page.spec.ts new file mode 100644 index 0000000..74ac0c0 --- /dev/null +++ b/src/app/features/indicadores/tea-status-page.spec.ts @@ -0,0 +1,24 @@ +import { provideHttpClient } from '@angular/common/http'; +import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing'; +import { TestBed } from '@angular/core/testing'; +import { TeaStatusPage } from './tea-status-page'; + +describe('TeaStatusPage', () => { + it('shows the stages in a FHIR report and reports a failed query', () => { + TestBed.configureTestingModule({ providers: [provideHttpClient(), provideHttpClientTesting()] }); + const component = TestBed.createComponent(TeaStatusPage).componentInstance; + const http = TestBed.inject(HttpTestingController); + component.consultar(); + const request = http.expectOne('/tea/fhir/Measure/M28_casos_por_estado/$evaluate-measure?periodo=2025-S1'); + request.flush({ group: [{ population: [{ count: 6 }], stratifier: [{ stratum: [ + { value: { coding: [{ code: 'SOLO_MCHAT' }] }, population: [{ count: 2 }] }, + ] }] }] }); + expect(component.total()).toBe(6); + expect(component.filas()).toEqual([{ codigo: 'SOLO_MCHAT', nombre: 'M-CHAT', cantidad: 2 }]); + component.consultar(); + http.expectOne('/tea/fhir/Measure/M28_casos_por_estado/$evaluate-measure?periodo=2025-S1') + .flush({}, { status: 404, statusText: 'Not Found' }); + expect(component.estado()).toBe('error'); + http.verify(); + }); +}); diff --git a/src/app/features/indicadores/tea-status-page.ts b/src/app/features/indicadores/tea-status-page.ts new file mode 100644 index 0000000..99b7b31 --- /dev/null +++ b/src/app/features/indicadores/tea-status-page.ts @@ -0,0 +1,53 @@ +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 { } + } + `, +}) +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'), + }); + } +}