nx_climbout_docs_gate.nx source
↩ module page · 50 lines · 2864 B
1// nx_climbout_docs_gate.nx -- R5c GATE: proves a real bill DOCUMENT flows into the climb-out plan. A bill's
2// TEXT (what the scanner/browser produces) -> nx_doc_extract -> 5 structured line-items -> nx_fin_audit ->
3// the recover figure ($2,650), matching the pre-structured path. Exits 0 iff ALL pass. license_tier: ORIGINAL
4import "nx_syscalls.nx"
5import "nx_money.nx"
6import "nx_climbout_docs.nx"
7
8func 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 }
9func g_putn(v: i64) -> i64 {
10 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
11 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
12 let d: *u8 = sys_mmap(24); var k: i64 = 0
13 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
14 var j: i64 = k - 1
15 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 }
16 return 0
17}
18func chk(name: *u8, got: i64, want: i64, st: *i64) -> i64 {
19 if got == want { st[0] = st[0] + 1; g_puts(" PASS "); g_puts(name); g_puts("\n") }
20 else { st[1] = st[1] + 1; g_puts(" FAIL "); g_puts(name); g_puts(" got="); g_putn(got); g_puts(" want="); g_putn(want); g_puts("\n") }
21 return 0
22}
23
24func main() -> i64 {
25 let st: *i64 = sys_mmap(16) as *i64
26 st[0] = 0; st[1] = 0
27
28 // a real itemized medical-bill DOCUMENT (the text a scanner/browser produces)
29 let bill: *u8 = "MEMORIAL HOSPITAL - ITEMIZED STATEMENT\nPatient: Jane Doe Account ACCT-12345\n\nDate Code Qty Description Amount\n03/10/2025 99214 1 Office visit established $400.00\n03/10/2025 96413 1 Chemotherapy IV infusion $2,000.00\n03/10/2025 96413 1 Chemotherapy IV infusion $2,000.00\n03/10/2025 36415 1 Routine venipuncture $150.00\n03/10/2025 85025 8 Complete blood count CBC $800.00\n\nTOTAL DUE: $5,350.00\n" as *u8
30 var bn: i64 = 0
31 while bill[bn] != (0 as u8) { bn = bn + 1 }
32
33 // packs (data)
34 let pairA: *i64 = sys_mmap(8 * 2) as *i64; let pairB: *i64 = sys_mmap(8 * 2) as *i64
35 pairA[0] = 96413; pairB[0] = 36415
36 let mcode: *i64 = sys_mmap(8 * 2) as *i64; let mmax: *i64 = sys_mmap(8 * 2) as *i64
37 mcode[0] = 85025; mmax[0] = 3
38
39 let cnt: *i64 = sys_mmap(16) as *i64
40 let recover: i64 = cor_recover_from_bill(bill, bn, pairA, pairB, 1, mcode, mmax, 1, cnt)
41 g_puts(" [info] extracted "); g_putn(cnt[0]); g_puts(" line-items, recover="); g_putn(recover); g_puts("c\n")
42
43 chk("bill document -> 5 line-items extracted", cnt[0], 5, st)
44 chk("document -> audit -> recover = 265000 ($2,650)", recover, 265000, st)
45
46 g_puts("nx_climbout_docs_gate: PASS="); g_putn(st[0]); g_puts(" FAIL="); g_putn(st[1]); g_puts("\n")
47 if st[1] == 0 { g_puts("SITUATION R5c nx_climbout_docs: GREEN\n"); return 0 }
48 g_puts("SITUATION R5c nx_climbout_docs: RED\n")
49 return 1
50}