nx_medbill_codes_gate.nx source
↩ module page · 113 lines · 6061 B
1// nx_medbill_codes_gate.nx -- M1 GATE: proves the medical-billing code-pack store decodes REAL codes from
2// REAL banked NLM ClinicalTables responses (knowledge/fetched/mbc_*.raw, fetched sovereignly) and NEVER
3// fabricates: an unknown code is -1 (the liar-kill), a code absent from a response ingests 0, a curated
4// CPT entry carries a visible curated: cite. Hermetic store under /tmp. Exits 0 iff ALL pass.
5// Run: ./_offc/nx_sov_build_run.elf nx_medbill_codes_gate (from nxc2 so knowledge/ paths resolve)
6// license_tier: ORIGINAL
7import "nx_syscalls.nx"
8import "nx_medbill_codes.nx"
9
10func 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 }
11func g_putn(v: i64) -> i64 {
12 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
13 var m: i64 = v
14 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
15 let d: *u8 = sys_mmap(24)
16 var k: i64 = 0
17 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
18 let r: *u8 = sys_mmap(24)
19 var i: i64 = 0
20 while k > 0 { k = k - 1; r[i] = d[k]; i = i + 1 }
21 sys_write(1, r, i)
22 return 0
23}
24func chk(name: *u8, got: i64, want: i64, st: *i64) -> i64 {
25 if got == want { st[0] = st[0] + 1; g_puts(" PASS " as *u8); g_puts(name); g_puts("\n" as *u8) }
26 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) }
27 return 0
28}
29
30func main() -> i64 {
31 let st: *i64 = sys_mmap(16) as *i64
32 st[0] = 0
33 st[1] = 0
34
35 // hermetic per-run prefix /tmp/medbill_<us>-
36 let pfx: *u8 = sys_mmap(64)
37 var pp: i64 = 0
38 let pre: *u8 = "/tmp/medbill_\x00" as *u8
39 while pre[pp] != (0 as u8) { pfx[pp] = pre[pp]; pp = pp + 1 }
40 var m: i64 = sys_now_us()
41 let tmp: *u8 = sys_mmap(32)
42 var kk: i64 = 0
43 while m > 0 { tmp[kk] = (0x30 + (m % 10)) as u8; m = m / 10; kk = kk + 1 }
44 while kk > 0 { kk = kk - 1; pfx[pp] = tmp[kk]; pp = pp + 1 }
45 pfx[pp] = 0x2d as u8
46 pp = pp + 1
47 pfx[pp] = 0 as u8
48
49 let rec: *u8 = sys_mmap(2048)
50 let fld: *u8 = sys_mmap(1024)
51
52 // ---- T1 synthetic round-trip + field extraction ----
53 chk("put synthetic record rc=0" as *u8, mbc_put(pfx, "TEST1\x00" as *u8, "SYS\x00" as *u8, "Hello world descriptor\x00" as *u8, "cite-a\x00" as *u8), 0, st)
54 let l1: i64 = mbc_get(pfx, "TEST1\x00" as *u8, rec, 2048)
55 var t1: i64 = 0
56 if l1 > 0 { t1 = 1 }
57 chk("get returns bytes" as *u8, t1, 1, st)
58 mbc_field(rec, 0, fld, 1024)
59 chk("field 0 == SYS" as *u8, mbc_streq(fld, "SYS\x00" as *u8), 1, st)
60 mbc_field(rec, 1, fld, 1024)
61 chk("field 1 contains Hello" as *u8, mbc_contains(fld, "Hello\x00" as *u8), 1, st)
62 mbc_field(rec, 2, fld, 1024)
63 chk("field 2 == cite-a" as *u8, mbc_streq(fld, "cite-a\x00" as *u8), 1, st)
64
65 // ---- T2 ingest a REAL banked NLM response (ICD-10-CM) ----
66 chk("ingest E11.9 from real NLM raw" as *u8, mbc_ingest_nlm(pfx, "knowledge/fetched/mbc_e11_9.raw\x00" as *u8, "E11.9\x00" as *u8, "ICD10CM\x00" as *u8), 1, st)
67 let l2: i64 = mbc_get(pfx, "E11.9\x00" as *u8, rec, 2048)
68 var t2: i64 = 0
69 if l2 > 0 { t2 = 1 }
70 chk("E11.9 resolves" as *u8, t2, 1, st)
71 mbc_field(rec, 1, fld, 1024)
72 chk("E11.9 descriptor is the OFFICIAL text" as *u8, mbc_contains(fld, "Type 2 diabetes mellitus without complications\x00" as *u8), 1, st)
73 chk("descriptor has a space (not a code echo)" as *u8, mbc_contains(fld, " \x00" as *u8), 1, st)
74 chk("descriptor is not the code itself" as *u8, mbc_streq(fld, "E11.9\x00" as *u8), 0, st)
75 mbc_field(rec, 2, fld, 1024)
76 chk("cite names the banked source" as *u8, mbc_contains(fld, "mbc_e11_9\x00" as *u8), 1, st)
77
78 // ---- T3 liar-kills ----
79 chk("UNKNOWN code returns -1 (never fabricates)" as *u8, mbc_get(pfx, "ZZZ99\x00" as *u8, rec, 2048), 0 - 1, st)
80 chk("code absent from response ingests 0" as *u8, mbc_ingest_nlm(pfx, "knowledge/fetched/mbc_e11_9.raw\x00" as *u8, "Q99.999\x00" as *u8, "ICD10CM\x00" as *u8), 0, st)
81 mbc_get(pfx, "E11.9\x00" as *u8, rec, 2048)
82 mbc_field(rec, 1, fld, 1024)
83 chk("neg-control: E11.9 is NOT hypertension" as *u8, mbc_contains(fld, "hypertension\x00" as *u8), 0, st)
84
85 // ---- T4 idempotent re-ingest (latest-wins, same official text) ----
86 chk("re-ingest E11.9 rc=1" as *u8, mbc_ingest_nlm(pfx, "knowledge/fetched/mbc_e11_9.raw\x00" as *u8, "E11.9\x00" as *u8, "ICD10CM\x00" as *u8), 1, st)
87 mbc_get(pfx, "E11.9\x00" as *u8, rec, 2048)
88 mbc_field(rec, 1, fld, 1024)
89 chk("re-ingested descriptor unchanged" as *u8, mbc_contains(fld, "Type 2 diabetes mellitus without complications\x00" as *u8), 1, st)
90
91 // ---- T5 HCPCS Level II from real banked response ----
92 chk("ingest J9271 (HCPCS) rc=1" as *u8, mbc_ingest_nlm(pfx, "knowledge/fetched/mbc_j9271.raw\x00" as *u8, "J9271\x00" as *u8, "HCPCS\x00" as *u8), 1, st)
93 mbc_get(pfx, "J9271\x00" as *u8, rec, 2048)
94 mbc_field(rec, 1, fld, 1024)
95 chk("J9271 descriptor mentions pembrolizumab" as *u8, mbc_contains(fld, "pembrolizumab\x00" as *u8), 1, st)
96
97 // ---- T6 curated CPT entry with visible provenance ----
98 chk("curated 96413 put rc=0" as *u8, mbc_put(pfx, "96413\x00" as *u8, "CPT\x00" as *u8, "Chemotherapy administration, intravenous infusion technique, up to 1 hour, single or initial substance or drug\x00" as *u8, "curated:fin-r5-gate\x00" as *u8), 0, st)
99 mbc_get(pfx, "96413\x00" as *u8, rec, 2048)
100 mbc_field(rec, 1, fld, 1024)
101 chk("96413 decodes to chemotherapy administration" as *u8, mbc_contains(fld, "Chemotherapy administration\x00" as *u8), 1, st)
102 mbc_field(rec, 2, fld, 1024)
103 chk("curated provenance visible in cite" as *u8, mbc_contains(fld, "curated\x00" as *u8), 1, st)
104
105 g_puts("nx_medbill_codes_gate: PASS=" as *u8)
106 g_putn(st[0])
107 g_puts(" FAIL=" as *u8)
108 g_putn(st[1])
109 g_puts("\n" as *u8)
110 if st[1] == 0 { g_puts("M1 nx_medbill_codes: GREEN\n" as *u8); return 0 }
111 g_puts("M1 nx_medbill_codes: RED\n" as *u8)
112 return 1
113}