Dear all,
I would like to use the change the patientID so that it fits the patientName upon receiving an instance (please don't ask why I have to do this :)). I had a look at the lua scripts and made use of the OnStoredInstance function as described in the example session. This works fine if upload the instances only once. However it could happen that scientists upload files a second time (you know how they are :)). However, it would then create a second instance in the database not realizing that there is already one which has been changed from the same original one. I guess this has something to do with the fact that I don't know how to change an instances without creating a new one and deleting the old one (in place changes).
Or is there a workaround?
All the best in advance!
Bernhard
function OnStoredInstance(instanceId, tags, metadata, origin)
if origin['RequestOrigin'] ~= 'Lua' then
local replace = {}
replace['0010,0020'] = tags['PatientName']
local request = {}
request['Replace'] = replace
-- Create the modified instance
local modified = RestApiPost('/instances/' .. instanceId .. '/modify',
DumpJson(request))
-- Upload the modified instance to the Orthanc store
RestApiPost('/instances/', modified)
-- Delete the original instance
RestApiDelete('/instances/' .. instanceId)
end
print('Lua script has been executed')
end
Hi,
I would like to use the change the patientID so that it fits the patientName upon receiving an instance (please don't ask why I have to do this :)). I had a look at the lua scripts and made use of the OnStoredInstance function as described in the example session. This works fine if upload the instances only once. However it could happen that scientists upload files a second time (you know how they are :)). However, it would then create a second instance in the database not realizing that there is already one which has been changed from the same original one. I guess this has something to do with the fact that I don't know how to change an instances without creating a new one and deleting the old one (in place changes).
The way Orthanc generates instance IDs is described here: Orthanc identifiers — Orthanc Book documentation
As you can see, Orthanc instance IDs are derived from PatientID and Study/Series/SOPInstance UIDs. If (and only if!) any of these change, Orthanc treats the result as a new instance.
Calls to /modify will silently reset the InstanceUID unless you tell Orthanc not to.
You can provide your own deterministic InstanceUID to the /modify call so that the generated instance id will be the same. With that the RestAPIPost will still succeed but you won't create a duplicate if the instance already existed.
You might be fine with just keeping the UIDs from the original instance:
-- note: changing instance data but not changing UIDs is a bad idea. You should generate new UIDs instead.
local keep = { 'SeriesInstanceUID', 'StudyInstanceUID', 'SOPInstanceUID' }
request['Keep'] = keep
If you ever have a system that handles both the changed and unchanged instance, then you might run into trouble with that. Dicom standard assumes that if the SOPInstanceUID is unchanged then the instances are _identical_. It would be better if you replace the UIDs with your own; but you would have to generate them with a deterministic process from the source UID so you don't generate duplicates.
hth,
Levin
Hi Levin,
that means that upon change of a second uploaded instance it will create a new InstanceUID and since there is already one (the first modified instance with an already modified UID) it will add a another UID to the modification of the second instance. I see.
Thanks for your help and advice! Ill give the “Keep” code a try!
All the best,
B