code wiki / (root) / nx_fin_dispute.nx

nx_fin_dispute.nx source

↩ module page · 95 lines · 6255 B

1// nx_fin_dispute.nx -- R8 (fail-safe execute) of THE NISHI FINANCIAL ECOSYSTEM: turn audit findings into 2// a filled, ready-to-send MEDICAL-BILL DISPUTE LETTER. This is the "executing -> reducing costs" verb for 3// the operator's cancer-billing crisis: the engine renders the artifact, the OPERATOR reviews and sends it. 4// 5// NEVER-BRICK / FAIL-SAFE BY CONSTRUCTION (#26): disp_build writes ONLY into a caller buffer -- it has no 6// socket, no file send, no transmit. It can NEVER auto-send a dispute, mail a letter, or take an 7// irreversible action. It produces text; a human decides what to do with it. Amounts are exact no-float 8// cents (nx_money). Reasons are cited to standard billing-integrity grounds (duplicate / NCCI unbundling / 9// Medically Unlikely Edits / reasonable-charge benchmark) + FDCPA dispute + No Surprises Act, grounded on 10// the fetched corpus (fin_r3_no_surprises_act, fin_r6_fdcpa, fin_r10_cpt/medicare). PRIVACY: patient/ 11// provider/account are caller-supplied (operator's specifics stay LOCAL; never enter web queries). 12// reason codes: 1=duplicate, 2=unbundling, 3=MUE over-units, 4=fair-price. license_tier: ORIGINAL 13import "nx_syscalls.nx" 14import "nx_money.nx" 15const K_MAGIC_10000: i64 = 10000 16 17func d_cat(out: *u8, off: i64, s: *u8) -> i64 { 18 var o: i64 = off; var i: i64 = 0 19 while s[i] != (0 as u8) { out[o] = s[i]; o = o + 1; i = i + 1 } 20 return o 21} 22func d_n(out: *u8, off: i64, v: i64) -> i64 { 23 if v == 0 { out[off] = 0x30 as u8; return off + 1 } 24 let tmp: *u8 = sys_mmap(24); var m: i64 = v; var k: i64 = 0 25 while m > 0 { tmp[k] = (0x30 + (m % 10)) as u8; m = m / 10; k = k + 1 } 26 var o: i64 = off; var i: i64 = k - 1 27 while i >= 0 { out[o] = tmp[i]; o = o + 1; i = i - 1 } 28 return o 29} 30func d_n2(out: *u8, off: i64, v: i64) -> i64 { 31 out[off] = (0x30 + ((v / 10) % 10)) as u8 32 out[off + 1] = (0x30 + (v % 10)) as u8 33 return off + 2 34} 35func d_money(out: *u8, off: i64, cents: i64) -> i64 { 36 var o: i64 = off; var c: i64 = cents 37 if c < 0 { out[o] = 0x2d as u8; o = o + 1; c = 0 - c } 38 out[o] = 0x24 as u8; o = o + 1 39 let dollars: i64 = c / 100 40 let cc: i64 = c - dollars * 100 41 o = d_n(out, o, dollars) 42 out[o] = 0x2e as u8; o = o + 1 43 o = d_n2(out, o, cc) 44 return o 45} 46// YYYYMMDD integer -> "YYYY-MM-DD" 47func d_date(out: *u8, off: i64, ymd: i64) -> i64 { 48 let y: i64 = ymd / K_MAGIC_10000 49 let m: i64 = (ymd / 100) % 100 50 let dd: i64 = ymd % 100 51 var o: i64 = d_n(out, off, y) 52 out[o] = 0x2d as u8; o = o + 1 53 o = d_n2(out, o, m) 54 out[o] = 0x2d as u8; o = o + 1 55 o = d_n2(out, o, dd) 56 return o 57} 58func d_reason(out: *u8, off: i64, code: i64) -> i64 { 59 if code == 1 { return d_cat(out, off, "this charge appears to duplicate an identical charge for the same service on the same date\x00" as *u8) } 60 if code == 2 { return d_cat(out, off, "this is a component service that NCCI edits bundle into the primary procedure and should not be billed separately\x00" as *u8) } 61 if code == 3 { return d_cat(out, off, "the units billed exceed the Medically Unlikely Edit maximum for this code\x00" as *u8) } 62 if code == 4 { return d_cat(out, off, "this charge substantially exceeds a reasonable benchmark (a multiple of the Medicare allowed amount)\x00" as *u8) } 63 if code == 5 { return d_cat(out, off, "this charge exceeds the plan allowed amount shown on the Explanation of Benefits for this service\x00" as *u8) } 64 if code == 6 { return d_cat(out, off, "this charge does not appear on the Explanation of Benefits for this date of service; please provide the corresponding claim adjudication or remove the charge\x00" as *u8) } 65 return d_cat(out, off, "this charge appears to be billed in error\x00" as *u8) 66} 67 68// Render a complete dispute letter into out (caller buffer >= ~8 KiB). Parallel finding arrays: 69// reasons[k] (1..4), cpts[k] (CPT code), fdates[k] (YYYYMMDD), amounts[k] (requested adjustment cents). 70// Returns the letter length. The TOTAL requested adjustment is the sum of amounts[] (the caller is 71// responsible for passing a non-overlapping finding set so the total does not double-count a line). 72func disp_build(patient: *u8, provider: *u8, account: *u8, reasons: *i64, cpts: *i64, fdates: *i64, amounts: *i64, nf: i64, out: *u8) -> i64 { 73 var o: i64 = 0 74 o = d_cat(out, o, "To: "); o = d_cat(out, o, provider); o = d_cat(out, o, " Billing Department\n" as *u8) 75 o = d_cat(out, o, "Re: Account "); o = d_cat(out, o, account); o = d_cat(out, o, " - Patient "); o = d_cat(out, o, patient); o = d_cat(out, o, "\n" as *u8) 76 o = d_cat(out, o, "Subject: Formal request for itemized billing review and correction\n\n" as *u8) 77 o = d_cat(out, o, "I am writing to formally dispute specific charges on the above account and to request an itemized review and correction. This is a good-faith dispute, not a refusal to pay legitimate charges. After a line-by-line review, the following charges appear to be billed in error:\n\n" as *u8) 78 var total: i64 = 0 79 var k: i64 = 0 80 while k < nf { 81 o = d_cat(out, o, " - CPT "); o = d_n(out, o, cpts[k]) 82 o = d_cat(out, o, ", date of service "); o = d_date(out, o, fdates[k]) 83 o = d_cat(out, o, ": requested adjustment "); o = d_money(out, o, amounts[k]) 84 o = d_cat(out, o, " - "); o = d_reason(out, o, reasons[k]) 85 o = d_cat(out, o, ".\n" as *u8) 86 total = mny_add(total, amounts[k]) 87 k = k + 1 88 } 89 o = d_cat(out, o, "\nTotal requested adjustment: "); o = d_money(out, o, total); o = d_cat(out, o, ".\n\n" as *u8) 90 o = d_cat(out, o, "Under the No Surprises Act and standard billing-integrity rules (NCCI bundling edits, Medically Unlikely Edits, and reasonable-charge benchmarks), I request a corrected itemized statement within 30 days. Please treat this as a disputed debt under the Fair Debt Collection Practices Act: do not report the disputed amount to consumer reporting agencies or pursue collection while this review is pending.\n\n" as *u8) 91 o = d_cat(out, o, "Please send the corrected statement and your itemized response to the address on file.\n\nSincerely,\n" as *u8) 92 o = d_cat(out, o, patient); o = d_cat(out, o, "\n" as *u8) 93 out[o] = 0 as u8 94 return o 95}