tebra-mcp-server 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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +103 -0
  3. package/dist/config.d.ts +16 -0
  4. package/dist/config.d.ts.map +1 -0
  5. package/dist/config.js +35 -0
  6. package/dist/config.js.map +1 -0
  7. package/dist/index.d.ts +18 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +104 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/soap-client.d.ts +14 -0
  12. package/dist/soap-client.d.ts.map +1 -0
  13. package/dist/soap-client.js +108 -0
  14. package/dist/soap-client.js.map +1 -0
  15. package/dist/tools/appointments.d.ts +33 -0
  16. package/dist/tools/appointments.d.ts.map +1 -0
  17. package/dist/tools/appointments.js +80 -0
  18. package/dist/tools/appointments.js.map +1 -0
  19. package/dist/tools/authorizations.d.ts +25 -0
  20. package/dist/tools/authorizations.d.ts.map +1 -0
  21. package/dist/tools/authorizations.js +101 -0
  22. package/dist/tools/authorizations.js.map +1 -0
  23. package/dist/tools/charges.d.ts +33 -0
  24. package/dist/tools/charges.d.ts.map +1 -0
  25. package/dist/tools/charges.js +78 -0
  26. package/dist/tools/charges.js.map +1 -0
  27. package/dist/tools/eligibility.d.ts +29 -0
  28. package/dist/tools/eligibility.d.ts.map +1 -0
  29. package/dist/tools/eligibility.js +98 -0
  30. package/dist/tools/eligibility.js.map +1 -0
  31. package/dist/tools/encounters.d.ts +100 -0
  32. package/dist/tools/encounters.d.ts.map +1 -0
  33. package/dist/tools/encounters.js +186 -0
  34. package/dist/tools/encounters.js.map +1 -0
  35. package/dist/tools/patients.d.ts +40 -0
  36. package/dist/tools/patients.d.ts.map +1 -0
  37. package/dist/tools/patients.js +151 -0
  38. package/dist/tools/patients.js.map +1 -0
  39. package/dist/tools/procedure-codes.d.ts +25 -0
  40. package/dist/tools/procedure-codes.d.ts.map +1 -0
  41. package/dist/tools/procedure-codes.js +56 -0
  42. package/dist/tools/procedure-codes.js.map +1 -0
  43. package/package.json +54 -0
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ /**
3
+ * Tebra MCP tools: Patient authorization retrieval.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.authorizationTools = void 0;
7
+ exports.handleAuthorizationTool = handleAuthorizationTool;
8
+ const soap_client_js_1 = require("../soap-client.js");
9
+ // ─── Tool Definitions ───────────────────────────────────────────
10
+ exports.authorizationTools = [
11
+ {
12
+ name: 'tebra_get_patient_authorizations',
13
+ description: 'Get all authorizations for a Tebra patient across all cases. Returns auth number, approved/used/remaining visits, expiry dates, and covered CPT codes.',
14
+ inputSchema: {
15
+ type: 'object',
16
+ properties: {
17
+ patientId: {
18
+ type: 'string',
19
+ description: 'Tebra patient ID',
20
+ },
21
+ },
22
+ required: ['patientId'],
23
+ },
24
+ },
25
+ ];
26
+ // ─── Tool Handler ───────────────────────────────────────────────
27
+ async function handleAuthorizationTool(name, args, config) {
28
+ if (name !== 'tebra_get_patient_authorizations') {
29
+ return { content: [{ type: 'text', text: `Unknown authorization tool: ${name}` }] };
30
+ }
31
+ const patientId = String(args.patientId ?? '');
32
+ if (!patientId) {
33
+ return { content: [{ type: 'text', text: 'patientId is required.' }] };
34
+ }
35
+ const bodyXml = `
36
+ <kar:request>
37
+ <kar:Fields>
38
+ <kar:PatientID>${(0, soap_client_js_1.escapeXml)(patientId)}</kar:PatientID>
39
+ </kar:Fields>
40
+ </kar:request>`;
41
+ const xml = await (0, soap_client_js_1.soapRequest)(config, 'GetPatient', bodyXml);
42
+ const patientBlock = (0, soap_client_js_1.extractTag)(xml, 'Patient');
43
+ if (!patientBlock) {
44
+ return { content: [{ type: 'text', text: `Patient not found: ${patientId}` }] };
45
+ }
46
+ const caseBlocks = (0, soap_client_js_1.extractAllTags)(patientBlock, 'CaseData');
47
+ const authorizations = [];
48
+ for (const caseBlock of caseBlocks) {
49
+ const caseName = (0, soap_client_js_1.extractTag)(caseBlock, 'CaseName') || (0, soap_client_js_1.extractTag)(caseBlock, 'Name');
50
+ const authBlocks = (0, soap_client_js_1.extractAllTags)(caseBlock, 'AuthorizationData');
51
+ for (const authBlock of authBlocks) {
52
+ const approved = (0, soap_client_js_1.extractNumber)(authBlock, 'ApprovedVisits');
53
+ const used = (0, soap_client_js_1.extractNumber)(authBlock, 'UsedVisits');
54
+ const remaining = Math.max(0, approved - used);
55
+ const endDate = (0, soap_client_js_1.extractTag)(authBlock, 'EndDate');
56
+ const authNumber = (0, soap_client_js_1.extractTag)(authBlock, 'AuthorizationNumber');
57
+ let status = 'active';
58
+ if (remaining <= 0)
59
+ status = 'exhausted';
60
+ else if (endDate && new Date(endDate) < new Date())
61
+ status = 'expired';
62
+ else if (!authNumber)
63
+ status = 'pending';
64
+ // Check if expiring within 30 days
65
+ let expiringWarning;
66
+ if (status === 'active' && endDate) {
67
+ const daysUntilExpiry = Math.ceil((new Date(endDate).getTime() - Date.now()) / (1000 * 60 * 60 * 24));
68
+ if (daysUntilExpiry <= 30 && daysUntilExpiry > 0) {
69
+ expiringWarning = `Authorization expires in ${daysUntilExpiry} days`;
70
+ }
71
+ }
72
+ const cptCodesRaw = (0, soap_client_js_1.extractTag)(authBlock, 'CPTCodes') || (0, soap_client_js_1.extractTag)(authBlock, 'ProcedureCodes');
73
+ const diagCodesRaw = (0, soap_client_js_1.extractTag)(authBlock, 'DiagnosisCodes');
74
+ authorizations.push({
75
+ caseName,
76
+ authorizationId: (0, soap_client_js_1.extractTag)(authBlock, 'AuthorizationID') || (0, soap_client_js_1.extractTag)(authBlock, 'ID'),
77
+ authNumber,
78
+ insurancePlan: (0, soap_client_js_1.extractTag)(authBlock, 'InsurancePlanName'),
79
+ status,
80
+ approvedVisits: approved,
81
+ usedVisits: used,
82
+ remainingVisits: remaining,
83
+ startDate: (0, soap_client_js_1.extractTag)(authBlock, 'StartDate'),
84
+ endDate,
85
+ approvedCptCodes: cptCodesRaw ? cptCodesRaw.split(',').map((c) => c.trim()).filter(Boolean) : [],
86
+ diagnosisCodes: diagCodesRaw ? diagCodesRaw.split(',').map((c) => c.trim()).filter(Boolean) : [],
87
+ notes: (0, soap_client_js_1.extractTag)(authBlock, 'Notes'),
88
+ expiringWarning,
89
+ });
90
+ }
91
+ }
92
+ if (authorizations.length === 0) {
93
+ return {
94
+ content: [{ type: 'text', text: `No authorizations found for patient ${patientId}.` }],
95
+ };
96
+ }
97
+ return {
98
+ content: [{ type: 'text', text: JSON.stringify(authorizations, null, 2) }],
99
+ };
100
+ }
101
+ //# sourceMappingURL=authorizations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorizations.js","sourceRoot":"","sources":["../../src/tools/authorizations.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAiCH,0DAyFC;AAvHD,sDAM2B;AAE3B,mEAAmE;AAEtD,QAAA,kBAAkB,GAAG;IAChC;QACE,IAAI,EAAE,kCAAkC;QACxC,WAAW,EACT,wJAAwJ;QAC1J,WAAW,EAAE;YACX,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,kBAAkB;iBAChC;aACF;YACD,QAAQ,EAAE,CAAC,WAAW,CAAC;SACxB;KACF;CACF,CAAC;AAEF,mEAAmE;AAE5D,KAAK,UAAU,uBAAuB,CAC3C,IAAY,EACZ,IAA6B,EAC7B,MAAmB;IAEnB,IAAI,IAAI,KAAK,kCAAkC,EAAE,CAAC;QAChD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,+BAA+B,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;IACtF,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;IAC/C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,EAAE,OAAO,EAAE,CAA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AAM;gBACN,cAAc,EAAE,QAAQ;gBACxB,UAAU,EAAE,IAAI;gBAChB,eAAe,EAAE,SAAS;gBAC1B,SAAS,EAAE,IAAA,2BAAU,EAAC,SAAS,EAAE,WAAW,CAAC;gBAC7C,OAAO;gBACP,gBAAgB,EAAE,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;gBAChG,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;gBAChG,KAAK,EAAE,IAAA,2BAAU,EAAC,SAAS,EAAE,OAAO,CAAC;gBACrC,eAAe;aAChB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,uCAAuC,SAAS,GAAG,EAAE,CAAC;SACvF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KAC3E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Tebra MCP tools: Charge retrieval.
3
+ */
4
+ import type { TebraConfig } from '../config.js';
5
+ export declare const chargeTools: {
6
+ name: string;
7
+ description: string;
8
+ inputSchema: {
9
+ type: "object";
10
+ properties: {
11
+ fromDate: {
12
+ type: string;
13
+ description: string;
14
+ };
15
+ toDate: {
16
+ type: string;
17
+ description: string;
18
+ };
19
+ patientId: {
20
+ type: string;
21
+ description: string;
22
+ };
23
+ };
24
+ required: never[];
25
+ };
26
+ }[];
27
+ export declare function handleChargeTool(name: string, args: Record<string, unknown>, config: TebraConfig): Promise<{
28
+ content: Array<{
29
+ type: string;
30
+ text: string;
31
+ }>;
32
+ }>;
33
+ //# sourceMappingURL=charges.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"charges.d.ts","sourceRoot":"","sources":["../../src/tools/charges.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKhD,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;GAwBvB,CAAC;AAIF,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CAiD7D"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /**
3
+ * Tebra MCP tools: Charge retrieval.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.chargeTools = void 0;
7
+ exports.handleChargeTool = handleChargeTool;
8
+ const soap_client_js_1 = require("../soap-client.js");
9
+ // ─── Tool Definitions ───────────────────────────────────────────
10
+ exports.chargeTools = [
11
+ {
12
+ name: 'tebra_get_charges',
13
+ description: 'Get charges from Tebra with optional date range and patient filters. Returns charge details with payment status, amounts, and balances.',
14
+ inputSchema: {
15
+ type: 'object',
16
+ properties: {
17
+ fromDate: {
18
+ type: 'string',
19
+ description: 'Start date filter (ISO 8601)',
20
+ },
21
+ toDate: {
22
+ type: 'string',
23
+ description: 'End date filter (ISO 8601)',
24
+ },
25
+ patientId: {
26
+ type: 'string',
27
+ description: 'Optional Tebra patient ID to filter by',
28
+ },
29
+ },
30
+ required: [],
31
+ },
32
+ },
33
+ ];
34
+ // ─── Tool Handler ───────────────────────────────────────────────
35
+ async function handleChargeTool(name, args, config) {
36
+ if (name !== 'tebra_get_charges') {
37
+ return { content: [{ type: 'text', text: `Unknown charge tool: ${name}` }] };
38
+ }
39
+ const fromDate = args.fromDate ? String(args.fromDate) : undefined;
40
+ const toDate = args.toDate ? String(args.toDate) : undefined;
41
+ const patientId = args.patientId ? String(args.patientId) : undefined;
42
+ const fieldsXml = [
43
+ fromDate ? `<kar:FromServiceDate>${(0, soap_client_js_1.escapeXml)(fromDate)}</kar:FromServiceDate>` : '',
44
+ toDate ? `<kar:ToServiceDate>${(0, soap_client_js_1.escapeXml)(toDate)}</kar:ToServiceDate>` : '',
45
+ patientId ? `<kar:PatientID>${(0, soap_client_js_1.escapeXml)(patientId)}</kar:PatientID>` : '',
46
+ ]
47
+ .filter(Boolean)
48
+ .join('\n ');
49
+ const bodyXml = `
50
+ <kar:request>
51
+ <kar:Fields>
52
+ ${fieldsXml}
53
+ </kar:Fields>
54
+ </kar:request>`;
55
+ const xml = await (0, soap_client_js_1.soapRequest)(config, 'GetCharges', bodyXml);
56
+ const blocks = (0, soap_client_js_1.extractAllTags)(xml, 'ChargeData');
57
+ const charges = blocks.map((block) => ({
58
+ chargeId: (0, soap_client_js_1.extractTag)(block, 'ChargeID') || (0, soap_client_js_1.extractTag)(block, 'ID'),
59
+ patientId: (0, soap_client_js_1.extractTag)(block, 'PatientID'),
60
+ patientName: (0, soap_client_js_1.extractTag)(block, 'PatientFullName'),
61
+ procedureCode: (0, soap_client_js_1.extractTag)(block, 'ProcedureCode'),
62
+ diagnosisCode: (0, soap_client_js_1.extractTag)(block, 'DiagnosisCode1'),
63
+ serviceDate: (0, soap_client_js_1.extractTag)(block, 'ServiceStartDate'),
64
+ amount: (0, soap_client_js_1.extractTag)(block, 'Amount'),
65
+ balance: (0, soap_client_js_1.extractTag)(block, 'Balance'),
66
+ paymentStatus: (0, soap_client_js_1.extractTag)(block, 'PaymentStatus') || (0, soap_client_js_1.extractTag)(block, 'Status'),
67
+ providerName: (0, soap_client_js_1.extractTag)(block, 'ProviderFullName'),
68
+ }));
69
+ if (charges.length === 0) {
70
+ return {
71
+ content: [{ type: 'text', text: 'No charges found matching the specified filters.' }],
72
+ };
73
+ }
74
+ return {
75
+ content: [{ type: 'text', text: JSON.stringify(charges, null, 2) }],
76
+ };
77
+ }
78
+ //# sourceMappingURL=charges.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"charges.js","sourceRoot":"","sources":["../../src/tools/charges.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAmCH,4CAqDC;AArFD,sDAAuF;AAEvF,mEAAmE;AAEtD,QAAA,WAAW,GAAG;IACzB;QACE,IAAI,EAAE,mBAAmB;QACzB,WAAW,EACT,yIAAyI;QAC3I,WAAW,EAAE;YACX,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,8BAA8B;iBAC5C;gBACD,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,4BAA4B;iBAC1C;gBACD,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,wCAAwC;iBACtD;aACF;YACD,QAAQ,EAAE,EAAE;SACb;KACF;CACF,CAAC;AAEF,mEAAmE;AAE5D,KAAK,UAAU,gBAAgB,CACpC,IAAY,EACZ,IAA6B,EAC7B,MAAmB;IAEnB,IAAI,IAAI,KAAK,mBAAmB,EAAE,CAAC;QACjC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,wBAAwB,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;IA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AE,IAAA,2BAAU,EAAC,KAAK,EAAE,WAAW,CAAC;QACzC,WAAW,EAAE,IAAA,2BAAU,EAAC,KAAK,EAAE,iBAAiB,CAAC;QACjD,aAAa,EAAE,IAAA,2BAAU,EAAC,KAAK,EAAE,eAAe,CAAC;QACjD,aAAa,EAAE,IAAA,2BAAU,EAAC,KAAK,EAAE,gBAAgB,CAAC;QAClD,WAAW,EAAE,IAAA,2BAAU,EAAC,KAAK,EAAE,kBAAkB,CAAC;QAClD,MAAM,EAAE,IAAA,2BAAU,EAAC,KAAK,EAAE,QAAQ,CAAC;QACnC,OAAO,EAAE,IAAA,2BAAU,EAAC,KAAK,EAAE,SAAS,CAAC;QACrC,aAAa,EAAE,IAAA,2BAAU,EAAC,KAAK,EAAE,eAAe,CAAC,IAAI,IAAA,2BAAU,EAAC,KAAK,EAAE,QAAQ,CAAC;QAChF,YAAY,EAAE,IAAA,2BAAU,EAAC,KAAK,EAAE,kBAAkB,CAAC;KACpD,CAAC,CAAC,CAAC;IAEJ,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,kDAAkD,EAAE,CAAC;SACtF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KACpE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Tebra MCP tools: Insurance eligibility checking.
3
+ *
4
+ * Note: Tebra SOAP API does not expose a direct real-time eligibility
5
+ * endpoint. This tool approximates eligibility by checking the patient's
6
+ * active insurance policies and authorization history.
7
+ */
8
+ import type { TebraConfig } from '../config.js';
9
+ export declare const eligibilityTools: {
10
+ name: string;
11
+ description: string;
12
+ inputSchema: {
13
+ type: "object";
14
+ properties: {
15
+ patientId: {
16
+ type: string;
17
+ description: string;
18
+ };
19
+ };
20
+ required: string[];
21
+ };
22
+ }[];
23
+ export declare function handleEligibilityTool(name: string, args: Record<string, unknown>, config: TebraConfig): Promise<{
24
+ content: Array<{
25
+ type: string;
26
+ text: string;
27
+ }>;
28
+ }>;
29
+ //# sourceMappingURL=eligibility.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eligibility.d.ts","sourceRoot":"","sources":["../../src/tools/eligibility.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAWhD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;GAgB5B,CAAC;AAIF,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CA+E7D"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ /**
3
+ * Tebra MCP tools: Insurance eligibility checking.
4
+ *
5
+ * Note: Tebra SOAP API does not expose a direct real-time eligibility
6
+ * endpoint. This tool approximates eligibility by checking the patient's
7
+ * active insurance policies and authorization history.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.eligibilityTools = void 0;
11
+ exports.handleEligibilityTool = handleEligibilityTool;
12
+ const soap_client_js_1 = require("../soap-client.js");
13
+ // ─── Tool Definitions ───────────────────────────────────────────
14
+ exports.eligibilityTools = [
15
+ {
16
+ name: 'tebra_check_insurance_eligibility',
17
+ description: 'Check insurance eligibility for a Tebra patient. Examines active insurance policies and authorization history. Note: this is an approximation based on on-file data, not a real-time payer eligibility check.',
18
+ inputSchema: {
19
+ type: 'object',
20
+ properties: {
21
+ patientId: {
22
+ type: 'string',
23
+ description: 'Tebra patient ID',
24
+ },
25
+ },
26
+ required: ['patientId'],
27
+ },
28
+ },
29
+ ];
30
+ // ─── Tool Handler ───────────────────────────────────────────────
31
+ async function handleEligibilityTool(name, args, config) {
32
+ if (name !== 'tebra_check_insurance_eligibility') {
33
+ return { content: [{ type: 'text', text: `Unknown eligibility tool: ${name}` }] };
34
+ }
35
+ const patientId = String(args.patientId ?? '');
36
+ if (!patientId) {
37
+ return { content: [{ type: 'text', text: 'patientId is required.' }] };
38
+ }
39
+ const bodyXml = `
40
+ <kar:request>
41
+ <kar:Fields>
42
+ <kar:PatientID>${(0, soap_client_js_1.escapeXml)(patientId)}</kar:PatientID>
43
+ </kar:Fields>
44
+ </kar:request>`;
45
+ const xml = await (0, soap_client_js_1.soapRequest)(config, 'GetPatient', bodyXml);
46
+ const patientBlock = (0, soap_client_js_1.extractTag)(xml, 'Patient');
47
+ if (!patientBlock) {
48
+ return {
49
+ content: [
50
+ {
51
+ type: 'text',
52
+ text: JSON.stringify({
53
+ eligible: false,
54
+ reason: 'Patient not found in Tebra',
55
+ authRequired: false,
56
+ }, null, 2),
57
+ },
58
+ ],
59
+ };
60
+ }
61
+ const insuranceBlocks = (0, soap_client_js_1.extractAllTags)(patientBlock, 'InsurancePolicyData');
62
+ const caseBlocks = (0, soap_client_js_1.extractAllTags)(patientBlock, 'CaseData');
63
+ // Find primary insurance
64
+ let primaryInsurance = null;
65
+ for (const ins of insuranceBlocks) {
66
+ const seq = (0, soap_client_js_1.extractNumber)(ins, 'SequenceNumber');
67
+ if (seq === 1 || insuranceBlocks.length === 1) {
68
+ primaryInsurance = {
69
+ payerName: (0, soap_client_js_1.extractTag)(ins, 'PayerName') || (0, soap_client_js_1.extractTag)(ins, 'CompanyName'),
70
+ memberId: (0, soap_client_js_1.extractTag)(ins, 'MemberNumber') || (0, soap_client_js_1.extractTag)(ins, 'PolicyNumber'),
71
+ };
72
+ break;
73
+ }
74
+ }
75
+ // Check if any authorizations exist (indicates auth-required payer)
76
+ let hasActiveAuths = false;
77
+ for (const caseBlock of caseBlocks) {
78
+ const authBlocks = (0, soap_client_js_1.extractAllTags)(caseBlock, 'AuthorizationData');
79
+ if (authBlocks.length > 0) {
80
+ hasActiveAuths = true;
81
+ break;
82
+ }
83
+ }
84
+ const result = {
85
+ eligible: !!primaryInsurance,
86
+ planName: primaryInsurance?.payerName ?? null,
87
+ memberId: primaryInsurance?.memberId ?? null,
88
+ authRequired: hasActiveAuths,
89
+ insurancePoliciesOnFile: insuranceBlocks.length,
90
+ note: primaryInsurance
91
+ ? 'Eligibility based on on-file insurance data. Verify with payer for real-time status.'
92
+ : 'No insurance policies on file. Patient may be self-pay.',
93
+ };
94
+ return {
95
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
96
+ };
97
+ }
98
+ //# sourceMappingURL=eligibility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eligibility.js","sourceRoot":"","sources":["../../src/tools/eligibility.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAiCH,sDAmFC;AAjHD,sDAM2B;AAE3B,mEAAmE;AAEtD,QAAA,gBAAgB,GAAG;IAC9B;QACE,IAAI,EAAE,mCAAmC;QACzC,WAAW,EACT,+MAA+M;QACjN,WAAW,EAAE;YACX,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,kBAAkB;iBAChC;aACF;YACD,QAAQ,EAAE,CAAC,WAAW,CAAC;SACxB;KACF;CACF,CAAC;AAEF,mEAAmE;AAE5D,KAAK,UAAU,qBAAqB,CACzC,IAAY,EACZ,IAA6B,EAC7B,MAAmB;IAEnB,IAAI,IAAI,KAAK,mCAAmC,EAAE,CAAC;QACjD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,6BAA6B,IAAI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,GAAG;gBACjB,SAAS,EAAE,IAAA,2BAAU,EAAC,GAAG,EAAE,WAAW,CAAC,IAAI,IAAA,2BAAU,EAAC,GAAG,EAAE,aAAa,CAAC;gBACzE,QAAQ,EAAE,IAAA,2BAAU,EAAC,GAAG,EAAE,cAAc,CAAC,IAAI,IAAA,2BAAU,EAAC,GAAG,EAAE,cAAc,CAAC;aAC7E,CAAC;YACF,MAAM;QACR,CAAC;IACH,CAAC;IAED,oEAAoE;IACpE,IAAI,cAAc,GAAG,KAAK,CAAC;IAC3B,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,MAAM,UAAU,GAAG,IAAA,+BAAc,EAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;QAClE,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,cAAc,GAAG,IAAI,CAAC;YACtB,MAAM;QACR,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG;QACb,QAAQ,EAAE,CAAC,CAAC,gBAAgB;QAC5B,QAAQ,EAAE,gBAAgB,EAAE,SAAS,IAAI,IAAI;QAC7C,QAAQ,EAAE,gBAAgB,EAAE,QAAQ,IAAI,IAAI;QAC5C,YAAY,EAAE,cAAc;QAC5B,uBAAuB,EAAE,eAAe,CAAC,MAAM;QAC/C,IAAI,EAAE,gBAAgB;YACpB,CAAC,CAAC,sFAAsF;YACxF,CAAC,CAAC,yDAAyD;KAC9D,CAAC;IAEF,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KACnE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Tebra MCP tools: Encounter creation and retrieval.
3
+ */
4
+ import type { TebraConfig } from '../config.js';
5
+ export declare const encounterTools: ({
6
+ name: string;
7
+ description: string;
8
+ inputSchema: {
9
+ type: "object";
10
+ properties: {
11
+ encounterId: {
12
+ type: string;
13
+ description: string;
14
+ };
15
+ patientId?: undefined;
16
+ providerId?: undefined;
17
+ serviceDate?: undefined;
18
+ diagnoses?: undefined;
19
+ procedures?: undefined;
20
+ authorizationId?: undefined;
21
+ };
22
+ required: string[];
23
+ };
24
+ } | {
25
+ name: string;
26
+ description: string;
27
+ inputSchema: {
28
+ type: "object";
29
+ properties: {
30
+ patientId: {
31
+ type: string;
32
+ description: string;
33
+ };
34
+ providerId: {
35
+ type: string;
36
+ description: string;
37
+ };
38
+ serviceDate: {
39
+ type: string;
40
+ description: string;
41
+ };
42
+ diagnoses: {
43
+ type: string;
44
+ items: {
45
+ type: string;
46
+ properties: {
47
+ code: {
48
+ type: string;
49
+ description: string;
50
+ };
51
+ description: {
52
+ type: string;
53
+ description: string;
54
+ };
55
+ };
56
+ required: string[];
57
+ };
58
+ description: string;
59
+ };
60
+ procedures: {
61
+ type: string;
62
+ items: {
63
+ type: string;
64
+ properties: {
65
+ code: {
66
+ type: string;
67
+ description: string;
68
+ };
69
+ modifiers: {
70
+ type: string;
71
+ items: {
72
+ type: string;
73
+ };
74
+ description: string;
75
+ };
76
+ units: {
77
+ type: string;
78
+ description: string;
79
+ };
80
+ };
81
+ required: string[];
82
+ };
83
+ description: string;
84
+ };
85
+ authorizationId: {
86
+ type: string;
87
+ description: string;
88
+ };
89
+ encounterId?: undefined;
90
+ };
91
+ required: string[];
92
+ };
93
+ })[];
94
+ export declare function handleEncounterTool(name: string, args: Record<string, unknown>, config: TebraConfig): Promise<{
95
+ content: Array<{
96
+ type: string;
97
+ text: string;
98
+ }>;
99
+ }>;
100
+ //# sourceMappingURL=encounters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encounters.d.ts","sourceRoot":"","sources":["../../src/tools/encounters.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKhD,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAwE1B,CAAC;AAeF,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CA8G7D"}
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ /**
3
+ * Tebra MCP tools: Encounter creation and retrieval.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.encounterTools = void 0;
7
+ exports.handleEncounterTool = handleEncounterTool;
8
+ const soap_client_js_1 = require("../soap-client.js");
9
+ // ─── Tool Definitions ───────────────────────────────────────────
10
+ exports.encounterTools = [
11
+ {
12
+ name: 'tebra_get_encounter',
13
+ description: 'Get encounter details from Tebra by encounter ID, including linked charges, diagnoses, and procedures.',
14
+ inputSchema: {
15
+ type: 'object',
16
+ properties: {
17
+ encounterId: {
18
+ type: 'string',
19
+ description: 'Tebra encounter ID',
20
+ },
21
+ },
22
+ required: ['encounterId'],
23
+ },
24
+ },
25
+ {
26
+ name: 'tebra_create_encounter',
27
+ description: 'Create a new encounter (superbill) in Tebra with diagnoses and procedures. Returns the created encounter ID.',
28
+ inputSchema: {
29
+ type: 'object',
30
+ properties: {
31
+ patientId: {
32
+ type: 'string',
33
+ description: 'Tebra patient ID',
34
+ },
35
+ providerId: {
36
+ type: 'string',
37
+ description: 'Tebra provider ID',
38
+ },
39
+ serviceDate: {
40
+ type: 'string',
41
+ description: 'Date of service (ISO 8601, e.g. 2026-03-25)',
42
+ },
43
+ diagnoses: {
44
+ type: 'array',
45
+ items: {
46
+ type: 'object',
47
+ properties: {
48
+ code: { type: 'string', description: 'ICD-10-CM code' },
49
+ description: { type: 'string', description: 'Diagnosis description' },
50
+ },
51
+ required: ['code', 'description'],
52
+ },
53
+ description: 'Array of diagnosis codes',
54
+ },
55
+ procedures: {
56
+ type: 'array',
57
+ items: {
58
+ type: 'object',
59
+ properties: {
60
+ code: { type: 'string', description: 'CPT code' },
61
+ modifiers: {
62
+ type: 'array',
63
+ items: { type: 'string' },
64
+ description: 'CPT modifiers (e.g. ["-25", "-59"])',
65
+ },
66
+ units: { type: 'number', description: 'Number of units (default 1)' },
67
+ },
68
+ required: ['code'],
69
+ },
70
+ description: 'Array of procedure codes',
71
+ },
72
+ authorizationId: {
73
+ type: 'string',
74
+ description: 'Optional authorization ID to link',
75
+ },
76
+ },
77
+ required: ['patientId', 'providerId', 'serviceDate', 'diagnoses', 'procedures'],
78
+ },
79
+ },
80
+ ];
81
+ async function handleEncounterTool(name, args, config) {
82
+ switch (name) {
83
+ case 'tebra_get_encounter': {
84
+ const encounterId = String(args.encounterId ?? '');
85
+ if (!encounterId) {
86
+ return { content: [{ type: 'text', text: 'encounterId is required.' }] };
87
+ }
88
+ const bodyXml = `
89
+ <kar:request>
90
+ <kar:Fields>
91
+ <kar:EncounterID>${(0, soap_client_js_1.escapeXml)(encounterId)}</kar:EncounterID>
92
+ </kar:Fields>
93
+ </kar:request>`;
94
+ const xml = await (0, soap_client_js_1.soapRequest)(config, 'GetEncounterDetails', bodyXml);
95
+ return { content: [{ type: 'text', text: formatEncounterXml(xml) }] };
96
+ }
97
+ case 'tebra_create_encounter': {
98
+ const patientId = String(args.patientId ?? '');
99
+ const providerId = String(args.providerId ?? '');
100
+ const serviceDate = String(args.serviceDate ?? '');
101
+ const diagnoses = (args.diagnoses ?? []);
102
+ const procedures = (args.procedures ?? []);
103
+ if (!patientId || !providerId || !serviceDate) {
104
+ return {
105
+ content: [{ type: 'text', text: 'patientId, providerId, and serviceDate are required.' }],
106
+ };
107
+ }
108
+ if (diagnoses.length === 0 || procedures.length === 0) {
109
+ return {
110
+ content: [{ type: 'text', text: 'At least one diagnosis and one procedure are required.' }],
111
+ };
112
+ }
113
+ const diagnosisXml = diagnoses
114
+ .map((dx, i) => `
115
+ <kar:EncounterDiagnosisReq>
116
+ <kar:DiagnosisCode>${(0, soap_client_js_1.escapeXml)(dx.code)}</kar:DiagnosisCode>
117
+ <kar:Description>${(0, soap_client_js_1.escapeXml)(dx.description)}</kar:Description>
118
+ <kar:Sequence>${i + 1}</kar:Sequence>
119
+ </kar:EncounterDiagnosisReq>`)
120
+ .join('');
121
+ const procedureXml = procedures
122
+ .map((px) => `
123
+ <kar:EncounterProcedureReq>
124
+ <kar:ProcedureCode>${(0, soap_client_js_1.escapeXml)(px.code)}</kar:ProcedureCode>
125
+ ${px.modifiers?.[0] ? `<kar:Modifier1>${(0, soap_client_js_1.escapeXml)(px.modifiers[0])}</kar:Modifier1>` : ''}
126
+ ${px.modifiers?.[1] ? `<kar:Modifier2>${(0, soap_client_js_1.escapeXml)(px.modifiers[1])}</kar:Modifier2>` : ''}
127
+ ${px.modifiers?.[2] ? `<kar:Modifier3>${(0, soap_client_js_1.escapeXml)(px.modifiers[2])}</kar:Modifier3>` : ''}
128
+ ${px.modifiers?.[3] ? `<kar:Modifier4>${(0, soap_client_js_1.escapeXml)(px.modifiers[3])}</kar:Modifier4>` : ''}
129
+ <kar:Units>${px.units ?? 1}</kar:Units>
130
+ </kar:EncounterProcedureReq>`)
131
+ .join('');
132
+ const authNumber = args.authorizationId ? String(args.authorizationId) : '';
133
+ const bodyXml = `
134
+ <kar:request>
135
+ <kar:Encounter>
136
+ <kar:PatientID>${(0, soap_client_js_1.escapeXml)(patientId)}</kar:PatientID>
137
+ <kar:ProviderID>${(0, soap_client_js_1.escapeXml)(providerId)}</kar:ProviderID>
138
+ <kar:ServiceStartDate>${(0, soap_client_js_1.escapeXml)(serviceDate)}</kar:ServiceStartDate>
139
+ <kar:ServiceEndDate>${(0, soap_client_js_1.escapeXml)(serviceDate)}</kar:ServiceEndDate>
140
+ ${authNumber ? `<kar:AuthorizationNumber>${(0, soap_client_js_1.escapeXml)(authNumber)}</kar:AuthorizationNumber>` : ''}
141
+ <kar:EncounterDiagnoses>${diagnosisXml}</kar:EncounterDiagnoses>
142
+ <kar:EncounterProcedures>${procedureXml}</kar:EncounterProcedures>
143
+ </kar:Encounter>
144
+ </kar:request>`;
145
+ const xml = await (0, soap_client_js_1.soapRequest)(config, 'CreateEncounter', bodyXml);
146
+ const encounterId = (0, soap_client_js_1.extractTag)(xml, 'EncounterID') || (0, soap_client_js_1.extractTag)(xml, 'ID');
147
+ const status = (0, soap_client_js_1.extractTag)(xml, 'Status') || 'created';
148
+ const errorMsg = (0, soap_client_js_1.extractTag)(xml, 'ErrorMessage');
149
+ if (errorMsg) {
150
+ return {
151
+ content: [{ type: 'text', text: `Encounter creation error: ${errorMsg}` }],
152
+ };
153
+ }
154
+ return {
155
+ content: [
156
+ {
157
+ type: 'text',
158
+ text: JSON.stringify({
159
+ encounterId,
160
+ status,
161
+ message: `Encounter created successfully with ${diagnoses.length} diagnoses and ${procedures.length} procedures.`,
162
+ }, null, 2),
163
+ },
164
+ ],
165
+ };
166
+ }
167
+ default:
168
+ return { content: [{ type: 'text', text: `Unknown encounter tool: ${name}` }] };
169
+ }
170
+ }
171
+ // ─── Helpers ────────────────────────────────────────────────────
172
+ function formatEncounterXml(xml) {
173
+ // Extract key encounter fields for a readable response
174
+ const encounterId = (0, soap_client_js_1.extractTag)(xml, 'EncounterID');
175
+ const patientName = (0, soap_client_js_1.extractTag)(xml, 'PatientFullName');
176
+ const serviceDate = (0, soap_client_js_1.extractTag)(xml, 'ServiceStartDate');
177
+ const status = (0, soap_client_js_1.extractTag)(xml, 'Status');
178
+ return JSON.stringify({
179
+ encounterId,
180
+ patientName,
181
+ serviceDate,
182
+ status,
183
+ rawDataAvailable: true,
184
+ }, null, 2);
185
+ }
186
+ //# sourceMappingURL=encounters.js.map