`;
+ const sources = list(e.fact_ids, facts);
+ if (sources) h += `Sources and facts (${(e.fact_ids || []).filter((id) => facts[id]).length})
${sources}
`;
+ if (!telehealth) {
+ const ours = list(e.stance_fact_ids, facts);
+ if (ours) h += `
Our classification
${ours}
`;
+ const cms = list(e.cms_summary_fact_ids, facts);
+ if (cms) h += `
CMS's summarycms
${cms}
`;
+ }
+ return h + "
";
+}
+
+export function render(data, state) {
+ const T = data.timeline;
+ const facts = T.facts || {};
+ const code = (state && state.code) || "";
+ const all = T.events || [];
+ const events = all.filter((e) => !code || (e.codes || []).includes(code));
+ const unplaced = (T.unplaced || []).map((id) => facts[id]).filter((f) => f && (!code || (f.codes || []).includes(code)));
+
+ const counts = new Map();
+ for (const e of events) counts.set(filterKey(e.kind), (counts.get(filterKey(e.kind)) || 0) + 1);
+ const codes = Array.from(new Set(all.flatMap((e) => e.codes || []))).sort();
+ if (code && !codes.includes(code)) codes.push(code);
+
+ let h = `
Timeline
+
Dated changes to the family: what appeared, was deleted or revalued, and CMS's own summaries of comments. Open an entry's sources to read the fact behind it.
Facts the timeline did not attach to a dated entry. They are listed here so none is lost.
+
${unplaced.map((f) => factHtml(f)).join("")}
`;
+ }
+ return h;
+}
+
+export function mount(root, data, state, nav) {
+ const bar = root.querySelector("#tl-f");
+ const sel = root.querySelector("#tl-code");
+ if (bar) {
+ bar.addEventListener("click", (e) => {
+ const b = e.target.closest("[data-k]");
+ if (!b) return;
+ for (const x of bar.querySelectorAll("[data-k]")) x.setAttribute("aria-pressed", String(x === b));
+ // the kind filter is UI only: it hides rows, it does not touch the URL
+ for (const it of root.querySelectorAll(".tl-item")) it.hidden = b.dataset.k !== "all" && it.dataset.kind !== b.dataset.k;
+ for (const y of root.querySelectorAll(".tl-year")) y.hidden = !y.querySelector(".tl-item:not([hidden])");
+ });
+ }
+ if (sel) sel.addEventListener("change", () => nav.go({ code: sel.value }, { push: false }));
+ root.addEventListener("click", (e) => {
+ if (e.target.closest("a, button, summary, details, [data-fact], [data-ref], [data-refs]")) return;
+ const it = e.target.closest(".tl-item");
+ if (it && it.dataset.open) nav.openFact(it.dataset.open);
+ });
}
diff --git a/infra/gitea/custom/public/assets/dossier/view-valuation.js b/infra/gitea/custom/public/assets/dossier/view-valuation.js
index 7be5c18..fa6e5e2 100644
--- a/infra/gitea/custom/public/assets/dossier/view-valuation.js
+++ b/infra/gitea/custom/public/assets/dossier/view-valuation.js
@@ -1,10 +1,160 @@
-// lex · Valuation view. A stub until S1 Task 7 fills it in.
+// lex · Valuation view: RUC recommendation against CMS's proposed and final
+// work RVUs, one table per rule, then the dot plot across the rounds.
//
-// A view module exports needs (the API slices it reads), render(data, state)
-// returning markup, and optionally mount(root, data, state, nav).
+// Proposed values sit in their own hatched columns with a "proposed" pill and
+// are never blended with final ones. Columns that are empty across every row
+// are left out (the slice's `columns`).
+
+import { esc, int, n2 } from "./fmt.js";
+import { citeHtml, factHtml } from "./cite.js";
export const needs = ["header", "valuation"];
-export function render() {
- return `
This view is being built.
`;
+const OPTIONAL = {
+ ruc_percentile: ["Survey pct.", "text"],
+ survey_intra_min: ["Survey intra (min)", "int"],
+ survey_total_min: ["Survey total (min)", "int"],
+ comparators: ["Comparators", "text"],
+ surveying_societies: ["Surveying societies", "text"],
+ requested_work_rvu: ["Requested", "rvu"],
+ rationale_quote: ["CMS rationale", "why"],
+ pe_note: ["PE note", "why"],
+};
+
+const asArr = (c) => (Array.isArray(c) ? c : c ? [c] : []);
+const filled = (v) => v !== null && v !== undefined && v !== "" && !(Array.isArray(v) && v.length === 0);
+const byId = (a, b) => parseInt(String(a.id).slice(1), 10) - parseInt(String(b.id).slice(1), 10);
+
+// The row's source: its rationale, else the cite behind its final value.
+function sourceCite(r) {
+ if (r.rationale) return r.rationale;
+ const c = r.cites || {};
+ for (const k of ["final_work_rvu", "decision", "proposed_work_rvu", "ruc_work_rvu", ...Object.keys(c)]) {
+ const [first] = asArr(c[k]);
+ if (first) return first;
+ }
+ return null;
+}
+
+function cell(r, key, kind) {
+ const v = r[key];
+ if (kind === "int") return `
${v == null ? "—" : esc(int(v))}
`;
+ if (kind === "rvu") return `
${esc(n2(v))}
`;
+ return `
${filled(v) ? esc(v) : "—"}
`;
+}
+
+function groupTable(rows, columns, deleted) {
+ let h = `
Code
RUC rec.
`;
+ h += columns.map((c) => `
${esc(OPTIONAL[c][0])}
`).join("");
+ h += `
CMS proposed proposed
CMS final
Decision
Source
`;
+ for (const { r, i } of rows) {
+ const del = deleted.has(r.code);
+ h += `
${esc(r.code)}
${esc(n2(r.ruc_work_rvu))}
`;
+ h += columns.map((c) => cell(r, c, OPTIONAL[c][1])).join("");
+ h += `
${esc(n2(r.proposed_work_rvu))}
${esc(n2(r.final_work_rvu))}
${esc(r.decision || "—")}
${citeHtml(sourceCite(r))}
`;
+ }
+ return h + `
`;
+}
+
+/** One row's evidence for the drawer: every non-empty field, each with its cite. */
+export function roundEvidence(r) {
+ const skip = new Set(["family", "cites", "rationale"]);
+ const dl = Object.entries(r)
+ .filter(([k, v]) => !skip.has(k) && filled(v))
+ .map(([k, v]) => `
`;
+}
+
+/** Work RVUs by code: an open ring for each RUC recommendation, a circle for
+ * each CMS final value, one position per round year (older rounds paler). */
+export function dotPlot(rounds, deleted = new Set()) {
+ const codes = Array.from(new Set(rounds.map((r) => r.code))).sort();
+ const years = Array.from(new Set(rounds.map((r) => r.rule_year))).sort((a, b) => a - b);
+ const vals = rounds.flatMap((r) => [r.ruc_work_rvu, r.final_work_rvu]).filter((v) => v != null).map(Number);
+ const xmax = Math.max(1, Math.ceil(Math.max(0, ...vals)));
+ const W = 660, rowH = 24, top = 46, left = 70, right = 24, H = top + codes.length * rowH + 30;
+ const X = (v) => left + (v / xmax) * (W - left - right);
+ const step = xmax > 8 ? 2 : 1;
+ const fade = (y) => (years.length > 1 ? (0.45 + (0.55 * years.indexOf(y)) / (years.length - 1)).toFixed(2) : "1");
+ let s = ``;
+}
+
+export function render(data) {
+ const V = data.valuation;
+ const rounds = V.rounds || [];
+ const facts = Object.values(V.facts || {}).sort(byId);
+ const deleted = new Set(((data.header && data.header.code_groups) || {}).deleted || []);
+ const columns = (V.columns || []).filter((c) => OPTIONAL[c]);
+ let h = `
Valuation
+
The RUC's recommendation against CMS's proposed and final work RVUs, per code per rule. Proposed values are hatched and kept in their own column; they are never blended with final ones.
+
proposed from the proposed rulefinal from the final rule
`;
+ if (!rounds.length) h += `
No valuation rounds captured for this family.
`;
+
+ const keyOf = (r) => [r.rule_year, r.rule_kind, r.item_key];
+ const groups = [];
+ rounds.forEach((r, i) => {
+ let g = groups.find((x) => x.key.join("|") === keyOf(r).join("|"));
+ if (!g) groups.push((g = { key: keyOf(r), rows: [] }));
+ g.rows.push({ r, i });
+ });
+ const cmp = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
+ groups.sort((a, b) => cmp(a.key[0], b.key[0]) || cmp(String(a.key[1]), String(b.key[1])) || cmp(String(a.key[2]), String(b.key[2])));
+ const years = Array.from(new Set([...groups.map((g) => g.key[0]), ...facts.map((f) => f.year)])).sort((a, b) => (a ?? 1e9) - (b ?? 1e9));
+ for (const y of years) {
+ for (const g of groups.filter((x) => x.key[0] === y)) {
+ g.rows.sort((a, b) => String(a.r.code).localeCompare(String(b.r.code)));
+ h += `