Hello all,
I’m struggling with this case.
We need to modify the patient ID and send the data to other modalities.
Can someone help me with a Lua script?
This part works well:
function OnStoredInstance(instanceId, tags, metadata)
Delete(SendToModality(instanceId, ‘sample’))
end
But I don’t understand how to perform the modification by lua script.
Hello @andrii ,
This example demonstrates how to modify an instance before sending it to another modality.
Please read carefully the Modification of a Single Instance section of the Orthanc Book.The code will download the modified instance that will not be, after the /modify
request, modified in Orthanc, then it will be transferred to the target-modality
by sending the whole DICOM to /store-straight
(straight here means “without storing it in Orthanc first”)
Normally, a new instance with a new instance ID is created, but the Force
and SOPInstanceUID
below will ensure it keeps the same ID.
Pasting the code here for future visitors who might have issues with the GitHub link:
unction OnStoredInstance(instanceId, tags, metadata, origin)
-- Do not process twice the same file
if origin['RequestOrigin'] ~= 'Lua' then
local modifyRequest = {}
modifyRequest["Remove"] = {}
table.insert(modifyRequest["Remove"], "0028-3010")
modifyRequest["Replace"] = {}
modifyRequest["Replace"]["SOPInstanceUID"] = tags["SOPInstanceUID"]
modifyRequest["Force"] = true -- because we want to keep the same SOPInstanceUID
-- download a modified version of the instance
local modifiedDicom = RestApiPost('/instances/' .. instanceId .. '/modify', DumpJson(modifyRequest))
RestApiPost('/modalities/target-modality/store-straight', modifiedDicom)
RestApiDelete('/instances/' .. instanceId)
end
end
If you want to upload to the same Orthanc, you need to make sure that OverwriteInstances
is set to true
in your configuration file, and you need to adapt the RestApiPost
URL and, of course, don’t do the RestApiDelete
.
Hope this helps!
Benjamin