Skip to content

Commit

Permalink
feat(dcm2json): correct DICOM when missing charset
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Mar 29, 2023
1 parent 95e70d6 commit ad1f4d1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion models/DICOM/dicom-json-parser.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
const { DicomUtf8Converter } = require("./dcm4che/DicomUtf8Converter");
const {
dcm2jsonV8
} = require("./dcmtk");
const { logger } = require("../../utils/log");


class DicomJsonParser {
constructor() {}

async parseFromFilename(filename) {
let dicomJson;
try {
let dicomJson = await dcm2jsonV8.exec(filename);
dicomJson = await dcm2jsonV8.exec(filename);
return dicomJson;
} catch (e) {

/**
* EXITCODE_CANNOT_CONVERT_TO_UNICODE is usually due to dicom file missing (0008,0005)
* To fix this error, we use dcmconv to convert DICOM file to UTF-8 (ISO_IR 192)
*/
if (e.message.includes("EXITCODE_CANNOT_CONVERT_TO_UNICODE")) {
logger.warn(`The file: ${filename} may missing/incorrect (0008,0005) charset, converter dicom to UTF8`);

try {
let dicomUtf8Converter = new DicomUtf8Converter(filename);
await dicomUtf8Converter.convert();

dicomJson = await dcm2jsonV8.exec(filename);
return dicomJson;
} catch(e) {
throw e;
}
}

throw e;
}
}
Expand Down

0 comments on commit ad1f4d1

Please sign in to comment.