Hi!
To recode all incoming DICOM files to UTF-8 in the ImportConverter, I use this :
Code
local function convertEncoding(str, fromEncoding)
if not str then
return 'ret-free'
end
local sanitizedStr = string.gsub(str, "'", "'\\''")
local command = "echo '" .. sanitizedStr .. "' | iconv -f " .. fromEncoding .. " -t utf8"
local handle = io.popen(command)
if not handle then
print('Error: iconv does not work.')
return str
end
local result = handle:read("*a")
handle:close()
return result
end
function string.toutf8(str)
return convertEncoding(str, 'iso8859-5')
end
local function processField(data, fieldName, encodingFunc)
if data[fieldName] then
local originalValue = data[fieldName]
local convertedValue = encodingFunc(originalValue)
data[fieldName] = string.gsub(convertedValue, "\n", "")
end
end
print("----- ImportConverter.lua BEGIN -----")
if tostring(Data["0008,0005"]) == 'ISO_IR 144' then
print('FOUND ISO_IR_144, CHANGE Data.CodePage(0008,0005)=ISO_IR 144 to ISO_IR 192')
Data["0008,0005"] = 'ISO_IR 192'
processField(Data, '0008,0080', string.toutf8)
processField(Data, '0008,0081', string.toutf8)
processField(Data, '0008,1010', string.toutf8)
processField(Data, '0008,1070', string.toutf8)
processField(Data, '0010,0010', string.toutf8)
processField(Data, '0010,0090', string.toutf8)
processField(Data, '0011,1105', string.toutf8)
processField(Data, '0018,1020', string.toutf8)
processField(Data, '0021,1103', string.toutf8)
processField(Data, '0021,1109', string.toutf8)
processField(Data, '0021,1132', string.toutf8)
processField(Data, '0021,1134', string.toutf8)
processField(Data, '0021,1135', string.toutf8)
processField(Data, '0021,1177', string.toutf8)
processField(Data, '0029,1107', string.toutf8)
end
print("===== ImportConverter.lua END =====")
Display More
It works, but sometimes it doesn't - because DICOM has a new tag needed for recoding. How can I iterate over (userdata object) and recode all the tags?