code wiki / (root) / nx_medbill_advocacy_gate.nx

nx_medbill_advocacy_gate.nx source

↩ module page · 100 lines · 5909 B

1// nx_medbill_advocacy_gate.nx -- M-ADV GATE: proves (1) charity-care screening reads the CURRENT HHS 2// poverty guidelines from the DATA pack and the pack MATCHES THE BANKED SOURCE bytes (aspe.hhs.gov, 3// fetched sovereignly -- caught a stale-year error at authoring time), with the uniform increment 4// cross-checked against the table's own multi-person rows; (2) FPL percent math is exact integer; 5// (3) the 501(r) request letter carries the load-bearing content; (4) appeal deadline math is exact 6// and LEAP-SAFE; (5) the denial-appeal letter is reason-specific with the computed deadline inline. 7// Exits 0 iff ALL pass. Run from nxc2. license_tier: ORIGINAL 8import "nx_syscalls.nx" 9import "nx_medbill_codes.nx" 10import "nx_medbill_charity.nx" 11import "nx_medbill_appeal.nx" 12 13func g_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 14func g_putn(v: i64) -> i64 { 15 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 16 var m: i64 = v 17 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 18 let d: *u8 = sys_mmap(24) 19 var k: i64 = 0 20 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 21 let r: *u8 = sys_mmap(24) 22 var i: i64 = 0 23 while k > 0 { k = k - 1; r[i] = d[k]; i = i + 1 } 24 sys_write(1, r, i) 25 return 0 26} 27func chk(name: *u8, got: i64, want: i64, st: *i64) -> i64 { 28 if got == want { st[0] = st[0] + 1; g_puts(" PASS " as *u8); g_puts(name); g_puts("\n" as *u8) } 29 else { st[1] = st[1] + 1; g_puts(" FAIL " as *u8); g_puts(name); g_puts(" got=" as *u8); g_putn(got); g_puts(" want=" as *u8); g_putn(want); g_puts("\n" as *u8) } 30 return 0 31} 32 33func main() -> i64 { 34 let st: *i64 = sys_mmap(16) as *i64 35 st[0] = 0 36 st[1] = 0 37 let FPL: *u8 = "knowledge/medbill/fpl.list\x00" as *u8 38 39 // ---- charity: pack math + table cross-checks ---- 40 chk("FPL contiguous 1 person = 15960" as *u8, mbch_fpl(FPL, "contiguous\x00" as *u8, 1), 15960, st) 41 chk("FPL contiguous 4 == table 4-person row 33000 (uniform increment)" as *u8, mbch_fpl(FPL, "contiguous\x00" as *u8, 4), 33000, st) 42 chk("FPL alaska 2 == table row 27050" as *u8, mbch_fpl(FPL, "alaska\x00" as *u8, 2), 27050, st) 43 chk("FPL hawaii 3 == table row 31420" as *u8, mbch_fpl(FPL, "hawaii\x00" as *u8, 3), 31420, st) 44 chk("unknown region -> -1" as *u8, mbch_fpl(FPL, "mars\x00" as *u8, 1), 0 - 1, st) 45 chk("household 0 -> -1" as *u8, mbch_fpl(FPL, "contiguous\x00" as *u8, 0), 0 - 1, st) 46 47 // ---- GROUNDING: the data pack matches the banked official source bytes ---- 48 let cap: i64 = 262144 49 let src: *u8 = sys_mmap(cap) 50 let sn: i64 = mbc_read_all("knowledge/library/swc_mb_fpl.txt\x00" as *u8, src, cap) 51 var g1: i64 = 0 52 if sn > 0 { if mbc_find(src, sn, "15,960\x00" as *u8, 0) >= 0 { g1 = 1 } } 53 chk("banked aspe.hhs.gov page contains 15,960 (pack==source)" as *u8, g1, 1, st) 54 var g2: i64 = 0 55 if sn > 0 { if mbc_find(src, sn, "5,680\x00" as *u8, 0) >= 0 { g2 = 1 } } 56 chk("banked page contains the 5,680 increment" as *u8, g2, 1, st) 57 58 // ---- percent math ---- 59 let fpl4: i64 = mbch_fpl(FPL, "contiguous\x00" as *u8, 4) 60 chk("income 40000 household 4 = 121 percent FPL" as *u8, mbch_pct(40000, fpl4), 121, st) 61 chk("income 66000 household 4 = 200 percent FPL exactly" as *u8, mbch_pct(66000, fpl4), 200, st) 62 63 // ---- charity letter content ---- 64 let letter: *u8 = sys_mmap(16384) 65 mbch_letter(40000, 4, 121, letter) 66 chk("letter cites section 501(r)" as *u8, mbc_contains(letter, "501(r)\x00" as *u8), 1, st) 67 chk("letter requests collection hold (501(r)(6) ECAs)" as *u8, mbc_contains(letter, "extraordinary collection\x00" as *u8), 1, st) 68 chk("letter states the screen: 121 percent" as *u8, mbc_contains(letter, "121 percent\x00" as *u8), 1, st) 69 chk("letter keeps identity as placeholder" as *u8, mbc_contains(letter, "[HOSPITAL NAME]\x00" as *u8), 1, st) 70 71 // ---- appeal: exact leap-safe calendar ---- 72 chk("20250310 + 180d = 20250906" as *u8, mba_add_days(20250310, 180), 20250906, st) 73 chk("20250131 + 30d = 20250302 (Feb non-leap)" as *u8, mba_add_days(20250131, 30), 20250302, st) 74 chk("20241231 + 1d = 20250101 (year roll)" as *u8, mba_add_days(20241231, 1), 20250101, st) 75 chk("20240228 + 1d = 20240229 (LEAP day)" as *u8, mba_add_days(20240228, 1), 20240229, st) 76 chk("20250228 + 1d = 20250301 (non-leap)" as *u8, mba_add_days(20250228, 1), 20250301, st) 77 78 // ---- appeal letter content per reason ---- 79 mba_letter(1, 20250310, letter) 80 chk("r1 cites medical necessity" as *u8, mbc_contains(letter, "medical necessity\x00" as *u8), 1, st) 81 chk("r1 carries the computed deadline 2025-09-06" as *u8, mbc_contains(letter, "2025-09-06\x00" as *u8), 1, st) 82 chk("letter demands claim file + criteria free of charge" as *u8, mbc_contains(letter, "free of charge\x00" as *u8), 1, st) 83 chk("letter escalates to external review" as *u8, mbc_contains(letter, "external review\x00" as *u8), 1, st) 84 mba_letter(3, 20250310, letter) 85 chk("r3 invokes surprise-billing protections" as *u8, mbc_contains(letter, "surprise-billing\x00" as *u8), 1, st) 86 mba_letter(4, 20250310, letter) 87 chk("r4 requests retroactive authorization" as *u8, mbc_contains(letter, "retroactive authorization\x00" as *u8), 1, st) 88 mba_letter(9, 20250310, letter) 89 chk("unknown reason -> generic re-review (no fabricated ground)" as *u8, mbc_contains(letter, "re-review\x00" as *u8), 1, st) 90 chk("unknown reason does NOT claim medical necessity" as *u8, mbc_contains(letter, "medical necessity\x00" as *u8), 0, st) 91 92 g_puts("nx_medbill_advocacy_gate: PASS=" as *u8) 93 g_putn(st[0]) 94 g_puts(" FAIL=" as *u8) 95 g_putn(st[1]) 96 g_puts("\n" as *u8) 97 if st[1] == 0 { g_puts("M-ADV nx_medbill_charity + nx_medbill_appeal: GREEN\n" as *u8); return 0 } 98 g_puts("M-ADV: RED\n" as *u8) 99 return 1 100}