95 lines
3.9 KiB
TypeScript
95 lines
3.9 KiB
TypeScript
export const DOMINIOS = ['tea', 'cacu', 'cama'] as const;
|
|
export type Dominio = typeof DOMINIOS[number];
|
|
export type TipoPeriodo = 'semestre' | 'mes';
|
|
export function isDominio(value: unknown): value is Dominio {
|
|
return typeof value === 'string' && DOMINIOS.some(domain => domain === value);
|
|
}
|
|
export function requireDominio(value: unknown): Dominio {
|
|
if (!isDominio(value)) throw new Error('Dominio no permitido');
|
|
return value;
|
|
}
|
|
export interface Indicador {
|
|
id: string;
|
|
version?: string;
|
|
titulo: string;
|
|
contrato: string;
|
|
figuras: string[];
|
|
tipos_periodo: TipoPeriodo[];
|
|
filtros?: IndicadorFiltro[];
|
|
}
|
|
export type DimensionEstrato = 'grupo_edad' | 'estatus_seguimiento' | 'citologia_alto_grado';
|
|
export interface IndicadorFiltro { estrato: string; etiqueta: string; valores: { valor: string; etiqueta: string }[]; }
|
|
export interface DatosScope { estrato?: DimensionEstrato; filtros?: readonly string[]; }
|
|
export interface EstratoTotal { periodo: string; grupo: string; estrato: string; n: number | null; suprimido: 0 | 1; }
|
|
export interface IndicadorDatosEstratificados extends IndicadorDatos {
|
|
estrato: DimensionEstrato;
|
|
valores_estrato: string[];
|
|
etiquetas_estrato: Record<string, string>;
|
|
totales_estrato?: EstratoTotal[];
|
|
}
|
|
export interface IndicadorFicha {
|
|
codigo?: string | null;
|
|
para?: string | null;
|
|
unidad?: string | null;
|
|
pregunta?: string | null;
|
|
definicion?: string | null;
|
|
nota?: string | null;
|
|
}
|
|
export interface IndicadorFiguraDetalle {
|
|
figura: string;
|
|
descripcion: string | null;
|
|
como_leer: string[] | null;
|
|
}
|
|
export interface IndicadorMetadatos {
|
|
descripcion?: string | null;
|
|
ficha?: IndicadorFicha | null;
|
|
referencias?: { tipo: string; etiqueta: string; ref: string | null }[] | null;
|
|
poblaciones?: { grupo: string; codigo: string; descripcion: string }[] | null;
|
|
figuras_detalle?: IndicadorFiguraDetalle[] | null;
|
|
categorias?: Record<string, { etiqueta: string; color?: string | null }>;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
// Keep the complete HTTP figure, including future attributes and interpretation notes.
|
|
export interface PlotlyFigure {
|
|
data: Record<string, unknown>[];
|
|
layout: Record<string, unknown>;
|
|
frames?: Record<string, unknown>[];
|
|
config?: Record<string, unknown>;
|
|
[key: string]: unknown;
|
|
}
|
|
export type Tema = 'claro' | 'oscuro';
|
|
export interface FigureSelection { dominio?: Dominio; tipoPeriodo?: TipoPeriodo; indicador: string; figura: string; tema: Tema; periodos?: string[]; }
|
|
|
|
export function parsePeriodos(value: string, tipo: TipoPeriodo = 'semestre'): string[] | null {
|
|
if (tipo !== 'semestre' && tipo !== 'mes') return null;
|
|
const parts = value.split(',').map(part => part.trim());
|
|
return parts.length && parts.every(part => part.slice(0, 4) !== '0000' && (tipo === 'semestre' ? /^[0-9]{4}-S[12]$/ : /^[0-9]{4}-(0[1-9]|1[0-2])$/).test(part))
|
|
? [...new Set(parts)] : null;
|
|
}
|
|
|
|
// Only assert emptiness for known traces with ordinary arrays. Unknown/binary
|
|
// representations remain indeterminate; never infer counts or suppression causes.
|
|
export function hasNoVisibleValues(figure: PlotlyFigure): boolean {
|
|
return figure.data.every(trace => {
|
|
if (trace['visible'] === false || trace['visible'] === 'legendonly') return true;
|
|
const type = trace['type'] ?? 'scatter';
|
|
const values = type === 'box' ? trace['median'] ?? trace['y']
|
|
: type === 'bar' ? (trace['orientation'] === 'h' ? trace['x'] : trace['orientation'] === undefined || trace['orientation'] === 'v' ? trace['y'] : undefined)
|
|
: type === 'pie' ? trace['values']
|
|
: type === 'scatter' ? trace['y'] : undefined;
|
|
if (!Array.isArray(values)) return false;
|
|
return values.every(value => value === null || value === undefined || (typeof value === 'number' && !Number.isFinite(value)));
|
|
});
|
|
}
|
|
|
|
export interface IndicadorDatos {
|
|
id: string;
|
|
contrato: string;
|
|
tipo_periodo: TipoPeriodo;
|
|
periodos: string[];
|
|
filas: Record<string, unknown>[];
|
|
notas?: string[];
|
|
[key: string]: unknown;
|
|
}
|