diff --git a/infra/gitea/custom/public/assets/dossier/cite.js b/infra/gitea/custom/public/assets/dossier/cite.js
index 2cc2138..21e4ad0 100644
--- a/infra/gitea/custom/public/assets/dossier/cite.js
+++ b/infra/gitea/custom/public/assets/dossier/cite.js
@@ -75,20 +75,37 @@ function groupChip(cite, refs) {
return `${text} ×${refs.length} `;
}
-/** Text with [F#] tags turned into the facts' cites. Consecutive tags that
+/** Text with [F#] tags turned into the facts' cites. Each distinct source
+ * appears once per line, at its first position (a later repeat is dropped;
+ * its fact still joins that chip's drawer list). Consecutive tags that
* cite the same source collapse into one chip with a count (S1-P11); a
* repeat of one tag counts once. An unknown tag, or a fact with no cite,
* stays as text and ends a run. */
export function tagged(text, facts) {
if (!text) return "";
const lookup = (id) => (facts && Object.prototype.hasOwnProperty.call(facts, id) ? facts[id] : null);
- return esc(text).replace(/(?:\[F\d+\])+/g, (run) => {
+ const src = esc(text);
+ // every fact id per source across the line: a source's first chip counts
+ // and lists them all, so the drawer still reaches each fact
+ const all = new Map();
+ for (const [, id] of src.matchAll(/\[(F\d+)\]/g)) {
+ const f = lookup(id);
+ if (!f || !f.cite) continue;
+ const k = citeKey(f.cite);
+ if (!all.has(k)) all.set(k, []);
+ if (!all.get(k).includes(id)) all.get(k).push(id);
+ }
+ const seen = new Set();
+ return src.replace(/(?:\[F\d+\])+/g, (run) => {
const out = [];
let cur = null;
let chips = 0;
const flush = () => {
- // a space between chips, so a long run of distinct cites can wrap
- if (cur) out.push((chips++ ? " " : "") + citeHtml(cur.cite, { ref: cur.ids[0], refs: cur.ids }));
+ if (cur && !seen.has(citeKey(cur.cite))) {
+ seen.add(citeKey(cur.cite));
+ // a space between chips, so a long run of distinct cites can wrap
+ out.push((chips++ ? " " : "") + citeHtml(cur.cite, { ref: cur.ids[0], refs: all.get(citeKey(cur.cite)) }));
+ }
cur = null;
};
for (const [, id] of run.matchAll(/\[(F\d+)\]/g)) {
diff --git a/infra/gitea/custom/public/assets/dossier/view-timeline.js b/infra/gitea/custom/public/assets/dossier/view-timeline.js
index 122733d..1b08da2 100644
--- a/infra/gitea/custom/public/assets/dossier/view-timeline.js
+++ b/infra/gitea/custom/public/assets/dossier/view-timeline.js
@@ -35,8 +35,13 @@ const list = (ids, facts) => (ids || []).map((id) => facts[id]).filter(Boolean).
function eventHtml(e, facts) {
const telehealth = e.kind === "telehealth_list";
- let h = `
`;
- h += `
${esc(kindLabel(e.kind))} ${tagged(e.what_changed, facts)}
`;
+ const open = (e.fact_ids || [])[0] || (e.cms_summary_fact_ids || [])[0] || "";
+ // a line that is CMS's own summary text is shown once, under its label
+ const flat = (t) => String(t || "").replace(/\s*\[F\d+\]/g, "").replace(/\s+/g, " ").trim();
+ const line = flat(e.what_changed);
+ const dup = !telehealth && (e.cms_summary_fact_ids || []).some((id) => facts[id] && flat(facts[id].text) && line.includes(flat(facts[id].text)));
+ let h = `
`;
+ h += `
${esc(kindLabel(e.kind))} ${dup ? "" : `${tagged(e.what_changed, facts)} `}
`;
if ((e.codes || []).length) h += `
${e.codes.map((c) => `${esc(c)} `).join("")}
`;
const sources = list(e.fact_ids, facts);
if (sources) h += `
Sources and facts (${(e.fact_ids || []).filter((id) => facts[id]).length}) `;
@@ -70,12 +75,13 @@ export function render(data, state) {
Code
All codes ${codes.map((c) => `${esc(c)} `).join("")}`;
- const years = Array.from(new Set(events.map((e) => e.year))).sort((a, b) => a - b);
+ const years = Array.from(new Set(events.map((e) => e.year))).sort((a, b) => (a ?? 1e9) - (b ?? 1e9));
+ const yr = (y) => (y == null ? "Undated" : "CY" + esc(y));
h += `
`;
if (!years.length) h += `
No timeline entries${code ? " for " + esc(code) : ""}.
`;
for (const y of years) {
const its = events.filter((e) => e.year === y);
- h += `
CY${esc(y)}${its.length} ${its.length === 1 ? "entry" : "entries"} ${its.map((e) => eventHtml(e, facts)).join("")}
`;
+ h += `
${yr(y)}${its.length} ${its.length === 1 ? "entry" : "entries"} ${its.map((e) => eventHtml(e, facts)).join("")}
`;
}
h += `
`;
if (unplaced.length) {
diff --git a/infra/gitea/custom/public/assets/dossier/view-valuation.js b/infra/gitea/custom/public/assets/dossier/view-valuation.js
index fa6e5e2..d9bbe03 100644
--- a/infra/gitea/custom/public/assets/dossier/view-valuation.js
+++ b/infra/gitea/custom/public/assets/dossier/view-valuation.js
@@ -44,14 +44,22 @@ function cell(r, key, kind) {
}
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 `;
+ const any = (key) => rows.some(({ r }) => filled(r[key]));
+ const opt = columns.filter(any);
+ const showFinal = any("final_work_rvu");
+ const showDecision = any("decision");
+ let h = `Code RUC rec. CMS proposed proposed `;
+ if (showFinal) h += `CMS final `;
+ if (showDecision) h += `Decision `;
+ h += opt.map((c) => `${esc(OPTIONAL[c][0])} `).join("");
+ h += `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))} `;
+ h += `${esc(r.code)} ${esc(n2(r.ruc_work_rvu))} ${esc(n2(r.proposed_work_rvu))} `;
+ if (showFinal) h += `${esc(n2(r.final_work_rvu))} `;
+ if (showDecision) h += `${esc(r.decision || "—")} `;
+ h += opt.map((c) => cell(r, c, OPTIONAL[c][1])).join("");
+ h += `${citeHtml(sourceCite(r))} `;
}
return h + `
`;
}
@@ -59,13 +67,14 @@ function groupTable(rows, columns, deleted) {
/** 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 internal = (k) => k === "p_id" || k.endsWith("_p_id");
const dl = Object.entries(r)
- .filter(([k, v]) => !skip.has(k) && filled(v))
+ .filter(([k, v]) => !skip.has(k) && !internal(k) && filled(v))
.map(([k, v]) => `${esc(k.replace(/_/g, " "))} ${esc(v)}${asArr((r.cites || {})[k]).map((c) => " " + citeHtml(c)).join("")} `)
.join("");
const rat = r.rationale ? `${citeHtml(r.rationale)}
Rationale
` : "";
return `Evidence · valuation round Close
-
${esc(r.code)} · CY${esc(r.rule_year)} ${esc(r.rule_kind)} rule
+
${esc(r.code)} · ${r.rule_year == null ? "undated" : "CY" + esc(r.rule_year)} ${esc(r.rule_kind)} rule
proposed final
${dl} ${rat}
`;
}
@@ -125,13 +134,14 @@ export function render(data) {
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));
+ const yr = (y) => (y == null ? "Undated" : "CY" + esc(y));
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 += `CY${esc(y)} · ${esc(g.key[1])} rule ${esc(g.key[2])} ${groupTable(g.rows, columns, deleted)}`;
+ h += `${yr(y)} · ${esc(g.key[1])} rule ${esc(g.key[2])} ${groupTable(g.rows, columns, deleted)}`;
}
const yf = facts.filter((f) => f.year === y);
- if (yf.length) h += `Round and practice-expense facts${y == null ? "" : ", CY" + esc(y)} ${yf.map((f) => factHtml(f)).join("")} `;
+ if (yf.length) h += `Round and practice-expense facts${y == null ? "" : ", " + yr(y)} ${yf.map((f) => factHtml(f)).join("")} `;
}
if (rounds.length) h += `Work RVUs across the rounds ${dotPlot(rounds, deleted)}
`;
return h;
diff --git a/tests/lex/cite.test.mjs b/tests/lex/cite.test.mjs
index 69923e5..b3c7853 100644
--- a/tests/lex/cite.test.mjs
+++ b/tests/lex/cite.test.mjs
@@ -176,21 +176,30 @@ test("tagged collapses a run of identical cites into one counted chip (S1-P11)",
ok(!h.includes(" {
+test("one source appears once per line, at its first position; the chip lists every fact (S1-P12)", () => {
const fs = { F1: mk("F1", "A"), F2: mk("F2", "A"), F3: mk("F3", "B"), F4: mk("F4", "A"), F5: mk("F5", "A") };
const h = tagged("x [F1][F2][F3][F4][F5].", fs);
- eq(count(h, " B<") && h.indexOf(">B<") < h.lastIndexOf("A ×2"));
- eq(count(h, "A ×2"), 2);
+ eq(count(h, " B<"));
+});
+
+test("a source repeated later in the line is dropped, its fact kept in the first chip", () => {
+ const fs = { F1: mk("F1", "A"), F2: mk("F2", "B"), F3: mk("F3", "A") };
+ const h = tagged("one [F1] two [F2] three [F3].", fs);
+ eq(count(h, 'data-refs="F1 F3"'), 1);
+ eq(count(h, ">B<"), 1);
+ ok(h.includes("A ×2") && h.endsWith("three ."));
});
test("an uncited tag in a run stays text and ends the run", () => {
const fs = { F1: mk("F1", "A"), F2: { id: "F2", kind: "event", text: "n" }, F3: mk("F3", "A") };
const h = tagged("[F1][F2][F3]", fs);
ok(h.includes("[F2]"));
- eq(count(h, "group"), 0);
- eq(count(h, " {
diff --git a/tests/lex/views-history.test.mjs b/tests/lex/views-history.test.mjs
index 0870589..97c6bc8 100644
--- a/tests/lex/views-history.test.mjs
+++ b/tests/lex/views-history.test.mjs
@@ -115,3 +115,46 @@ test("valuation: round evidence lists every non-empty field with its cite", () =
ok(e.includes("final work rvu") && e.includes("1.5") && e.includes('href="https://example.test/x"'));
ok(e.includes("25th") && !e.includes("survey intra min") && e.includes("data-close"));
});
+
+// ---- S1-P12 fix round ----
+const heads = (html) => [...html.matchAll(/ /g)].map((m) => [...m[0].matchAll(/]*>([\s\S]*?)<\/th>/g)].map((x) => x[1].replace(/<[^>]+>/g, "").trim()));
+
+test("valuation: order Code, RUC, proposed, final, Decision, optional, Source; empty columns dropped per table", () => {
+ const base = { ...V.rounds[0], ruc_percentile: "", survey_total_min: null, requested_work_rvu: null, rationale_quote: "", pe_note: "" };
+ const rounds = [
+ { ...base, code: "99341", rule_year: 2008, rule_kind: "final", item_key: "A", ruc_work_rvu: 1, proposed_work_rvu: 1, final_work_rvu: 1.2, decision: "refine", requested_work_rvu: 2.85 },
+ { ...base, code: "99341", rule_year: 2023, rule_kind: "proposed", item_key: "B", ruc_work_rvu: 1, proposed_work_rvu: 1, final_work_rvu: null, decision: "", ruc_percentile: "25th", pe_note: "supplies" },
+ ];
+ const v = valuation.render({ header: H, valuation: { ...V, rounds, columns: ["ruc_percentile", "requested_work_rvu", "pe_note"], facts: {} } }, st("/valuation?family=X"));
+ const [a, b] = heads(v);
+ eq(a.join("|"), "Code|RUC rec.|CMS proposed proposed|CMS final|Decision|Requested|Source");
+ eq(b.join("|"), "Code|RUC rec.|CMS proposed proposed|Survey pct.|PE note|Source");
+ ok(!a.includes("Survey pct.") && !b.includes("Requested"));
+});
+
+test("valuation: evidence shows cites, not internal ids; a null year does not break the page", () => {
+ const e = valuation.roundEvidence({ ...V.rounds[0], p_id: 5, final_p_id: 7, rationale_p_id: 0, ruc_p_id: 0, final_work_rvu: 1.5 });
+ ok(!/p id/.test(e) && e.includes("final work rvu"));
+ const rounds = [{ ...V.rounds[0], rule_year: null }, { ...V.rounds[1], rule_year: 2008 }];
+ const v = valuation.render({ header: H, valuation: { ...V, rounds, facts: {} } }, st("/valuation?family=X"));
+ ok(v.indexOf("CY2008") < v.indexOf("Undated"));
+ const T2 = { ...T, events: [{ year: null, kind: "origin", codes: [], what_changed: "u", fact_ids: [], stance_fact_ids: [], cms_summary_fact_ids: [] }, { year: 2020, kind: "origin", codes: [], what_changed: "d", fact_ids: [], stance_fact_ids: [], cms_summary_fact_ids: [] }], unplaced: [] };
+ const t = timeline.render({ header: H, timeline: T2 }, st("/timeline?family=X"));
+ ok(t.indexOf("CY2020") < t.indexOf("Undated"));
+});
+
+test("timeline: a comments line that is CMS's summary text shows once, under its label; click and drawer work without fact_ids", () => {
+ const F = { ...T.facts.F6, id: "F12", text: "In the CY2005 final rule, CMS summarized: \"x\"." };
+ const T5 = { ...T, facts: { F12: F }, unplaced: [], events: [{ year: 2005, kind: "comments", codes: [], what_changed: "In the CY2005 final rule, CMS summarized: \"x\". [F12][F12]", fact_ids: [], stance_fact_ids: [], cms_summary_fact_ids: ["F12"] }] };
+ const t = timeline.render({ header: H, timeline: T5 }, st("/timeline?family=X"));
+ eq(count(t, "CMS summarized"), 1);
+ ok(t.includes("CMS's summary") && t.includes('data-open="F12"') && t.includes('data-fact="F12"'));
+ eq(count(t, 'class="cite'), 1, "one chip for the one source");
+});
+
+test("timeline: a repeated tag in a line gives one chip", () => {
+ const T6 = { ...T, unplaced: [], events: [{ year: 2005, kind: "appeared", codes: [], what_changed: "a [F3] b [F4] c [F3] d [F3]", fact_ids: ["F3"], stance_fact_ids: [], cms_summary_fact_ids: [] }] };
+ const t = timeline.render({ header: H, timeline: T6 }, st("/timeline?family=X"));
+ const line = t.slice(t.indexOf('class="sum"'), t.indexOf("