diff --git a/src/app/features/indicadores/indicador-metadata.scss b/src/app/features/indicadores/indicador-metadata.scss index 92d2cf1..241f185 100644 --- a/src/app/features/indicadores/indicador-metadata.scss +++ b/src/app/features/indicadores/indicador-metadata.scss @@ -9,8 +9,6 @@ table { border-collapse: collapse; width: 100%; max-width: 75rem; } th, td { text-align: left; vertical-align: top; padding: var(--issste-space-2); border-bottom: 1px solid var(--issste-border); } thead th, tbody th { color: var(--issste-text-secondary); font-weight: 600; } .ficha-table th { width: 10rem; } -.rules-table code { overflow-wrap: anywhere; } -.rules-table td:nth-child(2) { min-width: 8rem; } @media (max-width: 36rem) { .ficha-table th { width: 6rem; } } diff --git a/src/app/features/indicadores/indicador-metadata.spec.ts b/src/app/features/indicadores/indicador-metadata.spec.ts index c767271..2de1889 100644 --- a/src/app/features/indicadores/indicador-metadata.spec.ts +++ b/src/app/features/indicadores/indicador-metadata.spec.ts @@ -37,31 +37,21 @@ describe('Metadatos metodológicos opcionales', () => { http.verify(); fixture.destroy(); }); - it('presenta la ficha en una tabla y las reglas con valor legible, estado y fuente', () => { + it('presenta la ficha en una tabla y no muestra las reglas (parametros) aunque vengan', () => { const { fixture, http, text } = render({ ficha: { codigo: 'EU-T', definicion: 'Días de la toma al diagnóstico.' }, - parametros: [ - { clave: 'cacu.horizontes.toma_diagnostico_dias', valor: 180, estado: 'provisional', fuente: 'Arbitrario para poder calcular.' }, - { clave: 'cacu.diagnostico.cie', valor: ['Z014', 'R87'], estado: 'confirmado', fuente: null }, - ], + parametros: [{ clave: 'cacu.horizontes.toma_diagnostico_dias', valor: 180, estado: 'provisional', fuente: 'Arbitrario.' }], }); const ficha = fixture.nativeElement.querySelector('table.ficha-table') as HTMLTableElement; expect([...ficha.querySelectorAll('th[scope=row]')].map(th => th.textContent)).toEqual(['Código', 'Definición']); - const rules = fixture.nativeElement.querySelector('table.rules-table') as HTMLTableElement; - expect([...rules.querySelectorAll('thead th')].map(th => th.textContent)).toEqual(['Clave', 'Valor', 'Estado', 'Fuente']); - const rows = [...rules.querySelectorAll('tbody tr')].map(tr => [...tr.children].map(cell => cell.textContent)); - expect(rows).toEqual([ - ['cacu.horizontes.toma_diagnostico_dias', '180', 'Provisional', 'Arbitrario para poder calcular.'], - ['cacu.diagnostico.cie', 'Z014, R87', 'Confirmado', '—'], - ]); - expect(text).toContain('Reglas'); expect(text).not.toContain('no está disponible'); + expect(fixture.nativeElement.querySelectorAll('table')).toHaveLength(1); + for (const absent of ['Reglas', 'cacu.horizontes', 'Provisional', 'Arbitrario']) expect(text).not.toContain(absent); http.verify(); fixture.destroy(); }); - it('muestra sólo reglas cuando no hay ficha', () => { + it('con solo parametros anuncia que no hay información ampliada', () => { const { fixture, http, text } = render({ parametros: [{ clave: 'comun.umbral_supresion', valor: 5, estado: 'provisional' }] }); - expect(text).toContain('comun.umbral_supresion'); expect(text).not.toContain('Ficha técnica'); - expect(text).not.toContain('no está disponible'); + expect(text).toContain('no está disponible'); expect(text).not.toContain('comun.umbral_supresion'); http.verify(); fixture.destroy(); }); diff --git a/src/app/features/indicadores/indicador-metadata.ts b/src/app/features/indicadores/indicador-metadata.ts index ed887da..d2d0bc0 100644 --- a/src/app/features/indicadores/indicador-metadata.ts +++ b/src/app/features/indicadores/indicador-metadata.ts @@ -4,21 +4,6 @@ import { catchError, of, Subject, switchMap } from 'rxjs'; import { Dominio, IndicadorMetadatos } from './indicadores.models'; import { IndicadoresService } from './indicadores.service'; -const RULE_STATES: Record = { provisional: 'Provisional', confirmado: 'Confirmado' }; - -// Readable rule value: lists separated by commas, objects by their label when they carry one. -export function ruleValue(value: unknown): string { - if (value === null || value === undefined) return 'Sin definir'; - if (Array.isArray(value)) return value.length ? value.map(ruleValue).join(', ') : 'Lista vacía'; - if (typeof value === 'boolean') return value ? 'Sí' : 'No'; - if (typeof value === 'number') return value.toLocaleString('es-MX'); - if (typeof value === 'object') { - const label = (value as Record)['etiqueta']; - return typeof label === 'string' && label.trim() ? label : JSON.stringify(value); - } - return String(value); -} - @Component({ selector: 'app-indicador-metadata', styleUrl: './indicador-metadata.scss', @@ -42,19 +27,6 @@ export function ruleValue(value: unknown): string { } - @if (rules.length) { -
-

Reglas

-
- - - @for (rule of rules; track rule.clave) { - - } -
ClaveValorEstadoFuente
{{ rule.clave }}{{ rule.valor }}{{ rule.estado }}
-
-
- } @if (references.length) {

Referencias

@@ -88,17 +60,9 @@ export class IndicadorMetadata implements OnChanges { const ficha = this.metadata?.ficha; return ficha ? this.fichaLabels.flatMap(([key, label]) => this.hasText(ficha[key]) ? [{ key, label, value: ficha[key]!.trim() }] : []) : []; } - get rules() { - return (this.metadata?.parametros ?? []).map(rule => ({ - clave: rule.clave, - valor: ruleValue(rule.valor), - estado: RULE_STATES[rule.estado] ?? rule.estado, - fuente: this.hasText(rule.fuente) ? rule.fuente.trim() : '—', - })); - } get references() { return (this.metadata?.referencias ?? []).filter(ref => this.hasText(ref.etiqueta)); } get populations() { return (this.metadata?.poblaciones ?? []).filter(population => this.hasText(population.descripcion)); } - get hasUsableMetadata() { return !!(this.description || this.fichaFields.length || this.rules.length || this.references.length || this.populations.length); } + get hasUsableMetadata() { return !!(this.description || this.fichaFields.length || this.references.length || this.populations.length); } constructor() { this.requests.pipe(switchMap(() => this.service.metadatos(this.dominio, this.indicador).pipe(catchError(() => of(undefined)))), takeUntilDestroyed(inject(DestroyRef))).subscribe(value => { this.metadata = value; this.loading = false; this.changeDetector.markForCheck(); }); } diff --git a/src/app/features/indicadores/indicadores.models.ts b/src/app/features/indicadores/indicadores.models.ts index 4b76b63..f40a8d4 100644 --- a/src/app/features/indicadores/indicadores.models.ts +++ b/src/app/features/indicadores/indicadores.models.ts @@ -40,17 +40,9 @@ export interface IndicadorFiguraDetalle { descripcion: string | null; como_leer: string[] | null; } -// A rule the kit used to compute the indicator (horizon, code lists, thresholds). -export interface IndicadorParametro { - clave: string; - valor: unknown; - estado: string; - fuente?: string | null; -} export interface IndicadorMetadatos { descripcion?: string | null; ficha?: IndicadorFicha | null; - parametros?: IndicadorParametro[] | null; referencias?: { tipo: string; etiqueta: string; ref: string | null }[] | null; poblaciones?: { grupo: string; codigo: string; descripcion: string }[] | null; figuras_detalle?: IndicadorFiguraDetalle[] | null; diff --git a/src/app/features/indicadores/indicadores.service.spec.ts b/src/app/features/indicadores/indicadores.service.spec.ts index ffaf934..81baa21 100644 --- a/src/app/features/indicadores/indicadores.service.spec.ts +++ b/src/app/features/indicadores/indicadores.service.spec.ts @@ -48,30 +48,11 @@ describe('IndicadoresService HTTP', () => { expect(error).toBeInstanceOf(Error); }); - it('acepta parámetros publicados con valores de cualquier tipo y fuente opcional', () => { - const parametros = [ - { clave: 'cacu.horizontes.toma_diagnostico_dias', valor: 180, estado: 'provisional', fuente: 'Arbitrario para poder calcular.' }, - { clave: 'cacu.diagnostico.cie', valor: ['Z014', 'R87'], estado: 'provisional', fuente: null }, - { clave: 'comun.umbral_supresion', valor: 5, estado: 'confirmado' }, - ]; - let value: unknown, nulo: unknown; + it('ignora parametros: ni los valida ni bloquea los metadatos aunque vengan mal formados', () => { + let value: unknown; service.metadatos('cacu', 'p').subscribe(v => value = v); - http.expectOne('/cacu/indicadores/p/metadatos').flush({ parametros }); - service.metadatos('cacu', 'n').subscribe(v => nulo = v); - http.expectOne('/cacu/indicadores/n/metadatos').flush({ parametros: null }); - expect(value).toMatchObject({ parametros }); expect(nulo).toMatchObject({ parametros: null }); - }); - it.each([ - { parametros: 'incorrecto' }, - { parametros: [{ clave: '', valor: 1, estado: 'provisional' }] }, - { parametros: [{ clave: 'a', estado: 'provisional' }] }, - { parametros: [{ clave: 'a', valor: 1, estado: 1 }] }, - { parametros: [{ clave: 'a', valor: 1, estado: 'confirmado', fuente: 2 }] }, - ])('rechaza parámetros mal formados $parametros', payload => { - let error: unknown; - service.metadatos('cacu', 'i').subscribe({ error: value => error = value }); - http.expectOne('/cacu/indicadores/i/metadatos').flush(payload); - expect(error).toBeInstanceOf(Error); + http.expectOne('/cacu/indicadores/p/metadatos').flush({ descripcion: 'Descripción', parametros: 'incorrecto' }); + expect(value).toMatchObject({ descripcion: 'Descripción' }); }); it.each(['tea', 'cacu', 'cama'] as const)('lee catálogo sintético dinámico de %s y sus tipos publicados', dominio => { diff --git a/src/app/features/indicadores/indicadores.service.ts b/src/app/features/indicadores/indicadores.service.ts index 8992c02..025e81a 100644 --- a/src/app/features/indicadores/indicadores.service.ts +++ b/src/app/features/indicadores/indicadores.service.ts @@ -40,13 +40,6 @@ export class IndicadoresService { if (content !== undefined && content !== null && typeof content !== 'string') throw new Error('Metadatos inválidos'); } } - const parameters = value['parametros']; - if (parameters !== undefined && parameters !== null && (!Array.isArray(parameters) || !parameters.every(v => record(v) - && typeof v['clave'] === 'string' && v['clave'].trim().length > 0 && Object.hasOwn(v, 'valor') - && typeof v['estado'] === 'string' - && (v['fuente'] === undefined || v['fuente'] === null || typeof v['fuente'] === 'string')))) { - throw new Error('Metadatos inválidos'); - } for (const field of ['referencias', 'poblaciones']) { const list = value[field]; if (list !== undefined && list !== null && (!Array.isArray(list) || !list.every(v => record(v) && (field === 'referencias'