--- a/model.typ +++ b/model.typ @@ #let render-timeline(theme, entries) = { @@ for entry in entries { + let time = str(dict-get(entry, "time", "")) rows.push( ( - [#as-content(dict-get(entry, "time", ""))], + // Dates/times are identifier-like strings with few natural break points. + // Give them a slightly wider column and a smaller face so ranges such as + // `2026-03-19 ~08:17-08:20` stay inside the cell. + [#text(size: 8pt)[#time]], [#as-content(dict-get(entry, "event", ""))], [#as-content(dict-get(entry, "notes", ""))], ), @@ table( - columns: (22mm, 1.1fr, 2fr), + columns: (31mm, 1.1fr, 2fr), @@ ) } + +// ----------------------------------------------------------------------------- +// ----- Diagnostic hypotheses +// ----------------------------------------------------------------------------- +#let confidence-bar(theme, value) = { + let value = int(value) + let color = if value >= 80 { + theme-color(theme, "critical") + } else if value >= 50 { + theme-color(theme, "warning") + } else { + theme-color(theme, "info") + } + + grid( + columns: (1fr, 12mm), + gutter: 6pt, + align: (left + horizon, right + horizon), + block( + width: 100%, + height: 5pt, + radius: 2.5pt, + fill: theme-color(theme, "paper_soft"), + stroke: 0.4pt + theme-color(theme, "line"), + )[ + #block( + width: value * 1%, + height: 100%, + radius: 2.5pt, + fill: color, + ) + ], + text(size: 8pt, weight: "bold", fill: color)[#value%], + ) +} + +#let diagnostic-list(theme, title, items) = { + if items.len() > 0 { + text(size: 7.5pt, weight: "bold", fill: theme-color(theme, "muted"))[#title] + v(2pt) + list( + tight: true, + ..items.map(item => text(size: 8.5pt)[#as-content(item)]), + ) + } +} + +#let render-diagnostics(theme, diagnostics) = { + let scale = dict-get(diagnostics, "confidence_scale", (:)) + let interpretation = dict-get(scale, "interpretation", none) + let hypotheses = dict-get(diagnostics, "hypotheses", ()) + let leading = dict-get(diagnostics, "current_leading_assessment", (:)) + let unsupported = dict-get(diagnostics, "not_yet_supported", ()) + + if interpretation != none { + callout( + theme, + [#as-content(interpretation)], + title: "How to read confidence", + kind: "info", + ) + v(7pt) + } + + for hypothesis in hypotheses { + let id = dict-get(hypothesis, "id", "Dx") + let diagnosis = dict-get(hypothesis, "diagnosis", "Diagnostic hypothesis") + let confidence = dict-get(hypothesis, "confidence_percent", 0) + let status = dict-get(hypothesis, "status", none) + let scope = dict-get(hypothesis, "scope", none) + let evidence-for = dict-get(hypothesis, "evidence_for", ()) + let evidence-against = dict-get(hypothesis, "evidence_against", ()) + let hypothesis-interpretation = dict-get(hypothesis, "interpretation", none) + let tests = dict-get(hypothesis, "tests_to_confirm", ()) + + block( + width: 100%, + breakable: true, + inset: 8pt, + stroke: 0.5pt + theme-color(theme, "line"), + radius: 2pt, + )[ + #grid( + columns: (auto, 1fr, auto), + gutter: 6pt, + align: (left + horizon, left + horizon, right + horizon), + badge(id, color: theme-color(theme, "accent")), + text(size: 10pt, weight: "bold")[#diagnosis], + if status != none { badge(status, color: severity-color(theme, status)) } else { [] }, + ) + #v(5pt) + #confidence-bar(theme, confidence) + #if scope != none { + v(3pt) + text(size: 7.5pt, fill: theme-color(theme, "muted"))[SCOPE: #upper(str(scope))] + } + #if evidence-for.len() > 0 { + v(6pt) + diagnostic-list(theme, "EVIDENCE FOR", evidence-for) + } + #if evidence-against.len() > 0 { + v(5pt) + diagnostic-list(theme, "EVIDENCE AGAINST / LIMITATIONS", evidence-against) + } + #if hypothesis-interpretation != none { + v(5pt) + text(size: 7.5pt, weight: "bold", fill: theme-color(theme, "muted"))[INTERPRETATION] + v(2pt) + text(size: 8.5pt)[#as-content(hypothesis-interpretation)] + } + #if tests.len() > 0 { + v(5pt) + diagnostic-list(theme, "TESTS TO CONFIRM / REFUTE", tests) + } + ] + v(6pt) + } + + if leading.len() > 0 { + let statement = dict-get(leading, "statement", none) + let confidence = dict-get(leading, "confidence_percent", none) + callout( + theme, + [ + #if confidence != none { confidence-bar(theme, confidence); v(5pt) } + #as-content(statement) + ], + title: "Current leading assessment", + kind: "warning", + ) + } + + if unsupported.len() > 0 { + v(7pt) + diagnostic-list(theme, "NOT YET SUPPORTED", unsupported) + } +} @@ if findings.len() > 0 { section-title(theme, "Findings") render-findings(theme, findings) } + + // --------------------------------------------------------------------------- + // Diagnostics / working hypotheses + // --------------------------------------------------------------------------- + let diagnostics = dict-get(report, "diagnostics", (:)) + let hypotheses = dict-get(diagnostics, "hypotheses", ()) + + if hypotheses.len() > 0 { + section-title(theme, "Diagnostic hypotheses") + render-diagnostics(theme, diagnostics) + } // --------------------------------------------------------------------------- // Arbitrary sections