function OnStoredInstance(instanceId, tags, metadata, origin)
if origin['RequestOrigin'] ~= 'Lua' then
-- The tags to be replaced
local replace = {}
replace['PatientName'] = tags['PatientID']
-- The tags to be removed
local remove = { 'MilitaryRank' }
-- Modify the instance, send it, then delete the modified instance
-- Delete(SendToModality(ModifyInstance(instanceId, replace, remove, true), 'AZM'))
ModifyInstance(instanceId, replace, remove, true)
-- Delete the original instance
Delete(instanceId)
end
end