Integra fecha de nacimiento y contrato de seguimiento CaCu
This commit is contained in:
@@ -23,9 +23,7 @@ export function validSeguimientoQuery(q: SeguimientoQuery) {
|
|||||||
&& rangoEdadValido(q.edad_min, q.edad_max) && normalizarConsulta(q.q).length <= CONSULTA_MAXIMA;
|
&& rangoEdadValido(q.edad_min, q.edad_max) && normalizarConsulta(q.q).length <= CONSULTA_MAXIMA;
|
||||||
}
|
}
|
||||||
export function seguimientoResponse(v: unknown): SeguimientoResponse {
|
export function seguimientoResponse(v: unknown): SeguimientoResponse {
|
||||||
// The current authorization covers demonstration records only. Validate this
|
if (!record(v) || typeof v['simulado'] !== 'boolean') throw new Error('Respuesta de seguimiento inválida');
|
||||||
// before passing any item to the component; real-patient activation is separate.
|
|
||||||
if (!record(v) || v['simulado'] !== true) throw new Error('Esta vista solo admite datos de demostración.');
|
|
||||||
const p = v['paginacion'], window = v['ventana'], filters = v['filtros'];
|
const p = v['paginacion'], window = v['ventana'], filters = v['filtros'];
|
||||||
if (!isoDate(v['corte']) || !record(window) || ![1,3,6,12].includes(window['meses'] as number) || !isoDate(window['desde']) || !isoDate(window['hasta'])
|
if (!isoDate(v['corte']) || !record(window) || ![1,3,6,12].includes(window['meses'] as number) || !isoDate(window['desde']) || !isoDate(window['hasta'])
|
||||||
|| !record(filters) || (filters['estatus'] !== null && typeof filters['estatus'] !== 'string')
|
|| !record(filters) || (filters['estatus'] !== null && typeof filters['estatus'] !== 'string')
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ describe('Seguimiento CaCu con contrato de demostración', () => {
|
|||||||
responder(exportacion, ['P-1'], { paginacion: { total_items: 1, total_pages: 1 } });
|
responder(exportacion, ['P-1'], { paginacion: { total_items: 1, total_pages: 1 } });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('sin edad exacta del servicio dice «No disponible», no muestra el grupo de edad y señala la ausencia de fecha de nacimiento', () => {
|
it('sin edad exacta ni identificador demográfico muestra los estados correspondientes', () => {
|
||||||
respond();
|
respond();
|
||||||
const root: HTMLElement = fixture.nativeElement;
|
const root: HTMLElement = fixture.nativeElement;
|
||||||
const fila = root.querySelector<HTMLElement>('tr[data-paciente]')!;
|
const fila = root.querySelector<HTMLElement>('tr[data-paciente]')!;
|
||||||
@@ -237,9 +237,23 @@ describe('Seguimiento CaCu con contrato de demostración', () => {
|
|||||||
fila.querySelector('button')!.click();
|
fila.querySelector('button')!.click();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
const nacimiento = [...root.querySelectorAll('app-paciente-detalle dt')].find(dt => dt.textContent === 'Fecha de nacimiento');
|
const nacimiento = [...root.querySelectorAll('app-paciente-detalle dt')].find(dt => dt.textContent === 'Fecha de nacimiento');
|
||||||
expect(nacimiento?.nextElementSibling?.textContent).toBe('No disponible');
|
expect(nacimiento?.nextElementSibling?.textContent?.trim()).toBe('No se pudo cargar');
|
||||||
http.expectNone(() => true);
|
http.expectNone(() => true);
|
||||||
});
|
});
|
||||||
|
it('muestra en la ficha la fecha recuperada para el paciente seleccionado', () => {
|
||||||
|
open().flush({ ...fixtureData, items: [{ ...fixtureData.items[0], pac_id: '42' }] });
|
||||||
|
http.expectOne('/cacu/indicadores/cacu_eu7/metadatos').flush({ categorias: {} });
|
||||||
|
fixture.detectChanges();
|
||||||
|
const root: HTMLElement = fixture.nativeElement;
|
||||||
|
root.querySelector<HTMLElement>('tr[data-paciente] button')!.click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
http.expectOne(r => r.url === '/cacu/fhir/RiskAssessment').flush({}, { status: 404, statusText: 'Not Found' });
|
||||||
|
const nacimiento = [...root.querySelectorAll('app-paciente-detalle dt')].find(dt => dt.textContent === 'Fecha de nacimiento')!;
|
||||||
|
expect(nacimiento.nextElementSibling?.textContent).toContain('Cargando');
|
||||||
|
http.expectOne('/cacu/seguimiento/pacientes/42/demografia').flush({ pac_id: '42', fecha_nacimiento: '1980-01-02' });
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(nacimiento.nextElementSibling?.textContent?.trim()).toBe('02/01/1980');
|
||||||
|
});
|
||||||
// Why: the exact age is shown only when the service gives it, as whole years, and never estimated from the age group.
|
// Why: the exact age is shown only when the service gives it, as whole years, and never estimated from the age group.
|
||||||
it('muestra la edad exacta en años y distingue la edad ausente de una edad de 0 años', () => {
|
it('muestra la edad exacta en años y distingue la edad ausente de una edad de 0 años', () => {
|
||||||
const items = [{ ...fixtureData.items[0], edad_al_corte: 42 }, { ...fixtureData.items[1], edad_al_corte: 1 }, { ...fixtureData.items[2], edad_al_corte: 0 },
|
const items = [{ ...fixtureData.items[0], edad_al_corte: 42 }, { ...fixtureData.items[1], edad_al_corte: 1 }, { ...fixtureData.items[2], edad_al_corte: 0 },
|
||||||
@@ -310,11 +324,16 @@ describe('Seguimiento CaCu con contrato de demostración', () => {
|
|||||||
http.expectOne('/cacu/indicadores/cacu_eu7/metadatos').flush({}, {status:404,statusText:'Absent'}); fixture.detectChanges();
|
http.expectOne('/cacu/indicadores/cacu_eu7/metadatos').flush({}, {status:404,statusText:'Absent'}); fixture.detectChanges();
|
||||||
expect(fixture.nativeElement.textContent).toContain('No hay registros');
|
expect(fixture.nativeElement.textContent).toContain('No hay registros');
|
||||||
});
|
});
|
||||||
it('no activa registros reales ni acepta respuestas malformadas', () => {
|
it('acepta ambas marcas de simulación y rechaza respuestas malformadas', () => {
|
||||||
expect(()=>seguimientoResponse({...fixtureData,simulado:false})).toThrow();
|
expect(seguimientoResponse({...fixtureData,simulado:false}).simulado).toBe(false);
|
||||||
|
expect(tablaExportacionCaCu(seguimientoResponse({...fixtureData,simulado:false}), () => '', () => null).simulado).toBe(false);
|
||||||
|
expect(seguimientoResponse({...fixtureData,simulado:true}).simulado).toBe(true);
|
||||||
|
expect(()=>seguimientoResponse({...fixtureData,simulado:'false'})).toThrow();
|
||||||
expect(()=>seguimientoResponse({...fixtureData,items:[{...fixtureData.items[0],ultimo_vph:{fecha:'bad'}}]})).toThrow();
|
expect(()=>seguimientoResponse({...fixtureData,items:[{...fixtureData.items[0],ultimo_vph:{fecha:'bad'}}]})).toThrow();
|
||||||
expect(()=>seguimientoResponse({...fixtureData,items:[{...fixtureData.items[2],ultima_citologia:{...fixtureData.items[2].ultima_citologia,calidad:42}}]})).toThrow();
|
expect(()=>seguimientoResponse({...fixtureData,items:[{...fixtureData.items[2],ultima_citologia:{...fixtureData.items[2].ultima_citologia,calidad:42}}]})).toThrow();
|
||||||
open().flush({...fixtureData,simulado:false}); fixture.detectChanges(); expect(fixture.nativeElement.querySelector('tbody')).toBeNull();
|
open().flush({...fixtureData,simulado:false});
|
||||||
|
http.expectOne('/cacu/indicadores/cacu_eu7/metadatos').flush({categorias:{}});
|
||||||
|
fixture.detectChanges(); expect(fixture.nativeElement.querySelector('tbody')).not.toBeNull();
|
||||||
});
|
});
|
||||||
it('valida parámetros antes del transporte sin confundir fechas del filtro general', () => {
|
it('valida parámetros antes del transporte sin confundir fechas del filtro general', () => {
|
||||||
const service=TestBed.inject(CacuSeguimientoService);
|
const service=TestBed.inject(CacuSeguimientoService);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export function tablaExportacionCaCu(
|
|||||||
const probabilidades = estatus ? COLUMNAS_DE_PROBABILIDAD[estatus] ?? [] : [];
|
const probabilidades = estatus ? COLUMNAS_DE_PROBABILIDAD[estatus] ?? [] : [];
|
||||||
const horizonteMostrado = horizonte ?? 5;
|
const horizonteMostrado = horizonte ?? 5;
|
||||||
return {
|
return {
|
||||||
simulado: true,
|
simulado: respuesta.simulado,
|
||||||
corte: respuesta.corte,
|
corte: respuesta.corte,
|
||||||
ventana: respuesta.ventana,
|
ventana: respuesta.ventana,
|
||||||
paginacion: respuesta.paginacion,
|
paginacion: respuesta.paginacion,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
@if (pacienteDetalle.estado().tipo !== 'cerrado') {
|
@if (pacienteDetalle.estado().tipo !== 'cerrado') {
|
||||||
<app-paciente-detalle [estado]="pacienteDetalle.estado()" [categorias]="categories"
|
<app-paciente-detalle [estado]="pacienteDetalle.estado()" [nacimiento]="pacienteDetalle.nacimiento()" [categorias]="categories"
|
||||||
[registrosTemporales]="pacienteDetalle.registrosTemporales()"
|
[registrosTemporales]="pacienteDetalle.registrosTemporales()"
|
||||||
(registroAgregado)="pacienteDetalle.agregarRegistro($event)" (volver)="volverASeguimiento()" />
|
(registroAgregado)="pacienteDetalle.agregarRegistro($event)" (volver)="volverASeguimiento()" />
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,11 @@
|
|||||||
<p>Fecha de corte: {{ estado.resumen.corte }}.</p>
|
<p>Fecha de corte: {{ estado.resumen.corte }}.</p>
|
||||||
<dl class="summary">
|
<dl class="summary">
|
||||||
<div><dt>{{ etiquetaIdentidad }}</dt><dd>{{ estado.resumen.identidad.id }}</dd></div>
|
<div><dt>{{ etiquetaIdentidad }}</dt><dd>{{ estado.resumen.identidad.id }}</dd></div>
|
||||||
<div><dt>Fecha de nacimiento</dt><dd>No disponible</dd></div>
|
<div><dt>Fecha de nacimiento</dt><dd>
|
||||||
|
@if (nacimiento.tipo === 'cargando') { <span role="status">Cargando…</span> }
|
||||||
|
@else if (nacimiento.tipo === 'error') { <span role="alert">No se pudo cargar</span> }
|
||||||
|
@else { {{ nacimiento.valor ?? 'No disponible' }} }
|
||||||
|
</dd></div>
|
||||||
<div><dt>Grupo de edad</dt><dd>{{ estado.resumen.grupoEdad ?? 'No disponible' }}</dd></div>
|
<div><dt>Grupo de edad</dt><dd>{{ estado.resumen.grupoEdad ?? 'No disponible' }}</dd></div>
|
||||||
<div><dt>Estatus de seguimiento</dt><dd>{{ estado.resumen.estatus ?? 'No disponible' }}</dd></div>
|
<div><dt>Estatus de seguimiento</dt><dd>{{ estado.resumen.estatus ?? 'No disponible' }}</dd></div>
|
||||||
<div><dt>Días de toma a diagnóstico</dt><dd>{{ estado.resumen.diasTomaDiagnostico ?? 'No disponible' }}</dd></div>
|
<div><dt>Días de toma a diagnóstico</dt><dd>{{ estado.resumen.diasTomaDiagnostico ?? 'No disponible' }}</dd></div>
|
||||||
|
|||||||
@@ -46,10 +46,30 @@ describe('Proveedor de detalle sintético', () => {
|
|||||||
|
|
||||||
describe('Estado de selección del paciente', () => {
|
describe('Estado de selección del paciente', () => {
|
||||||
function setup(provider: PacienteDetalleProvider) {
|
function setup(provider: PacienteDetalleProvider) {
|
||||||
TestBed.configureTestingModule({ providers: [PacienteDetalleState, { provide: PACIENTE_DETALLE_PROVIDER, useValue: provider }] });
|
TestBed.configureTestingModule({ providers: [provideHttpClient(), provideHttpClientTesting(), PacienteDetalleState, { provide: PACIENTE_DETALLE_PROVIDER, useValue: provider }] });
|
||||||
return TestBed.inject(PacienteDetalleState);
|
return TestBed.inject(PacienteDetalleState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it('carga la fecha del paciente seleccionado y distingue nulo, error y respuestas cruzadas', () => {
|
||||||
|
const state = setup({ obtener: () => of(null) });
|
||||||
|
const http = TestBed.inject(HttpTestingController);
|
||||||
|
const paciente = { ...pacientes[0], pac_id: '42' };
|
||||||
|
state.abrir(paciente, fixtureData.corte);
|
||||||
|
expect(state.nacimiento().tipo).toBe('cargando');
|
||||||
|
http.expectOne('/cacu/seguimiento/pacientes/42/demografia').flush({ pac_id: '42', fecha_nacimiento: '1980-01-02' });
|
||||||
|
expect(state.nacimiento()).toEqual({ tipo: 'disponible', valor: '02/01/1980' });
|
||||||
|
state.abrir(paciente, fixtureData.corte);
|
||||||
|
http.expectOne('/cacu/seguimiento/pacientes/42/demografia').flush({ pac_id: '42', fecha_nacimiento: null });
|
||||||
|
expect(state.nacimiento()).toEqual({ tipo: 'disponible', valor: null });
|
||||||
|
state.abrir(paciente, fixtureData.corte);
|
||||||
|
http.expectOne('/cacu/seguimiento/pacientes/42/demografia').flush({ pac_id: '43', fecha_nacimiento: '1980-01-02' });
|
||||||
|
expect(state.nacimiento().tipo).toBe('error');
|
||||||
|
state.abrir(paciente, fixtureData.corte);
|
||||||
|
http.expectOne('/cacu/seguimiento/pacientes/42/demografia').flush('error', { status: 500, statusText: 'Error' });
|
||||||
|
expect(state.nacimiento().tipo).toBe('error');
|
||||||
|
http.verify();
|
||||||
|
});
|
||||||
|
|
||||||
it('entrega el seudónimo sin conversión y toma una instantánea independiente de la fila', () => {
|
it('entrega el seudónimo sin conversión y toma una instantánea independiente de la fila', () => {
|
||||||
const obtener = vi.fn(() => of(null));
|
const obtener = vi.fn(() => of(null));
|
||||||
const state = setup({ obtener });
|
const state = setup({ obtener });
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { computed, DestroyRef, Injectable, inject, signal } from '@angular/core';
|
import { computed, DestroyRef, Injectable, inject, signal } from '@angular/core';
|
||||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||||
import { Subject, catchError, defer, map, of, switchMap } from 'rxjs';
|
import { Subject, catchError, defer, map, of, switchMap } from 'rxjs';
|
||||||
import { SeguimientoPaciente } from '../cacu-seguimiento.models';
|
import { isoDate, SeguimientoPaciente } from '../cacu-seguimiento.models';
|
||||||
import { identidadDe } from '../paciente-identidad';
|
import { identidadDe } from '../paciente-identidad';
|
||||||
import { PacienteDetalleEstado, PacienteResumen } from './paciente-detalle.models';
|
import { PacienteDetalleEstado, PacienteResumen } from './paciente-detalle.models';
|
||||||
import { PACIENTE_DETALLE_PROVIDER } from './paciente-detalle.provider';
|
import { PACIENTE_DETALLE_PROVIDER } from './paciente-detalle.provider';
|
||||||
@@ -11,6 +12,9 @@ import { PacienteRegistrosSesion } from './paciente-registros-sesion';
|
|||||||
/** Selección por instancia de Seguimiento; las altas temporales viven aparte en la sesión Angular. */
|
/** Selección por instancia de Seguimiento; las altas temporales viven aparte en la sesión Angular. */
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PacienteDetalleState {
|
export class PacienteDetalleState {
|
||||||
|
private readonly http = inject(HttpClient);
|
||||||
|
private readonly nacimientoActual = signal<{ tipo: 'cargando' } | { tipo: 'error' } | { tipo: 'disponible'; valor: string | null }>({ tipo: 'cargando' });
|
||||||
|
readonly nacimiento = this.nacimientoActual.asReadonly();
|
||||||
private readonly provider = inject(PACIENTE_DETALLE_PROVIDER);
|
private readonly provider = inject(PACIENTE_DETALLE_PROVIDER);
|
||||||
private readonly sesion = inject(PacienteRegistrosSesion);
|
private readonly sesion = inject(PacienteRegistrosSesion);
|
||||||
private readonly seleccion = new Subject<PacienteResumen | null>();
|
private readonly seleccion = new Subject<PacienteResumen | null>();
|
||||||
@@ -22,6 +26,25 @@ export class PacienteDetalleState {
|
|||||||
});
|
});
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
this.seleccion.pipe(
|
||||||
|
switchMap(resumen => {
|
||||||
|
if (!resumen) return of({ tipo: 'cargando' } as const);
|
||||||
|
if (resumen.identidad.campo !== 'pac_id') return of({ tipo: 'error' } as const);
|
||||||
|
const id = resumen.identidad.id;
|
||||||
|
return this.http.get<unknown>(`/cacu/seguimiento/pacientes/${id}/demografia`).pipe(
|
||||||
|
map(valor => {
|
||||||
|
if (!valor || typeof valor !== 'object' || !('pac_id' in valor) || valor.pac_id !== id
|
||||||
|
|| !('fecha_nacimiento' in valor) || (valor.fecha_nacimiento !== null && !isoDate(valor.fecha_nacimiento))) {
|
||||||
|
throw new Error('Respuesta demográfica inválida');
|
||||||
|
}
|
||||||
|
const fecha = valor.fecha_nacimiento as string | null;
|
||||||
|
return { tipo: 'disponible', valor: fecha ? `${fecha.slice(8, 10)}/${fecha.slice(5, 7)}/${fecha.slice(0, 4)}` : null } as const;
|
||||||
|
}),
|
||||||
|
catchError(() => of({ tipo: 'error' } as const)),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
takeUntilDestroyed(inject(DestroyRef)),
|
||||||
|
).subscribe(estado => this.nacimientoActual.set(estado));
|
||||||
this.seleccion.pipe(
|
this.seleccion.pipe(
|
||||||
switchMap(resumen => resumen ? defer(() => this.provider.obtener(resumen.identidad.id)).pipe(
|
switchMap(resumen => resumen ? defer(() => this.provider.obtener(resumen.identidad.id)).pipe(
|
||||||
map(detalle => {
|
map(detalle => {
|
||||||
@@ -61,6 +84,7 @@ export class PacienteDetalleState {
|
|||||||
diasTomaDiagnostico: paciente.dias_toma_diagnostico,
|
diasTomaDiagnostico: paciente.dias_toma_diagnostico,
|
||||||
prioridad: paciente.prioridad?.etiqueta ?? null,
|
prioridad: paciente.prioridad?.etiqueta ?? null,
|
||||||
};
|
};
|
||||||
|
this.nacimientoActual.set({ tipo: 'cargando' });
|
||||||
this.actual.set({ tipo: 'cargando', resumen });
|
this.actual.set({ tipo: 'cargando', resumen });
|
||||||
this.seleccion.next(resumen);
|
this.seleccion.next(resumen);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { downloadBlob, exportFilename } from '../export/download-file';
|
|||||||
})
|
})
|
||||||
export class PacienteDetalleComponent implements AfterViewInit, OnDestroy {
|
export class PacienteDetalleComponent implements AfterViewInit, OnDestroy {
|
||||||
@Input({ required: true }) estado: PacienteDetalleEstado = { tipo: 'cerrado' };
|
@Input({ required: true }) estado: PacienteDetalleEstado = { tipo: 'cerrado' };
|
||||||
|
@Input() nacimiento: { tipo: 'cargando' } | { tipo: 'error' } | { tipo: 'disponible'; valor: string | null } = { tipo: 'cargando' };
|
||||||
@Input() categorias: Record<string, { etiqueta: string }> = {};
|
@Input() categorias: Record<string, { etiqueta: string }> = {};
|
||||||
@Input() registrosTemporales: readonly RegistroTemporal[] = [];
|
@Input() registrosTemporales: readonly RegistroTemporal[] = [];
|
||||||
readonly volver = output<void>();
|
readonly volver = output<void>();
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export interface SeguimientoTablaQuery {
|
|||||||
contexto?: ContextoLista;
|
contexto?: ContextoLista;
|
||||||
}
|
}
|
||||||
export interface SeguimientoTablaResponse extends Partial<ContextoLista> {
|
export interface SeguimientoTablaResponse extends Partial<ContextoLista> {
|
||||||
simulado: true;
|
simulado: boolean;
|
||||||
corte: string;
|
corte: string;
|
||||||
ventana: { meses: MesesVentana; desde: string; hasta: string };
|
ventana: { meses: MesesVentana; desde: string; hasta: string };
|
||||||
filtros: Record<string, string | null>;
|
filtros: Record<string, string | null>;
|
||||||
|
|||||||
Reference in New Issue
Block a user