T10/T11: the TEA record and the risk page render inside rebuild's patient frame
Paciente renders the TEA record and, on the risk route, the risk page with the same frame as CaCu and CaMa: back link, title with id, identity block from the FHIR Patient (name, birth date, sex, one row per identifier system), sections as one card component, Material controls for the altered-zones toggle and the pair choice, export button in rebuild's style. tea-patient.ts, tea-record.html, tea-risk.html and tea-section.html/scss are deleted; the logic specs follow the new structure.
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { Component, computed, inject, input, resource } from '@angular/core';
|
||||
import { Component, computed, ElementRef, inject, input, resource, signal } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import type {
|
||||
Condition,
|
||||
@@ -13,6 +16,7 @@ import type {
|
||||
RiskAssessment,
|
||||
} from 'fhir/r4';
|
||||
import { Api } from '../api/api';
|
||||
import { curve } from '../api/fn/models/curve';
|
||||
import { readReport$Json } from '../api/fn/models/read-report-json';
|
||||
import type { Domain } from '../api/models/domain';
|
||||
import { code, EXT, ext, Fhir, label, resources } from '../fhir';
|
||||
@@ -22,7 +26,17 @@ import { LABELS, name, PRIORITY } from '../indicadores/measures';
|
||||
import { Figure, PALETTE, Plot } from '../plot';
|
||||
import { Loading } from '../loading';
|
||||
import { Factores, ScenarioFactors } from './factores';
|
||||
import { TeaRecord } from './tea-patient';
|
||||
import { identityRows, loadTeaPatient, Study } from './tea-data';
|
||||
import { ageNorm, Centile } from './tea-figures';
|
||||
import { TeaSection } from './tea-section';
|
||||
import {
|
||||
exportTeaPdf,
|
||||
forestTitle,
|
||||
probabilityTitle,
|
||||
recordSections,
|
||||
riskSections,
|
||||
Section,
|
||||
} from './tea-sections';
|
||||
|
||||
/** An Observation's value as the screens say it, whatever its type. */
|
||||
function shown(o: Observation): string {
|
||||
@@ -46,10 +60,13 @@ function shown(o: Observation): string {
|
||||
DecimalPipe,
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatSelectModule,
|
||||
MatSlideToggleModule,
|
||||
RouterLink,
|
||||
Plot,
|
||||
TeaRecord,
|
||||
TeaSection,
|
||||
],
|
||||
templateUrl: './paciente.html',
|
||||
styleUrl: './paciente.scss',
|
||||
@@ -57,11 +74,13 @@ function shown(o: Observation): string {
|
||||
export class Paciente {
|
||||
private readonly fhir = inject(Fhir);
|
||||
private readonly api = inject(Api);
|
||||
private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);
|
||||
readonly domain = input.required<string>();
|
||||
readonly id = input.required<string>();
|
||||
/** The follow-up list she was opened from: its window (months) and cut-off. */
|
||||
readonly ventana = input<string>();
|
||||
readonly corte = input<string>();
|
||||
readonly risk = input(false);
|
||||
|
||||
private readonly data = resource({
|
||||
params: () => (this.domain() === 'tea' ? undefined : { domain: this.domain(), id: this.id() }),
|
||||
@@ -345,4 +364,89 @@ export class Paciente {
|
||||
const p = this.patient();
|
||||
return p ? name(ext(p, 'follow-up-status')?.valueCoding?.code ?? '') : '';
|
||||
});
|
||||
protected readonly tea = resource({
|
||||
params: () => (this.domain() === 'tea' ? this.id() : undefined),
|
||||
loader: ({ params }) => loadTeaPatient(this.fhir, params),
|
||||
});
|
||||
protected readonly norms = resource({
|
||||
params: () => (this.risk() || !this.tea.hasValue() ? undefined : this.tea.value().studies),
|
||||
loader: ({ params }) => this.loadNorms(params),
|
||||
});
|
||||
protected readonly onlyAltered = signal(false);
|
||||
protected readonly selectedKey = signal('');
|
||||
protected readonly selectedPair = computed(() => {
|
||||
const pairs = this.tea.hasValue() ? this.tea.value().pairs : [];
|
||||
return pairs.find((pair) => pair.key === this.selectedKey()) ?? pairs[0];
|
||||
});
|
||||
protected readonly teaIdentity = computed(() =>
|
||||
this.tea.hasValue() ? identityRows(this.tea.value().patient) : [],
|
||||
);
|
||||
protected readonly teaSections = computed<Section[]>(() => {
|
||||
if (!this.tea.hasValue()) return [];
|
||||
const patient = this.tea.value();
|
||||
return this.risk()
|
||||
? riskSections(patient, this.onlyAltered(), this.selectedPair())
|
||||
: recordSections(patient, this.norms.hasValue() ? this.norms.value() : new Map());
|
||||
});
|
||||
protected readonly forestTitle = forestTitle;
|
||||
protected readonly probabilityTitle = probabilityTitle;
|
||||
protected readonly exporting = signal(false);
|
||||
protected readonly exportError = signal(false);
|
||||
|
||||
private async loadNorms(studies: Study[]) {
|
||||
const curves = new Map<string, Promise<Centile[]>>();
|
||||
const charts = await Promise.all(
|
||||
studies.flatMap((eeg) =>
|
||||
eeg.metrics.map(async (metric) => {
|
||||
const model = /^tea\.([^/]+)\/([1-9]\d*)$/.exec(metric.model ?? '');
|
||||
if (
|
||||
!model ||
|
||||
metric.key === 'paroxysmal_spikes' ||
|
||||
metric.value == null ||
|
||||
eeg.age == null
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
const [, name, version] = model;
|
||||
const key = model[0];
|
||||
if (!curves.has(key)) {
|
||||
curves.set(
|
||||
key,
|
||||
this.api
|
||||
.invoke(curve, { domain: 'tea', name, version: Number(version) })
|
||||
.then((rows) => rows as Centile[])
|
||||
.catch(() => []),
|
||||
);
|
||||
}
|
||||
const rows = await curves.get(key)!;
|
||||
if (!rows.some((row) => row.median != null)) return undefined;
|
||||
return [
|
||||
`${eeg.id}|${metric.key}`,
|
||||
{
|
||||
title: 'Norma por edad · p5–p95',
|
||||
figure: ageNorm(rows, metric, eeg.age),
|
||||
},
|
||||
] as const;
|
||||
}),
|
||||
),
|
||||
);
|
||||
return new Map(charts.filter((chart) => chart !== undefined));
|
||||
}
|
||||
|
||||
protected async download(): Promise<void> {
|
||||
this.exportError.set(false);
|
||||
this.exporting.set(true);
|
||||
try {
|
||||
await exportTeaPdf(
|
||||
this.risk() ? 'riesgos' : 'seguimiento',
|
||||
this.risk() ? 'Análisis de riesgo TEA' : 'Expediente TEA',
|
||||
this.teaSections(),
|
||||
this.host.nativeElement.querySelectorAll<HTMLDivElement>('app-plot .plot'),
|
||||
);
|
||||
} catch {
|
||||
this.exportError.set(true);
|
||||
} finally {
|
||||
this.exporting.set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user