fairpractice-referral-tracking 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (unreleased)
4
+
5
+ - First version (Fairpractice wave 2, ver 1).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kurt Francisco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,160 @@
1
- # Temporary Holding Version
1
+ <!-- Generated by scripts/readme.mjs from the agent itself. Edit the manifest or fixtures/README.md, then run npm run readme. -->
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # Fairpractice Referral Tracking (`fairpractice-referral-tracking`)
4
+
5
+ Tracks referrals in and out: outgoing referrals not scheduled, incoming referrals not contacted, scheduled referrals not seen, consult reports not back, and outgoing referrals sent outside the group for specialties you offer, with your own estimated value by specialty. Patient names are masked before results reach the model.
6
+
7
+ **Fairpractice Referral Tracking never calls, texts or writes to patients. Fairpractice Referral Tracking never sends or changes a referral.**
8
+
9
+ Fairpractice wave 2 ver 1 · Scheduling and intake · 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-referral-tracking demo
13
+ npx -y fairpractice-referral-tracking mcp --root ./practice-files
14
+ ```
15
+
16
+ ## What the sample data shows
17
+
18
+ Fictional data only: Cedar Ridge Medical Group (with its own heart center and orthopedics), made-up outside practices and made-up patients. Checked on 15 November 2026.
19
+
20
+ - [`referrals.csv`](fixtures/referrals.csv): nine referrals. Planted: RF-103, an incoming referral from 11 November, has no contact (4 days); RF-101, an outgoing cardiology referral from 20 October, is not scheduled (26 days); RF-104 was scheduled for 10 November and is not marked seen; RF-105 was seen 15 September with no consult report (61 days); RF-102 (cardiology) and RF-106 (gastroenterology) went to outside practices for specialties the group offers. RF-107 came in two days ago, RF-108 was cancelled and RF-109 is closed with its report.
21
+ - [`settings.json`](fixtures/settings.json): 14 days to schedule, 2 days to call back, 30 days for the report, the group's own names, the specialties it offers and an example value per referral for the leakage table. The values are made up; use your own. [`settings-typo.json`](fixtures/settings-typo.json) misspells a setting and is refused.
22
+
23
+ ## A demo run
24
+
25
+ `npx -y fairpractice-referral-tracking demo` runs the agent on the fictional files in [`fixtures/`](fixtures) in a temporary folder. Captured output:
26
+
27
+ ```text
28
+ Fairpractice Referral Tracking demo (fictional practice, patients, staff and payers)
29
+
30
+ ▶ Check referrals in and out
31
+ status: executed decision: allow
32
+ 6 outgoing and 2 incoming referral(s). 6 finding(s): in_not_contacted 1, out_not_scheduled 1, scheduled_not_seen 1, no_report_back 1, leakage 2. Estimated value of referrals sent outside: 2100.
33
+ in_not_contacted Incoming Primary Care referral RF-103 from 2026-11-11 has no contact or appointment after 4 days.
34
+ out_not_scheduled Outgoing Cardiology referral RF-101 to Cedar Ridge Heart Center from 2026-10-20 is not scheduled after 26 days.
35
+ scheduled_not_seen Referral RF-104 (Dermatology) was scheduled for 2026-11-10 and is not marked seen.
36
+ no_report_back Outgoing Orthopedics referral RF-105 was seen 2026-09-15; no consult report after 61 days.
37
+ leakage Outgoing Cardiology referral RF-102 went to Lantern Bay Cardiology Associates, though the group offers Cardiology.
38
+ leakage Outgoing Gastroenterology referral RF-106 went to Valley GI Partners, though the group offers Gastroenterology.
39
+
40
+ ▶ Write the coordinator worklist
41
+ status: executed decision: allow
42
+ Referral tracking written: 6 outgoing and 2 incoming referral(s). 6 finding(s): in_not_contacted 1, out_not_scheduled 1, scheduled_not_seen 1, no_report_back 1, leakage 2. Estimated value of referrals sent outside: 2100. Files: fairpractice-out/referrals/referral-tracking.csv, fairpractice-out/referrals/referral-tracking.html.
43
+
44
+ ▶ Agent tries to text a patient itself
45
+ status: blocked decision: block
46
+ reason: Fairpractice Referral Tracking never calls, texts or writes to patients.
47
+ ```
48
+
49
+ ## Tools
50
+
51
+ | Tool | What it does | Policy |
52
+ |---|---|---|
53
+ | `referrals_check` | List incoming referrals not contacted, outgoing not scheduled, scheduled not seen, reports not back and referrals sent outside for specialties you offer. | runs |
54
+ | `referrals_write_report` | Write referral-tracking.csv (one row per item, with blank owner and decision columns) and referral-tracking.html into out_dir (default fairpractice-out/referrals). | runs |
55
+ | `referrals_recall` | Search this agent's own memory of the customer's setup: accepted facts (in use) and facts waiting for a person. | runs |
56
+ | `referrals_learn` | Propose one fact about the customer's setup for this agent to remember. | runs |
57
+ | `referrals_accept_learning` | A named person accepts or rejects a fact waiting in this agent's memory. | one named click, even in Auto (`accept_learning`) |
58
+ | `referrals_retire_memory` | A named person stops an accepted fact from applying. | one named click, even in Auto (`accept_learning`) |
59
+ | `patient_message_send` | Fairpractice Referral Tracking never calls, texts or writes to patients. | refused |
60
+ | `referral_send` | Fairpractice Referral Tracking never sends or changes a referral. | refused |
61
+
62
+ 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.
63
+
64
+ ### `referrals_check` arguments
65
+
66
+ | Argument | What it is |
67
+ |---|---|
68
+ | `referrals` (required) | Referral log under --root: referral, patient, direction (in or out), date, specialty, referred-to organization, status, contact, appointment, visit and report dates |
69
+ | `settings` | Optional settings JSON: schedule_days, callback_days, report_days, in_network, offered, values |
70
+ | `as_of` | Date to measure deadlines and ages from (YYYY-MM-DD); default today |
71
+ | `status` | Only items with this status |
72
+ | `limit` | Most items to return to the model (the report file always has all of them) |
73
+
74
+ ## Columns it reads
75
+
76
+ 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.
77
+
78
+ 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-referral-tracking inspect <file>` (column names and shapes only, never values) and name any column it misses in `remedy-sources.json`.
79
+
80
+ ### Referral log (`referrals`)
81
+
82
+ | Column | Type | Read from |
83
+ |---|---|---|
84
+ | `referral_id` | text | Referral ID, Referral #, Order #, Referral Number |
85
+ | `patient_id` | text (masked) | Patient ID, Patient #, Patient Number, MRN, Medical Record Number, Chart #, Chart Number, Account # |
86
+ | `patient_name` | text (masked) | Patient, Patient Name, Name, Client, Client Name, Member, Member Name, Beneficiary |
87
+ | `direction` | text | Direction, In/Out, Type, Referral Type |
88
+ | `date` (required) | date | Date, Referral Date, Ordered, Received, Created |
89
+ | `specialty` | text | Specialty, Service, Department, Referred To Specialty |
90
+ | `to_org` | text | Referred To, To Organization, Receiving Provider, Receiving Practice, Facility |
91
+ | `status` | text | Status, Referral Status |
92
+ | `contacted` | date | Contacted, Patient Contacted, Call Date, First Contact |
93
+ | `scheduled` | date | Scheduled, Appointment Date, Scheduled Date |
94
+ | `seen` | date | Seen, Visit Date, Completed, Seen On |
95
+ | `report_received` | date | Report Received, Consult Note Received, Report Date, Loop Closed |
96
+
97
+ ## Settings file (`referrals_settings`)
98
+
99
+ 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.
100
+
101
+ | Setting | What it does |
102
+ |---|---|
103
+ | `schedule_days` | Days for an outgoing referral to be scheduled; default 14 |
104
+ | `callback_days` | Days to contact the patient on an incoming referral; default 2 |
105
+ | `report_days` | Days after the visit to receive the consult report; default 30 |
106
+ | `in_network` | Names of your own group, sites or partners; referrals to them are not leakage |
107
+ | `offered` | Specialties your group offers; outgoing referrals for these to other organizations are listed |
108
+ | `values` | Your own estimated value of one referral by specialty, for the leakage table (an estimate, not a forecast) |
109
+
110
+ ## Memory
111
+
112
+ `referrals_learn` only proposes a fact; nothing changes until a named person accepts it with `referrals_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.
113
+
114
+ | Kind | What an accepted fact does |
115
+ |---|---|
116
+
117
+ ## Install
118
+
119
+ Node 20 or newer. No other runtime dependencies besides `fairpractice-core` and `fairclaim-core`.
120
+
121
+ ```json
122
+ {
123
+ "mcpServers": {
124
+ "fairpractice-referral-tracking": {
125
+ "command": "npx",
126
+ "args": [
127
+ "-y",
128
+ "fairpractice-referral-tracking",
129
+ "mcp",
130
+ "--root",
131
+ "/path/to/practice-files"
132
+ ]
133
+ }
134
+ }
135
+ }
136
+ ```
137
+
138
+ Claude Code: `claude mcp add fairpractice-referral-tracking -- npx -y fairpractice-referral-tracking mcp --root .`, or use the plugin files in this folder.
139
+
140
+ ## CLI
141
+
142
+ ```bash
143
+ fairpractice-referral-tracking tools # every tool, its policy and arguments
144
+ fairpractice-referral-tracking sources # the columns each input is read from
145
+ fairpractice-referral-tracking inspect <file> # how a file would be read (names and shapes, never values)
146
+ fairpractice-referral-tracking call referrals_check '{"referrals":"<referrals>"}'
147
+ fairpractice-referral-tracking eval # the private eval cases on the fictional fixtures
148
+ fairpractice-referral-tracking demo
149
+ ```
150
+
151
+ ## Patient and staff data
152
+
153
+ 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.
154
+
155
+ ## Limits
156
+
157
+ - 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.
158
+ - 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.
159
+ - 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.
160
+ - 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-referral-tracking', demo, evalFile: fileURLToPath(new URL('../evals/cases.json', import.meta.url)) });
@@ -0,0 +1,287 @@
1
+ {
2
+ "suite": "fairpractice-referral-tracking",
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": "referrals_recall",
9
+ "args": {},
10
+ "expect": {
11
+ "status": "executed",
12
+ "contains": [
13
+ "memory is empty"
14
+ ]
15
+ }
16
+ },
17
+ {
18
+ "id": "refuses-patient_message_send",
19
+ "tool": "patient_message_send",
20
+ "args": {},
21
+ "expect": {
22
+ "status": "blocked"
23
+ }
24
+ },
25
+ {
26
+ "id": "refuses-referral_send",
27
+ "tool": "referral_send",
28
+ "args": {},
29
+ "expect": {
30
+ "status": "blocked"
31
+ }
32
+ },
33
+ {
34
+ "id": "report",
35
+ "tool": "referrals_write_report",
36
+ "args": {
37
+ "referrals": "fixtures/referrals.csv",
38
+ "settings": "fixtures/settings.json",
39
+ "as_of": "2026-11-15"
40
+ },
41
+ "expect": {
42
+ "status": "executed",
43
+ "matches": [
44
+ "\\.csv",
45
+ "\\.html"
46
+ ]
47
+ }
48
+ },
49
+ {
50
+ "id": "totals",
51
+ "tool": "referrals_check",
52
+ "args": {
53
+ "referrals": "fixtures/referrals.csv",
54
+ "settings": "fixtures/settings.json",
55
+ "as_of": "2026-11-15"
56
+ },
57
+ "expect": {
58
+ "status": "executed",
59
+ "equals": {
60
+ "result.referrals": 9,
61
+ "result.outgoing": 6,
62
+ "result.incoming": 2,
63
+ "result.estimated_leakage": 2100
64
+ }
65
+ }
66
+ },
67
+ {
68
+ "id": "every-planted-status-in-order",
69
+ "tool": "referrals_check",
70
+ "args": {
71
+ "referrals": "fixtures/referrals.csv",
72
+ "settings": "fixtures/settings.json",
73
+ "as_of": "2026-11-15"
74
+ },
75
+ "expect": {
76
+ "equals": {
77
+ "result.items.0.status": "in_not_contacted",
78
+ "result.items.1.status": "out_not_scheduled",
79
+ "result.items.2.status": "scheduled_not_seen",
80
+ "result.items.3.status": "no_report_back",
81
+ "result.items.4.status": "leakage",
82
+ "result.items.5.status": "leakage"
83
+ },
84
+ "length": {
85
+ "result.items": 6
86
+ }
87
+ }
88
+ },
89
+ {
90
+ "id": "status-filter",
91
+ "tool": "referrals_check",
92
+ "args": {
93
+ "referrals": "fixtures/referrals.csv",
94
+ "settings": "fixtures/settings.json",
95
+ "as_of": "2026-11-15",
96
+ "status": "in_not_contacted"
97
+ },
98
+ "expect": {
99
+ "status": "executed",
100
+ "equals": {
101
+ "result.items.0.status": "in_not_contacted"
102
+ }
103
+ }
104
+ },
105
+ {
106
+ "id": "limit-one",
107
+ "tool": "referrals_check",
108
+ "args": {
109
+ "referrals": "fixtures/referrals.csv",
110
+ "settings": "fixtures/settings.json",
111
+ "as_of": "2026-11-15",
112
+ "limit": 1
113
+ },
114
+ "expect": {
115
+ "status": "executed",
116
+ "length": {
117
+ "result.items": 1
118
+ }
119
+ }
120
+ },
121
+ {
122
+ "id": "report-spanish",
123
+ "tool": "referrals_write_report",
124
+ "args": {
125
+ "referrals": "fixtures/referrals.csv",
126
+ "settings": "fixtures/settings.json",
127
+ "as_of": "2026-11-15",
128
+ "language": "es"
129
+ },
130
+ "expect": {
131
+ "status": "executed"
132
+ }
133
+ },
134
+ {
135
+ "id": "report-japanese",
136
+ "tool": "referrals_write_report",
137
+ "args": {
138
+ "referrals": "fixtures/referrals.csv",
139
+ "settings": "fixtures/settings.json",
140
+ "as_of": "2026-11-15",
141
+ "language": "ja"
142
+ },
143
+ "expect": {
144
+ "status": "executed",
145
+ "matches": [
146
+ "\\.html"
147
+ ]
148
+ }
149
+ },
150
+ {
151
+ "id": "typo-setting-refused",
152
+ "tool": "referrals_check",
153
+ "args": {
154
+ "referrals": "fixtures/referrals.csv",
155
+ "settings": "fixtures/settings-typo.json",
156
+ "as_of": "2026-11-15"
157
+ },
158
+ "expect": {
159
+ "status": "error"
160
+ }
161
+ },
162
+ {
163
+ "id": "null-settings-refused",
164
+ "tool": "referrals_check",
165
+ "args": {
166
+ "referrals": "fixtures/referrals.csv",
167
+ "settings": null,
168
+ "as_of": "2026-11-15"
169
+ },
170
+ "expect": {
171
+ "status": "error"
172
+ }
173
+ },
174
+ {
175
+ "id": "file-outside-root-refused",
176
+ "tool": "referrals_check",
177
+ "args": {
178
+ "referrals": "../../outside-root.csv",
179
+ "settings": "fixtures/settings.json",
180
+ "as_of": "2026-11-15"
181
+ },
182
+ "expect": {
183
+ "status": "error",
184
+ "contains": [
185
+ "outside the allowed root"
186
+ ]
187
+ }
188
+ },
189
+ {
190
+ "id": "missing-file-named",
191
+ "tool": "referrals_check",
192
+ "args": {
193
+ "referrals": "fixtures/missing-export.csv",
194
+ "settings": "fixtures/settings.json",
195
+ "as_of": "2026-11-15"
196
+ },
197
+ "expect": {
198
+ "status": "error",
199
+ "contains": [
200
+ "not found",
201
+ "missing-export.csv"
202
+ ]
203
+ }
204
+ },
205
+ {
206
+ "id": "no-settings-defaults",
207
+ "tool": "referrals_check",
208
+ "args": {
209
+ "referrals": "fixtures/referrals.csv",
210
+ "as_of": "2026-11-15"
211
+ },
212
+ "expect": {
213
+ "status": "executed",
214
+ "not_contains": [
215
+ "\"leakage\""
216
+ ],
217
+ "equals": {
218
+ "result.by_status.out_not_scheduled": 1
219
+ }
220
+ }
221
+ },
222
+ {
223
+ "id": "incoming-callback-days",
224
+ "tool": "referrals_check",
225
+ "args": {
226
+ "referrals": "fixtures/referrals.csv",
227
+ "settings": "fixtures/settings.json",
228
+ "as_of": "2026-11-15",
229
+ "status": "in_not_contacted"
230
+ },
231
+ "expect": {
232
+ "equals": {
233
+ "result.items.0.referral_id": "RF-103",
234
+ "result.items.0.days": 4
235
+ }
236
+ }
237
+ },
238
+ {
239
+ "id": "report-age",
240
+ "tool": "referrals_check",
241
+ "args": {
242
+ "referrals": "fixtures/referrals.csv",
243
+ "settings": "fixtures/settings.json",
244
+ "as_of": "2026-11-15",
245
+ "status": "no_report_back"
246
+ },
247
+ "expect": {
248
+ "equals": {
249
+ "result.items.0.referral_id": "RF-105",
250
+ "result.items.0.days": 61
251
+ }
252
+ }
253
+ },
254
+ {
255
+ "id": "leakage-table",
256
+ "tool": "referrals_check",
257
+ "args": {
258
+ "referrals": "fixtures/referrals.csv",
259
+ "settings": "fixtures/settings.json",
260
+ "as_of": "2026-11-15"
261
+ },
262
+ "expect": {
263
+ "equals": {
264
+ "result.leakage_by_specialty.0.specialty": "Cardiology",
265
+ "result.leakage_by_specialty.0.estimated_value": 1200,
266
+ "result.leakage_by_specialty.1.specialty": "Gastroenterology"
267
+ }
268
+ }
269
+ },
270
+ {
271
+ "id": "closed-and-recent-not-listed",
272
+ "tool": "referrals_check",
273
+ "args": {
274
+ "referrals": "fixtures/referrals.csv",
275
+ "settings": "fixtures/settings.json",
276
+ "as_of": "2026-11-15"
277
+ },
278
+ "expect": {
279
+ "not_contains": [
280
+ "RF-107",
281
+ "RF-108",
282
+ "RF-109"
283
+ ]
284
+ }
285
+ }
286
+ ]
287
+ }
@@ -0,0 +1,6 @@
1
+ # Fixtures
2
+
3
+ Fictional data only: Cedar Ridge Medical Group (with its own heart center and orthopedics), made-up outside practices and made-up patients. Checked on 15 November 2026.
4
+
5
+ - `referrals.csv`: nine referrals. Planted: RF-103, an incoming referral from 11 November, has no contact (4 days); RF-101, an outgoing cardiology referral from 20 October, is not scheduled (26 days); RF-104 was scheduled for 10 November and is not marked seen; RF-105 was seen 15 September with no consult report (61 days); RF-102 (cardiology) and RF-106 (gastroenterology) went to outside practices for specialties the group offers. RF-107 came in two days ago, RF-108 was cancelled and RF-109 is closed with its report.
6
+ - `settings.json`: 14 days to schedule, 2 days to call back, 30 days for the report, the group's own names, the specialties it offers and an example value per referral for the leakage table. The values are made up; use your own. `settings-typo.json` misspells a setting and is refused.
@@ -0,0 +1,109 @@
1
+ {
2
+ "case": "totals",
3
+ "id": [
4
+ [
5
+ "referral_id"
6
+ ]
7
+ ],
8
+ "planted": [
9
+ ["RF-103", "in_not_contacted"],
10
+ ["RF-101", "out_not_scheduled"],
11
+ ["RF-104", "scheduled_not_seen"],
12
+ ["RF-105", "no_report_back"],
13
+ ["RF-102", "leakage"],
14
+ ["RF-106", "leakage"]
15
+ ],
16
+ "clean": [
17
+ {
18
+ "arg": "referrals",
19
+ "set": [
20
+ {
21
+ "where": ["Referral #", "RF-101"],
22
+ "column": "Referral Date",
23
+ "value": "2026-11-05"
24
+ },
25
+ {
26
+ "where": ["Referral #", "RF-102"],
27
+ "column": "Referred To",
28
+ "value": "Cedar Ridge Heart Center"
29
+ },
30
+ {
31
+ "where": ["Referral #", "RF-103"],
32
+ "column": "Patient Contacted",
33
+ "value": "2026-11-12"
34
+ },
35
+ {
36
+ "where": ["Referral #", "RF-104"],
37
+ "column": "Seen On",
38
+ "value": "2026-11-10"
39
+ },
40
+ {
41
+ "where": ["Referral #", "RF-105"],
42
+ "column": "Report Received",
43
+ "value": "2026-09-20"
44
+ },
45
+ {
46
+ "where": ["Referral #", "RF-106"],
47
+ "column": "Referred To",
48
+ "value": "Cedar Ridge GI"
49
+ }
50
+ ]
51
+ }
52
+ ],
53
+ "mutations": [
54
+ {
55
+ "name": "incoming referral two days older",
56
+ "edits": [
57
+ {
58
+ "arg": "referrals",
59
+ "set": [
60
+ {
61
+ "where": ["Referral #", "RF-107"],
62
+ "column": "Referral Date",
63
+ "value": "2026-11-10"
64
+ }
65
+ ]
66
+ }
67
+ ],
68
+ "expect": [
69
+ ["RF-107", "in_not_contacted"]
70
+ ]
71
+ },
72
+ {
73
+ "name": "orthopedic referral sent out of network",
74
+ "edits": [
75
+ {
76
+ "arg": "referrals",
77
+ "set": [
78
+ {
79
+ "where": ["Referral #", "RF-104"],
80
+ "column": "Specialty",
81
+ "value": "Orthopedics"
82
+ }
83
+ ]
84
+ }
85
+ ],
86
+ "expect": [
87
+ ["RF-104", "leakage"]
88
+ ]
89
+ },
90
+ {
91
+ "name": "open referral 16 days old",
92
+ "edits": [
93
+ {
94
+ "arg": "referrals",
95
+ "set": [
96
+ {
97
+ "where": ["Referral #", "RF-101"],
98
+ "column": "Referral Date",
99
+ "value": "2026-10-30"
100
+ }
101
+ ]
102
+ }
103
+ ],
104
+ "expect": [
105
+ ["RF-101", "out_not_scheduled"]
106
+ ]
107
+ }
108
+ ]
109
+ }
@@ -0,0 +1 @@
1
+ { "note": "Fictional patient names and ids used in these fixtures. None may reach a model result when masking is on.", "values": ["Avery Lund", "Bianca Ode", "Cyril Haas", "Ezra Mole", "P1803"] }
@@ -0,0 +1,10 @@
1
+ Referral #,Patient #,Patient Name,Direction,Referral Date,Specialty,Referred To,Status,Patient Contacted,Appointment Date,Seen On,Report Received
2
+ RF-101,P1801,Avery Lund,Out,2026-10-20,Cardiology,Cedar Ridge Heart Center,Open,,,,
3
+ RF-102,P1802,Bianca Ode,Out,2026-10-05,Cardiology,Lantern Bay Cardiology Associates,Scheduled,,2026-10-30,2026-10-30,
4
+ RF-103,P1803,Cyril Haas,In,2026-11-11,Primary Care,Cedar Ridge Medical Group,Open,,,,
5
+ RF-104,P1804,Dina Vos,Out,2026-10-25,Dermatology,Prairie Skin Clinic,Scheduled,,2026-11-10,,
6
+ RF-105,P1805,Ezra Mole,Out,2026-09-01,Orthopedics,Cedar Ridge Orthopedics,Completed,,2026-09-15,2026-09-15,
7
+ RF-106,P1806,Fiona Lake,Out,2026-11-01,Gastroenterology,Valley GI Partners,Scheduled,,2026-11-28,,
8
+ RF-107,P1807,Gil Ames,In,2026-11-13,Cardiology,Cedar Ridge Heart Center,Open,,,,
9
+ RF-108,P1808,Hana Roe,Out,2026-10-02,Endocrinology,Copperline Endocrine,Cancelled,,,,
10
+ RF-109,P1809,Ivo Barr,Out,2026-10-10,Orthopedics,Cedar Ridge Orthopedics,Completed,,2026-10-20,2026-10-20,2026-10-25
@@ -0,0 +1 @@
1
+ { "schedule_day": 14 }
@@ -0,0 +1 @@
1
+ { "schedule_days": 14, "callback_days": 2, "report_days": 30, "in_network": ["Cedar Ridge"], "offered": ["Cardiology", "Orthopedics", "Gastroenterology", "Primary Care"], "values": { "Cardiology": 1200, "Gastroenterology": 900, "Orthopedics": 1500 } }
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "fairpractice-referral-tracking",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "mcpName": "io.github.fpavia111-creator/fairpractice-referral-tracking",
5
+ "description": "Referral tracking: referrals out not scheduled, referrals in not called back, scheduled referrals not seen, consult reports not back, and referrals sent outside the group for specialties you offer, with an estimated value by specialty.",
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-referral-tracking": "bin/fairpractice-referral-tracking.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-referral-tracking.js demo",
33
+ "eval": "node bin/fairpractice-referral-tracking.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-referral-tracking"
42
+ },
43
+ "homepage": "https://github.com/fpavia111-creator/fairpractice2-agents/tree/master/packages/fairpractice-referral-tracking#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
+ "referrals",
55
+ "leakage",
56
+ "scheduling",
57
+ "care-coordination"
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-referral-tracking",
4
+ "title": "Fairpractice Referral Tracking",
5
+ "description": "Referral tracking: referrals out not scheduled, referrals in not called back, scheduled referrals…",
6
+ "version": "0.1.0",
7
+ "repository": {
8
+ "url": "https://github.com/fpavia111-creator/fairpractice2-agents",
9
+ "source": "github",
10
+ "subfolder": "packages/fairpractice-referral-tracking"
11
+ },
12
+ "websiteUrl": "https://fair-agents.com/fairpractice.html",
13
+ "packages": [
14
+ {
15
+ "registryType": "npm",
16
+ "identifier": "fairpractice-referral-tracking",
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 = { referrals: 'referrals.csv', settings: 'settings.json', as_of: '2026-11-15' };
5
+ export const demo = () => runDemo(manifest, new URL('../fixtures', import.meta.url), 'Fairpractice Referral Tracking', [
6
+ { label: 'Check referrals in and out', tool: 'referrals_check', args: f, list: (i) => `${i.status.padEnd(20)} ${i.message}` },
7
+ { label: 'Write the coordinator worklist', tool: 'referrals_write_report', args: f },
8
+ { label: 'Agent tries to text a patient itself', tool: 'patient_message_send', args: {} },
9
+ ]);
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { manifest } from './manifest.js';
2
+ export * from './logic.js';
package/src/logic.js ADDED
@@ -0,0 +1,41 @@
1
+ // Referral tracking logic: referrals in and out against your timing settings, consult reports and referrals sent outside the group. No I/O.
2
+ import { str, num, isoDate, daysBetween, round2, lookupRule, sortByStatus, countBy } from 'fairpractice-core';
3
+
4
+ const ORDER = { in_not_contacted: 0, out_not_scheduled: 1, scheduled_not_seen: 2, no_report_back: 3, leakage: 4 };
5
+ const CLOSED = /cancel|declin|withdr|closed|void|duplicate/i;
6
+ const norm = (s) => str(s).toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
7
+
8
+ /**
9
+ * referrals: [{ referral_id, patient_id, patient_name, direction, date, specialty, to_org, status, contacted, scheduled, seen, report_received }]
10
+ * opts: { asOf, scheduleDays = 14, callbackDays = 2, reportDays = 30, inNetwork = [], offered = [], values = {} }
11
+ */
12
+ export function checkReferrals(referrals, { asOf, scheduleDays = 14, callbackDays = 2, reportDays = 30, inNetwork = [], offered = [], values = {} } = {}) {
13
+ const own = inNetwork.map(norm).filter(Boolean); const inHouse = new Set(offered.map(norm));
14
+ const items = []; const leak = new Map(); let out = 0, inbound = 0;
15
+ for (const [i, r] of referrals.entries()) {
16
+ const date = isoDate(r.date); if (!date || CLOSED.test(str(r.status))) continue;
17
+ const dir = /^in/i.test(str(r.direction)) ? 'in' : 'out'; dir === 'in' ? inbound++ : out++;
18
+ const sched = isoDate(r.scheduled), seen = isoDate(r.seen), rep = isoDate(r.report_received), contacted = isoDate(r.contacted);
19
+ const spec = str(r.specialty) || '(no specialty)';
20
+ const base = { referral_id: str(r.referral_id) || `line ${i + 1}`, patient_id: str(r.patient_id) || null, patient_name: str(r.patient_name) || null, direction: dir, date, specialty: spec, to_org: str(r.to_org) || null, amount: 0 };
21
+ const age = daysBetween(date, asOf);
22
+ if (dir === 'in' && !contacted && !sched && age > callbackDays) items.push({ ...base, status: 'in_not_contacted', days: age });
23
+ if (dir === 'out' && !sched && !seen && age > scheduleDays) items.push({ ...base, status: 'out_not_scheduled', days: age });
24
+ if (sched && sched < asOf && !seen) items.push({ ...base, status: 'scheduled_not_seen', scheduled: sched, days: daysBetween(sched, asOf) });
25
+ if (dir === 'out' && seen && !rep && daysBetween(seen, asOf) > reportDays) items.push({ ...base, status: 'no_report_back', seen, days: daysBetween(seen, asOf) });
26
+ if (dir === 'out' && inHouse.has(norm(spec))) {
27
+ const to = norm(r.to_org); const inside = own.some((o) => to && (to === o || to.includes(o)));
28
+ if (!inside) { const v = num(lookupRule(values, spec)) || 0; items.push({ ...base, status: 'leakage', amount: v }); const l = leak.get(spec) || { specialty: spec, referrals: 0, estimated_value: 0 }; l.referrals++; l.estimated_value = round2(l.estimated_value + v); leak.set(spec, l); }
29
+ }
30
+ }
31
+ const T = {
32
+ in_not_contacted: (x) => [`Incoming ${x.specialty} referral ${x.referral_id} from ${x.date} has no contact or appointment after ${x.days} days.`, 'Call the patient and the referring office today.'],
33
+ out_not_scheduled: (x) => [`Outgoing ${x.specialty} referral ${x.referral_id} to ${x.to_org || 'an unnamed office'} from ${x.date} is not scheduled after ${x.days} days.`, 'Follow up with the patient and the receiving office, and record the appointment.'],
34
+ scheduled_not_seen: (x) => [`Referral ${x.referral_id} (${x.specialty}) was scheduled for ${x.scheduled} and is not marked seen.`, 'Find out whether the patient was seen, missed it or needs a new date.'],
35
+ no_report_back: (x) => [`Outgoing ${x.specialty} referral ${x.referral_id} was seen ${x.seen}; no consult report after ${x.days} days.`, 'Ask the specialist\'s office for the report so the loop is closed.'],
36
+ leakage: (x) => [`Outgoing ${x.specialty} referral ${x.referral_id} went to ${x.to_org || 'an outside office'}, though the group offers ${x.specialty}.`, 'Review with the referring provider; the patient may have a reason or preference.'],
37
+ };
38
+ for (const it of items) { const [m, f] = T[it.status](it); it.message = m; it.fix = f; }
39
+ sortByStatus(items, ORDER, 'days');
40
+ return { referrals: referrals.length, outgoing: out, incoming: inbound, leakage_by_specialty: [...leak.values()].sort((a, b) => b.estimated_value - a.estimated_value), estimated_leakage: round2([...leak.values()].reduce((s, x) => s + x.estimated_value, 0)), by_status: countBy(items, 'status'), items };
41
+ }
@@ -0,0 +1,71 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { medAgent, fileArg, AS_OF_ARG, PATIENT_ID, PATIENT_NAME, PRACTICE_LIMITS, today } from 'fairpractice-core';
3
+ import { checkReferrals } 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
+
9
+ export const REFERRAL_FIELDS = Object.freeze({
10
+ referral_id: t(['Referral ID', 'Referral #', 'Order #', 'Referral Number'], { translate: false }),
11
+ patient_id: PATIENT_ID, patient_name: PATIENT_NAME,
12
+ direction: t(['Direction', 'In/Out', 'Type', 'Referral Type'], { translate: false }),
13
+ date: t(['Date', 'Referral Date', 'Ordered', 'Received', 'Created'], { type: 'date', translate: 'date', required: true }),
14
+ specialty: t(['Specialty', 'Service', 'Department', 'Referred To Specialty'], { translate: 'category' }),
15
+ to_org: t(['Referred To', 'To Organization', 'Receiving Provider', 'Receiving Practice', 'Facility'], { translate: false }),
16
+ status: t(['Status', 'Referral Status'], { translate: 'status' }),
17
+ contacted: D(['Contacted', 'Patient Contacted', 'Call Date', 'First Contact']),
18
+ scheduled: D(['Scheduled', 'Appointment Date', 'Scheduled Date']),
19
+ seen: D(['Seen', 'Visit Date', 'Completed', 'Seen On']),
20
+ report_received: D(['Report Received', 'Consult Note Received', 'Report Date', 'Loop Closed']),
21
+ });
22
+
23
+ const SETTINGS = { type: 'object', additionalProperties: false, properties: {
24
+ schedule_days: { type: 'integer', minimum: 1, maximum: 120, description: 'Days for an outgoing referral to be scheduled; default 14' },
25
+ callback_days: { type: 'integer', minimum: 0, maximum: 30, description: 'Days to contact the patient on an incoming referral; default 2' },
26
+ report_days: { type: 'integer', minimum: 1, maximum: 180, description: 'Days after the visit to receive the consult report; default 30' },
27
+ in_network: { type: 'array', items: { type: 'string', maxLength: 120 }, maxItems: 50, description: 'Names of your own group, sites or partners; referrals to them are not leakage' },
28
+ offered: { type: 'array', items: { type: 'string', maxLength: 80 }, maxItems: 100, description: 'Specialties your group offers; outgoing referrals for these to other organizations are listed' },
29
+ values: { type: 'object', additionalProperties: { type: 'number', minimum: 0 }, description: 'Your own estimated value of one referral by specialty, for the leakage table (an estimate, not a forecast)' },
30
+ } };
31
+
32
+ const args = {
33
+ referrals: fileArg('Referral log under --root: referral, patient, direction (in or out), date, specialty, referred-to organization, status, contact, appointment, visit and report dates'),
34
+ settings: fileArg('Optional settings JSON: schedule_days, callback_days, report_days, in_network, offered, values'),
35
+ as_of: AS_OF_ARG,
36
+ };
37
+ const run = (a, ctx) => {
38
+ const s = a.settings ? ctx.readJson(a.settings, 'referrals_settings') : {};
39
+ return checkReferrals(ctx.records(a.referrals, 'referrals'), { asOf: a.as_of || today(), scheduleDays: s.schedule_days ?? 14, callbackDays: s.callback_days ?? 2, reportDays: s.report_days ?? 30, inNetwork: s.in_network || [], offered: s.offered || [], values: s.values || {} });
40
+ };
41
+ const summary = (o) => `${o.outgoing} outgoing and ${o.incoming} incoming referral(s). ${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'}. Estimated value of referrals sent outside: ${o.estimated_leakage}.`;
42
+
43
+ export const manifest = medAgent({
44
+ pkg, prefix: 'referrals', title: 'Fairpractice Referral Tracking',
45
+ description: 'Tracks referrals in and out: outgoing referrals not scheduled, incoming referrals not contacted, scheduled referrals not seen, consult reports not back, and outgoing referrals sent outside the group for specialties you offer, with your own estimated value by specialty. Patient names are masked before results reach the model.',
46
+ args, required: ['referrals'],
47
+ sources: { referrals: { label: 'Referral log', args: ['referrals'], fields: REFERRAL_FIELDS } },
48
+ configSchemas: { referrals_settings: SETTINGS }, memoryKinds: {},
49
+ run, summary,
50
+ check: { title: 'Check referrals', description: 'List incoming referrals not contacted, outgoing not scheduled, scheduled not seen, reports not back and referrals sent outside for specialties you offer.' },
51
+ report: {
52
+ title: { en: 'Referral tracking', es: 'Seguimiento de derivaciones', de: 'Überweisungsverfolgung', fr: 'Suivi des orientations', pt: 'Acompanhamento de encaminhamentos', it: 'Monitoraggio delle invii', ja: '紹介状の追跡', zh: '转诊跟踪', ko: '의뢰 추적' },
53
+ base: 'referral-tracking',
54
+ rows: (o) => o.items.map((i) => ({ status: i.status, referral_id: i.referral_id, patient_id: i.patient_id || '', patient_name: i.patient_name || '', direction: i.direction, date: i.date, specialty: i.specialty, to_org: i.to_org || '', amount: i.amount, message: i.message, fix: i.fix })),
55
+ htmlColumns: ['status', 'referral_id', 'patient_name', 'direction', 'date', 'specialty', 'to_org', 'message'],
56
+ sections: (o) => [{ title: { en: 'Referrals sent outside, by specialty (estimate)' }, rows: o.leakage_by_specialty, columns: ['specialty', 'referrals', 'estimated_value'] }],
57
+ limits: [PRACTICE_LIMITS.files, PRACTICE_LIMITS.estimate, 'Patients choose where they go; a referral sent outside is a question for the referring provider, not an error. It sends nothing to patients or offices.', PRACTICE_LIMITS.advice, PRACTICE_LIMITS.phi],
58
+ },
59
+ refused: [
60
+ { name: 'patient_message_send', category: 'binding_send', description: 'Fairpractice Referral Tracking never calls, texts or writes to patients.' },
61
+ { name: 'referral_send', category: 'binding_send', description: 'Fairpractice Referral Tracking never sends or changes a referral.' },
62
+ ],
63
+ prompt: { title: 'Referral review', description: 'Walks the host model through a weekly referral review.', text: `You are helping a referral coordinator with fairpractice-referral-tracking.
64
+
65
+ Rules: it only reads the log. Patient names in results are pseudonyms.
66
+
67
+ 1. Call referrals_check with the referral log, settings and as_of.
68
+ 2. Lead with incoming referrals not contacted and outgoing not scheduled.
69
+ 3. Present leakage as a question for the referring provider, with the estimate labeled as one.
70
+ 4. Call referrals_write_report for the coordinator.` },
71
+ });