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)
Some checks failed
CI / lint (push) Successful in 54s
CI / notebooks-smoke (push) Successful in 3m10s
Deploy / changes (push) Successful in 21s
Deploy / notebooks (push) Has been skipped
Deploy / zotero (push) Has been skipped
Deploy / docs (push) Successful in 2m19s
CI / test (push) Failing after 7m56s
Deploy / api (push) Successful in 3m35s
Deploy / bcda (push) Successful in 3m18s
Deploy / mc (push) Has been skipped
Deploy / llm (push) Successful in 1m49s
Deploy / report (push) Successful in 21s

This commit is contained in:
kert
2026-11-13 04:18:23 -05:00
parent 3f6b44a33b
commit 2bfd36858c
2 changed files with 115 additions and 18 deletions

View File

@@ -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 += `</tr>`;
}
h += `<tr><td class="mono small stick">Conv. factor</td>${cols.map((c) => `<td class="${cls(c, "r num")}">${esc(n2((firstOf(rows, c.vintage) || {}).cf))}</td>`).join("")}</tr>`;
h += `<tr><td class="mono small stick">Conv. factor</td>${cols.map((c) => `<td class="${cls(c, "r num")}">${esc(cf4((firstOf(rows, c.vintage) || {}).cf))}</td>`).join("")}</tr>`;
h += `<tr><td class="mono small stick">Source</td>${cols
.map((c) => {
const r = firstOf(rows, c.vintage);
@@ -166,19 +167,46 @@ function charts(P, code) {
<p class="small muted">National totals, all places of service, from CMS's Medicare Physician &amp; Other Practitioners by Geography and Service files.</p></div></div>`;
}
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(`<li><b>CY${esc(c.year)} ${c.proposed ? "proposed" : "final"}</b> ${esc(note)}</li>`);
/** 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 `<li><b>${yrs} ${r.proposed ? "proposed" : "final"}</b> ${esc(r.note)}</li>`;
});
return items.length ? `<div class="sec"><h3>Conversion factor notes</h3><ul class="gaps">${items.join("")}</ul></div>` : "";
}
/** 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;
});

View File

@@ -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 <x>"), mk(2017, false, "std <x>"), mk(2018, false, "std <x>"), mk(2019, false, "other"), mk(2020, false, "std <x>"), mk(2020, true, "std <x>")];
const runs = payment.cfNoteRuns(rows);
eq(runs.length, 4);
deq([runs[0].from, runs[0].to, runs[0].note], [2016, 2018, "std <x>"]);
const h = page("/payment?family=HOME-VISITS", { ...P, rows, cells: {}, unplaced: [] });
ok(h.includes("<b>CY2016–CY2018 final</b> std &lt;x&gt;") && h.includes("<b>CY2020 proposed</b>") && h.includes("<b>CY2020 final</b>"));
eq(count(h, "std &lt;x&gt;"), 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(/<tr data-code="99343" class="sel"/.test(f.els["#pay-tbl"].innerHTML) && !f.els["#pay-tbl"].innerHTML.includes('data-code="99341"'));
f.handlers.clicktbl({ target: { closest: (s) => (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(/<tr data-code="99341" class="sel"/.test(g.els["#pay-tbl"].innerHTML));
});
test("payment: the table scrolls inside its wrapper, the page does not", () => {
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('<div class="tbl-wrap" id="pay-scroll">'));
ok(/\.pay-tbl|\.tbl\b/.test(css) && !/body\s*\{[^}]*overflow-x:\s*scroll/.test(css));
ok(/\.stick\s*\{[^}]*position:\s*sticky/.test(css));
});