fairstay-payer-source 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 +7 -0
- package/LICENSE +21 -0
- package/README.md +169 -2
- package/bin/fairstay-payer-source.js +7 -0
- package/evals/cases.json +290 -0
- package/fixtures/README.md +3 -0
- package/fixtures/census.csv +10 -0
- package/fixtures/phi-canaries.json +1 -0
- package/fixtures/residents.csv +6 -0
- package/fixtures/rules-typo.json +1 -0
- package/fixtures/rules.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 +53 -0
- package/src/manifest.js +56 -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,170 @@
|
|
|
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
|
+
# Fairstay Payer Source (`fairstay-payer-source`)
|
|
4
|
+
|
|
5
|
+
Checks that every nursing-home resident day has one proper payer: days with no payer, two payers on one day, payers not on your payer list, Medicare Part A past day 100, Part A coinsurance days with no secondary payer, hospice residents on Part A, and private pay with no responsible party. Resident identifiers are masked before results reach the model.
|
|
6
|
+
|
|
7
|
+
**Fairstay Payer Source never changes payers in PointClickCare or any other system.**
|
|
8
|
+
|
|
9
|
+
Fairstay ver 1 · Billing and revenue cycle · MIT · Node 20 or newer · local files only · resident and staff identifiers masked before results reach the model · built on [`fairstay-core`](../fairstay-core)
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx -y fairstay-payer-source demo
|
|
13
|
+
npx -y fairstay-payer-source mcp --root ./facility-files
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## What the sample data shows
|
|
17
|
+
|
|
18
|
+
Fictional Cedar Hollow Health and Rehab, March 2026 (example coinsurance rate 200, not the CMS figure). Planted: Part A past day 100 (R301: 40 earlier days + Part A since 1 January), coinsurance days with no secondary payer (R302 from day 21), no payer for four days (R303), two payers from 20 March (R304), a payer spelled differently from the payer list (R305), a hospice resident on Part A (R306) and private pay with no responsible party (R307).
|
|
19
|
+
|
|
20
|
+
## A demo run
|
|
21
|
+
|
|
22
|
+
`npx -y fairstay-payer-source demo` runs the agent on the fictional files in [`fixtures/`](fixtures) in a temporary folder. Captured output:
|
|
23
|
+
|
|
24
|
+
```text
|
|
25
|
+
Fairstay Payer Source demo (fictional home, residents, staff and vendors)
|
|
26
|
+
|
|
27
|
+
▶ Check the payer for every resident day in March 2026
|
|
28
|
+
status: executed decision: allow
|
|
29
|
+
7 resident(s), 213 resident days, 169 day(s) with a payer problem. no_payer 1, payer_overlap 1, part_a_over_100 1, unknown_payer 1, hospice_on_part_a 1, coinsurance_no_secondary 1, private_no_guarantor 1. Coinsurance with no secondary payer: 6000.
|
|
30
|
+
no_payer 4 day(s) No payer on the census for 2026-03-05 to 2026-03-08.
|
|
31
|
+
payer_overlap 12 day(s) Two payers on the census for 2026-03-20 to 2026-03-31: Lone Star Medicaid (fictional) and Private Pay.
|
|
32
|
+
part_a_over_100 30 day(s) Medicare Part A days 101 to 130 (2026-03-02 to 2026-03-31); Part A covers at most 100 days per benefit period.
|
|
33
|
+
unknown_payer 31 day(s) "LS Medicaid" (2026-03-01 to 2026-03-31) is not on your payer list.
|
|
34
|
+
hospice_on_part_a 31 day(s) The resident has a hospice agency (Bluebonnet Hospice (fictional)) and is on Medicare Part A for 2026-03-01 to 2026-03-31.
|
|
35
|
+
coinsurance_no_secondary 30 day(s) Part A days 21 to 50 (2026-03-02 to 2026-03-31) carry daily coinsurance, and no secondary payer is on file.
|
|
36
|
+
private_no_guarantor 31 day(s) Private pay for 2026-03-01 to 2026-03-31 with no responsible party on file.
|
|
37
|
+
|
|
38
|
+
▶ Write the payer source work list
|
|
39
|
+
status: executed decision: allow
|
|
40
|
+
Payer source work list written: 7 resident(s), 213 resident days, 169 day(s) with a payer problem. no_payer 1, payer_overlap 1, part_a_over_100 1, unknown_payer 1, hospice_on_part_a 1, coinsurance_no_secondary 1, private_no_guarantor 1. Coinsurance with no secondary payer: 6000. Files: evergreen-out/payer/payer-source.csv, evergreen-out/payer/payer-source.html.
|
|
41
|
+
|
|
42
|
+
▶ Teach another spelling of the Medicaid payer
|
|
43
|
+
status: executed decision: allow
|
|
44
|
+
Stored MEM-dd1b5fd24f7d as waiting. It changes nothing until a named person accepts it with payer_accept_learning (id "MEM-dd1b5fd24f7d", decision "accept").
|
|
45
|
+
|
|
46
|
+
▶ Agent tries to change the census itself
|
|
47
|
+
status: blocked decision: block
|
|
48
|
+
reason: Fairstay Payer Source never changes payers in PointClickCare or any other system.
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Tools
|
|
52
|
+
|
|
53
|
+
| Tool | What it does | Policy |
|
|
54
|
+
|---|---|---|
|
|
55
|
+
| `payer_check` | List runs of resident days with a missing, doubled, unknown or improper payer for a month (or start to end). | runs |
|
|
56
|
+
| `payer_write_report` | Write payer-source.csv (one row per item, with blank owner and decision columns) and payer-source.html into out_dir (default evergreen-out/payer). | runs |
|
|
57
|
+
| `payer_recall` | Search this agent's own memory of the customer's setup: accepted facts (in use) and facts waiting for a person. | runs |
|
|
58
|
+
| `payer_learn` | Propose one fact about the customer's setup for this agent to remember. | runs |
|
|
59
|
+
| `payer_accept_learning` | A named person accepts or rejects a fact waiting in this agent's memory. | one named click, even in Auto (`accept_learning`) |
|
|
60
|
+
| `payer_retire_memory` | A named person stops an accepted fact from applying. | one named click, even in Auto (`accept_learning`) |
|
|
61
|
+
| `census_update` | Fairstay Payer Source never changes payers in PointClickCare or any other system. | 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
|
+
### `payer_check` arguments
|
|
66
|
+
|
|
67
|
+
| Argument | What it is |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `census` (required) | Census export under --root (rows with resident, payer, from, to; the to day is not counted) |
|
|
70
|
+
| `residents` | Optional resident financial file under --root: secondary payer, responsible party, hospice agency, Part A days used earlier in the benefit period |
|
|
71
|
+
| `rules` | Optional rules JSON: your payer list and the daily coinsurance rate |
|
|
72
|
+
| `month` | Month to check, YYYY-MM |
|
|
73
|
+
| `start` | Start of the period (YYYY-MM-DD) if not a whole month |
|
|
74
|
+
| `end` | End of the period, inclusive |
|
|
75
|
+
| `status` | Only items with this status |
|
|
76
|
+
| `limit` | Most items to return to the model (the report file always has all of them) |
|
|
77
|
+
|
|
78
|
+
## Columns it reads
|
|
79
|
+
|
|
80
|
+
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 resident or staff identifiers.
|
|
81
|
+
|
|
82
|
+
The PointClickCare, MatrixCare and American HealthTech style names were written from public help pages and general knowledge, **not checked against real exports**. Run `npx fairstay-payer-source inspect <file>` (column names and shapes only, never values) and name any column it misses in `remedy-sources.json`.
|
|
83
|
+
|
|
84
|
+
### Census (`census`)
|
|
85
|
+
|
|
86
|
+
| Column | Type | Read from |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| `resident_id` | text (masked) | Resident ID, Resident #, Resident Number, Res ID, Res #, MRN, Medical Record Number, Client ID |
|
|
89
|
+
| `resident_name` | text (masked) | Resident, Resident Name, Name, Patient, Patient Name, Client Name, Resident Full Name |
|
|
90
|
+
| `facility` | text | Facility, Facility Name, Building, Location, Fac, Center |
|
|
91
|
+
| `from` (required) | date | From, Start, Start Date, Effective Date, Begin Date, From Date, Admit Date, Census Date |
|
|
92
|
+
| `to` | date | To, End, End Date, Thru, Through, Thru Date, Through Date, To Date |
|
|
93
|
+
| `payer` (required) | text | Payer, Payer Name, Primary Payer, Pay Source, Payer Source, Payor, Payor Name, Insurance |
|
|
94
|
+
| `payer_type` | text | Payer Type, Payor Type, Payer Class, Payer Category, Pay Type |
|
|
95
|
+
| `level` | text | Level, Level of Care, Care Level, Rate Type, Rate Level, Room Type, Accommodation, RUG |
|
|
96
|
+
| `bed_status` | text | Bed Status, Status, Census Status, Action, Census Action, Leave Type |
|
|
97
|
+
| `room` | text | Room, Room Bed, Bed, Room/Bed, Unit |
|
|
98
|
+
|
|
99
|
+
### Resident financial file (`residents`)
|
|
100
|
+
|
|
101
|
+
| Column | Type | Read from |
|
|
102
|
+
|---|---|---|
|
|
103
|
+
| `resident_id` | text (masked) | Resident ID, Resident #, Resident Number, Res ID, Res #, MRN, Medical Record Number, Client ID |
|
|
104
|
+
| `resident_name` | text (masked) | Resident, Resident Name, Name, Patient, Patient Name, Client Name, Resident Full Name |
|
|
105
|
+
| `secondary_payer` | text | Secondary Payer, Secondary, Secondary Insurance, Coinsurance Payer, Supplemental |
|
|
106
|
+
| `responsible_party` | text | Responsible Party, Guarantor, Financially Responsible, POA, Billing Contact |
|
|
107
|
+
| `hospice_agency` | text | Hospice, Hospice Agency, Hospice Provider |
|
|
108
|
+
| `part_a_days_used` | number | Part A Days Used, Prior SNF Days, Benefit Days Used |
|
|
109
|
+
|
|
110
|
+
## Settings file (`payer_rules`)
|
|
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
|
+
| `payers` | Your payer list (names as they appear on the census) |
|
|
117
|
+
| `coinsurance_rate` | Medicare SNF daily coinsurance for days 21-100 for the year (set it from the current CMS notice) |
|
|
118
|
+
|
|
119
|
+
## Memory
|
|
120
|
+
|
|
121
|
+
`payer_learn` only proposes a fact; nothing changes until a named person accepts it with `payer_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
|
+
| `payer_alias` | treats the alias as a known payer, so it is not flagged as unknown_payer. It never changes other checks. |
|
|
126
|
+
|
|
127
|
+
## Install
|
|
128
|
+
|
|
129
|
+
Node 20 or newer. No other runtime dependencies besides `fairstay-core` and `fairclaim-core`.
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"mcpServers": {
|
|
134
|
+
"fairstay-payer-source": {
|
|
135
|
+
"command": "npx",
|
|
136
|
+
"args": [
|
|
137
|
+
"-y",
|
|
138
|
+
"fairstay-payer-source",
|
|
139
|
+
"mcp",
|
|
140
|
+
"--root",
|
|
141
|
+
"/path/to/facility-files"
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Claude Code: `claude mcp add fairstay-payer-source -- npx -y fairstay-payer-source mcp --root .`, or use the plugin files in this folder.
|
|
149
|
+
|
|
150
|
+
## CLI
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
fairstay-payer-source tools # every tool, its policy and arguments
|
|
154
|
+
fairstay-payer-source sources # the columns each input is read from
|
|
155
|
+
fairstay-payer-source inspect <file> # how a file would be read (names and shapes, never values)
|
|
156
|
+
fairstay-payer-source call payer_check '{"census":"<census>"}'
|
|
157
|
+
fairstay-payer-source eval # the private eval cases on the fictional fixtures
|
|
158
|
+
fairstay-payer-source demo
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Resident and staff data
|
|
162
|
+
|
|
163
|
+
Results go to an AI model, so identifiers are masked before they leave the agent: resident 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.
|
|
164
|
+
|
|
165
|
+
## Limits
|
|
166
|
+
|
|
167
|
+
- Reads only the files you give it. It does not log in to PointClickCare, MatrixCare, a payer portal, a bank, a state Medicaid portal or a payroll system.
|
|
168
|
+
- Medicare, Medicaid and payroll rules are summarised from public material as of 2026 and the numbers are settings you supply; a billing, payroll or legal professional checks them before you rely on them.
|
|
169
|
+
- Not legal, tax, accounting, clinical, reimbursement or HIPAA advice. A person decides what to bill, pay, appeal, file or send.
|
|
170
|
+
- 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 'fairstay-core';
|
|
4
|
+
import { manifest } from '../src/manifest.js';
|
|
5
|
+
import { demo } from '../src/demo.js';
|
|
6
|
+
|
|
7
|
+
main(manifest, { bin: 'fairstay-payer-source', demo, evalFile: fileURLToPath(new URL('../evals/cases.json', import.meta.url)) });
|
package/evals/cases.json
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
{
|
|
2
|
+
"suite": "fairstay-payer-source",
|
|
3
|
+
"root": "..",
|
|
4
|
+
"data_note": "Fictional home, residents and payers in ../fixtures. Deterministic checks; no model is called.",
|
|
5
|
+
"cases": [
|
|
6
|
+
{
|
|
7
|
+
"id": "totals",
|
|
8
|
+
"tool": "payer_check",
|
|
9
|
+
"args": {
|
|
10
|
+
"census": "fixtures/census.csv",
|
|
11
|
+
"residents": "fixtures/residents.csv",
|
|
12
|
+
"rules": "fixtures/rules.json",
|
|
13
|
+
"month": "2026-03"
|
|
14
|
+
},
|
|
15
|
+
"expect": {
|
|
16
|
+
"status": "executed",
|
|
17
|
+
"equals": {
|
|
18
|
+
"result.residents": 7,
|
|
19
|
+
"result.resident_days": 213,
|
|
20
|
+
"result.days_with_findings": 169,
|
|
21
|
+
"result.coinsurance_at_risk": 6000
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"id": "order",
|
|
27
|
+
"tool": "payer_check",
|
|
28
|
+
"args": {
|
|
29
|
+
"census": "fixtures/census.csv",
|
|
30
|
+
"residents": "fixtures/residents.csv",
|
|
31
|
+
"rules": "fixtures/rules.json",
|
|
32
|
+
"month": "2026-03"
|
|
33
|
+
},
|
|
34
|
+
"expect": {
|
|
35
|
+
"equals": {
|
|
36
|
+
"result.items.0.status": "no_payer",
|
|
37
|
+
"result.items.1.status": "payer_overlap",
|
|
38
|
+
"result.items.2.status": "part_a_over_100",
|
|
39
|
+
"result.items.3.status": "unknown_payer",
|
|
40
|
+
"result.items.4.status": "hospice_on_part_a",
|
|
41
|
+
"result.items.5.status": "coinsurance_no_secondary",
|
|
42
|
+
"result.items.6.status": "private_no_guarantor"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"id": "no-payer-four-days",
|
|
48
|
+
"tool": "payer_check",
|
|
49
|
+
"args": {
|
|
50
|
+
"census": "fixtures/census.csv",
|
|
51
|
+
"residents": "fixtures/residents.csv",
|
|
52
|
+
"rules": "fixtures/rules.json",
|
|
53
|
+
"month": "2026-03",
|
|
54
|
+
"status": "no_payer"
|
|
55
|
+
},
|
|
56
|
+
"expect": {
|
|
57
|
+
"equals": {
|
|
58
|
+
"result.items.0.days": 4,
|
|
59
|
+
"result.items.0.to": "2026-03-08"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"id": "part-a-day-101-on",
|
|
65
|
+
"tool": "payer_check",
|
|
66
|
+
"args": {
|
|
67
|
+
"census": "fixtures/census.csv",
|
|
68
|
+
"residents": "fixtures/residents.csv",
|
|
69
|
+
"rules": "fixtures/rules.json",
|
|
70
|
+
"month": "2026-03",
|
|
71
|
+
"status": "part_a_over_100"
|
|
72
|
+
},
|
|
73
|
+
"expect": {
|
|
74
|
+
"equals": {
|
|
75
|
+
"result.items.0.days": 30,
|
|
76
|
+
"result.items.0.from": "2026-03-02"
|
|
77
|
+
},
|
|
78
|
+
"contains": [
|
|
79
|
+
"days 101 to 130"
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"id": "coinsurance-from-day-21",
|
|
85
|
+
"tool": "payer_check",
|
|
86
|
+
"args": {
|
|
87
|
+
"census": "fixtures/census.csv",
|
|
88
|
+
"residents": "fixtures/residents.csv",
|
|
89
|
+
"rules": "fixtures/rules.json",
|
|
90
|
+
"month": "2026-03",
|
|
91
|
+
"status": "coinsurance_no_secondary"
|
|
92
|
+
},
|
|
93
|
+
"expect": {
|
|
94
|
+
"equals": {
|
|
95
|
+
"result.items.0.from": "2026-03-02",
|
|
96
|
+
"result.items.0.amount": 6000
|
|
97
|
+
},
|
|
98
|
+
"contains": [
|
|
99
|
+
"days 21 to 50"
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"id": "overlap-from-the-20th",
|
|
105
|
+
"tool": "payer_check",
|
|
106
|
+
"args": {
|
|
107
|
+
"census": "fixtures/census.csv",
|
|
108
|
+
"residents": "fixtures/residents.csv",
|
|
109
|
+
"rules": "fixtures/rules.json",
|
|
110
|
+
"month": "2026-03",
|
|
111
|
+
"status": "payer_overlap"
|
|
112
|
+
},
|
|
113
|
+
"expect": {
|
|
114
|
+
"equals": {
|
|
115
|
+
"result.items.0.days": 12
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"id": "without-payer-list-no-unknown",
|
|
121
|
+
"tool": "payer_check",
|
|
122
|
+
"args": {
|
|
123
|
+
"census": "fixtures/census.csv",
|
|
124
|
+
"residents": "fixtures/residents.csv",
|
|
125
|
+
"month": "2026-03"
|
|
126
|
+
},
|
|
127
|
+
"expect": {
|
|
128
|
+
"equals": {
|
|
129
|
+
"result.coinsurance_at_risk": 0
|
|
130
|
+
},
|
|
131
|
+
"not_contains": [
|
|
132
|
+
"unknown_payer"
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"id": "without-resident-file",
|
|
138
|
+
"tool": "payer_check",
|
|
139
|
+
"args": {
|
|
140
|
+
"census": "fixtures/census.csv",
|
|
141
|
+
"rules": "fixtures/rules.json",
|
|
142
|
+
"month": "2026-03"
|
|
143
|
+
},
|
|
144
|
+
"expect": {
|
|
145
|
+
"not_contains": [
|
|
146
|
+
"hospice_on_part_a"
|
|
147
|
+
],
|
|
148
|
+
"min": {
|
|
149
|
+
"result.by_status.private_no_guarantor": 1
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"id": "short-period",
|
|
155
|
+
"tool": "payer_check",
|
|
156
|
+
"args": {
|
|
157
|
+
"census": "fixtures/census.csv",
|
|
158
|
+
"residents": "fixtures/residents.csv",
|
|
159
|
+
"rules": "fixtures/rules.json",
|
|
160
|
+
"start": "2026-03-01",
|
|
161
|
+
"end": "2026-03-04"
|
|
162
|
+
},
|
|
163
|
+
"expect": {
|
|
164
|
+
"not_contains": [
|
|
165
|
+
"no_payer",
|
|
166
|
+
"payer_overlap"
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"id": "names-masked",
|
|
172
|
+
"tool": "payer_check",
|
|
173
|
+
"args": {
|
|
174
|
+
"census": "fixtures/census.csv",
|
|
175
|
+
"residents": "fixtures/residents.csv",
|
|
176
|
+
"rules": "fixtures/rules.json",
|
|
177
|
+
"month": "2026-03"
|
|
178
|
+
},
|
|
179
|
+
"expect": {
|
|
180
|
+
"matches": [
|
|
181
|
+
"\"resident_id\":\"MRN-[0-9a-f]{8}\""
|
|
182
|
+
],
|
|
183
|
+
"not_contains": [
|
|
184
|
+
"Nwosu",
|
|
185
|
+
"R307"
|
|
186
|
+
]
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"id": "bad-rules-refused",
|
|
191
|
+
"tool": "payer_check",
|
|
192
|
+
"args": {
|
|
193
|
+
"census": "fixtures/census.csv",
|
|
194
|
+
"residents": "fixtures/residents.csv",
|
|
195
|
+
"rules": "fixtures/rules-typo.json",
|
|
196
|
+
"month": "2026-03"
|
|
197
|
+
},
|
|
198
|
+
"expect": {
|
|
199
|
+
"status": "error",
|
|
200
|
+
"contains": [
|
|
201
|
+
"payers"
|
|
202
|
+
]
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"id": "no-period-refused",
|
|
207
|
+
"tool": "payer_check",
|
|
208
|
+
"args": {
|
|
209
|
+
"census": "fixtures/census.csv"
|
|
210
|
+
},
|
|
211
|
+
"expect": {
|
|
212
|
+
"status": "error",
|
|
213
|
+
"contains": [
|
|
214
|
+
"month"
|
|
215
|
+
]
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"id": "report",
|
|
220
|
+
"tool": "payer_write_report",
|
|
221
|
+
"args": {
|
|
222
|
+
"census": "fixtures/census.csv",
|
|
223
|
+
"residents": "fixtures/residents.csv",
|
|
224
|
+
"rules": "fixtures/rules.json",
|
|
225
|
+
"month": "2026-03",
|
|
226
|
+
"out_dir": "evergreen-out/eval-payer"
|
|
227
|
+
},
|
|
228
|
+
"expect": {
|
|
229
|
+
"status": "executed",
|
|
230
|
+
"equals": {
|
|
231
|
+
"result.lang": "en"
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
"id": "census-update-refused",
|
|
237
|
+
"tool": "census_update",
|
|
238
|
+
"args": {},
|
|
239
|
+
"expect": {
|
|
240
|
+
"status": "blocked",
|
|
241
|
+
"decision": "block"
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
"id": "recall-empty-memory",
|
|
246
|
+
"tool": "payer_recall",
|
|
247
|
+
"args": {},
|
|
248
|
+
"expect": {
|
|
249
|
+
"status": "executed",
|
|
250
|
+
"contains": [
|
|
251
|
+
"memory is empty",
|
|
252
|
+
"payer_alias"
|
|
253
|
+
]
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
"id": "file-outside-root-refused",
|
|
258
|
+
"tool": "payer_check",
|
|
259
|
+
"args": {
|
|
260
|
+
"census": "../../outside-root.csv",
|
|
261
|
+
"residents": "fixtures/residents.csv",
|
|
262
|
+
"rules": "fixtures/rules.json",
|
|
263
|
+
"month": "2026-03"
|
|
264
|
+
},
|
|
265
|
+
"expect": {
|
|
266
|
+
"status": "error",
|
|
267
|
+
"contains": [
|
|
268
|
+
"outside the allowed root"
|
|
269
|
+
]
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
"id": "missing-file-named",
|
|
274
|
+
"tool": "payer_check",
|
|
275
|
+
"args": {
|
|
276
|
+
"census": "fixtures/missing-export.csv",
|
|
277
|
+
"residents": "fixtures/residents.csv",
|
|
278
|
+
"rules": "fixtures/rules.json",
|
|
279
|
+
"month": "2026-03"
|
|
280
|
+
},
|
|
281
|
+
"expect": {
|
|
282
|
+
"status": "error",
|
|
283
|
+
"contains": [
|
|
284
|
+
"not found",
|
|
285
|
+
"missing-export.csv"
|
|
286
|
+
]
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
]
|
|
290
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# Fixtures
|
|
2
|
+
|
|
3
|
+
Fictional Cedar Hollow Health and Rehab, March 2026 (example coinsurance rate 200, not the CMS figure). Planted: Part A past day 100 (R301: 40 earlier days + Part A since 1 January), coinsurance days with no secondary payer (R302 from day 21), no payer for four days (R303), two payers from 20 March (R304), a payer spelled differently from the payer list (R305), a hospice resident on Part A (R306) and private pay with no responsible party (R307).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Resident #,Resident Name,Payer,Effective Date,End Date,Bed Status
|
|
2
|
+
R301,Tomas Lindgren,Medicare A,2026-01-01,,In House
|
|
3
|
+
R302,Uma Castellanos,Medicare A,2026-02-10,,In House
|
|
4
|
+
R303,Victor Nwosu,,2026-03-05,2026-03-09,In House
|
|
5
|
+
R303,Victor Nwosu,Lone Star Medicaid (fictional),2026-03-09,,In House
|
|
6
|
+
R304,Wren Okoye,Lone Star Medicaid (fictional),2025-10-01,,In House
|
|
7
|
+
R304,Wren Okoye,Private Pay,2026-03-20,,In House
|
|
8
|
+
R305,Xavier Duval,LS Medicaid,2025-06-01,,In House
|
|
9
|
+
R306,Yara Whitcombe,Medicare A,2026-03-01,,In House
|
|
10
|
+
R307,Zane Morrow,Private Pay,2025-12-01,,In House
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "note": "Fictional resident names and ids.", "values": ["Tomas Lindgren", "Uma Castellanos", "Victor Nwosu", "Zane Morrow", "R303", "R307"] }
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Resident #,Resident Name,Secondary Payer,Responsible Party,Hospice,Part A Days Used
|
|
2
|
+
R301,Tomas Lindgren,Lone Star Medicaid (fictional),Self,,40
|
|
3
|
+
R302,Uma Castellanos,,Daughter,,0
|
|
4
|
+
R304,Wren Okoye,,Son,,
|
|
5
|
+
R306,Yara Whitcombe,Supplement Co (fictional),Self,Bluebonnet Hospice (fictional),0
|
|
6
|
+
R307,Zane Morrow,,,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "payers": ["Medicare A"], "coinsurance": 200 }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "payers": [ { "name": "Medicare A", "type": "medicare_a" }, { "name": "Lone Star Medicaid (fictional)", "type": "medicaid" }, { "name": "Private Pay", "type": "private" } ], "coinsurance_rate": 200 }
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fairstay-payer-source",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"mcpName": "io.github.fpavia111-creator/fairstay-payer-source",
|
|
5
|
+
"description": "Payer source for every resident day: days with no payer, two payers on the same day, payers missing from your payer list, Medicare Part A past day 100, coinsurance days with no secondary payer, hospice residents on the wrong payer and private pay with no responsible party.",
|
|
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
|
+
"fairstay-payer-source": "bin/fairstay-payer-source.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/fairstay-payer-source.js demo",
|
|
33
|
+
"eval": "node bin/fairstay-payer-source.js eval"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"fairstay-core": "^0.1.0"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/fpavia111-creator/fairstay-agents.git",
|
|
41
|
+
"directory": "packages/fairstay-payer-source"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/fpavia111-creator/fairstay-agents/tree/master/packages/fairstay-payer-source#readme",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/fpavia111-creator/fairstay-agents/issues"
|
|
46
|
+
},
|
|
47
|
+
"keywords": [
|
|
48
|
+
"mcp",
|
|
49
|
+
"mcp-server",
|
|
50
|
+
"nursing-home",
|
|
51
|
+
"skilled-nursing",
|
|
52
|
+
"snf",
|
|
53
|
+
"long-term-care",
|
|
54
|
+
"evergreen",
|
|
55
|
+
"payer-source",
|
|
56
|
+
"census",
|
|
57
|
+
"coinsurance"
|
|
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/fairstay-payer-source",
|
|
4
|
+
"title": "Fairstay Payer Source",
|
|
5
|
+
"description": "Payer source for every resident day",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"url": "https://github.com/fpavia111-creator/fairstay-agents",
|
|
9
|
+
"source": "github",
|
|
10
|
+
"subfolder": "packages/fairstay-payer-source"
|
|
11
|
+
},
|
|
12
|
+
"websiteUrl": "https://fair-agents.com/fairstay.html",
|
|
13
|
+
"packages": [
|
|
14
|
+
{
|
|
15
|
+
"registryType": "npm",
|
|
16
|
+
"identifier": "fairstay-payer-source",
|
|
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 'fairstay-core';
|
|
2
|
+
|
|
3
|
+
const f = { census: 'census.csv', residents: 'residents.csv', rules: 'rules.json', month: '2026-03' };
|
|
4
|
+
export const demo = (manifest) => runDemo(manifest, new URL('../fixtures', import.meta.url), 'Fairstay Payer Source', [
|
|
5
|
+
{ label: 'Check the payer for every resident day in March 2026', tool: 'payer_check', args: f, list: (i) => `${i.status.padEnd(25)} ${String(i.days).padStart(3)} day(s) ${i.message}` },
|
|
6
|
+
{ label: 'Write the payer source work list', tool: 'payer_write_report', args: f },
|
|
7
|
+
{ label: 'Teach another spelling of the Medicaid payer', tool: 'payer_learn', args: { kind: 'payer_alias', value: { alias: 'LS Medicaid', payer: 'Lone Star Medicaid (fictional)' } } },
|
|
8
|
+
{ label: 'Agent tries to change the census itself', tool: 'census_update', args: {} },
|
|
9
|
+
]);
|
package/src/index.js
ADDED
package/src/logic.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Fairstay Payer Source logic: every resident day has one proper payer. No I/O.
|
|
2
|
+
import { str, num, payerKey, round2, censusDays, dayRuns, sortByStatus, countBy, total, idKey } from 'fairstay-core';
|
|
3
|
+
|
|
4
|
+
const ORDER = { no_payer: 0, payer_overlap: 1, part_a_over_100: 2, unknown_payer: 3, hospice_on_part_a: 4, coinsurance_no_secondary: 5, private_no_guarantor: 6 };
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* opts: { start, end, payers: [{ name, type? }] | null, residents: [{ resident_id, secondary_payer, responsible_party, hospice_agency, part_a_days_used }], coinsuranceRate }
|
|
8
|
+
*/
|
|
9
|
+
export function checkPayerSource(censusRows, { start, end, payers = null, residents = [], coinsuranceRate = null } = {}) {
|
|
10
|
+
const all = censusDays(censusRows, undefined, end);
|
|
11
|
+
const known = payers ? new Set(payers.map((p) => payerKey(p.name))) : null;
|
|
12
|
+
const res = new Map(residents.map((r) => [idKey(r.resident_id || r.resident_name), r]));
|
|
13
|
+
// Part A day number per resident: count Part A days in date order (prior days from the residents file first).
|
|
14
|
+
const partA = new Map();
|
|
15
|
+
for (const d of all.filter((x) => x.payer_type === 'medicare_a').sort((a, b) => a.date.localeCompare(b.date))) {
|
|
16
|
+
const k = idKey(d.resident_id); const seen = partA.get(k) || { n: num((res.get(k) || {}).part_a_days_used) || 0, dates: new Set() };
|
|
17
|
+
if (!seen.dates.has(d.date)) { seen.n++; seen.dates.add(d.date); d.part_a_day = seen.n; }
|
|
18
|
+
partA.set(k, seen);
|
|
19
|
+
}
|
|
20
|
+
const days = all.filter((d) => d.date >= start && d.date <= end);
|
|
21
|
+
const byDay = new Map(); for (const d of days) { const k = `${idKey(d.resident_id)}|${d.date}`; if (!byDay.has(k)) byDay.set(k, []); byDay.get(k).push(d); }
|
|
22
|
+
const finds = [];
|
|
23
|
+
for (const ds of byDay.values()) {
|
|
24
|
+
const payersToday = [...new Set(ds.filter((d) => d.payer).map((d) => payerKey(d.payer)))];
|
|
25
|
+
if (payersToday.length > 1) finds.push({ ...ds[0], status: 'payer_overlap', other: ds.slice(1).map((d) => d.payer).join(', ') });
|
|
26
|
+
for (const d of ds.slice(0, 1)) {
|
|
27
|
+
const r = res.get(idKey(d.resident_id)) || {};
|
|
28
|
+
if (!d.payer) { finds.push({ ...d, status: 'no_payer' }); continue; }
|
|
29
|
+
if (known && !known.has(payerKey(d.payer))) finds.push({ ...d, status: 'unknown_payer' });
|
|
30
|
+
if (d.payer_type === 'medicare_a' && d.part_a_day > 100) finds.push({ ...d, status: 'part_a_over_100' });
|
|
31
|
+
if (d.payer_type === 'medicare_a' && d.part_a_day >= 21 && d.part_a_day <= 100 && !str(r.secondary_payer)) finds.push({ ...d, status: 'coinsurance_no_secondary', amount: coinsuranceRate || 0 });
|
|
32
|
+
if (d.payer_type === 'medicare_a' && str(r.hospice_agency)) finds.push({ ...d, status: 'hospice_on_part_a', hospice: str(r.hospice_agency) });
|
|
33
|
+
if (d.payer_type === 'private' && !str(r.responsible_party)) finds.push({ ...d, status: 'private_no_guarantor' });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const runs = dayRuns(finds, (f) => `${idKey(f.resident_id)}|${f.status}|${payerKey(f.payer)}`);
|
|
37
|
+
const items = runs.map((r) => {
|
|
38
|
+
const f = r.first; const span = r.from === r.to ? r.from : `${r.from} to ${r.to}`;
|
|
39
|
+
const firstDay = r.items[0].part_a_day; const lastDay = r.items.at(-1).part_a_day;
|
|
40
|
+
const T = {
|
|
41
|
+
no_payer: [`No payer on the census for ${span}.`, 'Set the payer for these days; nobody can be billed until it is set.'],
|
|
42
|
+
payer_overlap: [`Two payers on the census for ${span}: ${f.payer} and ${f.other}.`, 'End one payer the day the other starts.'],
|
|
43
|
+
unknown_payer: [`"${f.payer}" (${span}) is not on your payer list.`, 'Fix the spelling or add the payer (with its type and billing rules) to the payer list.'],
|
|
44
|
+
part_a_over_100: [`Medicare Part A ${lastDay !== firstDay ? `days ${firstDay} to ${lastDay}` : `day ${firstDay}`} (${span}); Part A covers at most 100 days per benefit period.`, 'Move these days to the next payer and give the required notices.'],
|
|
45
|
+
coinsurance_no_secondary: [`${lastDay !== firstDay ? `Part A days ${firstDay} to ${lastDay}` : `Part A day ${firstDay}`} (${span}) ${lastDay !== firstDay ? 'carry' : 'carries'} daily coinsurance, and no secondary payer is on file.`, 'Record the secondary payer (Medicaid crossover, supplemental plan) or bill the resident for the coinsurance.'],
|
|
46
|
+
hospice_on_part_a: [`The resident has a hospice agency (${f.hospice}) and is on Medicare Part A for ${span}.`, 'Part A SNF and hospice for the same terminal illness do not run together; confirm the skilled stay is for an unrelated condition, or fix the payer.'],
|
|
47
|
+
private_no_guarantor: [`Private pay for ${span} with no responsible party on file.`, 'Record who pays (resident, family, POA) and their billing address.'],
|
|
48
|
+
}[f.status];
|
|
49
|
+
return { status: f.status, resident_id: f.resident_id, resident_name: f.resident_name, payer: f.payer, from: r.from, to: r.to, days: r.days, amount: round2(r.items.reduce((s, x) => s + (x.amount || 0), 0)), message: T[0], fix: T[1] };
|
|
50
|
+
});
|
|
51
|
+
sortByStatus(items, ORDER);
|
|
52
|
+
return { period: { start, end }, residents: new Set(days.map((d) => idKey(d.resident_id))).size, resident_days: byDay.size, days_with_findings: new Set(finds.map((f) => `${idKey(f.resident_id)}|${f.date}`)).size, coinsurance_at_risk: total(items.filter((i) => i.status === 'coinsurance_no_secondary'), 'amount'), by_status: countBy(items, 'status'), items };
|
|
53
|
+
}
|
package/src/manifest.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { snfAgent, fileArg, MONTH_ARG, DATE_ARG, CENSUS_FIELDS, RESIDENT_ID, RESIDENT_NAME, EVERGREEN_LIMITS, monthBounds, payerKey } from 'fairstay-core';
|
|
3
|
+
import { checkPayerSource } from './logic.js';
|
|
4
|
+
|
|
5
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
6
|
+
|
|
7
|
+
export const RESIDENT_FIELDS = Object.freeze({
|
|
8
|
+
resident_id: RESIDENT_ID, resident_name: RESIDENT_NAME,
|
|
9
|
+
secondary_payer: { aliases: ['Secondary Payer', 'Secondary', 'Secondary Insurance', 'Coinsurance Payer', 'Supplemental'] },
|
|
10
|
+
responsible_party: { aliases: ['Responsible Party', 'Guarantor', 'Financially Responsible', 'POA', 'Billing Contact'] },
|
|
11
|
+
hospice_agency: { aliases: ['Hospice', 'Hospice Agency', 'Hospice Provider'] },
|
|
12
|
+
part_a_days_used: { aliases: ['Part A Days Used', 'Prior SNF Days', 'Benefit Days Used'], type: 'number' },
|
|
13
|
+
});
|
|
14
|
+
const RULES_SCHEMA = { type: 'object', additionalProperties: false, properties: {
|
|
15
|
+
payers: { type: 'array', maxItems: 2000, items: { type: 'object', additionalProperties: false, required: ['name'], properties: { name: { type: 'string', minLength: 1 }, type: { type: 'string' } } }, description: 'Your payer list (names as they appear on the census)' },
|
|
16
|
+
coinsurance_rate: { type: 'number', minimum: 0, description: 'Medicare SNF daily coinsurance for days 21-100 for the year (set it from the current CMS notice)' },
|
|
17
|
+
} };
|
|
18
|
+
export const MEMORY_KINDS = Object.freeze({
|
|
19
|
+
payer_alias: {
|
|
20
|
+
description: 'Another spelling of a payer on your list, e.g. {"alias": "LS Medicaid", "payer": "Lone Star Medicaid (fictional)"}.',
|
|
21
|
+
effect: 'treats the alias as a known payer, so it is not flagged as unknown_payer. It never changes other checks.',
|
|
22
|
+
schema: { type: 'object', additionalProperties: false, required: ['alias', 'payer'], properties: { alias: { type: 'string', minLength: 1, maxLength: 120 }, payer: { type: 'string', minLength: 1, maxLength: 120 }, note: { type: 'string', maxLength: 300 } } },
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
const args = {
|
|
26
|
+
census: fileArg('Census export under --root (rows with resident, payer, from, to; the to day is not counted)'),
|
|
27
|
+
residents: fileArg('Optional resident financial file under --root: secondary payer, responsible party, hospice agency, Part A days used earlier in the benefit period'),
|
|
28
|
+
rules: fileArg('Optional rules JSON: your payer list and the daily coinsurance rate'),
|
|
29
|
+
month: MONTH_ARG, start: DATE_ARG('Start of the period (YYYY-MM-DD) if not a whole month'), end: DATE_ARG('End of the period, inclusive'),
|
|
30
|
+
};
|
|
31
|
+
const run = (a, ctx) => {
|
|
32
|
+
const p = a.month ? monthBounds(a.month) : (a.start && a.end ? { start: a.start, end: a.end } : null);
|
|
33
|
+
if (!p) throw new Error('give month (YYYY-MM) or start and end');
|
|
34
|
+
const r = a.rules ? ctx.readJson(a.rules, 'payer_rules') : {};
|
|
35
|
+
const aliases = ctx.memoryFacts('payer_alias').map((f) => ({ name: f.value.alias }));
|
|
36
|
+
return checkPayerSource(ctx.records(a.census, 'census'), { start: p.start, end: p.end, payers: r.payers ? [...r.payers, ...aliases] : null, residents: a.residents ? ctx.records(a.residents, 'residents') : [], coinsuranceRate: r.coinsurance_rate ?? null });
|
|
37
|
+
};
|
|
38
|
+
const summary = (o) => `${o.residents} resident(s), ${o.resident_days} resident days, ${o.days_with_findings} day(s) with a payer problem. ${Object.entries(o.by_status).map(([k, v]) => `${k} ${v}`).join(', ') || 'No findings'}.${o.coinsurance_at_risk ? ` Coinsurance with no secondary payer: ${o.coinsurance_at_risk}.` : ''}`;
|
|
39
|
+
|
|
40
|
+
export const manifest = snfAgent({
|
|
41
|
+
pkg, prefix: 'payer', title: 'Fairstay Payer Source',
|
|
42
|
+
description: 'Checks that every nursing-home resident day has one proper payer: days with no payer, two payers on one day, payers not on your payer list, Medicare Part A past day 100, Part A coinsurance days with no secondary payer, hospice residents on Part A, and private pay with no responsible party. Resident identifiers are masked before results reach the model.',
|
|
43
|
+
args, required: ['census'],
|
|
44
|
+
sources: { census: { label: 'Census', args: ['census'], fields: CENSUS_FIELDS }, residents: { label: 'Resident financial file', args: ['residents'], fields: RESIDENT_FIELDS } },
|
|
45
|
+
configSchemas: { payer_rules: RULES_SCHEMA }, memoryKinds: MEMORY_KINDS, run, summary,
|
|
46
|
+
check: { title: 'Check payer source for every day', description: 'List runs of resident days with a missing, doubled, unknown or improper payer for a month (or start to end).' },
|
|
47
|
+
report: {
|
|
48
|
+
title: { en: 'Payer source work list', es: 'Lista de trabajo de fuente de pago', de: 'Arbeitsliste Kostenträger', fr: 'Liste de travail des payeurs', pt: 'Lista de trabalho de fonte pagadora', it: 'Elenco di lavoro dei pagatori', ja: '支払者確認作業リスト', zh: '付款方核查工作清单', ko: '지불자 확인 작업 목록' },
|
|
49
|
+
base: 'payer-source',
|
|
50
|
+
rows: (o) => o.items.map((i) => ({ status: i.status, resident_id: i.resident_id, resident_name: i.resident_name, payer: i.payer || '', from: i.from, to: i.to, days: i.days, amount: i.amount, message: i.message, fix: i.fix })),
|
|
51
|
+
htmlColumns: ['status', 'resident_name', 'payer', 'from', 'to', 'days', 'message', 'fix'],
|
|
52
|
+
limits: [EVERGREEN_LIMITS.files, 'Part A day counts use the census plus the earlier days you supply; the Common Working File is the record.', EVERGREEN_LIMITS.rules, EVERGREEN_LIMITS.advice],
|
|
53
|
+
},
|
|
54
|
+
refused: [{ name: 'census_update', category: 'production_deploy', description: 'Fairstay Payer Source never changes payers in PointClickCare or any other system.' }],
|
|
55
|
+
prompt: { title: 'Payer source review', description: 'Walks the host model through the payer source review with Fairstay Payer Source.', text: 'You are helping a business office manager with fairstay-payer-source.\n\nRules: Fairstay Payer Source reads files only. Resident names and ids are pseudonyms in results.\n\n1. Call payer_check for the month.\n2. Lead with no_payer and payer_overlap (nothing can be billed), then part_a_over_100.\n3. For unknown_payer that is a spelling, offer payer_learn (kind payer_alias).\n4. Call payer_write_report.' },
|
|
56
|
+
});
|