@lowlysre/icd-10-cm 1.1.0 → 2.0.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.cjs ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getICD10Description = exports.normalizeICD10Code = exports.ensureICD10DatasetLoaded = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ const ensureICD10DatasetLoaded = (data) => {
7
+ const datasetHasEntries = data && Object.keys(data).length > 0;
8
+ if (!datasetHasEntries) {
9
+ throw new Error("ICD-10-CM data failed to load");
10
+ }
11
+ return data;
12
+ };
13
+ exports.ensureICD10DatasetLoaded = ensureICD10DatasetLoaded;
14
+ let dataset;
15
+ // Lazily read and parse the dataset on first lookup so importing the
16
+ // package costs nothing until it is actually used.
17
+ const loadDataset = () => {
18
+ if (dataset === undefined) {
19
+ const dataPath = (0, node_path_1.join)(__dirname, "..", "data", "icd10.min.json");
20
+ dataset = (0, exports.ensureICD10DatasetLoaded)(JSON.parse((0, node_fs_1.readFileSync)(dataPath, "utf-8")));
21
+ }
22
+ return dataset;
23
+ };
24
+ // ICD-10-CM codes are 3-7 alphanumeric characters; the decimal point
25
+ // conventionally written after the third character (e.g. "W61.62XD") is
26
+ // display-only formatting and is not part of the code itself. The CMS
27
+ // source file (icd10cm_codes_*.txt) lists codes without it, uppercase,
28
+ // so lookups normalize by stripping dots and uppercasing to match the
29
+ // dataset keys.
30
+ const normalizeICD10Code = (code) => code.trim().replace(/\./g, "").toUpperCase();
31
+ exports.normalizeICD10Code = normalizeICD10Code;
32
+ const getICD10Description = (code) => loadDataset()[(0, exports.normalizeICD10Code)(code)];
33
+ exports.getICD10Description = getICD10Description;
34
+ exports.default = exports.getICD10Description;
@@ -1,6 +1,7 @@
1
- import type { ICD10Dictionary } from "./ICD10Dictionary";
1
+ export type ICD10Dictionary = {
2
+ [code: string]: string;
3
+ };
2
4
  export declare const ensureICD10DatasetLoaded: (data: ICD10Dictionary) => ICD10Dictionary;
3
5
  export declare const normalizeICD10Code: (code: string) => string;
4
6
  export declare const getICD10Description: (code: string) => string | undefined;
5
- export type { ICD10Dictionary };
6
7
  export default getICD10Description;
@@ -0,0 +1,4 @@
1
+ import { getICD10Description } from "./index.cjs";
2
+ export { getICD10Description, ensureICD10DatasetLoaded, normalizeICD10Code, } from "./index.cjs";
3
+ export type { ICD10Dictionary } from "./index.cjs";
4
+ export default getICD10Description;