CaCu's page by readings, screening stages, ages and exports
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
import { Component, computed, input, signal } from '@angular/core';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import type { Measure } from 'fhir/r4';
|
||||
import { Mode } from './bars';
|
||||
import { scenarioBars } from './figures';
|
||||
import { detail, donut, formatScore, name, Reading, scoring } from './measures';
|
||||
import type { Section } from './pages';
|
||||
import { Readings } from './readings';
|
||||
|
||||
/** The applied period's readings and the measures they are of. */
|
||||
export interface Source {
|
||||
loading: boolean;
|
||||
reading: (measure: string) => Reading | undefined;
|
||||
measure: (name: string) => Measure | undefined;
|
||||
}
|
||||
type Shown = Extract<Section, { kind: 'readings' | 'columns' | 'choice' }>;
|
||||
|
||||
/** A card of readings, several side by side, or one of several at a time. */
|
||||
@Component({
|
||||
selector: 'app-section',
|
||||
imports: [MatButtonToggleModule, MatCardModule, Readings],
|
||||
template: `
|
||||
@let s = section();
|
||||
@if (s.kind === 'readings') {
|
||||
<mat-card appearance="outlined">
|
||||
<mat-card-content>
|
||||
<app-readings
|
||||
[title]="s.title"
|
||||
[headline]="headline()"
|
||||
[note]="s.note ?? ''"
|
||||
[modes]="s.modes"
|
||||
[loading]="of().loading"
|
||||
[read]="of().reading"
|
||||
[draw]="draw()"
|
||||
/>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
} @else {
|
||||
<h2>{{ s.title }}</h2>
|
||||
@if (s.kind === 'columns') {
|
||||
<div class="columns">
|
||||
@for (inner of s.sections; track $index) {
|
||||
<app-section [section]="inner" [of]="of()" />
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
@let open = chosen() || s.choices[0].label;
|
||||
<mat-button-toggle-group
|
||||
[attr.aria-label]="s.title"
|
||||
[value]="open"
|
||||
(change)="chosen.set($event.value)"
|
||||
>
|
||||
@for (c of s.choices; track c.label) {
|
||||
<mat-button-toggle [value]="c.label">{{ c.label }}</mat-button-toggle>
|
||||
}
|
||||
</mat-button-toggle-group>
|
||||
@for (c of s.choices; track c.label) {
|
||||
@if (c.label === open) {
|
||||
<app-section [section]="c.section" [of]="of()" />
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
styles: `
|
||||
:host {
|
||||
display: block;
|
||||
margin-top: 16px;
|
||||
min-width: 0;
|
||||
}
|
||||
.columns {
|
||||
display: grid;
|
||||
column-gap: 16px;
|
||||
grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr));
|
||||
}
|
||||
.columns > :last-child:nth-child(odd) {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class ReadingsSection {
|
||||
readonly section = input.required<Shown>();
|
||||
readonly of = input.required<Source>();
|
||||
protected readonly chosen = signal('');
|
||||
|
||||
protected readonly headline = computed(() => {
|
||||
const s = this.section();
|
||||
const code = s.kind === 'readings' ? s.headline : undefined;
|
||||
const measure = code && this.of().measure(code);
|
||||
const r = code && this.of().reading(code);
|
||||
if (!measure || !r) return '';
|
||||
const words = detail(measure, r);
|
||||
return scoring(measure) === 'cohort' ? words : `${formatScore(measure, r)} · ${words}`;
|
||||
});
|
||||
protected readonly draw = computed(() => (mode: Mode) => {
|
||||
if (mode.kind !== 'figure') return undefined;
|
||||
const r = this.of().reading(mode.measure);
|
||||
const measure = this.of().measure(mode.measure);
|
||||
if (!measure || !r?.populations['initial-population']) return undefined;
|
||||
if (mode.figure === 'donut') return donut(measure, r);
|
||||
const categories = (mode.catalog ?? []).map((c) => ({ ...c, group: '' }));
|
||||
return scenarioBars(r, { groups: [], categories }, 'follow_up_status', name);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user