One shell with the current look: indicators, follow-up list and patient view from FHIR; /conectar canvas; /revision; Playwright page tests
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import type { RiskAssessment } from 'fhir/r4';
|
||||
import { ageGroup, currentRisk, windowStart } from './follow-up';
|
||||
import { periods } from './measures';
|
||||
|
||||
describe('follow-up list', () => {
|
||||
it('starts the window the day after the same day months before (core.follow_up)', () => {
|
||||
expect(windowStart('2026-11-22', 3)).toBe('2026-08-23');
|
||||
expect(windowStart('2026-05-31', 3)).toBe('2026-03-01'); // 2026-02-28, plus one
|
||||
expect(windowStart('2026-01-15', 1)).toBe('2025-12-16');
|
||||
});
|
||||
|
||||
it('groups ages at the cut-off, open at both ends', () => {
|
||||
expect(ageGroup('1980-11-23', '2026-11-22')).toBe('45-54');
|
||||
expect(ageGroup('2002-01-01', '2026-11-22')).toBe('<25');
|
||||
expect(ageGroup('1950-01-01', '2026-11-22')).toBe('65+');
|
||||
expect(ageGroup(undefined, '2026-11-22')).toBe('Sin dato');
|
||||
});
|
||||
|
||||
it('takes the latest index date, the highest risk there', () => {
|
||||
const risk = (model: string, at: string, p: number): RiskAssessment => ({
|
||||
resourceType: 'RiskAssessment',
|
||||
status: 'final',
|
||||
subject: {},
|
||||
occurrenceDateTime: at,
|
||||
method: { coding: [{ code: model }] },
|
||||
prediction: [{ probabilityDecimal: p, whenRange: { high: { value: 5 } } }],
|
||||
});
|
||||
const risks = [
|
||||
risk('cacu.cin2_pim', '2025-01-01', 0.9),
|
||||
risk('cacu.cin2_logistic', '2026-01-01', 0.2),
|
||||
risk('cacu.cin2_pim_post_colposcopy', '2026-01-01', 0.3),
|
||||
risk('cacu.cancer_pim', '2026-01-01', 0.05),
|
||||
];
|
||||
expect(currentRisk(risks, 'cin2', 5)).toBe(0.3);
|
||||
expect(currentRisk(risks, 'cancer', 5)).toBe(0.05);
|
||||
expect(currentRisk(risks, 'cin2', 3)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('lists periods most recent first', () => {
|
||||
expect(periods('semester', 1, new Date(2026, 10, 25))).toEqual(['2026-S2', '2026-S1']);
|
||||
expect(periods('month', 1, new Date(2026, 1, 3)).slice(0, 3)).toEqual([
|
||||
'2026-02',
|
||||
'2026-01',
|
||||
'2025-12',
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,128 @@
|
||||
import type { Bundle, DiagnosticReport, Observation, Patient, RiskAssessment } from 'fhir/r4';
|
||||
import { code, ext, resources } from '../fhir';
|
||||
|
||||
/** One row of the follow-up list: what the list shows of a patient at the cut-off. */
|
||||
export interface Row {
|
||||
patient: Patient;
|
||||
status: string;
|
||||
ageGroup: string;
|
||||
cytology?: { date: string; result?: string; adequacy?: string };
|
||||
hpv?: { date: string; positive: boolean; types1618?: boolean };
|
||||
daysToDiagnosis?: number;
|
||||
biopsy?: { date: string; histology?: string };
|
||||
risk: Record<'cin2' | 'cancer', number | undefined>;
|
||||
}
|
||||
|
||||
const AGE_GROUPS: [number, number][] = [
|
||||
[25, 34],
|
||||
[35, 44],
|
||||
[45, 54],
|
||||
[55, 64],
|
||||
];
|
||||
|
||||
export function ageGroup(birth: string | undefined, at: string): 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);
|
||||
if (found) return `${found[0]}-${found[1]}`;
|
||||
return age < AGE_GROUPS[0][0] ? `<${AGE_GROUPS[0][0]}` : `${AGE_GROUPS.at(-1)![1] + 1}+`;
|
||||
}
|
||||
|
||||
/** Her current risk of an outcome at a horizon: from the latest index date any of the
|
||||
* outcome's models scored her at, the highest when several did (as the list is sorted). */
|
||||
export function currentRisk(
|
||||
risks: RiskAssessment[],
|
||||
outcome: 'cin2' | 'cancer',
|
||||
horizon: number,
|
||||
): number | undefined {
|
||||
const mine = risks
|
||||
.filter((r) => code(r.method)?.startsWith(`cacu.${outcome}`))
|
||||
.flatMap((r) =>
|
||||
(r.prediction ?? [])
|
||||
.filter((p) => p.whenRange?.high?.value === horizon)
|
||||
.map((p) => ({ r, p })),
|
||||
);
|
||||
if (!mine.length) return undefined;
|
||||
const latest = mine
|
||||
.map((x) => x.r.occurrenceDateTime ?? '')
|
||||
.sort()
|
||||
.at(-1);
|
||||
return Math.max(
|
||||
...mine
|
||||
.filter((x) => x.r.occurrenceDateTime === latest)
|
||||
.map((x) => x.p.probabilityDecimal ?? 0),
|
||||
);
|
||||
}
|
||||
|
||||
/** The list's rows from one page: per patient, her latest cytology and HPV sampled in the
|
||||
* window, her days to diagnosis, and her latest reported biopsy. */
|
||||
export function rows(page: Bundle, start: string, cutoff: string, horizon: number): Row[] {
|
||||
const reports = resources<DiagnosticReport>(page, 'DiagnosticReport');
|
||||
const observations = new Map(resources<Observation>(page, 'Observation').map((o) => [o.id, o]));
|
||||
const risks = resources<RiskAssessment>(page, 'RiskAssessment');
|
||||
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!]),
|
||||
);
|
||||
return resources<Patient>(page, 'Patient', 'match').map((patient) => {
|
||||
const mine = reports.filter((r) => r.subject?.reference === `Patient/${patient.id}`);
|
||||
const by = (kind: string) => mine.filter((r) => code(r.code) === kind);
|
||||
const cytologies = by('cervical-cytology')
|
||||
.filter((r) => start <= r.effectiveDateTime! && r.effectiveDateTime! <= cutoff)
|
||||
.sort((a, b) => a.effectiveDateTime!.localeCompare(b.effectiveDateTime!));
|
||||
const last = cytologies.at(-1);
|
||||
const lastResults = last ? results(last) : new Map();
|
||||
const hpv = cytologies.filter((r) => results(r).has('hpv')).at(-1);
|
||||
const hpvResults = hpv ? results(hpv) : new Map();
|
||||
const types = ['hpv-16', 'hpv-18']
|
||||
.filter((k) => hpvResults.has(k))
|
||||
.map((k) => hpvResults.get(k)!.valueBoolean);
|
||||
const biopsy = by('cervical-biopsy')
|
||||
.filter((r) => ext(r, 'report-date'))
|
||||
.sort((a, b) =>
|
||||
ext(a, 'report-date')!.valueDate!.localeCompare(ext(b, 'report-date')!.valueDate!),
|
||||
)
|
||||
.at(-1);
|
||||
const theirs = risks.filter((r) => r.subject?.reference === `Patient/${patient.id}`);
|
||||
return {
|
||||
patient,
|
||||
status: ext(patient, 'follow-up-status')?.valueCoding?.code ?? '',
|
||||
ageGroup: ageGroup(patient.birthDate, cutoff),
|
||||
cytology: last && {
|
||||
date: last.effectiveDateTime!,
|
||||
result: code(lastResults.get('cytology-result')?.valueCodeableConcept),
|
||||
adequacy: code(lastResults.get('cytology-adequacy')?.valueCodeableConcept),
|
||||
},
|
||||
hpv: hpv && {
|
||||
date: hpv.effectiveDateTime!,
|
||||
positive: !!hpvResults.get('hpv')?.valueBoolean,
|
||||
types1618: types.length ? types.some((t) => t) : undefined,
|
||||
},
|
||||
daysToDiagnosis: last ? ext(last, 'days-to-diagnosis')?.valueInteger : undefined,
|
||||
biopsy: biopsy && {
|
||||
date: ext(biopsy, 'report-date')!.valueDate!,
|
||||
histology: code(biopsy.conclusionCode?.[0]),
|
||||
},
|
||||
risk: {
|
||||
cin2: currentRisk(theirs, 'cin2', horizon),
|
||||
cancer: currentRisk(theirs, 'cancer', horizon),
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** The window's first day: `months` before the cut-off (the month's last day when shorter), plus one. */
|
||||
export function windowStart(cutoff: string, months: number): string {
|
||||
const [y, m, d] = cutoff.split('-').map(Number);
|
||||
const total = y * 12 + (m - 1) - months;
|
||||
const year = Math.floor(total / 12);
|
||||
const month = total % 12;
|
||||
const last = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
|
||||
const day = new Date(Date.UTC(year, month, Math.min(d, last) + 1));
|
||||
return day.toISOString().slice(0, 10);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import { Component, computed, inject, input, resource } from '@angular/core';
|
||||
import { MatTabsModule } from '@angular/material/tabs';
|
||||
import type { Measure } from 'fhir/r4';
|
||||
import { DOMAINS } from '../app';
|
||||
import { Fhir, resources } from '../fhir';
|
||||
import { TabDefiniciones } from './tab-definiciones';
|
||||
import { TabIndicadores } from './tab-indicadores';
|
||||
import { TabRiesgos } from './tab-riesgos';
|
||||
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],
|
||||
template: `
|
||||
<section class="page">
|
||||
<h1>{{ title() }}</h1>
|
||||
<p class="subtitle">
|
||||
Indicadores de calidad y oportunidad del tamizaje, a partir de los datos cargados.
|
||||
</p>
|
||||
@if (measures.isLoading()) {
|
||||
<p class="muted">Cargando indicadores…</p>
|
||||
} @else if (measures.error()) {
|
||||
<p class="muted" role="alert">No se pudieron leer los indicadores.</p>
|
||||
} @else if (!measures.value()?.length) {
|
||||
<p class="muted empty">Este dominio todavía no tiene indicadores publicados.</p>
|
||||
} @else {
|
||||
<mat-tab-group mat-stretch-tabs="false" mat-align-tabs="center" animationDuration="0ms">
|
||||
<mat-tab label="Indicadores">
|
||||
<app-tab-indicadores [domain]="domain()" [measures]="measures.value()!" />
|
||||
</mat-tab>
|
||||
<mat-tab label="Trazabilidad">
|
||||
<ng-template matTabContent>
|
||||
<app-tab-trazabilidad [domain]="domain()" [measures]="measures.value()!" />
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
@if (patients()) {
|
||||
<mat-tab label="Análisis de riesgos">
|
||||
<ng-template matTabContent>
|
||||
<app-tab-riesgos [domain]="domain()" />
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
}
|
||||
<mat-tab label="Datos y definiciones">
|
||||
<ng-template matTabContent>
|
||||
<app-tab-definiciones [measures]="measures.value()!" />
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
</mat-tab-group>
|
||||
}
|
||||
</section>
|
||||
`,
|
||||
styles: `
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
.subtitle {
|
||||
text-align: center;
|
||||
}
|
||||
.empty {
|
||||
padding: 48px 0;
|
||||
text-align: center;
|
||||
}
|
||||
::ng-deep .mdc-tab-indicator__content--underline {
|
||||
border-color: var(--color-primary) !important;
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class Indicadores {
|
||||
private readonly fhir = inject(Fhir);
|
||||
readonly domain = input.required<string>();
|
||||
protected readonly title = computed(
|
||||
() => DOMAINS[this.domain() as keyof typeof DOMAINS] ?? this.domain(),
|
||||
);
|
||||
protected readonly measures = resource({
|
||||
params: () => this.domain(),
|
||||
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');
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/** Where each measure goes on a domain's indicator page (today's layout); measures not
|
||||
* named here are clinical cards. Measures are named by their code (`Measure.name`). */
|
||||
export interface Layout {
|
||||
kpis: string[];
|
||||
route: { label: string; fromSample: string; fromStep: string; step: string }[];
|
||||
/** The measure whose data decides the default period. */
|
||||
anchor: string;
|
||||
}
|
||||
|
||||
export const LAYOUTS: Record<string, Layout> = {
|
||||
cacu: {
|
||||
kpis: [
|
||||
'CACU_EU7',
|
||||
'CACU_EU_TIEMPO_REPORTE',
|
||||
'CACU_DIAS_TOMA_DIAGNOSTICO',
|
||||
'CACU_DIAS_TOMA_TRATAMIENTO',
|
||||
'CACU_DIAS_DIAGNOSTICO_TRATAMIENTO',
|
||||
],
|
||||
route: [
|
||||
{
|
||||
label: 'Resultado de citología',
|
||||
step: 'Toma a resultado de citología',
|
||||
fromSample: 'CACU_EU_TIEMPO_REPORTE',
|
||||
fromStep: 'CACU_EU_TIEMPO_REPORTE',
|
||||
},
|
||||
{
|
||||
label: 'Colposcopía',
|
||||
step: 'Del resultado de citología a la colposcopía',
|
||||
fromSample: 'CACU_DIAS_TOMA_COLPOSCOPIA',
|
||||
fromStep: 'CACU_DIAS_RESULTADO_COLPOSCOPIA',
|
||||
},
|
||||
{
|
||||
label: 'Resultado de biopsia',
|
||||
step: 'De la colposcopía al resultado de biopsia',
|
||||
fromSample: 'CACU_DIAS_TOMA_BIOPSIA',
|
||||
fromStep: 'CACU_DIAS_COLPOSCOPIA_BIOPSIA',
|
||||
},
|
||||
{
|
||||
label: 'Diagnóstico',
|
||||
step: 'Del resultado de biopsia al diagnóstico',
|
||||
fromSample: 'CACU_DIAS_TOMA_DIAGNOSTICO',
|
||||
fromStep: 'CACU_DIAS_BIOPSIA_DIAGNOSTICO',
|
||||
},
|
||||
],
|
||||
anchor: 'IND1',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,280 @@
|
||||
import type { Measure, MeasureReport, MeasureReportGroup } from 'fhir/r4';
|
||||
import { code, ext } from '../fhir';
|
||||
import { Figure, PALETTE } from '../plot';
|
||||
|
||||
export type PeriodType = 'semester' | 'month';
|
||||
export type Scoring = 'proportion' | 'continuous-variable' | 'cohort';
|
||||
|
||||
/** The periods back from today, most recent first: semesters (`2025-S1`) or months. */
|
||||
export function periods(type: PeriodType, years = 6, today = new Date()): string[] {
|
||||
const found: string[] = [];
|
||||
const year = today.getFullYear();
|
||||
if (type === 'semester') {
|
||||
for (let y = year; y > year - years; y--) {
|
||||
if (y < year || today.getMonth() >= 6) found.push(`${y}-S2`);
|
||||
found.push(`${y}-S1`);
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < years * 12; i++) {
|
||||
const d = new Date(year, today.getMonth() - i, 1);
|
||||
found.push(`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`);
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
export function periodLabel(period: string): string {
|
||||
const [year, part] = period.split('-');
|
||||
if (part.startsWith('S')) return `${part === 'S1' ? 'Ene–Jun' : 'Jul–Dic'} ${year}`;
|
||||
const month = new Date(Number(year), Number(part) - 1, 1).toLocaleString('es-MX', {
|
||||
month: 'short',
|
||||
});
|
||||
return `${month} ${year}`;
|
||||
}
|
||||
|
||||
export function scoring(measure: Measure): Scoring {
|
||||
return code(measure.scoring) as Scoring;
|
||||
}
|
||||
|
||||
export function periodTypes(measure: Measure): PeriodType[] {
|
||||
return (measure.extension ?? [])
|
||||
.filter((e) => e.url.endsWith('/period-type'))
|
||||
.map((e) => e.valueCode as PeriodType);
|
||||
}
|
||||
|
||||
/** What one report says: its counts, its score and interval, and its strata. */
|
||||
export interface Reading {
|
||||
populations: Record<string, number>;
|
||||
score?: number;
|
||||
low?: number;
|
||||
high?: number;
|
||||
unit?: string;
|
||||
strata: Record<string, Record<string, Record<string, number>>>;
|
||||
}
|
||||
|
||||
function counts(group: {
|
||||
population?: { code?: { coding?: { code?: string }[] }; count?: number }[];
|
||||
}) {
|
||||
return Object.fromEntries(
|
||||
(group.population ?? []).map((p) => [p.code?.coding?.[0]?.code ?? '', p.count ?? 0]),
|
||||
);
|
||||
}
|
||||
|
||||
export function reading(report: MeasureReport | undefined): Reading | undefined {
|
||||
const group: MeasureReportGroup | undefined = report?.group?.[0];
|
||||
if (!group) return undefined;
|
||||
const score = group.measureScore;
|
||||
const strata: Reading['strata'] = {};
|
||||
for (const s of group.stratifier ?? []) {
|
||||
const name = code(s.code?.[0]) ?? s.code?.[0]?.text ?? '';
|
||||
strata[name] = Object.fromEntries(
|
||||
(s.stratum ?? []).map((x) => [x.value?.text ?? '', counts(x)]),
|
||||
);
|
||||
}
|
||||
return {
|
||||
populations: counts(group),
|
||||
score: score?.value,
|
||||
low: (ext(score, 'ic-bajo') ?? ext(score, 'q1'))?.valueDecimal,
|
||||
high: (ext(score, 'ic-alto') ?? ext(score, 'q3'))?.valueDecimal,
|
||||
unit: score?.unit,
|
||||
strata,
|
||||
};
|
||||
}
|
||||
|
||||
/** Codes as the screens name them. */
|
||||
const LABELS: Record<string, string> = {
|
||||
NILM: 'Normal (NILM)',
|
||||
LSIL: 'LIEBG',
|
||||
HSIL: 'LIEAG',
|
||||
normal: 'Normal',
|
||||
carcinoma: 'Carcinoma',
|
||||
no_data: 'Sin dato',
|
||||
no_biopsy: 'Sin biopsia',
|
||||
pre_colposcopy: 'Pre colposcopia',
|
||||
post_colposcopy: 'Post colposcopia',
|
||||
post_treatment: 'Post tratamiento',
|
||||
case: 'Caso (cáncer)',
|
||||
low: 'Bajo',
|
||||
intermediate: 'Intermedio',
|
||||
high: 'Alto',
|
||||
satisfactory: 'satisfactoria',
|
||||
unsatisfactory: 'insatisfactoria',
|
||||
};
|
||||
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',
|
||||
};
|
||||
export const name = (value: string) => LABELS[value] ?? value;
|
||||
|
||||
export function formatScore(measure: Measure, r: Reading | undefined): string {
|
||||
if (!r || r.score === undefined) return 'Sin dato';
|
||||
switch (scoring(measure)) {
|
||||
case 'proportion':
|
||||
return `${(r.score * 100).toFixed(1)} %`;
|
||||
case 'continuous-variable':
|
||||
return `${Math.round(r.score * 10) / 10} días`;
|
||||
default:
|
||||
return `${r.score}`;
|
||||
}
|
||||
}
|
||||
|
||||
export function detail(measure: Measure, r: Reading | undefined): string {
|
||||
if (!r) return '';
|
||||
const p = r.populations;
|
||||
switch (scoring(measure)) {
|
||||
case 'proportion':
|
||||
return r.score === undefined
|
||||
? 'Sin pacientes en el periodo.'
|
||||
: `${p['numerator']} de ${p['denominator']} pacientes. IC 95 %: ${pct(r.low)}–${pct(r.high)}.`;
|
||||
case 'continuous-variable':
|
||||
return r.score === undefined
|
||||
? `${p['initial-population'] ?? 0} sin medición en el periodo.`
|
||||
: `Mediana de ${p['measure-observation']} mediciones; cuartiles ${r.low}–${r.high} días.`;
|
||||
default:
|
||||
return `${p['initial-population'] ?? 0} pacientes.`;
|
||||
}
|
||||
}
|
||||
|
||||
const pct = (v?: number) => (v === undefined ? '—' : `${(v * 100).toFixed(1)} %`);
|
||||
|
||||
/** A donut of one stratifier's counts (initial population), or of numerator vs the rest. */
|
||||
export function donut(measure: Measure, r: Reading, stratifier = 'category'): Figure {
|
||||
let labels: string[], values: number[];
|
||||
if (scoring(measure) === 'proportion') {
|
||||
const { numerator = 0, denominator = 0 } = r.populations;
|
||||
labels = ['Numerador', 'Resto'];
|
||||
values = [numerator, denominator - numerator];
|
||||
} else {
|
||||
const cells = Object.entries(r.strata[stratifier] ?? {});
|
||||
labels = cells.map(([v]) => name(v));
|
||||
values = cells.map(([, c]) => c['initial-population'] ?? 0);
|
||||
}
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'pie',
|
||||
hole: 0.62,
|
||||
labels,
|
||||
values,
|
||||
sort: false,
|
||||
textinfo: 'value+percent',
|
||||
marker: { colors: PALETTE },
|
||||
},
|
||||
],
|
||||
layout: { showlegend: true, margin: { t: 32, r: 8, b: 32, l: 8 } },
|
||||
};
|
||||
}
|
||||
|
||||
/** Bars per stratum: the rate (proportion) or the count (others). */
|
||||
export function strataBars(measure: Measure, r: Reading, stratifier: string): Figure {
|
||||
const cells = Object.entries(r.strata[stratifier] ?? {});
|
||||
const proportion = scoring(measure) === 'proportion';
|
||||
const values = cells.map(([, c]) =>
|
||||
proportion
|
||||
? c['denominator']
|
||||
? (100 * (c['numerator'] ?? 0)) / c['denominator']
|
||||
: 0
|
||||
: (c['initial-population'] ?? 0),
|
||||
);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'bar',
|
||||
orientation: 'h',
|
||||
y: cells.map(([v]) => name(v)),
|
||||
x: values,
|
||||
marker: { color: PALETTE[0] },
|
||||
},
|
||||
],
|
||||
layout: {
|
||||
xaxis: { title: { text: proportion ? '%' : 'Pacientes' } },
|
||||
yaxis: { automargin: true },
|
||||
margin: { t: 8, r: 16, b: 48, l: 8 },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** Horizontal median bars with their interquartile range, one per measure. */
|
||||
export function medians(rows: { label: string; r: Reading | undefined }[]): Figure {
|
||||
const shown = rows.filter((x) => x.r?.score !== undefined);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'bar',
|
||||
orientation: 'h',
|
||||
y: shown.map((x) => x.label),
|
||||
x: shown.map((x) => x.r!.score!),
|
||||
error_x: {
|
||||
type: 'data',
|
||||
symmetric: false,
|
||||
array: shown.map((x) => (x.r!.high ?? x.r!.score!) - x.r!.score!),
|
||||
arrayminus: shown.map((x) => x.r!.score! - (x.r!.low ?? x.r!.score!)),
|
||||
color: '#17324d',
|
||||
},
|
||||
marker: { color: PALETTE[0] },
|
||||
hovertemplate: '%{y}: %{x} días<extra></extra>',
|
||||
},
|
||||
],
|
||||
layout: {
|
||||
xaxis: { title: { text: 'Días (mediana, Q1–Q3)' } },
|
||||
yaxis: { automargin: true, autorange: 'reversed' },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** A measure over time: % with its interval, median with its quartiles, or counts by category. */
|
||||
export function history(
|
||||
measure: Measure,
|
||||
series: { period: string; r: Reading | undefined }[],
|
||||
): Figure {
|
||||
const x = series.map((s) => periodLabel(s.period));
|
||||
const kind = scoring(measure);
|
||||
if (kind === 'cohort') {
|
||||
const categories = [
|
||||
...new Set(series.flatMap((s) => Object.keys(s.r?.strata['category'] ?? {}))),
|
||||
];
|
||||
return {
|
||||
data: categories.map((c, i) => ({
|
||||
type: 'bar',
|
||||
name: name(c),
|
||||
x,
|
||||
y: series.map((s) => s.r?.strata['category']?.[c]?.['initial-population'] ?? 0),
|
||||
marker: { color: PALETTE[i % PALETTE.length] },
|
||||
})),
|
||||
layout: { barmode: 'stack', yaxis: { title: { text: 'Pacientes' } } },
|
||||
};
|
||||
}
|
||||
const k = kind === 'proportion' ? 100 : 1;
|
||||
const value = (v?: number) => (v === undefined ? null : v * k);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
x,
|
||||
y: series.map((s) => value(s.r?.high)),
|
||||
mode: 'lines',
|
||||
line: { width: 0 },
|
||||
showlegend: false,
|
||||
hoverinfo: 'skip',
|
||||
},
|
||||
{
|
||||
x,
|
||||
y: series.map((s) => value(s.r?.low)),
|
||||
mode: 'lines',
|
||||
line: { width: 0 },
|
||||
fill: 'tonexty',
|
||||
fillcolor: 'rgba(168,194,67,0.25)',
|
||||
name: kind === 'proportion' ? 'IC 95 %' : 'Q1–Q3',
|
||||
},
|
||||
{
|
||||
x,
|
||||
y: series.map((s) => value(s.r?.score)),
|
||||
mode: 'lines+markers',
|
||||
name: kind === 'proportion' ? '%' : 'Mediana',
|
||||
line: { color: PALETTE[0] },
|
||||
},
|
||||
],
|
||||
layout: { yaxis: { title: { text: kind === 'proportion' ? '%' : 'Días' } } },
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { Component, input } from '@angular/core';
|
||||
import type { Measure } from 'fhir/r4';
|
||||
import { code, label } from '../fhir';
|
||||
import { periodTypes, STRATA } from './measures';
|
||||
|
||||
const SCORING: Record<string, string> = {
|
||||
proportion: 'Proporción',
|
||||
'continuous-variable': 'Variable continua (mediana)',
|
||||
cohort: 'Composición (conteo)',
|
||||
};
|
||||
const IMPROVEMENT: Record<string, string> = {
|
||||
increase: 'Mejor si sube',
|
||||
decrease: 'Mejor si baja',
|
||||
};
|
||||
const PERIODS: Record<string, string> = { semester: 'Semestral', month: 'Mensual' };
|
||||
|
||||
/** What each measure is: how it scores, which way is better, its periods and strata. */
|
||||
@Component({
|
||||
selector: 'app-tab-definiciones',
|
||||
template: `
|
||||
<table class="plain card">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Indicador</th>
|
||||
<th>Clave</th>
|
||||
<th>Cálculo</th>
|
||||
<th>Mejora</th>
|
||||
<th>Periodos</th>
|
||||
<th>Estratos</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (m of measures(); track m.id) {
|
||||
<tr>
|
||||
<td>{{ m.title }}</td>
|
||||
<td>
|
||||
<code>{{ m.name }}</code> v{{ m.version }}
|
||||
</td>
|
||||
<td>{{ scoring[code(m.scoring) ?? ''] }}</td>
|
||||
<td>{{ improvement[code(m.improvementNotation) ?? ''] ?? '—' }}</td>
|
||||
<td>{{ types(m) }}</td>
|
||||
<td>{{ strata(m) }}</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
`,
|
||||
styles: ':host { display: block; padding-top: 16px; overflow-x: auto; }',
|
||||
})
|
||||
export class TabDefiniciones {
|
||||
readonly measures = input.required<Measure[]>();
|
||||
protected readonly scoring = SCORING;
|
||||
protected readonly improvement = IMPROVEMENT;
|
||||
protected readonly code = code;
|
||||
protected types(m: Measure): string {
|
||||
return periodTypes(m)
|
||||
.map((p) => PERIODS[p] ?? p)
|
||||
.join(', ');
|
||||
}
|
||||
protected strata(m: Measure): string {
|
||||
const names = (m.group?.[0]?.stratifier ?? []).map((s) => code(s.code) ?? label(s.code));
|
||||
return names.map((n) => STRATA[n] ?? n).join(', ') || '—';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<div class="filters card">
|
||||
<div class="field">
|
||||
<span class="label">Intervalo de análisis</span>
|
||||
<mat-button-toggle-group
|
||||
[value]="type()"
|
||||
(change)="setType($event.value)"
|
||||
aria-label="Intervalo de análisis"
|
||||
>
|
||||
<mat-button-toggle value="month">Mensual</mat-button-toggle>
|
||||
<mat-button-toggle value="semester">Semestral</mat-button-toggle>
|
||||
</mat-button-toggle-group>
|
||||
</div>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Periodo seleccionado</mat-label>
|
||||
<mat-select [value]="chosen()" (selectionChange)="chosen.set($event.value)">
|
||||
@for (p of options(); track p) {
|
||||
<mat-option [value]="p">{{ label(p) }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<button
|
||||
mat-flat-button
|
||||
(click)="applied.set(chosen())"
|
||||
[disabled]="!chosen() || chosen() === applied()"
|
||||
>
|
||||
Aplicar
|
||||
</button>
|
||||
@if (applied(); as p) {
|
||||
<span class="muted applied">Mostrando {{ label(p) }}</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (reports.isLoading()) {
|
||||
<p class="muted">Calculando…</p>
|
||||
}
|
||||
|
||||
@if (kpis().length) {
|
||||
<h2>Indicadores de oportunidad</h2>
|
||||
<div class="kpis">
|
||||
@for (m of kpis(); track m.id) {
|
||||
<mat-card appearance="outlined" class="kpi" [attr.data-measure]="m.name">
|
||||
<mat-card-content>
|
||||
<div class="kpi-title">{{ m.title }}</div>
|
||||
<div class="kpi-value">{{ score(m) }}</div>
|
||||
<div class="kpi-detail muted">{{ detail(m) }}</div>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (layout().route.length) {
|
||||
<mat-card appearance="outlined" class="route">
|
||||
<mat-card-header>
|
||||
<mat-card-title>Ruta del tamizaje</mat-card-title>
|
||||
<mat-button-toggle-group
|
||||
[value]="routeView()"
|
||||
(change)="routeView.set($event.value)"
|
||||
class="route-toggle"
|
||||
>
|
||||
<mat-button-toggle value="sample">Acumulado desde la toma</mat-button-toggle>
|
||||
<mat-button-toggle value="step">Por pasos</mat-button-toggle>
|
||||
</mat-button-toggle-group>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<app-plot [figure]="route()" [height]="260" />
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
|
||||
<h2>Indicadores clínicos</h2>
|
||||
<div class="clinical">
|
||||
@for (m of clinical(); track m.id) {
|
||||
<mat-card appearance="outlined" class="clinical-card" [attr.data-measure]="m.name">
|
||||
<mat-card-header>
|
||||
<mat-card-title>{{ m.title }}</mat-card-title>
|
||||
<mat-card-subtitle>{{ score(m) }} · {{ detail(m) }}</mat-card-subtitle>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
@for (f of figureSets().get(m.name!) ?? []; track f.title) {
|
||||
<h3 class="figure-title">{{ f.title }}</h3>
|
||||
<app-plot [figure]="f.figure" [height]="260" />
|
||||
} @empty {
|
||||
<p class="muted">Sin datos en el periodo.</p>
|
||||
}
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,99 @@
|
||||
:host {
|
||||
display: block;
|
||||
padding-top: var(--space-4);
|
||||
}
|
||||
|
||||
.filters {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-4);
|
||||
margin-bottom: var(--space-4);
|
||||
}
|
||||
|
||||
.field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
.label {
|
||||
color: var(--color-text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.15rem;
|
||||
font-weight: 500;
|
||||
margin: var(--space-6) 0 var(--space-3);
|
||||
}
|
||||
|
||||
.kpis {
|
||||
display: grid;
|
||||
gap: var(--space-3);
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
@media (min-width: 600px) {
|
||||
.kpis {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1000px) {
|
||||
.kpis {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1350px) {
|
||||
.kpis {
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
.kpi-title {
|
||||
font-weight: 500;
|
||||
min-height: 2.6em;
|
||||
}
|
||||
|
||||
.kpi-value {
|
||||
font-size: 2rem;
|
||||
font-weight: 500;
|
||||
margin: var(--space-2) 0;
|
||||
}
|
||||
|
||||
.kpi-detail {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.route {
|
||||
margin-top: var(--space-4);
|
||||
}
|
||||
|
||||
.route mat-card-header {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-3);
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.clinical {
|
||||
display: grid;
|
||||
gap: var(--space-4);
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
@media (min-width: 1304px) {
|
||||
.clinical {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
.figure-title {
|
||||
color: var(--color-text-secondary);
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
margin: var(--space-3) 0 0;
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
import { Component, computed, effect, inject, input, resource, signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import type { Measure, MeasureReport } from 'fhir/r4';
|
||||
import { Fhir, resources } from '../fhir';
|
||||
import { Figure, Plot } from '../plot';
|
||||
import { LAYOUTS } from './layout';
|
||||
import {
|
||||
detail,
|
||||
donut,
|
||||
formatScore,
|
||||
medians,
|
||||
name,
|
||||
periodLabel,
|
||||
periods,
|
||||
PeriodType,
|
||||
reading,
|
||||
Reading,
|
||||
scoring,
|
||||
STRATA,
|
||||
strataBars,
|
||||
} from './measures';
|
||||
|
||||
/** The period's indicators: the timeliness KPIs, the screening route, and a card per
|
||||
* clinical measure with its figures. */
|
||||
@Component({
|
||||
selector: 'app-tab-indicadores',
|
||||
imports: [
|
||||
FormsModule,
|
||||
MatButtonModule,
|
||||
MatButtonToggleModule,
|
||||
MatCardModule,
|
||||
MatSelectModule,
|
||||
Plot,
|
||||
],
|
||||
templateUrl: './tab-indicadores.html',
|
||||
styleUrl: './tab-indicadores.scss',
|
||||
})
|
||||
export class TabIndicadores {
|
||||
private readonly fhir = inject(Fhir);
|
||||
readonly domain = input.required<string>();
|
||||
readonly measures = input.required<Measure[]>();
|
||||
|
||||
protected readonly type = signal<PeriodType>('semester');
|
||||
protected readonly options = computed(() => periods(this.type()));
|
||||
protected readonly chosen = signal<string | undefined>(undefined);
|
||||
/** The period the figures show (set by Aplicar). */
|
||||
protected readonly applied = signal<string | undefined>(undefined);
|
||||
protected readonly routeView = signal<'sample' | 'step'>('sample');
|
||||
|
||||
protected readonly layout = computed(
|
||||
() => LAYOUTS[this.domain()] ?? { kpis: [], route: [], anchor: '' },
|
||||
);
|
||||
private readonly byName = computed(() => new Map(this.measures().map((m) => [m.name!, m])));
|
||||
protected readonly kpis = computed(() =>
|
||||
this.layout()
|
||||
.kpis.map((n) => this.byName().get(n))
|
||||
.filter((m) => !!m),
|
||||
);
|
||||
protected readonly clinical = computed(() => {
|
||||
const placed = new Set([
|
||||
...this.layout().kpis,
|
||||
...this.layout().route.flatMap((s) => [s.fromSample, s.fromStep]),
|
||||
]);
|
||||
return this.measures().filter((m) => !placed.has(m.name!));
|
||||
});
|
||||
|
||||
/** The latest period with data, the default. */
|
||||
private readonly latest = resource({
|
||||
params: () => ({
|
||||
domain: this.domain(),
|
||||
anchor: this.byName().get(this.layout().anchor) ?? this.measures()[0],
|
||||
all: this.options(),
|
||||
}),
|
||||
loader: async ({ params }) => {
|
||||
const pages = await this.fhir.all(params.domain, 'MeasureReport', {
|
||||
measure: params.anchor.id!,
|
||||
'reporting-period': params.all.join(','),
|
||||
});
|
||||
const found = resources<MeasureReport>(pages, 'MeasureReport');
|
||||
const index = found.findIndex(
|
||||
(r) => (reading(r)?.populations['initial-population'] ?? 0) > 0,
|
||||
);
|
||||
return params.all[Math.max(index, 0)];
|
||||
},
|
||||
});
|
||||
|
||||
protected readonly reports = resource({
|
||||
params: () => ({ domain: this.domain(), period: this.applied(), measures: this.measures() }),
|
||||
loader: async ({ params }) => {
|
||||
if (!params.period) return new Map<string, Reading | undefined>();
|
||||
const found = await Promise.all(
|
||||
params.measures.map(async (m) => {
|
||||
const page = await this.fhir.search(params.domain, 'MeasureReport', {
|
||||
measure: m.id!,
|
||||
'reporting-period': params.period,
|
||||
});
|
||||
return [m.name!, reading(resources<MeasureReport>(page, 'MeasureReport')[0])] as const;
|
||||
}),
|
||||
);
|
||||
return new Map(found);
|
||||
},
|
||||
});
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const latest = this.latest.value();
|
||||
if (latest && !this.applied()) {
|
||||
this.chosen.set(latest);
|
||||
this.applied.set(latest);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected readonly label = periodLabel;
|
||||
protected readonly strataNames = STRATA;
|
||||
protected r(m: Measure): Reading | undefined {
|
||||
return this.reports.value()?.get(m.name!);
|
||||
}
|
||||
protected score(m: Measure): string {
|
||||
return formatScore(m, this.r(m));
|
||||
}
|
||||
protected detail(m: Measure): string {
|
||||
return detail(m, this.r(m));
|
||||
}
|
||||
|
||||
protected setType(type: PeriodType): void {
|
||||
this.type.set(type);
|
||||
this.chosen.set(this.options()[0]);
|
||||
}
|
||||
|
||||
protected readonly route = computed<Figure>(() => {
|
||||
const view = this.routeView();
|
||||
return medians(
|
||||
this.layout().route.map((s) => {
|
||||
const m = this.byName().get(view === 'sample' ? s.fromSample : s.fromStep);
|
||||
return { label: view === 'sample' ? s.label : s.step, r: m && this.r(m) };
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
/** Each clinical card's figures, built once per loaded period. */
|
||||
protected readonly figureSets = computed(
|
||||
() =>
|
||||
new Map(
|
||||
this.clinical().map((m) => [m.name!, this.build(m, this.reports.value()?.get(m.name!))]),
|
||||
),
|
||||
);
|
||||
|
||||
/** A clinical card's figures: the overall split, then one per stratum. */
|
||||
private build(m: Measure, r: Reading | undefined): { title: string; figure: Figure }[] {
|
||||
if (!r || !(r.populations['initial-population'] ?? 0)) return [];
|
||||
const strata = Object.keys(r.strata).filter(
|
||||
(s) => s !== 'category' && Object.keys(r.strata[s]).length,
|
||||
);
|
||||
const kind = scoring(m);
|
||||
if (kind === 'continuous-variable')
|
||||
return [{ title: 'Mediana y cuartiles', figure: medians([{ label: m.title!, r }]) }];
|
||||
return [
|
||||
{ title: kind === 'proportion' ? 'Numerador y resto' : 'Por categoría', figure: donut(m, r) },
|
||||
...strata.map((s) => ({
|
||||
title: `Por ${STRATA[s]?.toLowerCase() ?? s}`,
|
||||
figure: strataBars(m, r, s),
|
||||
})),
|
||||
];
|
||||
}
|
||||
protected readonly name = name;
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<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>Horizonte</mat-label>
|
||||
<mat-select [value]="horizon()" (selectionChange)="horizon.set($event.value)">
|
||||
@for (h of [1, 2, 3, 4, 5]; track h) {
|
||||
<mat-option [value]="h">{{ h }} {{ h === 1 ? 'año' : 'años' }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Orden</mat-label>
|
||||
<mat-select [value]="sort()" (selectionChange)="sort.set($event.value)">
|
||||
<mat-option value="-recent">Estudio más reciente</mat-option>
|
||||
<mat-option value="-risk-cin2">Mayor riesgo de LIEAG+</mat-option>
|
||||
<mat-option value="-risk-cancer">Mayor riesgo de cáncer</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>Estatus</th>
|
||||
<th>Última citología</th>
|
||||
<th>VPH</th>
|
||||
<th>Biopsia</th>
|
||||
<th>Riesgo LIEAG+ ({{ horizon() }} a)</th>
|
||||
<th>Riesgo cáncer ({{ horizon() }} a)</th>
|
||||
<th>Días toma → diagnóstico</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (row of rows(); track row.patient.id) {
|
||||
<tr>
|
||||
<td>
|
||||
<a [routerLink]="['/indicadores', domain(), 'pacientes', row.patient.id]" class="id">{{
|
||||
row.patient.id!.slice(0, 10)
|
||||
}}</a>
|
||||
</td>
|
||||
<td>{{ row.ageGroup }}</td>
|
||||
<td>{{ name(row.status) }}</td>
|
||||
<td>
|
||||
@if (row.cytology; as c) {
|
||||
{{ c.date }} ·
|
||||
{{
|
||||
c.result
|
||||
? name(c.result)
|
||||
: c.adequacy === 'unsatisfactory'
|
||||
? 'Insatisfactoria'
|
||||
: 'Pendiente'
|
||||
}}
|
||||
} @else {
|
||||
—
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@if (row.hpv; as h) {
|
||||
{{ h.positive ? 'Positivo' : 'Negativo' }}{{ h.types1618 ? ' (16/18)' : '' }}
|
||||
} @else {
|
||||
—
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@if (row.biopsy; as b) {
|
||||
{{ b.date }} · {{ name(b.histology ?? '') || 'Sin dato' }}
|
||||
} @else {
|
||||
—
|
||||
}
|
||||
</td>
|
||||
<td class="num">
|
||||
{{ row.risk.cin2 === undefined ? '—' : (row.risk.cin2 * 100 | number: '1.1-1') + ' %' }}
|
||||
</td>
|
||||
<td class="num">
|
||||
{{
|
||||
row.risk.cancer === undefined ? '—' : (row.risk.cancer * 100 | number: '1.1-1') + ' %'
|
||||
}}
|
||||
</td>
|
||||
<td class="num">{{ row.daysToDiagnosis ?? '—' }}</td>
|
||||
</tr>
|
||||
} @empty {
|
||||
<tr>
|
||||
<td colspan="9" 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,38 @@
|
||||
:host {
|
||||
display: block;
|
||||
padding-top: var(--space-4);
|
||||
}
|
||||
|
||||
.filters {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-3);
|
||||
margin-bottom: var(--space-4);
|
||||
}
|
||||
|
||||
.table-wrap {
|
||||
overflow-x: auto;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.worklist .num {
|
||||
text-align: right;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.id {
|
||||
color: var(--color-action);
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.pager {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: var(--space-3);
|
||||
justify-content: flex-end;
|
||||
margin-top: var(--space-3);
|
||||
}
|
||||
|
||||
.pager .muted {
|
||||
margin-right: auto;
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
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 { rows, windowStart } from './follow-up';
|
||||
import { name } from './measures';
|
||||
|
||||
const STATUSES = ['case', 'pre_colposcopy', 'post_colposcopy', 'post_treatment'];
|
||||
|
||||
/** CaCu's follow-up list at a cut-off: who had a cytology in the window, her status,
|
||||
* results and current risks, in the order asked for. */
|
||||
@Component({
|
||||
selector: 'app-tab-riesgos',
|
||||
imports: [
|
||||
DecimalPipe,
|
||||
FormsModule,
|
||||
MatButtonModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatSelectModule,
|
||||
RouterLink,
|
||||
],
|
||||
templateUrl: './tab-riesgos.html',
|
||||
styleUrl: './tab-riesgos.scss',
|
||||
})
|
||||
export class TabRiesgos {
|
||||
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 horizon = signal(5);
|
||||
protected readonly sort = signal('-recent');
|
||||
protected readonly size = signal(20);
|
||||
/** A page the user moved to (`next`/`previous`), else the first. */
|
||||
private readonly moved = signal<Bundle | undefined>(undefined);
|
||||
|
||||
protected readonly statuses = STATUSES;
|
||||
protected readonly name = name;
|
||||
|
||||
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,
|
||||
'risk-horizon': this.horizon(),
|
||||
_sort: this.sort(),
|
||||
_count: this.size(),
|
||||
}),
|
||||
loader: ({ params: { domain, ...params } }) => {
|
||||
this.moved.set(undefined);
|
||||
return this.fhir.search(domain, 'Patient', {
|
||||
...params,
|
||||
_revinclude: ['DiagnosticReport:subject', 'RiskAssessment:subject'],
|
||||
'_include:iterate': 'DiagnosticReport:result',
|
||||
});
|
||||
},
|
||||
});
|
||||
protected readonly loading = signal(false);
|
||||
protected readonly page = computed(() => this.moved() ?? this.first.value());
|
||||
/** The cut-off as applied (the server's default when none is given). */
|
||||
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
|
||||
? rows(page, windowStart(cutoff, this.window()), cutoff, this.horizon())
|
||||
: [];
|
||||
});
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import { Component, computed, inject, input, resource, signal } from '@angular/core';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import type { Measure, MeasureReport } from 'fhir/r4';
|
||||
import { Fhir, resources } from '../fhir';
|
||||
import { Figure, Plot } from '../plot';
|
||||
import { history, periods, PeriodType, periodTypes, reading } from './measures';
|
||||
|
||||
/** Each measure over time: every period of the chosen kind, oldest first. */
|
||||
@Component({
|
||||
selector: 'app-tab-trazabilidad',
|
||||
imports: [MatButtonToggleModule, MatCardModule, Plot],
|
||||
template: `
|
||||
<div class="bar">
|
||||
<mat-button-toggle-group
|
||||
[value]="type()"
|
||||
(change)="type.set($event.value)"
|
||||
aria-label="Intervalo"
|
||||
>
|
||||
<mat-button-toggle value="month">Mensual</mat-button-toggle>
|
||||
<mat-button-toggle value="semester">Semestral</mat-button-toggle>
|
||||
</mat-button-toggle-group>
|
||||
</div>
|
||||
@if (series.isLoading()) {
|
||||
<p class="muted">Calculando…</p>
|
||||
}
|
||||
<div class="grid">
|
||||
@for (item of figures(); track item.measure.id) {
|
||||
<mat-card appearance="outlined" [attr.data-measure]="item.measure.name">
|
||||
<mat-card-header
|
||||
><mat-card-title>{{ item.measure.title }}</mat-card-title></mat-card-header
|
||||
>
|
||||
<mat-card-content><app-plot [figure]="item.figure" [height]="280" /></mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
</div>
|
||||
`,
|
||||
styles: `
|
||||
:host {
|
||||
display: block;
|
||||
padding-top: 16px;
|
||||
}
|
||||
.bar {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.grid {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
@media (min-width: 1304px) {
|
||||
.grid {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class TabTrazabilidad {
|
||||
private readonly fhir = inject(Fhir);
|
||||
readonly domain = input.required<string>();
|
||||
readonly measures = input.required<Measure[]>();
|
||||
protected readonly type = signal<PeriodType>('semester');
|
||||
|
||||
protected readonly series = resource({
|
||||
params: () => ({ domain: this.domain(), type: this.type(), measures: this.measures() }),
|
||||
loader: async ({ params }) => {
|
||||
const asked = periods(params.type).reverse();
|
||||
const shown = params.measures.filter((m) => periodTypes(m).includes(params.type));
|
||||
return Promise.all(
|
||||
shown.map(async (measure) => {
|
||||
const pages = await this.fhir.all(params.domain, 'MeasureReport', {
|
||||
measure: measure.id!,
|
||||
'reporting-period': asked.join(','),
|
||||
});
|
||||
const found = resources<MeasureReport>(pages, 'MeasureReport');
|
||||
return { measure, points: asked.map((period, i) => ({ period, r: reading(found[i]) })) };
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
protected readonly figures = computed<{ measure: Measure; figure: Figure }[]>(() =>
|
||||
(this.series.value() ?? []).map(({ measure, points }) => {
|
||||
// From the first period with data on.
|
||||
const first = points.findIndex((p) => (p.r?.populations['initial-population'] ?? 0) > 0);
|
||||
return { measure, figure: history(measure, first < 0 ? [] : points.slice(first)) };
|
||||
}),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user