I am facing an issue with Orthanc when trying to change the PatientID of already stored exams. Every time I make the change, even if it is just adding a suffix to the PatientID, Orthanc creates a duplicate of the study, keeping the original exam with the old PatientID.
I have tried the following approaches:
Configuring “OverwriteInstances”: true in the config.json file.
Intercepting exams with Lua scripts to modify the PatientID before storing them.
Resending the modified exams and then manually deleting the original study.
This approach came closest to what I need, but the exam is still briefly duplicated until the original study is deleted. This is not ideal for my workflow as I need to avoid duplication at any point in the process.
My requirement is:
To change the PatientID of an exam (either generating a new one or correcting the ID) without creating a duplicate in Orthanc, and keeping only the modified version of the study immediately.
Is there any recommended configuration or workflow to achieve this? Any functional example of a Lua script or configuration that I can use?
On our side, we usually use another Orthanc instance that is acting as an “inbox” and that sanitizes the data before pushing it to the “final” Orthanc. (Sample)
Thank you so much for your suggestion and for sharing your approach! Using a separate Orthanc instance as an “inbox” for sanitizing data before forwarding it to the final instance is indeed an interesting solution.
I was wondering if it would be possible to implement a similar workflow directly using Lua scripts in Orthanc? Perhaps by leveraging callbacks or modifying the metadata during processing?
I meant implementing a way to change the patientId at the instance level without duplicating it, using a Lua script. This would avoid creating copies by directly modifying the existing instance.
By doing it in the inbox, you create temporary copies in the inbox only but you should not care about it → you can do it in Lua on the OnStoredInstance using the REST Api.
I resumed testing and it worked with a python script, Alain. With the lua script it took a long time to process when the study flow was large, but with python it was very quick. Thank you very much for your help