Changing PatientID without Duplication in Orthanc

Hello, community!

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:

  1. Configuring “OverwriteInstances”: true in the config.json file.

  2. Intercepting exams with Lua scripts to modify the PatientID before storing them.

  3. 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?

Thank you in advance for your help!

Hello @Onerb

The ReceivedInstanceCallback in python is the only way I can think of.

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)

Hope this helps,

Alain

Hello @Alain,

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?

Your insights would be greatly appreciated!

Best regards,
Onerb

You mean implement the inbox in lua ? This is actually done in the sample.
If you mean something else, I don’t get it :frowning:

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.

No, that is definitely not possible in Lua.

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.

1 Like