Hi, I’m beginner on Orthanc utilization and having problems with Lua script.
When are executed create an new Instance UID, in the compressing stage, and delete the older file. Whatever if the same study is send to Orthanc it duplicate the instance image. I think it does not recognizes the old file UID and repeat the process duplicanting the image.
Here is my script:
`
function OnStoredInstance(instanceId, tags, metadata, origin)
if origin[‘RequestOrigin’] ~= ‘Lua’ and tags[‘Modality’] ~= ‘RF’ then
local dicom = RestApiGet(‘/instances/’ … instanceId … ‘/file’)
local uncompressed = instanceId … ‘-uncompressed.dcm’
local target = assert(io.open(uncompressed, ‘wb’))
target:write(dicom)
target:close()
local compressed = instanceId … ‘-compressed.dcm’
os.execute('gdcmconv --lossy --j2k ’ … uncompressed … ’ ’ … compressed)
local source = assert(io.open(compressed, ‘rb’))
local jpeg2k = source:read(“*all”)
source:close()
RestApiDelete(‘/instances/’ … instanceId)
RestApiPost(‘/instances’, jpeg2k)
os.remove(uncompressed)
os.remove(compressed)
end
a = {‘port1’, ‘port2’, ‘port3’, ‘port4’, ‘port5’, ‘port6’, ‘port7’, ‘port8’, ‘port9’, ‘port10’, ‘port11’}
keys = {}
for key, value in pairs(a) do
keys[#keys+1] = key
end
math.randomseed(os.time())
index = keys[math.random(1, #keys)]
SendToModality(instanceId, a[index])
end
`
There is some change that can end this?