@pipeworx/mcp-meps 0.1.3 → 0.2.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/src/conditions.ts DELETED
@@ -1,108 +0,0 @@
1
- /**
2
- * Turning what a caller says into a CCSR condition category.
3
- *
4
- * MEPS codes conditions as CCSR categories — END010, MBD002 — and nobody asks
5
- * a question in those terms. An agent asks "what do people take for high
6
- * cholesterol". Without this the pack answers zero rows to almost every real
7
- * question, which reads as "we have no data" rather than "you used the wrong
8
- * vocabulary".
9
- *
10
- * Two layers: these hand-written synonyms for the way people actually speak,
11
- * then a trigram match against the official CCSR labels for everything else.
12
- */
13
-
14
- /** Everyday phrasing -> CCSR categories. Several codes where the plain word
15
- * genuinely spans them: "diabetes" is END002 and END003, and returning only
16
- * one of them would quietly halve the answer. */
17
- export const CONDITION_SYNONYMS: Record<string, string[]> = {
18
- // EVERY code below was checked against the HCUP CCSR reference file, because
19
- // a first pass written from memory got roughly a dozen of them wrong in a way
20
- // no test would catch: "epilepsy" pointed at cerebral palsy, "psoriasis" at
21
- // pressure ulcer, "hypothyroidism" at diabetes. Each would have returned a
22
- // confident, plausible, wrong list of drugs. If you add a synonym, look the
23
- // code up — do not recall it.
24
- 'high cholesterol': ['END010'],
25
- cholesterol: ['END010'],
26
- hyperlipidemia: ['END010'],
27
- 'lipid disorder': ['END010'],
28
- // END004/005/006 are diabetes categories too, but MEPS does not use them:
29
- // in the 2024 file every diabetes person sits in END002 or END003. Including
30
- // the unused codes would only widen the query, but naming them here would
31
- // imply a coverage that is not in the data.
32
- diabetes: ['END002', 'END003'],
33
- 'type 2 diabetes': ['END002', 'END003'],
34
- 'blood sugar': ['END002', 'END003'],
35
- obesity: ['END009'],
36
- 'weight loss': ['END009'],
37
- thyroid: ['END001'],
38
- hypothyroidism: ['END001'],
39
- 'high blood pressure': ['CIR007'],
40
- hypertension: ['CIR007'],
41
- 'heart failure': ['CIR019'],
42
- 'atrial fibrillation': ['CIR017'],
43
- afib: ['CIR017'],
44
- arrhythmia: ['CIR017'],
45
- 'coronary artery disease': ['CIR011'],
46
- 'pulmonary embolism': ['CIR013'],
47
- depression: ['MBD002'],
48
- depressive: ['MBD002'],
49
- anxiety: ['MBD005'],
50
- ocd: ['MBD006'],
51
- ptsd: ['MBD007'],
52
- bipolar: ['MBD003'],
53
- schizophrenia: ['MBD001'],
54
- psychosis: ['MBD001'],
55
- 'opioid use disorder': ['MBD018'],
56
- 'alcohol use disorder': ['MBD017'],
57
- smoking: ['MBD024'],
58
- 'tobacco use': ['MBD024'],
59
- insomnia: ['NVS016'],
60
- 'sleep disorder': ['NVS016'],
61
- epilepsy: ['NVS009'],
62
- seizures: ['NVS009'],
63
- migraine: ['NVS010'],
64
- headache: ['NVS010'],
65
- 'nerve pain': ['NVS019'],
66
- asthma: ['RSP009'],
67
- copd: ['RSP008'],
68
- emphysema: ['RSP008'],
69
- 'acid reflux': ['DIG004'],
70
- gerd: ['DIG004'],
71
- heartburn: ['DIG004'],
72
- arthritis: ['MUS006', 'MUS003'],
73
- osteoarthritis: ['MUS006'],
74
- 'rheumatoid arthritis': ['MUS003'],
75
- osteoporosis: ['MUS013'],
76
- 'back pain': ['MUS038'],
77
- 'low back pain': ['MUS038'],
78
- 'chronic pain': ['MUS010', 'MUS038', 'NVS019'],
79
- 'kidney disease': ['GEN003'],
80
- ckd: ['GEN003'],
81
- hiv: ['INF006'],
82
- glaucoma: ['EYE003'],
83
- // Deliberately absent: ADHD (CCSR splits it across neurodevelopmental and
84
- // impulse-control in a way the data does not settle), eczema and psoriasis
85
- // (no dedicated category — the nearest is "other specified inflammatory
86
- // condition of skin"), and allergies (the only "allergic" category is an
87
- // INJURY code for allergic reactions). Those fall through to the label
88
- // search, which reports which category it matched so a caller can see what
89
- // they actually got.
90
- };
91
-
92
- const CCSR_RE = /^[A-Z]{3}\d{3}$/;
93
-
94
- /** An exact CCSR code if the caller gave one, else the synonym hit, else null
95
- * meaning "fall through to a label search". */
96
- export function resolveConditionCodes(raw: string): string[] | null {
97
- const t = raw.trim();
98
- if (!t) return null;
99
- if (CCSR_RE.test(t.toUpperCase())) return [t.toUpperCase()];
100
- const lower = t.toLowerCase().replace(/\s+/g, ' ');
101
- if (CONDITION_SYNONYMS[lower]) return CONDITION_SYNONYMS[lower];
102
- // Longest containing synonym, so "type 2 diabetes mellitus" still resolves
103
- // and does not lose to the shorter "diabetes".
104
- const hit = Object.keys(CONDITION_SYNONYMS)
105
- .filter((k) => lower.includes(k))
106
- .sort((a, b) => b.length - a.length)[0];
107
- return hit ? CONDITION_SYNONYMS[hit] : null;
108
- }