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