Files
WebApp/src/app/indicadores/tab-definiciones.ts
T

139 lines
4.5 KiB
TypeScript

import { Component, computed, input } from '@angular/core';
import type { Measure } from 'fhir/r4';
import { DOMAINS } from '../app';
import type { Domain } from '../api/models/domain';
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' };
/** "Datos y definiciones" as the old tab: the domain's information, then its catalog, each
* indicator opening to what it is (how it scores, which way is better, its periods and
* strata). */
@Component({
selector: 'app-tab-definiciones',
template: `
<section class="card">
<h2>Datos y definiciones de {{ domainName() }}</h2>
<section aria-labelledby="domain-info-title">
<h3 id="domain-info-title">Información del dominio</h3>
@if (domain() === 'cacu') {
<p>
Pacientes evaluadas incluye a las pacientes con citología tomada en el periodo cuyo
espécimen fue insatisfactorio.
</p>
}
@if (available().length) {
<p>Periodicidad disponible: {{ available().join(', ') }}.</p>
} @else {
<p>Periodicidad: pendiente de información.</p>
}
</section>
<section aria-labelledby="definitions-catalog-title">
<h3 id="definitions-catalog-title">Catálogo de indicadores</h3>
<p>Consulta las gráficas disponibles y la periodicidad de cada indicador.</p>
@for (m of measures(); track m.id) {
<details>
<summary>{{ m.title || 'Nombre pendiente de publicación' }}</summary>
<div class="indicator-detail">
@if (m.description) {
<p>{{ m.description }}</p>
}
<h4>Cálculo</h4>
<p>
{{ scoring[code(m.scoring) ?? ''] }}
@if (improvement[code(m.improvementNotation) ?? '']; as better) {
· {{ better }}
}
</p>
<h4>Tipos de periodo admitidos</h4>
@if (types(m).length) {
<ul>
@for (t of types(m); track t) {
<li>{{ t }}</li>
}
</ul>
} @else {
<p>Pendiente de información.</p>
}
<h4>Estratos</h4>
<p>{{ strata(m) }}</p>
<p class="muted">
Clave <code>{{ m.name }}</code> · versión {{ m.version }}
</p>
</div>
</details>
} @empty {
<p role="status">
No hay indicadores disponibles en el catálogo. Las definiciones están pendientes de
información.
</p>
}
</section>
</section>
`,
styles: `
:host {
display: block;
padding-top: 16px;
}
.card {
background: var(--mat-sys-surface);
border: 1px solid var(--mat-sys-outline-variant);
border-radius: 12px;
padding: 16px 20px;
}
h2,
h3 {
font-size: 20px;
font-weight: 500;
}
h4 {
font-size: 14px;
font-weight: 500;
margin: 12px 0 4px;
}
details {
border-bottom: 1px solid var(--mat-sys-outline-variant);
padding: 8px 0;
}
summary {
cursor: pointer;
font-weight: 500;
}
.indicator-detail {
padding: 4px 0 8px 16px;
}
`,
})
export class TabDefiniciones {
readonly domain = input.required<string>();
readonly measures = input.required<Measure[]>();
protected readonly scoring = SCORING;
protected readonly improvement = IMPROVEMENT;
protected readonly code = code;
protected readonly domainName = computed(
() => DOMAINS[this.domain() as Domain]?.toLocaleLowerCase('es-MX') ?? this.domain(),
);
/** The periodicities any of its indicators admits. */
protected readonly available = computed(() =>
[...new Set(this.measures().flatMap((m) => periodTypes(m)))].map((p) => PERIODS[p] ?? p),
);
protected types(m: Measure): string[] {
return periodTypes(m).map((p) => PERIODS[p] ?? p);
}
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(', ') || '—';
}
}