CaMa record as the old card: summary, mammography, histopathology, prognosis, risk of death and its scenarios' risk factors
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
import { Component, computed, input, signal } from '@angular/core';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
|
||||
/** One scenario's row of a model's scenario summary (models.factors.scenario_row). */
|
||||
export interface ScenarioFactors {
|
||||
escenario: string;
|
||||
n_escenario: number;
|
||||
horizonte_meses?: number;
|
||||
riesgo_definitorios: string;
|
||||
riesgo_mayoritarios: string;
|
||||
incluye_factor_riesgo: boolean;
|
||||
}
|
||||
|
||||
interface Entry {
|
||||
text: string;
|
||||
robust: boolean;
|
||||
}
|
||||
|
||||
/** A listing cell, `variable=category (robusto|sugerente, share)` separated by `;`. */
|
||||
export function entries(cell: string | null | undefined): Entry[] {
|
||||
return (cell ?? '')
|
||||
.split(';')
|
||||
.map((e) => e.trim())
|
||||
.filter(Boolean)
|
||||
.map((text) => ({ text, robust: /\(\s*robusto\b/i.test(text) }));
|
||||
}
|
||||
|
||||
/** "Factores de riesgo de este escenario", as the old record: per scenario of hers, the risk
|
||||
* factors present in at least 95 % of it and those in 50 to 95 %, a robust one solid and a
|
||||
* suggestive one outlined; with a horizon to choose when the model has several. */
|
||||
@Component({
|
||||
selector: 'app-factores',
|
||||
imports: [MatFormFieldModule, MatSelectModule],
|
||||
template: `
|
||||
<h3>Factores de riesgo</h3>
|
||||
@if (horizons().length > 1) {
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="horizon">
|
||||
<mat-label>Horizonte</mat-label>
|
||||
<mat-select [value]="horizon()" (selectionChange)="chosen.set($event.value)">
|
||||
@for (h of horizons(); track h) {
|
||||
<mat-option [value]="h">{{ h }} meses</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
}
|
||||
@for (s of shown(); track s.escenario) {
|
||||
<h4>
|
||||
{{ s.escenario }} <span class="muted">(n = {{ s.n }})</span>
|
||||
</h4>
|
||||
@if (s.defining.length || s.majority.length) {
|
||||
@if (s.defining.length) {
|
||||
<p class="level">Presentes en al menos 95 % del escenario</p>
|
||||
<ul class="factors">
|
||||
@for (e of s.defining; track e.text) {
|
||||
<li [class.robust]="e.robust">{{ e.text }}</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
@if (s.majority.length) {
|
||||
<p class="level">Presentes en 50 a 95 % del escenario</p>
|
||||
<ul class="factors">
|
||||
@for (e of s.majority; track e.text) {
|
||||
<li [class.robust]="e.robust">{{ e.text }}</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
} @else {
|
||||
<p class="muted">Sin factores de riesgo identificados en este escenario.</p>
|
||||
}
|
||||
} @empty {
|
||||
<p class="muted">El informe del modelo no describe factores de sus escenarios.</p>
|
||||
}
|
||||
`,
|
||||
styles: `
|
||||
.horizon {
|
||||
margin: 4px 0 8px;
|
||||
}
|
||||
.level {
|
||||
margin: 6px 0 2px;
|
||||
font-size: 0.85rem;
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
}
|
||||
.factors {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0 0 6px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
.factors li {
|
||||
padding: 2px 10px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--mat-sys-primary);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.factors li.robust {
|
||||
background: var(--mat-sys-primary);
|
||||
color: var(--mat-sys-on-primary);
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class Factores {
|
||||
/** Her scenarios' rows (every horizon when the model has several). */
|
||||
readonly rows = input.required<ScenarioFactors[]>();
|
||||
protected readonly chosen = signal<number | undefined>(undefined);
|
||||
protected readonly horizons = computed(() =>
|
||||
[
|
||||
...new Set(
|
||||
this.rows()
|
||||
.map((r) => r.horizonte_meses)
|
||||
.filter((h) => h !== undefined),
|
||||
),
|
||||
].sort((a, b) => a! - b!),
|
||||
);
|
||||
protected readonly horizon = computed(() => this.chosen() ?? this.horizons().at(-1));
|
||||
protected readonly shown = computed(() =>
|
||||
this.rows()
|
||||
.filter((r) => r.horizonte_meses === undefined || r.horizonte_meses === this.horizon())
|
||||
.map((r) => ({
|
||||
escenario: r.escenario,
|
||||
n: r.n_escenario,
|
||||
defining: entries(r.riesgo_definitorios),
|
||||
majority: entries(r.riesgo_mayoritarios),
|
||||
})),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user