fairpractice-payment-window 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 +162 -2
- package/bin/fairpractice-payment-window.js +7 -0
- package/evals/cases.json +286 -0
- package/fixtures/README.md +7 -0
- package/fixtures/accuracy.json +97 -0
- package/fixtures/admissions.csv +6 -0
- package/fixtures/outpatient.csv +9 -0
- package/fixtures/phi-canaries.json +1 -0
- package/fixtures/settings-typo.json +1 -0
- package/fixtures/settings.json +1 -0
- package/package.json +58 -4
- package/server.json +37 -0
- package/src/demo.js +9 -0
- package/src/index.js +2 -0
- package/src/logic.js +39 -0
- package/src/manifest.js +65 -0
- package/src/rev.js +4 -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,163 @@
|
|
|
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 Payment Window (`fairpractice-payment-window`)
|
|
4
|
+
|
|
5
|
+
Checks the three-day payment window: outpatient services at the same hospital in the days before an inpatient admission (the admission day included), diagnostic ones that belong on the inpatient claim and non-diagnostic ones for a person to review, with the dollars already billed on separate claims. Ambulance and maintenance dialysis are left out. Patient names are masked before results reach the model.
|
|
6
|
+
|
|
7
|
+
**Fairpractice Payment Window never cancels, adjusts or rebills a claim. Fairpractice Payment Window never moves charges between accounts in the billing system.**
|
|
8
|
+
|
|
9
|
+
Fairpractice wave 2 ver 1 · Coding integrity (no reading of notes, no code suggestions) · 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-payment-window demo
|
|
13
|
+
npx -y fairpractice-payment-window mcp --root ./practice-files
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## What the sample data shows
|
|
17
|
+
|
|
18
|
+
Fictional data only: Elmswood Community Hospital, Hollowbrook Medical Center (both made up) and made-up patients.
|
|
19
|
+
|
|
20
|
+
- [`admissions.csv`](fixtures/admissions.csv): five inpatient stays.
|
|
21
|
+
- [`outpatient.csv`](fixtures/outpatient.csv): Planted: Anton Reyes had a blood count (48.00) and a head CT (1,450.00) two days before his 5 October admission, both already billed on their own claims, and an ambulance trip the same day (left out); Bettina Shore had an ECG on her admission day (diagnostic, not billed yet) and a clinic visit two days before (non-diagnostic, for review). Corwin Bale's x-ray was seven days before (outside the window), Delphine Okoye's lab was at another hospital, and Emmett Vane's dialysis is left out.
|
|
22
|
+
- [`settings.json`](fixtures/settings.json): a three-day window; the excluded and diagnostic revenue code lists use the defaults. [`settings-typo.json`](fixtures/settings-typo.json) misspells a setting and is refused.
|
|
23
|
+
|
|
24
|
+
## A demo run
|
|
25
|
+
|
|
26
|
+
`npx -y fairpractice-payment-window demo` runs the agent on the fictional files in [`fixtures/`](fixtures) in a temporary folder. Captured output:
|
|
27
|
+
|
|
28
|
+
```text
|
|
29
|
+
Fairpractice Payment Window demo (fictional practice, patients, staff and payers)
|
|
30
|
+
|
|
31
|
+
▶ Check outpatient lines before each admission
|
|
32
|
+
status: executed decision: allow
|
|
33
|
+
5 admission(s), 4 outpatient line(s) in the window (2 left out as ambulance or dialysis). 4 finding(s): diagnostic_in_window 3, nondiagnostic_review 1. Already billed separately: 1498.
|
|
34
|
+
diagnostic_in_window Outpatient 70450 (rev 0350) on 2026-10-03, 2 day(s) before the 2026-10-05 admission, already billed on its own claim.
|
|
35
|
+
diagnostic_in_window Outpatient 93000 (rev 0730) on 2026-10-12, 0 day(s) before the 2026-10-12 admission.
|
|
36
|
+
diagnostic_in_window Outpatient 85025 (rev 0300) on 2026-10-03, 2 day(s) before the 2026-10-05 admission, already billed on its own claim.
|
|
37
|
+
nondiagnostic_review Outpatient 99213 (rev 0510) on 2026-10-10, 2 day(s) before the 2026-10-12 admission.
|
|
38
|
+
|
|
39
|
+
▶ Write the billing list
|
|
40
|
+
status: executed decision: allow
|
|
41
|
+
Three-day payment window written: 5 admission(s), 4 outpatient line(s) in the window (2 left out as ambulance or dialysis). 4 finding(s): diagnostic_in_window 3, nondiagnostic_review 1. Already billed separately: 1498. Files: fairpractice-out/window/payment-window.csv, fairpractice-out/window/payment-window.html.
|
|
42
|
+
|
|
43
|
+
▶ Agent tries to rebill a claim itself
|
|
44
|
+
status: blocked decision: block
|
|
45
|
+
reason: Fairpractice Payment Window never cancels, adjusts or rebills a claim.
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Tools
|
|
49
|
+
|
|
50
|
+
| Tool | What it does | Policy |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| `window_check` | List outpatient lines in the window before an admission: diagnostic ones to move to the inpatient claim and non-diagnostic ones to review. | runs |
|
|
53
|
+
| `window_write_report` | Write payment-window.csv (one row per item, with blank owner and decision columns) and payment-window.html into out_dir (default fairpractice-out/window). | runs |
|
|
54
|
+
| `window_recall` | Search this agent's own memory of the customer's setup: accepted facts (in use) and facts waiting for a person. | runs |
|
|
55
|
+
| `window_learn` | Propose one fact about the customer's setup for this agent to remember. | runs |
|
|
56
|
+
| `window_accept_learning` | A named person accepts or rejects a fact waiting in this agent's memory. | one named click, even in Auto (`accept_learning`) |
|
|
57
|
+
| `window_retire_memory` | A named person stops an accepted fact from applying. | one named click, even in Auto (`accept_learning`) |
|
|
58
|
+
| `claim_rebill` | Fairpractice Payment Window never cancels, adjusts or rebills a claim. | refused |
|
|
59
|
+
| `charge_move` | Fairpractice Payment Window never moves charges between accounts in the billing system. | refused |
|
|
60
|
+
|
|
61
|
+
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.
|
|
62
|
+
|
|
63
|
+
### `window_check` arguments
|
|
64
|
+
|
|
65
|
+
| Argument | What it is |
|
|
66
|
+
|---|---|
|
|
67
|
+
| `outpatient` (required) | Outpatient claim lines under --root: account, patient, date of service, revenue code, CPT/HCPCS, charge, facility and bill status |
|
|
68
|
+
| `inpatient` (required) | Inpatient admissions: account, patient, admit and discharge dates, facility |
|
|
69
|
+
| `settings` | Optional settings JSON: window_days, excluded_rev, diagnostic_rev |
|
|
70
|
+
| `status` | Only items with this status |
|
|
71
|
+
| `limit` | Most items to return to the model (the report file always has all of them) |
|
|
72
|
+
|
|
73
|
+
## Columns it reads
|
|
74
|
+
|
|
75
|
+
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.
|
|
76
|
+
|
|
77
|
+
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-payment-window inspect <file>` (column names and shapes only, never values) and name any column it misses in `remedy-sources.json`.
|
|
78
|
+
|
|
79
|
+
### Outpatient claim lines (`outpatient`)
|
|
80
|
+
|
|
81
|
+
| Column | Type | Read from |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| `account` | text (masked) | Account, Account #, Account Number, Patient Account, Acct, Acct #, Encounter #, HAR |
|
|
84
|
+
| `patient_id` (required) | text (masked) | Patient ID, Patient #, Patient Number, MRN, Medical Record Number, Chart #, Chart Number, Account # |
|
|
85
|
+
| `patient_name` | text (masked) | Patient, Patient Name, Name, Client, Client Name, Member, Member Name, Beneficiary |
|
|
86
|
+
| `dos` (required) | date | Date of Service, DOS, Service Date, Visit Date, Date, From DOS, Session Date, Appointment Date |
|
|
87
|
+
| `rev_code` | text | Revenue Code, Rev Code, Rev, UB Rev Code, RC, Rev Cd |
|
|
88
|
+
| `cpt` | text | CPT, Code, Procedure, Procedure Code, CPT/HCPCS, HCPCS, Service Code, Proc Code |
|
|
89
|
+
| `charge` | amount | Charge, Charges, Billed, Billed Amount, Amount, Fee, Total Charge |
|
|
90
|
+
| `facility` | text | Facility, Hospital, Campus, Location, Provider Number, CCN |
|
|
91
|
+
| `claim_status` | text | Claim Status, Bill Status, Billing Status, Status |
|
|
92
|
+
|
|
93
|
+
### Inpatient admissions (`inpatient`)
|
|
94
|
+
|
|
95
|
+
| Column | Type | Read from |
|
|
96
|
+
|---|---|---|
|
|
97
|
+
| `account` | text (masked) | Account, Account #, Account Number, Patient Account, Acct, Acct #, Encounter #, HAR |
|
|
98
|
+
| `patient_id` (required) | text (masked) | Patient ID, Patient #, Patient Number, MRN, Medical Record Number, Chart #, Chart Number, Account # |
|
|
99
|
+
| `admit` (required) | date | Admit Date, Admission Date, Admitted, Admit, Admit Dt |
|
|
100
|
+
| `discharge` | date | Discharge Date, Discharged, Discharge, Disch Date, Discharge Dt |
|
|
101
|
+
| `facility` | text | Facility, Hospital, Campus, Location, Provider Number, CCN |
|
|
102
|
+
|
|
103
|
+
## Settings file (`window_settings`)
|
|
104
|
+
|
|
105
|
+
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.
|
|
106
|
+
|
|
107
|
+
| Setting | What it does |
|
|
108
|
+
|---|---|
|
|
109
|
+
| `window_days` | Days before the admission in the window (3 for most hospitals, 1 for hospitals outside the inpatient prospective payment system); default 3 |
|
|
110
|
+
| `excluded_rev` | Revenue codes left out of the window (ambulance 054x and maintenance dialysis by default) |
|
|
111
|
+
| `diagnostic_rev` | Revenue codes treated as diagnostic (the public list as of 2026 by default); others are listed for a person to review |
|
|
112
|
+
|
|
113
|
+
## Memory
|
|
114
|
+
|
|
115
|
+
`window_learn` only proposes a fact; nothing changes until a named person accepts it with `window_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.
|
|
116
|
+
|
|
117
|
+
| Kind | What an accepted fact does |
|
|
118
|
+
|---|---|
|
|
119
|
+
|
|
120
|
+
## Install
|
|
121
|
+
|
|
122
|
+
Node 20 or newer. No other runtime dependencies besides `fairpractice-core` and `fairclaim-core`.
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"mcpServers": {
|
|
127
|
+
"fairpractice-payment-window": {
|
|
128
|
+
"command": "npx",
|
|
129
|
+
"args": [
|
|
130
|
+
"-y",
|
|
131
|
+
"fairpractice-payment-window",
|
|
132
|
+
"mcp",
|
|
133
|
+
"--root",
|
|
134
|
+
"/path/to/practice-files"
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Claude Code: `claude mcp add fairpractice-payment-window -- npx -y fairpractice-payment-window mcp --root .`, or use the plugin files in this folder.
|
|
142
|
+
|
|
143
|
+
## CLI
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
fairpractice-payment-window tools # every tool, its policy and arguments
|
|
147
|
+
fairpractice-payment-window sources # the columns each input is read from
|
|
148
|
+
fairpractice-payment-window inspect <file> # how a file would be read (names and shapes, never values)
|
|
149
|
+
fairpractice-payment-window call window_check '{"outpatient":"<outpatient>","inpatient":"<inpatient>"}'
|
|
150
|
+
fairpractice-payment-window eval # the private eval cases on the fictional fixtures
|
|
151
|
+
fairpractice-payment-window demo
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Patient and staff data
|
|
155
|
+
|
|
156
|
+
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.
|
|
157
|
+
|
|
158
|
+
## Limits
|
|
159
|
+
|
|
160
|
+
- 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.
|
|
161
|
+
- 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.
|
|
162
|
+
- 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.
|
|
163
|
+
- 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-payment-window', demo, evalFile: fileURLToPath(new URL('../evals/cases.json', import.meta.url)) });
|
package/evals/cases.json
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
{
|
|
2
|
+
"suite": "fairpractice-payment-window",
|
|
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": "window_recall",
|
|
9
|
+
"args": {},
|
|
10
|
+
"expect": {
|
|
11
|
+
"status": "executed",
|
|
12
|
+
"contains": [
|
|
13
|
+
"memory is empty"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"id": "refuses-claim_rebill",
|
|
19
|
+
"tool": "claim_rebill",
|
|
20
|
+
"args": {},
|
|
21
|
+
"expect": {
|
|
22
|
+
"status": "blocked"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"id": "refuses-charge_move",
|
|
27
|
+
"tool": "charge_move",
|
|
28
|
+
"args": {},
|
|
29
|
+
"expect": {
|
|
30
|
+
"status": "blocked"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": "report",
|
|
35
|
+
"tool": "window_write_report",
|
|
36
|
+
"args": {
|
|
37
|
+
"outpatient": "fixtures/outpatient.csv",
|
|
38
|
+
"inpatient": "fixtures/admissions.csv",
|
|
39
|
+
"settings": "fixtures/settings.json"
|
|
40
|
+
},
|
|
41
|
+
"expect": {
|
|
42
|
+
"status": "executed",
|
|
43
|
+
"matches": [
|
|
44
|
+
"\\.csv",
|
|
45
|
+
"\\.html"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"id": "totals",
|
|
51
|
+
"tool": "window_check",
|
|
52
|
+
"args": {
|
|
53
|
+
"outpatient": "fixtures/outpatient.csv",
|
|
54
|
+
"inpatient": "fixtures/admissions.csv",
|
|
55
|
+
"settings": "fixtures/settings.json"
|
|
56
|
+
},
|
|
57
|
+
"expect": {
|
|
58
|
+
"status": "executed",
|
|
59
|
+
"equals": {
|
|
60
|
+
"result.outpatient_lines": 8,
|
|
61
|
+
"result.admissions": 5,
|
|
62
|
+
"result.lines_in_window": 4,
|
|
63
|
+
"result.excluded_in_window": 2,
|
|
64
|
+
"result.billed_separately": 1498
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"id": "every-planted-status-in-order",
|
|
70
|
+
"tool": "window_check",
|
|
71
|
+
"args": {
|
|
72
|
+
"outpatient": "fixtures/outpatient.csv",
|
|
73
|
+
"inpatient": "fixtures/admissions.csv",
|
|
74
|
+
"settings": "fixtures/settings.json"
|
|
75
|
+
},
|
|
76
|
+
"expect": {
|
|
77
|
+
"equals": {
|
|
78
|
+
"result.items.0.status": "diagnostic_in_window",
|
|
79
|
+
"result.items.1.status": "diagnostic_in_window",
|
|
80
|
+
"result.items.2.status": "diagnostic_in_window",
|
|
81
|
+
"result.items.3.status": "nondiagnostic_review"
|
|
82
|
+
},
|
|
83
|
+
"length": {
|
|
84
|
+
"result.items": 4
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"id": "status-filter",
|
|
90
|
+
"tool": "window_check",
|
|
91
|
+
"args": {
|
|
92
|
+
"outpatient": "fixtures/outpatient.csv",
|
|
93
|
+
"inpatient": "fixtures/admissions.csv",
|
|
94
|
+
"settings": "fixtures/settings.json",
|
|
95
|
+
"status": "diagnostic_in_window"
|
|
96
|
+
},
|
|
97
|
+
"expect": {
|
|
98
|
+
"status": "executed",
|
|
99
|
+
"equals": {
|
|
100
|
+
"result.items.0.status": "diagnostic_in_window"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"id": "limit-one",
|
|
106
|
+
"tool": "window_check",
|
|
107
|
+
"args": {
|
|
108
|
+
"outpatient": "fixtures/outpatient.csv",
|
|
109
|
+
"inpatient": "fixtures/admissions.csv",
|
|
110
|
+
"settings": "fixtures/settings.json",
|
|
111
|
+
"limit": 1
|
|
112
|
+
},
|
|
113
|
+
"expect": {
|
|
114
|
+
"status": "executed",
|
|
115
|
+
"length": {
|
|
116
|
+
"result.items": 1
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"id": "report-spanish",
|
|
122
|
+
"tool": "window_write_report",
|
|
123
|
+
"args": {
|
|
124
|
+
"outpatient": "fixtures/outpatient.csv",
|
|
125
|
+
"inpatient": "fixtures/admissions.csv",
|
|
126
|
+
"settings": "fixtures/settings.json",
|
|
127
|
+
"language": "es"
|
|
128
|
+
},
|
|
129
|
+
"expect": {
|
|
130
|
+
"status": "executed"
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"id": "report-japanese",
|
|
135
|
+
"tool": "window_write_report",
|
|
136
|
+
"args": {
|
|
137
|
+
"outpatient": "fixtures/outpatient.csv",
|
|
138
|
+
"inpatient": "fixtures/admissions.csv",
|
|
139
|
+
"settings": "fixtures/settings.json",
|
|
140
|
+
"language": "ja"
|
|
141
|
+
},
|
|
142
|
+
"expect": {
|
|
143
|
+
"status": "executed",
|
|
144
|
+
"matches": [
|
|
145
|
+
"\\.html"
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"id": "typo-setting-refused",
|
|
151
|
+
"tool": "window_check",
|
|
152
|
+
"args": {
|
|
153
|
+
"outpatient": "fixtures/outpatient.csv",
|
|
154
|
+
"inpatient": "fixtures/admissions.csv",
|
|
155
|
+
"settings": "fixtures/settings-typo.json"
|
|
156
|
+
},
|
|
157
|
+
"expect": {
|
|
158
|
+
"status": "error"
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"id": "null-settings-refused",
|
|
163
|
+
"tool": "window_check",
|
|
164
|
+
"args": {
|
|
165
|
+
"outpatient": "fixtures/outpatient.csv",
|
|
166
|
+
"inpatient": "fixtures/admissions.csv",
|
|
167
|
+
"settings": null
|
|
168
|
+
},
|
|
169
|
+
"expect": {
|
|
170
|
+
"status": "error"
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"id": "file-outside-root-refused",
|
|
175
|
+
"tool": "window_check",
|
|
176
|
+
"args": {
|
|
177
|
+
"outpatient": "../../outside-root.csv",
|
|
178
|
+
"inpatient": "fixtures/admissions.csv",
|
|
179
|
+
"settings": "fixtures/settings.json"
|
|
180
|
+
},
|
|
181
|
+
"expect": {
|
|
182
|
+
"status": "error",
|
|
183
|
+
"contains": [
|
|
184
|
+
"outside the allowed root"
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
"id": "missing-file-named",
|
|
190
|
+
"tool": "window_check",
|
|
191
|
+
"args": {
|
|
192
|
+
"outpatient": "fixtures/missing-export.csv",
|
|
193
|
+
"inpatient": "fixtures/admissions.csv",
|
|
194
|
+
"settings": "fixtures/settings.json"
|
|
195
|
+
},
|
|
196
|
+
"expect": {
|
|
197
|
+
"status": "error",
|
|
198
|
+
"contains": [
|
|
199
|
+
"not found",
|
|
200
|
+
"missing-export.csv"
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"id": "no-settings-defaults",
|
|
206
|
+
"tool": "window_check",
|
|
207
|
+
"args": {
|
|
208
|
+
"outpatient": "fixtures/outpatient.csv",
|
|
209
|
+
"inpatient": "fixtures/admissions.csv"
|
|
210
|
+
},
|
|
211
|
+
"expect": {
|
|
212
|
+
"status": "executed",
|
|
213
|
+
"equals": {
|
|
214
|
+
"result.by_status.diagnostic_in_window": 3
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"id": "largest-first-with-admission",
|
|
220
|
+
"tool": "window_check",
|
|
221
|
+
"args": {
|
|
222
|
+
"outpatient": "fixtures/outpatient.csv",
|
|
223
|
+
"inpatient": "fixtures/admissions.csv",
|
|
224
|
+
"settings": "fixtures/settings.json",
|
|
225
|
+
"status": "diagnostic_in_window"
|
|
226
|
+
},
|
|
227
|
+
"expect": {
|
|
228
|
+
"equals": {
|
|
229
|
+
"result.items.0.cpt": "70450",
|
|
230
|
+
"result.items.0.amount": 1450,
|
|
231
|
+
"result.items.0.days_before": 2,
|
|
232
|
+
"result.items.0.admit": "2026-10-05",
|
|
233
|
+
"result.items.0.billed_separately": true
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
"id": "admission-day-not-billed",
|
|
239
|
+
"tool": "window_check",
|
|
240
|
+
"args": {
|
|
241
|
+
"outpatient": "fixtures/outpatient.csv",
|
|
242
|
+
"inpatient": "fixtures/admissions.csv",
|
|
243
|
+
"settings": "fixtures/settings.json",
|
|
244
|
+
"status": "diagnostic_in_window"
|
|
245
|
+
},
|
|
246
|
+
"expect": {
|
|
247
|
+
"equals": {
|
|
248
|
+
"result.items.1.cpt": "93000",
|
|
249
|
+
"result.items.1.days_before": 0,
|
|
250
|
+
"result.items.1.billed_separately": false
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
"id": "accounts-masked-outside-window-not-listed",
|
|
256
|
+
"tool": "window_check",
|
|
257
|
+
"args": {
|
|
258
|
+
"outpatient": "fixtures/outpatient.csv",
|
|
259
|
+
"inpatient": "fixtures/admissions.csv",
|
|
260
|
+
"settings": "fixtures/settings.json"
|
|
261
|
+
},
|
|
262
|
+
"expect": {
|
|
263
|
+
"not_contains": [
|
|
264
|
+
"OP-8002",
|
|
265
|
+
"IP-9001",
|
|
266
|
+
"A0427",
|
|
267
|
+
"71046",
|
|
268
|
+
"80048",
|
|
269
|
+
"90935"
|
|
270
|
+
]
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
"id": "one-day-window",
|
|
275
|
+
"tool": "window_check",
|
|
276
|
+
"args": {
|
|
277
|
+
"outpatient": "fixtures/outpatient.csv",
|
|
278
|
+
"inpatient": "fixtures/admissions.csv",
|
|
279
|
+
"settings": null
|
|
280
|
+
},
|
|
281
|
+
"expect": {
|
|
282
|
+
"status": "error"
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
]
|
|
286
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Fixtures
|
|
2
|
+
|
|
3
|
+
Fictional data only: Elmswood Community Hospital, Hollowbrook Medical Center (both made up) and made-up patients.
|
|
4
|
+
|
|
5
|
+
- `admissions.csv`: five inpatient stays.
|
|
6
|
+
- `outpatient.csv`: Planted: Anton Reyes had a blood count (48.00) and a head CT (1,450.00) two days before his 5 October admission, both already billed on their own claims, and an ambulance trip the same day (left out); Bettina Shore had an ECG on her admission day (diagnostic, not billed yet) and a clinic visit two days before (non-diagnostic, for review). Corwin Bale's x-ray was seven days before (outside the window), Delphine Okoye's lab was at another hospital, and Emmett Vane's dialysis is left out.
|
|
7
|
+
- `settings.json`: a three-day window; the excluded and diagnostic revenue code lists use the defaults. `settings-typo.json` misspells a setting and is refused.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"case": "totals",
|
|
3
|
+
"id": [
|
|
4
|
+
[
|
|
5
|
+
"account"
|
|
6
|
+
]
|
|
7
|
+
],
|
|
8
|
+
"planted": [
|
|
9
|
+
["OP-8002", "diagnostic_in_window"],
|
|
10
|
+
["OP-8005", "diagnostic_in_window"],
|
|
11
|
+
["OP-8001", "diagnostic_in_window"],
|
|
12
|
+
["OP-8004", "nondiagnostic_review"]
|
|
13
|
+
],
|
|
14
|
+
"clean": [
|
|
15
|
+
{
|
|
16
|
+
"arg": "outpatient",
|
|
17
|
+
"set": [
|
|
18
|
+
{
|
|
19
|
+
"where": ["Account #", "OP-8001"],
|
|
20
|
+
"column": "Service Date",
|
|
21
|
+
"value": "2026-10-01"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"where": ["Account #", "OP-8002"],
|
|
25
|
+
"column": "Service Date",
|
|
26
|
+
"value": "2026-10-01"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"where": ["Account #", "OP-8004"],
|
|
30
|
+
"column": "Service Date",
|
|
31
|
+
"value": "2026-10-08"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"where": ["Account #", "OP-8005"],
|
|
35
|
+
"column": "Service Date",
|
|
36
|
+
"value": "2026-10-08"
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"mutations": [
|
|
42
|
+
{
|
|
43
|
+
"name": "x-ray two days before the admission",
|
|
44
|
+
"edits": [
|
|
45
|
+
{
|
|
46
|
+
"arg": "outpatient",
|
|
47
|
+
"set": [
|
|
48
|
+
{
|
|
49
|
+
"where": ["Account #", "OP-8006"],
|
|
50
|
+
"column": "Service Date",
|
|
51
|
+
"value": "2026-10-06"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"expect": [
|
|
57
|
+
["OP-8006", "diagnostic_in_window"]
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"name": "lab at the admitting hospital the day before",
|
|
62
|
+
"edits": [
|
|
63
|
+
{
|
|
64
|
+
"arg": "outpatient",
|
|
65
|
+
"set": [
|
|
66
|
+
{
|
|
67
|
+
"where": ["Account #", "OP-8007"],
|
|
68
|
+
"column": "Facility",
|
|
69
|
+
"value": "Elmswood Community Hospital"
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
"expect": [
|
|
75
|
+
["OP-8007", "diagnostic_in_window"]
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"name": "ambulance line recoded as an ED visit",
|
|
80
|
+
"edits": [
|
|
81
|
+
{
|
|
82
|
+
"arg": "outpatient",
|
|
83
|
+
"set": [
|
|
84
|
+
{
|
|
85
|
+
"where": ["Account #", "OP-8003"],
|
|
86
|
+
"column": "Rev Code",
|
|
87
|
+
"value": "0450"
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
"expect": [
|
|
93
|
+
["OP-8003", "nondiagnostic_review"]
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Account #,MRN,Admit Date,Discharge Date,Facility
|
|
2
|
+
IP-9001,M2001,2026-10-05,2026-10-09,Elmswood Community Hospital
|
|
3
|
+
IP-9002,M2002,2026-10-12,2026-10-15,Elmswood Community Hospital
|
|
4
|
+
IP-9003,M2003,2026-10-08,2026-10-10,Elmswood Community Hospital
|
|
5
|
+
IP-9004,M2004,2026-10-15,2026-10-18,Elmswood Community Hospital
|
|
6
|
+
IP-9005,M2005,2026-10-19,2026-10-24,Elmswood Community Hospital
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Account #,MRN,Patient Name,Service Date,Rev Code,HCPCS,Charges,Facility,Bill Status
|
|
2
|
+
OP-8001,M2001,Anton Reyes,2026-10-03,0300,85025,48.00,Elmswood Community Hospital,Billed
|
|
3
|
+
OP-8002,M2001,Anton Reyes,2026-10-03,0350,70450,1450.00,Elmswood Community Hospital,Billed
|
|
4
|
+
OP-8003,M2001,Anton Reyes,2026-10-03,0540,A0427,820.00,Elmswood Community Hospital,Billed
|
|
5
|
+
OP-8004,M2002,Bettina Shore,2026-10-10,0510,99213,210.00,Elmswood Community Hospital,Held
|
|
6
|
+
OP-8005,M2002,Bettina Shore,2026-10-12,0730,93000,95.00,Elmswood Community Hospital,Not billed
|
|
7
|
+
OP-8006,M2003,Corwin Bale,2026-10-01,0320,71046,210.00,Elmswood Community Hospital,Billed
|
|
8
|
+
OP-8007,M2004,Delphine Okoye,2026-10-14,0300,80048,62.00,Hollowbrook Medical Center,Billed
|
|
9
|
+
OP-8008,M2005,Emmett Vane,2026-10-18,0821,90935,640.00,Elmswood Community Hospital,Billed
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "note": "Fictional patient names and record numbers used in these fixtures. None may reach a model result when masking is on.", "values": ["Anton Reyes", "Bettina Shore", "Corwin Bale", "M2001", "M2002"] }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "window": 3 }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "window_days": 3 }
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fairpractice-payment-window",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"mcpName": "io.github.fpavia111-creator/fairpractice-payment-window",
|
|
5
|
+
"description": "The three-day payment window: outpatient diagnostic services in the days before an admission that belong on the inpatient claim, non-diagnostic services for a person to review, and the dollars billed separately, with ambulance and maintenance dialysis left out.",
|
|
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-payment-window": "bin/fairpractice-payment-window.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-payment-window.js demo",
|
|
33
|
+
"eval": "node bin/fairpractice-payment-window.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-payment-window"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/fpavia111-creator/fairpractice2-agents/tree/master/packages/fairpractice-payment-window#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
|
+
"payment-window",
|
|
55
|
+
"72-hour-rule",
|
|
56
|
+
"hospital",
|
|
57
|
+
"inpatient",
|
|
58
|
+
"bundling"
|
|
59
|
+
]
|
|
60
|
+
}
|
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-payment-window",
|
|
4
|
+
"title": "Fairpractice Payment Window",
|
|
5
|
+
"description": "The three-day payment window: outpatient diagnostic services in the days before an admission that…",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"url": "https://github.com/fpavia111-creator/fairpractice2-agents",
|
|
9
|
+
"source": "github",
|
|
10
|
+
"subfolder": "packages/fairpractice-payment-window"
|
|
11
|
+
},
|
|
12
|
+
"websiteUrl": "https://fair-agents.com/fairpractice.html",
|
|
13
|
+
"packages": [
|
|
14
|
+
{
|
|
15
|
+
"registryType": "npm",
|
|
16
|
+
"identifier": "fairpractice-payment-window",
|
|
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 = { outpatient: 'outpatient.csv', inpatient: 'admissions.csv', settings: 'settings.json' };
|
|
5
|
+
export const demo = () => runDemo(manifest, new URL('../fixtures', import.meta.url), 'Fairpractice Payment Window', [
|
|
6
|
+
{ label: 'Check outpatient lines before each admission', tool: 'window_check', args: f, list: (i) => `${i.status.padEnd(22)} ${i.message}` },
|
|
7
|
+
{ label: 'Write the billing list', tool: 'window_write_report', args: f },
|
|
8
|
+
{ label: 'Agent tries to rebill a claim itself', tool: 'claim_rebill', args: {} },
|
|
9
|
+
]);
|
package/src/index.js
ADDED
package/src/logic.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Three-day payment window logic: outpatient services in the days before an admission at the same hospital. No I/O.
|
|
2
|
+
import { str, num, isoDate, addDays, daysBetween, inCodeList, round2, sortByStatus, countBy } from 'fairpractice-core';
|
|
3
|
+
import { revKey } from './rev.js';
|
|
4
|
+
|
|
5
|
+
const ORDER = { diagnostic_in_window: 0, nondiagnostic_review: 1 };
|
|
6
|
+
export const DEFAULT_EXCLUDED_REV = Object.freeze(['054*', '0821-0829', '0831-0839', '0841-0849', '0851-0859', '0881-0889']);
|
|
7
|
+
export const DEFAULT_DIAGNOSTIC_REV = Object.freeze(['0254', '0255', '030*', '031*', '032*', '0341', '0343', '035*', '0371', '0372', '040*', '046*', '0471', '0481', '0482', '0483', '0489', '0610-0619', '0730-0739', '0740-0749', '0920-0929']);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* outpatient: [{ account, patient_id, patient_name, dos, rev_code, cpt, charge, facility, claim_status }]
|
|
11
|
+
* inpatient: [{ account, patient_id, admit, discharge, facility }]
|
|
12
|
+
* opts: { windowDays = 3, excludedRev = DEFAULT_EXCLUDED_REV, diagnosticRev = DEFAULT_DIAGNOSTIC_REV }
|
|
13
|
+
*/
|
|
14
|
+
export function checkWindow(outpatient, inpatient, { windowDays = 3, excludedRev = DEFAULT_EXCLUDED_REV, diagnosticRev = DEFAULT_DIAGNOSTIC_REV } = {}) {
|
|
15
|
+
const stays = new Map();
|
|
16
|
+
// Admissions by patient, the window start worked out once, identical stays once.
|
|
17
|
+
const seenStay = new Set();
|
|
18
|
+
for (const s of inpatient) { const k = str(s.patient_id); const a = isoDate(s.admit); if (!k || !a) continue; const fac = str(s.facility).toLowerCase(); const sig = `${k}|${a}|${fac}|${str(s.account)}`; if (seenStay.has(sig)) continue; seenStay.add(sig); if (!stays.has(k)) stays.set(k, []); stays.get(k).push({ ...s, a, ws: addDays(a, -windowDays), fac }); }
|
|
19
|
+
const items = []; let inWindow = 0; let excluded = 0;
|
|
20
|
+
for (const [i, o] of outpatient.entries()) {
|
|
21
|
+
const dos = isoDate(o.dos); const pid = str(o.patient_id); if (!dos || !pid) continue;
|
|
22
|
+
const ofac = str(o.facility).toLowerCase();
|
|
23
|
+
const stay = (stays.get(pid) || []).find((s) => dos <= s.a && dos >= s.ws && (!s.fac || !ofac || s.fac === ofac));
|
|
24
|
+
if (!stay) continue;
|
|
25
|
+
const rev = revKey(o.rev_code);
|
|
26
|
+
if (rev && inCodeList(rev, excludedRev)) { excluded++; continue; }
|
|
27
|
+
inWindow++;
|
|
28
|
+
const bs = str(o.claim_status); const billed = /bill|paid|sent|submit|final/i.test(bs) && !/\bnot\b|\bun|held|hold|pend/i.test(bs);
|
|
29
|
+
const base = { account: str(o.account) || `line ${i + 1}`, patient_id: pid, patient_name: str(o.patient_name) || null, dos, rev_code: rev || null, cpt: str(o.cpt) || null, admit: stay.a, inpatient_account: str(stay.account) || null, days_before: daysBetween(dos, stay.a), billed_separately: billed, amount: round2(num(o.charge) || 0) };
|
|
30
|
+
items.push({ ...base, status: rev && inCodeList(rev, diagnosticRev) ? 'diagnostic_in_window' : 'nondiagnostic_review' });
|
|
31
|
+
}
|
|
32
|
+
const T = {
|
|
33
|
+
diagnostic_in_window: (x) => [`Outpatient ${x.cpt || 'service'} (rev ${x.rev_code}) on ${x.dos}, ${x.days_before} day(s) before the ${x.admit} admission${x.billed_separately ? ', already billed on its own claim' : ''}.`, x.billed_separately ? 'Diagnostic services in the window go on the inpatient claim: cancel or adjust the outpatient claim and rebill the stay.' : 'Move the charge to the inpatient account before the stay is billed.'],
|
|
34
|
+
nondiagnostic_review: (x) => [`Outpatient ${x.cpt || 'service'} (rev ${x.rev_code || 'none'}) on ${x.dos}, ${x.days_before} day(s) before the ${x.admit} admission.`, 'Non-diagnostic services related to the admission belong on the inpatient claim; a person checks whether it was related.'],
|
|
35
|
+
};
|
|
36
|
+
for (const it of items) { const [m, f] = T[it.status](it); it.message = m; it.fix = f; }
|
|
37
|
+
sortByStatus(items, ORDER);
|
|
38
|
+
return { outpatient_lines: outpatient.length, admissions: inpatient.length, lines_in_window: inWindow, excluded_in_window: excluded, billed_separately: round2(items.filter((x) => x.billed_separately).reduce((s, x) => s + x.amount, 0)), by_status: countBy(items, 'status'), items };
|
|
39
|
+
}
|
package/src/manifest.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { medAgent, fileArg, ACCOUNT, PATIENT_ID, PATIENT_NAME, DOS, REV_CODE, CPT, CHARGE, ADMIT, DISCHARGE, PRACTICE_LIMITS } from 'fairpractice-core';
|
|
3
|
+
import { checkWindow, DEFAULT_EXCLUDED_REV, DEFAULT_DIAGNOSTIC_REV } 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 FACILITY = t(['Facility', 'Hospital', 'Campus', 'Location', 'Provider Number', 'CCN'], { translate: false });
|
|
8
|
+
|
|
9
|
+
export const OUTPATIENT_FIELDS = Object.freeze({
|
|
10
|
+
account: ACCOUNT, patient_id: { ...PATIENT_ID, required: true }, patient_name: PATIENT_NAME,
|
|
11
|
+
dos: { ...DOS, required: true }, rev_code: REV_CODE, cpt: CPT, charge: CHARGE, facility: FACILITY,
|
|
12
|
+
claim_status: t(['Claim Status', 'Bill Status', 'Billing Status', 'Status'], { translate: 'status' }),
|
|
13
|
+
});
|
|
14
|
+
export const INPATIENT_FIELDS = Object.freeze({
|
|
15
|
+
account: ACCOUNT, patient_id: { ...PATIENT_ID, required: true },
|
|
16
|
+
admit: { ...ADMIT, required: true }, discharge: DISCHARGE, facility: FACILITY,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const REV_LIST = { type: 'array', items: { type: 'string', maxLength: 20 }, maxItems: 100 };
|
|
20
|
+
const SETTINGS = { type: 'object', additionalProperties: false, properties: {
|
|
21
|
+
window_days: { type: 'integer', minimum: 0, maximum: 7, description: 'Days before the admission in the window (3 for most hospitals, 1 for hospitals outside the inpatient prospective payment system); default 3' },
|
|
22
|
+
excluded_rev: { ...REV_LIST, description: 'Revenue codes left out of the window (ambulance 054x and maintenance dialysis by default)' },
|
|
23
|
+
diagnostic_rev: { ...REV_LIST, description: 'Revenue codes treated as diagnostic (the public list as of 2026 by default); others are listed for a person to review' },
|
|
24
|
+
} };
|
|
25
|
+
|
|
26
|
+
const args = {
|
|
27
|
+
outpatient: fileArg('Outpatient claim lines under --root: account, patient, date of service, revenue code, CPT/HCPCS, charge, facility and bill status'),
|
|
28
|
+
inpatient: fileArg('Inpatient admissions: account, patient, admit and discharge dates, facility'),
|
|
29
|
+
settings: fileArg('Optional settings JSON: window_days, excluded_rev, diagnostic_rev'),
|
|
30
|
+
};
|
|
31
|
+
const run = (a, ctx) => {
|
|
32
|
+
const s = a.settings ? ctx.readJson(a.settings, 'window_settings') : {};
|
|
33
|
+
return checkWindow(ctx.records(a.outpatient, 'outpatient'), ctx.records(a.inpatient, 'inpatient'), { windowDays: s.window_days ?? 3, excludedRev: s.excluded_rev || DEFAULT_EXCLUDED_REV, diagnosticRev: s.diagnostic_rev || DEFAULT_DIAGNOSTIC_REV });
|
|
34
|
+
};
|
|
35
|
+
const summary = (o) => `${o.admissions} admission(s), ${o.lines_in_window} outpatient line(s) in the window (${o.excluded_in_window} left out as ambulance or dialysis). ${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'}. Already billed separately: ${o.billed_separately}.`;
|
|
36
|
+
|
|
37
|
+
export const manifest = medAgent({
|
|
38
|
+
pkg, prefix: 'window', title: 'Fairpractice Payment Window',
|
|
39
|
+
description: 'Checks the three-day payment window: outpatient services at the same hospital in the days before an inpatient admission (the admission day included), diagnostic ones that belong on the inpatient claim and non-diagnostic ones for a person to review, with the dollars already billed on separate claims. Ambulance and maintenance dialysis are left out. Patient names are masked before results reach the model.',
|
|
40
|
+
args, required: ['outpatient', 'inpatient'],
|
|
41
|
+
sources: { outpatient: { label: 'Outpatient claim lines', args: ['outpatient'], fields: OUTPATIENT_FIELDS }, inpatient: { label: 'Inpatient admissions', args: ['inpatient'], fields: INPATIENT_FIELDS } },
|
|
42
|
+
configSchemas: { window_settings: SETTINGS }, memoryKinds: {},
|
|
43
|
+
run, summary,
|
|
44
|
+
check: { title: 'Check the payment window', description: 'List outpatient lines in the window before an admission: diagnostic ones to move to the inpatient claim and non-diagnostic ones to review.' },
|
|
45
|
+
report: {
|
|
46
|
+
title: { en: 'Three-day payment window', es: 'Ventana de pago de tres días', de: 'Dreitägiges Zahlungsfenster', fr: 'Fenêtre de paiement de trois jours', pt: 'Janela de pagamento de três dias', it: 'Finestra di pagamento di tre giorni', ja: '入院前3日間の請求ルール', zh: '入院前三天支付窗口', ko: '입원 전 3일 지불 기간' },
|
|
47
|
+
base: 'payment-window',
|
|
48
|
+
rows: (o) => o.items.map((i) => ({ status: i.status, account: i.account, patient_id: i.patient_id, patient_name: i.patient_name || '', dos: i.dos, rev_code: i.rev_code || '', cpt: i.cpt || '', admit: i.admit, inpatient_account: i.inpatient_account || '', billed_separately: i.billed_separately ? 'yes' : 'no', amount: i.amount, message: i.message, fix: i.fix })),
|
|
49
|
+
htmlColumns: ['status', 'account', 'patient_name', 'dos', 'rev_code', 'admit', 'amount', 'message', 'fix'],
|
|
50
|
+
sections: (o) => [{ title: { en: 'Findings by type' }, rows: Object.entries(o.by_status).map(([status, count]) => ({ status, count })), columns: ['status', 'count'] }],
|
|
51
|
+
limits: [PRACTICE_LIMITS.files, 'Whether a non-diagnostic service was related to the admission is a judgment for a person; the revenue code lists and window length are settings that follow the public rule as of 2026.', PRACTICE_LIMITS.advice, PRACTICE_LIMITS.phi],
|
|
52
|
+
},
|
|
53
|
+
refused: [
|
|
54
|
+
{ name: 'claim_rebill', category: 'binding_send', description: 'Fairpractice Payment Window never cancels, adjusts or rebills a claim.' },
|
|
55
|
+
{ name: 'charge_move', category: 'production_deploy', description: 'Fairpractice Payment Window never moves charges between accounts in the billing system.' },
|
|
56
|
+
],
|
|
57
|
+
prompt: { title: 'Payment window review', description: 'Walks the host model through a weekly payment window check.', text: `You are helping a hospital billing lead with fairpractice-payment-window.
|
|
58
|
+
|
|
59
|
+
Rules: it only reads files. Patient names in results are pseudonyms.
|
|
60
|
+
|
|
61
|
+
1. Call window_check with the outpatient lines and admissions.
|
|
62
|
+
2. Lead with diagnostic_in_window lines already billed separately: those claims need correcting.
|
|
63
|
+
3. Non-diagnostic lines are for a person to judge; do not call them errors.
|
|
64
|
+
4. Call window_write_report for the billing team.` },
|
|
65
|
+
});
|
package/src/rev.js
ADDED