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 { ReadingsCard, 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; /** 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') { } @else if (s.kind === 'choice' && s.card) { @let open = chosen() || s.choices[0].label;

{{ s.title }}

@for (c of s.choices; track c.label) { {{ c.label }} } @for (c of s.choices; track c.label) { @if (c.label === open) { } }
} @else {

{{ s.title }}

@if (s.kind === 'columns') { @if (s.views) { @for (v of s.views; track v) { {{ v }} } }
@for (inner of s.sections; track $index) { }
} @else { @let open = chosen() || s.choices[0].label; @for (c of s.choices; track c.label) { {{ c.label }} } @for (c of s.choices; track c.label) { @if (c.label === open) { } } } } `, styles: ` :host { display: block; margin-top: 24px; min-width: 0; } .views { flex-wrap: wrap; margin: 4px 0 8px; } .title { font-size: 18px; font-weight: 500; margin: 0 0 8px; } .choice-card app-readings { margin-top: 8px; } .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(); readonly of = input.required(); /** The mode a card of a `columns` section takes from the section's selector (its label). */ readonly view = input(); /** The view a columns section's selector has chosen. */ protected readonly picked = signal(''); protected readonly chosen = signal(''); protected hasCamaHeading(s: ReadingsCard): boolean { return s.modes.some((mode) => !!mode.heading); } /** A reading card's headline: its measure's score and its counts, in its own units. */ protected headlineOf(s: ReadingsCard): string { const code = s.headline; const measure = code && this.of().measure(code); const r = code && this.of().reading(code); if (!measure || !r) return ''; const words = detail(measure, r, s.unit); 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, 'category', mode.colors); const categories = (mode.catalog ?? []).map((c) => ({ ...c, group: '' })); return scenarioBars( r, { groups: [], categories }, mode.stratum ?? 'follow_up_status', name, mode.order, { fill: mode.complete, ofAll: mode.ofAll }, ); }); }