autoicd-js 0.6.0 → 0.8.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 CHANGED
@@ -72,6 +72,10 @@ var AutoICD = class {
72
72
  icd10;
73
73
  /** Sub-resource for ICD-11 code lookup. */
74
74
  icd11;
75
+ /** Sub-resource for ICF code lookup and coding. */
76
+ icf;
77
+ /** Sub-resource for LOINC code lookup and coding. */
78
+ loinc;
75
79
  constructor(options) {
76
80
  if (!options.apiKey) {
77
81
  throw new Error("apiKey is required");
@@ -82,6 +86,8 @@ var AutoICD = class {
82
86
  this._fetch = options.fetch ?? globalThis.fetch;
83
87
  this.icd10 = new ICD10Codes(this);
84
88
  this.icd11 = new ICD11Codes(this);
89
+ this.icf = new ICFCodes(this);
90
+ this.loinc = new LOINCCodes(this);
85
91
  }
86
92
  // ─── Public Methods ───
87
93
  /**
@@ -100,7 +106,11 @@ var AutoICD = class {
100
106
  text,
101
107
  top_k: options?.topK,
102
108
  include_negated: options?.includeNegated,
103
- output_system: options?.outputSystem
109
+ output_system: options?.outputSystem,
110
+ include_icf: options?.includeIcf,
111
+ include_icd11: options?.includeIcd11,
112
+ include_snomed: options?.includeSnomed,
113
+ include_umls: options?.includeUmls
104
114
  });
105
115
  }
106
116
  /**
@@ -116,6 +126,47 @@ var AutoICD = class {
116
126
  async anonymize(text) {
117
127
  return this.post("/api/v1/anonymize", { text });
118
128
  }
129
+ /**
130
+ * Audit a chart for coding gaps, RADV risk, specificity, denial flags, and
131
+ * a reconciled problem list. Every finding carries extractive evidence spans.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * const audit = await autoicd.audit({
136
+ * text: "68yo M, type 2 diabetes, chronic systolic heart failure on furosemide.",
137
+ * codes: [{ code: "E11.9", kind: "icd10" }],
138
+ * capabilities: ["hcc", "radv", "specificity", "denial", "problem_list"],
139
+ * context: { patient: { coverage: "medicare_advantage" } },
140
+ * });
141
+ * console.log(audit.totals.estimated_revenue_recovery);
142
+ * for (const m of audit.missed) {
143
+ * console.log(`${m.code} ${m.hcc_category} $${m.estimated_revenue}`);
144
+ * }
145
+ * ```
146
+ */
147
+ async audit(request) {
148
+ return this.post("/api/v1/audit", request);
149
+ }
150
+ /**
151
+ * Translate a code between healthcare coding systems. Maps a source code
152
+ * (ICD-10, ICD-11, SNOMED, UMLS, ICF) to equivalents in requested target
153
+ * systems. Omit `to` to get every system reachable from the source.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * const result = await autoicd.translate({
158
+ * from: { code: "E11.9", system: "icd10" },
159
+ * });
160
+ * console.log(result.mappings.icd11);
161
+ * console.log(result.mappings.snomed);
162
+ * ```
163
+ */
164
+ async translate(request) {
165
+ return this.post(
166
+ "/api/v1/translate",
167
+ request
168
+ );
169
+ }
119
170
  // ─── Internal HTTP ───
120
171
  /** @internal */
121
172
  async get(path) {
@@ -242,6 +293,124 @@ var ICD11Codes = class {
242
293
  return this.client.get(`/api/v1/icd11/codes/${encodeURIComponent(code)}`);
243
294
  }
244
295
  };
296
+ var ICFCodes = class {
297
+ constructor(client) {
298
+ this.client = client;
299
+ }
300
+ /**
301
+ * Code clinical text to ICF codes.
302
+ *
303
+ * @example
304
+ * ```ts
305
+ * const result = await autoicd.icf.code("Patient has difficulty walking");
306
+ * for (const entity of result.results) {
307
+ * console.log(entity.entity_text, entity.codes[0]?.code);
308
+ * }
309
+ * ```
310
+ */
311
+ async code(text, options) {
312
+ return this.client.post("/api/v1/icf/code", {
313
+ text,
314
+ top_k: options?.topK
315
+ });
316
+ }
317
+ /**
318
+ * Get full details for a single ICF code, including definition,
319
+ * hierarchy (parent/children), inclusions, exclusions, and index terms.
320
+ *
321
+ * @example
322
+ * ```ts
323
+ * const detail = await autoicd.icf.lookup("b280");
324
+ * console.log(detail.title);
325
+ * console.log(detail.definition);
326
+ * console.log(detail.children.length);
327
+ * ```
328
+ */
329
+ async lookup(code) {
330
+ return this.client.get(`/api/v1/icf/codes/${encodeURIComponent(code)}`);
331
+ }
332
+ /**
333
+ * Search ICF codes by description.
334
+ *
335
+ * @example
336
+ * ```ts
337
+ * const results = await autoicd.icf.search("pain");
338
+ * ```
339
+ */
340
+ async search(query, options) {
341
+ const params = new URLSearchParams({ q: query });
342
+ if (options?.limit !== void 0) params.set("limit", String(options.limit));
343
+ if (options?.offset !== void 0) params.set("offset", String(options.offset));
344
+ return this.client.get(`/api/v1/icf/codes/search?${params}`);
345
+ }
346
+ /**
347
+ * Get the ICF Core Set for an ICD-10 diagnosis code.
348
+ *
349
+ * @example
350
+ * ```ts
351
+ * const coreSet = await autoicd.icf.coreSet("M54.5");
352
+ * console.log(coreSet.condition_name);
353
+ * console.log(coreSet.brief.length, "brief codes");
354
+ * console.log(coreSet.comprehensive.length, "comprehensive codes");
355
+ * ```
356
+ */
357
+ async coreSet(icd10Code) {
358
+ return this.client.get(`/api/v1/icf/core-set/${encodeURIComponent(icd10Code)}`);
359
+ }
360
+ };
361
+ var LOINCCodes = class {
362
+ constructor(client) {
363
+ this.client = client;
364
+ }
365
+ /**
366
+ * Code clinical text to LOINC codes.
367
+ *
368
+ * Extracts lab tests, imaging orders, and clinical observations from
369
+ * free text and matches to LOINC codes using NER + SapBERT embeddings.
370
+ *
371
+ * @example
372
+ * ```ts
373
+ * const result = await autoicd.loinc.code("Order CBC, glucose, and TSH");
374
+ * for (const entity of result.results) {
375
+ * console.log(entity.entity_text, entity.codes[0]?.code);
376
+ * }
377
+ * ```
378
+ */
379
+ async code(text, options) {
380
+ return this.client.post("/api/v1/loinc/code", {
381
+ text,
382
+ top_k: options?.topK
383
+ });
384
+ }
385
+ /**
386
+ * Get full details for a single LOINC code, including 6-axis classification,
387
+ * definition, related names, and cross-references.
388
+ *
389
+ * @example
390
+ * ```ts
391
+ * const detail = await autoicd.loinc.lookup("2345-7");
392
+ * console.log(detail.long_common_name);
393
+ * console.log(detail.component, detail.system);
394
+ * ```
395
+ */
396
+ async lookup(code) {
397
+ return this.client.get(`/api/v1/loinc/codes/${encodeURIComponent(code)}`);
398
+ }
399
+ /**
400
+ * Search LOINC codes by description.
401
+ *
402
+ * @example
403
+ * ```ts
404
+ * const results = await autoicd.loinc.search("glucose");
405
+ * ```
406
+ */
407
+ async search(query, options) {
408
+ const params = new URLSearchParams({ q: query });
409
+ if (options?.limit !== void 0) params.set("limit", String(options.limit));
410
+ if (options?.offset !== void 0) params.set("offset", String(options.offset));
411
+ return this.client.get(`/api/v1/loinc/codes/search?${params}`);
412
+ }
413
+ };
245
414
  function parseRateLimit(headers) {
246
415
  const limit = headers.get("X-RateLimit-Limit");
247
416
  const remaining = headers.get("X-RateLimit-Remaining");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/client.ts"],"sourcesContent":["export { AutoICD } from \"./client.js\";\n\nexport type {\n AutoICDOptions,\n CodeOptions,\n CodeMatch,\n CodingEntity,\n CodingResponse,\n SearchOptions,\n CodeDetail,\n CodeDetailFull,\n ChapterInfo,\n CodeSearchResponse,\n PIIEntity,\n AnonymizeResponse,\n RateLimit,\n ICD11CodeDetail,\n ICD11ChapterInfo,\n CrosswalkMapping,\n ICD11CodeDetailFull,\n ICD11CodeSearchResult,\n ICD11CodeSearchResponse,\n} from \"./types.js\";\n\nexport {\n AutoICDError,\n AuthenticationError,\n RateLimitError,\n NotFoundError,\n} from \"./errors.js\";\n","import type { RateLimit } from \"./types.js\";\n\nexport class AutoICDError extends Error {\n readonly status: number;\n\n constructor(status: number, message: string) {\n super(message);\n this.name = \"AutoICDError\";\n this.status = status;\n }\n}\n\nexport class AuthenticationError extends AutoICDError {\n constructor(message = \"Invalid API key\") {\n super(401, message);\n this.name = \"AuthenticationError\";\n }\n}\n\nexport class RateLimitError extends AutoICDError {\n readonly rateLimit: RateLimit;\n\n constructor(message: string, rateLimit: RateLimit) {\n super(429, message);\n this.name = \"RateLimitError\";\n this.rateLimit = rateLimit;\n }\n}\n\nexport class NotFoundError extends AutoICDError {\n constructor(message = \"Resource not found\") {\n super(404, message);\n this.name = \"NotFoundError\";\n }\n}\n","import type {\n AutoICDOptions,\n CodeOptions,\n CodingResponse,\n SearchOptions,\n CodeSearchResponse,\n CodeDetail,\n CodeDetailFull,\n AnonymizeResponse,\n RateLimit,\n ErrorBody,\n ICD11CodeSearchResponse,\n ICD11CodeDetailFull,\n} from \"./types.js\";\nimport {\n AutoICDError,\n AuthenticationError,\n RateLimitError,\n NotFoundError,\n} from \"./errors.js\";\n\nconst DEFAULT_BASE_URL = \"https://autoicdapi.com\";\nconst DEFAULT_TIMEOUT = 30_000;\n\nexport class AutoICD {\n private readonly apiKey: string;\n private readonly baseURL: string;\n private readonly timeout: number;\n private readonly _fetch: typeof globalThis.fetch;\n\n /** Rate limit info from the most recent API response. */\n lastRateLimit: RateLimit | null = null;\n\n /** Sub-resource for ICD-10 code lookup. */\n readonly icd10: ICD10Codes;\n\n /** Sub-resource for ICD-11 code lookup. */\n readonly icd11: ICD11Codes;\n\n constructor(options: AutoICDOptions) {\n if (!options.apiKey) {\n throw new Error(\"apiKey is required\");\n }\n this.apiKey = options.apiKey;\n this.baseURL = (options.baseURL ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT;\n this._fetch = options.fetch ?? globalThis.fetch;\n this.icd10 = new ICD10Codes(this);\n this.icd11 = new ICD11Codes(this);\n }\n\n // ─── Public Methods ───\n\n /**\n * Code clinical text to ICD-10-CM diagnoses.\n *\n * @example\n * ```ts\n * const result = await autoicd.code(\"Patient has type 2 diabetes\");\n * for (const entity of result.entities) {\n * console.log(entity.entity_text, entity.codes[0]?.code);\n * }\n * ```\n */\n async code(text: string, options?: CodeOptions): Promise<CodingResponse> {\n return this.post<CodingResponse>(\"/api/v1/code\", {\n text,\n top_k: options?.topK,\n include_negated: options?.includeNegated,\n output_system: options?.outputSystem,\n });\n }\n\n /**\n * Anonymize PHI/PII in clinical text.\n *\n * @example\n * ```ts\n * const result = await autoicd.anonymize(\"John Smith, DOB 01/15/1980, has COPD\");\n * console.log(result.anonymized_text);\n * // \"[NAME], DOB [DATE], has COPD\"\n * ```\n */\n async anonymize(text: string): Promise<AnonymizeResponse> {\n return this.post<AnonymizeResponse>(\"/api/v1/anonymize\", { text });\n }\n\n // ─── Internal HTTP ───\n\n /** @internal */\n async get<T>(path: string): Promise<T> {\n return this.request<T>(\"GET\", path);\n }\n\n /** @internal */\n async post<T>(path: string, body: Record<string, unknown>): Promise<T> {\n // Strip undefined values so the API receives clean JSON\n const clean = Object.fromEntries(\n Object.entries(body).filter(([, v]) => v !== undefined)\n );\n return this.request<T>(\"POST\", path, clean);\n }\n\n private async request<T>(\n method: string,\n path: string,\n body?: Record<string, unknown>\n ): Promise<T> {\n const url = `${this.baseURL}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeout);\n\n try {\n const res = await this._fetch(url, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n },\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n // Parse rate limit headers\n this.lastRateLimit = parseRateLimit(res.headers);\n\n if (res.ok) {\n return (await res.json()) as T;\n }\n\n // Error responses\n const errorBody = (await res.json().catch(() => null)) as ErrorBody | null;\n const message = errorBody?.error ?? `HTTP ${res.status}`;\n\n if (res.status === 401) throw new AuthenticationError(message);\n if (res.status === 404) throw new NotFoundError(message);\n if (res.status === 429) {\n throw new RateLimitError(\n message,\n this.lastRateLimit ?? {\n limit: errorBody?.limit ?? 0,\n remaining: 0,\n resetAt: errorBody?.resetAt ? new Date(errorBody.resetAt) : new Date(),\n }\n );\n }\n\n throw new AutoICDError(res.status, message);\n } catch (err) {\n if (err instanceof AutoICDError) throw err;\n if (err instanceof DOMException && err.name === \"AbortError\") {\n throw new AutoICDError(0, `Request timed out after ${this.timeout}ms`);\n }\n throw err;\n } finally {\n clearTimeout(timer);\n }\n }\n}\n\n// ─── ICD-10 Codes Sub-resource ───\n\nclass ICD10Codes {\n constructor(private readonly client: AutoICD) {}\n\n /**\n * Search ICD-10 codes by description.\n *\n * @example\n * ```ts\n * const results = await autoicd.icd10.search(\"diabetes mellitus\");\n * ```\n */\n async search(query: string, options?: SearchOptions): Promise<CodeSearchResponse> {\n const params = new URLSearchParams({ q: query });\n if (options?.limit !== undefined) params.set(\"limit\", String(options.limit));\n if (options?.offset !== undefined) params.set(\"offset\", String(options.offset));\n return this.client.get<CodeSearchResponse>(`/api/v1/icd10/codes/search?${params}`);\n }\n\n /**\n * Get comprehensive details for a single ICD-10 code, including synonyms,\n * hierarchy (parent/children), chapter, and SNOMED CT / UMLS cross-references.\n *\n * @example\n * ```ts\n * const detail = await autoicd.icd10.get(\"E11.9\");\n * console.log(detail.long_description);\n * console.log(detail.synonyms.snomed); // SNOMED CT synonyms\n * console.log(detail.chapter?.title); // \"Endocrine, Nutritional and Metabolic Diseases\"\n * console.log(detail.children.length); // child codes\n * ```\n */\n async get(code: string): Promise<CodeDetailFull> {\n return this.client.get<CodeDetailFull>(`/api/v1/icd10/codes/${encodeURIComponent(code)}`);\n }\n\n}\n\n// ─── ICD-11 Codes Sub-resource ───\n\nclass ICD11Codes {\n constructor(private readonly client: AutoICD) {}\n\n /**\n * Search ICD-11 codes by description.\n *\n * @example\n * ```ts\n * const results = await autoicd.icd11.search(\"diabetes mellitus\");\n * ```\n */\n async search(query: string, options?: SearchOptions): Promise<ICD11CodeSearchResponse> {\n const params = new URLSearchParams({ q: query });\n if (options?.limit !== undefined) params.set(\"limit\", String(options.limit));\n if (options?.offset !== undefined) params.set(\"offset\", String(options.offset));\n return this.client.get<ICD11CodeSearchResponse>(`/api/v1/icd11/codes/search?${params}`);\n }\n\n /**\n * Get comprehensive details for a single ICD-11 code, including synonyms,\n * hierarchy (parent/children), chapter, and ICD-10 crosswalk mappings.\n *\n * @example\n * ```ts\n * const detail = await autoicd.icd11.get(\"5A11\");\n * console.log(detail.long_description);\n * console.log(detail.chapter?.title);\n * console.log(detail.icd10_mappings);\n * ```\n */\n async get(code: string): Promise<ICD11CodeDetailFull> {\n return this.client.get<ICD11CodeDetailFull>(`/api/v1/icd11/codes/${encodeURIComponent(code)}`);\n }\n}\n\n// ─── Helpers ───\n\nfunction parseRateLimit(headers: Headers): RateLimit | null {\n const limit = headers.get(\"X-RateLimit-Limit\");\n const remaining = headers.get(\"X-RateLimit-Remaining\");\n const reset = headers.get(\"X-RateLimit-Reset\");\n\n if (!limit || !remaining || !reset) return null;\n\n return {\n limit: parseInt(limit, 10),\n remaining: parseInt(remaining, 10),\n resetAt: new Date(reset),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,eAAN,cAA2B,MAAM;AAAA,EAC7B;AAAA,EAET,YAAY,QAAgB,SAAiB;AAC3C,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AAEO,IAAM,sBAAN,cAAkC,aAAa;AAAA,EACpD,YAAY,UAAU,mBAAmB;AACvC,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,iBAAN,cAA6B,aAAa;AAAA,EACtC;AAAA,EAET,YAAY,SAAiB,WAAsB;AACjD,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AACZ,SAAK,YAAY;AAAA,EACnB;AACF;AAEO,IAAM,gBAAN,cAA4B,aAAa;AAAA,EAC9C,YAAY,UAAU,sBAAsB;AAC1C,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AAAA,EACd;AACF;;;ACbA,IAAM,mBAAmB;AACzB,IAAM,kBAAkB;AAEjB,IAAM,UAAN,MAAc;AAAA,EACF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAGjB,gBAAkC;AAAA;AAAA,EAGzB;AAAA;AAAA,EAGA;AAAA,EAET,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BAAuB;AACrD,QAAM,QAAQ,QAAQ,IAAI,mBAAmB;AAE7C,MAAI,CAAC,SAAS,CAAC,aAAa,CAAC,MAAO,QAAO;AAE3C,SAAO;AAAA,IACL,OAAO,SAAS,OAAO,EAAE;AAAA,IACzB,WAAW,SAAS,WAAW,EAAE;AAAA,IACjC,SAAS,IAAI,KAAK,KAAK;AAAA,EACzB;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/client.ts"],"sourcesContent":["export { AutoICD } from \"./client.js\";\n\nexport type {\n AutoICDOptions,\n CodeOptions,\n CodeMatch,\n CodingEntity,\n CodingResponse,\n SearchOptions,\n CodeDetail,\n CodeDetailFull,\n ChapterInfo,\n CodeSearchResponse,\n PIIEntity,\n AnonymizeResponse,\n RateLimit,\n ICD11CodeDetail,\n ICD11ChapterInfo,\n CrosswalkMapping,\n ICD11CodeDetailFull,\n ICD11CodeSearchResult,\n ICD11CodeSearchResponse,\n ICFComponent,\n ICFCodeSummary,\n ICFCodeDetail,\n ICFCodeResult,\n ICFCodingEntity,\n ICFCodingResponse,\n ICFSearchResponse,\n ICFCoreSetResult,\n ICFCrossReference,\n LOINCCodeSummary,\n LOINCCodeDetail,\n LOINCSearchResponse,\n LOINCCodeResult,\n LOINCCodingEntity,\n LOINCCodingResponse,\n AuditCapability,\n AuditCode,\n AuditDocument,\n AuditContext,\n AuditRequest,\n AuditResponse,\n EvidenceSpan,\n ConfirmedCode,\n MissedCode,\n UnsupportedCode,\n SpecificityUpgrade,\n DenialRisk,\n ProblemListEntry,\n AuditTotals,\n RatesUsed,\n UpgradeHint,\n InteropSystem,\n TranslateRequest,\n TranslateResponse,\n TranslateMapping,\n TranslateSource,\n} from \"./types.js\";\n\nexport {\n AutoICDError,\n AuthenticationError,\n RateLimitError,\n NotFoundError,\n} from \"./errors.js\";\n","import type { RateLimit } from \"./types.js\";\n\nexport class AutoICDError extends Error {\n readonly status: number;\n\n constructor(status: number, message: string) {\n super(message);\n this.name = \"AutoICDError\";\n this.status = status;\n }\n}\n\nexport class AuthenticationError extends AutoICDError {\n constructor(message = \"Invalid API key\") {\n super(401, message);\n this.name = \"AuthenticationError\";\n }\n}\n\nexport class RateLimitError extends AutoICDError {\n readonly rateLimit: RateLimit;\n\n constructor(message: string, rateLimit: RateLimit) {\n super(429, message);\n this.name = \"RateLimitError\";\n this.rateLimit = rateLimit;\n }\n}\n\nexport class NotFoundError extends AutoICDError {\n constructor(message = \"Resource not found\") {\n super(404, message);\n this.name = \"NotFoundError\";\n }\n}\n","import type {\n AutoICDOptions,\n CodeOptions,\n CodingResponse,\n SearchOptions,\n CodeSearchResponse,\n CodeDetail,\n CodeDetailFull,\n AnonymizeResponse,\n RateLimit,\n ErrorBody,\n ICD11CodeSearchResponse,\n ICD11CodeDetailFull,\n ICFCodingResponse,\n ICFCodeDetail,\n ICFSearchResponse,\n ICFCoreSetResult,\n LOINCCodeDetail,\n LOINCSearchResponse,\n LOINCCodingResponse,\n AuditRequest,\n AuditResponse,\n TranslateRequest,\n TranslateResponse,\n} from \"./types.js\";\nimport {\n AutoICDError,\n AuthenticationError,\n RateLimitError,\n NotFoundError,\n} from \"./errors.js\";\n\nconst DEFAULT_BASE_URL = \"https://autoicdapi.com\";\nconst DEFAULT_TIMEOUT = 30_000;\n\nexport class AutoICD {\n private readonly apiKey: string;\n private readonly baseURL: string;\n private readonly timeout: number;\n private readonly _fetch: typeof globalThis.fetch;\n\n /** Rate limit info from the most recent API response. */\n lastRateLimit: RateLimit | null = null;\n\n /** Sub-resource for ICD-10 code lookup. */\n readonly icd10: ICD10Codes;\n\n /** Sub-resource for ICD-11 code lookup. */\n readonly icd11: ICD11Codes;\n\n /** Sub-resource for ICF code lookup and coding. */\n readonly icf: ICFCodes;\n\n /** Sub-resource for LOINC code lookup and coding. */\n readonly loinc: LOINCCodes;\n\n constructor(options: AutoICDOptions) {\n if (!options.apiKey) {\n throw new Error(\"apiKey is required\");\n }\n this.apiKey = options.apiKey;\n this.baseURL = (options.baseURL ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT;\n this._fetch = options.fetch ?? globalThis.fetch;\n this.icd10 = new ICD10Codes(this);\n this.icd11 = new ICD11Codes(this);\n this.icf = new ICFCodes(this);\n this.loinc = new LOINCCodes(this);\n }\n\n // ─── Public Methods ───\n\n /**\n * Code clinical text to ICD-10-CM diagnoses.\n *\n * @example\n * ```ts\n * const result = await autoicd.code(\"Patient has type 2 diabetes\");\n * for (const entity of result.entities) {\n * console.log(entity.entity_text, entity.codes[0]?.code);\n * }\n * ```\n */\n async code(text: string, options?: CodeOptions): Promise<CodingResponse> {\n return this.post<CodingResponse>(\"/api/v1/code\", {\n text,\n top_k: options?.topK,\n include_negated: options?.includeNegated,\n output_system: options?.outputSystem,\n include_icf: options?.includeIcf,\n include_icd11: options?.includeIcd11,\n include_snomed: options?.includeSnomed,\n include_umls: options?.includeUmls,\n });\n }\n\n /**\n * Anonymize PHI/PII in clinical text.\n *\n * @example\n * ```ts\n * const result = await autoicd.anonymize(\"John Smith, DOB 01/15/1980, has COPD\");\n * console.log(result.anonymized_text);\n * // \"[NAME], DOB [DATE], has COPD\"\n * ```\n */\n async anonymize(text: string): Promise<AnonymizeResponse> {\n return this.post<AnonymizeResponse>(\"/api/v1/anonymize\", { text });\n }\n\n /**\n * Audit a chart for coding gaps, RADV risk, specificity, denial flags, and\n * a reconciled problem list. Every finding carries extractive evidence spans.\n *\n * @example\n * ```ts\n * const audit = await autoicd.audit({\n * text: \"68yo M, type 2 diabetes, chronic systolic heart failure on furosemide.\",\n * codes: [{ code: \"E11.9\", kind: \"icd10\" }],\n * capabilities: [\"hcc\", \"radv\", \"specificity\", \"denial\", \"problem_list\"],\n * context: { patient: { coverage: \"medicare_advantage\" } },\n * });\n * console.log(audit.totals.estimated_revenue_recovery);\n * for (const m of audit.missed) {\n * console.log(`${m.code} ${m.hcc_category} $${m.estimated_revenue}`);\n * }\n * ```\n */\n async audit(request: AuditRequest): Promise<AuditResponse> {\n return this.post<AuditResponse>(\"/api/v1/audit\", request as unknown as Record<string, unknown>);\n }\n\n /**\n * Translate a code between healthcare coding systems. Maps a source code\n * (ICD-10, ICD-11, SNOMED, UMLS, ICF) to equivalents in requested target\n * systems. Omit `to` to get every system reachable from the source.\n *\n * @example\n * ```ts\n * const result = await autoicd.translate({\n * from: { code: \"E11.9\", system: \"icd10\" },\n * });\n * console.log(result.mappings.icd11);\n * console.log(result.mappings.snomed);\n * ```\n */\n async translate(request: TranslateRequest): Promise<TranslateResponse> {\n return this.post<TranslateResponse>(\n \"/api/v1/translate\",\n request as unknown as Record<string, unknown>,\n );\n }\n\n // ─── Internal HTTP ───\n\n /** @internal */\n async get<T>(path: string): Promise<T> {\n return this.request<T>(\"GET\", path);\n }\n\n /** @internal */\n async post<T>(path: string, body: Record<string, unknown>): Promise<T> {\n // Strip undefined values so the API receives clean JSON\n const clean = Object.fromEntries(\n Object.entries(body).filter(([, v]) => v !== undefined)\n );\n return this.request<T>(\"POST\", path, clean);\n }\n\n private async request<T>(\n method: string,\n path: string,\n body?: Record<string, unknown>\n ): Promise<T> {\n const url = `${this.baseURL}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeout);\n\n try {\n const res = await this._fetch(url, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n },\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n // Parse rate limit headers\n this.lastRateLimit = parseRateLimit(res.headers);\n\n if (res.ok) {\n return (await res.json()) as T;\n }\n\n // Error responses\n const errorBody = (await res.json().catch(() => null)) as ErrorBody | null;\n const message = errorBody?.error ?? `HTTP ${res.status}`;\n\n if (res.status === 401) throw new AuthenticationError(message);\n if (res.status === 404) throw new NotFoundError(message);\n if (res.status === 429) {\n throw new RateLimitError(\n message,\n this.lastRateLimit ?? {\n limit: errorBody?.limit ?? 0,\n remaining: 0,\n resetAt: errorBody?.resetAt ? new Date(errorBody.resetAt) : new Date(),\n }\n );\n }\n\n throw new AutoICDError(res.status, message);\n } catch (err) {\n if (err instanceof AutoICDError) throw err;\n if (err instanceof DOMException && err.name === \"AbortError\") {\n throw new AutoICDError(0, `Request timed out after ${this.timeout}ms`);\n }\n throw err;\n } finally {\n clearTimeout(timer);\n }\n }\n}\n\n// ─── ICD-10 Codes Sub-resource ───\n\nclass ICD10Codes {\n constructor(private readonly client: AutoICD) {}\n\n /**\n * Search ICD-10 codes by description.\n *\n * @example\n * ```ts\n * const results = await autoicd.icd10.search(\"diabetes mellitus\");\n * ```\n */\n async search(query: string, options?: SearchOptions): Promise<CodeSearchResponse> {\n const params = new URLSearchParams({ q: query });\n if (options?.limit !== undefined) params.set(\"limit\", String(options.limit));\n if (options?.offset !== undefined) params.set(\"offset\", String(options.offset));\n return this.client.get<CodeSearchResponse>(`/api/v1/icd10/codes/search?${params}`);\n }\n\n /**\n * Get comprehensive details for a single ICD-10 code, including synonyms,\n * hierarchy (parent/children), chapter, and SNOMED CT / UMLS cross-references.\n *\n * @example\n * ```ts\n * const detail = await autoicd.icd10.get(\"E11.9\");\n * console.log(detail.long_description);\n * console.log(detail.synonyms.snomed); // SNOMED CT synonyms\n * console.log(detail.chapter?.title); // \"Endocrine, Nutritional and Metabolic Diseases\"\n * console.log(detail.children.length); // child codes\n * ```\n */\n async get(code: string): Promise<CodeDetailFull> {\n return this.client.get<CodeDetailFull>(`/api/v1/icd10/codes/${encodeURIComponent(code)}`);\n }\n\n}\n\n// ─── ICD-11 Codes Sub-resource ───\n\nclass ICD11Codes {\n constructor(private readonly client: AutoICD) {}\n\n /**\n * Search ICD-11 codes by description.\n *\n * @example\n * ```ts\n * const results = await autoicd.icd11.search(\"diabetes mellitus\");\n * ```\n */\n async search(query: string, options?: SearchOptions): Promise<ICD11CodeSearchResponse> {\n const params = new URLSearchParams({ q: query });\n if (options?.limit !== undefined) params.set(\"limit\", String(options.limit));\n if (options?.offset !== undefined) params.set(\"offset\", String(options.offset));\n return this.client.get<ICD11CodeSearchResponse>(`/api/v1/icd11/codes/search?${params}`);\n }\n\n /**\n * Get comprehensive details for a single ICD-11 code, including synonyms,\n * hierarchy (parent/children), chapter, and ICD-10 crosswalk mappings.\n *\n * @example\n * ```ts\n * const detail = await autoicd.icd11.get(\"5A11\");\n * console.log(detail.long_description);\n * console.log(detail.chapter?.title);\n * console.log(detail.icd10_mappings);\n * ```\n */\n async get(code: string): Promise<ICD11CodeDetailFull> {\n return this.client.get<ICD11CodeDetailFull>(`/api/v1/icd11/codes/${encodeURIComponent(code)}`);\n }\n}\n\n// ─── ICF Codes Sub-resource ───\n\nclass ICFCodes {\n constructor(private readonly client: AutoICD) {}\n\n /**\n * Code clinical text to ICF codes.\n *\n * @example\n * ```ts\n * const result = await autoicd.icf.code(\"Patient has difficulty walking\");\n * for (const entity of result.results) {\n * console.log(entity.entity_text, entity.codes[0]?.code);\n * }\n * ```\n */\n async code(text: string, options?: { topK?: number }): Promise<ICFCodingResponse> {\n return this.client.post<ICFCodingResponse>(\"/api/v1/icf/code\", {\n text,\n top_k: options?.topK,\n });\n }\n\n /**\n * Get full details for a single ICF code, including definition,\n * hierarchy (parent/children), inclusions, exclusions, and index terms.\n *\n * @example\n * ```ts\n * const detail = await autoicd.icf.lookup(\"b280\");\n * console.log(detail.title);\n * console.log(detail.definition);\n * console.log(detail.children.length);\n * ```\n */\n async lookup(code: string): Promise<ICFCodeDetail> {\n return this.client.get<ICFCodeDetail>(`/api/v1/icf/codes/${encodeURIComponent(code)}`);\n }\n\n /**\n * Search ICF codes by description.\n *\n * @example\n * ```ts\n * const results = await autoicd.icf.search(\"pain\");\n * ```\n */\n async search(query: string, options?: SearchOptions): Promise<ICFSearchResponse> {\n const params = new URLSearchParams({ q: query });\n if (options?.limit !== undefined) params.set(\"limit\", String(options.limit));\n if (options?.offset !== undefined) params.set(\"offset\", String(options.offset));\n return this.client.get<ICFSearchResponse>(`/api/v1/icf/codes/search?${params}`);\n }\n\n /**\n * Get the ICF Core Set for an ICD-10 diagnosis code.\n *\n * @example\n * ```ts\n * const coreSet = await autoicd.icf.coreSet(\"M54.5\");\n * console.log(coreSet.condition_name);\n * console.log(coreSet.brief.length, \"brief codes\");\n * console.log(coreSet.comprehensive.length, \"comprehensive codes\");\n * ```\n */\n async coreSet(icd10Code: string): Promise<ICFCoreSetResult> {\n return this.client.get<ICFCoreSetResult>(`/api/v1/icf/core-set/${encodeURIComponent(icd10Code)}`);\n }\n}\n\n// ─── LOINC Codes Sub-resource ───\n\nclass LOINCCodes {\n constructor(private readonly client: AutoICD) {}\n\n /**\n * Code clinical text to LOINC codes.\n *\n * Extracts lab tests, imaging orders, and clinical observations from\n * free text and matches to LOINC codes using NER + SapBERT embeddings.\n *\n * @example\n * ```ts\n * const result = await autoicd.loinc.code(\"Order CBC, glucose, and TSH\");\n * for (const entity of result.results) {\n * console.log(entity.entity_text, entity.codes[0]?.code);\n * }\n * ```\n */\n async code(text: string, options?: { topK?: number }): Promise<LOINCCodingResponse> {\n return this.client.post<LOINCCodingResponse>(\"/api/v1/loinc/code\", {\n text,\n top_k: options?.topK,\n });\n }\n\n /**\n * Get full details for a single LOINC code, including 6-axis classification,\n * definition, related names, and cross-references.\n *\n * @example\n * ```ts\n * const detail = await autoicd.loinc.lookup(\"2345-7\");\n * console.log(detail.long_common_name);\n * console.log(detail.component, detail.system);\n * ```\n */\n async lookup(code: string): Promise<LOINCCodeDetail> {\n return this.client.get<LOINCCodeDetail>(`/api/v1/loinc/codes/${encodeURIComponent(code)}`);\n }\n\n /**\n * Search LOINC codes by description.\n *\n * @example\n * ```ts\n * const results = await autoicd.loinc.search(\"glucose\");\n * ```\n */\n async search(query: string, options?: SearchOptions): Promise<LOINCSearchResponse> {\n const params = new URLSearchParams({ q: query });\n if (options?.limit !== undefined) params.set(\"limit\", String(options.limit));\n if (options?.offset !== undefined) params.set(\"offset\", String(options.offset));\n return this.client.get<LOINCSearchResponse>(`/api/v1/loinc/codes/search?${params}`);\n }\n}\n\n// ─── Helpers ───\n\nfunction parseRateLimit(headers: Headers): RateLimit | null {\n const limit = headers.get(\"X-RateLimit-Limit\");\n const remaining = headers.get(\"X-RateLimit-Remaining\");\n const reset = headers.get(\"X-RateLimit-Reset\");\n\n if (!limit || !remaining || !reset) return null;\n\n return {\n limit: parseInt(limit, 10),\n remaining: parseInt(remaining, 10),\n resetAt: new Date(reset),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,eAAN,cAA2B,MAAM;AAAA,EAC7B;AAAA,EAET,YAAY,QAAgB,SAAiB;AAC3C,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AAEO,IAAM,sBAAN,cAAkC,aAAa;AAAA,EACpD,YAAY,UAAU,mBAAmB;AACvC,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,iBAAN,cAA6B,aAAa;AAAA,EACtC;AAAA,EAET,YAAY,SAAiB,WAAsB;AACjD,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AACZ,SAAK,YAAY;AAAA,EACnB;AACF;AAEO,IAAM,gBAAN,cAA4B,aAAa;AAAA,EAC9C,YAAY,UAAU,sBAAsB;AAC1C,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AAAA,EACd;AACF;;;ACFA,IAAM,mBAAmB;AACzB,IAAM,kBAAkB;AAEjB,IAAM,UAAN,MAAc;AAAA,EACF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAGjB,gBAAkC;AAAA;AAAA,EAGzB;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA,EAET,YAAY,SAAyB;AACnC,QAAI,CAAC,QAAQ,QAAQ;AACnB,YAAM,IAAI,MAAM,oBAAoB;AAAA,IAC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SAAS,WAAW,EAAE;AAAA,IACjC,SAAS,IAAI,KAAK,KAAK;AAAA,EACzB;AACF;","names":[]}
package/dist/index.mjs CHANGED
@@ -42,6 +42,10 @@ var AutoICD = class {
42
42
  icd10;
43
43
  /** Sub-resource for ICD-11 code lookup. */
44
44
  icd11;
45
+ /** Sub-resource for ICF code lookup and coding. */
46
+ icf;
47
+ /** Sub-resource for LOINC code lookup and coding. */
48
+ loinc;
45
49
  constructor(options) {
46
50
  if (!options.apiKey) {
47
51
  throw new Error("apiKey is required");
@@ -52,6 +56,8 @@ var AutoICD = class {
52
56
  this._fetch = options.fetch ?? globalThis.fetch;
53
57
  this.icd10 = new ICD10Codes(this);
54
58
  this.icd11 = new ICD11Codes(this);
59
+ this.icf = new ICFCodes(this);
60
+ this.loinc = new LOINCCodes(this);
55
61
  }
56
62
  // ─── Public Methods ───
57
63
  /**
@@ -70,7 +76,11 @@ var AutoICD = class {
70
76
  text,
71
77
  top_k: options?.topK,
72
78
  include_negated: options?.includeNegated,
73
- output_system: options?.outputSystem
79
+ output_system: options?.outputSystem,
80
+ include_icf: options?.includeIcf,
81
+ include_icd11: options?.includeIcd11,
82
+ include_snomed: options?.includeSnomed,
83
+ include_umls: options?.includeUmls
74
84
  });
75
85
  }
76
86
  /**
@@ -86,6 +96,47 @@ var AutoICD = class {
86
96
  async anonymize(text) {
87
97
  return this.post("/api/v1/anonymize", { text });
88
98
  }
99
+ /**
100
+ * Audit a chart for coding gaps, RADV risk, specificity, denial flags, and
101
+ * a reconciled problem list. Every finding carries extractive evidence spans.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * const audit = await autoicd.audit({
106
+ * text: "68yo M, type 2 diabetes, chronic systolic heart failure on furosemide.",
107
+ * codes: [{ code: "E11.9", kind: "icd10" }],
108
+ * capabilities: ["hcc", "radv", "specificity", "denial", "problem_list"],
109
+ * context: { patient: { coverage: "medicare_advantage" } },
110
+ * });
111
+ * console.log(audit.totals.estimated_revenue_recovery);
112
+ * for (const m of audit.missed) {
113
+ * console.log(`${m.code} ${m.hcc_category} $${m.estimated_revenue}`);
114
+ * }
115
+ * ```
116
+ */
117
+ async audit(request) {
118
+ return this.post("/api/v1/audit", request);
119
+ }
120
+ /**
121
+ * Translate a code between healthcare coding systems. Maps a source code
122
+ * (ICD-10, ICD-11, SNOMED, UMLS, ICF) to equivalents in requested target
123
+ * systems. Omit `to` to get every system reachable from the source.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * const result = await autoicd.translate({
128
+ * from: { code: "E11.9", system: "icd10" },
129
+ * });
130
+ * console.log(result.mappings.icd11);
131
+ * console.log(result.mappings.snomed);
132
+ * ```
133
+ */
134
+ async translate(request) {
135
+ return this.post(
136
+ "/api/v1/translate",
137
+ request
138
+ );
139
+ }
89
140
  // ─── Internal HTTP ───
90
141
  /** @internal */
91
142
  async get(path) {
@@ -212,6 +263,124 @@ var ICD11Codes = class {
212
263
  return this.client.get(`/api/v1/icd11/codes/${encodeURIComponent(code)}`);
213
264
  }
214
265
  };
266
+ var ICFCodes = class {
267
+ constructor(client) {
268
+ this.client = client;
269
+ }
270
+ /**
271
+ * Code clinical text to ICF codes.
272
+ *
273
+ * @example
274
+ * ```ts
275
+ * const result = await autoicd.icf.code("Patient has difficulty walking");
276
+ * for (const entity of result.results) {
277
+ * console.log(entity.entity_text, entity.codes[0]?.code);
278
+ * }
279
+ * ```
280
+ */
281
+ async code(text, options) {
282
+ return this.client.post("/api/v1/icf/code", {
283
+ text,
284
+ top_k: options?.topK
285
+ });
286
+ }
287
+ /**
288
+ * Get full details for a single ICF code, including definition,
289
+ * hierarchy (parent/children), inclusions, exclusions, and index terms.
290
+ *
291
+ * @example
292
+ * ```ts
293
+ * const detail = await autoicd.icf.lookup("b280");
294
+ * console.log(detail.title);
295
+ * console.log(detail.definition);
296
+ * console.log(detail.children.length);
297
+ * ```
298
+ */
299
+ async lookup(code) {
300
+ return this.client.get(`/api/v1/icf/codes/${encodeURIComponent(code)}`);
301
+ }
302
+ /**
303
+ * Search ICF codes by description.
304
+ *
305
+ * @example
306
+ * ```ts
307
+ * const results = await autoicd.icf.search("pain");
308
+ * ```
309
+ */
310
+ async search(query, options) {
311
+ const params = new URLSearchParams({ q: query });
312
+ if (options?.limit !== void 0) params.set("limit", String(options.limit));
313
+ if (options?.offset !== void 0) params.set("offset", String(options.offset));
314
+ return this.client.get(`/api/v1/icf/codes/search?${params}`);
315
+ }
316
+ /**
317
+ * Get the ICF Core Set for an ICD-10 diagnosis code.
318
+ *
319
+ * @example
320
+ * ```ts
321
+ * const coreSet = await autoicd.icf.coreSet("M54.5");
322
+ * console.log(coreSet.condition_name);
323
+ * console.log(coreSet.brief.length, "brief codes");
324
+ * console.log(coreSet.comprehensive.length, "comprehensive codes");
325
+ * ```
326
+ */
327
+ async coreSet(icd10Code) {
328
+ return this.client.get(`/api/v1/icf/core-set/${encodeURIComponent(icd10Code)}`);
329
+ }
330
+ };
331
+ var LOINCCodes = class {
332
+ constructor(client) {
333
+ this.client = client;
334
+ }
335
+ /**
336
+ * Code clinical text to LOINC codes.
337
+ *
338
+ * Extracts lab tests, imaging orders, and clinical observations from
339
+ * free text and matches to LOINC codes using NER + SapBERT embeddings.
340
+ *
341
+ * @example
342
+ * ```ts
343
+ * const result = await autoicd.loinc.code("Order CBC, glucose, and TSH");
344
+ * for (const entity of result.results) {
345
+ * console.log(entity.entity_text, entity.codes[0]?.code);
346
+ * }
347
+ * ```
348
+ */
349
+ async code(text, options) {
350
+ return this.client.post("/api/v1/loinc/code", {
351
+ text,
352
+ top_k: options?.topK
353
+ });
354
+ }
355
+ /**
356
+ * Get full details for a single LOINC code, including 6-axis classification,
357
+ * definition, related names, and cross-references.
358
+ *
359
+ * @example
360
+ * ```ts
361
+ * const detail = await autoicd.loinc.lookup("2345-7");
362
+ * console.log(detail.long_common_name);
363
+ * console.log(detail.component, detail.system);
364
+ * ```
365
+ */
366
+ async lookup(code) {
367
+ return this.client.get(`/api/v1/loinc/codes/${encodeURIComponent(code)}`);
368
+ }
369
+ /**
370
+ * Search LOINC codes by description.
371
+ *
372
+ * @example
373
+ * ```ts
374
+ * const results = await autoicd.loinc.search("glucose");
375
+ * ```
376
+ */
377
+ async search(query, options) {
378
+ const params = new URLSearchParams({ q: query });
379
+ if (options?.limit !== void 0) params.set("limit", String(options.limit));
380
+ if (options?.offset !== void 0) params.set("offset", String(options.offset));
381
+ return this.client.get(`/api/v1/loinc/codes/search?${params}`);
382
+ }
383
+ };
215
384
  function parseRateLimit(headers) {
216
385
  const limit = headers.get("X-RateLimit-Limit");
217
386
  const remaining = headers.get("X-RateLimit-Remaining");
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/client.ts"],"sourcesContent":["import type { RateLimit } from \"./types.js\";\n\nexport class AutoICDError extends Error {\n readonly status: number;\n\n constructor(status: number, message: string) {\n super(message);\n this.name = \"AutoICDError\";\n this.status = status;\n }\n}\n\nexport class AuthenticationError extends AutoICDError {\n constructor(message = \"Invalid API key\") {\n super(401, message);\n this.name = \"AuthenticationError\";\n }\n}\n\nexport class RateLimitError extends AutoICDError {\n readonly rateLimit: RateLimit;\n\n constructor(message: string, rateLimit: RateLimit) {\n super(429, message);\n this.name = \"RateLimitError\";\n this.rateLimit = rateLimit;\n }\n}\n\nexport class NotFoundError extends AutoICDError {\n constructor(message = \"Resource not found\") {\n super(404, message);\n this.name = \"NotFoundError\";\n }\n}\n","import type {\n AutoICDOptions,\n CodeOptions,\n CodingResponse,\n SearchOptions,\n CodeSearchResponse,\n CodeDetail,\n CodeDetailFull,\n AnonymizeResponse,\n RateLimit,\n ErrorBody,\n ICD11CodeSearchResponse,\n ICD11CodeDetailFull,\n} from \"./types.js\";\nimport {\n AutoICDError,\n AuthenticationError,\n RateLimitError,\n NotFoundError,\n} from \"./errors.js\";\n\nconst DEFAULT_BASE_URL = \"https://autoicdapi.com\";\nconst DEFAULT_TIMEOUT = 30_000;\n\nexport class AutoICD {\n private readonly apiKey: string;\n private readonly baseURL: string;\n private readonly timeout: number;\n private readonly _fetch: typeof globalThis.fetch;\n\n /** Rate limit info from the most recent API response. */\n lastRateLimit: RateLimit | null = null;\n\n /** Sub-resource for ICD-10 code lookup. */\n readonly icd10: ICD10Codes;\n\n /** Sub-resource for ICD-11 code lookup. */\n readonly icd11: ICD11Codes;\n\n constructor(options: AutoICDOptions) {\n if (!options.apiKey) {\n throw new Error(\"apiKey is required\");\n }\n this.apiKey = options.apiKey;\n this.baseURL = (options.baseURL ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT;\n this._fetch = options.fetch ?? globalThis.fetch;\n this.icd10 = new ICD10Codes(this);\n this.icd11 = new ICD11Codes(this);\n }\n\n // ─── Public Methods ───\n\n /**\n * Code clinical text to ICD-10-CM diagnoses.\n *\n * @example\n * ```ts\n * const result = await autoicd.code(\"Patient has type 2 diabetes\");\n * for (const entity of result.entities) {\n * console.log(entity.entity_text, entity.codes[0]?.code);\n * }\n * ```\n */\n async code(text: string, options?: CodeOptions): Promise<CodingResponse> {\n return this.post<CodingResponse>(\"/api/v1/code\", {\n text,\n top_k: options?.topK,\n include_negated: options?.includeNegated,\n output_system: options?.outputSystem,\n });\n }\n\n /**\n * Anonymize PHI/PII in clinical text.\n *\n * @example\n * ```ts\n * const result = await autoicd.anonymize(\"John Smith, DOB 01/15/1980, has COPD\");\n * console.log(result.anonymized_text);\n * // \"[NAME], DOB [DATE], has COPD\"\n * ```\n */\n async anonymize(text: string): Promise<AnonymizeResponse> {\n return this.post<AnonymizeResponse>(\"/api/v1/anonymize\", { text });\n }\n\n // ─── Internal HTTP ───\n\n /** @internal */\n async get<T>(path: string): Promise<T> {\n return this.request<T>(\"GET\", path);\n }\n\n /** @internal */\n async post<T>(path: string, body: Record<string, unknown>): Promise<T> {\n // Strip undefined values so the API receives clean JSON\n const clean = Object.fromEntries(\n Object.entries(body).filter(([, v]) => v !== undefined)\n );\n return this.request<T>(\"POST\", path, clean);\n }\n\n private async request<T>(\n method: string,\n path: string,\n body?: Record<string, unknown>\n ): Promise<T> {\n const url = `${this.baseURL}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeout);\n\n try {\n const res = await this._fetch(url, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n },\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n // Parse rate limit headers\n this.lastRateLimit = parseRateLimit(res.headers);\n\n if (res.ok) {\n return (await res.json()) as T;\n }\n\n // Error responses\n const errorBody = (await res.json().catch(() => null)) as ErrorBody | null;\n const message = errorBody?.error ?? `HTTP ${res.status}`;\n\n if (res.status === 401) throw new AuthenticationError(message);\n if (res.status === 404) throw new NotFoundError(message);\n if (res.status === 429) {\n throw new RateLimitError(\n message,\n this.lastRateLimit ?? {\n limit: errorBody?.limit ?? 0,\n remaining: 0,\n resetAt: errorBody?.resetAt ? new Date(errorBody.resetAt) : new Date(),\n }\n );\n }\n\n throw new AutoICDError(res.status, message);\n } catch (err) {\n if (err instanceof AutoICDError) throw err;\n if (err instanceof DOMException && err.name === \"AbortError\") {\n throw new AutoICDError(0, `Request timed out after ${this.timeout}ms`);\n }\n throw err;\n } finally {\n clearTimeout(timer);\n }\n }\n}\n\n// ─── ICD-10 Codes Sub-resource ───\n\nclass ICD10Codes {\n constructor(private readonly client: AutoICD) {}\n\n /**\n * Search ICD-10 codes by description.\n *\n * @example\n * ```ts\n * const results = await autoicd.icd10.search(\"diabetes mellitus\");\n * ```\n */\n async search(query: string, options?: SearchOptions): Promise<CodeSearchResponse> {\n const params = new URLSearchParams({ q: query });\n if (options?.limit !== undefined) params.set(\"limit\", String(options.limit));\n if (options?.offset !== undefined) params.set(\"offset\", String(options.offset));\n return this.client.get<CodeSearchResponse>(`/api/v1/icd10/codes/search?${params}`);\n }\n\n /**\n * Get comprehensive details for a single ICD-10 code, including synonyms,\n * hierarchy (parent/children), chapter, and SNOMED CT / UMLS cross-references.\n *\n * @example\n * ```ts\n * const detail = await autoicd.icd10.get(\"E11.9\");\n * console.log(detail.long_description);\n * console.log(detail.synonyms.snomed); // SNOMED CT synonyms\n * console.log(detail.chapter?.title); // \"Endocrine, Nutritional and Metabolic Diseases\"\n * console.log(detail.children.length); // child codes\n * ```\n */\n async get(code: string): Promise<CodeDetailFull> {\n return this.client.get<CodeDetailFull>(`/api/v1/icd10/codes/${encodeURIComponent(code)}`);\n }\n\n}\n\n// ─── ICD-11 Codes Sub-resource ───\n\nclass ICD11Codes {\n constructor(private readonly client: AutoICD) {}\n\n /**\n * Search ICD-11 codes by description.\n *\n * @example\n * ```ts\n * const results = await autoicd.icd11.search(\"diabetes mellitus\");\n * ```\n */\n async search(query: string, options?: SearchOptions): Promise<ICD11CodeSearchResponse> {\n const params = new URLSearchParams({ q: query });\n if (options?.limit !== undefined) params.set(\"limit\", String(options.limit));\n if (options?.offset !== undefined) params.set(\"offset\", String(options.offset));\n return this.client.get<ICD11CodeSearchResponse>(`/api/v1/icd11/codes/search?${params}`);\n }\n\n /**\n * Get comprehensive details for a single ICD-11 code, including synonyms,\n * hierarchy (parent/children), chapter, and ICD-10 crosswalk mappings.\n *\n * @example\n * ```ts\n * const detail = await autoicd.icd11.get(\"5A11\");\n * console.log(detail.long_description);\n * console.log(detail.chapter?.title);\n * console.log(detail.icd10_mappings);\n * ```\n */\n async get(code: string): Promise<ICD11CodeDetailFull> {\n return this.client.get<ICD11CodeDetailFull>(`/api/v1/icd11/codes/${encodeURIComponent(code)}`);\n }\n}\n\n// ─── Helpers ───\n\nfunction parseRateLimit(headers: Headers): RateLimit | null {\n const limit = headers.get(\"X-RateLimit-Limit\");\n const remaining = headers.get(\"X-RateLimit-Remaining\");\n const reset = headers.get(\"X-RateLimit-Reset\");\n\n if (!limit || !remaining || !reset) return null;\n\n return {\n limit: parseInt(limit, 10),\n remaining: parseInt(remaining, 10),\n resetAt: new Date(reset),\n };\n}\n"],"mappings":";AAEO,IAA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F;AAEF;AAIA,IAAM,aAAN,MAAiB;AAAA,EACf,YAA6B,QAAiB;AAAjB;AAAA,EAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU/C,MAAM,OAAO,OAAe,SAA2D;AACrF,UAAM,SAAS,IAAI,gBAAgB,EAAE,GAAG,MAAM,CAAC;AAC/C,QAAI,SAAS,UAAU,OAAW,QAAO,IAAI,SAAS,OAAO,QAAQ,KAAK,CAAC;AAC3E,QAAI,SAAS,WAAW,OAAW,QAAO,IAAI,UAAU,OAAO,QAAQ,MAAM,CAAC;AAC9E,WAAO,KAAK,OAAO,IAA6B,8BAA8B,MAAM,EAAE;AAAA,EACxF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,MAAM,IAAI,MAA4C;AACpD,WAAO,KAAK,OAAO,IAAyB,uBAAuB,mBAAmB,IAAI,CAAC,EAAE;AAAA,EAC/F;AACF;AAIA,SAAS,eAAe,SAAoC;AAC1D,QAAM,QAAQ,QAAQ,IAAI,mBAAmB;AAC7C,QAAM,YAAY,QAAQ,IAAI,uBAAuB;AACrD,QAAM,QAAQ,QAAQ,IAAI,mBAAmB;AAE7C,MAAI,CAAC,SAAS,CAAC,aAAa,CAAC,MAAO,QAAO;AAE3C,SAAO;AAAA,IACL,OAAO,SAAS,OAAO,EAAE;AAAA,IACzB,WAAW,SAAS,WAAW,EAAE;AAAA,IACjC,SAAS,IAAI,KAAK,KAAK;AAAA,EACzB;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/errors.ts","../src/client.ts"],"sourcesContent":["import type { RateLimit } from \"./types.js\";\n\nexport class AutoICDError extends Error {\n readonly status: number;\n\n constructor(status: number, message: string) {\n super(message);\n this.name = \"AutoICDError\";\n this.status = status;\n }\n}\n\nexport class AuthenticationError extends AutoICDError {\n constructor(message = \"Invalid API key\") {\n super(401, message);\n this.name = \"AuthenticationError\";\n }\n}\n\nexport class RateLimitError extends AutoICDError {\n readonly rateLimit: RateLimit;\n\n constructor(message: string, rateLimit: RateLimit) {\n super(429, message);\n this.name = \"RateLimitError\";\n this.rateLimit = rateLimit;\n }\n}\n\nexport class NotFoundError extends AutoICDError {\n constructor(message = \"Resource not found\") {\n super(404, message);\n this.name = \"NotFoundError\";\n }\n}\n","import type {\n AutoICDOptions,\n CodeOptions,\n CodingResponse,\n SearchOptions,\n CodeSearchResponse,\n CodeDetail,\n CodeDetailFull,\n AnonymizeResponse,\n RateLimit,\n ErrorBody,\n ICD11CodeSearchResponse,\n ICD11CodeDetailFull,\n ICFCodingResponse,\n ICFCodeDetail,\n ICFSearchResponse,\n ICFCoreSetResult,\n LOINCCodeDetail,\n LOINCSearchResponse,\n LOINCCodingResponse,\n AuditRequest,\n AuditResponse,\n TranslateRequest,\n TranslateResponse,\n} from \"./types.js\";\nimport {\n AutoICDError,\n AuthenticationError,\n RateLimitError,\n NotFoundError,\n} from \"./errors.js\";\n\nconst DEFAULT_BASE_URL = \"https://autoicdapi.com\";\nconst DEFAULT_TIMEOUT = 30_000;\n\nexport class AutoICD {\n private readonly apiKey: string;\n private readonly baseURL: string;\n private readonly timeout: number;\n private readonly _fetch: typeof globalThis.fetch;\n\n /** Rate limit info from the most recent API response. */\n lastRateLimit: RateLimit | null = null;\n\n /** Sub-resource for ICD-10 code lookup. */\n readonly icd10: ICD10Codes;\n\n /** Sub-resource for ICD-11 code lookup. */\n readonly icd11: ICD11Codes;\n\n /** Sub-resource for ICF code lookup and coding. */\n readonly icf: ICFCodes;\n\n /** Sub-resource for LOINC code lookup and coding. */\n readonly loinc: LOINCCodes;\n\n constructor(options: AutoICDOptions) {\n if (!options.apiKey) {\n throw new Error(\"apiKey is required\");\n }\n this.apiKey = options.apiKey;\n this.baseURL = (options.baseURL ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT;\n this._fetch = options.fetch ?? globalThis.fetch;\n this.icd10 = new ICD10Codes(this);\n this.icd11 = new ICD11Codes(this);\n this.icf = new ICFCodes(this);\n this.loinc = new LOINCCodes(this);\n }\n\n // ─── Public Methods ───\n\n /**\n * Code clinical text to ICD-10-CM diagnoses.\n *\n * @example\n * ```ts\n * const result = await autoicd.code(\"Patient has type 2 diabetes\");\n * for (const entity of result.entities) {\n * console.log(entity.entity_text, entity.codes[0]?.code);\n * }\n * ```\n */\n async code(text: string, options?: CodeOptions): Promise<CodingResponse> {\n return this.post<CodingResponse>(\"/api/v1/code\", {\n text,\n top_k: options?.topK,\n include_negated: options?.includeNegated,\n output_system: options?.outputSystem,\n include_icf: options?.includeIcf,\n include_icd11: options?.includeIcd11,\n include_snomed: options?.includeSnomed,\n include_umls: options?.includeUmls,\n });\n }\n\n /**\n * Anonymize PHI/PII in clinical text.\n *\n * @example\n * ```ts\n * const result = await autoicd.anonymize(\"John Smith, DOB 01/15/1980, has COPD\");\n * console.log(result.anonymized_text);\n * // \"[NAME], DOB [DATE], has COPD\"\n * ```\n */\n async anonymize(text: string): Promise<AnonymizeResponse> {\n return this.post<AnonymizeResponse>(\"/api/v1/anonymize\", { text });\n }\n\n /**\n * Audit a chart for coding gaps, RADV risk, specificity, denial flags, and\n * a reconciled problem list. Every finding carries extractive evidence spans.\n *\n * @example\n * ```ts\n * const audit = await autoicd.audit({\n * text: \"68yo M, type 2 diabetes, chronic systolic heart failure on furosemide.\",\n * codes: [{ code: \"E11.9\", kind: \"icd10\" }],\n * capabilities: [\"hcc\", \"radv\", \"specificity\", \"denial\", \"problem_list\"],\n * context: { patient: { coverage: \"medicare_advantage\" } },\n * });\n * console.log(audit.totals.estimated_revenue_recovery);\n * for (const m of audit.missed) {\n * console.log(`${m.code} ${m.hcc_category} $${m.estimated_revenue}`);\n * }\n * ```\n */\n async audit(request: AuditRequest): Promise<AuditResponse> {\n return this.post<AuditResponse>(\"/api/v1/audit\", request as unknown as Record<string, unknown>);\n }\n\n /**\n * Translate a code between healthcare coding systems. Maps a source code\n * (ICD-10, ICD-11, SNOMED, UMLS, ICF) to equivalents in requested target\n * systems. Omit `to` to get every system reachable from the source.\n *\n * @example\n * ```ts\n * const result = await autoicd.translate({\n * from: { code: \"E11.9\", system: \"icd10\" },\n * });\n * console.log(result.mappings.icd11);\n * console.log(result.mappings.snomed);\n * ```\n */\n async translate(request: TranslateRequest): Promise<TranslateResponse> {\n return this.post<TranslateResponse>(\n \"/api/v1/translate\",\n request as unknown as Record<string, unknown>,\n );\n }\n\n // ─── Internal HTTP ───\n\n /** @internal */\n async get<T>(path: string): Promise<T> {\n return this.request<T>(\"GET\", path);\n }\n\n /** @internal */\n async post<T>(path: string, body: Record<string, unknown>): Promise<T> {\n // Strip undefined values so the API receives clean JSON\n const clean = Object.fromEntries(\n Object.entries(body).filter(([, v]) => v !== undefined)\n );\n return this.request<T>(\"POST\", path, clean);\n }\n\n private async request<T>(\n method: string,\n path: string,\n body?: Record<string, unknown>\n ): Promise<T> {\n const url = `${this.baseURL}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeout);\n\n try {\n const res = await this._fetch(url, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n },\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n // Parse rate limit headers\n this.lastRateLimit = parseRateLimit(res.headers);\n\n if (res.ok) {\n return (await res.json()) as T;\n }\n\n // Error responses\n const errorBody = (await res.json().catch(() => null)) as ErrorBody | null;\n const message = errorBody?.error ?? `HTTP ${res.status}`;\n\n if (res.status === 401) throw new AuthenticationError(message);\n if (res.status === 404) throw new NotFoundError(message);\n if (res.status === 429) {\n throw new RateLimitError(\n message,\n this.lastRateLimit ?? {\n limit: errorBody?.limit ?? 0,\n remaining: 0,\n resetAt: errorBody?.resetAt ? new Date(errorBody.resetAt) : new Date(),\n }\n );\n }\n\n throw new AutoICDError(res.status, message);\n } catch (err) {\n if (err instanceof AutoICDError) throw err;\n if (err instanceof DOMException && err.name === \"AbortError\") {\n throw new AutoICDError(0, `Request timed out after ${this.timeout}ms`);\n }\n throw err;\n } finally {\n clearTimeout(timer);\n }\n }\n}\n\n// ─── ICD-10 Codes Sub-resource ───\n\nclass ICD10Codes {\n constructor(private readonly client: AutoICD) {}\n\n /**\n * Search ICD-10 codes by description.\n *\n * @example\n * ```ts\n * const results = await autoicd.icd10.search(\"diabetes mellitus\");\n * ```\n */\n async search(query: string, options?: SearchOptions): Promise<CodeSearchResponse> {\n const params = new URLSearchParams({ q: query });\n if (options?.limit !== undefined) params.set(\"limit\", String(options.limit));\n if (options?.offset !== undefined) params.set(\"offset\", String(options.offset));\n return this.client.get<CodeSearchResponse>(`/api/v1/icd10/codes/search?${params}`);\n }\n\n /**\n * Get comprehensive details for a single ICD-10 code, including synonyms,\n * hierarchy (parent/children), chapter, and SNOMED CT / UMLS cross-references.\n *\n * @example\n * ```ts\n * const detail = await autoicd.icd10.get(\"E11.9\");\n * console.log(detail.long_description);\n * console.log(detail.synonyms.snomed); // SNOMED CT synonyms\n * console.log(detail.chapter?.title); // \"Endocrine, Nutritional and Metabolic Diseases\"\n * console.log(detail.children.length); // child codes\n * ```\n */\n async get(code: string): Promise<CodeDetailFull> {\n return this.client.get<CodeDetailFull>(`/api/v1/icd10/codes/${encodeURIComponent(code)}`);\n }\n\n}\n\n// ─── ICD-11 Codes Sub-resource ───\n\nclass ICD11Codes {\n constructor(private readonly client: AutoICD) {}\n\n /**\n * Search ICD-11 codes by description.\n *\n * @example\n * ```ts\n * const results = await autoicd.icd11.search(\"diabetes mellitus\");\n * ```\n */\n async search(query: string, options?: SearchOptions): Promise<ICD11CodeSearchResponse> {\n const params = new URLSearchParams({ q: query });\n if (options?.limit !== undefined) params.set(\"limit\", String(options.limit));\n if (options?.offset !== undefined) params.set(\"offset\", String(options.offset));\n return this.client.get<ICD11CodeSearchResponse>(`/api/v1/icd11/codes/search?${params}`);\n }\n\n /**\n * Get comprehensive details for a single ICD-11 code, including synonyms,\n * hierarchy (parent/children), chapter, and ICD-10 crosswalk mappings.\n *\n * @example\n * ```ts\n * const detail = await autoicd.icd11.get(\"5A11\");\n * console.log(detail.long_description);\n * console.log(detail.chapter?.title);\n * console.log(detail.icd10_mappings);\n * ```\n */\n async get(code: string): Promise<ICD11CodeDetailFull> {\n return this.client.get<ICD11CodeDetailFull>(`/api/v1/icd11/codes/${encodeURIComponent(code)}`);\n }\n}\n\n// ─── ICF Codes Sub-resource ───\n\nclass ICFCodes {\n constructor(private readonly client: AutoICD) {}\n\n /**\n * Code clinical text to ICF codes.\n *\n * @example\n * ```ts\n * const result = await autoicd.icf.code(\"Patient has difficulty walking\");\n * for (const entity of result.results) {\n * console.log(entity.entity_text, entity.codes[0]?.code);\n * }\n * ```\n */\n async code(text: string, options?: { topK?: number }): Promise<ICFCodingResponse> {\n return this.client.post<ICFCodingResponse>(\"/api/v1/icf/code\", {\n text,\n top_k: options?.topK,\n });\n }\n\n /**\n * Get full details for a single ICF code, including definition,\n * hierarchy (parent/children), inclusions, exclusions, and index terms.\n *\n * @example\n * ```ts\n * const detail = await autoicd.icf.lookup(\"b280\");\n * console.log(detail.title);\n * console.log(detail.definition);\n * console.log(detail.children.length);\n * ```\n */\n async lookup(code: string): Promise<ICFCodeDetail> {\n return this.client.get<ICFCodeDetail>(`/api/v1/icf/codes/${encodeURIComponent(code)}`);\n }\n\n /**\n * Search ICF codes by description.\n *\n * @example\n * ```ts\n * const results = await autoicd.icf.search(\"pain\");\n * ```\n */\n async search(query: string, options?: SearchOptions): Promise<ICFSearchResponse> {\n const params = new URLSearchParams({ q: query });\n if (options?.limit !== undefined) params.set(\"limit\", String(options.limit));\n if (options?.offset !== undefined) params.set(\"offset\", String(options.offset));\n return this.client.get<ICFSearchResponse>(`/api/v1/icf/codes/search?${params}`);\n }\n\n /**\n * Get the ICF Core Set for an ICD-10 diagnosis code.\n *\n * @example\n * ```ts\n * const coreSet = await autoicd.icf.coreSet(\"M54.5\");\n * console.log(coreSet.condition_name);\n * console.log(coreSet.brief.length, \"brief codes\");\n * console.log(coreSet.comprehensive.length, \"comprehensive codes\");\n * ```\n */\n async coreSet(icd10Code: string): Promise<ICFCoreSetResult> {\n return this.client.get<ICFCoreSetResult>(`/api/v1/icf/core-set/${encodeURIComponent(icd10Code)}`);\n }\n}\n\n// ─── LOINC Codes Sub-resource ───\n\nclass LOINCCodes {\n constructor(private readonly client: AutoICD) {}\n\n /**\n * Code clinical text to LOINC codes.\n *\n * Extracts lab tests, imaging orders, and clinical observations from\n * free text and matches to LOINC codes using NER + SapBERT embeddings.\n *\n * @example\n * ```ts\n * const result = await autoicd.loinc.code(\"Order CBC, glucose, and TSH\");\n * for (const entity of result.results) {\n * console.log(entity.entity_text, entity.codes[0]?.code);\n * }\n * ```\n */\n async code(text: string, options?: { topK?: number }): Promise<LOINCCodingResponse> {\n return this.client.post<LOINCCodingResponse>(\"/api/v1/loinc/code\", {\n text,\n top_k: options?.topK,\n });\n }\n\n /**\n * Get full details for a single LOINC code, including 6-axis classification,\n * definition, related names, and cross-references.\n *\n * @example\n * ```ts\n * const detail = await autoicd.loinc.lookup(\"2345-7\");\n * console.log(detail.long_common_name);\n * console.log(detail.component, detail.system);\n * ```\n */\n async lookup(code: string): Promise<LOINCCodeDetail> {\n return this.client.get<LOINCCodeDetail>(`/api/v1/loinc/codes/${encodeURIComponent(code)}`);\n }\n\n /**\n * Search LOINC codes by description.\n *\n * @example\n * ```ts\n * const results = await autoicd.loinc.search(\"glucose\");\n * ```\n */\n async search(query: string, options?: SearchOptions): Promise<LOINCSearchResponse> {\n const params = new URLSearchParams({ q: query });\n if (options?.limit !== undefined) params.set(\"limit\", String(options.limit));\n if (options?.offset !== undefined) params.set(\"offset\", String(options.offset));\n return this.client.get<LOINCSearchResponse>(`/api/v1/loinc/codes/search?${params}`);\n }\n}\n\n// ─── Helpers ───\n\nfunction parseRateLimit(headers: Headers): RateLimit | null {\n const limit = headers.get(\"X-RateLimit-Limit\");\n const remaining = headers.get(\"X-RateLimit-Remaining\");\n const reset = headers.get(\"X-RateLimit-Reset\");\n\n if (!limit || !remaining || !reset) return null;\n\n return {\n limit: parseInt(limit, 10),\n remaining: parseInt(remaining, 10),\n resetAt: new Date(reset),\n };\n}\n"],"mappings":";AAEO,IAAM,eAAN,cAA2B,MAAM;AAAA,EAC7B;AAAA,EAET,YAAY,QAAgB,SAAiB;AAC3C,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AAEO,IAAM,sBAAN,cAAkC,aAAa;AAAA,EACpD,YAAY,UAAU,mBAAmB;AACvC,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,iBAAN,cAA6B,aAAa;AAAA,EACtC;AAAA,EAET,YAAY,SAAiB,WAAsB;AACjD,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AACZ,SAAK,YAAY;AAAA,EACnB;AACF;AAEO,IAAM,gBAAN,cAA4B,aAAa;AAAA,EAC9C,YAAY,UAAU,sBAAsB;AAC1C,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AAAA,EACd;AACF;;;ACFA,IAAM,mBAAmB;AACzB,IAAM,kBAAkB;AAEjB,IAAM,UAAN,MAAc;AAAA,EACF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAGjB,gBAAkC;AAAA;AAAA,EAGzB;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA,EAET,YAAY,SAAyB;AACnC,QAAI,CAAC,QAAQ,QAAQ;AACnB,YAAM,IAAI,MAAM,oBAAoB;AAAA,IACtC;AACA,SAAK,SAAS,QAAQ;AACtB,SAAK,WAAW,QAAQ,WAAW,kBAAkB,QAAQ,QAAQ,EAAE;AACvE,SAAK,UAAU,QAAQ,WAAW;AAClC,SAAK,SAAS,QAAQ,SAAS,WAAW;AAC1C,SAAK,QAAQ,IAAI,WAAW,IAAI;A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ical text to ICD-10-CM and ICD-11 diagnosis codes with AI-powered NLP. Automated medical coding, PHI de-identification, code search, and ICD-10/ICD-11 crosswalk for EHR, billing, and health-tech apps.",
3
+ "version": "0.8.0",
4
+ "description": "AI medical coding SDK — convert clinical text to ICD-10-CM and ICD-11 diagnosis codes with AI-powered NLP. Automated ICD-10 coding, PHI de-identification, code search, and ICD-10/ICD-11 crosswalk for EHR, billing, and health-tech apps.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
@@ -55,7 +55,13 @@
55
55
  "icd-11-api",
56
56
  "icd-10-icd-11-crosswalk",
57
57
  "autoicd",
58
- "autoicd-api"
58
+ "autoicd-api",
59
+ "ai-medical-coding",
60
+ "icd-ai",
61
+ "ai-icd-10",
62
+ "automated-diagnosis-coding",
63
+ "ai-medical-coder",
64
+ "computer-assisted-coding"
59
65
  ],
60
66
  "author": "AutoICD",
61
67
  "license": "MIT",