@fhirfly-io/terminology 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/LICENSE +21 -0
- package/README.md +213 -0
- package/dist/index.cjs +718 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +991 -0
- package/dist/index.d.ts +991 -0
- package/dist/index.js +706 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var FhirflyError = class _FhirflyError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "FhirflyError";
|
|
6
|
+
Object.setPrototypeOf(this, _FhirflyError.prototype);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
var ApiError = class _ApiError extends FhirflyError {
|
|
10
|
+
statusCode;
|
|
11
|
+
code;
|
|
12
|
+
details;
|
|
13
|
+
constructor(message, statusCode, code, details) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "ApiError";
|
|
16
|
+
this.statusCode = statusCode;
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.details = details;
|
|
19
|
+
Object.setPrototypeOf(this, _ApiError.prototype);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var AuthenticationError = class _AuthenticationError extends ApiError {
|
|
23
|
+
constructor(message = "Authentication failed. Check your API key.") {
|
|
24
|
+
super(message, 401, "AUTHENTICATION_ERROR");
|
|
25
|
+
this.name = "AuthenticationError";
|
|
26
|
+
Object.setPrototypeOf(this, _AuthenticationError.prototype);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var NotFoundError = class _NotFoundError extends ApiError {
|
|
30
|
+
code_type;
|
|
31
|
+
code_value;
|
|
32
|
+
constructor(codeType, codeValue) {
|
|
33
|
+
super(`${codeType} not found: ${codeValue}`, 404, "NOT_FOUND");
|
|
34
|
+
this.name = "NotFoundError";
|
|
35
|
+
this.code_type = codeType;
|
|
36
|
+
this.code_value = codeValue;
|
|
37
|
+
Object.setPrototypeOf(this, _NotFoundError.prototype);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var ValidationError = class _ValidationError extends ApiError {
|
|
41
|
+
field;
|
|
42
|
+
constructor(message, field) {
|
|
43
|
+
super(message, 400, "VALIDATION_ERROR");
|
|
44
|
+
this.name = "ValidationError";
|
|
45
|
+
this.field = field;
|
|
46
|
+
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var RateLimitError = class _RateLimitError extends ApiError {
|
|
50
|
+
retryAfter;
|
|
51
|
+
limit;
|
|
52
|
+
remaining;
|
|
53
|
+
reset;
|
|
54
|
+
constructor(message = "Rate limit exceeded", retryAfter, limit, remaining, reset) {
|
|
55
|
+
super(message, 429, "RATE_LIMIT_EXCEEDED");
|
|
56
|
+
this.name = "RateLimitError";
|
|
57
|
+
this.retryAfter = retryAfter;
|
|
58
|
+
this.limit = limit;
|
|
59
|
+
this.remaining = remaining;
|
|
60
|
+
this.reset = reset;
|
|
61
|
+
Object.setPrototypeOf(this, _RateLimitError.prototype);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var QuotaExceededError = class _QuotaExceededError extends ApiError {
|
|
65
|
+
quotaLimit;
|
|
66
|
+
quotaUsed;
|
|
67
|
+
quotaResetDate;
|
|
68
|
+
constructor(message = "Monthly quota exceeded", quotaLimit, quotaUsed, quotaResetDate) {
|
|
69
|
+
super(message, 429, "QUOTA_EXCEEDED");
|
|
70
|
+
this.name = "QuotaExceededError";
|
|
71
|
+
this.quotaLimit = quotaLimit;
|
|
72
|
+
this.quotaUsed = quotaUsed;
|
|
73
|
+
this.quotaResetDate = quotaResetDate;
|
|
74
|
+
Object.setPrototypeOf(this, _QuotaExceededError.prototype);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var ServerError = class _ServerError extends ApiError {
|
|
78
|
+
constructor(message = "Server error", statusCode = 500) {
|
|
79
|
+
super(message, statusCode, "SERVER_ERROR");
|
|
80
|
+
this.name = "ServerError";
|
|
81
|
+
Object.setPrototypeOf(this, _ServerError.prototype);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var NetworkError = class _NetworkError extends FhirflyError {
|
|
85
|
+
cause;
|
|
86
|
+
constructor(message = "Network error", cause) {
|
|
87
|
+
super(message);
|
|
88
|
+
this.name = "NetworkError";
|
|
89
|
+
this.cause = cause;
|
|
90
|
+
Object.setPrototypeOf(this, _NetworkError.prototype);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var TimeoutError = class _TimeoutError extends FhirflyError {
|
|
94
|
+
timeoutMs;
|
|
95
|
+
constructor(timeoutMs) {
|
|
96
|
+
super(`Request timed out after ${timeoutMs}ms`);
|
|
97
|
+
this.name = "TimeoutError";
|
|
98
|
+
this.timeoutMs = timeoutMs;
|
|
99
|
+
Object.setPrototypeOf(this, _TimeoutError.prototype);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/http.ts
|
|
104
|
+
var HttpClient = class {
|
|
105
|
+
config;
|
|
106
|
+
constructor(config) {
|
|
107
|
+
this.config = {
|
|
108
|
+
baseUrl: config.baseUrl,
|
|
109
|
+
apiKey: config.apiKey,
|
|
110
|
+
timeout: config.timeout ?? 3e4,
|
|
111
|
+
maxRetries: config.maxRetries ?? 3,
|
|
112
|
+
retryDelay: config.retryDelay ?? 1e3,
|
|
113
|
+
userAgent: config.userAgent ?? `@fhirfly/sdk/0.1.0 Node.js/${process.version}`
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Build query string from options.
|
|
118
|
+
*/
|
|
119
|
+
buildQueryString(options) {
|
|
120
|
+
if (!options) return "";
|
|
121
|
+
const params = new URLSearchParams();
|
|
122
|
+
if (options.shape) {
|
|
123
|
+
params.set("shape", options.shape);
|
|
124
|
+
}
|
|
125
|
+
if (options.include?.length) {
|
|
126
|
+
params.set("include", options.include.join(","));
|
|
127
|
+
}
|
|
128
|
+
const queryString = params.toString();
|
|
129
|
+
return queryString ? `?${queryString}` : "";
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Parse error response from API.
|
|
133
|
+
*/
|
|
134
|
+
async parseErrorResponse(response, endpoint) {
|
|
135
|
+
const status = response.status;
|
|
136
|
+
let body = {};
|
|
137
|
+
try {
|
|
138
|
+
body = await response.json();
|
|
139
|
+
} catch {
|
|
140
|
+
}
|
|
141
|
+
const message = body.message || body.error || response.statusText;
|
|
142
|
+
switch (status) {
|
|
143
|
+
case 401:
|
|
144
|
+
throw new AuthenticationError(message);
|
|
145
|
+
case 404: {
|
|
146
|
+
const match = endpoint.match(/\/v1\/(\w+)\/(.+)/);
|
|
147
|
+
if (match) {
|
|
148
|
+
throw new NotFoundError(match[1].toUpperCase(), match[2]);
|
|
149
|
+
}
|
|
150
|
+
throw new NotFoundError("Resource", endpoint);
|
|
151
|
+
}
|
|
152
|
+
case 400:
|
|
153
|
+
throw new ValidationError(message);
|
|
154
|
+
case 429: {
|
|
155
|
+
const retryAfter = response.headers.get("retry-after");
|
|
156
|
+
const limit = response.headers.get("x-ratelimit-limit");
|
|
157
|
+
const remaining = response.headers.get("x-ratelimit-remaining");
|
|
158
|
+
const reset = response.headers.get("x-ratelimit-reset");
|
|
159
|
+
if (body.code === "QUOTA_EXCEEDED") {
|
|
160
|
+
throw new QuotaExceededError(message);
|
|
161
|
+
}
|
|
162
|
+
throw new RateLimitError(
|
|
163
|
+
message,
|
|
164
|
+
retryAfter ? parseInt(retryAfter, 10) : void 0,
|
|
165
|
+
limit ? parseInt(limit, 10) : void 0,
|
|
166
|
+
remaining ? parseInt(remaining, 10) : void 0,
|
|
167
|
+
reset ? new Date(parseInt(reset, 10) * 1e3) : void 0
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
default:
|
|
171
|
+
if (status >= 500) {
|
|
172
|
+
throw new ServerError(message, status);
|
|
173
|
+
}
|
|
174
|
+
throw new ApiError(message, status, body.code, body.details);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Sleep for a given number of milliseconds.
|
|
179
|
+
*/
|
|
180
|
+
sleep(ms) {
|
|
181
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Make an HTTP request with retries.
|
|
185
|
+
*/
|
|
186
|
+
async request(method, endpoint, body) {
|
|
187
|
+
const url = `${this.config.baseUrl}${endpoint}`;
|
|
188
|
+
let lastError;
|
|
189
|
+
for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {
|
|
190
|
+
try {
|
|
191
|
+
const controller = new AbortController();
|
|
192
|
+
const timeoutId = setTimeout(
|
|
193
|
+
() => controller.abort(),
|
|
194
|
+
this.config.timeout
|
|
195
|
+
);
|
|
196
|
+
const response = await fetch(url, {
|
|
197
|
+
method,
|
|
198
|
+
headers: {
|
|
199
|
+
"Authorization": `Bearer ${this.config.apiKey}`,
|
|
200
|
+
"Content-Type": "application/json",
|
|
201
|
+
"User-Agent": this.config.userAgent,
|
|
202
|
+
"Accept": "application/json"
|
|
203
|
+
},
|
|
204
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
205
|
+
signal: controller.signal
|
|
206
|
+
});
|
|
207
|
+
clearTimeout(timeoutId);
|
|
208
|
+
if (!response.ok) {
|
|
209
|
+
if (response.status < 500 && response.status !== 429) {
|
|
210
|
+
await this.parseErrorResponse(response, endpoint);
|
|
211
|
+
}
|
|
212
|
+
if (response.status === 429) {
|
|
213
|
+
const retryAfter = response.headers.get("retry-after");
|
|
214
|
+
if (retryAfter && attempt < this.config.maxRetries) {
|
|
215
|
+
await this.sleep(parseInt(retryAfter, 10) * 1e3);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
await this.parseErrorResponse(response, endpoint);
|
|
219
|
+
}
|
|
220
|
+
if (attempt < this.config.maxRetries) {
|
|
221
|
+
await this.sleep(this.config.retryDelay * Math.pow(2, attempt));
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
await this.parseErrorResponse(response, endpoint);
|
|
225
|
+
}
|
|
226
|
+
const data = await response.json();
|
|
227
|
+
return { data, status: response.status, headers: response.headers };
|
|
228
|
+
} catch (error) {
|
|
229
|
+
if (error instanceof ApiError) {
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
if (error instanceof Error) {
|
|
233
|
+
if (error.name === "AbortError") {
|
|
234
|
+
throw new TimeoutError(this.config.timeout);
|
|
235
|
+
}
|
|
236
|
+
lastError = error;
|
|
237
|
+
if (attempt < this.config.maxRetries) {
|
|
238
|
+
await this.sleep(this.config.retryDelay * Math.pow(2, attempt));
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
throw new NetworkError(
|
|
243
|
+
lastError?.message || "Unknown network error",
|
|
244
|
+
lastError
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
throw new NetworkError(
|
|
249
|
+
lastError?.message || "Request failed after retries",
|
|
250
|
+
lastError
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Make a GET request.
|
|
255
|
+
*/
|
|
256
|
+
async get(endpoint, options) {
|
|
257
|
+
const queryString = this.buildQueryString(options);
|
|
258
|
+
const response = await this.request("GET", `${endpoint}${queryString}`);
|
|
259
|
+
return response.data;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Make a POST request.
|
|
263
|
+
*/
|
|
264
|
+
async post(endpoint, body, options) {
|
|
265
|
+
const queryString = this.buildQueryString(options);
|
|
266
|
+
const response = await this.request("POST", `${endpoint}${queryString}`, body);
|
|
267
|
+
return response.data;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// src/endpoints/ndc.ts
|
|
272
|
+
var NdcEndpoint = class {
|
|
273
|
+
constructor(http) {
|
|
274
|
+
this.http = http;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Look up a single NDC code.
|
|
278
|
+
*
|
|
279
|
+
* @param code - NDC code (10-digit, 11-digit, or hyphenated format)
|
|
280
|
+
* @param options - Response shape and include options
|
|
281
|
+
* @returns NDC data
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
285
|
+
* const ndc = await client.ndc.lookup("0069-0151-01");
|
|
286
|
+
* console.log(ndc.data.product_name); // "Lipitor"
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
async lookup(code, options) {
|
|
290
|
+
return this.http.get(`/v1/ndc/${encodeURIComponent(code)}`, options);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Look up multiple NDC codes in a single request.
|
|
294
|
+
*
|
|
295
|
+
* @param codes - Array of NDC codes (max 500)
|
|
296
|
+
* @param options - Response shape, include, and batch options
|
|
297
|
+
* @returns Batch response with results for each code
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```ts
|
|
301
|
+
* const results = await client.ndc.lookupMany([
|
|
302
|
+
* "0069-0151-01",
|
|
303
|
+
* "0069-0151-02",
|
|
304
|
+
* "invalid-code"
|
|
305
|
+
* ]);
|
|
306
|
+
*
|
|
307
|
+
* for (const item of results.results) {
|
|
308
|
+
* if (item.found) {
|
|
309
|
+
* console.log(item.data.product_name);
|
|
310
|
+
* } else {
|
|
311
|
+
* console.log(`Not found: ${item.code}`);
|
|
312
|
+
* }
|
|
313
|
+
* }
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
async lookupMany(codes, options) {
|
|
317
|
+
return this.http.post(
|
|
318
|
+
"/v1/ndc/_batch",
|
|
319
|
+
{ codes },
|
|
320
|
+
options
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
// src/endpoints/npi.ts
|
|
326
|
+
var NpiEndpoint = class {
|
|
327
|
+
constructor(http) {
|
|
328
|
+
this.http = http;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Look up a single NPI.
|
|
332
|
+
*
|
|
333
|
+
* @param npi - 10-digit NPI number
|
|
334
|
+
* @param options - Response shape and include options
|
|
335
|
+
* @returns NPI data
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```ts
|
|
339
|
+
* const npi = await client.npi.lookup("1234567890");
|
|
340
|
+
* console.log(npi.data.name);
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
async lookup(npi, options) {
|
|
344
|
+
return this.http.get(`/v1/npi/${encodeURIComponent(npi)}`, options);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Look up multiple NPIs in a single request.
|
|
348
|
+
*
|
|
349
|
+
* @param npis - Array of 10-digit NPI numbers (max 500)
|
|
350
|
+
* @param options - Response shape, include, and batch options
|
|
351
|
+
* @returns Batch response with results for each NPI
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```ts
|
|
355
|
+
* const results = await client.npi.lookupMany([
|
|
356
|
+
* "1234567890",
|
|
357
|
+
* "0987654321"
|
|
358
|
+
* ]);
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
async lookupMany(npis, options) {
|
|
362
|
+
return this.http.post(
|
|
363
|
+
"/v1/npi/_batch",
|
|
364
|
+
{ codes: npis },
|
|
365
|
+
options
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
// src/endpoints/rxnorm.ts
|
|
371
|
+
var RxNormEndpoint = class {
|
|
372
|
+
constructor(http) {
|
|
373
|
+
this.http = http;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Look up a single RxCUI.
|
|
377
|
+
*
|
|
378
|
+
* @param rxcui - RxNorm Concept Unique Identifier
|
|
379
|
+
* @param options - Response shape and include options
|
|
380
|
+
* @returns RxNorm data
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* const rx = await client.rxnorm.lookup("213169");
|
|
385
|
+
* console.log(rx.data.name); // "atorvastatin 10 MG Oral Tablet"
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
async lookup(rxcui, options) {
|
|
389
|
+
return this.http.get(`/v1/rxnorm/${encodeURIComponent(rxcui)}`, options);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Look up multiple RxCUIs in a single request.
|
|
393
|
+
*
|
|
394
|
+
* @param rxcuis - Array of RxCUIs (max 500)
|
|
395
|
+
* @param options - Response shape, include, and batch options
|
|
396
|
+
* @returns Batch response with results for each RxCUI
|
|
397
|
+
*/
|
|
398
|
+
async lookupMany(rxcuis, options) {
|
|
399
|
+
return this.http.post(
|
|
400
|
+
"/v1/rxnorm/_batch",
|
|
401
|
+
{ codes: rxcuis },
|
|
402
|
+
options
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
// src/endpoints/loinc.ts
|
|
408
|
+
var LoincEndpoint = class {
|
|
409
|
+
constructor(http) {
|
|
410
|
+
this.http = http;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Look up a single LOINC code.
|
|
414
|
+
*
|
|
415
|
+
* @param loincNum - LOINC number (e.g., "2345-7")
|
|
416
|
+
* @param options - Response shape and include options
|
|
417
|
+
* @returns LOINC data
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* ```ts
|
|
421
|
+
* const loinc = await client.loinc.lookup("2345-7");
|
|
422
|
+
* console.log(loinc.data.long_common_name); // "Glucose [Mass/volume] in Serum or Plasma"
|
|
423
|
+
* ```
|
|
424
|
+
*/
|
|
425
|
+
async lookup(loincNum, options) {
|
|
426
|
+
return this.http.get(`/v1/loinc/${encodeURIComponent(loincNum)}`, options);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Look up multiple LOINC codes in a single request.
|
|
430
|
+
*
|
|
431
|
+
* @param loincNums - Array of LOINC numbers (max 500)
|
|
432
|
+
* @param options - Response shape, include, and batch options
|
|
433
|
+
* @returns Batch response with results for each LOINC
|
|
434
|
+
*/
|
|
435
|
+
async lookupMany(loincNums, options) {
|
|
436
|
+
return this.http.post(
|
|
437
|
+
"/v1/loinc/_batch",
|
|
438
|
+
{ codes: loincNums },
|
|
439
|
+
options
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
// src/endpoints/icd10.ts
|
|
445
|
+
var Icd10Endpoint = class {
|
|
446
|
+
constructor(http) {
|
|
447
|
+
this.http = http;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Look up a single ICD-10-CM code (diagnoses).
|
|
451
|
+
*
|
|
452
|
+
* @param code - ICD-10-CM code (e.g., "E11.9")
|
|
453
|
+
* @param options - Response shape and include options
|
|
454
|
+
* @returns ICD-10 data
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```ts
|
|
458
|
+
* const icd = await client.icd10.lookupCm("E11.9");
|
|
459
|
+
* console.log(icd.data.description); // "Type 2 diabetes mellitus without complications"
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
async lookupCm(code, options) {
|
|
463
|
+
return this.http.get(`/v1/icd10/cm/${encodeURIComponent(code)}`, options);
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Look up a single ICD-10-PCS code (procedures).
|
|
467
|
+
*
|
|
468
|
+
* @param code - ICD-10-PCS code (e.g., "0BJ08ZZ")
|
|
469
|
+
* @param options - Response shape and include options
|
|
470
|
+
* @returns ICD-10 data
|
|
471
|
+
*
|
|
472
|
+
* @example
|
|
473
|
+
* ```ts
|
|
474
|
+
* const icd = await client.icd10.lookupPcs("0BJ08ZZ");
|
|
475
|
+
* console.log(icd.data.description);
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
async lookupPcs(code, options) {
|
|
479
|
+
return this.http.get(`/v1/icd10/pcs/${encodeURIComponent(code)}`, options);
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Look up multiple ICD-10-CM codes in a single request.
|
|
483
|
+
*
|
|
484
|
+
* @param codes - Array of ICD-10-CM codes (max 500)
|
|
485
|
+
* @param options - Response shape, include, and batch options
|
|
486
|
+
* @returns Batch response with results for each code
|
|
487
|
+
*/
|
|
488
|
+
async lookupCmMany(codes, options) {
|
|
489
|
+
return this.http.post(
|
|
490
|
+
"/v1/icd10/cm/_batch",
|
|
491
|
+
{ codes },
|
|
492
|
+
options
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Look up multiple ICD-10-PCS codes in a single request.
|
|
497
|
+
*
|
|
498
|
+
* @param codes - Array of ICD-10-PCS codes (max 500)
|
|
499
|
+
* @param options - Response shape, include, and batch options
|
|
500
|
+
* @returns Batch response with results for each code
|
|
501
|
+
*/
|
|
502
|
+
async lookupPcsMany(codes, options) {
|
|
503
|
+
return this.http.post(
|
|
504
|
+
"/v1/icd10/pcs/_batch",
|
|
505
|
+
{ codes },
|
|
506
|
+
options
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
// src/endpoints/cvx.ts
|
|
512
|
+
var CvxEndpoint = class {
|
|
513
|
+
constructor(http) {
|
|
514
|
+
this.http = http;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Look up a single CVX code.
|
|
518
|
+
*
|
|
519
|
+
* @param cvxCode - CVX vaccine code
|
|
520
|
+
* @param options - Response shape and include options
|
|
521
|
+
* @returns CVX data
|
|
522
|
+
*
|
|
523
|
+
* @example
|
|
524
|
+
* ```ts
|
|
525
|
+
* const cvx = await client.cvx.lookup("208");
|
|
526
|
+
* console.log(cvx.data.short_description); // "COVID-19, mRNA, LNP-S, PF, 30 mcg/0.3 mL dose"
|
|
527
|
+
* ```
|
|
528
|
+
*/
|
|
529
|
+
async lookup(cvxCode, options) {
|
|
530
|
+
return this.http.get(`/v1/cvx/${encodeURIComponent(cvxCode)}`, options);
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Look up multiple CVX codes in a single request.
|
|
534
|
+
*
|
|
535
|
+
* @param cvxCodes - Array of CVX codes (max 500)
|
|
536
|
+
* @param options - Response shape, include, and batch options
|
|
537
|
+
* @returns Batch response with results for each code
|
|
538
|
+
*/
|
|
539
|
+
async lookupMany(cvxCodes, options) {
|
|
540
|
+
return this.http.post(
|
|
541
|
+
"/v1/cvx/_batch",
|
|
542
|
+
{ codes: cvxCodes },
|
|
543
|
+
options
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
// src/endpoints/mvx.ts
|
|
549
|
+
var MvxEndpoint = class {
|
|
550
|
+
constructor(http) {
|
|
551
|
+
this.http = http;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Look up a single MVX code.
|
|
555
|
+
*
|
|
556
|
+
* @param mvxCode - MVX manufacturer code
|
|
557
|
+
* @param options - Response shape and include options
|
|
558
|
+
* @returns MVX data
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* ```ts
|
|
562
|
+
* const mvx = await client.mvx.lookup("PFR");
|
|
563
|
+
* console.log(mvx.data.manufacturer_name); // "Pfizer, Inc"
|
|
564
|
+
* ```
|
|
565
|
+
*/
|
|
566
|
+
async lookup(mvxCode, options) {
|
|
567
|
+
return this.http.get(`/v1/mvx/${encodeURIComponent(mvxCode)}`, options);
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Look up multiple MVX codes in a single request.
|
|
571
|
+
*
|
|
572
|
+
* @param mvxCodes - Array of MVX codes (max 500)
|
|
573
|
+
* @param options - Response shape, include, and batch options
|
|
574
|
+
* @returns Batch response with results for each code
|
|
575
|
+
*/
|
|
576
|
+
async lookupMany(mvxCodes, options) {
|
|
577
|
+
return this.http.post(
|
|
578
|
+
"/v1/mvx/_batch",
|
|
579
|
+
{ codes: mvxCodes },
|
|
580
|
+
options
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// src/endpoints/fda-labels.ts
|
|
586
|
+
var FdaLabelsEndpoint = class {
|
|
587
|
+
constructor(http) {
|
|
588
|
+
this.http = http;
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Look up FDA label by Set ID.
|
|
592
|
+
*
|
|
593
|
+
* @param setId - FDA SPL Set ID
|
|
594
|
+
* @param options - Response shape and include options
|
|
595
|
+
* @returns FDA Label data
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```ts
|
|
599
|
+
* const label = await client.fdaLabels.lookup("abc123-def456");
|
|
600
|
+
* console.log(label.data.indications_and_usage);
|
|
601
|
+
* ```
|
|
602
|
+
*/
|
|
603
|
+
async lookup(setId, options) {
|
|
604
|
+
return this.http.get(`/v1/fda-labels/${encodeURIComponent(setId)}`, options);
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Look up FDA label by NDC code.
|
|
608
|
+
*
|
|
609
|
+
* @param ndc - NDC code
|
|
610
|
+
* @param options - Response shape and include options
|
|
611
|
+
* @returns FDA Label data
|
|
612
|
+
*
|
|
613
|
+
* @example
|
|
614
|
+
* ```ts
|
|
615
|
+
* const label = await client.fdaLabels.lookupByNdc("0069-0151-01");
|
|
616
|
+
* console.log(label.data.product_name);
|
|
617
|
+
* ```
|
|
618
|
+
*/
|
|
619
|
+
async lookupByNdc(ndc, options) {
|
|
620
|
+
return this.http.get(`/v1/fda-labels/ndc/${encodeURIComponent(ndc)}`, options);
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Look up multiple FDA labels by Set IDs in a single request.
|
|
624
|
+
*
|
|
625
|
+
* @param setIds - Array of Set IDs (max 500)
|
|
626
|
+
* @param options - Response shape, include, and batch options
|
|
627
|
+
* @returns Batch response with results for each Set ID
|
|
628
|
+
*/
|
|
629
|
+
async lookupMany(setIds, options) {
|
|
630
|
+
return this.http.post(
|
|
631
|
+
"/v1/fda-labels/_batch",
|
|
632
|
+
{ codes: setIds },
|
|
633
|
+
options
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
// src/client.ts
|
|
639
|
+
var Fhirfly = class {
|
|
640
|
+
http;
|
|
641
|
+
/**
|
|
642
|
+
* NDC (National Drug Code) lookups.
|
|
643
|
+
*/
|
|
644
|
+
ndc;
|
|
645
|
+
/**
|
|
646
|
+
* NPI (National Provider Identifier) lookups.
|
|
647
|
+
*/
|
|
648
|
+
npi;
|
|
649
|
+
/**
|
|
650
|
+
* RxNorm drug terminology lookups.
|
|
651
|
+
*/
|
|
652
|
+
rxnorm;
|
|
653
|
+
/**
|
|
654
|
+
* LOINC laboratory and clinical observation code lookups.
|
|
655
|
+
*/
|
|
656
|
+
loinc;
|
|
657
|
+
/**
|
|
658
|
+
* ICD-10 diagnosis and procedure code lookups.
|
|
659
|
+
*/
|
|
660
|
+
icd10;
|
|
661
|
+
/**
|
|
662
|
+
* CVX vaccine code lookups.
|
|
663
|
+
*/
|
|
664
|
+
cvx;
|
|
665
|
+
/**
|
|
666
|
+
* MVX vaccine manufacturer code lookups.
|
|
667
|
+
*/
|
|
668
|
+
mvx;
|
|
669
|
+
/**
|
|
670
|
+
* FDA drug label lookups.
|
|
671
|
+
*/
|
|
672
|
+
fdaLabels;
|
|
673
|
+
/**
|
|
674
|
+
* Create a new FHIRfly client.
|
|
675
|
+
*
|
|
676
|
+
* @param config - Client configuration
|
|
677
|
+
* @throws {Error} If apiKey is not provided
|
|
678
|
+
*/
|
|
679
|
+
constructor(config) {
|
|
680
|
+
if (!config.apiKey) {
|
|
681
|
+
throw new Error(
|
|
682
|
+
"FHIRfly API key is required. Get one at https://fhirfly.io/dashboard"
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
const httpConfig = {
|
|
686
|
+
baseUrl: config.baseUrl ?? "https://api.fhirfly.io",
|
|
687
|
+
apiKey: config.apiKey,
|
|
688
|
+
timeout: config.timeout,
|
|
689
|
+
maxRetries: config.maxRetries,
|
|
690
|
+
retryDelay: config.retryDelay
|
|
691
|
+
};
|
|
692
|
+
this.http = new HttpClient(httpConfig);
|
|
693
|
+
this.ndc = new NdcEndpoint(this.http);
|
|
694
|
+
this.npi = new NpiEndpoint(this.http);
|
|
695
|
+
this.rxnorm = new RxNormEndpoint(this.http);
|
|
696
|
+
this.loinc = new LoincEndpoint(this.http);
|
|
697
|
+
this.icd10 = new Icd10Endpoint(this.http);
|
|
698
|
+
this.cvx = new CvxEndpoint(this.http);
|
|
699
|
+
this.mvx = new MvxEndpoint(this.http);
|
|
700
|
+
this.fdaLabels = new FdaLabelsEndpoint(this.http);
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
export { ApiError, AuthenticationError, Fhirfly, FhirflyError, NetworkError, NotFoundError, QuotaExceededError, RateLimitError, ServerError, TimeoutError, ValidationError };
|
|
705
|
+
//# sourceMappingURL=index.js.map
|
|
706
|
+
//# sourceMappingURL=index.js.map
|