nx_medbill_civic.nx source
↩ module page · 222 lines · 11517 B
1// nx_medbill_civic.nx -- ADV5 of the MEDICAL BILLING & PATIENT ADVOCACY ladder: CIVIC ESCALATION with
2// MEASURED ACCOUNTABILITY. When the direct tools (dispute/appeal/charity/NSA) hit a wall, the patient
3// can CHOOSE to escalate to the oversight body that owns the problem. This organ (1) routes an issue to
4// its channel, (2) renders the complaint/pattern letter, (3) keeps an additive CASE LEDGER of what the
5// user actually sent, and (4) computes a per-channel ACCOUNTABILITY SCORECARD -- responded/resolved/
6// OVERDUE against each channel's expected-response window -- so "are they moving to fix this" is a
7// MEASURED verdict, never an assertion. STRICTLY OPT-IN + FAIL-SAFE: letters are placeholder text in a
8// caller buffer, the ledger records only what the user says they sent, nothing is ever transmitted.
9// NEUTRALITY: letters state facts and request action/answers; they push no narrative and no party.
10// Issues: 1=insurer claim-handling/denial misconduct -> DOI · 2=surprise-billing protection violation ->
11// CMS-NSA · 3=charity-care/501(r) obligations not honored -> IRS 13909 · 4=abusive collection or credit
12// reporting on disputed debt -> CFPB · 5=suspected billing fraud (duplicates/unbundling/upcoding) ->
13// HHS-OIG · 6=systemic-reform story to an elected representative -> REP. Channels + expected-response
14// windows are DATA (knowledge/medbill/civic_channels.list, #11). Case records live on the sovereign
15// seg-store (additive, latest-wins; segid=now_us). Deadlines reuse the shared leap-safe calendar (DRY).
16// license_tier: ORIGINAL
17import "nx_syscalls.nx"
18import "nx_seg_store.nx"
19import "nx_medbill_codes.nx"
20import "nx_medbill_appeal.nx"
21
22// issue -> channel (1=doi 2=cmsnsa 3=ag 4=irs 5=cfpb 6=oig 7=rep); -1 = unknown (never guesses)
23func cv_route(issue: i64) -> i64 {
24 if issue == 1 { return 1 }
25 if issue == 2 { return 2 }
26 if issue == 3 { return 4 }
27 if issue == 4 { return 5 }
28 if issue == 5 { return 6 }
29 if issue == 6 { return 7 }
30 return 0 - 1
31}
32
33// expected-response days for a channel, from the DATA pack; -1 if absent.
34func cv_expect(listpath: *u8, channel: i64) -> i64 {
35 let cap: i64 = 65536
36 let buf: *u8 = sys_mmap(cap)
37 let n: i64 = mbc_read_all(listpath, buf, cap)
38 if n <= 0 { return 0 - 1 }
39 var i: i64 = 0
40 while i < n {
41 var e: i64 = i
42 var stop: i64 = 0
43 while stop == 0 { if e >= n { stop = 1 } else { if buf[e] == (10 as u8) { stop = 1 } else { e = e + 1 } } }
44 if e - i > 4 { if buf[i] != (35 as u8) {
45 var f: i64 = 0
46 var ch: i64 = 0
47 var days: i64 = 0
48 var p: i64 = i
49 while p < e {
50 let c: i64 = buf[p] as i64
51 if c == 124 { f = f + 1 } else {
52 if c >= 48 { if c <= 57 {
53 if f == 0 { ch = ch * 10 + (c - 48) }
54 if f == 3 { days = days * 10 + (c - 48) }
55 } }
56 }
57 p = p + 1
58 }
59 if ch == channel { return days }
60 } }
61 i = e + 1
62 }
63 return 0 - 1
64}
65
66// -------- case ledger (seg-store; record = issue|channel|sent_ymd|status|status_ymd) --------
67// statuses: 1=SENT 2=ACKNOWLEDGED 3=RESPONDED 4=RESOLVED 5=NO-ACTION
68func cv_key(id: *u8, out: *u8) -> i64 {
69 var o: i64 = 0
70 o = mbc_app(out, o, "civic:case:\x00" as *u8)
71 o = mbc_app(out, o, id)
72 out[o] = 0 as u8
73 return o
74}
75func cv_w(prefix: *u8, id: *u8, rec: *u8) -> i64 {
76 let key: *u8 = sys_mmap(256)
77 cv_key(id, key)
78 let w: *i64 = ss_begin()
79 let l: i64 = mbc_slen(rec)
80 if ss_add(w, 1, key, rec, l + 1) != 0 { return 0 - 10 }
81 if ss_commit(prefix, w, sys_now_us()) != 0 { return 0 - 11 }
82 return 0
83}
84func cv_get(prefix: *u8, id: *u8, out: *u8, cap: i64) -> i64 {
85 let key: *u8 = sys_mmap(256)
86 cv_key(id, key)
87 let h: *i64 = ss_open(prefix)
88 if (h as i64) == 0 { return 0 - 1 }
89 let pp: *i64 = sys_mmap(16) as *i64
90 let ll: *i64 = sys_mmap(16) as *i64
91 if ss_hget(h, key, pp, ll) != 1 { return 0 - 1 }
92 let b: *u8 = pp[0] as *u8
93 var n: i64 = ll[0]
94 if n > cap - 1 { n = cap - 1 }
95 var i: i64 = 0
96 while i < n { out[i] = b[i]; i = i + 1 }
97 out[n] = 0 as u8
98 return n
99}
100func cv_num(out: *u8, off: i64, v0: i64) -> i64 {
101 if v0 == 0 { out[off] = 48 as u8; return off + 1 }
102 var v: i64 = v0
103 var o: i64 = off
104 let t: *u8 = sys_mmap(24)
105 var k: i64 = 0
106 while v > 0 { t[k] = (48 + (v % 10)) as u8; v = v / 10; k = k + 1 }
107 while k > 0 { k = k - 1; out[o] = t[k]; o = o + 1 }
108 return o
109}
110// open a case: routes the issue, stamps SENT. -1 bad issue, else 0/neg store rc.
111func cv_case_open(prefix: *u8, id: *u8, issue: i64, sent_ymd: i64) -> i64 {
112 let ch: i64 = cv_route(issue)
113 if ch < 0 { return 0 - 1 }
114 let rec: *u8 = sys_mmap(256)
115 var o: i64 = 0
116 o = cv_num(rec, o, issue)
117 rec[o] = 124 as u8
118 o = o + 1
119 o = cv_num(rec, o, ch)
120 rec[o] = 124 as u8
121 o = o + 1
122 o = cv_num(rec, o, sent_ymd)
123 rec[o] = 124 as u8
124 o = o + 1
125 o = cv_num(rec, o, 1)
126 rec[o] = 124 as u8
127 o = o + 1
128 o = cv_num(rec, o, sent_ymd)
129 rec[o] = 0 as u8
130 return cv_w(prefix, id, rec)
131}
132// pipe-field i64 at idx from a record
133func cv_f(rec: *u8, idx: i64) -> i64 {
134 var i: i64 = 0
135 var f: i64 = 0
136 while f < idx {
137 while rec[i] != (124 as u8) { if rec[i] == (0 as u8) { return 0 - 1 } i = i + 1 }
138 i = i + 1
139 f = f + 1
140 }
141 var v: i64 = 0
142 var any: i64 = 0
143 while rec[i] != (124 as u8) {
144 if rec[i] == (0 as u8) { if any == 1 { return v } return 0 - 1 }
145 let c: i64 = rec[i] as i64
146 if c >= 48 { if c <= 57 { v = v * 10 + (c - 48); any = 1 } }
147 i = i + 1
148 }
149 if any == 1 { return v }
150 return 0 - 1
151}
152// update status (latest-wins rewrite, history preserved in segs). -1 unknown case.
153func cv_case_set(prefix: *u8, id: *u8, status: i64, ymd: i64) -> i64 {
154 let old: *u8 = sys_mmap(512)
155 if cv_get(prefix, id, old, 512) < 0 { return 0 - 1 }
156 let rec: *u8 = sys_mmap(256)
157 var o: i64 = 0
158 o = cv_num(rec, o, cv_f(old, 0))
159 rec[o] = 124 as u8
160 o = o + 1
161 o = cv_num(rec, o, cv_f(old, 1))
162 rec[o] = 124 as u8
163 o = o + 1
164 o = cv_num(rec, o, cv_f(old, 2))
165 rec[o] = 124 as u8
166 o = o + 1
167 o = cv_num(rec, o, status)
168 rec[o] = 124 as u8
169 o = o + 1
170 o = cv_num(rec, o, ymd)
171 rec[o] = 0 as u8
172 return cv_w(prefix, id, rec)
173}
174// follow-up date = sent + channel expectation (shared leap-safe calendar)
175func cv_followup(sent_ymd: i64, expect_days: i64) -> i64 { return mba_add_days(sent_ymd, expect_days) }
176
177// per-case movement verdict vs today: 1=MOVING (responded/resolved) · 2=PENDING (in window)
178// · 3=OVERDUE-UNRESPONSIVE (window passed, still only sent/acked) · 4=CLOSED-NO-ACTION
179func cv_verdict(status: i64, sent_ymd: i64, expect_days: i64, today: i64) -> i64 {
180 if status == 5 { return 4 }
181 if status >= 3 { return 1 }
182 if today > cv_followup(sent_ymd, expect_days) { return 3 }
183 return 2
184}
185
186// -------- letters (patterns the USER chooses to send; placeholders; facts only) --------
187func cv_letter(issue: i64, out: *u8) -> i64 {
188 var o: i64 = 0
189 if issue == 1 {
190 o = mba_cat(out, o, "To: [STATE] Department of Insurance - Consumer Services\nRe: Complaint against [INSURANCE PLAN NAME], member [MEMBER ID]\n\nI am filing a consumer complaint regarding this insurer's claim handling. Facts: [DATES, CLAIM NUMBERS, WHAT WAS DENIED OR MISHANDLED]. I have completed the plan's internal process where applicable and attach the denial letters, my appeal, and the plan's responses. I request that the Department review this claim handling for compliance with state law and market-conduct standards, and inform me of the outcome.\n\nSincerely,\n[NAME], [ADDRESS]\n\x00" as *u8)
191 out[o] = 0 as u8
192 return o
193 }
194 if issue == 2 {
195 o = mba_cat(out, o, "To: CMS No Surprises Help Desk (federal surprise-billing complaints)\nRe: Balance-billing protection violation - [PROVIDER OR PLAN NAME]\n\nI believe my No Surprises Act protections were violated. Facts: [DATE OF SERVICE, EMERGENCY OR IN-NETWORK FACILITY SITUATION, AMOUNT BALANCE-BILLED]. I notified the provider and plan in writing (copies attached) and the bill was not corrected. I request a federal complaint investigation and confirmation of the outcome.\n\nSincerely,\n[NAME], [ADDRESS]\n\x00" as *u8)
196 out[o] = 0 as u8
197 return o
198 }
199 if issue == 3 {
200 o = mba_cat(out, o, "To: IRS Exempt Organizations (referral via Form 13909)\nRe: Tax-exempt hospital financial-assistance obligations - [HOSPITAL NAME]\n\nThis tax-exempt hospital did not honor its financial assistance obligations under section 501(r): [WHAT HAPPENED - FAP not provided, application ignored, extraordinary collection actions during a pending application]. My written request and the hospital's responses are attached. I am submitting this as a Form 13909 referral; I understand the IRS does not report back on individual referrals, and I am also copying the [STATE] Attorney General so the matter has a responsive channel.\n\nSincerely,\n[NAME], [ADDRESS]\n\x00" as *u8)
201 out[o] = 0 as u8
202 return o
203 }
204 if issue == 4 {
205 o = mba_cat(out, o, "To: Consumer Financial Protection Bureau\nRe: Collection and credit reporting on disputed medical debt - [COLLECTOR OR FURNISHER NAME]\n\nA disputed medical bill is being pursued or credit-reported despite my timely written dispute: [DATES, AMOUNTS, WHAT WAS REPORTED]. My dispute letters and the responses are attached. I request that the Bureau obtain a response from the company and review the conduct under fair-debt-collection and fair-credit-reporting rules.\n\nSincerely,\n[NAME], [ADDRESS]\n\x00" as *u8)
206 out[o] = 0 as u8
207 return o
208 }
209 if issue == 5 {
210 o = mba_cat(out, o, "To: HHS Office of Inspector General - fraud reporting\nRe: Suspected improper billing by [PROVIDER NAME]\n\nA line-by-line review of my itemized bill found billing-integrity problems consistent with improper billing: [FINDINGS - duplicate charges, services billed separately that standard edits bundle, units beyond clinical norms], documented in the attached audit. I report this for investigation; the pattern may affect other patients and federal health programs.\n\nSincerely,\n[NAME], [ADDRESS]\n\x00" as *u8)
211 out[o] = 0 as u8
212 return o
213 }
214 if issue == 6 {
215 o = mba_cat(out, o, "To: The Honorable [REPRESENTATIVE OR SENATOR NAME]\nRe: Constituent request - medical billing accountability\n\nAs your constituent, I am sharing documented facts from my own medical billing experience: [SHORT FACTS - errors found, amounts overcharged, what the oversight process did or did not do, response times]. I am not asking you to intervene in a private dispute. I am asking, in writing: what oversight, hearings, or legislation are you advancing to address billing errors, surprise billing, and unresponsive oversight channels, and how can constituents follow that progress? Please send a written response; I track responsiveness and outcomes and will share both with my community.\n\nRespectfully,\n[NAME], [ADDRESS]\n\x00" as *u8)
216 out[o] = 0 as u8
217 return o
218 }
219 o = mba_cat(out, o, "Unknown issue; no letter generated (the router never guesses a channel).\n\x00" as *u8)
220 out[o] = 0 as u8
221 return o
222}