Trying to delete old studies

I am try to achieve automatic deletion of studies after a certain period of time using Lua scripting in Orthanc, but facing some issue.
I have created a created a Lua delete_old_studies.lua and placed it in Orthanc configuration directory.
I have Lua installed on your Windows system as well.
On manually running this lua script I am getting this following message.

C:\Program Files\Orthanc Server\Configuration>lua delete_old_studies.lua
lua: delete_old_studies.lua:8: attempt to index global ‘DICOMExplorer’ (a nil value)
stack traceback:
delete_old_studies.lua:8: in main chunk
[C]: ?

C:\Program Files\Orthanc Server\Configuration>

My delete_old_studies.lua is as follows:-

– the retention period in days
local retentionPeriod = 100

– Calculate the threshold date (current date - retention period)
local thresholdDate = os.date(“%Y-%m-%d”, os.time() - (retentionPeriod * 8640000))

– Get a list of all studies
local studies = DICOMExplorer.Studies()

– Iterate through the studies and delete those older than the threshold date
for studyId, study in pairs(studies) do
local studyDate = study[‘StudyDate’]
if studyDate < thresholdDate then
DICOMExplorer.DeleteStudy(studyId)
end
end

Please help me solving this issue.

Hi,

What is DICOMExplorer supposed to be ?

There is no such class/object in the Orthanc Eco-system …

Best regards,

Alain.

Maybe this can help?