From 2216186d2604f1a0634ae88750357cf05494ebfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o?= Date: Sun, 29 Nov 2026 12:39:07 -0600 Subject: [PATCH] Patient lists have a search box; TEA alterations by their Spanish names --- src/app/indicadores/patient-search.spec.ts | 19 +++++ src/app/indicadores/patient-search.ts | 83 ++++++++++++++++++++++ src/app/indicadores/tab-riesgos-tea.html | 1 + src/app/indicadores/tab-riesgos-tea.ts | 20 +++++- src/app/indicadores/tab-riesgos.html | 1 + src/app/indicadores/tab-riesgos.ts | 5 ++ src/app/indicadores/tab-seguimiento.html | 9 ++- src/app/indicadores/tab-seguimiento.ts | 5 ++ 8 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 src/app/indicadores/patient-search.spec.ts create mode 100644 src/app/indicadores/patient-search.ts diff --git a/src/app/indicadores/patient-search.spec.ts b/src/app/indicadores/patient-search.spec.ts new file mode 100644 index 0000000..873ca12 --- /dev/null +++ b/src/app/indicadores/patient-search.spec.ts @@ -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); + }); +}); diff --git a/src/app/indicadores/patient-search.ts b/src/app/indicadores/patient-search.ts new file mode 100644 index 0000000..ba73080 --- /dev/null +++ b/src/app/indicadores/patient-search.ts @@ -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: ` + + Buscar paciente + + @if (value()) { + + } @else { + + } + + `, + styles: ` + .patient-search { + min-width: 18rem; + } + `, +}) +export class PatientSearch { + /** The search as applied. */ + readonly value = model(''); + readonly searched = output(); + 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(); + } +} diff --git a/src/app/indicadores/tab-riesgos-tea.html b/src/app/indicadores/tab-riesgos-tea.html index a034362..e9f24cb 100644 --- a/src/app/indicadores/tab-riesgos-tea.html +++ b/src/app/indicadores/tab-riesgos-tea.html @@ -1,6 +1,7 @@

Alteraciones de EEG relacionadas al TEA

+ Fecha de corte diff --git a/src/app/indicadores/tab-riesgos-tea.ts b/src/app/indicadores/tab-riesgos-tea.ts index 2cadbf0..a51de02 100644 --- a/src/app/indicadores/tab-riesgos-tea.ts +++ b/src/app/indicadores/tab-riesgos-tea.ts @@ -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 = { 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(() => diff --git a/src/app/indicadores/tab-riesgos.html b/src/app/indicadores/tab-riesgos.html index 191a17e..fda4a21 100644 --- a/src/app/indicadores/tab-riesgos.html +++ b/src/app/indicadores/tab-riesgos.html @@ -1,4 +1,5 @@
+ Fecha de corte (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(), diff --git a/src/app/indicadores/tab-seguimiento.html b/src/app/indicadores/tab-seguimiento.html index b2ec399..66dd6c9 100644 --- a/src/app/indicadores/tab-seguimiento.html +++ b/src/app/indicadores/tab-seguimiento.html @@ -1,4 +1,5 @@ + Fecha de corte - {{ - row.name ?? row.patient.id!.slice(0, 10) - }} + {{ row.name ?? row.patient.id!.slice(0, 10) }} @if (row.curp) {
{{ row.curp }}
} diff --git a/src/app/indicadores/tab-seguimiento.ts b/src/app/indicadores/tab-seguimiento.ts index 87fd721..c35d163 100644 --- a/src/app/indicadores/tab-seguimiento.ts +++ b/src/app/indicadores/tab-seguimiento.ts @@ -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(''); protected readonly size = signal(20); + /** "Buscar paciente": her name, CURP or record number, as applied. */ + protected readonly search = signal(''); private readonly moved = signal(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(),