nx_medbill_nsa_gate.nx source
↩ module page · 87 lines · 4883 B
1// nx_medbill_nsa_gate.nx -- ADV3 GATE: the situation classifier routes to the CORRECT federal
2// protection (truth table incl precedence: emergency wins; PPDR is uninsured-only and threshold-gated),
3// the PPDR 120-day window is computed exactly off the shared leap-safe calendar, and each route's
4// letter carries its load-bearing content. Neg-controls: an INSURED patient can never route to PPDR;
5// below-threshold overage never routes to PPDR; route 4 fabricates no protection. Exits 0 iff ALL pass.
6// license_tier: ORIGINAL
7import "nx_syscalls.nx"
8import "nx_medbill_codes.nx"
9import "nx_medbill_nsa.nx"
10
11func 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 }
12func g_putn(v: i64) -> i64 {
13 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
14 var m: i64 = v
15 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
16 let d: *u8 = sys_mmap(24)
17 var k: i64 = 0
18 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
19 let r: *u8 = sys_mmap(24)
20 var i: i64 = 0
21 while k > 0 { k = k - 1; r[i] = d[k]; i = i + 1 }
22 sys_write(1, r, i)
23 return 0
24}
25func chk(name: *u8, got: i64, want: i64, st: *i64) -> i64 {
26 if got == want { st[0] = st[0] + 1; g_puts(" PASS " as *u8); g_puts(name); g_puts("\n" as *u8) }
27 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) }
28 return 0
29}
30// flags helper: [emergency, oon, in_net_fac, insured, has_gfe]
31func fl(a: i64, b: i64, c: i64, d: i64, e: i64) -> *i64 {
32 let f: *i64 = sys_mmap(8 * 8) as *i64
33 f[0] = a
34 f[1] = b
35 f[2] = c
36 f[3] = d
37 f[4] = e
38 return f
39}
40
41func main() -> i64 {
42 let st: *i64 = sys_mmap(16) as *i64
43 st[0] = 0
44 st[1] = 0
45 let T: i64 = 40000
46
47 // ---- classification truth table ----
48 chk("insured emergency OON -> route 1" as *u8, nsa_classify(fl(1,1,0,1,0), 0, T), 1, st)
49 chk("emergency wins even at OON facility" as *u8, nsa_classify(fl(1,1,1,1,0), 0, T), 1, st)
50 chk("insured non-emergency OON at in-network facility -> route 2" as *u8, nsa_classify(fl(0,1,1,1,0), 0, T), 2, st)
51 chk("uninsured + GFE + overage 50000 >= 40000 -> route 3 PPDR" as *u8, nsa_classify(fl(0,0,0,0,1), 50000, T), 3, st)
52 chk("overage 39999 below threshold -> route 4" as *u8, nsa_classify(fl(0,0,0,0,1), 39999, T), 4, st)
53 chk("insured in-network non-emergency -> route 4" as *u8, nsa_classify(fl(0,0,0,1,0), 0, T), 4, st)
54 chk("uninsured WITHOUT GFE -> route 4 (no PPDR without an estimate)" as *u8, nsa_classify(fl(0,1,1,0,0), 999999, T), 4, st)
55 chk("NEG: INSURED patient never routes to PPDR" as *u8, nsa_classify(fl(0,0,0,1,1), 999999, T), 4, st)
56 chk("insured OON but OON facility (no NSA facility shield) -> route 4" as *u8, nsa_classify(fl(0,1,0,1,0), 0, T), 4, st)
57
58 // ---- PPDR window: shared leap-safe calendar ----
59 chk("PPDR window 20250310 + 120d = 20250708" as *u8, mba_add_days(20250310, 120), 20250708, st)
60
61 // ---- letters carry the load-bearing content ----
62 let letter: *u8 = sys_mmap(16384)
63 nsa_letter(1, 0, 20250310, letter)
64 chk("r1 cites the No Surprises Act" as *u8, mbc_contains(letter, "No Surprises Act\x00" as *u8), 1, st)
65 chk("r1 demands in-network cost sharing" as *u8, mbc_contains(letter, "in-network cost sharing\x00" as *u8), 1, st)
66 chk("r1 says balance billing prohibited" as *u8, mbc_contains(letter, "prohibited\x00" as *u8), 1, st)
67 nsa_letter(2, 0, 20250310, letter)
68 chk("r2 names the in-network facility protection" as *u8, mbc_contains(letter, "IN-NETWORK facility\x00" as *u8), 1, st)
69 chk("r2 addresses notice-and-consent waiver" as *u8, mbc_contains(letter, "notice-and-consent\x00" as *u8), 1, st)
70 nsa_letter(3, 50000, 20250310, letter)
71 chk("r3 names the PPDR process" as *u8, mbc_contains(letter, "Patient-Provider Dispute Resolution\x00" as *u8), 1, st)
72 chk("r3 states the exact overage $500.00" as *u8, mbc_contains(letter, "$500.00\x00" as *u8), 1, st)
73 chk("r3 carries the computed window 2025-07-08" as *u8, mbc_contains(letter, "2025-07-08\x00" as *u8), 1, st)
74 chk("r3 asks to pause collection" as *u8, mbc_contains(letter, "pause collection\x00" as *u8), 1, st)
75 nsa_letter(4, 0, 20250310, letter)
76 chk("r4 fabricates NO protection (points to standard path)" as *u8, mbc_contains(letter, "No situation-specific federal shield\x00" as *u8), 1, st)
77 chk("r4 does not mention the No Surprises Act" as *u8, mbc_contains(letter, "No Surprises Act\x00" as *u8), 0, st)
78
79 g_puts("nx_medbill_nsa_gate: PASS=" as *u8)
80 g_putn(st[0])
81 g_puts(" FAIL=" as *u8)
82 g_putn(st[1])
83 g_puts("\n" as *u8)
84 if st[1] == 0 { g_puts("ADV3 nx_medbill_nsa: GREEN\n" as *u8); return 0 }
85 g_puts("ADV3 nx_medbill_nsa: RED\n" as *u8)
86 return 1
87}