CaMa indicators and follow-up list, model governance page
This commit is contained in:
@@ -24,14 +24,18 @@ const AGE_GROUPS: [number, number][] = [
|
||||
[55, 64],
|
||||
];
|
||||
|
||||
export function ageGroup(birth: string | undefined, at: string): string {
|
||||
export function ageGroup(
|
||||
birth: string | undefined,
|
||||
at: string,
|
||||
groups: [number, number][] = AGE_GROUPS,
|
||||
): string {
|
||||
if (!birth) return 'Sin dato';
|
||||
const [by, bm, bd] = birth.split('-').map(Number);
|
||||
const [y, m, d] = at.split('-').map(Number);
|
||||
const age = y - by - (m < bm || (m === bm && d < bd) ? 1 : 0);
|
||||
const found = AGE_GROUPS.find(([lo, hi]) => lo <= age && age <= hi);
|
||||
const found = groups.find(([lo, hi]) => lo <= age && age <= hi);
|
||||
if (found) return `${found[0]}-${found[1]}`;
|
||||
return age < AGE_GROUPS[0][0] ? `<${AGE_GROUPS[0][0]}` : `${AGE_GROUPS.at(-1)![1] + 1}+`;
|
||||
return age < groups[0][0] ? `<${groups[0][0]}` : `${groups.at(-1)![1] + 1}+`;
|
||||
}
|
||||
|
||||
/** Her current risk of an outcome at a horizon: from the latest index date any of the
|
||||
@@ -132,3 +136,71 @@ export function windowStart(cutoff: string, months: number): string {
|
||||
const day = new Date(Date.UTC(year, month, Math.min(d, last) + 1));
|
||||
return day.toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
/** One row of CaMa's follow-up list: her latest mammogram reported by the cut-off, where the
|
||||
* biopsy it led to stands, and how soon she should be seen. */
|
||||
export interface CamaRow {
|
||||
patient: Patient;
|
||||
name?: string;
|
||||
curp?: string;
|
||||
status: string;
|
||||
priority: string;
|
||||
ageGroup: string;
|
||||
mammogram: { date: string; birads?: string };
|
||||
biopsy?: { date: string; histology?: string };
|
||||
}
|
||||
|
||||
const CAMA_AGE_GROUPS: [number, number][] = [
|
||||
[40, 49],
|
||||
[50, 59],
|
||||
[60, 69],
|
||||
];
|
||||
|
||||
export function camaRows(page: Bundle, cutoff: string): CamaRow[] {
|
||||
const reports = resources<DiagnosticReport>(page, 'DiagnosticReport');
|
||||
const observations = new Map(resources<Observation>(page, 'Observation').map((o) => [o.id, o]));
|
||||
const results = (r: DiagnosticReport) =>
|
||||
new Map(
|
||||
(r.result ?? [])
|
||||
.map((x) => observations.get(x.reference?.split('/')[1]))
|
||||
.filter((o) => !!o)
|
||||
.map((o) => [code(o!.code), o!]),
|
||||
);
|
||||
const reported = (r: DiagnosticReport) => ext(r, 'report-date')?.valueDate;
|
||||
return resources<Patient>(page, 'Patient', 'match').map((patient) => {
|
||||
const mine = reports.filter((r) => r.subject?.reference === `Patient/${patient.id}`);
|
||||
const mammogram = mine
|
||||
.filter((r) => code(r.code) === 'mammography' && (reported(r) ?? '9') <= cutoff)
|
||||
.sort((a, b) => a.effectiveDateTime!.localeCompare(b.effectiveDateTime!))
|
||||
.at(-1);
|
||||
const exam = mammogram?.effectiveDateTime ?? '';
|
||||
const biopsy = mine
|
||||
.filter(
|
||||
(r) =>
|
||||
code(r.code) === 'breast_biopsy' &&
|
||||
results(r).get('breast_biopsy.mammogram_exam_date')?.valueDateTime === exam &&
|
||||
exam <= (reported(r) ?? '') &&
|
||||
reported(r)! <= cutoff,
|
||||
)
|
||||
.sort((a, b) => reported(a)!.localeCompare(reported(b)!))
|
||||
.at(-1);
|
||||
return {
|
||||
patient,
|
||||
name: patient.name?.[0]?.text,
|
||||
curp: patient.identifier?.find((i) => i.system === CURP)?.value,
|
||||
status: ext(patient, 'follow-up-status')?.valueCoding?.code ?? '',
|
||||
priority: ext(patient, 'follow-up-priority')?.valueCoding?.code ?? '',
|
||||
ageGroup: ageGroup(patient.birthDate, cutoff, CAMA_AGE_GROUPS),
|
||||
mammogram: {
|
||||
date: exam,
|
||||
birads: mammogram
|
||||
? code(results(mammogram).get('mammography.birads')?.valueCodeableConcept)
|
||||
: undefined,
|
||||
},
|
||||
biopsy: biopsy && {
|
||||
date: reported(biopsy)!,
|
||||
histology: code(results(biopsy).get('breast_biopsy.histology')?.valueCodeableConcept),
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,12 +6,20 @@ import { Fhir, resources } from '../fhir';
|
||||
import { TabDefiniciones } from './tab-definiciones';
|
||||
import { TabIndicadores } from './tab-indicadores';
|
||||
import { TabRiesgos } from './tab-riesgos';
|
||||
import { TabSeguimiento } from './tab-seguimiento';
|
||||
import { TabTrazabilidad } from './tab-trazabilidad';
|
||||
|
||||
/** A domain's indicator page: four tabs over its FHIR measures and patients. */
|
||||
@Component({
|
||||
selector: 'app-indicadores',
|
||||
imports: [MatTabsModule, TabIndicadores, TabTrazabilidad, TabRiesgos, TabDefiniciones],
|
||||
imports: [
|
||||
MatTabsModule,
|
||||
TabIndicadores,
|
||||
TabTrazabilidad,
|
||||
TabRiesgos,
|
||||
TabSeguimiento,
|
||||
TabDefiniciones,
|
||||
],
|
||||
template: `
|
||||
<section class="page">
|
||||
<h1>{{ title() }}</h1>
|
||||
@@ -34,12 +42,18 @@ import { TabTrazabilidad } from './tab-trazabilidad';
|
||||
<app-tab-trazabilidad [domain]="domain()" [measures]="measures.value()!" />
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
@if (patients()) {
|
||||
@if (domain() === 'cacu') {
|
||||
<mat-tab label="Análisis de riesgos">
|
||||
<ng-template matTabContent>
|
||||
<app-tab-riesgos [domain]="domain()" />
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
} @else if (domain() === 'cama') {
|
||||
<mat-tab label="Seguimiento">
|
||||
<ng-template matTabContent>
|
||||
<app-tab-seguimiento [domain]="domain()" />
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
}
|
||||
<mat-tab label="Datos y definiciones">
|
||||
<ng-template matTabContent>
|
||||
@@ -80,6 +94,4 @@ export class Indicadores {
|
||||
loader: async ({ params }) =>
|
||||
resources<Measure>(await this.fhir.all(params, 'Measure'), 'Measure'),
|
||||
});
|
||||
/** Patient-level analysis is served for CaCu only (so far). */
|
||||
protected readonly patients = computed(() => this.domain() === 'cacu');
|
||||
}
|
||||
|
||||
@@ -44,4 +44,28 @@ export const LAYOUTS: Record<string, Layout> = {
|
||||
],
|
||||
anchor: 'IND1',
|
||||
},
|
||||
cama: {
|
||||
kpis: [
|
||||
'CAMA_BIRADS',
|
||||
'CAMA_EU38A',
|
||||
'CAMA_DIAS_TOMA_DIAGNOSTICO',
|
||||
'CAMA_CONFIRMACION_BIRADS45',
|
||||
'CAMA_TASA_DETECCION_HISTOPATOLOGICA',
|
||||
],
|
||||
route: [
|
||||
{
|
||||
label: 'Resultado de mastografía',
|
||||
step: 'Toma a resultado de mastografía',
|
||||
fromSample: 'CAMA_EU38A',
|
||||
fromStep: 'CAMA_EU38A',
|
||||
},
|
||||
{
|
||||
label: 'Diagnóstico',
|
||||
step: 'Del resultado de mastografía al diagnóstico',
|
||||
fromSample: 'CAMA_DIAS_TOMA_DIAGNOSTICO',
|
||||
fromStep: 'CAMA_DIAS_RESULTADO_DIAGNOSTICO',
|
||||
},
|
||||
],
|
||||
anchor: 'CAMA_BIRADS',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -99,12 +99,25 @@ const LABELS: Record<string, string> = {
|
||||
high: 'Alto',
|
||||
satisfactory: 'satisfactoria',
|
||||
unsatisfactory: 'insatisfactoria',
|
||||
benign: 'Benigno',
|
||||
in_situ: 'Carcinoma in situ',
|
||||
invasive: 'Carcinoma invasor',
|
||||
cancer: 'Diagnóstico confirmado',
|
||||
pending_biopsy: 'Pendiente de biopsia',
|
||||
biopsy_no_result: 'Biopsia sin resultado',
|
||||
benign_biopsy: 'Biopsia benigna',
|
||||
...Object.fromEntries(
|
||||
['0', '1', '2', '3', '4', '4A', '4B', '4C', '5', '6'].map((c) => [c, `BI-RADS ${c}`]),
|
||||
),
|
||||
};
|
||||
/** A follow-up priority's label. */
|
||||
export const PRIORITY: Record<string, string> = { high: 'Alta', medium: 'Media', low: 'Baja' };
|
||||
export const STRATA: Record<string, string> = {
|
||||
category: 'Categoría',
|
||||
age_group: 'Grupo de edad',
|
||||
follow_up_status: 'Estatus de seguimiento',
|
||||
result: 'Citología de alto grado',
|
||||
birads: 'BI-RADS de la mastografía',
|
||||
};
|
||||
export const name = (value: string) => LABELS[value] ?? value;
|
||||
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
<form class="filters card" (submit)="$event.preventDefault()">
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Fecha de corte</mat-label>
|
||||
<input
|
||||
matInput
|
||||
type="date"
|
||||
[ngModel]="cutoff() || applied()"
|
||||
(ngModelChange)="cutoff.set($event)"
|
||||
name="cutoff"
|
||||
/>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Ventana</mat-label>
|
||||
<mat-select [value]="window()" (selectionChange)="window.set($event.value)">
|
||||
@for (m of [1, 3, 6, 12]; track m) {
|
||||
<mat-option [value]="m">{{ m }} {{ m === 1 ? 'mes' : 'meses' }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Estatus</mat-label>
|
||||
<mat-select [value]="status()" (selectionChange)="status.set($event.value)">
|
||||
<mat-option value="">Todos</mat-option>
|
||||
@for (s of statuses; track s) {
|
||||
<mat-option [value]="s">{{ name(s) }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Por página</mat-label>
|
||||
<mat-select [value]="size()" (selectionChange)="size.set($event.value)">
|
||||
@for (n of [20, 50, 100]; track n) {
|
||||
<mat-option [value]="n">{{ n }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</form>
|
||||
|
||||
@if (error()) {
|
||||
<p class="muted" role="alert">No se pudo leer la lista de seguimiento.</p>
|
||||
}
|
||||
|
||||
<div class="table-wrap card">
|
||||
<table class="plain worklist">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Paciente</th>
|
||||
<th>Grupo de edad</th>
|
||||
<th>Mastografía</th>
|
||||
<th>Biopsia</th>
|
||||
<th>Estatus</th>
|
||||
<th>Prioridad</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@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>
|
||||
@if (row.curp) {
|
||||
<div class="muted curp">{{ row.curp }}</div>
|
||||
}
|
||||
</td>
|
||||
<td>{{ row.ageGroup }}</td>
|
||||
<td>{{ row.mammogram.date }} · {{ name(row.mammogram.birads ?? '') || 'Sin dato' }}</td>
|
||||
<td>
|
||||
@if (row.biopsy; as b) {
|
||||
{{ b.date }} · {{ name(b.histology ?? '') || 'Sin resultado' }}
|
||||
} @else {
|
||||
—
|
||||
}
|
||||
</td>
|
||||
<td>{{ name(row.status) }}</td>
|
||||
<td>{{ priority(row.priority) }}</td>
|
||||
</tr>
|
||||
} @empty {
|
||||
<tr>
|
||||
<td colspan="6" class="muted">
|
||||
{{ page() ? 'Nadie en la lista con estos filtros.' : 'Cargando…' }}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="pager">
|
||||
<span class="muted">
|
||||
@if (page()?.total; as total) {
|
||||
{{ offset() + 1 }}–{{ offset() + rows().length }} de {{ total }} pacientes · corte
|
||||
{{ applied() }}
|
||||
}
|
||||
</span>
|
||||
<button mat-stroked-button (click)="go('previous')" [disabled]="!has('previous') || loading()">
|
||||
Anterior
|
||||
</button>
|
||||
<button mat-stroked-button (click)="go('next')" [disabled]="!has('next') || loading()">
|
||||
Siguiente
|
||||
</button>
|
||||
</div>
|
||||
@@ -0,0 +1,93 @@
|
||||
import { Component, computed, inject, input, resource, signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import type { Bundle } from 'fhir/r4';
|
||||
import { Fhir } from '../fhir';
|
||||
import { camaRows } from './follow-up';
|
||||
import { name, PRIORITY } from './measures';
|
||||
|
||||
const STATUSES = ['cancer', 'pending_biopsy', 'biopsy_no_result', 'benign_biopsy'];
|
||||
|
||||
/** CaMa's follow-up list at a cut-off: patients whose latest mammogram in the window is
|
||||
* BI-RADS 4 to 6, where their biopsy stands and how soon they should be seen. */
|
||||
@Component({
|
||||
selector: 'app-tab-seguimiento',
|
||||
imports: [
|
||||
FormsModule,
|
||||
MatButtonModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatSelectModule,
|
||||
RouterLink,
|
||||
],
|
||||
templateUrl: './tab-seguimiento.html',
|
||||
styleUrl: './tab-riesgos.scss',
|
||||
})
|
||||
export class TabSeguimiento {
|
||||
private readonly fhir = inject(Fhir);
|
||||
readonly domain = input.required<string>();
|
||||
|
||||
protected readonly cutoff = signal<string>('');
|
||||
protected readonly window = signal(3);
|
||||
protected readonly status = signal<string>('');
|
||||
protected readonly size = signal(20);
|
||||
private readonly moved = signal<Bundle | undefined>(undefined);
|
||||
|
||||
protected readonly statuses = STATUSES;
|
||||
protected readonly name = name;
|
||||
protected readonly priority = (code: string) => PRIORITY[code] ?? code;
|
||||
|
||||
private readonly first = resource({
|
||||
params: () => ({
|
||||
domain: this.domain(),
|
||||
'follow-up-window': this.window(),
|
||||
'follow-up-cutoff': this.cutoff() || undefined,
|
||||
'follow-up-status': this.status() || undefined,
|
||||
_count: this.size(),
|
||||
}),
|
||||
loader: ({ params: { domain, ...params } }) => {
|
||||
this.moved.set(undefined);
|
||||
return this.fhir.search(domain, 'Patient', {
|
||||
...params,
|
||||
_revinclude: ['DiagnosticReport:subject'],
|
||||
'_include:iterate': 'DiagnosticReport:result',
|
||||
});
|
||||
},
|
||||
});
|
||||
protected readonly loading = signal(false);
|
||||
protected readonly page = computed(() => this.moved() ?? this.first.value());
|
||||
protected readonly applied = computed(() => {
|
||||
const self = this.page()?.link?.find((l) => l.relation === 'self')?.url;
|
||||
return self ? (new URL(self).searchParams.get('follow-up-cutoff') ?? '') : '';
|
||||
});
|
||||
protected readonly offset = computed(() => {
|
||||
const self = this.page()?.link?.find((l) => l.relation === 'self')?.url;
|
||||
return self ? Number(new URL(self).searchParams.get('_offset') ?? 0) : 0;
|
||||
});
|
||||
protected readonly rows = computed(() => {
|
||||
const page = this.page();
|
||||
const cutoff = this.applied();
|
||||
return page && cutoff ? camaRows(page, cutoff) : [];
|
||||
});
|
||||
protected readonly error = computed(() => this.first.error());
|
||||
|
||||
protected has(relation: 'next' | 'previous'): boolean {
|
||||
return !!this.page()?.link?.some((l) => l.relation === relation);
|
||||
}
|
||||
|
||||
protected async go(relation: 'next' | 'previous'): Promise<void> {
|
||||
const page = this.page();
|
||||
const next = page && this.fhir.follow(this.domain(), page, relation);
|
||||
if (!next) return;
|
||||
this.loading.set(true);
|
||||
try {
|
||||
this.moved.set(await next);
|
||||
} finally {
|
||||
this.loading.set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user