Good faith estimate comparison (No Surprises Act)
LegalFor a patient who is uninsured or paying for their own care, each provider or facility is compared with its own line on the good faith estimate, never with the estimate as a whole, and everything it billed counts, including items that were not on the estimate. A provider missing from the estimate is compared with nothing. Where a provider billed at least $400 more, counted in whole cents, the patient is told they can dispute that bill, by a deadline 120 days from the date on the initial bill, that it will not go to collections or gather late fees while the dispute is open, and whom to contact: CMS, or the state where it runs its own process. A statement can offer the dispute for one provider and not another. Under $400 it says so without dispute wording. A patient billing their plan or enrolled in a federal programme, or with no estimate, gets nothing. All of it is one deriver.
npx dxcl add good-faith-estimate-comparison patientBill.coverage Datos de vista previa
el JSON con el que se construyó esta vista previa{
"patientBill": {
"coverage": "uninsured",
"initialBillDate": "2026-11-02",
"estimate": {
"date": "2026-09-14"
},
"providers": [
{
"name": "Northwestern Lakeshore Regional Medical Center Ambulatory Surgery Department",
"estimateCents": 4850000,
"billedLines": [
{
"amountCents": 4612500
},
{
"amountCents": 186750
},
{
"amountCents": 39999
}
]
},
{
"name": "Associated Anesthesiologists of the Greater Metropolitan Area, P.C.",
"estimateCents": 640000,
"billedLines": [
{
"amountCents": 702500
},
{
"amountCents": 118289
}
]
},
{
"name": "Lakeshore Pathology and Laboratory Medicine Consultants, LLC",
"billedLines": [
{
"amountCents": 48250
}
]
}
]
}
} {
"patientBill": {
"coverage": "self-pay",
"initialBillDate": "2026-11-02",
"estimate": {
"date": "2026-09-14"
},
"providers": [
{
"name": "Northwestern Lakeshore Regional Medical Center Ambulatory Surgery Department",
"estimateCents": 4850000,
"billedLines": [
{
"amountCents": 4612500
},
{
"amountCents": 186750
},
{
"amountCents": 39999
}
]
},
{
"name": "Associated Anesthesiologists of the Greater Metropolitan Area, P.C.",
"estimateCents": 640000,
"billedLines": [
{
"amountCents": 702500
},
{
"amountCents": 118289
}
]
},
{
"name": "Lakeshore Pathology and Laboratory Medicine Consultants, LLC",
"billedLines": [
{
"amountCents": 48250
}
]
}
]
}
} {
"patientBill": {
"coverage": "insured",
"initialBillDate": "2026-11-02",
"estimate": {
"date": "2026-09-14"
},
"providers": [
{
"name": "Northwestern Lakeshore Regional Medical Center Ambulatory Surgery Department",
"estimateCents": 4850000,
"billedLines": [
{
"amountCents": 4612500
},
{
"amountCents": 186750
},
{
"amountCents": 39999
}
]
},
{
"name": "Associated Anesthesiologists of the Greater Metropolitan Area, P.C.",
"estimateCents": 640000,
"billedLines": [
{
"amountCents": 702500
},
{
"amountCents": 118289
}
]
},
{
"name": "Lakeshore Pathology and Laboratory Medicine Consultants, LLC",
"billedLines": [
{
"amountCents": 48250
}
]
}
]
}
} {
"patientBill": {
"coverage": "federal-program",
"initialBillDate": "2026-11-02",
"estimate": {
"date": "2026-09-14"
},
"providers": [
{
"name": "Northwestern Lakeshore Regional Medical Center Ambulatory Surgery Department",
"estimateCents": 4850000,
"billedLines": [
{
"amountCents": 4612500
},
{
"amountCents": 186750
},
{
"amountCents": 39999
}
]
},
{
"name": "Associated Anesthesiologists of the Greater Metropolitan Area, P.C.",
"estimateCents": 640000,
"billedLines": [
{
"amountCents": 702500
},
{
"amountCents": 118289
}
]
},
{
"name": "Lakeshore Pathology and Laboratory Medicine Consultants, LLC",
"billedLines": [
{
"amountCents": 48250
}
]
}
]
}
} Vista previa renderizada
el componente renderizado por su cuentaNodos resueltos
lo que recibe un renderizador — 1 nodosgfe-comparison section gfe-comparison section Los archivos
lo que escribe la instalación; el archivo seleccionado es el componentenodes/good-faith-estimate-comparison.node.tsx import { Cell, type Nodes, Paragraph, Row, Section, Table, useDeriver, useState } from "docxcelerate/template";
import goodFaithEstimateComparison from "../derivers/good-faith-estimate-comparison.deriver.ts";
/**
* For a bill sent to an uninsured or self-pay patient: each provider or
* facility's bill against its own line on the good faith estimate (GFE), and,
* where one billed at least $400 more, the patient's right to use the No
* Surprises Act patient-provider dispute process.
*
* Decisions already made for you:
*
* - Each provider is compared with its own estimate. The $400 test is never
* applied to the estimate total or the bill total, so one statement can offer
* a dispute for the anesthesiologist and not for the surgeon.
* - Everything billed counts, including items that were not on the estimate.
* - A provider missing from the estimate is compared with $0.
* - "At least $400" is inclusive, and the sums are done in integer cents.
* - Only for uninsured or self-pay patients (self-pay includes an insured
* patient who chose not to bill their plan). Nothing prints for a patient
* billing their plan or enrolled in a federal programme, or when no estimate
* was given.
* - The 120 days run from the date on the initial bill, not the date of service
* or of receipt. The deadline uses date-only arithmetic, so a timezone cannot
* move it by a day.
* - The collections promise prints whenever dispute rights do: the patient
* needs it to dispute safely.
* - A state process replaces the federal one when the state runs its own.
*
* All of it is one deriver, because summing, comparing, counting, joining names,
* date arithmetic and formatting money are all things publishing refuses on
* request data. The node computes nothing; every test is written inline on
* `g.*` so a publish build keeps each arm. The wording is regulated, so no
* prose is generated.
*
* The six provider rows are fixed slots rather than a `.map()`. The resolver
* reads a published loop's collection from request data and ignores the derived
* scope, so a `.map()` over the deriver's rows would publish and then resolve to
* no rows.
*
* The node publishes 12 branches against the default `branchLimit` of 32: the
* section, six rows, three outcomes, and the state or federal contact.
*
* The legal points (a provider missing from the estimate compared with $0, the
* CMS number, 120 days from the bill date) should be checked against
* 45 CFR 149.620 and the current CMS notice before use.
*
* Installed by `dxcl add good-faith-estimate-comparison`.
*/
/** What this component reads. Add these fields to your document data type. */
export interface GoodFaithEstimateComparisonData {
patientBill: {
/**
* How the patient is paying for this care. Required: the deriver throws
* when it is missing or not one of these four, because printing nothing
* for a misspelt value would silently withhold dispute rights.
*
* - `uninsured`: no coverage. Entitled to a GFE.
* - `self-pay`: has coverage but chose not to bill the plan. Entitled to a GFE.
* - `insured`: billing the plan. Prints nothing.
* - `federal-program`: enrolled in Medicare, Medicaid or another federal
* health programme. Not entitled to a GFE. Prints nothing.
*/
coverage: "uninsured" | "self-pay" | "insured" | "federal-program";
/**
* The date printed on the initial bill for this care, ISO 8601
* (`2026-11-19`). Anything after the tenth character is ignored. The
* dispute deadline is this date plus 120 calendar days. Required whenever
* the component would print (eligible coverage, an estimate, at least one
* provider): the deriver throws when it is missing or not YYYY-MM-DD.
* Not read when nothing prints.
*/
initialBillDate: string;
/**
* The good faith estimate the patient was given. Missing means no estimate
* exists, and the component prints nothing.
*/
estimate?: {
/**
* The date on the estimate, ISO 8601. Printed in the intro. Required when
* `estimate` is given: throws when it is missing or not a date.
*/
date: string;
};
/**
* The state's own patient-provider dispute process, given only where the
* state runs one in place of the federal process. Missing means the
* federal process: the CMS contact is printed. When given, both fields
* are required and are printed as given; the deriver throws if either is
* missing or blank.
*/
stateProcess?: {
/** Who runs it, as printed: "the Example State Department of Insurance". */
name: string;
/** How to reach it, as printed: a phone number, a URL, or both. */
contact: string;
};
/**
* One entry per provider or facility billing on this statement, in the
* order they should be printed. At most 6: the deriver throws above 6.
* Missing or empty prints nothing. Two entries with the same name (after
* trimming) throw, because splitting one provider across entries would
* split its comparison.
*/
providers: Array<{
/** The provider's or facility's name, as printed. Required, non-blank. */
name: string;
/**
* The total expected charges for this provider on the GFE, in integer
* cents (125000 is $1,250.00). Missing means this provider was not on
* the estimate: it is compared with $0 and printed as "Not on your
* estimate". Throws when present and not a non-negative integer.
*/
estimateCents?: number;
/**
* Every item this provider billed, whether or not it was on the
* estimate. Each line has its amount in integer cents, net of any
* discount. Other fields on a line are ignored. Required (it may be
* empty, which bills $0): throws when it is missing or not an array, or
* when an `amountCents` is not a non-negative integer.
*/
billedLines: Array<{ amountCents: number }>;
}>;
};
}
/**
* Prints the comparison table and, where a provider billed at least $400 over
* its own estimate, the dispute rights. Prints nothing when the patient is not
* eligible, no estimate was given, or there are no providers.
*/
export const GoodFaithEstimateComparison: Nodes = async () => {
const [bill] = useState((data: GoodFaithEstimateComparisonData) => data.patientBill);
const g = await useDeriver(goodFaithEstimateComparison, [bill]);
return (
<>
{g.outcome !== "none" && (
<Section id="gfe-comparison" title="Your bill and your good faith estimate">
<Paragraph id="gfe-comparison-intro">
This statement compares what each provider and facility billed with the good faith estimate you were given
on {g.estimateDate}. Each is compared with its own estimate, and everything it billed counts, including
items that were not on the estimate.
</Paragraph>
<Table
id="gfe-comparison-table"
columns={[{ width: "auto" }, { width: 30, align: "right" }, { width: 30, align: "right" }, { width: 34, align: "right" }]}
>
<Row id="gfe-comparison-header" header>
<Cell>Provider or facility</Cell>
<Cell>Estimate</Cell>
<Cell>Billed</Cell>
<Cell>Difference</Cell>
</Row>
{g.rows[0].name && (
<Row id="gfe-comparison-provider-1">
<Cell>{g.rows[0].name}</Cell>
<Cell>{g.rows[0].estimate}</Cell>
<Cell>{g.rows[0].billed}</Cell>
<Cell>{g.rows[0].difference}</Cell>
</Row>
)}
{g.rows[1].name && (
<Row id="gfe-comparison-provider-2">
<Cell>{g.rows[1].name}</Cell>
<Cell>{g.rows[1].estimate}</Cell>
<Cell>{g.rows[1].billed}</Cell>
<Cell>{g.rows[1].difference}</Cell>
</Row>
)}
{g.rows[2].name && (
<Row id="gfe-comparison-provider-3">
<Cell>{g.rows[2].name}</Cell>
<Cell>{g.rows[2].estimate}</Cell>
<Cell>{g.rows[2].billed}</Cell>
<Cell>{g.rows[2].difference}</Cell>
</Row>
)}
{g.rows[3].name && (
<Row id="gfe-comparison-provider-4">
<Cell>{g.rows[3].name}</Cell>
<Cell>{g.rows[3].estimate}</Cell>
<Cell>{g.rows[3].billed}</Cell>
<Cell>{g.rows[3].difference}</Cell>
</Row>
)}
{g.rows[4].name && (
<Row id="gfe-comparison-provider-5">
<Cell>{g.rows[4].name}</Cell>
<Cell>{g.rows[4].estimate}</Cell>
<Cell>{g.rows[4].billed}</Cell>
<Cell>{g.rows[4].difference}</Cell>
</Row>
)}
{g.rows[5].name && (
<Row id="gfe-comparison-provider-6">
<Cell>{g.rows[5].name}</Cell>
<Cell>{g.rows[5].estimate}</Cell>
<Cell>{g.rows[5].billed}</Cell>
<Cell>{g.rows[5].difference}</Cell>
</Row>
)}
</Table>
{g.outcome === "within" && (
<Paragraph id="gfe-comparison-within">
Every provider and facility on this statement billed no more than its good faith estimate.
</Paragraph>
)}
{g.outcome === "over" && (
<Paragraph id="gfe-comparison-over">
At least one provider or facility billed more than its good faith estimate, but each by less than $400.
The table shows the difference for each.
</Paragraph>
)}
{g.outcome === "dispute" && (
<Section id="gfe-dispute" title="Your right to dispute this bill">
<Paragraph id="gfe-dispute-eligible">
You can dispute {g.disputeSubject}, because it is at least $400 more than that provider's own good faith
estimate.
</Paragraph>
<Paragraph id="gfe-dispute-deadline">
To dispute, start the process by {g.deadline}. That is 120 calendar days from {g.initialBillDate}, the
date on your initial bill.
</Paragraph>
<Paragraph id="gfe-dispute-collections">
While a dispute is open, the provider or facility it concerns will not send the disputed bill to
collections or threaten to, will pause any collection already started, and will not charge late fees on
the disputed amount.
</Paragraph>
{g.stateName && (
<Paragraph id="gfe-dispute-how-state">
To start a dispute, contact {g.stateName}: {g.stateContact}.
</Paragraph>
)}
{!g.stateName && (
<Paragraph id="gfe-dispute-how-federal">
To start a dispute, contact the Centers for Medicare & Medicaid Services at 1-800-985-3059 or visit
www.cms.gov/nosurprises.
</Paragraph>
)}
</Section>
)}
</Section>
)}
</>
);
}; derivers/good-faith-estimate-comparison.deriver.ts // deno-lint-ignore-file no-explicit-any
import { deriver } from "docxcelerate/template";
/**
* Compares each provider's bill with its own line on a good faith estimate and
* decides what the patient is told. Installed by
* `dxcl add good-faith-estimate-comparison`.
*
* It is self-contained on purpose: it travels to the engine as source text, so
* a module-level constant or helper would be a ReferenceError there. Every
* helper, formatter and the 40000-cent threshold are declared inside `run`.
*/
export default deriver({
name: "goodFaithEstimateComparison",
run: (patientBill: unknown) => {
const bill = patientBill as any;
const emptyRow = () => ({ name: "", estimate: "", billed: "", difference: "" });
const none = () => ({
outcome: "none" as "none" | "within" | "over" | "dispute",
estimateDate: "",
rows: [emptyRow(), emptyRow(), emptyRow(), emptyRow(), emptyRow(), emptyRow()],
disputeSubject: "",
initialBillDate: "",
deadline: "",
stateName: "",
stateContact: "",
});
if (bill === null || typeof bill !== "object") throw new Error("patientBill is required");
const coverage = bill.coverage;
if (coverage !== "uninsured" && coverage !== "self-pay" && coverage !== "insured" && coverage !== "federal-program") {
throw new Error('patientBill.coverage must be "uninsured", "self-pay", "insured" or "federal-program"');
}
if (coverage === "insured" || coverage === "federal-program") return none();
if (bill.estimate === undefined || bill.estimate === null) return none();
if (!Array.isArray(bill.providers) || bill.providers.length === 0) return none();
const isoDay = (value: unknown, field: string): string => {
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}/.test(value)) {
throw new Error(field + " must be an ISO 8601 date");
}
return value.slice(0, 10);
};
const centsOf = (value: unknown, field: string): number => {
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
throw new Error(field + " must be a non-negative integer of cents");
}
return value;
};
const dates = new Intl.DateTimeFormat("en-US", { dateStyle: "long", timeZone: "UTC" });
const fmtDate = (iso: string) => dates.format(new Date(iso + "T00:00:00Z"));
const money = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" });
const fmtMoney = (cents: number) => money.format(cents / 100);
const estimateIso = isoDay(bill.estimate.date, "patientBill.estimate.date");
const billIso = isoDay(bill.initialBillDate, "patientBill.initialBillDate");
if (bill.providers.length > 6) {
throw new Error("patientBill.providers has " + bill.providers.length + " entries; this component prints at most 6");
}
let stateName = "";
let stateContact = "";
if (bill.stateProcess !== undefined && bill.stateProcess !== null) {
const sp = bill.stateProcess;
if (typeof sp.name !== "string" || sp.name.trim() === "") throw new Error("patientBill.stateProcess.name is required");
if (typeof sp.contact !== "string" || sp.contact.trim() === "") {
throw new Error("patientBill.stateProcess.contact is required");
}
stateName = sp.name.trim();
stateContact = sp.contact.trim();
}
const seen = new Set<string>();
const results = bill.providers.map((p: any, i: number) => {
const f = "patientBill.providers[" + i + "]";
if (typeof p?.name !== "string" || p.name.trim() === "") throw new Error(f + ".name is required");
const key = p.name.trim();
if (seen.has(key)) throw new Error(f + ".name is a duplicate of an earlier provider");
seen.add(key);
const onEstimate = p.estimateCents !== undefined && p.estimateCents !== null;
const est = onEstimate ? centsOf(p.estimateCents, f + ".estimateCents") : 0;
if (!Array.isArray(p.billedLines)) throw new Error(f + ".billedLines must be an array");
let billed = 0;
p.billedLines.forEach((l: any, j: number) => {
billed += centsOf(l?.amountCents, f + ".billedLines[" + j + "].amountCents");
});
const diff = billed - est;
return {
name: key,
status: diff >= 40000 ? "dispute" : diff > 0 ? "over" : "within",
row: {
name: p.name.trim(),
estimate: onEstimate ? fmtMoney(est) : "Not on your estimate",
billed: fmtMoney(billed),
difference: diff > 0 ? fmtMoney(diff) + " more" : diff < 0 ? fmtMoney(-diff) + " less" : "No difference",
},
};
});
const disputed = results.filter((r: any) => r.status === "dispute").map((r: any) => r.name as string);
const outcome = disputed.length > 0 ? "dispute" : results.some((r: any) => r.status === "over") ? "over" : "within";
const rows = results.map((r: any) => r.row);
while (rows.length < 6) rows.push(emptyRow());
const deadlineDate = (() => {
const [y, m, d] = billIso.split("-").map(Number);
return new Date(Date.UTC(y, m - 1, d + 120));
})();
return {
outcome: outcome as "none" | "within" | "over" | "dispute",
estimateDate: fmtDate(estimateIso),
rows,
disputeSubject: disputed.length === 0
? ""
: disputed.length === 1
? "the bill from " + disputed[0]
: "the bills from " + new Intl.ListFormat("en-US", { type: "conjunction" }).format(disputed),
initialBillDate: fmtDate(billIso),
deadline: outcome === "dispute" ? dates.format(deadlineDate) : "",
stateName,
stateContact,
};
},
});