CaMa development view reads each table's column order
This commit is contained in:
@@ -6,12 +6,13 @@ import { catchError, map, Observable, of, throwError } from 'rxjs';
|
||||
// the cohort (variables kept, odds ratios, Bayesian network arcs, risk factors, subgroup curves) as tables, and their
|
||||
// figures. They describe the cohort, never a patient. A 404 is "no version with a development record yet".
|
||||
export type FilaDeTabla = Record<string, string | number | boolean | null>;
|
||||
export interface TablaDesarrollo { columnas: string[]; filas: FilaDeTabla[]; }
|
||||
export interface RegistroDesarrollo {
|
||||
n: number;
|
||||
etapas: { etapa: string; estado: string; segundos: number }[];
|
||||
errores: Record<string, string>;
|
||||
variables_no_disponibles: string[];
|
||||
tablas: Record<string, FilaDeTabla[]>;
|
||||
tablas: Record<string, TablaDesarrollo>;
|
||||
figuras: Record<string, string>;
|
||||
}
|
||||
export interface RespuestaDesarrollo {
|
||||
@@ -35,7 +36,9 @@ export function respuestaDesarrollo(v: unknown): RespuestaDesarrollo {
|
||||
if (typeof d['n'] !== 'number' || !Array.isArray(d['etapas']) || !record(d['errores']) || !Array.isArray(d['variables_no_disponibles'])
|
||||
|| !record(d['tablas']) || !record(d['figuras'])) invalid();
|
||||
for (const e of d['etapas'] as unknown[]) if (!record(e) || !text(e['etapa']) || !text(e['estado'])) invalid();
|
||||
for (const rows of Object.values(d['tablas'] as Record<string, unknown>)) if (!Array.isArray(rows) || !rows.every(record)) invalid();
|
||||
for (const t of Object.values(d['tablas'] as Record<string, unknown>)) {
|
||||
if (!record(t) || !Array.isArray(t['columnas']) || !t['columnas'].every(text) || !Array.isArray(t['filas']) || !t['filas'].every(record)) invalid();
|
||||
}
|
||||
for (const png of Object.values(d['figuras'] as Record<string, unknown>)) if (!text(png) || !/^[A-Za-z0-9+/=]+$/.test(png)) invalid();
|
||||
return {
|
||||
simulado: v['simulado'] === true,
|
||||
|
||||
@@ -14,7 +14,7 @@ function registroEjemplo(): any {
|
||||
desarrollo: {
|
||||
n: 500, etapas: [{ etapa: '01', estado: 'ok', segundos: 0 }, { etapa: '05', estado: 'error', segundos: 0 }],
|
||||
errores: { '05': 'ValueError: sin subgrupos' }, variables_no_disponibles: ['Estadio_cat', 'Radioterapia_cat'],
|
||||
tablas: { or_lr_balanceada: [{ indice: 'Grado_G3', OR: 2.5, p: 0.0123456 }], hbn_arcos: [] },
|
||||
tablas: { or_lr_balanceada: { columnas: ['indice', 'OR', 'p'], filas: [{ indice: 'Grado_G3', OR: 2.5, p: 0.0123456 }] }, hbn_arcos: { columnas: [], filas: [] } },
|
||||
figuras: { sens_esp_edad: 'iVBORw0KGgo=' },
|
||||
},
|
||||
};
|
||||
@@ -28,7 +28,7 @@ describe('Desarrollo CaMa: respuesta', () => {
|
||||
// Fails if a record that would break the page (or inject markup through a figure) is accepted.
|
||||
it.each([
|
||||
['no model version', (d: any) => { delete d.modelo.version; }],
|
||||
['a table that is not rows', (d: any) => { d.desarrollo.tablas.hbn_arcos = 'x'; }],
|
||||
['a table that is not rows', (d: any) => { d.desarrollo.tablas.hbn_arcos = { columnas: ['a'], filas: 'x' }; }],
|
||||
['a figure that is not base64', (d: any) => { d.desarrollo.figuras.sens_esp_edad = '" onerror="x'; }],
|
||||
['no stages', (d: any) => { delete d.desarrollo.etapas; }],
|
||||
])('rejects %s', (_, estropear) => {
|
||||
@@ -77,6 +77,7 @@ describe('Desarrollo CaMa: componente', () => {
|
||||
expect(t).toContain('Razones de momios de la regresión logística (1)');
|
||||
expect(t).not.toContain('Arcos de la red bayesiana');
|
||||
expect(t).toContain('0.01235');
|
||||
expect([...el.querySelectorAll('th')].map(th => th.textContent!.trim())).toEqual(['indice', 'OR', 'p']);
|
||||
expect(t).toContain('Estadio_cat, Radioterapia_cat');
|
||||
expect(t).toContain('Etapa 05 no pudo calcularse');
|
||||
expect(el.querySelector('img')!.getAttribute('src')).toBe('data:image/png;base64,iVBORw0KGgo=');
|
||||
|
||||
@@ -51,10 +51,10 @@ export class CamaDesarrollo {
|
||||
|
||||
/** The tables the record holds, in display order, with their rows' columns. */
|
||||
tablas(datos: RespuestaDesarrollo): { id: string; titulo: string; columnas: string[]; filas: FilaDeTabla[] }[] {
|
||||
return TABLAS.filter(([id]) => datos.desarrollo.tablas[id]?.length)
|
||||
return TABLAS.filter(([id]) => datos.desarrollo.tablas[id]?.filas.length)
|
||||
.map(([id, titulo]) => {
|
||||
const filas = datos.desarrollo.tablas[id];
|
||||
return { id, titulo, columnas: Object.keys(filas[0]), filas };
|
||||
const { columnas, filas } = datos.desarrollo.tablas[id];
|
||||
return { id, titulo, columnas, filas };
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user