-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: correct dicom missing 00080005 when STOW
# Problems - When I uploaded DICOM file, I got an `EXITCODE_CANNOT_CONVERT_TO_UNICODE ` error - Upon checking DICOM file, I found that the error was caused by missing 00080005 # Solution - Use dcmconv to convert DICOM file to Unicode that can replace 00080005 to `ISO_IR 192`
- Loading branch information
1 parent
cf2bbeb
commit 45ea880
Showing
2 changed files
with
130 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
const childProcess = require('child_process'); | ||
const path = require("path"); | ||
const iconv = require('iconv-lite'); | ||
const os = require("os"); | ||
|
||
const CONVERT_TO_UTF8_OPTION = "--convert-to-utf8"; | ||
const DISCARD_ILLEGAL_OPTION = "--discard-illegal"; | ||
|
||
class DcmConv { | ||
constructor() { | ||
let platform = os.platform(); | ||
/** @private */ | ||
this.executer = {}; | ||
if (platform === "win32") { | ||
this.handler = new DcmConvWindowsHandler(); | ||
} else { | ||
this.handler = new DcmConvBasicHandler(); | ||
} | ||
} | ||
|
||
async exec(inputFile, options=[]) { | ||
return this.handler.exec(inputFile, options); | ||
} | ||
} | ||
|
||
class DcmConvWindowsHandler { | ||
constructor() {} | ||
|
||
/** | ||
* Convert file to UTF-8 that use dcmconv | ||
* Use for dicom file missing (0008,0005) | ||
* @param {string} inputFile | ||
*/ | ||
exec(inputFile, options=[]) { | ||
return new Promise((resolve, reject) => { | ||
let dcmconvExecBinary = path.resolve(`models/dcmtk/dcmtk-3.6.5-win64-dynamic/bin/dcmconv.exe`); | ||
let execOption = [inputFile, inputFile, CONVERT_TO_UTF8_OPTION, DISCARD_ILLEGAL_OPTION, ...options]; | ||
|
||
let dcmcovSpawn = childProcess.spawn(dcmconvExecBinary, execOption, { | ||
cwd: process.cwd(), | ||
shell: true | ||
}); | ||
|
||
dcmcovSpawn.stdout.on("data" , function (data) { | ||
if (data) console.log(data); | ||
resolve(data); | ||
}); | ||
|
||
dcmcovSpawn.on("close", function() { | ||
resolve(true); | ||
}); | ||
|
||
dcmcovSpawn.stderr.on("data", function (stderr) { | ||
stderr = iconv.decode(stderr, 'cp950'); | ||
reject(new Error(stderr)); | ||
}); | ||
|
||
}); | ||
} | ||
} | ||
|
||
class DcmConvBasicHandler { | ||
constructor() {} | ||
|
||
/** | ||
* Convert file to UTF-8 that use dcmconv | ||
* Use for dicom file missing (0008,0005) | ||
* @param {string} inputFile | ||
*/ | ||
exec(inputFile, options=[]) { | ||
return new Promise((resolve, reject) => { | ||
let dcmconvExecBinary = `dcmconv`; | ||
let execOption = [inputFile, inputFile, CONVERT_TO_UTF8_OPTION, DISCARD_ILLEGAL_OPTION, ...options]; | ||
|
||
let dcmcovSpawn = childProcess.spawn(dcmconvExecBinary, execOption, { | ||
cwd: process.cwd(), | ||
shell: true | ||
}); | ||
|
||
dcmcovSpawn.stdout.on("data" , function (data) { | ||
if (data) console.log(data); | ||
resolve(data); | ||
}); | ||
|
||
dcmcovSpawn.on("close", function() { | ||
resolve(true); | ||
}); | ||
|
||
dcmcovSpawn.stderr.on("data", function (stderr) { | ||
stderr = iconv.decode(stderr, 'cp950'); | ||
reject(new Error(stderr)); | ||
}); | ||
|
||
}); | ||
} | ||
} | ||
|
||
|
||
module.exports.DcmConv = DcmConv; |