How to get dicom tags on OnDeletedInstance?

Hello,

When instance is deleted we would like to get it’s dicom tags (studyuid, sopinstanceuid, etc.) and save to json file.

We use OnDeletedInstance lua callback however it does not have dicom tags.
We have tried to use this:

function OnDeletedInstance(instanceId)
local instance = ParseJson(RestApiGet(‘/instances/’ … instanceId … ‘/simplified-tags’))
local info = {}
info[‘study_iuid’] = instance[‘StudyInstanceUID’]
info[‘series_iuid’] = instance[‘SeriesInstanceUID’]
info[‘modality’] = instance[‘Modality’]
info[‘sop_iuid’] = instance[‘SOPInstanceUID’]
info[‘sop_class_uid’] = instance[‘SOPClassUID’]

– Write to the file

local target = assert(io.open(TARGET … os.time(os.date(“!*t”)) … ‘_’ … instanceId … ‘.json’, ‘wb’))
target:write(JSON:encode(info))
target:close()

end

But it seems that instance is already deleted, because we get error: attempt to index a nil value (local ‘instance’)

Any suggestions how to get these dicom tags then instance is deleted?

Thanks,
M.

Hi Marius,

Sorry, not much we can do against that. We could maybe implement a PreDelete callback but that’s quite a bit of development.

Your only chance is probably to have an extra DB in which you store the meaningful tags associated with each orthanc instance id.

Best regards,

Alain.

Maybe it would be easier to include tags variable on OnDeletedInstance?

Unfortunately not, since we need to keep backward compatibility, we can not change the signature of the callback so we need to define a new callback anyway

Hello,

You could implement such a feature using a Python plugin:
https://book.orthanc-server.com/plugins/python.html

You’ll find attached to this message a sample Python script that overrides the “DELETE” method on the “/instances/{id}” URI.

You could extend this script to deal with the deletion of patients/studies/series.

HTH,
Sébastien-

test.py (571 Bytes)