fairpractice-medicare-advantage 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (unreleased)
4
+
5
+ - First version (Fairpractice wave 2, ver 1).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kurt Francisco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,158 @@
1
- # Temporary Holding Version
1
+ <!-- Generated by scripts/readme.mjs from the agent itself. Edit the manifest or fixtures/README.md, then run npm run readme. -->
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # Fairpractice Medicare Advantage (`fairpractice-medicare-advantage`)
4
+
5
+ Compares Medicare Advantage plans with traditional Medicare on the same services from your own claims: denial rates, paid per unit and days to pay by code, with the codes where Advantage plans fall behind by more than your settings and each Advantage claim paid under a different code than billed. Patient identifiers are masked before results reach the model.
6
+
7
+ **Fairpractice Medicare Advantage never files appeals or disputes with a plan. Fairpractice Medicare Advantage never sends contract or termination notices.**
8
+
9
+ Fairpractice wave 2 ver 1 · Payers and prior authorization · MIT · Node 20 or newer · local files only · patient and staff identifiers masked before results reach the model · built on [`fairpractice-core`](../fairpractice-core)
10
+
11
+ ```bash
12
+ npx -y fairpractice-medicare-advantage demo
13
+ npx -y fairpractice-medicare-advantage mcp --root ./practice-files
14
+ ```
15
+
16
+ ## What the sample data shows
17
+
18
+ Fictional data only: Cedar Ridge Medical Group, made-up patients and made-up plans (Copperline Advantage, Lantern Bay Advantage HMO, Goldfield Health). Amounts are invented; they are not any fee schedule.
19
+
20
+ - [`claims.csv`](fixtures/claims.csv): sixteen claims. Planted for 99214: traditional Medicare paid all four at 130.00 in 14 days; the Advantage plans denied two of five, paid two at 110.00 (15% less) after 40 days, and paid one (M-1009) as 99213. For 97110 the two sides are within the settings (58.00 against 60.00 for two units, 16 days against 14). M-1016 is a commercial claim and is left out of the comparison.
21
+ - [`settings.json`](fixtures/settings.json): names Lantern Bay Advantage HMO as an Advantage plan, needs three claims a side, and lists gaps of 10 points, 10 days or 5% pay. [`settings-typo.json`](fixtures/settings-typo.json) misspells a setting and is refused.
22
+
23
+ ## A demo run
24
+
25
+ `npx -y fairpractice-medicare-advantage demo` runs the agent on the fictional files in [`fixtures/`](fixtures) in a temporary folder. Captured output:
26
+
27
+ ```text
28
+ Fairpractice Medicare Advantage demo (fictional practice, patients, staff and payers)
29
+
30
+ ▶ Compare Advantage plans with traditional Medicare
31
+ status: executed decision: allow
32
+ 16 claim(s): 8 Medicare Advantage, 7 traditional Medicare, 1 other. 2 code(s) compared. 4 finding(s): ma_denial_gap 1, ma_lower_pay 1, ma_slower_pay 1, ma_downgraded 1.
33
+ ma_denial_gap 99214: Advantage plans denied 40% of claims against 0% for traditional Medicare (40 points more).
34
+ ma_lower_pay 99214: Advantage plans paid 110 a unit against 130 from traditional Medicare (15.38% less).
35
+ ma_slower_pay 99214: Advantage plans took 40 days to pay on average against 14 for traditional Medicare.
36
+ ma_downgraded Claim M-1009 (Lantern Bay Advantage HMO) was billed as 99214 and paid as 99213.
37
+
38
+ ▶ Write the contract meeting page
39
+ status: executed decision: allow
40
+ Medicare Advantage and traditional Medicare written: 16 claim(s): 8 Medicare Advantage, 7 traditional Medicare, 1 other. 2 code(s) compared. 4 finding(s): ma_denial_gap 1, ma_lower_pay 1, ma_slower_pay 1, ma_downgraded 1. Files: fairpractice-out/advantage/medicare-advantage-compare.csv, fairpractice-out/advantage/medicare-advantage-compare.html.
41
+
42
+ ▶ Agent tries to file an appeal itself
43
+ status: blocked decision: block
44
+ reason: Fairpractice Medicare Advantage never files appeals or disputes with a plan.
45
+ ```
46
+
47
+ ## Tools
48
+
49
+ | Tool | What it does | Policy |
50
+ |---|---|---|
51
+ | `advantage_check` | List codes where Advantage plans deny more, pay less per unit or pay slower than traditional Medicare, and Advantage claims paid under a different code. | runs |
52
+ | `advantage_write_report` | Write medicare-advantage-compare.csv (one row per item, with blank owner and decision columns) and medicare-advantage-compare.html into out_dir (default fairpractice-out/advantage). | runs |
53
+ | `advantage_recall` | Search this agent's own memory of the customer's setup: accepted facts (in use) and facts waiting for a person. | runs |
54
+ | `advantage_learn` | Propose one fact about the customer's setup for this agent to remember. | runs |
55
+ | `advantage_accept_learning` | A named person accepts or rejects a fact waiting in this agent's memory. | one named click, even in Auto (`accept_learning`) |
56
+ | `advantage_retire_memory` | A named person stops an accepted fact from applying. | one named click, even in Auto (`accept_learning`) |
57
+ | `appeal_submit` | Fairpractice Medicare Advantage never files appeals or disputes with a plan. | refused |
58
+ | `contract_notice_send` | Fairpractice Medicare Advantage never sends contract or termination notices. | refused |
59
+
60
+ Any tool name not in this table is blocked, including names a model invents. Refused tools are listed so a model can see they exist and are refused.
61
+
62
+ ### `advantage_check` arguments
63
+
64
+ | Argument | What it is |
65
+ |---|---|
66
+ | `claims` (required) | Claims and payments export under --root: claim, patient, payer, plan type, billed and paid codes, units, billed and paid amounts, status, submitted and paid dates |
67
+ | `settings` | Optional settings JSON: plan_types, min_claims, denial_gap_pts, days_gap, pay_gap_pct |
68
+ | `status` | Only items with this status |
69
+ | `limit` | Most items to return to the model (the report file always has all of them) |
70
+
71
+ ## Columns it reads
72
+
73
+ Tables can be CSV, TSV, semicolon- or pipe-separated text, Excel `.xlsx`, JSON or JSONL. Columns are matched by the names below (any case and punctuation), and by their usual names in German, French, Spanish, Portuguese, Italian, Japanese, Chinese and Korean. Dates become `YYYY-MM-DD`. Columns marked *masked* hold patient or staff identifiers.
74
+
75
+ The PointClickCare, MatrixCare and American HealthTech style names were written from public help pages and general knowledge, **not checked against real exports**. Run `npx fairpractice-medicare-advantage inspect <file>` (column names and shapes only, never values) and name any column it misses in `remedy-sources.json`.
76
+
77
+ ### Claims and payments (`claims`)
78
+
79
+ | Column | Type | Read from |
80
+ |---|---|---|
81
+ | `claim_id` | text | Claim, Claim ID, Claim #, Claim Number, Encounter, Encounter ID, Visit ID, Invoice |
82
+ | `patient_id` | text (masked) | Patient ID, Patient #, Patient Number, MRN, Medical Record Number, Chart #, Chart Number, Account # |
83
+ | `patient_name` | text (masked) | Patient, Patient Name, Name, Client, Client Name, Member, Member Name, Beneficiary |
84
+ | `payer` (required) | text | Payer, Payer Name, Primary Payer, Insurance, Insurance Name, Plan, Plan Name, Payor |
85
+ | `plan_type` | text | Plan Type, Coverage Type, Product, Line of Business, LOB |
86
+ | `cpt` (required) | text | CPT, Code, Procedure, Procedure Code, CPT/HCPCS, HCPCS, Service Code, Proc Code |
87
+ | `paid_code` | text | Paid Code, Adjudicated Code, Allowed Code, Paid CPT |
88
+ | `dos` | date | Date of Service, DOS, Service Date, Visit Date, Date, From DOS, Session Date, Appointment Date |
89
+ | `units` | number | Units, Unit, Qty, Quantity, Days/Units, Service Units |
90
+ | `billed` | amount | Charge, Charges, Billed, Billed Amount, Amount, Fee, Total Charge |
91
+ | `paid` | amount | Paid, Paid Amount, Payment, Insurance Paid, Amount Paid, Allowed Paid |
92
+ | `status` | text | Status, Claim Status, Outcome |
93
+ | `submitted` | date | Submitted, Submitted On, Bill Date, Date Billed, Sent |
94
+ | `paid_date` | date | Paid Date, Payment Date, Check Date, Remit Date |
95
+
96
+ ## Settings file (`advantage_settings`)
97
+
98
+ A small JSON file you pass by path. A misspelled setting is refused by name rather than ignored, so a typo never silently changes a check.
99
+
100
+ | Setting | What it does |
101
+ |---|---|
102
+ | `plan_types` | Payer name to "ma" or "traditional" when the export has no plan type column |
103
+ | `min_claims` | Claims needed on each side before a code is compared; default 3 |
104
+ | `denial_gap_pts` | Percentage points more denials on Advantage before a code is listed; default 10 |
105
+ | `days_gap` | Days slower to pay on Advantage before a code is listed; default 10 |
106
+ | `pay_gap_pct` | Percent less paid per unit on Advantage before a code is listed; default 5 |
107
+
108
+ ## Memory
109
+
110
+ `advantage_learn` only proposes a fact; nothing changes until a named person accepts it with `advantage_accept_learning`, which is one click even in Auto. Facts live in a hash-chained file under `.remedy/memory/`; if the chain does not verify, no fact is used. Credentials, personal identifiers and text that reads like instructions to an AI are refused.
111
+
112
+ | Kind | What an accepted fact does |
113
+ |---|---|
114
+
115
+ ## Install
116
+
117
+ Node 20 or newer. No other runtime dependencies besides `fairpractice-core` and `fairclaim-core`.
118
+
119
+ ```json
120
+ {
121
+ "mcpServers": {
122
+ "fairpractice-medicare-advantage": {
123
+ "command": "npx",
124
+ "args": [
125
+ "-y",
126
+ "fairpractice-medicare-advantage",
127
+ "mcp",
128
+ "--root",
129
+ "/path/to/practice-files"
130
+ ]
131
+ }
132
+ }
133
+ }
134
+ ```
135
+
136
+ Claude Code: `claude mcp add fairpractice-medicare-advantage -- npx -y fairpractice-medicare-advantage mcp --root .`, or use the plugin files in this folder.
137
+
138
+ ## CLI
139
+
140
+ ```bash
141
+ fairpractice-medicare-advantage tools # every tool, its policy and arguments
142
+ fairpractice-medicare-advantage sources # the columns each input is read from
143
+ fairpractice-medicare-advantage inspect <file> # how a file would be read (names and shapes, never values)
144
+ fairpractice-medicare-advantage call advantage_check '{"claims":"<claims>"}'
145
+ fairpractice-medicare-advantage eval # the private eval cases on the fictional fixtures
146
+ fairpractice-medicare-advantage demo
147
+ ```
148
+
149
+ ## Patient and staff data
150
+
151
+ Results go to an AI model, so identifiers are masked before they leave the agent: patient and staff names become stable pseudonyms such as `PT-3f9a1c2e`, record and account numbers become `MRN-…` or `ACCT-…`, and e-mails and phone numbers are removed, also inside free text. Report files written to disk keep real names because staff work from them: keep them in a folder only your staff can open. The shared tests check that no fictional identifier from the fixtures reaches any eval result, and the hostile-input check plants spreadsheet formulas, HTML and AI-aimed instructions in the data. This keeps PHI away from the model; it is **not** a HIPAA compliance determination. Your business associate agreements, access controls and policies still apply.
152
+
153
+ ## Limits
154
+
155
+ - Reads only the files you give it. It does not log in to an EHR, practice-management system, payer portal, clearinghouse, state system, HR or payroll system, or bank.
156
+ - Payer, Medicare, Medicaid, state and federal rules are summarised from public material as of 2026, and the numbers are settings you supply; a billing, compliance or legal professional checks them before you rely on them.
157
+ - Not legal, billing, coding, tax, clinical or HIPAA advice. It does not diagnose or recommend care. A person decides what to bill, pay, report, file or send.
158
+ - Every call is written to a hash-chained audit log under `.remedy/` in the root. No network calls, no telemetry, no credentials. The bundled data is fictional.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { fileURLToPath } from 'node:url';
3
+ import { main } from 'fairpractice-core';
4
+ import { manifest } from '../src/manifest.js';
5
+ import { demo } from '../src/demo.js';
6
+
7
+ main(manifest, { bin: 'fairpractice-medicare-advantage', demo, evalFile: fileURLToPath(new URL('../evals/cases.json', import.meta.url)) });
@@ -0,0 +1,273 @@
1
+ {
2
+ "suite": "fairpractice-medicare-advantage",
3
+ "root": "..",
4
+ "data_note": "Fictional data in ../fixtures. Deterministic checks; no model is called.",
5
+ "cases": [
6
+ {
7
+ "id": "recall-empty-memory",
8
+ "tool": "advantage_recall",
9
+ "args": {},
10
+ "expect": {
11
+ "status": "executed",
12
+ "contains": [
13
+ "memory is empty"
14
+ ]
15
+ }
16
+ },
17
+ {
18
+ "id": "refuses-appeal_submit",
19
+ "tool": "appeal_submit",
20
+ "args": {},
21
+ "expect": {
22
+ "status": "blocked"
23
+ }
24
+ },
25
+ {
26
+ "id": "refuses-contract_notice_send",
27
+ "tool": "contract_notice_send",
28
+ "args": {},
29
+ "expect": {
30
+ "status": "blocked"
31
+ }
32
+ },
33
+ {
34
+ "id": "report",
35
+ "tool": "advantage_write_report",
36
+ "args": {
37
+ "claims": "fixtures/claims.csv",
38
+ "settings": "fixtures/settings.json"
39
+ },
40
+ "expect": {
41
+ "status": "executed",
42
+ "matches": [
43
+ "\\.csv",
44
+ "\\.html"
45
+ ]
46
+ }
47
+ },
48
+ {
49
+ "id": "totals",
50
+ "tool": "advantage_check",
51
+ "args": {
52
+ "claims": "fixtures/claims.csv",
53
+ "settings": "fixtures/settings.json"
54
+ },
55
+ "expect": {
56
+ "status": "executed",
57
+ "equals": {
58
+ "result.claims": 16,
59
+ "result.advantage_claims": 8,
60
+ "result.traditional_claims": 7,
61
+ "result.not_classified": 1,
62
+ "result.codes_compared": 2
63
+ }
64
+ }
65
+ },
66
+ {
67
+ "id": "every-planted-status-in-order",
68
+ "tool": "advantage_check",
69
+ "args": {
70
+ "claims": "fixtures/claims.csv",
71
+ "settings": "fixtures/settings.json"
72
+ },
73
+ "expect": {
74
+ "equals": {
75
+ "result.items.0.status": "ma_denial_gap",
76
+ "result.items.1.status": "ma_lower_pay",
77
+ "result.items.2.status": "ma_slower_pay",
78
+ "result.items.3.status": "ma_downgraded"
79
+ },
80
+ "length": {
81
+ "result.items": 4
82
+ }
83
+ }
84
+ },
85
+ {
86
+ "id": "status-filter",
87
+ "tool": "advantage_check",
88
+ "args": {
89
+ "claims": "fixtures/claims.csv",
90
+ "settings": "fixtures/settings.json",
91
+ "status": "ma_denial_gap"
92
+ },
93
+ "expect": {
94
+ "status": "executed",
95
+ "equals": {
96
+ "result.items.0.status": "ma_denial_gap"
97
+ }
98
+ }
99
+ },
100
+ {
101
+ "id": "limit-one",
102
+ "tool": "advantage_check",
103
+ "args": {
104
+ "claims": "fixtures/claims.csv",
105
+ "settings": "fixtures/settings.json",
106
+ "limit": 1
107
+ },
108
+ "expect": {
109
+ "status": "executed",
110
+ "length": {
111
+ "result.items": 1
112
+ }
113
+ }
114
+ },
115
+ {
116
+ "id": "report-spanish",
117
+ "tool": "advantage_write_report",
118
+ "args": {
119
+ "claims": "fixtures/claims.csv",
120
+ "settings": "fixtures/settings.json",
121
+ "language": "es"
122
+ },
123
+ "expect": {
124
+ "status": "executed"
125
+ }
126
+ },
127
+ {
128
+ "id": "report-japanese",
129
+ "tool": "advantage_write_report",
130
+ "args": {
131
+ "claims": "fixtures/claims.csv",
132
+ "settings": "fixtures/settings.json",
133
+ "language": "ja"
134
+ },
135
+ "expect": {
136
+ "status": "executed",
137
+ "matches": [
138
+ "\\.html"
139
+ ]
140
+ }
141
+ },
142
+ {
143
+ "id": "typo-setting-refused",
144
+ "tool": "advantage_check",
145
+ "args": {
146
+ "claims": "fixtures/claims.csv",
147
+ "settings": "fixtures/settings-typo.json"
148
+ },
149
+ "expect": {
150
+ "status": "error"
151
+ }
152
+ },
153
+ {
154
+ "id": "null-settings-refused",
155
+ "tool": "advantage_check",
156
+ "args": {
157
+ "claims": "fixtures/claims.csv",
158
+ "settings": null
159
+ },
160
+ "expect": {
161
+ "status": "error"
162
+ }
163
+ },
164
+ {
165
+ "id": "file-outside-root-refused",
166
+ "tool": "advantage_check",
167
+ "args": {
168
+ "claims": "../../outside-root.csv",
169
+ "settings": "fixtures/settings.json"
170
+ },
171
+ "expect": {
172
+ "status": "error",
173
+ "contains": [
174
+ "outside the allowed root"
175
+ ]
176
+ }
177
+ },
178
+ {
179
+ "id": "missing-file-named",
180
+ "tool": "advantage_check",
181
+ "args": {
182
+ "claims": "fixtures/missing-export.csv",
183
+ "settings": "fixtures/settings.json"
184
+ },
185
+ "expect": {
186
+ "status": "error",
187
+ "contains": [
188
+ "not found",
189
+ "missing-export.csv"
190
+ ]
191
+ }
192
+ },
193
+ {
194
+ "id": "no-settings-defaults",
195
+ "tool": "advantage_check",
196
+ "args": {
197
+ "claims": "fixtures/claims.csv"
198
+ },
199
+ "expect": {
200
+ "status": "executed",
201
+ "equals": {
202
+ "result.by_status.ma_denial_gap": 1,
203
+ "result.by_status.ma_downgraded": 1
204
+ }
205
+ }
206
+ },
207
+ {
208
+ "id": "denial-gap-points",
209
+ "tool": "advantage_check",
210
+ "args": {
211
+ "claims": "fixtures/claims.csv",
212
+ "settings": "fixtures/settings.json",
213
+ "status": "ma_denial_gap"
214
+ },
215
+ "expect": {
216
+ "equals": {
217
+ "result.items.0.code": "99214",
218
+ "result.items.0.ma": 40,
219
+ "result.items.0.traditional": 0
220
+ }
221
+ }
222
+ },
223
+ {
224
+ "id": "pay-per-unit",
225
+ "tool": "advantage_check",
226
+ "args": {
227
+ "claims": "fixtures/claims.csv",
228
+ "settings": "fixtures/settings.json",
229
+ "status": "ma_lower_pay"
230
+ },
231
+ "expect": {
232
+ "equals": {
233
+ "result.items.0.ma": 110,
234
+ "result.items.0.traditional": 130,
235
+ "result.items.0.gap": 15.38
236
+ }
237
+ }
238
+ },
239
+ {
240
+ "id": "downgraded-claim",
241
+ "tool": "advantage_check",
242
+ "args": {
243
+ "claims": "fixtures/claims.csv",
244
+ "settings": "fixtures/settings.json",
245
+ "status": "ma_downgraded"
246
+ },
247
+ "expect": {
248
+ "equals": {
249
+ "result.items.0.claim_id": "M-1009",
250
+ "result.items.0.paid_code": "99213"
251
+ }
252
+ }
253
+ },
254
+ {
255
+ "id": "within-settings-not-listed",
256
+ "tool": "advantage_check",
257
+ "args": {
258
+ "claims": "fixtures/claims.csv",
259
+ "settings": "fixtures/settings.json",
260
+ "status": "ma_lower_pay"
261
+ },
262
+ "expect": {
263
+ "length": {
264
+ "result.items": 1
265
+ },
266
+ "equals": {
267
+ "result.by_code.0.code": "97110",
268
+ "result.by_code.0.ma_paid_per_unit": 29
269
+ }
270
+ }
271
+ }
272
+ ]
273
+ }
@@ -0,0 +1,6 @@
1
+ # Fixtures
2
+
3
+ Fictional data only: Cedar Ridge Medical Group, made-up patients and made-up plans (Copperline Advantage, Lantern Bay Advantage HMO, Goldfield Health). Amounts are invented; they are not any fee schedule.
4
+
5
+ - `claims.csv`: sixteen claims. Planted for 99214: traditional Medicare paid all four at 130.00 in 14 days; the Advantage plans denied two of five, paid two at 110.00 (15% less) after 40 days, and paid one (M-1009) as 99213. For 97110 the two sides are within the settings (58.00 against 60.00 for two units, 16 days against 14). M-1016 is a commercial claim and is left out of the comparison.
6
+ - `settings.json`: names Lantern Bay Advantage HMO as an Advantage plan, needs three claims a side, and lists gaps of 10 points, 10 days or 5% pay. `settings-typo.json` misspells a setting and is refused.
@@ -0,0 +1,85 @@
1
+ {
2
+ "case": "totals",
3
+ "id": [
4
+ [
5
+ "claim_id"
6
+ ],
7
+ [
8
+ "code"
9
+ ]
10
+ ],
11
+ "planted": [
12
+ ["99214", "ma_denial_gap"],
13
+ ["99214", "ma_lower_pay"],
14
+ ["99214", "ma_slower_pay"],
15
+ ["M-1009", "ma_downgraded"]
16
+ ],
17
+ "clean": [
18
+ {
19
+ "arg": "claims",
20
+ "drop": [
21
+ ["Claim #", "M-1005"],
22
+ ["Claim #", "M-1006"],
23
+ ["Claim #", "M-1007"],
24
+ ["Claim #", "M-1008"],
25
+ ["Claim #", "M-1009"]
26
+ ]
27
+ }
28
+ ],
29
+ "mutations": [
30
+ {
31
+ "name": "one Advantage claim paid 40 days later",
32
+ "edits": [
33
+ {
34
+ "arg": "claims",
35
+ "set": [
36
+ {
37
+ "where": ["Claim #", "M-1013"],
38
+ "column": "Paid Date",
39
+ "value": "2026-09-30"
40
+ }
41
+ ]
42
+ }
43
+ ],
44
+ "expect": [
45
+ ["97110", "ma_slower_pay"]
46
+ ]
47
+ },
48
+ {
49
+ "name": "one Advantage claim paid 40 instead of 58",
50
+ "edits": [
51
+ {
52
+ "arg": "claims",
53
+ "set": [
54
+ {
55
+ "where": ["Claim #", "M-1014"],
56
+ "column": "Paid",
57
+ "value": "40.00"
58
+ }
59
+ ]
60
+ }
61
+ ],
62
+ "expect": [
63
+ ["97110", "ma_lower_pay"]
64
+ ]
65
+ },
66
+ {
67
+ "name": "paid under a lower code",
68
+ "edits": [
69
+ {
70
+ "arg": "claims",
71
+ "set": [
72
+ {
73
+ "where": ["Claim #", "M-1015"],
74
+ "column": "Paid Code",
75
+ "value": "97112"
76
+ }
77
+ ]
78
+ }
79
+ ],
80
+ "expect": [
81
+ ["M-1015", "ma_downgraded"]
82
+ ]
83
+ }
84
+ ]
85
+ }
@@ -0,0 +1,17 @@
1
+ Claim #,Patient #,Patient Name,Payer,CPT,Paid Code,Date of Service,Units,Billed,Paid,Claim Status,Bill Date,Paid Date
2
+ M-1001,P1101,Agnes Wylie,Medicare Part B,99214,,2026-07-01,1,180.00,130.00,Paid,2026-07-03,2026-07-17
3
+ M-1002,P1102,Boris Fenn,Medicare Part B,99214,,2026-07-08,1,180.00,130.00,Paid,2026-07-10,2026-07-24
4
+ M-1003,P1103,Clara Holm,Medicare Part B,99214,,2026-07-15,1,180.00,130.00,Paid,2026-07-17,2026-07-31
5
+ M-1004,P1104,Dorian Pike,Medicare Part B,99214,,2026-07-22,1,180.00,130.00,Paid,2026-07-24,2026-08-07
6
+ M-1005,P1105,Edith Rowe,Copperline Advantage,99214,,2026-07-02,1,180.00,110.00,Paid,2026-07-03,2026-08-12
7
+ M-1006,P1106,Fabian Kerr,Copperline Advantage,99214,,2026-07-09,1,180.00,110.00,Paid,2026-07-10,2026-08-19
8
+ M-1007,P1107,Greer Lowe,Copperline Advantage,99214,,2026-07-16,1,180.00,0,Denied,2026-07-17,
9
+ M-1008,P1108,Hollis Ward,Lantern Bay Advantage HMO,99214,,2026-07-23,1,180.00,0,Denied,2026-07-24,
10
+ M-1009,P1109,Ines Faro,Lantern Bay Advantage HMO,99214,99213,2026-07-30,1,180.00,92.00,Paid,2026-07-31,2026-08-30
11
+ M-1010,P1110,Jasper Moss,Medicare Part B,97110,,2026-08-03,2,70.00,60.00,Paid,2026-08-04,2026-08-18
12
+ M-1011,P1111,Kerstin Bly,Medicare Part B,97110,,2026-08-10,2,70.00,60.00,Paid,2026-08-11,2026-08-25
13
+ M-1012,P1112,Leon Asher,Medicare Part B,97110,,2026-08-17,2,70.00,60.00,Paid,2026-08-18,2026-09-01
14
+ M-1013,P1113,Mirela Dunn,Copperline Advantage,97110,,2026-08-04,2,70.00,58.00,Paid,2026-08-05,2026-08-21
15
+ M-1014,P1114,Nils Okafor,Copperline Advantage,97110,,2026-08-11,2,70.00,58.00,Paid,2026-08-12,2026-08-28
16
+ M-1015,P1115,Odile Grant,Copperline Advantage,97110,,2026-08-18,2,70.00,58.00,Paid,2026-08-19,2026-09-04
17
+ M-1016,P1116,Piers Hart,Goldfield Health,99214,,2026-08-20,1,180.00,150.00,Paid,2026-08-21,2026-09-05
@@ -0,0 +1 @@
1
+ { "note": "Fictional patient names and ids used in these fixtures. None may reach a model result when masking is on.", "values": ["Ines Faro", "Edith Rowe", "Greer Lowe", "P1109", "P1107"] }
@@ -0,0 +1 @@
1
+ { "min_claim": 3 }
@@ -0,0 +1 @@
1
+ { "plan_types": { "Lantern Bay Advantage HMO": "ma", "Medicare Part B": "traditional" }, "min_claims": 3, "denial_gap_pts": 10, "days_gap": 10, "pay_gap_pct": 5 }
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "fairpractice-medicare-advantage",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "mcpName": "io.github.fpavia111-creator/fairpractice-medicare-advantage",
5
+ "description": "Medicare Advantage against traditional Medicare on the same services: denial rate, paid code differing from billed code, days to pay and paid per unit, with the codes where Advantage plans fall behind by more than your settings.",
6
+ "type": "module",
7
+ "license": "MIT",
8
+ "author": "Kurt Francisco",
9
+ "engines": {
10
+ "node": ">=20"
11
+ },
12
+ "main": "src/index.js",
13
+ "exports": {
14
+ ".": "./src/index.js",
15
+ "./package.json": "./package.json"
16
+ },
17
+ "bin": {
18
+ "fairpractice-medicare-advantage": "bin/fairpractice-medicare-advantage.js"
19
+ },
20
+ "files": [
21
+ "src",
22
+ "bin",
23
+ "fixtures",
24
+ "evals",
25
+ "README.md",
26
+ "CHANGELOG.md",
27
+ "LICENSE",
28
+ "server.json"
29
+ ],
30
+ "scripts": {
31
+ "test": "node scripts/run-tests.cjs",
32
+ "demo": "node bin/fairpractice-medicare-advantage.js demo",
33
+ "eval": "node bin/fairpractice-medicare-advantage.js eval"
34
+ },
35
+ "dependencies": {
36
+ "fairpractice-core": "^0.3.0"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/fpavia111-creator/fairpractice2-agents.git",
41
+ "directory": "packages/fairpractice-medicare-advantage"
42
+ },
43
+ "homepage": "https://github.com/fpavia111-creator/fairpractice2-agents/tree/master/packages/fairpractice-medicare-advantage#readme",
44
+ "bugs": {
45
+ "url": "https://github.com/fpavia111-creator/fairpractice2-agents/issues"
46
+ },
47
+ "keywords": [
48
+ "mcp",
49
+ "mcp-server",
50
+ "healthcare",
51
+ "medical-billing",
52
+ "revenue-cycle",
53
+ "healthcare-compliance",
54
+ "medicare-advantage",
55
+ "payer-performance",
56
+ "denials",
57
+ "underpayments"
58
+ ]
59
+ }
package/server.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.fpavia111-creator/fairpractice-medicare-advantage",
4
+ "title": "Fairpractice Medicare Advantage",
5
+ "description": "Medicare Advantage against traditional Medicare on the same services",
6
+ "version": "0.1.0",
7
+ "repository": {
8
+ "url": "https://github.com/fpavia111-creator/fairpractice2-agents",
9
+ "source": "github",
10
+ "subfolder": "packages/fairpractice-medicare-advantage"
11
+ },
12
+ "websiteUrl": "https://fair-agents.com/fairpractice.html",
13
+ "packages": [
14
+ {
15
+ "registryType": "npm",
16
+ "identifier": "fairpractice-medicare-advantage",
17
+ "version": "0.1.0",
18
+ "transport": {
19
+ "type": "stdio"
20
+ },
21
+ "packageArguments": [
22
+ {
23
+ "type": "positional",
24
+ "value": "mcp"
25
+ },
26
+ {
27
+ "type": "named",
28
+ "name": "--root",
29
+ "description": "Folder holding the exports this agent may read and write (it cannot reach outside it)",
30
+ "isRequired": true,
31
+ "format": "filepath",
32
+ "valueHint": "exports_folder"
33
+ }
34
+ ]
35
+ }
36
+ ]
37
+ }
package/src/demo.js ADDED
@@ -0,0 +1,9 @@
1
+ import { runDemo } from 'fairpractice-core';
2
+ import { manifest } from './manifest.js';
3
+
4
+ const f = { claims: 'claims.csv', settings: 'settings.json' };
5
+ export const demo = () => runDemo(manifest, new URL('../fixtures', import.meta.url), 'Fairpractice Medicare Advantage', [
6
+ { label: 'Compare Advantage plans with traditional Medicare', tool: 'advantage_check', args: f, list: (i) => `${i.status.padEnd(16)} ${i.message}` },
7
+ { label: 'Write the contract meeting page', tool: 'advantage_write_report', args: f },
8
+ { label: 'Agent tries to file an appeal itself', tool: 'appeal_submit', args: {} },
9
+ ]);
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { manifest } from './manifest.js';
2
+ export * from './logic.js';
package/src/logic.js ADDED
@@ -0,0 +1,55 @@
1
+ // Medicare Advantage against traditional Medicare on the same codes: denials, paid per unit, days to pay and downgrades. No I/O.
2
+ import { str, num, isoDate, daysBetween, payerKey, codeKey, round2, lookupRule, sortByStatus, countBy } from 'fairpractice-core';
3
+
4
+ const ORDER = { ma_denial_gap: 0, ma_lower_pay: 1, ma_slower_pay: 2, ma_downgraded: 3 };
5
+ /** Plan type of a claim: its own column, then the plan_types setting, then a few name patterns. */
6
+ export function planTypeOf(r, planTypes = {}) {
7
+ const own = str(r.plan_type).toLowerCase();
8
+ if (/^(ma|medicare advantage|advantage|part c|mapd)$/.test(own)) return 'ma';
9
+ if (/^(traditional|original|ffs|part b|medicare|original medicare)$/.test(own)) return 'traditional';
10
+ const set = lookupRule(planTypes, r.payer); if (set) return /^ma|adv/i.test(set) ? 'ma' : /trad|orig|ffs/i.test(set) ? 'traditional' : null;
11
+ const p = str(r.payer); if (/advantage|\bmapd\b|\bma\b/i.test(p)) return 'ma'; if (/^medicare( part b)?$/i.test(p)) return 'traditional';
12
+ return null;
13
+ }
14
+ const denied = (r) => /deni|reject/i.test(str(r.status)) || (num(r.paid) === 0 && /^0?$/.test(str(r.paid)) && /deni/i.test(str(r.status)));
15
+
16
+ /**
17
+ * claims: [{ claim_id, patient_id, payer, plan_type, cpt, paid_code, dos, units, billed, paid, status, submitted, paid_date }]
18
+ * opts: { planTypes = {}, minClaims = 3, denialGapPts = 10, daysGap = 10, payGapPct = 5 }
19
+ */
20
+ export function compareAdvantage(claims, { planTypes = {}, minClaims = 3, denialGapPts = 10, daysGap = 10, payGapPct = 5 } = {}) {
21
+ const groups = new Map(); const items = []; let ma = 0, trad = 0, other = 0;
22
+ const g = (code, type) => { const k = `${code}|${type}`; if (!groups.has(k)) groups.set(k, { claims: 0, denied: 0, paidUnits: 0, paidAmt: 0, days: [] }); return groups.get(k); };
23
+ for (const [i, r] of claims.entries()) {
24
+ const type = planTypeOf(r, planTypes); const code = codeKey(r.cpt); if (!code) continue;
25
+ if (!type) { other++; continue; } type === 'ma' ? ma++ : trad++;
26
+ const x = g(code, type); x.claims++;
27
+ if (denied(r)) { x.denied++; continue; }
28
+ const paidCode = codeKey(r.paid_code);
29
+ const units = num(r.units) || 1; const paid = num(r.paid) || 0;
30
+ if (paidCode && paidCode !== code) { if (type === 'ma') items.push({ status: 'ma_downgraded', claim_id: str(r.claim_id) || `line ${i + 1}`, patient_id: str(r.patient_id) || null, payer: str(r.payer), code, paid_code: paidCode, paid, line: i }); continue; }
31
+ x.paidUnits += units; x.paidAmt += paid;
32
+ const sub = isoDate(r.submitted), pd = isoDate(r.paid_date); if (sub && pd) x.days.push(daysBetween(sub, pd));
33
+ }
34
+ const avg = (a) => (a.length ? round2(a.reduce((s, v) => s + v, 0) / a.length) : null);
35
+ const codes = [...new Set([...groups.keys()].map((k) => k.split('|')[0]))].sort();
36
+ const by_code = codes.map((code) => {
37
+ const m = groups.get(`${code}|ma`) || { claims: 0, denied: 0, paidUnits: 0, paidAmt: 0, days: [] }; const t = groups.get(`${code}|traditional`) || { claims: 0, denied: 0, paidUnits: 0, paidAmt: 0, days: [] };
38
+ return { code, ma_claims: m.claims, traditional_claims: t.claims, ma_denial_pct: m.claims ? round2((m.denied / m.claims) * 100) : null, traditional_denial_pct: t.claims ? round2((t.denied / t.claims) * 100) : null, ma_paid_per_unit: m.paidUnits ? round2(m.paidAmt / m.paidUnits) : null, traditional_paid_per_unit: t.paidUnits ? round2(t.paidAmt / t.paidUnits) : null, ma_days_to_pay: avg(m.days), traditional_days_to_pay: avg(t.days) };
39
+ });
40
+ for (const c of by_code) {
41
+ if (c.ma_claims < minClaims || c.traditional_claims < minClaims) continue;
42
+ if (c.ma_denial_pct - c.traditional_denial_pct >= denialGapPts) items.push({ status: 'ma_denial_gap', code: c.code, ma: c.ma_denial_pct, traditional: c.traditional_denial_pct, gap: round2(c.ma_denial_pct - c.traditional_denial_pct) });
43
+ if (c.ma_paid_per_unit !== null && c.traditional_paid_per_unit && c.ma_paid_per_unit < c.traditional_paid_per_unit * (1 - payGapPct / 100)) items.push({ status: 'ma_lower_pay', code: c.code, ma: c.ma_paid_per_unit, traditional: c.traditional_paid_per_unit, gap: round2(((c.traditional_paid_per_unit - c.ma_paid_per_unit) / c.traditional_paid_per_unit) * 100) });
44
+ if (c.ma_days_to_pay !== null && c.traditional_days_to_pay !== null && c.ma_days_to_pay - c.traditional_days_to_pay >= daysGap) items.push({ status: 'ma_slower_pay', code: c.code, ma: c.ma_days_to_pay, traditional: c.traditional_days_to_pay, gap: round2(c.ma_days_to_pay - c.traditional_days_to_pay) });
45
+ }
46
+ const T = {
47
+ ma_denial_gap: (x) => [`${x.code}: Advantage plans denied ${x.ma}% of claims against ${x.traditional}% for traditional Medicare (${x.gap} points more).`, 'Pull the denial reasons for these claims and raise them with the plans.'],
48
+ ma_lower_pay: (x) => [`${x.code}: Advantage plans paid ${x.ma} a unit against ${x.traditional} from traditional Medicare (${x.gap}% less).`, 'Check the contract rate; many Advantage contracts promise a share of the Medicare fee schedule.'],
49
+ ma_slower_pay: (x) => [`${x.code}: Advantage plans took ${x.ma} days to pay on average against ${x.traditional} for traditional Medicare.`, 'Ask the plans about prompt-pay terms in the contract.'],
50
+ ma_downgraded: (x) => [`Claim ${x.claim_id} (${x.payer}) was billed as ${x.code} and paid as ${x.paid_code}.`, 'Check the remittance reason; appeal if the documentation supports the billed code.'],
51
+ };
52
+ for (const it of items) { const [m, f] = T[it.status](it); it.message = m; it.fix = f; delete it.line; }
53
+ sortByStatus(items, ORDER, 'gap');
54
+ return { claims: claims.length, advantage_claims: ma, traditional_claims: trad, not_classified: other, codes_compared: by_code.filter((c) => c.ma_claims >= minClaims && c.traditional_claims >= minClaims).length, by_code, by_status: countBy(items, 'status'), items };
55
+ }
@@ -0,0 +1,65 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { medAgent, fileArg, CLAIM_ID, PATIENT_ID, PATIENT_NAME, PAYER, CPT, DOS, UNITS, CHARGE, PAID, PRACTICE_LIMITS } from 'fairpractice-core';
3
+ import { compareAdvantage } from './logic.js';
4
+
5
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
6
+ const t = (aliases, extra = {}) => ({ aliases, ...extra });
7
+
8
+ export const CLAIM_FIELDS = Object.freeze({
9
+ claim_id: CLAIM_ID, patient_id: PATIENT_ID, patient_name: PATIENT_NAME, payer: { ...PAYER, required: true },
10
+ plan_type: t(['Plan Type', 'Coverage Type', 'Product', 'Line of Business', 'LOB'], { translate: false }),
11
+ cpt: { ...CPT, required: true },
12
+ paid_code: t(['Paid Code', 'Adjudicated Code', 'Allowed Code', 'Paid CPT'], { translate: false }),
13
+ dos: DOS, units: UNITS, billed: CHARGE, paid: PAID,
14
+ status: t(['Status', 'Claim Status', 'Outcome'], { translate: 'status' }),
15
+ submitted: t(['Submitted', 'Submitted On', 'Bill Date', 'Date Billed', 'Sent'], { type: 'date', translate: 'submitted_on' }),
16
+ paid_date: t(['Paid Date', 'Payment Date', 'Check Date', 'Remit Date'], { type: 'date', translate: false }),
17
+ });
18
+
19
+ const SETTINGS = { type: 'object', additionalProperties: false, properties: {
20
+ plan_types: { type: 'object', additionalProperties: { type: 'string', enum: ['ma', 'traditional'] }, description: 'Payer name to "ma" or "traditional" when the export has no plan type column' },
21
+ min_claims: { type: 'integer', minimum: 1, maximum: 1000, description: 'Claims needed on each side before a code is compared; default 3' },
22
+ denial_gap_pts: { type: 'number', minimum: 0, maximum: 100, description: 'Percentage points more denials on Advantage before a code is listed; default 10' },
23
+ days_gap: { type: 'number', minimum: 0, maximum: 365, description: 'Days slower to pay on Advantage before a code is listed; default 10' },
24
+ pay_gap_pct: { type: 'number', minimum: 0, maximum: 100, description: 'Percent less paid per unit on Advantage before a code is listed; default 5' },
25
+ } };
26
+
27
+ const args = {
28
+ claims: fileArg('Claims and payments export under --root: claim, patient, payer, plan type, billed and paid codes, units, billed and paid amounts, status, submitted and paid dates'),
29
+ settings: fileArg('Optional settings JSON: plan_types, min_claims, denial_gap_pts, days_gap, pay_gap_pct'),
30
+ };
31
+ const run = (a, ctx) => {
32
+ const s = a.settings ? ctx.readJson(a.settings, 'advantage_settings') : {};
33
+ return compareAdvantage(ctx.records(a.claims, 'claims'), { planTypes: s.plan_types || {}, minClaims: s.min_claims ?? 3, denialGapPts: s.denial_gap_pts ?? 10, daysGap: s.days_gap ?? 10, payGapPct: s.pay_gap_pct ?? 5 });
34
+ };
35
+ const summary = (o) => `${o.claims} claim(s): ${o.advantage_claims} Medicare Advantage, ${o.traditional_claims} traditional Medicare, ${o.not_classified} other. ${o.codes_compared} code(s) compared. ${Object.values(o.by_status).reduce((s, x) => s + x, 0)} finding(s): ${Object.entries(o.by_status).map(([k, v]) => `${k} ${v}`).join(', ') || 'none'}.`;
36
+
37
+ export const manifest = medAgent({
38
+ pkg, prefix: 'advantage', title: 'Fairpractice Medicare Advantage',
39
+ description: 'Compares Medicare Advantage plans with traditional Medicare on the same services from your own claims: denial rates, paid per unit and days to pay by code, with the codes where Advantage plans fall behind by more than your settings and each Advantage claim paid under a different code than billed. Patient identifiers are masked before results reach the model.',
40
+ args, required: ['claims'],
41
+ sources: { claims: { label: 'Claims and payments', args: ['claims'], fields: CLAIM_FIELDS } },
42
+ configSchemas: { advantage_settings: SETTINGS }, memoryKinds: {},
43
+ run, summary,
44
+ check: { title: 'Compare Advantage and traditional Medicare', description: 'List codes where Advantage plans deny more, pay less per unit or pay slower than traditional Medicare, and Advantage claims paid under a different code.' },
45
+ report: {
46
+ title: { en: 'Medicare Advantage and traditional Medicare', es: 'Medicare Advantage frente a Medicare tradicional', de: 'Medicare Advantage im Vergleich zu Original Medicare', fr: 'Medicare Advantage et Medicare traditionnel', pt: 'Medicare Advantage e Medicare tradicional', it: 'Medicare Advantage e Medicare tradizionale', ja: 'メディケア・アドバンテージと従来型メディケア', zh: '联邦医保优势计划与传统联邦医保', ko: '메디케어 어드밴티지와 기존 메디케어' },
47
+ base: 'medicare-advantage-compare',
48
+ rows: (o) => o.items.map((i) => ({ status: i.status, code: i.code, claim_id: i.claim_id || '', patient_id: i.patient_id || '', paid_code: i.paid_code || '', advantage: i.ma ?? i.paid ?? '', traditional: i.traditional ?? '', message: i.message, fix: i.fix })),
49
+ htmlColumns: ['status', 'code', 'claim_id', 'advantage', 'traditional', 'message', 'fix'],
50
+ sections: (o) => [{ title: { en: 'By code' }, rows: o.by_code, columns: ['code', 'ma_claims', 'traditional_claims', 'ma_denial_pct', 'traditional_denial_pct', 'ma_paid_per_unit', 'traditional_paid_per_unit', 'ma_days_to_pay', 'traditional_days_to_pay'] }],
51
+ limits: [PRACTICE_LIMITS.files, PRACTICE_LIMITS.estimate, 'Small samples swing: a code is compared only when both sides have the minimum number of claims. Differences in patients, sites of care and contracts are not adjusted for.', PRACTICE_LIMITS.advice, PRACTICE_LIMITS.phi],
52
+ },
53
+ refused: [
54
+ { name: 'appeal_submit', category: 'binding_send', description: 'Fairpractice Medicare Advantage never files appeals or disputes with a plan.' },
55
+ { name: 'contract_notice_send', category: 'binding_send', description: 'Fairpractice Medicare Advantage never sends contract or termination notices.' },
56
+ ],
57
+ prompt: { title: 'Medicare Advantage comparison', description: 'Walks the host model through a quarterly Advantage comparison.', text: `You are helping a revenue cycle or managed care lead with fairpractice-medicare-advantage.
58
+
59
+ Rules: it only reads files. Patient identifiers in results are masked.
60
+
61
+ 1. Call advantage_check with the claims export.
62
+ 2. Lead with the codes with the largest denial gap, then lower pay per unit.
63
+ 3. Say how many claims each side had; small samples swing.
64
+ 4. Call advantage_write_report for the contract meeting.` },
65
+ });