I'm trying to customize the script for my needs. I need to zip the folder after writing to disk and delete the folder.
TARGET = '/tmp/lua'
function ToAscii(s)
return s:gsub('[^a-zA-Z0-9-/-:]', '_')
end
function OnStableSeries(seriesId, tags, metadata)
local instances = ParseJson(RestApiGet('/series/' .. seriesId)) ['Instances']
local patient = ParseJson(RestApiGet('/series/' .. seriesId .. '/patient')) ['MainDicomTags']
local study = ParseJson(RestApiGet('/series/' .. seriesId .. '/study')) ['ID']
local series = ParseJson(RestApiGet('/series/' .. seriesId)) ['MainDicomTags']
print('This series is now stable, writing its instances on the disk: ' .. ToAscii(patient['PatientName'] .. '-' .. seriesId))
for i, instance in pairs(instances) do
local path = ToAscii(TARGET .. '/' .. patient['PatientName'] .. '/IMAGES')
-- Retrieve the DICOM file from Orthanc
local dicom = RestApiGet('/instances/' .. instance .. '/file')
-- Create the subdirectory (CAUTION: For Linux demo only, this is insecure!)
os.execute('mkdir -p "' .. path .. '"')
ptname = ToAscii(patient['PatientName'])
-- Write to the file
local target = assert(io.open(path .. '/' .. instance .. '.dcm', 'wb'))
target:write(dicom)
target:close()
RestApiDelete('/instances/' .. instance)
end
os.execute('/tmp/lua/zip.sh ' .. ToAscii(patient['PatientName']))
end
os.execute('rm -rf' .. ToAscii(TARGET .. '/' .. ToAscii(patient['PatientName'])))