-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicd9to10.js
More file actions
71 lines (57 loc) · 1.94 KB
/
icd9to10.js
File metadata and controls
71 lines (57 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const fs = require('fs');
const { program } = require('commander');
async function icd9to10Converter(infile) {
console.log('Super Simple ICD-9-CM to ICD-10-CM converter!');
const dataTable = {};
try {
const data = fs.readFileSync('icd9to10dictionary.txt', 'utf8');
const lines = data.split('\n');
lines.forEach(line => {
const parts = line.split('|').map(part => part.trim());
if (parts.length === 3) {
const nine = parts[0];
const ten = parts[1];
const desc = parts[2];
dataTable[nine] = [ten, desc];
}
});
} catch (error) {
if (error.code === 'ENOENT') {
console.error('Missing dependency: icd9to10dictionary.txt');
process.exit(1);
} else {
console.error("An error occurred while reading the dictionary file:", error);
process.exit(1);
}
}
try {
const inputData = fs.readFileSync(infile, 'utf8');
const inputLines = inputData.split('\n');
let count = 0;
let total = 0;
const outputFile = infile + '.out';
const outputStream = fs.createWriteStream(outputFile);
outputStream.write('icd9\ticd10\tdescription\n');
inputLines.forEach(line => {
total++;
const stripped = line.trim();
if (stripped in dataTable) {
count++;
outputStream.write(`${stripped}\t${dataTable[stripped].join('\t')}\n`);
} else {
outputStream.write(`${stripped}\tNA\tNA\n`);
}
});
outputStream.end();
console.log(`Matched ${count} codes from your list of ${total} codes`);
} catch (error) {
console.error("An error occurred while processing the input file:", error);
process.exit(1);
}
}
program
.argument('<infile>', 'File with list of 1 or more ICD-9 Codes in decimal format (e.g. 410.90). Will attempt to match some if decimals are missing but results are not guaranteed! :)')
.action((infile) => {
icd9to10Converter(infile);
});
program.parse(process.argv);