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:
Roberto Treviño
2026-11-25 10:21:30 -06:00
parent 70b6d6c646
commit cd7bbaf11a
70 changed files with 5459 additions and 182 deletions
+145
View File
@@ -0,0 +1,145 @@
<section class="page">
<a mat-button [routerLink]="['/indicadores', domain()]"
><mat-icon>arrow_back</mat-icon> Regresar</a
>
@if (error()) {
<p class="muted" role="alert">No se encontró la paciente.</p>
} @else if (patient(); as p) {
<h1>
Paciente <code>{{ p.id!.slice(0, 10) }}</code>
</h1>
<dl class="summary">
<div>
<dt>Fecha de nacimiento</dt>
<dd>{{ p.birthDate ?? 'Sin dato' }}</dd>
</div>
<div>
<dt>Sexo</dt>
<dd>
{{ p.gender === 'female' ? 'Femenino' : p.gender === 'male' ? 'Masculino' : 'Sin dato' }}
</dd>
</div>
<div>
<dt>Estatus de seguimiento</dt>
<dd>{{ status() }}</dd>
</div>
@if (p.deceasedDateTime) {
<div>
<dt>Defunción</dt>
<dd>{{ p.deceasedDateTime }}</dd>
</div>
}
</dl>
<div class="cards">
<mat-card appearance="outlined">
<mat-card-header><mat-card-title>Historial médico</mat-card-title></mat-card-header>
<mat-card-content>
<table class="plain">
<thead>
<tr>
<th>Fecha</th>
<th>Tipo</th>
<th>Detalle</th>
</tr>
</thead>
<tbody>
@for (h of history(); track $index) {
<tr>
<td class="nowrap">{{ h.date }}</td>
<td>{{ h.kind }}</td>
<td>
{{ h.text }}
@if (h.code && h.code !== h.text) {
<span class="muted">({{ h.code }})</span>
}
</td>
</tr>
} @empty {
<tr>
<td colspan="3" class="muted">Sin registros.</td>
</tr>
}
</tbody>
</table>
</mat-card-content>
</mat-card>
<mat-card appearance="outlined">
<mat-card-header><mat-card-title>Pruebas y resultados</mat-card-title></mat-card-header>
<mat-card-content>
<table class="plain">
<thead>
<tr>
<th>Toma</th>
<th>Estudio</th>
<th>Reporte</th>
<th>Resultados</th>
</tr>
</thead>
<tbody>
@for (t of tests(); track $index) {
<tr>
<td class="nowrap">{{ t.date }}</td>
<td>{{ t.kind }}</td>
<td class="nowrap">{{ t.reported ?? 'Pendiente' }}</td>
<td>{{ t.results.join(' · ') || '—' }}</td>
</tr>
} @empty {
<tr>
<td colspan="4" class="muted">Sin estudios.</td>
</tr>
}
</tbody>
</table>
</mat-card-content>
</mat-card>
<mat-card appearance="outlined" class="wide">
<mat-card-header
><mat-card-title>Riesgos y recomendaciones</mat-card-title></mat-card-header
>
<mat-card-content>
@if (models().length) {
<table class="plain">
<thead>
<tr>
<th>Modelo</th>
<th>Fecha índice</th>
<th>Horizonte</th>
<th>Probabilidad</th>
<th>IC 95 %</th>
</tr>
</thead>
<tbody>
@for (m of models(); track m.model) {
@for (p of m.predictions; track p.years) {
<tr>
<td>{{ $first ? m.text : '' }}</td>
<td>{{ $first ? m.index : '' }}</td>
<td>{{ p.years }} {{ p.years === 1 ? 'año' : 'años' }}</td>
<td>{{ p.p * 100 | number: '1.1-2' }} %</td>
<td>
@if (p.low !== undefined) {
{{ p.low * 100 | number: '1.1-2' }}–{{ p.high! * 100 | number: '1.1-2' }}
%
} @else {
—
}
</td>
</tr>
}
}
</tbody>
</table>
<app-plot [figure]="curve()" [height]="300" />
} @else {
<p class="muted">Ningún modelo vigente la ha evaluado.</p>
}
</mat-card-content>
</mat-card>
</div>
} @else if (loading()) {
<p class="muted">Cargando…</p>
}
</section>
+35
View File
@@ -0,0 +1,35 @@
.summary {
display: flex;
flex-wrap: wrap;
gap: var(--space-6);
margin: var(--space-3) 0 var(--space-4);
}
.summary dt {
color: var(--color-text-secondary);
font-size: 12px;
}
.summary dd {
font-weight: 500;
margin: 0;
}
.cards {
display: grid;
gap: var(--space-4);
grid-template-columns: 1fr;
}
@media (min-width: 1100px) {
.cards {
grid-template-columns: repeat(2, 1fr);
}
.wide {
grid-column: 1 / -1;
}
}
mat-card-content {
overflow-x: auto;
}
+176
View File
@@ -0,0 +1,176 @@
import { DecimalPipe } from '@angular/common';
import { Component, computed, inject, input, resource, signal } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatIconModule } from '@angular/material/icon';
import { RouterLink } from '@angular/router';
import type {
Condition,
DiagnosticReport,
Observation,
Patient,
Procedure,
RiskAssessment,
} from 'fhir/r4';
import { code, ext, Fhir, label, resources } from '../fhir';
import { name } from '../indicadores/measures';
import { Figure, PALETTE, Plot } from '../plot';
/** One patient: her history (conditions, procedures), her tests and results, and the
* champion models' risks with their curves. Everything read from the FHIR API. */
@Component({
selector: 'app-paciente',
imports: [DecimalPipe, MatButtonModule, MatCardModule, MatIconModule, RouterLink, Plot],
templateUrl: './paciente.html',
styleUrl: './paciente.scss',
})
export class Paciente {
private readonly fhir = inject(Fhir);
readonly domain = input.required<string>();
readonly id = input.required<string>();
private readonly data = resource({
params: () => ({ domain: this.domain(), id: this.id() }),
loader: async ({ params: { domain, id } }) => {
const subject = { subject: `Patient/${id}`, _count: 200 };
const [patient, conditions, procedures, reports, observations, risks] = await Promise.all([
this.fhir.read<Patient>(domain, 'Patient', id),
this.fhir.all(domain, 'Condition', subject),
this.fhir.all(domain, 'Procedure', subject),
this.fhir.all(domain, 'DiagnosticReport', subject),
this.fhir.all(domain, 'Observation', subject),
this.fhir.all(domain, 'RiskAssessment', subject),
]);
return {
patient,
conditions: resources<Condition>(conditions, 'Condition'),
procedures: resources<Procedure>(procedures, 'Procedure'),
reports: resources<DiagnosticReport>(reports, 'DiagnosticReport').reverse(),
observations: new Map(
resources<Observation>(observations, 'Observation').map((o) => [o.id, o]),
),
risks: resources<RiskAssessment>(risks, 'RiskAssessment'),
};
},
});
protected readonly patient = computed(() => this.data.value()?.patient);
protected readonly error = computed(() => this.data.error());
protected readonly loading = computed(() => this.data.isLoading());
protected readonly history = computed(() => {
const d = this.data.value();
if (!d) return [];
return [
...d.conditions.map((c) => ({
date: c.recordedDate ?? '',
kind: 'Diagnóstico',
text: label(c.code),
code: code(c.code),
})),
...d.procedures.map((p) => ({
date: p.performedDateTime ?? '',
kind: 'Procedimiento',
text: label(p.code),
code: undefined,
})),
].sort((a, b) => b.date.localeCompare(a.date));
});
protected readonly tests = computed(() => {
const d = this.data.value();
if (!d) return [];
return d.reports.map((r) => {
const results = (r.result ?? [])
.map((x) => d.observations.get(x.reference?.split('/')[1]))
.filter((o) => !!o) as Observation[];
return {
date: r.effectiveDateTime ?? '',
reported: ext(r, 'report-date')?.valueDate,
kind: label(r.code),
status: r.status,
results: [
...results.map(
(o) =>
`${label(o.code)}: ${o.valueBoolean !== undefined ? (o.valueBoolean ? 'positivo' : 'negativo') : name(code(o.valueCodeableConcept) ?? '')}`,
),
...(r.conclusionCode ?? []).map((c) => `Histología: ${name(code(c) ?? '')}`),
],
};
});
});
/** One model's latest risk assessment per model. */
protected readonly models = computed(() => {
const latest = new Map<string, RiskAssessment>();
for (const r of this.data.value()?.risks ?? []) {
const key = code(r.method) ?? '';
if (
!latest.has(key) ||
(latest.get(key)!.occurrenceDateTime ?? '') < (r.occurrenceDateTime ?? '')
)
latest.set(key, r);
}
return [...latest.values()].map((r) => ({
model: code(r.method) ?? '',
text: r.method?.text ?? '',
index: r.occurrenceDateTime ?? '',
predictions: (r.prediction ?? []).map((p) => ({
years: p.whenRange?.high?.value ?? 0,
p: p.probabilityDecimal ?? 0,
low: ext(p, 'ic-bajo')?.valueDecimal,
high: ext(p, 'ic-alto')?.valueDecimal,
})),
}));
});
protected readonly shown = signal<string | undefined>(undefined);
protected readonly curve = computed<Figure>(() => {
const models = this.models().filter((m) => m.predictions.length > 1);
return {
data: models.flatMap((m, i) => {
const x = m.predictions.map((p) => p.years);
const color = PALETTE[i % PALETTE.length];
return [
{
x,
y: m.predictions.map((p) => (p.high ?? p.p) * 100),
mode: 'lines',
line: { width: 0 },
showlegend: false,
hoverinfo: 'skip',
},
{
x,
y: m.predictions.map((p) => (p.low ?? p.p) * 100),
mode: 'lines',
line: { width: 0 },
fill: 'tonexty',
fillcolor: color + '33',
showlegend: false,
hoverinfo: 'skip',
},
{
x,
y: m.predictions.map((p) => p.p * 100),
mode: 'lines+markers',
name: m.model.replace('cacu.', ''),
line: { color },
},
];
}),
layout: {
xaxis: { title: { text: 'Años desde la fecha índice' }, dtick: 1 },
// At least 0–5 %: a near-zero risk reads as near zero, not as a full axis.
yaxis: {
title: { text: 'Probabilidad (%)' },
range: [0, Math.max(5, this.top() * 110)],
tickformat: '.1f',
},
},
};
});
private top(): number {
return Math.max(0, ...this.models().flatMap((m) => m.predictions.map((p) => p.high ?? p.p)));
}
protected readonly name = name;
protected readonly status = computed(() => {
const p = this.patient();
return p ? name(ext(p, 'follow-up-status')?.valueCoding?.code ?? '') : '';
});
}