Patient lists have a search box; TEA alterations by their Spanish names
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { matchesSearch, patientSearch } from './patient-search';
|
||||
|
||||
describe('patient search', () => {
|
||||
it('asks the API by identifier for one word with a digit, else by name', () => {
|
||||
expect(patientSearch(' IARM800101MNLBVR09 ')).toEqual({ identifier: 'IARM800101MNLBVR09' });
|
||||
expect(patientSearch('0451A')).toEqual({ identifier: '0451A' });
|
||||
expect(patientSearch('martha ibarra')).toEqual({ name: 'martha ibarra' });
|
||||
expect(patientSearch('')).toEqual({});
|
||||
});
|
||||
|
||||
it('matches in the browser by word starts, case and accents ignored', () => {
|
||||
const texts = ['IBARRA RIVERA MARTHA', 'd5a6a924-f2ad', 'N0183'];
|
||||
expect(matchesSearch('már riv', texts)).toBe(true);
|
||||
expect(matchesSearch('d5a6', texts)).toBe(true);
|
||||
expect(matchesSearch('n0183', texts)).toBe(true);
|
||||
expect(matchesSearch('arth', texts)).toBe(false);
|
||||
expect(matchesSearch('', texts)).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,83 @@
|
||||
import { Component, model, output, signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
|
||||
/** A search box's text as FHIR Patient search parameters: one word with a digit is an
|
||||
* identifier (a CURP or a record number); anything else is her name. */
|
||||
export function patientSearch(text: string): { name?: string; identifier?: string } {
|
||||
const t = text.trim();
|
||||
if (!t) return {};
|
||||
return /\d/.test(t) && !/\s/.test(t) ? { identifier: t } : { name: t };
|
||||
}
|
||||
|
||||
const fold = (s: string) => s.normalize('NFKD').replace(/\p{M}/gu, '').toLowerCase();
|
||||
|
||||
/** Whether a row matches the search in the browser (lists loaded whole): each word starts a
|
||||
* word of one of its texts (a name, an identifier, the pseudonymous id). */
|
||||
export function matchesSearch(text: string, texts: (string | undefined)[]): boolean {
|
||||
const words = fold(text).split(/\s+/).filter(Boolean);
|
||||
if (!words.length) return true;
|
||||
const known = texts.filter((t): t is string => !!t).map((t) => fold(t).split(/\s+/));
|
||||
return known.some((parts) => words.every((w) => parts.some((p) => p.startsWith(w))));
|
||||
}
|
||||
|
||||
/** "Buscar paciente": applied on Enter or the search button, cleared with the cross. */
|
||||
@Component({
|
||||
selector: 'app-patient-search',
|
||||
imports: [FormsModule, MatButtonModule, MatFormFieldModule, MatIconModule, MatInputModule],
|
||||
template: `
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="patient-search">
|
||||
<mat-label>Buscar paciente</mat-label>
|
||||
<input
|
||||
matInput
|
||||
type="search"
|
||||
name="patient-search"
|
||||
[placeholder]="hint"
|
||||
[ngModel]="draft()"
|
||||
[ngModelOptions]="{ standalone: true }"
|
||||
(ngModelChange)="draft.set($event)"
|
||||
(keydown.enter)="$event.preventDefault(); apply()"
|
||||
/>
|
||||
@if (value()) {
|
||||
<button
|
||||
mat-icon-button
|
||||
matSuffix
|
||||
type="button"
|
||||
aria-label="Limpiar búsqueda"
|
||||
(click)="clear()"
|
||||
>
|
||||
<mat-icon>close</mat-icon>
|
||||
</button>
|
||||
} @else {
|
||||
<button mat-icon-button matSuffix type="button" aria-label="Buscar" (click)="apply()">
|
||||
<mat-icon>search</mat-icon>
|
||||
</button>
|
||||
}
|
||||
</mat-form-field>
|
||||
`,
|
||||
styles: `
|
||||
.patient-search {
|
||||
min-width: 18rem;
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class PatientSearch {
|
||||
/** The search as applied. */
|
||||
readonly value = model('');
|
||||
readonly searched = output<string>();
|
||||
protected readonly draft = signal('');
|
||||
protected readonly hint = 'Nombre, CURP o expediente';
|
||||
|
||||
protected apply(): void {
|
||||
const text = this.draft().trim();
|
||||
this.value.set(text);
|
||||
this.searched.emit(text);
|
||||
}
|
||||
protected clear(): void {
|
||||
this.draft.set('');
|
||||
this.apply();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<section class="card risk-tea" aria-labelledby="tea-risk-title">
|
||||
<h2 id="tea-risk-title" class="risk-title">Alteraciones de EEG relacionadas al TEA</h2>
|
||||
<div class="filters">
|
||||
<app-patient-search [(value)]="search" (searched)="pageIndex.set(0)" />
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Fecha de corte</mat-label>
|
||||
<input matInput type="date" [ngModel]="cutoff()" (ngModelChange)="cutoff.set($event)" />
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { METRIC_NAMES } from '../eeg-labels';
|
||||
import { KeyValuePipe } from '@angular/common';
|
||||
import { Component, computed, inject, input, resource, signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
@@ -11,6 +12,7 @@ import { EXT, Fhir, resources } from '../fhir';
|
||||
import { Loading } from '../loading';
|
||||
import { ageLabel } from './figures';
|
||||
import { name } from './measures';
|
||||
import { matchesSearch, PatientSearch } from './patient-search';
|
||||
|
||||
/** One child on TEA's list, as the list shows her (core.tea.follow_up). */
|
||||
export interface TeaRow {
|
||||
@@ -67,14 +69,18 @@ const CASE: Record<string, string> = {
|
||||
not_confirmed: 'Sin TEA',
|
||||
};
|
||||
/** `theta_power:above` → "theta_power (aumentado)". */
|
||||
export const alteration = (a: string) =>
|
||||
a.replace(/:(above|below)$/, (_, s) => (s === 'above' ? ' (aumentado)' : ' (disminuido)'));
|
||||
export const alteration = (a: string) => {
|
||||
const [metric, side] = a.split(':');
|
||||
const shown = (METRIC_NAMES[metric] ?? metric).replace(/ \(.*\)$/, '');
|
||||
return side ? `${shown} (${side === 'above' ? 'aumentado' : 'disminuido'})` : shown;
|
||||
};
|
||||
|
||||
/** "Análisis de Riesgo" for TEA: the children active in the window, what their EEGs show,
|
||||
* filtered as the old page filtered them. */
|
||||
@Component({
|
||||
selector: 'app-tab-riesgos-tea',
|
||||
imports: [
|
||||
PatientSearch,
|
||||
FormsModule,
|
||||
KeyValuePipe,
|
||||
Loading,
|
||||
@@ -100,6 +106,8 @@ export class TabRiesgosTea {
|
||||
protected readonly caseState = signal('');
|
||||
protected readonly altered = signal('');
|
||||
protected readonly size = signal(50);
|
||||
/** "Buscar paciente": the pseudonymous id, a record number or a name. */
|
||||
protected readonly search = signal('');
|
||||
protected readonly pageIndex = signal(0);
|
||||
/** The query as last asked for ("Consultar"). */
|
||||
private readonly asked = signal({ cutoff: '', window: 3 });
|
||||
@@ -141,7 +149,13 @@ export class TabRiesgosTea {
|
||||
(!band || (r.mchat !== undefined && band.test(r.mchat))) &&
|
||||
(!level || (r.css !== undefined && level.test(r.css))) &&
|
||||
(!this.caseState() || r.case === this.caseState()) &&
|
||||
(!this.altered() || r.alterations.includes(this.altered())),
|
||||
(!this.altered() || r.alterations.includes(this.altered())) &&
|
||||
matchesSearch(this.search(), [
|
||||
r.name,
|
||||
r.patient.id,
|
||||
...(r.patient.name ?? []).map((n) => n.text),
|
||||
...(r.patient.identifier ?? []).map((i) => i.value),
|
||||
]),
|
||||
);
|
||||
});
|
||||
protected readonly shown = computed(() =>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<form class="filters card" (submit)="$event.preventDefault()">
|
||||
<app-patient-search [(value)]="search" />
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Fecha de corte</mat-label>
|
||||
<input
|
||||
|
||||
@@ -9,6 +9,7 @@ import { RouterLink } from '@angular/router';
|
||||
import type { Bundle } from 'fhir/r4';
|
||||
import { Fhir } from '../fhir';
|
||||
import { Row, rows, windowStart } from './follow-up';
|
||||
import { PatientSearch, patientSearch } from './patient-search';
|
||||
import { Loading } from '../loading';
|
||||
import { name } from './measures';
|
||||
|
||||
@@ -19,6 +20,7 @@ const STATUSES = ['case', 'pre_colposcopy', 'post_colposcopy', 'post_treatment']
|
||||
@Component({
|
||||
selector: 'app-tab-riesgos',
|
||||
imports: [
|
||||
PatientSearch,
|
||||
DecimalPipe,
|
||||
FormsModule,
|
||||
Loading,
|
||||
@@ -41,6 +43,8 @@ export class TabRiesgos {
|
||||
protected readonly horizon = signal(5);
|
||||
protected readonly sort = signal('-recent');
|
||||
protected readonly size = signal(20);
|
||||
/** "Buscar paciente": her name, CURP or record number, as applied. */
|
||||
protected readonly search = signal('');
|
||||
/** A page the user moved to (`next`/`previous`), else the first. */
|
||||
private readonly moved = signal<Bundle | undefined>(undefined);
|
||||
|
||||
@@ -51,6 +55,7 @@ export class TabRiesgos {
|
||||
params: () => ({
|
||||
domain: this.domain(),
|
||||
'follow-up-window': this.window(),
|
||||
...patientSearch(this.search()),
|
||||
'follow-up-cutoff': this.cutoff() || undefined,
|
||||
'follow-up-status': this.status() || undefined,
|
||||
'risk-horizon': this.horizon(),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<form class="filters card" (submit)="$event.preventDefault()">
|
||||
<app-patient-search [(value)]="search" />
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Fecha de corte</mat-label>
|
||||
<input
|
||||
@@ -66,9 +67,11 @@
|
||||
@for (row of rows(); track row.patient.id) {
|
||||
<tr>
|
||||
<td>
|
||||
<a [routerLink]="['/indicadores', domain(), 'pacientes', row.patient.id]">{{
|
||||
row.name ?? row.patient.id!.slice(0, 10)
|
||||
}}</a>
|
||||
<a
|
||||
[routerLink]="['/indicadores', domain(), 'pacientes', row.patient.id]"
|
||||
[queryParams]="{ ventana: window(), corte: applied() }"
|
||||
>{{ row.name ?? row.patient.id!.slice(0, 10) }}</a
|
||||
>
|
||||
@if (row.curp) {
|
||||
<div class="muted curp">{{ row.curp }}</div>
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { RouterLink } from '@angular/router';
|
||||
import type { Bundle } from 'fhir/r4';
|
||||
import { Fhir } from '../fhir';
|
||||
import { camaRows, windowStart } from './follow-up';
|
||||
import { PatientSearch, patientSearch } from './patient-search';
|
||||
import { Loading } from '../loading';
|
||||
import { name, PRIORITY } from './measures';
|
||||
|
||||
@@ -18,6 +19,7 @@ const STATUSES = ['cancer', 'pending_biopsy', 'biopsy_no_result', 'benign_biopsy
|
||||
@Component({
|
||||
selector: 'app-tab-seguimiento',
|
||||
imports: [
|
||||
PatientSearch,
|
||||
FormsModule,
|
||||
Loading,
|
||||
MatButtonModule,
|
||||
@@ -37,6 +39,8 @@ export class TabSeguimiento {
|
||||
protected readonly window = signal(3);
|
||||
protected readonly status = signal<string>('');
|
||||
protected readonly size = signal(20);
|
||||
/** "Buscar paciente": her name, CURP or record number, as applied. */
|
||||
protected readonly search = signal('');
|
||||
private readonly moved = signal<Bundle | undefined>(undefined);
|
||||
|
||||
protected readonly statuses = STATUSES;
|
||||
@@ -47,6 +51,7 @@ export class TabSeguimiento {
|
||||
params: () => ({
|
||||
domain: this.domain(),
|
||||
'follow-up-window': this.window(),
|
||||
...patientSearch(this.search()),
|
||||
'follow-up-cutoff': this.cutoff() || undefined,
|
||||
'follow-up-status': this.status() || undefined,
|
||||
_count: this.size(),
|
||||
|
||||
Reference in New Issue
Block a user