nx_medbill_appeal.nx source
↩ module page · 103 lines · 6451 B
1// nx_medbill_appeal.nx -- M-ADV2 of the MEDICAL BILLING & PATIENT ADVOCACY ladder: INSURANCE DENIAL
2// INTERNAL-APPEAL letter with computed DEADLINES. Plans must give claimants a full and fair review of
3// an adverse benefit determination; appeals may generally be filed within 180 days of the denial
4// notice, and an upheld denial can proceed to independent EXTERNAL REVIEW. This organ computes the
5// 180-day deadline with exact integer calendar math (civil-days algorithm, leap-safe) and renders a
6// reason-specific appeal letter (1=not medically necessary, 2=experimental/investigational,
7// 3=out-of-network, 4=prior authorization missing, 5=coding error). FAIL-SAFE: caller buffer only,
8// placeholders keep member identity out of the tool, nothing is ever sent. license_tier: ORIGINAL
9import "nx_syscalls.nx"
10
11// ---- exact integer calendar (days-from-civil / civil-from-days), valid for positive years ----
12func mba_dfc(y0: i64, m: i64, d: i64) -> i64 {
13 var y: i64 = y0
14 if m <= 2 { y = y - 1 }
15 let era: i64 = y / 400
16 let yoe: i64 = y - era * 400
17 var mp: i64 = m + 9
18 if m > 2 { mp = m - 3 }
19 let doy: i64 = (153 * mp + 2) / 5 + d - 1
20 let doe: i64 = yoe * 365 + yoe / 4 - yoe / 100 + doy
21 return era * 146097 + doe - 719468
22}
23func mba_cfd(z0: i64) -> i64 {
24 let z: i64 = z0 + 719468
25 let era: i64 = z / 146097
26 let doe: i64 = z - era * 146097
27 let yoe: i64 = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365
28 let y: i64 = yoe + era * 400
29 let doy: i64 = doe - (365 * yoe + yoe / 4 - yoe / 100)
30 let mp: i64 = (5 * doy + 2) / 153
31 let d: i64 = doy - (153 * mp + 2) / 5 + 1
32 var m: i64 = mp - 9
33 if mp < 10 { m = mp + 3 }
34 var yy: i64 = y
35 if m <= 2 { yy = y + 1 }
36 return yy * 10000 + m * 100 + d
37}
38// yyyymmdd + n days -> yyyymmdd (exact, leap-safe)
39func mba_add_days(ymd: i64, n: i64) -> i64 {
40 let y: i64 = ymd / 10000
41 let m: i64 = (ymd / 100) % 100
42 let d: i64 = ymd % 100
43 return mba_cfd(mba_dfc(y, m, d) + n)
44}
45
46func mba_cat(out: *u8, off: i64, s: *u8) -> i64 {
47 var o: i64 = off
48 var i: i64 = 0
49 while s[i] != (0 as u8) { out[o] = s[i]; o = o + 1; i = i + 1 }
50 return o
51}
52func mba_n2(out: *u8, off: i64, v: i64) -> i64 {
53 out[off] = (48 + ((v / 10) % 10)) as u8
54 out[off + 1] = (48 + (v % 10)) as u8
55 return off + 2
56}
57// yyyymmdd -> YYYY-MM-DD
58func mba_date(out: *u8, off: i64, ymd: i64) -> i64 {
59 var o: i64 = off
60 let y: i64 = ymd / 10000
61 out[o] = (48 + ((y / 1000) % 10)) as u8
62 out[o + 1] = (48 + ((y / 100) % 10)) as u8
63 out[o + 2] = (48 + ((y / 10) % 10)) as u8
64 out[o + 3] = (48 + (y % 10)) as u8
65 o = o + 4
66 out[o] = 45 as u8
67 o = o + 1
68 o = mba_n2(out, o, (ymd / 100) % 100)
69 out[o] = 45 as u8
70 o = o + 1
71 o = mba_n2(out, o, ymd % 100)
72 return o
73}
74
75func mba_reason(out: *u8, off: i64, code: i64) -> i64 {
76 if code == 1 { return mba_cat(out, off, "The denial states the service was not medically necessary. My treating physician's letter of medical necessity is enclosed. Please identify the specific clinical criteria and evidence relied upon, the specialty and credentials of the reviewing clinician, and reprocess this claim in light of the enclosed clinical documentation.\x00" as *u8) }
77 if code == 2 { return mba_cat(out, off, "The denial characterizes the service as experimental or investigational. This service is supported by peer-reviewed evidence and is standard of care for my condition; supporting literature is enclosed. Please provide the coverage criteria and the evidence review on which this determination rests.\x00" as *u8) }
78 if code == 3 { return mba_cat(out, off, "The denial applies out-of-network treatment to this claim. Federal surprise-billing protections limit my cost sharing to in-network levels for emergency services and for care from out-of-network providers at in-network facilities. Please reprocess this claim at the in-network benefit level.\x00" as *u8) }
79 if code == 4 { return mba_cat(out, off, "The denial cites missing prior authorization. The circumstances were urgent and authorization could not reasonably have been obtained in advance. I request retroactive authorization and reprocessing of the claim on its clinical merits.\x00" as *u8) }
80 if code == 5 { return mba_cat(out, off, "The denial appears to rest on a coding or billing error. A corrected claim is being requested from the provider; please reprocess the claim with the corrected codes.\x00" as *u8) }
81 return mba_cat(out, off, "I believe this determination is incorrect and request a complete re-review of the claim on its merits.\x00" as *u8)
82}
83
84// Render the internal-appeal letter. Deadline = denial date + 180 days, computed exactly.
85func mba_letter(reason: i64, denial_ymd: i64, out: *u8) -> i64 {
86 let deadline: i64 = mba_add_days(denial_ymd, 180)
87 var o: i64 = 0
88 o = mba_cat(out, o, "To: [INSURANCE PLAN NAME] Appeals Department\n" as *u8)
89 o = mba_cat(out, o, "Re: Member [MEMBER ID] - Claim [CLAIM NUMBER]\n" as *u8)
90 o = mba_cat(out, o, "Subject: Formal internal appeal of the adverse benefit determination dated " as *u8)
91 o = mba_date(out, o, denial_ymd)
92 o = mba_cat(out, o, "\n\nI am appealing your denial of the above claim and requesting a full and fair review. Please provide, free of charge, copies of: the complete claim file; any internal rule, guideline, protocol, or clinical criteria relied upon in this decision; and the specific plan provisions on which the denial is based.\n\n" as *u8)
93 o = mba_reason(out, o, reason)
94 o = mba_cat(out, o, "\n\nAppeals of adverse benefit determinations may be filed within 180 days of the denial notice. Measured from your " as *u8)
95 o = mba_date(out, o, denial_ymd)
96 o = mba_cat(out, o, " determination, the appeal window runs through " as *u8)
97 o = mba_date(out, o, deadline)
98 o = mba_cat(out, o, "; this appeal is timely. If the service at issue is urgent, I request an expedited review on the timeline required for urgent care claims.\n\n" as *u8)
99 o = mba_cat(out, o, "If this denial is upheld, I intend to request an independent external review by an Independent Review Organization as provided under the plan and applicable law.\n\n" as *u8)
100 o = mba_cat(out, o, "Please send your written determination and the requested documents to the address on file.\n\nSincerely,\n[MEMBER NAME]\n" as *u8)
101 out[o] = 0 as u8
102 return o
103}