|
@@ -0,0 +1,56 @@
|
|
|
+const parser = require('dicom-parser');
|
|
|
+const fsp = require('fs-promise');
|
|
|
+const iconv = require("iconv-lite")
|
|
|
+
|
|
|
+const filePath = '/Users/fuyu/Downloads/CgocGF1Cuu2AMYb5AIEtSKYTE8Q756.dcm';
|
|
|
+let test = async url => {
|
|
|
+ const fileBuffer = await fsp.readFile(url);
|
|
|
+ const dataSet = parser.parseDicom(fileBuffer);
|
|
|
+ const charset = getCharSet(dataSet)
|
|
|
+ const originalString = dataSet.string;
|
|
|
+ dataSet.string = (tag, index) => {
|
|
|
+ let value = originalString.call(dataSet, tag, index);
|
|
|
+ if (value != null && value != 'undefined') {
|
|
|
+ console.log('charset', charset)
|
|
|
+ let _value = iconv.decode(value, 'UTF-8');
|
|
|
+ // console.log()
|
|
|
+ if (_value != null && _value != 'undefined') {
|
|
|
+ return _value.replace(/['^']+/g, '')
|
|
|
+ }
|
|
|
+ return _value;
|
|
|
+ } else {
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ let text = dataSet.string('x0008103e')
|
|
|
+ console.log(text, iconv.decode(text, 'ISO_IR 100'))
|
|
|
+}
|
|
|
+
|
|
|
+const chatSetMap = {
|
|
|
+ 'ISO_IR 6': 'UTF-8',
|
|
|
+ 'ISO_IR 192': 'UTF-8',
|
|
|
+ 'ISO_IR 100': 'ISO-8859-1',
|
|
|
+ 'ISO_IR 101': 'ISO-8859-2',
|
|
|
+ 'ISO_IR 109': 'ISO-8859-3',
|
|
|
+ 'ISO_IR 110': 'ISO-8859-4',
|
|
|
+ 'ISO_IR 144': 'ISO-8859-5',
|
|
|
+ 'ISO_IR 127': 'ISO-8859-6',
|
|
|
+ 'ISO_IR 126': 'ISO-8859-7',
|
|
|
+ 'ISO_IR 138': 'ISO-8859-8',
|
|
|
+ 'ISO_IR 148': 'ISO-8859-9',
|
|
|
+}
|
|
|
+const getCharSet = dataSet => {
|
|
|
+ let specificCharacterSet = dataSet.string('x00080005');
|
|
|
+ let charset = 'GB2312'
|
|
|
+ console.log('specificCharacterSet', specificCharacterSet)
|
|
|
+ if (specificCharacterSet) {
|
|
|
+ charset = chatSetMap[specificCharacterSet] || charset
|
|
|
+ }
|
|
|
+ return charset
|
|
|
+ }
|
|
|
+ // GB2312
|
|
|
+ // //xml文件编码方式,以支持中文显示。
|
|
|
+ // if (!csetString.empty())
|
|
|
+ // encString = "GB2312";
|
|
|
+
|
|
|
+test(filePath)
|