Patient record: eligibility and currency of her risk, risk scales with intervals and factors, curves with the NCI series, survival by her values, antecedents and findings, route sources, CaMa PDF; TEA sections in their own component
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import { Component, computed, input, signal } from '@angular/core';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { Figure, Plot } from '../plot';
|
||||
|
||||
export interface Choice {
|
||||
id: string;
|
||||
name: string;
|
||||
/** drawn until the user says otherwise */
|
||||
on: boolean;
|
||||
}
|
||||
export type Draw = (ids: Set<string>) => Figure;
|
||||
|
||||
/** A figure's named curves as choices, all on; a trace with no legend of its own (a band) goes
|
||||
* with the named one after it. */
|
||||
export function figureChoices(figure: Figure): { choices: Choice[]; draw: Draw } {
|
||||
const groups = new Map<string, Figure['data']>();
|
||||
let pending: Figure['data'] = [];
|
||||
for (const trace of figure.data) {
|
||||
pending.push(trace);
|
||||
const { name, showlegend } = trace as { name?: string; showlegend?: boolean };
|
||||
if (name && showlegend !== false) {
|
||||
groups.set(name, pending);
|
||||
pending = [];
|
||||
}
|
||||
}
|
||||
return {
|
||||
choices: [...groups.keys()].map((name) => ({ id: name, name, on: true })),
|
||||
draw: (ids) => ({ ...figure, data: [...ids].flatMap((id) => groups.get(id) ?? []) }),
|
||||
};
|
||||
}
|
||||
|
||||
/** Curves to compare on one plot, each chosen or not, with what the chosen ones assume. */
|
||||
@Component({
|
||||
selector: 'app-curve-chooser',
|
||||
imports: [MatCheckboxModule, Plot],
|
||||
template: `
|
||||
<div class="choices">
|
||||
@for (c of choices(); track c.id) {
|
||||
<mat-checkbox [checked]="chosen().has(c.id)" (change)="toggle(c.id)">{{
|
||||
c.name
|
||||
}}</mat-checkbox>
|
||||
}
|
||||
</div>
|
||||
@if (chosen().size) {
|
||||
@for (note of said(); track note) {
|
||||
<p class="muted">{{ note }}</p>
|
||||
}
|
||||
<app-plot [figure]="figure()" [height]="340" [toolbar]="false" />
|
||||
}
|
||||
`,
|
||||
styles: `
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
.choices {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0 16px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class CurveChooser {
|
||||
readonly choices = input.required<Choice[]>();
|
||||
readonly draw = input.required<Draw>();
|
||||
readonly notes = input<(ids: Set<string>) => string[]>(() => []);
|
||||
/** the choices the user turned from their default */
|
||||
private readonly flipped = signal(new Set<string>());
|
||||
protected readonly chosen = computed(
|
||||
() =>
|
||||
new Set(
|
||||
this.choices()
|
||||
.filter((c) => c.on !== this.flipped().has(c.id))
|
||||
.map((c) => c.id),
|
||||
),
|
||||
);
|
||||
protected readonly figure = computed(() => this.draw()(this.chosen()));
|
||||
protected readonly said = computed(() => this.notes()(this.chosen()));
|
||||
protected toggle(id: string) {
|
||||
const next = new Set(this.flipped());
|
||||
if (!next.delete(id)) next.add(id);
|
||||
this.flipped.set(next);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user