fairpractice-pbm-audits 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 +5 -0
- package/LICENSE +21 -0
- package/README.md +168 -2
- package/bin/fairpractice-pbm-audits.js +7 -0
- package/evals/cases.json +320 -0
- package/fixtures/README.md +7 -0
- package/fixtures/accuracy.json +108 -0
- package/fixtures/audit-claims.csv +7 -0
- package/fixtures/audits.csv +7 -0
- package/fixtures/phi-canaries.json +1 -0
- package/fixtures/settings-typo.json +1 -0
- package/fixtures/settings.json +1 -0
- package/package.json +57 -4
- package/server.json +37 -0
- package/src/demo.js +9 -0
- package/src/index.js +2 -0
- package/src/logic.js +44 -0
- package/src/manifest.js +78 -0
package/CHANGELOG.md
ADDED
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,169 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
3
|
+
# Fairpractice PBM Audits (`fairpractice-pbm-audits`)
|
|
4
|
+
|
|
5
|
+
Tracks PBM audits for a pharmacy: responses overdue or due soon, claims whose documents are still not ready, appeal windows on preliminary findings closing or missed, and money taken back before a final report. Administrative only; no patient data is needed.
|
|
6
|
+
|
|
7
|
+
**Fairpractice PBM Audits never sends documents or responses to an auditor. Fairpractice PBM Audits never files an appeal.**
|
|
8
|
+
|
|
9
|
+
Fairpractice wave 2 ver 1 · Pharmacy (admin and money only) · 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-pbm-audits demo
|
|
13
|
+
npx -y fairpractice-pbm-audits mcp --root ./practice-files
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## What the sample data shows
|
|
17
|
+
|
|
18
|
+
Fictional data only: Main Street Pharmacy and made-up PBMs (Fernhollow Rx, Brightmoor Script). No prescription content is included; the checklist names documents only. Checked on 15 November 2026.
|
|
19
|
+
|
|
20
|
+
- [`audits.csv`](fixtures/audits.csv): six audits. Planted: AUD-301 was due 10 November and not sent; AUD-302 is due 19 November; AUD-303's preliminary finding of 1,840.00 (22 October) can be appealed for 30 days, to 21 November; AUD-304's appeal deadline of 1 October passed with no appeal; AUD-305 had 520.00 taken back on 10 September with no final report. AUD-306 closed with nothing owed.
|
|
21
|
+
- [`audit-claims.csv`](fixtures/audit-claims.csv): AUD-301 still lacks a signature log and an invoice.
|
|
22
|
+
- [`settings.json`](fixtures/settings.json): a 7-day warning and 30 days to appeal when the letter gives no date. Check each PBM contract and your state's pharmacy audit law. [`settings-typo.json`](fixtures/settings-typo.json) misspells a setting and is refused.
|
|
23
|
+
|
|
24
|
+
## A demo run
|
|
25
|
+
|
|
26
|
+
`npx -y fairpractice-pbm-audits demo` runs the agent on the fictional files in [`fixtures/`](fixtures) in a temporary folder. Captured output:
|
|
27
|
+
|
|
28
|
+
```text
|
|
29
|
+
Fairpractice PBM Audits demo (fictional practice, patients, staff and payers)
|
|
30
|
+
|
|
31
|
+
▶ Check open PBM audits and their documents
|
|
32
|
+
status: executed decision: allow
|
|
33
|
+
6 audit(s), 2 not answered yet, 6 claim(s) under audit, 3320 in preliminary findings. 6 finding(s): response_overdue 1, response_due_soon 1, documents_missing 1, appeal_closing 1, appeal_missed 1, recouped_before_final 1.
|
|
34
|
+
response_overdue Fernhollow Rx audit AUD-301 (3 claim(s)) was due 2026-11-10 and has not been sent (5 day(s) late).
|
|
35
|
+
response_due_soon Brightmoor Script audit AUD-302 (2 claim(s)) is due 2026-11-19 (in 4 day(s)).
|
|
36
|
+
documents_missing Fernhollow Rx audit AUD-301: 2 document(s) still not ready: RX-7102: Signature log; RX-7103: Wholesaler invoice.
|
|
37
|
+
appeal_closing Fernhollow Rx audit AUD-303: the preliminary finding of 1840 can be appealed until 2026-11-21 (in 6 day(s)).
|
|
38
|
+
appeal_missed Brightmoor Script audit AUD-304: the appeal window for the 960 finding ended 2026-10-01.
|
|
39
|
+
recouped_before_final Fernhollow Rx audit AUD-305: 520 was taken back on 2026-09-10, before a final report.
|
|
40
|
+
|
|
41
|
+
▶ Write the audit list
|
|
42
|
+
status: executed decision: allow
|
|
43
|
+
PBM audits written: 6 audit(s), 2 not answered yet, 6 claim(s) under audit, 3320 in preliminary findings. 6 finding(s): response_overdue 1, response_due_soon 1, documents_missing 1, appeal_closing 1, appeal_missed 1, recouped_before_final 1. Files: fairpractice-out/pbmaudits/pbm-audits.csv, fairpractice-out/pbmaudits/pbm-audits.html.
|
|
44
|
+
|
|
45
|
+
▶ Agent tries to send an audit response itself
|
|
46
|
+
status: blocked decision: block
|
|
47
|
+
reason: Fairpractice PBM Audits never sends documents or responses to an auditor.
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Tools
|
|
51
|
+
|
|
52
|
+
| Tool | What it does | Policy |
|
|
53
|
+
|---|---|---|
|
|
54
|
+
| `pbmaudits_check` | List audits overdue or due soon, documents not ready, appeal windows closing or missed and early recoupments. | runs |
|
|
55
|
+
| `pbmaudits_write_report` | Write pbm-audits.csv (one row per item, with blank owner and decision columns) and pbm-audits.html into out_dir (default fairpractice-out/pbmaudits). | runs |
|
|
56
|
+
| `pbmaudits_recall` | Search this agent's own memory of the customer's setup: accepted facts (in use) and facts waiting for a person. | runs |
|
|
57
|
+
| `pbmaudits_learn` | Propose one fact about the customer's setup for this agent to remember. | runs |
|
|
58
|
+
| `pbmaudits_accept_learning` | A named person accepts or rejects a fact waiting in this agent's memory. | one named click, even in Auto (`accept_learning`) |
|
|
59
|
+
| `pbmaudits_retire_memory` | A named person stops an accepted fact from applying. | one named click, even in Auto (`accept_learning`) |
|
|
60
|
+
| `audit_response_send` | Fairpractice PBM Audits never sends documents or responses to an auditor. | refused |
|
|
61
|
+
| `appeal_submit` | Fairpractice PBM Audits never files an appeal. | refused |
|
|
62
|
+
|
|
63
|
+
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.
|
|
64
|
+
|
|
65
|
+
### `pbmaudits_check` arguments
|
|
66
|
+
|
|
67
|
+
| Argument | What it is |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `audits` (required) | PBM audit log under --root: audit, PBM, type, notice and due dates, date sent, preliminary report date and amount, appeal deadline and date filed, final report date and amount, amount and date recouped |
|
|
70
|
+
| `audit_claims` | Optional claim checklist per audit: audit, Rx number, document needed and whether it is ready |
|
|
71
|
+
| `settings` | Optional settings JSON: warn_days, appeal_days |
|
|
72
|
+
| `as_of` | Date to measure deadlines and ages from (YYYY-MM-DD); default today |
|
|
73
|
+
| `status` | Only items with this status |
|
|
74
|
+
| `limit` | Most items to return to the model (the report file always has all of them) |
|
|
75
|
+
|
|
76
|
+
## Columns it reads
|
|
77
|
+
|
|
78
|
+
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.
|
|
79
|
+
|
|
80
|
+
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-pbm-audits inspect <file>` (column names and shapes only, never values) and name any column it misses in `remedy-sources.json`.
|
|
81
|
+
|
|
82
|
+
### PBM audit log (`audits`)
|
|
83
|
+
|
|
84
|
+
| Column | Type | Read from |
|
|
85
|
+
|---|---|---|
|
|
86
|
+
| `audit_id` (required) | text | Audit ID, Audit #, Case #, Reference, Audit Number |
|
|
87
|
+
| `pbm` | text | PBM, Auditor, Payer, Plan |
|
|
88
|
+
| `type` | text | Type, Audit Type, Desk or Onsite |
|
|
89
|
+
| `notice_date` | date | Notice Date, Letter Date, Received |
|
|
90
|
+
| `due_date` | date | Due Date, Response Due, Documents Due |
|
|
91
|
+
| `submitted` | date | Submitted, Response Sent, Sent, Documents Sent |
|
|
92
|
+
| `prelim_date` | date | Preliminary Date, Prelim Report Date, Draft Report Date |
|
|
93
|
+
| `prelim_amount` | amount | Preliminary Amount, Prelim Amount, Discrepancy Amount, Amount at Risk |
|
|
94
|
+
| `appeal_by` | date | Appeal By, Appeal Deadline, Dispute Deadline |
|
|
95
|
+
| `appeal_filed` | date | Appeal Filed, Appealed On, Dispute Sent |
|
|
96
|
+
| `final_date` | date | Final Date, Final Report Date |
|
|
97
|
+
| `final_amount` | amount | Final Amount, Final Recovery |
|
|
98
|
+
| `recouped` | amount | Recouped, Amount Recouped, Clawback, Offset |
|
|
99
|
+
| `recouped_on` | date | Recouped On, Recoupment Date, Clawback Date |
|
|
100
|
+
|
|
101
|
+
### Audit claim checklist (`audit_claims`)
|
|
102
|
+
|
|
103
|
+
| Column | Type | Read from |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| `audit_id` (required) | text | Audit ID, Audit #, Case #, Reference |
|
|
106
|
+
| `rx_number` | text | Rx #, Rx Number, Prescription #, Claim # |
|
|
107
|
+
| `document` | text | Document, Document Needed, Item Needed, Requested Item |
|
|
108
|
+
| `ready` | text | Ready, Found, Collected, In Packet, Done |
|
|
109
|
+
|
|
110
|
+
## Settings file (`pbmaudits_settings`)
|
|
111
|
+
|
|
112
|
+
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.
|
|
113
|
+
|
|
114
|
+
| Setting | What it does |
|
|
115
|
+
|---|---|
|
|
116
|
+
| `warn_days` | Days ahead to warn about due dates and appeal deadlines; default 7 |
|
|
117
|
+
| `appeal_days` | Days after the preliminary report to appeal when the log has no appeal date (check each PBM contract and state law); default 30 |
|
|
118
|
+
|
|
119
|
+
## Memory
|
|
120
|
+
|
|
121
|
+
`pbmaudits_learn` only proposes a fact; nothing changes until a named person accepts it with `pbmaudits_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.
|
|
122
|
+
|
|
123
|
+
| Kind | What an accepted fact does |
|
|
124
|
+
|---|---|
|
|
125
|
+
|
|
126
|
+
## Install
|
|
127
|
+
|
|
128
|
+
Node 20 or newer. No other runtime dependencies besides `fairpractice-core` and `fairclaim-core`.
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{
|
|
132
|
+
"mcpServers": {
|
|
133
|
+
"fairpractice-pbm-audits": {
|
|
134
|
+
"command": "npx",
|
|
135
|
+
"args": [
|
|
136
|
+
"-y",
|
|
137
|
+
"fairpractice-pbm-audits",
|
|
138
|
+
"mcp",
|
|
139
|
+
"--root",
|
|
140
|
+
"/path/to/practice-files"
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Claude Code: `claude mcp add fairpractice-pbm-audits -- npx -y fairpractice-pbm-audits mcp --root .`, or use the plugin files in this folder.
|
|
148
|
+
|
|
149
|
+
## CLI
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
fairpractice-pbm-audits tools # every tool, its policy and arguments
|
|
153
|
+
fairpractice-pbm-audits sources # the columns each input is read from
|
|
154
|
+
fairpractice-pbm-audits inspect <file> # how a file would be read (names and shapes, never values)
|
|
155
|
+
fairpractice-pbm-audits call pbmaudits_check '{"audits":"<audits>"}'
|
|
156
|
+
fairpractice-pbm-audits eval # the private eval cases on the fictional fixtures
|
|
157
|
+
fairpractice-pbm-audits demo
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Patient and staff data
|
|
161
|
+
|
|
162
|
+
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.
|
|
163
|
+
|
|
164
|
+
## Limits
|
|
165
|
+
|
|
166
|
+
- 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.
|
|
167
|
+
- 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.
|
|
168
|
+
- 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.
|
|
169
|
+
- 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-pbm-audits', demo, evalFile: fileURLToPath(new URL('../evals/cases.json', import.meta.url)) });
|
package/evals/cases.json
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
{
|
|
2
|
+
"suite": "fairpractice-pbm-audits",
|
|
3
|
+
"root": "..",
|
|
4
|
+
"data_note": "Fictional data in ../fixtures. Deterministic checks; no model is called.",
|
|
5
|
+
"no_names_in_report": true,
|
|
6
|
+
"cases": [
|
|
7
|
+
{
|
|
8
|
+
"id": "recall-empty-memory",
|
|
9
|
+
"tool": "pbmaudits_recall",
|
|
10
|
+
"args": {},
|
|
11
|
+
"expect": {
|
|
12
|
+
"status": "executed",
|
|
13
|
+
"contains": [
|
|
14
|
+
"memory is empty"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"id": "refuses-audit_response_send",
|
|
20
|
+
"tool": "audit_response_send",
|
|
21
|
+
"args": {},
|
|
22
|
+
"expect": {
|
|
23
|
+
"status": "blocked"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"id": "refuses-appeal_submit",
|
|
28
|
+
"tool": "appeal_submit",
|
|
29
|
+
"args": {},
|
|
30
|
+
"expect": {
|
|
31
|
+
"status": "blocked"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"id": "report",
|
|
36
|
+
"tool": "pbmaudits_write_report",
|
|
37
|
+
"args": {
|
|
38
|
+
"audits": "fixtures/audits.csv",
|
|
39
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
40
|
+
"settings": "fixtures/settings.json",
|
|
41
|
+
"as_of": "2026-11-15"
|
|
42
|
+
},
|
|
43
|
+
"expect": {
|
|
44
|
+
"status": "executed",
|
|
45
|
+
"matches": [
|
|
46
|
+
"\\.csv",
|
|
47
|
+
"\\.html"
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"id": "totals",
|
|
53
|
+
"tool": "pbmaudits_check",
|
|
54
|
+
"args": {
|
|
55
|
+
"audits": "fixtures/audits.csv",
|
|
56
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
57
|
+
"settings": "fixtures/settings.json",
|
|
58
|
+
"as_of": "2026-11-15"
|
|
59
|
+
},
|
|
60
|
+
"expect": {
|
|
61
|
+
"status": "executed",
|
|
62
|
+
"equals": {
|
|
63
|
+
"result.audits": 6,
|
|
64
|
+
"result.open": 2,
|
|
65
|
+
"result.claims_under_audit": 6,
|
|
66
|
+
"result.at_stake": 3320
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"id": "every-planted-status-in-order",
|
|
72
|
+
"tool": "pbmaudits_check",
|
|
73
|
+
"args": {
|
|
74
|
+
"audits": "fixtures/audits.csv",
|
|
75
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
76
|
+
"settings": "fixtures/settings.json",
|
|
77
|
+
"as_of": "2026-11-15"
|
|
78
|
+
},
|
|
79
|
+
"expect": {
|
|
80
|
+
"equals": {
|
|
81
|
+
"result.items.0.status": "response_overdue",
|
|
82
|
+
"result.items.1.status": "response_due_soon",
|
|
83
|
+
"result.items.2.status": "documents_missing",
|
|
84
|
+
"result.items.3.status": "appeal_closing",
|
|
85
|
+
"result.items.4.status": "appeal_missed",
|
|
86
|
+
"result.items.5.status": "recouped_before_final"
|
|
87
|
+
},
|
|
88
|
+
"length": {
|
|
89
|
+
"result.items": 6
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"id": "status-filter",
|
|
95
|
+
"tool": "pbmaudits_check",
|
|
96
|
+
"args": {
|
|
97
|
+
"audits": "fixtures/audits.csv",
|
|
98
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
99
|
+
"settings": "fixtures/settings.json",
|
|
100
|
+
"as_of": "2026-11-15",
|
|
101
|
+
"status": "response_overdue"
|
|
102
|
+
},
|
|
103
|
+
"expect": {
|
|
104
|
+
"status": "executed",
|
|
105
|
+
"equals": {
|
|
106
|
+
"result.items.0.status": "response_overdue"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"id": "limit-one",
|
|
112
|
+
"tool": "pbmaudits_check",
|
|
113
|
+
"args": {
|
|
114
|
+
"audits": "fixtures/audits.csv",
|
|
115
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
116
|
+
"settings": "fixtures/settings.json",
|
|
117
|
+
"as_of": "2026-11-15",
|
|
118
|
+
"limit": 1
|
|
119
|
+
},
|
|
120
|
+
"expect": {
|
|
121
|
+
"status": "executed",
|
|
122
|
+
"length": {
|
|
123
|
+
"result.items": 1
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"id": "report-spanish",
|
|
129
|
+
"tool": "pbmaudits_write_report",
|
|
130
|
+
"args": {
|
|
131
|
+
"audits": "fixtures/audits.csv",
|
|
132
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
133
|
+
"settings": "fixtures/settings.json",
|
|
134
|
+
"as_of": "2026-11-15",
|
|
135
|
+
"language": "es"
|
|
136
|
+
},
|
|
137
|
+
"expect": {
|
|
138
|
+
"status": "executed"
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"id": "report-japanese",
|
|
143
|
+
"tool": "pbmaudits_write_report",
|
|
144
|
+
"args": {
|
|
145
|
+
"audits": "fixtures/audits.csv",
|
|
146
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
147
|
+
"settings": "fixtures/settings.json",
|
|
148
|
+
"as_of": "2026-11-15",
|
|
149
|
+
"language": "ja"
|
|
150
|
+
},
|
|
151
|
+
"expect": {
|
|
152
|
+
"status": "executed",
|
|
153
|
+
"matches": [
|
|
154
|
+
"\\.html"
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"id": "typo-setting-refused",
|
|
160
|
+
"tool": "pbmaudits_check",
|
|
161
|
+
"args": {
|
|
162
|
+
"audits": "fixtures/audits.csv",
|
|
163
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
164
|
+
"settings": "fixtures/settings-typo.json",
|
|
165
|
+
"as_of": "2026-11-15"
|
|
166
|
+
},
|
|
167
|
+
"expect": {
|
|
168
|
+
"status": "error"
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"id": "null-settings-refused",
|
|
173
|
+
"tool": "pbmaudits_check",
|
|
174
|
+
"args": {
|
|
175
|
+
"audits": "fixtures/audits.csv",
|
|
176
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
177
|
+
"settings": null,
|
|
178
|
+
"as_of": "2026-11-15"
|
|
179
|
+
},
|
|
180
|
+
"expect": {
|
|
181
|
+
"status": "error"
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"id": "file-outside-root-refused",
|
|
186
|
+
"tool": "pbmaudits_check",
|
|
187
|
+
"args": {
|
|
188
|
+
"audits": "../../outside-root.csv",
|
|
189
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
190
|
+
"settings": "fixtures/settings.json",
|
|
191
|
+
"as_of": "2026-11-15"
|
|
192
|
+
},
|
|
193
|
+
"expect": {
|
|
194
|
+
"status": "error",
|
|
195
|
+
"contains": [
|
|
196
|
+
"outside the allowed root"
|
|
197
|
+
]
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"id": "missing-file-named",
|
|
202
|
+
"tool": "pbmaudits_check",
|
|
203
|
+
"args": {
|
|
204
|
+
"audits": "fixtures/missing-export.csv",
|
|
205
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
206
|
+
"settings": "fixtures/settings.json",
|
|
207
|
+
"as_of": "2026-11-15"
|
|
208
|
+
},
|
|
209
|
+
"expect": {
|
|
210
|
+
"status": "error",
|
|
211
|
+
"contains": [
|
|
212
|
+
"not found",
|
|
213
|
+
"missing-export.csv"
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"id": "no-settings-defaults",
|
|
219
|
+
"tool": "pbmaudits_check",
|
|
220
|
+
"args": {
|
|
221
|
+
"audits": "fixtures/audits.csv",
|
|
222
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
223
|
+
"as_of": "2026-11-15"
|
|
224
|
+
},
|
|
225
|
+
"expect": {
|
|
226
|
+
"status": "executed",
|
|
227
|
+
"equals": {
|
|
228
|
+
"result.by_status.appeal_closing": 1,
|
|
229
|
+
"result.by_status.response_overdue": 1
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"id": "missing-documents-named",
|
|
235
|
+
"tool": "pbmaudits_check",
|
|
236
|
+
"args": {
|
|
237
|
+
"audits": "fixtures/audits.csv",
|
|
238
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
239
|
+
"settings": "fixtures/settings.json",
|
|
240
|
+
"as_of": "2026-11-15",
|
|
241
|
+
"status": "documents_missing"
|
|
242
|
+
},
|
|
243
|
+
"expect": {
|
|
244
|
+
"equals": {
|
|
245
|
+
"result.items.0.audit_id": "AUD-301",
|
|
246
|
+
"result.items.0.missing_count": 2
|
|
247
|
+
},
|
|
248
|
+
"contains": [
|
|
249
|
+
"RX-7102: Signature log",
|
|
250
|
+
"RX-7103: Wholesaler invoice"
|
|
251
|
+
]
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
"id": "appeal-from-prelim-date",
|
|
256
|
+
"tool": "pbmaudits_check",
|
|
257
|
+
"args": {
|
|
258
|
+
"audits": "fixtures/audits.csv",
|
|
259
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
260
|
+
"settings": "fixtures/settings.json",
|
|
261
|
+
"as_of": "2026-11-15",
|
|
262
|
+
"status": "appeal_closing"
|
|
263
|
+
},
|
|
264
|
+
"expect": {
|
|
265
|
+
"equals": {
|
|
266
|
+
"result.items.0.audit_id": "AUD-303",
|
|
267
|
+
"result.items.0.appeal_by": "2026-11-21",
|
|
268
|
+
"result.items.0.days": 6
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
"id": "early-recoupment",
|
|
274
|
+
"tool": "pbmaudits_check",
|
|
275
|
+
"args": {
|
|
276
|
+
"audits": "fixtures/audits.csv",
|
|
277
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
278
|
+
"settings": "fixtures/settings.json",
|
|
279
|
+
"as_of": "2026-11-15",
|
|
280
|
+
"status": "recouped_before_final"
|
|
281
|
+
},
|
|
282
|
+
"expect": {
|
|
283
|
+
"equals": {
|
|
284
|
+
"result.items.0.audit_id": "AUD-305",
|
|
285
|
+
"result.items.0.amount": 520
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
"id": "without-checklist",
|
|
291
|
+
"tool": "pbmaudits_check",
|
|
292
|
+
"args": {
|
|
293
|
+
"audits": "fixtures/audits.csv",
|
|
294
|
+
"settings": "fixtures/settings.json",
|
|
295
|
+
"as_of": "2026-11-15"
|
|
296
|
+
},
|
|
297
|
+
"expect": {
|
|
298
|
+
"status": "executed",
|
|
299
|
+
"not_contains": [
|
|
300
|
+
"\"documents_missing\""
|
|
301
|
+
]
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
"id": "closed-audit-not-listed",
|
|
306
|
+
"tool": "pbmaudits_check",
|
|
307
|
+
"args": {
|
|
308
|
+
"audits": "fixtures/audits.csv",
|
|
309
|
+
"audit_claims": "fixtures/audit-claims.csv",
|
|
310
|
+
"settings": "fixtures/settings.json",
|
|
311
|
+
"as_of": "2026-11-15"
|
|
312
|
+
},
|
|
313
|
+
"expect": {
|
|
314
|
+
"not_contains": [
|
|
315
|
+
"AUD-306"
|
|
316
|
+
]
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
]
|
|
320
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Fixtures
|
|
2
|
+
|
|
3
|
+
Fictional data only: Main Street Pharmacy and made-up PBMs (Fernhollow Rx, Brightmoor Script). No prescription content is included; the checklist names documents only. Checked on 15 November 2026.
|
|
4
|
+
|
|
5
|
+
- `audits.csv`: six audits. Planted: AUD-301 was due 10 November and not sent; AUD-302 is due 19 November; AUD-303's preliminary finding of 1,840.00 (22 October) can be appealed for 30 days, to 21 November; AUD-304's appeal deadline of 1 October passed with no appeal; AUD-305 had 520.00 taken back on 10 September with no final report. AUD-306 closed with nothing owed.
|
|
6
|
+
- `audit-claims.csv`: AUD-301 still lacks a signature log and an invoice.
|
|
7
|
+
- `settings.json`: a 7-day warning and 30 days to appeal when the letter gives no date. Check each PBM contract and your state's pharmacy audit law. `settings-typo.json` misspells a setting and is refused.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
{
|
|
2
|
+
"case": "totals",
|
|
3
|
+
"id": [
|
|
4
|
+
[
|
|
5
|
+
"audit_id"
|
|
6
|
+
]
|
|
7
|
+
],
|
|
8
|
+
"planted": [
|
|
9
|
+
["AUD-301", "response_overdue"],
|
|
10
|
+
["AUD-302", "response_due_soon"],
|
|
11
|
+
["AUD-301", "documents_missing"],
|
|
12
|
+
["AUD-303", "appeal_closing"],
|
|
13
|
+
["AUD-304", "appeal_missed"],
|
|
14
|
+
["AUD-305", "recouped_before_final"]
|
|
15
|
+
],
|
|
16
|
+
"clean": [
|
|
17
|
+
{
|
|
18
|
+
"arg": "audits",
|
|
19
|
+
"set": [
|
|
20
|
+
{
|
|
21
|
+
"where": ["Audit ID", "AUD-301"],
|
|
22
|
+
"column": "Response Sent",
|
|
23
|
+
"value": "2026-11-08"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"where": ["Audit ID", "AUD-302"],
|
|
27
|
+
"column": "Response Sent",
|
|
28
|
+
"value": "2026-11-12"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"where": ["Audit ID", "AUD-303"],
|
|
32
|
+
"column": "Appeal Filed",
|
|
33
|
+
"value": "2026-11-01"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"where": ["Audit ID", "AUD-304"],
|
|
37
|
+
"column": "Appeal Filed",
|
|
38
|
+
"value": "2026-09-20"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"where": ["Audit ID", "AUD-305"],
|
|
42
|
+
"column": "Final Report Date",
|
|
43
|
+
"value": "2026-09-01"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"where": ["Audit ID", "AUD-305"],
|
|
47
|
+
"column": "Final Amount",
|
|
48
|
+
"value": "520.00"
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"arg": "audit_claims",
|
|
54
|
+
"set": [
|
|
55
|
+
{
|
|
56
|
+
"where": ["Rx #", "RX-7102"],
|
|
57
|
+
"column": "In Packet",
|
|
58
|
+
"value": "yes"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"where": ["Rx #", "RX-7103"],
|
|
62
|
+
"column": "In Packet",
|
|
63
|
+
"value": "yes"
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"mutations": [
|
|
69
|
+
{
|
|
70
|
+
"name": "response not sent although the packet is complete",
|
|
71
|
+
"edits": [
|
|
72
|
+
{
|
|
73
|
+
"arg": "audits",
|
|
74
|
+
"set": [
|
|
75
|
+
{
|
|
76
|
+
"where": ["Audit ID", "AUD-301"],
|
|
77
|
+
"column": "Response Sent",
|
|
78
|
+
"value": ""
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
"expect": [
|
|
84
|
+
["AUD-301", "response_overdue"]
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"name": "a new desk audit due in three days",
|
|
89
|
+
"edits": [
|
|
90
|
+
{
|
|
91
|
+
"arg": "audits",
|
|
92
|
+
"add": [
|
|
93
|
+
{
|
|
94
|
+
"Audit ID": "AUD-307",
|
|
95
|
+
"PBM": "Brightmoor Script",
|
|
96
|
+
"Audit Type": "Desk",
|
|
97
|
+
"Notice Date": "2026-11-10",
|
|
98
|
+
"Due Date": "2026-11-18"
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
"expect": [
|
|
104
|
+
["AUD-307", "response_due_soon"]
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Audit ID,Rx #,Document Needed,In Packet
|
|
2
|
+
AUD-301,RX-7101,Prescription image,yes
|
|
3
|
+
AUD-301,RX-7102,Signature log,no
|
|
4
|
+
AUD-301,RX-7103,Wholesaler invoice,no
|
|
5
|
+
AUD-302,RX-7201,Prescription image,yes
|
|
6
|
+
AUD-302,RX-7202,Prescriber verification,yes
|
|
7
|
+
AUD-303,RX-7301,Signature log,yes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Audit ID,PBM,Audit Type,Notice Date,Due Date,Response Sent,Prelim Report Date,Preliminary Amount,Appeal Deadline,Appeal Filed,Final Report Date,Final Amount,Amount Recouped,Recoupment Date
|
|
2
|
+
AUD-301,Fernhollow Rx,Desk,2026-10-20,2026-11-10,,,,,,,,,
|
|
3
|
+
AUD-302,Brightmoor Script,Desk,2026-11-02,2026-11-19,,,,,,,,,
|
|
4
|
+
AUD-303,Fernhollow Rx,Onsite,2026-08-15,2026-09-10,2026-09-05,2026-10-22,1840.00,,,,,,
|
|
5
|
+
AUD-304,Brightmoor Script,Desk,2026-07-01,2026-07-25,2026-07-20,2026-09-01,960.00,2026-10-01,,,,,
|
|
6
|
+
AUD-305,Fernhollow Rx,Desk,2026-06-01,2026-06-25,2026-06-20,2026-08-01,520.00,,2026-08-20,,,520.00,2026-09-10
|
|
7
|
+
AUD-306,Brightmoor Script,Desk,2026-05-01,2026-05-28,2026-05-25,2026-07-01,0.00,,,2026-08-01,0.00,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "note": "This agent reads no patient data. The canaries are checklist rows already in the packet, which must never reach a result.", "values": ["RX-7101", "RX-7202", "Prescriber verification"] }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "warning_days": 7 }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "warn_days": 7, "appeal_days": 30 }
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fairpractice-pbm-audits",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"mcpName": "io.github.fpavia111-creator/fairpractice-pbm-audits",
|
|
5
|
+
"description": "PBM audit tracker for pharmacies: audit responses overdue or due soon, claims still missing documents, appeal windows closing or missed, and amounts taken back before the final report.",
|
|
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-pbm-audits": "bin/fairpractice-pbm-audits.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-pbm-audits.js demo",
|
|
33
|
+
"eval": "node bin/fairpractice-pbm-audits.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-pbm-audits"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/fpavia111-creator/fairpractice2-agents/tree/master/packages/fairpractice-pbm-audits#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
|
+
"pharmacy",
|
|
55
|
+
"pbm-audit",
|
|
56
|
+
"appeals",
|
|
57
|
+
"recoupments"
|
|
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-pbm-audits",
|
|
4
|
+
"title": "Fairpractice PBM Audits",
|
|
5
|
+
"description": "PBM audit tracker for pharmacies",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"url": "https://github.com/fpavia111-creator/fairpractice2-agents",
|
|
9
|
+
"source": "github",
|
|
10
|
+
"subfolder": "packages/fairpractice-pbm-audits"
|
|
11
|
+
},
|
|
12
|
+
"websiteUrl": "https://fair-agents.com/fairpractice.html",
|
|
13
|
+
"packages": [
|
|
14
|
+
{
|
|
15
|
+
"registryType": "npm",
|
|
16
|
+
"identifier": "fairpractice-pbm-audits",
|
|
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 = { audits: 'audits.csv', audit_claims: 'audit-claims.csv', settings: 'settings.json', as_of: '2026-11-15' };
|
|
5
|
+
export const demo = () => runDemo(manifest, new URL('../fixtures', import.meta.url), 'Fairpractice PBM Audits', [
|
|
6
|
+
{ label: 'Check open PBM audits and their documents', tool: 'pbmaudits_check', args: f, list: (i) => `${i.status.padEnd(22)} ${i.message}` },
|
|
7
|
+
{ label: 'Write the audit list', tool: 'pbmaudits_write_report', args: f },
|
|
8
|
+
{ label: 'Agent tries to send an audit response itself', tool: 'audit_response_send', args: {} },
|
|
9
|
+
]);
|
package/src/index.js
ADDED
package/src/logic.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// PBM audit tracker logic: response due dates, documents still missing per claim, appeal windows and early recoupments. No I/O.
|
|
2
|
+
import { str, num, isoDate, addDays, daysBetween, yes, round2, sortByStatus, countBy } from 'fairpractice-core';
|
|
3
|
+
|
|
4
|
+
const ORDER = { response_overdue: 0, response_due_soon: 1, documents_missing: 2, appeal_closing: 3, appeal_missed: 4, recouped_before_final: 5 };
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* audits: [{ audit_id, pbm, type, notice_date, due_date, submitted, prelim_date, prelim_amount, appeal_by, appeal_filed, final_date, final_amount, recouped, recouped_on }]
|
|
8
|
+
* claims: [{ audit_id, rx_number, document, ready }]
|
|
9
|
+
* opts: { asOf, warnDays = 7, appealDays = 30 }
|
|
10
|
+
*/
|
|
11
|
+
export function checkPbmAudits(audits, claims, { asOf, warnDays = 7, appealDays = 30 } = {}) {
|
|
12
|
+
const missing = new Map(); const claimCount = new Map();
|
|
13
|
+
for (const c of claims) { const k = str(c.audit_id); if (!k) continue; claimCount.set(k, (claimCount.get(k) || new Set()).add(str(c.rx_number))); if (!yes(c.ready)) { if (!missing.has(k)) missing.set(k, []); missing.get(k).push(`${str(c.rx_number)}: ${str(c.document) || 'document'}`); } }
|
|
14
|
+
const items = []; let open = 0;
|
|
15
|
+
for (const [i, a] of audits.entries()) {
|
|
16
|
+
const id = str(a.audit_id) || `line ${i + 1}`; const due = isoDate(a.due_date); const sub = isoDate(a.submitted);
|
|
17
|
+
const base = { audit_id: id, pbm: str(a.pbm) || null, type: str(a.type) || null, due, claims: (claimCount.get(id) || new Set()).size, amount: round2(num(a.prelim_amount) || 0) };
|
|
18
|
+
if (!sub) {
|
|
19
|
+
open++;
|
|
20
|
+
if (due && due < asOf) items.push({ ...base, status: 'response_overdue', days: daysBetween(due, asOf) });
|
|
21
|
+
else if (due && daysBetween(asOf, due) <= warnDays) items.push({ ...base, status: 'response_due_soon', days: daysBetween(asOf, due) });
|
|
22
|
+
const m = missing.get(id); if (m && m.length) items.push({ ...base, status: 'documents_missing', missing: m, missing_count: m.length });
|
|
23
|
+
}
|
|
24
|
+
const prelim = isoDate(a.prelim_date); const amt = num(a.prelim_amount) || 0;
|
|
25
|
+
if (prelim && amt > 0 && !isoDate(a.appeal_filed)) {
|
|
26
|
+
const by = isoDate(a.appeal_by) || addDays(prelim, appealDays); const left = daysBetween(asOf, by);
|
|
27
|
+
if (left < 0) items.push({ ...base, status: 'appeal_missed', appeal_by: by, days: -left });
|
|
28
|
+
else if (left <= warnDays) items.push({ ...base, status: 'appeal_closing', appeal_by: by, days: left });
|
|
29
|
+
}
|
|
30
|
+
const rq = isoDate(a.recouped_on); const fin = isoDate(a.final_date);
|
|
31
|
+
if (rq && (num(a.recouped) || 0) > 0 && (!fin || rq < fin)) items.push({ ...base, status: 'recouped_before_final', recouped_on: rq, final_date: fin, amount: round2(num(a.recouped)) });
|
|
32
|
+
}
|
|
33
|
+
const T = {
|
|
34
|
+
response_overdue: (x) => [`${x.pbm} audit ${x.audit_id} (${x.claims} claim(s)) was due ${x.due} and has not been sent (${x.days} day(s) late).`, 'Send what you have and ask the auditor in writing for time on the rest.'],
|
|
35
|
+
response_due_soon: (x) => [`${x.pbm} audit ${x.audit_id} (${x.claims} claim(s)) is due ${x.due} (in ${x.days} day(s)).`, 'Finish the packet now.'],
|
|
36
|
+
documents_missing: (x) => [`${x.pbm} audit ${x.audit_id}: ${x.missing_count} document(s) still not ready: ${x.missing.slice(0, 5).join('; ')}${x.missing.length > 5 ? '; …' : ''}.`, 'Pull the prescriptions, signature logs and invoices named before the due date.'],
|
|
37
|
+
appeal_closing: (x) => [`${x.pbm} audit ${x.audit_id}: the preliminary finding of ${x.amount} can be appealed until ${x.appeal_by} (in ${x.days} day(s)).`, 'Decide on the appeal and send it with the supporting documents.'],
|
|
38
|
+
appeal_missed: (x) => [`${x.pbm} audit ${x.audit_id}: the appeal window for the ${x.amount} finding ended ${x.appeal_by}.`, 'Ask the PBM whether a late appeal is possible; note it for contract talks.'],
|
|
39
|
+
recouped_before_final: (x) => [`${x.pbm} audit ${x.audit_id}: ${x.amount} was taken back on ${x.recouped_on}, before a final report${x.final_date ? ` (final ${x.final_date})` : ''}.`, 'Check your contract and state pharmacy audit law on recoupment timing, and ask the PBM to return it if it was early.'],
|
|
40
|
+
};
|
|
41
|
+
for (const it of items) { const [m, f] = T[it.status](it); it.message = m; it.fix = f; }
|
|
42
|
+
sortByStatus(items, ORDER);
|
|
43
|
+
return { audits: audits.length, open, claims_under_audit: [...claimCount.values()].reduce((s, x) => s + x.size, 0), at_stake: round2(audits.reduce((s, a) => s + (num(a.prelim_amount) || 0), 0)), by_status: countBy(items, 'status'), items };
|
|
44
|
+
}
|
package/src/manifest.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { medAgent, fileArg, AS_OF_ARG, PRACTICE_LIMITS, today } from 'fairpractice-core';
|
|
3
|
+
import { checkPbmAudits } 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
|
+
const D = (aliases) => t(aliases, { type: 'date', translate: false });
|
|
8
|
+
const M = (aliases) => t(aliases, { type: 'money', translate: false });
|
|
9
|
+
|
|
10
|
+
export const AUDIT_FIELDS = Object.freeze({
|
|
11
|
+
audit_id: t(['Audit ID', 'Audit #', 'Case #', 'Reference', 'Audit Number'], { translate: false, required: true }),
|
|
12
|
+
pbm: t(['PBM', 'Auditor', 'Payer', 'Plan'], { translate: 'payer' }),
|
|
13
|
+
type: t(['Type', 'Audit Type', 'Desk or Onsite'], { translate: false }),
|
|
14
|
+
notice_date: D(['Notice Date', 'Letter Date', 'Received']),
|
|
15
|
+
due_date: D(['Due Date', 'Response Due', 'Documents Due']),
|
|
16
|
+
submitted: D(['Submitted', 'Response Sent', 'Sent', 'Documents Sent']),
|
|
17
|
+
prelim_date: D(['Preliminary Date', 'Prelim Report Date', 'Draft Report Date']),
|
|
18
|
+
prelim_amount: M(['Preliminary Amount', 'Prelim Amount', 'Discrepancy Amount', 'Amount at Risk']),
|
|
19
|
+
appeal_by: D(['Appeal By', 'Appeal Deadline', 'Dispute Deadline']),
|
|
20
|
+
appeal_filed: D(['Appeal Filed', 'Appealed On', 'Dispute Sent']),
|
|
21
|
+
final_date: D(['Final Date', 'Final Report Date']),
|
|
22
|
+
final_amount: M(['Final Amount', 'Final Recovery']),
|
|
23
|
+
recouped: M(['Recouped', 'Amount Recouped', 'Clawback', 'Offset']),
|
|
24
|
+
recouped_on: D(['Recouped On', 'Recoupment Date', 'Clawback Date']),
|
|
25
|
+
});
|
|
26
|
+
export const CLAIM_FIELDS = Object.freeze({
|
|
27
|
+
audit_id: t(['Audit ID', 'Audit #', 'Case #', 'Reference'], { translate: false, required: true }),
|
|
28
|
+
rx_number: t(['Rx #', 'Rx Number', 'Prescription #', 'Claim #'], { translate: false }),
|
|
29
|
+
document: t(['Document', 'Document Needed', 'Item Needed', 'Requested Item'], { translate: false }),
|
|
30
|
+
ready: t(['Ready', 'Found', 'Collected', 'In Packet', 'Done'], { translate: false }),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const SETTINGS = { type: 'object', additionalProperties: false, properties: {
|
|
34
|
+
warn_days: { type: 'integer', minimum: 0, maximum: 60, description: 'Days ahead to warn about due dates and appeal deadlines; default 7' },
|
|
35
|
+
appeal_days: { type: 'integer', minimum: 1, maximum: 180, description: 'Days after the preliminary report to appeal when the log has no appeal date (check each PBM contract and state law); default 30' },
|
|
36
|
+
} };
|
|
37
|
+
|
|
38
|
+
const args = {
|
|
39
|
+
audits: fileArg('PBM audit log under --root: audit, PBM, type, notice and due dates, date sent, preliminary report date and amount, appeal deadline and date filed, final report date and amount, amount and date recouped'),
|
|
40
|
+
audit_claims: fileArg('Optional claim checklist per audit: audit, Rx number, document needed and whether it is ready'),
|
|
41
|
+
settings: fileArg('Optional settings JSON: warn_days, appeal_days'),
|
|
42
|
+
as_of: AS_OF_ARG,
|
|
43
|
+
};
|
|
44
|
+
const run = (a, ctx) => {
|
|
45
|
+
const s = a.settings ? ctx.readJson(a.settings, 'pbmaudits_settings') : {};
|
|
46
|
+
return checkPbmAudits(ctx.records(a.audits, 'audits'), a.audit_claims ? ctx.records(a.audit_claims, 'claims') : [], { asOf: a.as_of || today(), warnDays: s.warn_days ?? 7, appealDays: s.appeal_days ?? 30 });
|
|
47
|
+
};
|
|
48
|
+
const summary = (o) => `${o.audits} audit(s), ${o.open} not answered yet, ${o.claims_under_audit} claim(s) under audit, ${o.at_stake} in preliminary findings. ${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'}.`;
|
|
49
|
+
|
|
50
|
+
export const manifest = medAgent({
|
|
51
|
+
pkg, prefix: 'pbmaudits', title: 'Fairpractice PBM Audits',
|
|
52
|
+
description: 'Tracks PBM audits for a pharmacy: responses overdue or due soon, claims whose documents are still not ready, appeal windows on preliminary findings closing or missed, and money taken back before a final report. Administrative only; no patient data is needed.',
|
|
53
|
+
args, required: ['audits'],
|
|
54
|
+
sources: { audits: { label: 'PBM audit log', args: ['audits'], fields: AUDIT_FIELDS }, claims: { label: 'Audit claim checklist', args: ['audit_claims'], fields: CLAIM_FIELDS } },
|
|
55
|
+
configSchemas: { pbmaudits_settings: SETTINGS }, memoryKinds: {},
|
|
56
|
+
run, summary,
|
|
57
|
+
check: { title: 'Check PBM audits', description: 'List audits overdue or due soon, documents not ready, appeal windows closing or missed and early recoupments.' },
|
|
58
|
+
report: {
|
|
59
|
+
title: { en: 'PBM audits', es: 'Auditorías de PBM', de: 'PBM-Prüfungen', fr: 'Audits des PBM', pt: 'Auditorias de PBM', it: 'Audit dei PBM', ja: 'PBM監査', zh: 'PBM审计', ko: 'PBM 감사' },
|
|
60
|
+
base: 'pbm-audits',
|
|
61
|
+
rows: (o) => o.items.map((i) => ({ status: i.status, audit_id: i.audit_id, pbm: i.pbm || '', type: i.type || '', due: i.due || '', claims: i.claims, amount: i.amount, message: i.message, fix: i.fix })),
|
|
62
|
+
htmlColumns: ['status', 'audit_id', 'pbm', 'due', 'claims', 'amount', 'message', 'fix'],
|
|
63
|
+
sections: (o) => [{ title: { en: 'Findings by type' }, rows: Object.entries(o.by_status).map(([status, count]) => ({ status, count })), columns: ['status', 'count'] }],
|
|
64
|
+
limits: [PRACTICE_LIMITS.files, 'Response and appeal windows and recoupment timing are set by each PBM contract and many state pharmacy audit laws; record the dates from the letters. It reads no prescriptions.', PRACTICE_LIMITS.advice],
|
|
65
|
+
},
|
|
66
|
+
refused: [
|
|
67
|
+
{ name: 'audit_response_send', category: 'binding_send', description: 'Fairpractice PBM Audits never sends documents or responses to an auditor.' },
|
|
68
|
+
{ name: 'appeal_submit', category: 'binding_send', description: 'Fairpractice PBM Audits never files an appeal.' },
|
|
69
|
+
],
|
|
70
|
+
prompt: { title: 'PBM audit review', description: 'Walks the host model through a weekly PBM audit review.', text: `You are helping a pharmacy owner or manager with fairpractice-pbm-audits.
|
|
71
|
+
|
|
72
|
+
Rules: it only reads the audit log and checklist.
|
|
73
|
+
|
|
74
|
+
1. Call pbmaudits_check with the audit log, the claim checklist and as_of.
|
|
75
|
+
2. Lead with response_overdue, response_due_soon and the documents still missing.
|
|
76
|
+
3. Name appeal deadlines and any money taken back early.
|
|
77
|
+
4. Call pbmaudits_write_report.` },
|
|
78
|
+
});
|