The “duplicate PatientID problem” is common and vexing. I have custom code that looks at errors in any of the following elements (I have found them all):
If any individual lookup (“/instances/$orthanc_instance_id/content/$dicom_tag”) result does not match what comes across in the Changes Log “Path” lookup, I create a new patient via split: /studies/$orthanc_study_id/split
I prepend a “FIX” variable with a self counting appended integer (e.g., “SPECIALFIX1_”, “SPECIALFIX2_”, etc.) to the prior study to avoid conflicts and correct errors. I have seen this in a commercial application.
In that way, I do “replace patientID at study level” per your post.
Hope that helps. I have a large data set (from many disparate input sources) and found this work around entirely necessary because the real world and the “DICOM model of the real world” never align.