diff --git a/infra/gitea/custom/public/assets/dossier/view-payment.js b/infra/gitea/custom/public/assets/dossier/view-payment.js
index 79653cb..3dfeb5f 100644
--- a/infra/gitea/custom/public/assets/dossier/view-payment.js
+++ b/infra/gitea/custom/public/assets/dossier/view-payment.js
@@ -1,10 +1,232 @@
-// lex · Payment view. A stub until S1 Task 8 fills it in.
+// lex · Payment view: national non-facility payment = non-facility total RVUs
+// x conversion factor, one column per year on file.
//
-// 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 column (with a "proposed" header),
+// before that year's final column, and are never blended with final values.
+// Every code group shows by default; the Active/Deleted/Linked buttons only
+// filter (S1-P2). The metric and group buttons are UI state, not URL state.
+
+import { esc, int, money, n2 } from "./fmt.js";
+import { citeHtml, factHtml } from "./cite.js";
export const needs = ["header", "payment"];
-export function render() {
- return `
This view is being built.
`;
+const METRICS = [
+ ["pay_nf", "Payment $"],
+ ["work", "Work RVU"],
+ ["total_nf", "Total RVU (non-facility)"],
+];
+const GROUPS = [
+ ["active", "Active"],
+ ["deleted", "Deleted"],
+ ["linked", "Linked"],
+];
+
+const ui = { metric: "pay_nf", group: "all" };
+
+const byId = (a, b) => parseInt(String(a.id).slice(1), 10) - parseInt(String(b.id).slice(1), 10);
+const groups = (P) => P.code_groups || {};
+const allCodes = (P) => [...(groups(P).active || []), ...(groups(P).deleted || []), ...(groups(P).linked || [])];
+const shownCodes = (P, group) => (group === "all" ? allCodes(P) : groups(P)[group] || []);
+
+/** The columns: per year, the proposed one first when that year has one. */
+function columns(rows) {
+ const keys = new Map();
+ for (const r of rows) keys.set(r.vintage, { vintage: r.vintage, year: r.year, proposed: !!r.proposed });
+ return Array.from(keys.values()).sort((a, b) => a.year - b.year || (b.proposed ? 1 : 0) - (a.proposed ? 1 : 0));
+}
+
+const fmt = (metric, v) => (metric === "pay_nf" ? money(v) : n2(v));
+
+function firstOf(rows, vintage) {
+ return rows.find((r) => r.vintage === vintage) || null;
+}
+
+/** The table: a code row per code, a column per vintage, then CF and Source. */
+export function payTable(P, { metric = "pay_nf", group = "all" } = {}, code = "") {
+ const rows = P.rows || [];
+ const cols = columns(rows);
+ const cells = P.cells || {};
+ const cls = (c, extra = "") => `${extra}${c.proposed ? " pcol" : ""}`.trim();
+ let h = `
National unadjusted non-facility payment = non-facility total RVUs × conversion factor, for every year on file. Final values come from each final rule's RVU file; proposed values from the proposed rule's file. They sit in separate columns and are never combined.
`;
+ if (!(P.rows || []).length) return h + `
No payment rows captured for this family.
`;
+ h += controls(P);
+ h += legend(`proposed hatched columnsfinal plain columnsSelect a code to chart it.`);
+ h += `
${payTable(P, ui, code)}
`;
+ h += `
The table opens at the latest years; scroll it sideways for earlier ones. A status letter in place of a dollar value means the status is not paid from RVUs × CF (hover for the reason). A dash means the code is not in that year's file.
`;
+ h += charts(P, code);
+ h += cfNotes(P);
+ const facts = P.facts || {};
+ const un = (P.unplaced || []).map((id) => facts[id]).filter(Boolean).sort(byId);
+ if (un.length) h += `
Unplaced payment facts
Facts the table has no cell for. They are listed so none is lost.
${un.map((f) => factHtml(f)).join("")}
`;
+ return h;
+}
+
+export function mount(root, data, state, nav) {
+ const P = data.payment;
+ const code = selectedCode(P, state);
+ const tbl = root.querySelector("#pay-tbl");
+ if (!tbl) return;
+ const scrollEnd = () => {
+ const sc = root.querySelector("#pay-scroll");
+ if (sc) sc.scrollLeft = sc.scrollWidth;
+ };
+ scrollEnd();
+ const bar = root.querySelector("#pay-f");
+ bar.addEventListener("click", (e) => {
+ const b = e.target.closest("button");
+ if (!b) return;
+ if (b.dataset.m) ui.metric = b.dataset.m;
+ if (b.dataset.g) ui.group = b.dataset.g;
+ for (const x of bar.querySelectorAll("[data-m]")) x.setAttribute("aria-pressed", String(x.dataset.m === ui.metric));
+ for (const x of bar.querySelectorAll("[data-g]")) x.setAttribute("aria-pressed", String(x.dataset.g === ui.group));
+ const sc = root.querySelector("#pay-scroll");
+ const left = sc ? sc.scrollLeft : 0;
+ tbl.innerHTML = payTable(P, ui, code);
+ const sc2 = root.querySelector("#pay-scroll");
+ if (sc2) sc2.scrollLeft = left;
+ });
+ // a click on a row (not on a value cell, which opens its fact) charts that code
+ tbl.addEventListener("click", (e) => {
+ if (e.target.closest("a, button, [data-fact]")) return;
+ const tr = e.target.closest("tr[data-code]");
+ if (tr) nav.go({ code: tr.dataset.code }, { push: false });
+ });
}
diff --git a/tests/lex/views-payment.test.mjs b/tests/lex/views-payment.test.mjs
new file mode 100644
index 0000000..b6cd6b0
--- /dev/null
+++ b/tests/lex/views-payment.test.mjs
@@ -0,0 +1,98 @@
+// lex · Payment view.
+import { test } from "node:test";
+import { equal as eq, ok } from "node:assert/strict";
+import { readFileSync } from "node:fs";
+
+import { parseLocation } from "../../infra/gitea/custom/public/assets/dossier/state.js";
+import * as payment from "../../infra/gitea/custom/public/assets/dossier/view-payment.js";
+
+const fx = (name) => JSON.parse(readFileSync(new URL(`./fixtures/${name}.json`, import.meta.url), "utf8"));
+const H = fx("header");
+const P = fx("payment");
+const st = (url) => parseLocation(new URL(url, "https://lex.test"));
+const count = (s, sub) => s.split(sub).length - 1;
+const page = (url = "/payment?family=HOME-VISITS", p = P) => payment.render({ header: H, payment: p }, st(url));
+
+test("payment: every cell fact, a hatched proposed column, the unplaced fact", () => {
+ const p = page();
+ for (const [k, id] of Object.entries(P.cells)) ok(p.includes(`data-fact="${id}"`), k);
+ ok(p.includes('data-fact="F18"') && p.includes("proposed") && p.includes("pcol"));
+ eq(payment.needs.join(), "header,payment");
+ ok(p.includes("Unplaced payment facts") && p.includes("Invented orphan payment."));
+});
+
+test("payment: the proposed column sits before its year's final column, apart", () => {
+ const t = payment.payTable(P, { metric: "pay_nf", group: "all" });
+ const heads = t.match(/
]*>.*?<\/th>/g);
+ const i27 = heads.findIndex((h) => h.includes("CY2027"));
+ ok(heads[i27].includes("pcol") && heads[i27].includes("proposed"));
+ ok(heads.findIndex((h) => h.includes("CY2023")) < i27);
+ eq(heads.length, 1 + 3, "code, CY2022, CY2023, CY2027 proposed");
+ // the proposed cell is in the hatched column, the final one is not
+ ok(/class="[^"]*pcol[^"]*"[^>]*data-fact="F12"|data-fact="F12"[^>]*class="[^"]*pcol/.test(t));
+ ok(!/pcol[^>]*data-fact="F11"|data-fact="F11"[^>]*pcol/.test(t));
+});
+
+test("payment: every group shows by default, the buttons only filter", () => {
+ const all = page();
+ for (const c of ["99341", "99343", "G0318"]) ok(all.includes(`data-code="${c}"`), c);
+ ok(all.includes("Active 1") && all.includes("Deleted 1") && all.includes("Linked 1"));
+ const del = payment.payTable(P, { metric: "pay_nf", group: "deleted" });
+ ok(del.includes('data-code="99343"') && !del.includes('data-code="99341"'));
+});
+
+test("payment: metric buttons, the value follows the metric", () => {
+ const pay = payment.payTable(P, { metric: "pay_nf", group: "all" });
+ const work = payment.payTable(P, { metric: "work", group: "all" });
+ const tot = payment.payTable(P, { metric: "total_nf", group: "all" });
+ ok(pay.includes("$69.30") && !pay.includes(">2.10<"));
+ ok(work.includes(">1.00<") && !work.includes("$69.30"));
+ ok(tot.includes(">2.10<"));
+ const h = page();
+ ok(h.includes("Payment $") && h.includes("Work RVU") && h.includes("Total RVU"));
+});
+
+test("payment: an unpaid status shows its letter with the note, a missing row a dash", () => {
+ const rows = P.rows.map((r) => (r.code === "99341" && r.year === 2023 ? { ...r, status: "B", pay_nf: null, status_note: "bundled — no separate PFS payment" } : r));
+ const t = payment.payTable({ ...P, rows }, { metric: "pay_nf", group: "all" });
+ ok(/title="bundled — no separate PFS payment"[^>]*>B—<"));
+});
+
+test("payment: CF row, source row, CF notes unchanged and escaped", () => {
+ const rows = P.rows.map((r) => (r.vintage === "CY2027 proposed" ? { ...r, cf_note: "proposed; QP CF $33.1693 ", citation: "CY2027 RVU" } : r));
+ const p = page("/payment?family=HOME-VISITS", { ...P, rows });
+ ok(p.includes("Conv. factor") && p.includes("Source") && p.includes("33.00"));
+ ok(p.includes("proposed; QP CF $33.1693 <b>") && !p.includes("\n"));
+ ok(p.includes("CY2027 <i>RVU</i>") && !p.includes("RVU"));
+ ok(p.includes('href="https://example.test/rvu"'));
+});
+
+test("payment: the payment chart is a final line with proposed rings", () => {
+ const c = payment.payChart(P.rows, "99341");
+ ok(c.includes(" ({ ...r, status: "B", pay_nf: null }));
+ ok(payment.payChart(unpaid, "99341").includes("status B"));
+ ok(!payment.payChart(P.rows, '').includes(""));
+});
+
+test("payment: the volume chart bars one year each", () => {
+ const v = payment.volChart(P.utilization, "99341");
+ eq(count(v, "services\""), 2);
+ ok(v.includes("