autoicd-js 0.9.0 → 0.10.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/README.md CHANGED
@@ -304,22 +304,22 @@ The SDK can code any of the 74,000+ ICD-10-CM codes. Here are some of the most c
304
304
 
305
305
  | Condition | ICD-10 Code | Description |
306
306
  |-----------|-------------|-------------|
307
- | [Hypertension](https://autoicdapi.com/icd10/condition/hypertension) | [I10](https://autoicdapi.com/icd10/I10) | Essential (primary) hypertension |
308
- | [Type 2 Diabetes](https://autoicdapi.com/icd10/condition/diabetes) | [E11.9](https://autoicdapi.com/icd10/E11.9) | Type 2 diabetes mellitus without complications |
309
- | [Depression](https://autoicdapi.com/icd10/condition/depression) | [F32.9](https://autoicdapi.com/icd10/F32.9) | Major depressive disorder, single episode, unspecified |
310
- | [Anxiety](https://autoicdapi.com/icd10/condition/anxiety) | [F41.1](https://autoicdapi.com/icd10/F41.1) | Generalized anxiety disorder |
311
- | [Low Back Pain](https://autoicdapi.com/icd10/condition/back-pain) | [M54.5](https://autoicdapi.com/icd10/M54.5) | Low back pain |
312
- | [COPD](https://autoicdapi.com/icd10/condition/copd) | [J44.9](https://autoicdapi.com/icd10/J44.9) | Chronic obstructive pulmonary disease, unspecified |
313
- | [Heart Failure](https://autoicdapi.com/icd10/condition/heart-failure) | [I50.9](https://autoicdapi.com/icd10/I50.9) | Heart failure, unspecified |
314
- | [UTI](https://autoicdapi.com/icd10/condition/urinary-tract-infection) | [N39.0](https://autoicdapi.com/icd10/N39.0) | Urinary tract infection, site not specified |
315
- | [Pneumonia](https://autoicdapi.com/icd10/condition/pneumonia) | [J18.9](https://autoicdapi.com/icd10/J18.9) | Pneumonia, unspecified organism |
316
- | [Atrial Fibrillation](https://autoicdapi.com/icd10/condition/atrial-fibrillation) | [I48.91](https://autoicdapi.com/icd10/I48.91) | Unspecified atrial fibrillation |
317
- | [Obesity](https://autoicdapi.com/icd10/condition/obesity) | [E66.01](https://autoicdapi.com/icd10/E66.01) | Morbid (severe) obesity due to excess calories |
318
- | [GERD](https://autoicdapi.com/icd10/condition/gerd) | [K21.9](https://autoicdapi.com/icd10/K21.9) | Gastro-esophageal reflux disease without esophagitis |
319
- | [Hypothyroidism](https://autoicdapi.com/icd10/condition/hypothyroidism) | [E03.9](https://autoicdapi.com/icd10/E03.9) | Hypothyroidism, unspecified |
320
- | [CKD](https://autoicdapi.com/icd10/condition/chronic-kidney-disease) | [N18.9](https://autoicdapi.com/icd10/N18.9) | Chronic kidney disease, unspecified |
321
-
322
- Browse all 74,000+ codes in the [ICD-10-CM Code Directory](https://autoicdapi.com/icd10) or find codes by [condition](https://autoicdapi.com/icd10/condition).
307
+ | [Hypertension](https://autoicdapi.com/reference/icd-10/condition/hypertension) | [I10](https://autoicdapi.com/reference/icd-10/I10) | Essential (primary) hypertension |
308
+ | [Type 2 Diabetes](https://autoicdapi.com/reference/icd-10/condition/diabetes) | [E11.9](https://autoicdapi.com/reference/icd-10/E11.9) | Type 2 diabetes mellitus without complications |
309
+ | [Depression](https://autoicdapi.com/reference/icd-10/condition/depression) | [F32.9](https://autoicdapi.com/reference/icd-10/F32.9) | Major depressive disorder, single episode, unspecified |
310
+ | [Anxiety](https://autoicdapi.com/reference/icd-10/condition/anxiety) | [F41.1](https://autoicdapi.com/reference/icd-10/F41.1) | Generalized anxiety disorder |
311
+ | [Low Back Pain](https://autoicdapi.com/reference/icd-10/condition/back-pain) | [M54.5](https://autoicdapi.com/reference/icd-10/M54.5) | Low back pain |
312
+ | [COPD](https://autoicdapi.com/reference/icd-10/condition/copd) | [J44.9](https://autoicdapi.com/reference/icd-10/J44.9) | Chronic obstructive pulmonary disease, unspecified |
313
+ | [Heart Failure](https://autoicdapi.com/reference/icd-10/condition/heart-failure) | [I50.9](https://autoicdapi.com/reference/icd-10/I50.9) | Heart failure, unspecified |
314
+ | [UTI](https://autoicdapi.com/reference/icd-10/condition/urinary-tract-infection) | [N39.0](https://autoicdapi.com/reference/icd-10/N39.0) | Urinary tract infection, site not specified |
315
+ | [Pneumonia](https://autoicdapi.com/reference/icd-10/condition/pneumonia) | [J18.9](https://autoicdapi.com/reference/icd-10/J18.9) | Pneumonia, unspecified organism |
316
+ | [Atrial Fibrillation](https://autoicdapi.com/reference/icd-10/condition/atrial-fibrillation) | [I48.91](https://autoicdapi.com/reference/icd-10/I48.91) | Unspecified atrial fibrillation |
317
+ | [Obesity](https://autoicdapi.com/reference/icd-10/condition/obesity) | [E66.01](https://autoicdapi.com/reference/icd-10/E66.01) | Morbid (severe) obesity due to excess calories |
318
+ | [GERD](https://autoicdapi.com/reference/icd-10/condition/gerd) | [K21.9](https://autoicdapi.com/reference/icd-10/K21.9) | Gastro-esophageal reflux disease without esophagitis |
319
+ | [Hypothyroidism](https://autoicdapi.com/reference/icd-10/condition/hypothyroidism) | [E03.9](https://autoicdapi.com/reference/icd-10/E03.9) | Hypothyroidism, unspecified |
320
+ | [CKD](https://autoicdapi.com/reference/icd-10/condition/chronic-kidney-disease) | [N18.9](https://autoicdapi.com/reference/icd-10/N18.9) | Chronic kidney disease, unspecified |
321
+
322
+ Browse all 74,000+ codes in the [ICD-10-CM Code Directory](https://autoicdapi.com/reference/icd-10) or find codes by [condition](https://autoicdapi.com/reference/icd-10/condition).
323
323
 
324
324
  ---
325
325
 
@@ -438,10 +438,10 @@ import type {
438
438
 
439
439
  - [AutoICD API](https://autoicdapi.com) — Homepage and API key management
440
440
  - [API Documentation](https://autoicdapi.com/docs) — Full REST API reference
441
- - [ICD-10-CM Code Directory](https://autoicdapi.com/icd10) — Browse all 74,000+ diagnosis codes
442
- - [ICD-11 Code Directory](https://autoicdapi.com/icd11) — Browse the WHO ICD-11 MMS hierarchy
441
+ - [ICD-10-CM Code Directory](https://autoicdapi.com/reference/icd-10) — Browse all 74,000+ diagnosis codes
442
+ - [ICD-11 Code Directory](https://autoicdapi.com/reference/icd-11) — Browse the WHO ICD-11 MMS hierarchy
443
443
  - [ICD-10 ↔ ICD-11 Crosswalk](https://autoicdapi.com/icd10-to-icd11) — Map codes between revisions
444
- - [ICD-10 Codes by Condition](https://autoicdapi.com/icd10/condition) — Find codes for common conditions
444
+ - [ICD-10 Codes by Condition](https://autoicdapi.com/reference/icd-10/condition) — Find codes for common conditions
445
445
  - [Python SDK](https://pypi.org/project/autoicd/) — `pip install autoicd`
446
446
  - [MCP Server](https://www.npmjs.com/package/autoicd-mcp) — For Claude Desktop, Cursor, VS Code
447
447
  - [SNOMED CT & UMLS Cross-References](https://autoicdapi.com/snomed-ct-umls) — Terminology mappings
package/dist/index.d.mts CHANGED
@@ -592,6 +592,29 @@ interface TranslateResponse {
592
592
  unsupported_targets: InteropSystem[];
593
593
  provider: string;
594
594
  }
595
+ /** Coding system slugs accepted by `client.reference.lookup`. */
596
+ type ReferenceSystem = "icd-10-cm" | "icd-11" | "icf" | "loinc";
597
+ /**
598
+ * Discriminated record returned by `GET /v1/reference/{system}/{code}`.
599
+ * `system` tags the variant; `record` carries the system-specific shape.
600
+ */
601
+ type ReferenceCodeRecord = {
602
+ system: "icd-10-cm";
603
+ code: string;
604
+ record: CodeDetailFull;
605
+ } | {
606
+ system: "icd-11";
607
+ code: string;
608
+ record: ICD11CodeDetailFull;
609
+ } | {
610
+ system: "icf";
611
+ code: string;
612
+ record: ICFCodeDetail;
613
+ } | {
614
+ system: "loinc";
615
+ code: string;
616
+ record: LOINCCodeDetail;
617
+ };
595
618
 
596
619
  declare class AutoICD {
597
620
  private readonly apiKey;
@@ -608,6 +631,8 @@ declare class AutoICD {
608
631
  readonly icf: ICFCodes;
609
632
  /** Sub-resource for LOINC code lookup and coding. */
610
633
  readonly loinc: LOINCCodes;
634
+ /** Unified cross-system reference lookup. */
635
+ readonly reference: ReferenceCodes;
611
636
  constructor(options: AutoICDOptions);
612
637
  /**
613
638
  * Code clinical text to ICD-10-CM diagnoses.
@@ -805,6 +830,26 @@ declare class LOINCCodes {
805
830
  */
806
831
  search(query: string, options?: SearchOptions): Promise<LOINCSearchResponse>;
807
832
  }
833
+ declare class ReferenceCodes {
834
+ private readonly client;
835
+ constructor(client: AutoICD);
836
+ /**
837
+ * Look up canonical reference data for a code in any supported coding system.
838
+ *
839
+ * Supersedes the per-system getters (`icd10.get`, `icd11.get`, `icf.lookup`,
840
+ * `loinc.lookup`), which remain available but emit `Deprecation` and `Sunset`
841
+ * response headers.
842
+ *
843
+ * @example
844
+ * ```ts
845
+ * const result = await autoicd.reference.lookup("icd-10-cm", "I50.23");
846
+ * if (result.system === "icd-10-cm") {
847
+ * console.log(result.record.long_description);
848
+ * }
849
+ * ```
850
+ */
851
+ lookup(system: ReferenceSystem, code: string): Promise<ReferenceCodeRecord>;
852
+ }
808
853
 
809
854
  declare class AutoICDError extends Error {
810
855
  readonly status: number;
@@ -821,4 +866,4 @@ declare class NotFoundError extends AutoICDError {
821
866
  constructor(message?: string);
822
867
  }
823
868
 
824
- export { type AnonymizeResponse, type AuditCapability, type AuditCode, type AuditContext, type AuditDocument, type AuditRequest, type AuditResponse, type AuditTotals, AuthenticationError, AutoICD, AutoICDError, type AutoICDOptions, type ChapterInfo, type CodeDetail, type CodeDetailFull, type CodeMatch, type CodeOptions, type CodeSearchResponse, type CodingEntity, type CodingResponse, type ConfirmedCode, type CrosswalkMapping, type DenialRisk, type EvidenceSpan, type ICD11ChapterInfo, type ICD11CodeDetail, type ICD11CodeDetailFull, type ICD11CodeSearchResponse, type ICD11CodeSearchResult, type ICFCodeDetail, type ICFCodeResult, type ICFCodeSummary, type ICFCodingEntity, type ICFComponent, type ICFCoreSetResult, type ICFCrossReference, type ICFSearchResponse, type InteropSystem, type LOINCCodeDetail, type LOINCCodeResult, type LOINCCodeSummary, type LOINCCodingEntity, type LOINCCodingResponse, type LOINCSearchResponse, type MissedCode, NotFoundError, type PIIEntity, type ProblemListEntry, type RateLimit, RateLimitError, type RatesUsed, type SearchOptions, type SpecificityUpgrade, type TranslateMapping, type TranslateRequest, type TranslateResponse, type TranslateSource, type UnsupportedCode, type UpgradeHint };
869
+ export { type AnonymizeResponse, type AuditCapability, type AuditCode, type AuditContext, type AuditDocument, type AuditRequest, type AuditResponse, type AuditTotals, AuthenticationError, AutoICD, AutoICDError, type AutoICDOptions, type ChapterInfo, type CodeDetail, type CodeDetailFull, type CodeMatch, type CodeOptions, type CodeSearchResponse, type CodingEntity, type CodingResponse, type ConfirmedCode, type CrosswalkMapping, type DenialRisk, type EvidenceSpan, type ICD11ChapterInfo, type ICD11CodeDetail, type ICD11CodeDetailFull, type ICD11CodeSearchResponse, type ICD11CodeSearchResult, type ICFCodeDetail, type ICFCodeResult, type ICFCodeSummary, type ICFCodingEntity, type ICFComponent, type ICFCoreSetResult, type ICFCrossReference, type ICFSearchResponse, type InteropSystem, type LOINCCodeDetail, type LOINCCodeResult, type LOINCCodeSummary, type LOINCCodingEntity, type LOINCCodingResponse, type LOINCSearchResponse, type MissedCode, NotFoundError, type PIIEntity, type ProblemListEntry, type RateLimit, RateLimitError, type RatesUsed, type ReferenceCodeRecord, type ReferenceSystem, type SearchOptions, type SpecificityUpgrade, type TranslateMapping, type TranslateRequest, type TranslateResponse, type TranslateSource, type UnsupportedCode, type UpgradeHint };
package/dist/index.d.ts CHANGED
@@ -592,6 +592,29 @@ interface TranslateResponse {
592
592
  unsupported_targets: InteropSystem[];
593
593
  provider: string;
594
594
  }
595
+ /** Coding system slugs accepted by `client.reference.lookup`. */
596
+ type ReferenceSystem = "icd-10-cm" | "icd-11" | "icf" | "loinc";
597
+ /**
598
+ * Discriminated record returned by `GET /v1/reference/{system}/{code}`.
599
+ * `system` tags the variant; `record` carries the system-specific shape.
600
+ */
601
+ type ReferenceCodeRecord = {
602
+ system: "icd-10-cm";
603
+ code: string;
604
+ record: CodeDetailFull;
605
+ } | {
606
+ system: "icd-11";
607
+ code: string;
608
+ record: ICD11CodeDetailFull;
609
+ } | {
610
+ system: "icf";
611
+ code: string;
612
+ record: ICFCodeDetail;
613
+ } | {
614
+ system: "loinc";
615
+ code: string;
616
+ record: LOINCCodeDetail;
617
+ };
595
618
 
596
619
  declare class AutoICD {
597
620
  private readonly apiKey;
@@ -608,6 +631,8 @@ declare class AutoICD {
608
631
  readonly icf: ICFCodes;
609
632
  /** Sub-resource for LOINC code lookup and coding. */
610
633
  readonly loinc: LOINCCodes;
634
+ /** Unified cross-system reference lookup. */
635
+ readonly reference: ReferenceCodes;
611
636
  constructor(options: AutoICDOptions);
612
637
  /**
613
638
  * Code clinical text to ICD-10-CM diagnoses.
@@ -805,6 +830,26 @@ declare class LOINCCodes {
805
830
  */
806
831
  search(query: string, options?: SearchOptions): Promise<LOINCSearchResponse>;
807
832
  }
833
+ declare class ReferenceCodes {
834
+ private readonly client;
835
+ constructor(client: AutoICD);
836
+ /**
837
+ * Look up canonical reference data for a code in any supported coding system.
838
+ *
839
+ * Supersedes the per-system getters (`icd10.get`, `icd11.get`, `icf.lookup`,
840
+ * `loinc.lookup`), which remain available but emit `Deprecation` and `Sunset`
841
+ * response headers.
842
+ *
843
+ * @example
844
+ * ```ts
845
+ * const result = await autoicd.reference.lookup("icd-10-cm", "I50.23");
846
+ * if (result.system === "icd-10-cm") {
847
+ * console.log(result.record.long_description);
848
+ * }
849
+ * ```
850
+ */
851
+ lookup(system: ReferenceSystem, code: string): Promise<ReferenceCodeRecord>;
852
+ }
808
853
 
809
854
  declare class AutoICDError extends Error {
810
855
  readonly status: number;
@@ -821,4 +866,4 @@ declare class NotFoundError extends AutoICDError {
821
866
  constructor(message?: string);
822
867
  }
823
868
 
824
- export { type AnonymizeResponse, type AuditCapability, type AuditCode, type AuditContext, type AuditDocument, type AuditRequest, type AuditResponse, type AuditTotals, AuthenticationError, AutoICD, AutoICDError, type AutoICDOptions, type ChapterInfo, type CodeDetail, type CodeDetailFull, type CodeMatch, type CodeOptions, type CodeSearchResponse, type CodingEntity, type CodingResponse, type ConfirmedCode, type CrosswalkMapping, type DenialRisk, type EvidenceSpan, type ICD11ChapterInfo, type ICD11CodeDetail, type ICD11CodeDetailFull, type ICD11CodeSearchResponse, type ICD11CodeSearchResult, type ICFCodeDetail, type ICFCodeResult, type ICFCodeSummary, type ICFCodingEntity, type ICFComponent, type ICFCoreSetResult, type ICFCrossReference, type ICFSearchResponse, type InteropSystem, type LOINCCodeDetail, type LOINCCodeResult, type LOINCCodeSummary, type LOINCCodingEntity, type LOINCCodingResponse, type LOINCSearchResponse, type MissedCode, NotFoundError, type PIIEntity, type ProblemListEntry, type RateLimit, RateLimitError, type RatesUsed, type SearchOptions, type SpecificityUpgrade, type TranslateMapping, type TranslateRequest, type TranslateResponse, type TranslateSource, type UnsupportedCode, type UpgradeHint };
869
+ export { type AnonymizeResponse, type AuditCapability, type AuditCode, type AuditContext, type AuditDocument, type AuditRequest, type AuditResponse, type AuditTotals, AuthenticationError, AutoICD, AutoICDError, type AutoICDOptions, type ChapterInfo, type CodeDetail, type CodeDetailFull, type CodeMatch, type CodeOptions, type CodeSearchResponse, type CodingEntity, type CodingResponse, type ConfirmedCode, type CrosswalkMapping, type DenialRisk, type EvidenceSpan, type ICD11ChapterInfo, type ICD11CodeDetail, type ICD11CodeDetailFull, type ICD11CodeSearchResponse, type ICD11CodeSearchResult, type ICFCodeDetail, type ICFCodeResult, type ICFCodeSummary, type ICFCodingEntity, type ICFComponent, type ICFCoreSetResult, type ICFCrossReference, type ICFSearchResponse, type InteropSystem, type LOINCCodeDetail, type LOINCCodeResult, type LOINCCodeSummary, type LOINCCodingEntity, type LOINCCodingResponse, type LOINCSearchResponse, type MissedCode, NotFoundError, type PIIEntity, type ProblemListEntry, type RateLimit, RateLimitError, type RatesUsed, type ReferenceCodeRecord, type ReferenceSystem, type SearchOptions, type SpecificityUpgrade, type TranslateMapping, type TranslateRequest, type TranslateResponse, type TranslateSource, type UnsupportedCode, type UpgradeHint };
package/dist/index.js CHANGED
@@ -76,6 +76,8 @@ var AutoICD = class {
76
76
  icf;
77
77
  /** Sub-resource for LOINC code lookup and coding. */
78
78
  loinc;
79
+ /** Unified cross-system reference lookup. */
80
+ reference;
79
81
  constructor(options) {
80
82
  if (!options.apiKey) {
81
83
  throw new Error("apiKey is required");
@@ -88,6 +90,7 @@ var AutoICD = class {
88
90
  this.icd11 = new ICD11Codes(this);
89
91
  this.icf = new ICFCodes(this);
90
92
  this.loinc = new LOINCCodes(this);
93
+ this.reference = new ReferenceCodes(this);
91
94
  }
92
95
  // ─── Public Methods ───
93
96
  /**
@@ -394,6 +397,31 @@ var LOINCCodes = class {
394
397
  return this.client.get(`/api/v1/loinc/codes/search?${params}`);
395
398
  }
396
399
  };
400
+ var ReferenceCodes = class {
401
+ constructor(client) {
402
+ this.client = client;
403
+ }
404
+ /**
405
+ * Look up canonical reference data for a code in any supported coding system.
406
+ *
407
+ * Supersedes the per-system getters (`icd10.get`, `icd11.get`, `icf.lookup`,
408
+ * `loinc.lookup`), which remain available but emit `Deprecation` and `Sunset`
409
+ * response headers.
410
+ *
411
+ * @example
412
+ * ```ts
413
+ * const result = await autoicd.reference.lookup("icd-10-cm", "I50.23");
414
+ * if (result.system === "icd-10-cm") {
415
+ * console.log(result.record.long_description);
416
+ * }
417
+ * ```
418
+ */
419
+ async lookup(system, code) {
420
+ return this.client.get(
421
+ `/api/v1/reference/${encodeURIComponent(system)}/${encodeURIComponent(code)}`
422
+ );
423
+ }
424
+ };
397
425
  function parseRateLimit(headers) {
398
426
  const limit = headers.get("X-RateLimit-Limit");
399
427
  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 ICFComponent,\n ICFCodeSummary,\n ICFCodeDetail,\n ICFCodeResult,\n ICFCodingEntity,\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 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 * 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,sBAAs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;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 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 ReferenceSystem,\n ReferenceCodeRecord,\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 ICFCodeDetail,\n ICFSearchResponse,\n ICFCoreSetResult,\n LOINCCodeDetail,\n LOINCSearchResponse,\n LOINCCodingResponse,\n AuditRequest,\n AuditResponse,\n TranslateRequest,\n TranslateResponse,\n ReferenceSystem,\n ReferenceCodeRecord,\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 /** Unified cross-system reference lookup. */\n readonly reference: ReferenceCodes;\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 this.reference = new ReferenceCodes(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 * 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// ─── Reference Sub-resource ───\n\nclass ReferenceCodes {\n constructor(private readonly client: AutoICD) {}\n\n /**\n * Look up canonical reference data for a code in any supported coding system.\n *\n * Supersedes the per-system getters (`icd10.get`, `icd11.get`, `icf.lookup`,\n * `loinc.lookup`), which remain available but emit `Deprecation` and `Sunset`\n * response headers.\n *\n * @example\n * ```ts\n * const result = await autoicd.reference.lookup(\"icd-10-cm\", \"I50.23\");\n * if (result.system === \"icd-10-cm\") {\n * console.log(result.record.long_description);\n * }\n * ```\n */\n async lookup(system: ReferenceSystem, code: string): Promise<ReferenceCodeRecord> {\n return this.client.get<ReferenceCodeRecord>(\n `/api/v1/reference/${encodeURIComponent(system)}/${encodeURIComponent(code)}`\n );\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;;;ACDA,IAAM,mBAA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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiB/C,MAAM,OAAO,QAAyB,MAA4C;AAChF,WAAO,KAAK,OAAO;AAAA,MACjB,qBAAqB,mBAAmB,MAAM,CAAC,IAAI,mBAAmB,IAAI,CAAC;AAAA,IAC7E;AAAA,EACF;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":[]}
package/dist/index.mjs CHANGED
@@ -46,6 +46,8 @@ var AutoICD = class {
46
46
  icf;
47
47
  /** Sub-resource for LOINC code lookup and coding. */
48
48
  loinc;
49
+ /** Unified cross-system reference lookup. */
50
+ reference;
49
51
  constructor(options) {
50
52
  if (!options.apiKey) {
51
53
  throw new Error("apiKey is required");
@@ -58,6 +60,7 @@ var AutoICD = class {
58
60
  this.icd11 = new ICD11Codes(this);
59
61
  this.icf = new ICFCodes(this);
60
62
  this.loinc = new LOINCCodes(this);
63
+ this.reference = new ReferenceCodes(this);
61
64
  }
62
65
  // ─── Public Methods ───
63
66
  /**
@@ -364,6 +367,31 @@ var LOINCCodes = class {
364
367
  return this.client.get(`/api/v1/loinc/codes/search?${params}`);
365
368
  }
366
369
  };
370
+ var ReferenceCodes = class {
371
+ constructor(client) {
372
+ this.client = client;
373
+ }
374
+ /**
375
+ * Look up canonical reference data for a code in any supported coding system.
376
+ *
377
+ * Supersedes the per-system getters (`icd10.get`, `icd11.get`, `icf.lookup`,
378
+ * `loinc.lookup`), which remain available but emit `Deprecation` and `Sunset`
379
+ * response headers.
380
+ *
381
+ * @example
382
+ * ```ts
383
+ * const result = await autoicd.reference.lookup("icd-10-cm", "I50.23");
384
+ * if (result.system === "icd-10-cm") {
385
+ * console.log(result.record.long_description);
386
+ * }
387
+ * ```
388
+ */
389
+ async lookup(system, code) {
390
+ return this.client.get(
391
+ `/api/v1/reference/${encodeURIComponent(system)}/${encodeURIComponent(code)}`
392
+ );
393
+ }
394
+ };
367
395
  function parseRateLimit(headers) {
368
396
  const limit = headers.get("X-RateLimit-Limit");
369
397
  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 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 * 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;;;ACHA,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,EA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","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 ICFCodeDetail,\n ICFSearchResponse,\n ICFCoreSetResult,\n LOINCCodeDetail,\n LOINCSearchResponse,\n LOINCCodingResponse,\n AuditRequest,\n AuditResponse,\n TranslateRequest,\n TranslateResponse,\n ReferenceSystem,\n ReferenceCodeRecord,\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 /** Unified cross-system reference lookup. */\n readonly reference: ReferenceCodes;\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 this.reference = new ReferenceCodes(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 * 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// ─── Reference Sub-resource ───\n\nclass ReferenceCodes {\n constructor(private readonly client: AutoICD) {}\n\n /**\n * Look up canonical reference data for a code in any supported coding system.\n *\n * Supersedes the per-system getters (`icd10.get`, `icd11.get`, `icf.lookup`,\n * `loinc.lookup`), which remain available but emit `Deprecation` and `Sunset`\n * response headers.\n *\n * @example\n * ```ts\n * const result = await autoicd.reference.lookup(\"icd-10-cm\", \"I50.23\");\n * if (result.system === \"icd-10-cm\") {\n * console.log(result.record.long_description);\n * }\n * ```\n */\n async lookup(system: ReferenceSystem, code: string): Promise<ReferenceCodeRecord> {\n return this.client.get<ReferenceCodeRecord>(\n `/api/v1/reference/${encodeURIComponent(system)}/${encodeURIComponent(code)}`\n );\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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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiB/C,MAAM,OAAO,QAAyB,MAA4C;AAChF,WAAO,KAAK,OAAO;AAAA,MACjB,qBAAqB,mBAAmB,MAAM,CAAC,IAAI,mBAAmB,IAAI,CAAC;AAAA,IAC7E;AAAA,EACF;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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autoicd-js",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
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",