code wiki / (root) / nx_medbill_charity.nx

nx_medbill_charity.nx source

↩ module page · 112 lines · 6001 B

1// nx_medbill_charity.nx -- M-ADV1 of the MEDICAL BILLING & PATIENT ADVOCACY ladder: CHARITY-CARE / 2// FINANCIAL-ASSISTANCE screening + request letter. Tax-exempt hospitals MUST maintain a written 3// Financial Assistance Policy under IRC section 501(r); most FAPs key eligibility to a percentage of 4// the HHS poverty guidelines. This organ screens a household against the CURRENT guidelines (a DATA 5// pack, knowledge/medbill/fpl.list, grounded against the sovereignly-banked aspe.hhs.gov page -- the 6// gate proves pack==source) and renders a FAP application-request letter. FAIL-SAFE: letter goes to a 7// caller buffer only, placeholders keep the patient's identity out of the tool, nothing is ever sent. 8// Thresholds (200/300/400 percent FPL) vary PER HOSPITAL -> the threshold is the caller's data, never 9// hardcoded (#6/#11). Integer math only. license_tier: ORIGINAL 10import "nx_syscalls.nx" 11import "nx_medbill_codes.nx" 12 13// parse the fpl.list pack: first non-comment row whose region matches -> annual FPL dollars for the 14// household size (base + addl*(n-1)). -1 if region absent or household < 1. 15func mbch_fpl(listpath: *u8, region: *u8, household: i64) -> i64 { 16 if household < 1 { return 0 - 1 } 17 let cap: i64 = 65536 18 let buf: *u8 = sys_mmap(cap) 19 let n: i64 = mbc_read_all(listpath, buf, cap) 20 if n <= 0 { return 0 - 1 } 21 var i: i64 = 0 22 while i < n { 23 var e: i64 = i 24 var stop: i64 = 0 25 while stop == 0 { 26 if e >= n { stop = 1 } else { if buf[e] == (10 as u8) { stop = 1 } else { e = e + 1 } } 27 } 28 if e - i > 4 { if buf[i] != (35 as u8) { 29 // fields: year|region|base|addl 30 var f: i64 = 0 31 var p: i64 = i 32 var rs: i64 = 0 - 1 33 var re: i64 = 0 - 1 34 var base: i64 = 0 35 var addl: i64 = 0 36 while p <= e { 37 var c: i64 = 0 38 if p < e { c = buf[p] as i64 } 39 if p == e { c = 124 } 40 if c == 124 { 41 f = f + 1 42 } else { 43 if f == 1 { if rs < 0 { rs = p } re = p + 1 } 44 if mbr10(c) == 1 { 45 if f == 2 { base = base * 10 + (c - 48) } 46 if f == 3 { addl = addl * 10 + (c - 48) } 47 } 48 } 49 p = p + 1 50 } 51 if rs >= 0 { if base > 0 { 52 // region match: compare buf[rs..re) to NUL-terminated region 53 var ok: i64 = 1 54 var k: i64 = 0 55 var q: i64 = rs 56 while q < re { if region[k] == (0 as u8) { ok = 0; q = re } else { if buf[q] != region[k] { ok = 0; q = re } else { q = q + 1; k = k + 1 } } } 57 if ok == 1 { if region[k] != (0 as u8) { ok = 0 } } 58 if ok == 1 { return base + addl * (household - 1) } 59 } } 60 } } 61 i = e + 1 62 } 63 return 0 - 1 64} 65func mbr10(c: i64) -> i64 { if c >= 48 { if c <= 57 { return 1 } } return 0 } 66 67// income as a percent of FPL (integer floor). -1 on bad fpl. 68func mbch_pct(income: i64, fpl: i64) -> i64 { 69 if fpl <= 0 { return 0 - 1 } 70 if income < 0 { return 0 - 1 } 71 return (income * 100) / fpl 72} 73 74func mbch_cat(out: *u8, off: i64, s: *u8) -> i64 { 75 var o: i64 = off 76 var i: i64 = 0 77 while s[i] != (0 as u8) { out[o] = s[i]; o = o + 1; i = i + 1 } 78 return o 79} 80func mbch_n(out: *u8, off: i64, v0: i64) -> i64 { 81 if v0 == 0 { out[off] = 48 as u8; return off + 1 } 82 var v: i64 = v0 83 var o: i64 = off 84 if v < 0 { out[o] = 45 as u8; o = o + 1; v = 0 - v } 85 let t: *u8 = sys_mmap(24) 86 var k: i64 = 0 87 while v > 0 { t[k] = (48 + (v % 10)) as u8; v = v / 10; k = k + 1 } 88 while k > 0 { k = k - 1; out[o] = t[k]; o = o + 1 } 89 return o 90} 91 92// Render the Financial Assistance (charity care) request letter. screen numbers are printed so the 93// hospital sees the eligibility picture immediately; placeholders keep identity out of the tool. 94func mbch_letter(income: i64, household: i64, pct: i64, out: *u8) -> i64 { 95 var o: i64 = 0 96 o = mbch_cat(out, o, "To: [HOSPITAL NAME] Financial Assistance Office / Billing Department\n" as *u8) 97 o = mbch_cat(out, o, "Re: Account [ACCOUNT NUMBER] - Patient [PATIENT NAME]\n" as *u8) 98 o = mbch_cat(out, o, "Subject: Request for Financial Assistance (charity care) application and account hold\n\n" as *u8) 99 o = mbch_cat(out, o, "I am requesting a copy of your Financial Assistance Policy, its plain-language summary, and an application form. Tax-exempt hospitals are required to maintain and widely publicize a written financial assistance policy under Internal Revenue Code section 501(r).\n\n" as *u8) 100 o = mbch_cat(out, o, "My household income is approximately $" as *u8) 101 o = mbch_n(out, o, income) 102 o = mbch_cat(out, o, " per year for a household of " as *u8) 103 o = mbch_n(out, o, household) 104 o = mbch_cat(out, o, ", which is approximately " as *u8) 105 o = mbch_n(out, o, pct) 106 o = mbch_cat(out, o, " percent of the current HHS poverty guideline. Many hospital financial assistance policies provide free or discounted care at this income level, and I believe I may qualify under your policy.\n\n" as *u8) 107 o = mbch_cat(out, o, "While my application is pending, please place this account on hold: section 501(r)(6) restricts extraordinary collection actions while a financial assistance application is being processed. Please also send an itemized statement of all charges, and let me know whether your policy provides presumptive eligibility screening.\n\n" as *u8) 108 o = mbch_cat(out, o, "If this facility is not a tax-exempt hospital or no financial assistance policy applies, please advise what self-pay discount, hardship, or payment-plan programs are available.\n\n" as *u8) 109 o = mbch_cat(out, o, "Please respond in writing to the address on file.\n\nSincerely,\n[PATIENT NAME]\n" as *u8) 110 out[o] = 0 as u8 111 return o 112}