@sequoiaport/codes 0.1.0-beta.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/dist/index.js ADDED
@@ -0,0 +1,495 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ CodesApiError: () => CodesApiError,
24
+ CptCategory: () => CptCategory,
25
+ HcpcsCategory: () => HcpcsCategory,
26
+ Icd10Category: () => Icd10Category,
27
+ LcdCategory: () => LcdCategory,
28
+ LoincCategory: () => LoincCategory,
29
+ NcdCategory: () => NcdCategory,
30
+ RxnormCategory: () => RxnormCategory,
31
+ SequoiaCodesClient: () => SequoiaCodesClient,
32
+ SnomedCategory: () => SnomedCategory
33
+ });
34
+ module.exports = __toCommonJS(index_exports);
35
+
36
+ // src/errors.ts
37
+ var CodesApiError = class extends Error {
38
+ constructor(status, message, action) {
39
+ super(message);
40
+ this.status = status;
41
+ this.action = action;
42
+ this.name = "CodesApiError";
43
+ }
44
+ toJSON() {
45
+ return {
46
+ name: this.name,
47
+ status: this.status,
48
+ message: this.message,
49
+ action: this.action
50
+ };
51
+ }
52
+ };
53
+
54
+ // src/engines.ts
55
+ var import_zod = require("zod");
56
+ var SnomedSearchCodeInputSchema = import_zod.z.object({
57
+ query: import_zod.z.string().min(1),
58
+ limit: import_zod.z.number().int().min(1).max(200).optional()
59
+ });
60
+ var SnomedIdentifyCodeInputSchema = import_zod.z.object({
61
+ code: import_zod.z.string().min(1)
62
+ });
63
+ var SnomedCategory = class {
64
+ constructor(request) {
65
+ this.request = request;
66
+ }
67
+ async searchCode(input) {
68
+ const validated = SnomedSearchCodeInputSchema.parse(input);
69
+ return this.request(
70
+ "snomed/searchCode",
71
+ validated
72
+ );
73
+ }
74
+ async identifyCode(input) {
75
+ const validated = SnomedIdentifyCodeInputSchema.parse(input);
76
+ return this.request("snomed/identifyCode", {
77
+ code: validated.code
78
+ });
79
+ }
80
+ };
81
+ var Icd10SearchCodeInputSchema = import_zod.z.object({
82
+ query: import_zod.z.string().min(1),
83
+ limit: import_zod.z.number().int().min(1).max(200).optional(),
84
+ billingOnly: import_zod.z.boolean().optional()
85
+ });
86
+ var Icd10IdentifyCodeInputSchema = import_zod.z.object({
87
+ code: import_zod.z.string().min(1)
88
+ });
89
+ var Icd10Category = class {
90
+ constructor(request) {
91
+ this.request = request;
92
+ }
93
+ async searchCode(input) {
94
+ const validated = Icd10SearchCodeInputSchema.parse(input);
95
+ return this.request("icd10/searchCode", validated);
96
+ }
97
+ async identifyCode(input) {
98
+ const validated = Icd10IdentifyCodeInputSchema.parse(input);
99
+ return this.request("icd10/identifyCode", {
100
+ code: validated.code
101
+ });
102
+ }
103
+ async getChapters() {
104
+ return this.request("icd10/getChapters", {});
105
+ }
106
+ };
107
+ var CptSearchCodeInputSchema = import_zod.z.object({
108
+ query: import_zod.z.string().min(1),
109
+ limit: import_zod.z.number().int().min(1).max(200).optional()
110
+ });
111
+ var CptIdentifyCodeInputSchema = import_zod.z.object({
112
+ code: import_zod.z.string().min(1)
113
+ });
114
+ var CptGetCostInputSchema = import_zod.z.object({
115
+ code: import_zod.z.string().min(1)
116
+ });
117
+ var CptLinkIcd10InputSchema = import_zod.z.object({
118
+ code: import_zod.z.string().min(1)
119
+ });
120
+ var CptCategory = class {
121
+ constructor(request) {
122
+ this.request = request;
123
+ }
124
+ async searchCode(input) {
125
+ const validated = CptSearchCodeInputSchema.parse(input);
126
+ return this.request("cpt/searchCode", validated);
127
+ }
128
+ async identifyCode(input) {
129
+ const validated = CptIdentifyCodeInputSchema.parse(input);
130
+ return this.request("cpt/identifyCode", {
131
+ code: validated.code
132
+ });
133
+ }
134
+ async getCost(input) {
135
+ const validated = CptGetCostInputSchema.parse(input);
136
+ return this.request("cpt/getCost", {
137
+ code: validated.code
138
+ });
139
+ }
140
+ async linkIcd10(input) {
141
+ const validated = CptLinkIcd10InputSchema.parse(input);
142
+ return this.request("cpt/linkIcd10", {
143
+ code: validated.code
144
+ });
145
+ }
146
+ };
147
+ var HcpcsSearchCodeInputSchema = import_zod.z.object({
148
+ query: import_zod.z.string().min(1),
149
+ limit: import_zod.z.number().int().min(1).max(200).optional()
150
+ });
151
+ var HcpcsIdentifyCodeInputSchema = import_zod.z.object({
152
+ code: import_zod.z.string().min(1)
153
+ });
154
+ var HcpcsGetCostInputSchema = import_zod.z.object({
155
+ code: import_zod.z.string().min(1)
156
+ });
157
+ var HcpcsCategory = class {
158
+ constructor(request) {
159
+ this.request = request;
160
+ }
161
+ async searchCode(input) {
162
+ const validated = HcpcsSearchCodeInputSchema.parse(input);
163
+ return this.request("hcpcs/searchCode", validated);
164
+ }
165
+ async identifyCode(input) {
166
+ const validated = HcpcsIdentifyCodeInputSchema.parse(input);
167
+ return this.request("hcpcs/identifyCode", {
168
+ code: validated.code
169
+ });
170
+ }
171
+ async getCost(input) {
172
+ const validated = HcpcsGetCostInputSchema.parse(input);
173
+ return this.request("hcpcs/getCost", {
174
+ code: validated.code
175
+ });
176
+ }
177
+ };
178
+ var LoincSearchCodeInputSchema = import_zod.z.object({
179
+ query: import_zod.z.string().min(1),
180
+ limit: import_zod.z.number().int().min(1).max(200).optional()
181
+ });
182
+ var LoincIdentifyCodeInputSchema = import_zod.z.object({
183
+ code: import_zod.z.string().min(1)
184
+ });
185
+ var LoincGetPanelMembersInputSchema = import_zod.z.object({
186
+ code: import_zod.z.string().min(1)
187
+ });
188
+ var LoincCategory = class {
189
+ constructor(request) {
190
+ this.request = request;
191
+ }
192
+ async searchCode(input) {
193
+ const validated = LoincSearchCodeInputSchema.parse(input);
194
+ return this.request(
195
+ "loinc/searchCode",
196
+ validated
197
+ );
198
+ }
199
+ async identifyCode(input) {
200
+ const validated = LoincIdentifyCodeInputSchema.parse(input);
201
+ return this.request("loinc/identifyCode", {
202
+ code: validated.code
203
+ });
204
+ }
205
+ async getPanelMembers(input) {
206
+ const validated = LoincGetPanelMembersInputSchema.parse(input);
207
+ return this.request(
208
+ "loinc/getPanelMembers",
209
+ { code: validated.code }
210
+ );
211
+ }
212
+ };
213
+ var RxnormSearchCodeInputSchema = import_zod.z.object({
214
+ query: import_zod.z.string().min(1),
215
+ limit: import_zod.z.number().int().min(1).max(200).optional()
216
+ });
217
+ var RxnormIdentifyCodeInputSchema = import_zod.z.object({
218
+ type: import_zod.z.enum(["ndc", "rxcui"]),
219
+ code: import_zod.z.string().min(1)
220
+ });
221
+ var RxnormGetIngredientsInputSchema = import_zod.z.object({
222
+ rxcui: import_zod.z.string().min(1)
223
+ });
224
+ var RxnormCategory = class {
225
+ constructor(request) {
226
+ this.request = request;
227
+ }
228
+ async searchCode(input) {
229
+ const validated = RxnormSearchCodeInputSchema.parse(input);
230
+ return this.request("rxnorm/searchCode", validated);
231
+ }
232
+ async identifyCode(input) {
233
+ const validated = RxnormIdentifyCodeInputSchema.parse(input);
234
+ return this.request(
235
+ "rxnorm/identifyCode",
236
+ { type: validated.type, code: validated.code }
237
+ );
238
+ }
239
+ async getIngredients(input) {
240
+ const validated = RxnormGetIngredientsInputSchema.parse(input);
241
+ return this.request(
242
+ "rxnorm/getIngredients",
243
+ validated
244
+ );
245
+ }
246
+ };
247
+ var LcdSearchGuidelinesInputSchema = import_zod.z.object({
248
+ query: import_zod.z.string().min(1),
249
+ limit: import_zod.z.number().int().min(1).max(200).optional()
250
+ });
251
+ var LcdIdentifyGuidelineInputSchema = import_zod.z.object({
252
+ id: import_zod.z.string().min(1)
253
+ });
254
+ var LcdCategory = class {
255
+ constructor(request) {
256
+ this.request = request;
257
+ }
258
+ async searchGuidelines(input) {
259
+ const validated = LcdSearchGuidelinesInputSchema.parse(input);
260
+ return this.request(
261
+ "lcd/searchGuidelines",
262
+ validated
263
+ );
264
+ }
265
+ async identifyGuideline(input) {
266
+ const validated = LcdIdentifyGuidelineInputSchema.parse(input);
267
+ return this.request("lcd/identifyGuideline", {
268
+ id: validated.id
269
+ });
270
+ }
271
+ };
272
+ var NcdSearchGuidelinesInputSchema = import_zod.z.object({
273
+ query: import_zod.z.string().min(1),
274
+ limit: import_zod.z.number().int().min(1).max(200).optional()
275
+ });
276
+ var NcdIdentifyGuidelineInputSchema = import_zod.z.object({
277
+ id: import_zod.z.string().optional(),
278
+ section: import_zod.z.string().optional()
279
+ }).refine((data) => data.id || data.section, {
280
+ message: "Either id or section must be provided"
281
+ });
282
+ var NcdCategory = class {
283
+ constructor(request) {
284
+ this.request = request;
285
+ }
286
+ async searchGuidelines(input) {
287
+ const validated = NcdSearchGuidelinesInputSchema.parse(input);
288
+ return this.request(
289
+ "ncd/searchGuidelines",
290
+ validated
291
+ );
292
+ }
293
+ async identifyGuideline(input) {
294
+ const validated = NcdIdentifyGuidelineInputSchema.parse(input);
295
+ return this.request("ncd/identifyGuideline", {
296
+ id: validated.id,
297
+ section: validated.section
298
+ });
299
+ }
300
+ };
301
+
302
+ // src/schemas/clinical.ts
303
+ var import_zod2 = require("zod");
304
+ var DiagnosisToProceduresInputSchema = import_zod2.z.object({
305
+ snomed_id: import_zod2.z.string().optional(),
306
+ icd10_code: import_zod2.z.string().optional(),
307
+ query: import_zod2.z.string().optional()
308
+ });
309
+ var CoverageCheckInputSchema = import_zod2.z.object({
310
+ cpt_code: import_zod2.z.string().min(1),
311
+ icd10_code: import_zod2.z.string().optional()
312
+ });
313
+ var DiagnosisToProceduresOutputSchema = import_zod2.z.object({
314
+ snomed_id: import_zod2.z.string().optional(),
315
+ icd10_code: import_zod2.z.string().optional(),
316
+ icd10_mappings: import_zod2.z.array(import_zod2.z.record(import_zod2.z.unknown())).optional(),
317
+ procedures: import_zod2.z.array(import_zod2.z.record(import_zod2.z.unknown())).optional()
318
+ });
319
+ var CoverageCheckOutputSchema = import_zod2.z.object({
320
+ cpt_code: import_zod2.z.string(),
321
+ icd10_code: import_zod2.z.string().optional(),
322
+ lcd: import_zod2.z.record(import_zod2.z.unknown()).optional(),
323
+ has_guidelines: import_zod2.z.boolean(),
324
+ diagnosis_covered: import_zod2.z.boolean().optional()
325
+ });
326
+ var GetCategoriesOutputSchema = import_zod2.z.object({
327
+ snomed_semantic_tags: import_zod2.z.record(import_zod2.z.unknown()).optional(),
328
+ icd10_chapters: import_zod2.z.array(import_zod2.z.record(import_zod2.z.unknown())).optional(),
329
+ cpt_categories: import_zod2.z.array(import_zod2.z.record(import_zod2.z.unknown())).optional()
330
+ });
331
+
332
+ // src/schemas/system.ts
333
+ var import_zod3 = require("zod");
334
+ var GetResultInputSchema = import_zod3.z.object({
335
+ request_id: import_zod3.z.string().min(1)
336
+ });
337
+ var GetResultOutputSchema = import_zod3.z.object({
338
+ request_id: import_zod3.z.string(),
339
+ status: import_zod3.z.enum(["pending", "running", "completed", "failed"]),
340
+ query: import_zod3.z.string().optional(),
341
+ result: import_zod3.z.record(import_zod3.z.unknown()).optional(),
342
+ error: import_zod3.z.string().optional()
343
+ });
344
+ var EngineStatusSchema = import_zod3.z.record(import_zod3.z.enum(["ok", "error", "unknown"]));
345
+ var HealthOutputSchema = import_zod3.z.object({
346
+ status: import_zod3.z.enum(["ok", "degraded"]),
347
+ version: import_zod3.z.string().optional(),
348
+ environment: import_zod3.z.string().optional(),
349
+ engines: EngineStatusSchema.optional()
350
+ });
351
+
352
+ // src/client.ts
353
+ var ClinicalCategory = class {
354
+ constructor(request) {
355
+ this.request = request;
356
+ }
357
+ /** Check LCD coverage for a CPT code + optional ICD-10 pair */
358
+ async checkCoverage(input) {
359
+ const validated = CoverageCheckInputSchema.parse(input);
360
+ return this.request(
361
+ "clinical/checkCoverage",
362
+ validated
363
+ );
364
+ }
365
+ /** Map a diagnosis (SNOMED or ICD-10) to relevant procedures */
366
+ async getProceduresForDiagnosis(input) {
367
+ const validated = DiagnosisToProceduresInputSchema.parse(input);
368
+ return this.request(
369
+ "clinical/getProceduresForDiagnosis",
370
+ validated
371
+ );
372
+ }
373
+ /** Get metadata/categories from all engines (semantic tags, chapters, etc.) */
374
+ async getMetadata() {
375
+ return this.request("clinical/getMetadata", {});
376
+ }
377
+ };
378
+ var SystemCategory = class {
379
+ constructor(request) {
380
+ this.request = request;
381
+ }
382
+ /** Get async request result by ID */
383
+ async getResult(input) {
384
+ const validated = GetResultInputSchema.parse(input);
385
+ return this.request("system/getResult", validated);
386
+ }
387
+ /** Health check all engines */
388
+ async health() {
389
+ return this.request("system/health", {});
390
+ }
391
+ };
392
+ var DEFAULT_BASE_URL = "https://api.sequoiacodes.com";
393
+ var DEFAULT_VERSION = "v1";
394
+ var SequoiaCodesClient = class {
395
+ apiKey;
396
+ baseUrl;
397
+ version;
398
+ // ==========================================================================
399
+ // Orchestrator Categories
400
+ // ==========================================================================
401
+ /** Clinical orchestrator: coverage check, diagnosis-to-procedures, metadata */
402
+ clinical;
403
+ /** System actions: get async result, health check */
404
+ system;
405
+ // ==========================================================================
406
+ // Coding System Categories
407
+ // ==========================================================================
408
+ /** SNOMED CT coding system */
409
+ snomed;
410
+ /** ICD-10 diagnosis codes */
411
+ icd10;
412
+ /** CPT procedure codes */
413
+ cpt;
414
+ /** HCPCS procedure codes */
415
+ hcpcs;
416
+ /** LOINC laboratory test codes */
417
+ loinc;
418
+ /** RxNorm drug/medication codes */
419
+ rxnorm;
420
+ // ==========================================================================
421
+ // Guideline Categories
422
+ // ==========================================================================
423
+ /** LCD (Local Coverage Determination) guidelines */
424
+ lcd;
425
+ /** NCD (National Coverage Determination) guidelines */
426
+ ncd;
427
+ constructor(config) {
428
+ this.apiKey = config.apiKey;
429
+ this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
430
+ this.version = config.version ?? DEFAULT_VERSION;
431
+ const boundRequest = this.request.bind(this);
432
+ this.clinical = new ClinicalCategory(boundRequest);
433
+ this.system = new SystemCategory(boundRequest);
434
+ this.snomed = new SnomedCategory(boundRequest);
435
+ this.icd10 = new Icd10Category(boundRequest);
436
+ this.cpt = new CptCategory(boundRequest);
437
+ this.hcpcs = new HcpcsCategory(boundRequest);
438
+ this.loinc = new LoincCategory(boundRequest);
439
+ this.rxnorm = new RxnormCategory(boundRequest);
440
+ this.lcd = new LcdCategory(boundRequest);
441
+ this.ncd = new NcdCategory(boundRequest);
442
+ }
443
+ /**
444
+ * Make an HTTP request to the Codes API Gateway.
445
+ */
446
+ async request(path, params, method = "GET") {
447
+ const url = new URL(`${this.baseUrl}/${this.version}/${path}`);
448
+ const headers = {
449
+ Authorization: `Bearer ${this.apiKey}`,
450
+ "Content-Type": "application/json"
451
+ };
452
+ const options = {
453
+ method,
454
+ headers
455
+ };
456
+ if (method === "GET" && params) {
457
+ for (const [key, value] of Object.entries(params)) {
458
+ if (value !== void 0 && value !== null) {
459
+ if (Array.isArray(value)) {
460
+ url.searchParams.set(key, JSON.stringify(value));
461
+ } else if (typeof value === "object") {
462
+ url.searchParams.set(key, JSON.stringify(value));
463
+ } else {
464
+ url.searchParams.set(key, String(value));
465
+ }
466
+ }
467
+ }
468
+ } else if (method === "POST" && params) {
469
+ options.body = JSON.stringify(params);
470
+ }
471
+ const response = await fetch(url.toString(), options);
472
+ const data = await response.json();
473
+ if (!response.ok || !data.success) {
474
+ throw new CodesApiError(
475
+ response.status,
476
+ data.error || "Unknown error",
477
+ path
478
+ );
479
+ }
480
+ return data.data;
481
+ }
482
+ };
483
+ // Annotate the CommonJS export names for ESM import in node:
484
+ 0 && (module.exports = {
485
+ CodesApiError,
486
+ CptCategory,
487
+ HcpcsCategory,
488
+ Icd10Category,
489
+ LcdCategory,
490
+ LoincCategory,
491
+ NcdCategory,
492
+ RxnormCategory,
493
+ SequoiaCodesClient,
494
+ SnomedCategory
495
+ });