refactor(indicadores): quitar la tabla de reglas de datos y definiciones
Las reglas de cálculo que publica el kit en `parametros` (clave, valor, estado y fuente) irán en un apéndice o manual técnico aparte, no en la pestaña «Datos y definiciones». Se quita la tabla «Reglas» y su formato de valores, y la pestaña conserva la ficha técnica, las referencias y las poblaciones. También se retiran el tipo y la validación estricta de `parametros` en el servicio: ya nadie los usa y una lista mal formada bloqueaba los metadatos completos. Si el servidor envía `parametros`, se ignoran. CSO5.5
This commit is contained in:
@@ -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); }
|
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; }
|
thead th, tbody th { color: var(--issste-text-secondary); font-weight: 600; }
|
||||||
.ficha-table th { width: 10rem; }
|
.ficha-table th { width: 10rem; }
|
||||||
.rules-table code { overflow-wrap: anywhere; }
|
|
||||||
.rules-table td:nth-child(2) { min-width: 8rem; }
|
|
||||||
@media (max-width: 36rem) {
|
@media (max-width: 36rem) {
|
||||||
.ficha-table th { width: 6rem; }
|
.ficha-table th { width: 6rem; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,31 +37,21 @@ describe('Metadatos metodológicos opcionales', () => {
|
|||||||
http.verify(); fixture.destroy();
|
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({
|
const { fixture, http, text } = render({
|
||||||
ficha: { codigo: 'EU-T', definicion: 'Días de la toma al diagnóstico.' },
|
ficha: { codigo: 'EU-T', definicion: 'Días de la toma al diagnóstico.' },
|
||||||
parametros: [
|
parametros: [{ clave: 'cacu.horizontes.toma_diagnostico_dias', valor: 180, estado: 'provisional', fuente: 'Arbitrario.' }],
|
||||||
{ 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 },
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
const ficha = fixture.nativeElement.querySelector('table.ficha-table') as HTMLTableElement;
|
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']);
|
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(fixture.nativeElement.querySelectorAll('table')).toHaveLength(1);
|
||||||
expect([...rules.querySelectorAll('thead th')].map(th => th.textContent)).toEqual(['Clave', 'Valor', 'Estado', 'Fuente']);
|
for (const absent of ['Reglas', 'cacu.horizontes', 'Provisional', 'Arbitrario']) expect(text).not.toContain(absent);
|
||||||
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');
|
|
||||||
http.verify(); fixture.destroy();
|
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' }] });
|
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).toContain('no está disponible'); expect(text).not.toContain('comun.umbral_supresion');
|
||||||
expect(text).not.toContain('no está disponible');
|
|
||||||
http.verify(); fixture.destroy();
|
http.verify(); fixture.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,21 +4,6 @@ import { catchError, of, Subject, switchMap } from 'rxjs';
|
|||||||
import { Dominio, IndicadorMetadatos } from './indicadores.models';
|
import { Dominio, IndicadorMetadatos } from './indicadores.models';
|
||||||
import { IndicadoresService } from './indicadores.service';
|
import { IndicadoresService } from './indicadores.service';
|
||||||
|
|
||||||
const RULE_STATES: Record<string, string> = { 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<string, unknown>)['etiqueta'];
|
|
||||||
return typeof label === 'string' && label.trim() ? label : JSON.stringify(value);
|
|
||||||
}
|
|
||||||
return String(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-indicador-metadata',
|
selector: 'app-indicador-metadata',
|
||||||
styleUrl: './indicador-metadata.scss',
|
styleUrl: './indicador-metadata.scss',
|
||||||
@@ -42,19 +27,6 @@ export function ruleValue(value: unknown): string {
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
}
|
}
|
||||||
@if (rules.length) {
|
|
||||||
<section aria-labelledby="metadata-rules-title">
|
|
||||||
<h4 id="metadata-rules-title">Reglas</h4>
|
|
||||||
<div class="table-scroll" role="region" aria-label="Tabla de reglas del indicador" tabindex="0">
|
|
||||||
<table class="rules-table">
|
|
||||||
<thead><tr><th scope="col">Clave</th><th scope="col">Valor</th><th scope="col">Estado</th><th scope="col">Fuente</th></tr></thead>
|
|
||||||
<tbody>@for (rule of rules; track rule.clave) {
|
|
||||||
<tr><th scope="row"><code>{{ rule.clave }}</code></th><td>{{ rule.valor }}</td><td>{{ rule.estado }}</td><td class="metadata-copy">{{ rule.fuente }}</td></tr>
|
|
||||||
}</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
}
|
|
||||||
@if (references.length) {
|
@if (references.length) {
|
||||||
<section aria-labelledby="metadata-references-title">
|
<section aria-labelledby="metadata-references-title">
|
||||||
<h4 id="metadata-references-title">Referencias</h4>
|
<h4 id="metadata-references-title">Referencias</h4>
|
||||||
@@ -88,17 +60,9 @@ export class IndicadorMetadata implements OnChanges {
|
|||||||
const ficha = this.metadata?.ficha;
|
const ficha = this.metadata?.ficha;
|
||||||
return ficha ? this.fichaLabels.flatMap(([key, label]) => this.hasText(ficha[key]) ? [{ key, label, value: ficha[key]!.trim() }] : []) : [];
|
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 references() { return (this.metadata?.referencias ?? []).filter(ref => this.hasText(ref.etiqueta)); }
|
||||||
get populations() { return (this.metadata?.poblaciones ?? []).filter(population => this.hasText(population.descripcion)); }
|
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() {
|
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(); });
|
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(); });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,17 +40,9 @@ export interface IndicadorFiguraDetalle {
|
|||||||
descripcion: string | null;
|
descripcion: string | null;
|
||||||
como_leer: 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 {
|
export interface IndicadorMetadatos {
|
||||||
descripcion?: string | null;
|
descripcion?: string | null;
|
||||||
ficha?: IndicadorFicha | null;
|
ficha?: IndicadorFicha | null;
|
||||||
parametros?: IndicadorParametro[] | null;
|
|
||||||
referencias?: { tipo: string; etiqueta: string; ref: string | null }[] | null;
|
referencias?: { tipo: string; etiqueta: string; ref: string | null }[] | null;
|
||||||
poblaciones?: { grupo: string; codigo: string; descripcion: string }[] | null;
|
poblaciones?: { grupo: string; codigo: string; descripcion: string }[] | null;
|
||||||
figuras_detalle?: IndicadorFiguraDetalle[] | null;
|
figuras_detalle?: IndicadorFiguraDetalle[] | null;
|
||||||
|
|||||||
@@ -48,30 +48,11 @@ describe('IndicadoresService HTTP', () => {
|
|||||||
expect(error).toBeInstanceOf(Error);
|
expect(error).toBeInstanceOf(Error);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('acepta parámetros publicados con valores de cualquier tipo y fuente opcional', () => {
|
it('ignora parametros: ni los valida ni bloquea los metadatos aunque vengan mal formados', () => {
|
||||||
const parametros = [
|
let value: unknown;
|
||||||
{ 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;
|
|
||||||
service.metadatos('cacu', 'p').subscribe(v => value = v);
|
service.metadatos('cacu', 'p').subscribe(v => value = v);
|
||||||
http.expectOne('/cacu/indicadores/p/metadatos').flush({ parametros });
|
http.expectOne('/cacu/indicadores/p/metadatos').flush({ descripcion: 'Descripción', parametros: 'incorrecto' });
|
||||||
service.metadatos('cacu', 'n').subscribe(v => nulo = v);
|
expect(value).toMatchObject({ descripcion: 'Descripción' });
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each(['tea', 'cacu', 'cama'] as const)('lee catálogo sintético dinámico de %s y sus tipos publicados', dominio => {
|
it.each(['tea', 'cacu', 'cama'] as const)('lee catálogo sintético dinámico de %s y sus tipos publicados', dominio => {
|
||||||
|
|||||||
@@ -40,13 +40,6 @@ export class IndicadoresService {
|
|||||||
if (content !== undefined && content !== null && typeof content !== 'string') throw new Error('Metadatos inválidos');
|
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']) {
|
for (const field of ['referencias', 'poblaciones']) {
|
||||||
const list = value[field];
|
const list = value[field];
|
||||||
if (list !== undefined && list !== null && (!Array.isArray(list) || !list.every(v => record(v) && (field === 'referencias'
|
if (list !== undefined && list !== null && (!Array.isArray(list) || !list.every(v => record(v) && (field === 'referencias'
|
||||||
|
|||||||
Reference in New Issue
Block a user