From 2bfd36858cc01729a6b4489b5d2f2a427b2971d7 Mon Sep 17 00:00:00 2001 From: kert Date: Fri, 13 Nov 2026 04:18:23 -0500 Subject: [PATCH] fix(lex): Payment view opens clear of the sticky column, CF to four decimals, CF notes collapse by run, filters read the current code (S1) --- .../public/assets/dossier/view-payment.js | 65 +++++++++++++----- tests/lex/views-payment.test.mjs | 68 ++++++++++++++++++- 2 files changed, 115 insertions(+), 18 deletions(-) diff --git a/infra/gitea/custom/public/assets/dossier/view-payment.js b/infra/gitea/custom/public/assets/dossier/view-payment.js index 3dfeb5f..1c69b30 100644 --- a/infra/gitea/custom/public/assets/dossier/view-payment.js +++ b/infra/gitea/custom/public/assets/dossier/view-payment.js @@ -36,6 +36,7 @@ function columns(rows) { return Array.from(keys.values()).sort((a, b) => a.year - b.year || (b.proposed ? 1 : 0) - (a.proposed ? 1 : 0)); } +const cf4 = (v) => (v == null ? "—" : Number(v).toFixed(4)); const fmt = (metric, v) => (metric === "pay_nf" ? money(v) : n2(v)); function firstOf(rows, vintage) { @@ -67,7 +68,7 @@ export function payTable(P, { metric = "pay_nf", group = "all" } = {}, code = "" } h += ``; } - h += `Conv. factor${cols.map((c) => `${esc(n2((firstOf(rows, c.vintage) || {}).cf))}`).join("")}`; + h += `Conv. factor${cols.map((c) => `${esc(cf4((firstOf(rows, c.vintage) || {}).cf))}`).join("")}`; h += `Source${cols .map((c) => { const r = firstOf(rows, c.vintage); @@ -166,19 +167,46 @@ function charts(P, code) {

National totals, all places of service, from CMS's Medicare Physician & Other Practitioners by Geography and Service files.

`; } -function cfNotes(P) { - const seen = new Set(); - const items = []; - for (const c of columns(P.rows || [])) { - const r = firstOf(P.rows, c.vintage); - const note = r && r.cf_note; - if (!note || seen.has(c.vintage + "|" + note)) continue; - seen.add(c.vintage + "|" + note); - items.push(`
  • CY${esc(c.year)} ${c.proposed ? "proposed" : "final"} ${esc(note)}
  • `); +/** Distinct CF notes, text unchanged; consecutive vintages of one kind that + * share an identical note collapse into one line ("CY2016–CY2018 final"). */ +export function cfNoteRuns(rows) { + const runs = []; + for (const proposed of [true, false]) { + let cur = null; + for (const c of columns(rows).filter((x) => x.proposed === proposed)) { + const note = (firstOf(rows, c.vintage) || {}).cf_note; + if (!note) { + cur = null; + } else if (cur && cur.note === note && c.year === cur.to + 1) { + cur.to = c.year; + } else { + runs.push((cur = { note, from: c.year, to: c.year, proposed })); + } + } } + return runs.sort((a, b) => a.from - b.from || (b.proposed ? 1 : 0) - (a.proposed ? 1 : 0)); +} + +function cfNotes(P) { + const items = cfNoteRuns(P.rows || []).map((r) => { + const yrs = r.from === r.to ? `CY${esc(r.from)}` : `CY${esc(r.from)}–CY${esc(r.to)}`; + return `
  • ${yrs} ${r.proposed ? "proposed" : "final"} ${esc(r.note)}
  • `; + }); return items.length ? `

    Conversion factor notes

    ` : ""; } +/** The opening scroll position: at the table's right end, with the first + * visible column's left edge exactly at the sticky Code column's right edge + * (the next column boundary at or past the end), so no digit sits under it. + * The caller pads the wrapper by (result - max) so that position exists. + * offsets are the columns' left edges in the table. */ +export function openScroll(offsets, stickyW, max) { + if (max <= 0) return 0; + let best = null; + for (const o of offsets) if (o - stickyW >= max && (best === null || o - stickyW < best)) best = o - stickyW; + return best === null ? max : best; +} + const selectedCode = (P, state) => (state && state.code) || (groups(P).active || [])[0] || allCodes(P)[0] || ""; export function render(data, state) { @@ -201,14 +229,17 @@ export function render(data, state) { 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 sc0 = root.querySelector("#pay-scroll"); + if (sc0) { + const heads = Array.from(sc0.querySelectorAll("thead th")); + const stickyW = heads[0].offsetWidth; + const max = sc0.scrollWidth - sc0.clientWidth; + const at = openScroll(heads.slice(1).map((th) => th.offsetLeft), stickyW, max); + if (at > max) sc0.style.paddingRight = `${at - max}px`; + sc0.scrollLeft = at; + } const bar = root.querySelector("#pay-f"); bar.addEventListener("click", (e) => { const b = e.target.closest("button"); @@ -219,7 +250,7 @@ export function mount(root, data, state, nav) { 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); + tbl.innerHTML = payTable(P, ui, selectedCode(P, state)); const sc2 = root.querySelector("#pay-scroll"); if (sc2) sc2.scrollLeft = left; }); diff --git a/tests/lex/views-payment.test.mjs b/tests/lex/views-payment.test.mjs index b6cd6b0..05116ee 100644 --- a/tests/lex/views-payment.test.mjs +++ b/tests/lex/views-payment.test.mjs @@ -1,6 +1,6 @@ // lex · Payment view. import { test } from "node:test"; -import { equal as eq, ok } from "node:assert/strict"; +import { equal as eq, deepEqual as deq, ok } from "node:assert/strict"; import { readFileSync } from "node:fs"; import { parseLocation } from "../../infra/gitea/custom/public/assets/dossier/state.js"; @@ -96,3 +96,69 @@ test("payment: no payment rows is a plain message", () => { const p = page("/payment?family=HOME-VISITS", { ...P, rows: [], cells: {}, unplaced: [], utilization: [], years: [], code_groups: { active: [], deleted: [], linked: [] } }); ok(p.includes("No payment rows")); }); + +test("payment: the CF row shows four decimals", () => { + const rows = P.rows.map((r) => (r.vintage === "CY2022 final" ? { ...r, cf: 35.9335 } : r)); + ok(payment.payTable({ ...P, rows }, { metric: "pay_nf", group: "all" }).includes(">35.9335<")); +}); + +test("payment: CF notes stay literal; identical consecutive notes collapse", () => { + const mk = (year, proposed, note) => ({ ...P.rows[0], year, proposed, vintage: `CY${year} ${proposed ? "proposed" : "final"}`, cf_note: note }); + const rows = [mk(2016, false, "std "), mk(2017, false, "std "), mk(2018, false, "std "), mk(2019, false, "other"), mk(2020, false, "std "), mk(2020, true, "std ")]; + const runs = payment.cfNoteRuns(rows); + eq(runs.length, 4); + deq([runs[0].from, runs[0].to, runs[0].note], [2016, 2018, "std "]); + const h = page("/payment?family=HOME-VISITS", { ...P, rows, cells: {}, unplaced: [] }); + ok(h.includes("CY2016–CY2018 final std <x>") && h.includes("CY2020 proposed") && h.includes("CY2020 final")); + eq(count(h, "std <x>"), 3); +}); + +test("payment: the opening scroll leaves the first visible column clear of the sticky column", () => { + // sticky 100 wide; columns start at 100, 200, 300, 400; table 500 in a 300 box (max 200) + eq(payment.openScroll([100, 200, 300, 400], 100, 200), 200, "column at 300 sits right at the sticky edge"); + eq(payment.openScroll([100, 200, 300, 400], 100, 250), 300, "the next boundary past the end; the caller pads"); + eq(payment.openScroll([100, 200], 100, 0), 0, "a table that fits stays put"); + eq(payment.openScroll([100, 200], 100, 500), 500, "no boundary reaches the end: the end itself"); +}); + +function fakeRoot(P, geometry) { + const handlers = {}; + const mkEl = (extra = {}) => ({ innerHTML: "", addEventListener: (t, f) => (handlers[t + (extra.id || "")] = f), querySelectorAll: () => [], ...extra }); + const sc = { style: {}, scrollLeft: -1, scrollWidth: geometry.sw, clientWidth: geometry.cw, querySelectorAll: () => geometry.heads.map(([l, w]) => ({ offsetLeft: l, offsetWidth: w })) }; + const els = { "#pay-tbl": mkEl({ id: "tbl" }), "#pay-scroll": sc, "#pay-f": mkEl({ id: "bar" }) }; + return { els, handlers, root: { querySelector: (s) => els[s] || null } }; +} + +test("payment: mount opens scrolled clear of the sticky column", () => { + const f = fakeRoot(P, { sw: 500, cw: 300, heads: [[0, 100], [100, 100], [200, 100], [300, 100], [400, 100]] }); + payment.mount(f.root, { header: H, payment: P }, st("/payment?family=HOME-VISITS"), { go() {} }); + eq(f.els["#pay-scroll"].scrollLeft, 200); + const g = fakeRoot(P, { sw: 500, cw: 300, heads: [[0, 100], [100, 120], [220, 100], [320, 100], [420, 80]] }); + payment.mount(g.root, { header: H, payment: P }, st("/payment?family=HOME-VISITS"), { go() {} }); + eq(g.els["#pay-scroll"].scrollLeft, 220, "boundary 320 - sticky 100"); + eq(g.els["#pay-scroll"].style.paddingRight, "20px", "padding so the position exists"); +}); + +test("payment: filters redraw with the current code; a code click re-mounts through nav.go", () => { + const gone = []; + const f = fakeRoot(P, { sw: 500, cw: 300, heads: [[0, 100], [100, 100]] }); + payment.mount(f.root, { header: H, payment: P }, st("/payment?family=HOME-VISITS#code=99343"), { go: (p, o) => gone.push([p, o]) }); + f.handlers.clickbar({ target: { closest: () => ({ dataset: { g: "deleted" } }) } }); + ok(/ (s.includes("data-fact") ? null : { dataset: { code: "99341" } }) } }); + eq(gone[0][0].code, "99341"); + // app.js re-renders (and so re-mounts) on a code change: the new mount carries the new code + const g = fakeRoot(P, { sw: 500, cw: 300, heads: [[0, 100], [100, 100]] }); + payment.mount(g.root, { header: H, payment: P }, st("/payment?family=HOME-VISITS#code=99341"), { go() {} }); + g.handlers.clickbar({ target: { closest: () => ({ dataset: { g: "all" } }) } }); + g.handlers.clickbar({ target: { closest: () => ({ dataset: { m: "work" } }) } }); + ok(/ { + const css = readFileSync(new URL("../../dev/scripts/dossier_page/template.html", import.meta.url), "utf8"); + ok(/\.tbl-wrap\s*\{[^}]*overflow-x:\s*auto/.test(css)); + ok(payment.payTable(P, { metric: "pay_nf", group: "all" }).startsWith('
    ')); + ok(/\.pay-tbl|\.tbl\b/.test(css) && !/body\s*\{[^}]*overflow-x:\s*scroll/.test(css)); + ok(/\.stick\s*\{[^}]*position:\s*sticky/.test(css)); +});