# Modifying patient takes a long time - KeepSource: False

**URL:** https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644
**Category:** General
**Created:** [April 30, 2024, 4:43pm UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644 "2024-04-30T16:43:29Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![dnudelman](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@dnudelman](https://discourse.orthanc-server.org/u/dnudelman)
#### Post date: [April 30, 2024, 4:43pm UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644/1 "2024-04-30T16:43:29Z")

</div>

Hey Everyone,  
Been using Orthanc alot over the last few months and wrote a python script that updates patients “PatientID”. I am using the patients "modify’ endpoint for this. when I include ‘KeepSource’: False in my command json it takes an extensive amount of time.

I am on Orthanc 1.12.2, using MYSQL DB. 32gb of memory both the DB and image storage are running on an SSD drive.

See the part of the script below that is taking a long time…

```auto
def update_patient_metadata(patient_id, new_patient_id):
    print(patient_id, new_patient_id)
    # Define headers for the request (e.g., content type)
    headers = {'Content-Type': 'application/json'}
    modify_endpoint = f'{orthanc_url}/patients/{patient_id}/modify'
    command = {
        'Replace': {
            'PatientID': str(new_patient_id),
        }, 'Force': True,
        'KeepSource': False
    }
    # Send POST request to modify the instance
    response = requests.post(modify_endpoint, data=json.dumps(command), headers=headers)
    if response.status_code == 200:
        return True
    else:
        return False

```

Relevant logs:

```auto
T0430 12:41:44.805049 JOBS-WORKER-3 ServerIndex.cpp:128] Remaining ancestor "4187a2f1-6692ac6f-344ffae7-b00a174e-f94ee966" (3)
T0430 12:41:44.806049 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.806049 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.806049 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.806049 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.807071 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.819657 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
I0430 12:41:44.820654 JOBS-WORKER-3 FilesystemStorage.cpp:266] Deleting attachment "1fcb1ce7-00c6-4941-af21-b7756e433069" of type 1
T0430 12:41:44.820654 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.820654 201c OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.821653 201c OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.822648 201c OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.823644 201c OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.823644 201c OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
I0430 12:41:44.823644 201c FilesystemStorage.cpp:182] Reading attachment "009a538d-84e5-4db5-bff2-aeea02fbc9f1" of "DICOM" content type (range from 0 to 10130)
T0430 12:41:44.823644 32e8 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
I0430 12:41:44.823644 201c FilesystemStorage.cpp:189] Read range of attachment "009a538d-84e5-4db5-bff2-aeea02fbc9f1" (9.89KB in 0ns = infGbps)
T0430 12:41:44.824642 32e8 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.825638 32e8 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.825638 32e8 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.825638 32e8 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.825638 32e8 OrthancPlugins.cpp:5882] (plugins) Calling service 4018 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancDicomWeb.dll
T0430 12:41:44.825638 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.826637 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:41:44.827634 201c OrthancPlugins.cpp:5882] (plugins) Calling service 3004 from plugin C:\Program Files\Orthanc Server\Plugins\libOrthancOHIF-Windows64.dll
I0430 12:41:44.827634 201c OrthancPlugins.cpp:3278] (plugins) Plugin making REST PUT call on URI /instances/059e3cb6-4c1df0e5-2bc8aa64-4c3d65ef-a5b49576/metadata/4202 (built-in API)
T0430 12:41:44.828665 32e8 OrthancPlugins.cpp:5882] (plugins) Calling service 4011 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancDicomWeb.dll
T0430 12:42:01.563920 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:01.563920 JOBS-WORKER-3 ServerIndex.cpp:161] Change related to resource 17926b25-336664d8-19258398-9ad945ad-d5cbab78 of type Instance: Deleted
T0430 12:42:01.563920 JOBS-WORKER-3 ServerIndex.cpp:128] Remaining ancestor "b39e7049-e6a57ab0-13e231a2-0c80e8a0-4f7d2d96" (3)
T0430 12:42:01.565190 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:01.565190 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:01.565190 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:01.565190 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:01.566169 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:01.580050 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
I0430 12:42:01.580050 JOBS-WORKER-3 FilesystemStorage.cpp:266] Deleting attachment "65ca2323-334f-4ddf-9df7-99cc98cf1fe9" of type 1
T0430 12:42:01.580050 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:01.581047 SAVE-JOBS OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:01.598999 SAVE-JOBS OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:01.629224 SAVE-JOBS OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:01.629224 SAVE-JOBS OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:01.629224 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:01.630237 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:04.052911 WEBDAV-UPLOAD OrthancWebDav.cpp:1246] Cleaning up the empty WebDAV upload folders
T0430 12:42:11.706680 SAVE-JOBS ServerContext.cpp:327] Serializing the content of the jobs engine
T0430 12:42:18.332146 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.332146 JOBS-WORKER-3 ServerIndex.cpp:161] Change related to resource 18daa2ec-e2a8f668-631a0b45-af9bafcb-d78dd34d of type Instance: Deleted
T0430 12:42:18.332146 JOBS-WORKER-3 ServerIndex.cpp:128] Remaining ancestor "8ed2e8d1-d7a5e14b-8eee2b9c-5324fb75-c4c32619" (3)
T0430 12:42:18.332972 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.332972 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.332972 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.333972 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.334805 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.347267 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
I0430 12:42:18.347267 JOBS-WORKER-3 FilesystemStorage.cpp:266] Deleting attachment "72b015d7-49f3-4cd3-a62e-c85d767fcbd6" of type 1
T0430 12:42:18.348256 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.348256 201c OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.349254 201c OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.350252 201c OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.351248 201c OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.352246 201c OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.352246 201c ServerIndex.cpp:161] Change related to resource 059e3cb6-4c1df0e5-2bc8aa64-4c3d65ef-a5b49576 of type Instance: UpdatedMetadata
T0430 12:42:18.355240 201c OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.355240 201c OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.355240 201c OrthancPlugins.cpp:5882] (plugins) Calling service 3001 from plugin C:\Program Files\Orthanc Server\Plugins\libOrthancOHIF-Windows64.dll
I0430 12:42:18.355240 201c OrthancPlugins.cpp:3221] (plugins) Plugin making REST GET call on URI /instances/153063d1-0d2713d5-641fa00a-305ddb8c-f4759aa1/metadata/4202 (built-in API)
T0430 12:42:18.355240 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0430 12:42:18.356244 JOBS-WORKER-3 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll

```

---

<div class="post-metadata">

### Author: ![dnudelman](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@dnudelman](https://discourse.orthanc-server.org/u/dnudelman)
#### Post date: [April 30, 2024, 5:21pm UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644/2 "2024-04-30T17:21:02Z")

</div>

Figured I should add that when I say a long time I mean about an hour for 1 patient with 2 studies.

---

<div class="post-metadata">

### Author: ![alainmazy](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/alainmazy/32/1576_2.png) [@alainmazy](https://discourse.orthanc-server.org/u/alainmazy)
#### Post date: [May 2, 2024, 4:07pm UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644/3 "2024-05-02T16:07:23Z")

</div>

Hi,

All I can say from the logs is the job that each deletion takes 17 seconds:

```auto
I0430 12:41:44.820654 JOBS-WORKER-3 FilesystemStorage.cpp:266] Deleting attachment "1fcb1ce7-00c6-4941-af21-b7756e433069" of type 1
I0430 12:42:01.580050 JOBS-WORKER-3 FilesystemStorage.cpp:266] Deleting attachment "65ca2323-334f-4ddf-9df7-99cc98cf1fe9" of type 1
I0430 12:42:18.347267 JOBS-WORKER-3 FilesystemStorage.cpp:266] Deleting attachment "72b015d7-49f3-4cd3-a62e-c85d767fcbd6" of type 1

```

It might be related to [this topic](https://discourse.orthanc-server.org/t/image-insert-are-too-slow-databse-performance-too-poor-when-using-mysql-mariadb/3820/19) but I actually never got the final feedback from @csimon3 so the topic is on hold right now.

Best regards,

Alain.

---

<div class="post-metadata">

### Author: ![csimon3](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/csimon3/32/1516_2.png) [@csimon3](https://discourse.orthanc-server.org/u/csimon3)
#### Post date: [May 2, 2024, 4:25pm UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644/4 "2024-05-02T16:25:25Z")

</div>

Hi Alain,

Sorry for the delay.

We will put this item back in front of the queue since it is almost done and unit tests passed. We just want to do a new full testing and will let you know the outcome.

Best regards,

Cedric.

---

<div class="post-metadata">

### Author: ![dnudelman](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@dnudelman](https://discourse.orthanc-server.org/u/dnudelman)
#### Post date: [May 2, 2024, 4:34pm UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644/5 "2024-05-02T16:34:57Z")

</div>

The instance of orthanc is only 70k studies just using it as an intermediary for a migration. Would I be better off converting away from mysql and using the sqllite db?

---

<div class="post-metadata">

### Author: ![alainmazy](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/alainmazy/32/1576_2.png) [@alainmazy](https://discourse.orthanc-server.org/u/alainmazy)
#### Post date: [May 2, 2024, 4:43pm UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644/6 "2024-05-02T16:43:14Z")

</div>

Well 70k studies is not that small and we usually advise to use postgresql from 5K-10K DB but that’s just a rule of thumb. SQlite might actually work very well.

But you’ll have to re-ingest everything since there are no conversion script from one DB to the other ☹

---

<div class="post-metadata">

### Author: ![dnudelman](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@dnudelman](https://discourse.orthanc-server.org/u/dnudelman)
#### Post date: [May 3, 2024, 1:35pm UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644/7 "2024-05-03T13:35:43Z")

</div>

Ahh and I might have a storage constraint on the server to have both live at the same time. Any other ideas to make this go faster? Trying to wrap up this migration process and only being able to do 1 patient ever hour will take a very long time.

---

<div class="post-metadata">

### Author: ![alainmazy](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/alainmazy/32/1576_2.png) [@alainmazy](https://discourse.orthanc-server.org/u/alainmazy)
#### Post date: [May 3, 2024, 1:53pm UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644/8 "2024-05-03T13:53:59Z")

</div>

> [@dnudelman](#):
>
> Any other ideas to make this go faster?

Well, if you are using Docker, I have built an image with the patch suggested by @csimon3. If not, what platform are you using ?

---

<div class="post-metadata">

### Author: ![dnudelman](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@dnudelman](https://discourse.orthanc-server.org/u/dnudelman)
#### Post date: [May 3, 2024, 2:06pm UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644/9 "2024-05-03T14:06:52Z")

</div>

I am on a windows server

---

<div class="post-metadata">

### Author: ![alainmazy](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/alainmazy/32/1576_2.png) [@alainmazy](https://discourse.orthanc-server.org/u/alainmazy)
#### Post date: [May 3, 2024, 2:35pm UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644/10 "2024-05-03T14:35:48Z")

</div>

You can then:

- download the “mainline” version from [here](https://orthanc.uclouvain.be/downloads/windows-64/orthanc-mysql/index.html)
- copy the file in `C:\Program Files\Orthanc Server\Plugins`,
- stop your Orthanc service,
- rename the current `OrthancMySQLIndex.dll` into `OrthancMySQLIndex.dll_old` (it must not have a .dll extension or it will be loaded by Orthanc)
- rename `OrthancMySQLIndex-mainline.dll` into `OrthancMySQLIndex.dll`
- restart the Orthanc service

Please tell us if this improves things on your side …

---

<div class="post-metadata">

### Author: ![dnudelman](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@dnudelman](https://discourse.orthanc-server.org/u/dnudelman)
#### Post date: [May 3, 2024, 4:06pm UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644/11 "2024-05-03T16:06:52Z")

</div>

```auto
I0503 12:04:45.307618 HTTP-20 JobsRegistry.cpp:794] New job submitted with priority 0: 911bc0cb-bf34-4e70-96a5-a0fae044b6f7
I0503 12:04:45.307618 JOBS-WORKER-2 JobsEngine.cpp:134] (jobs) Executing job with priority 0 in worker thread 2: 911bc0cb-bf34-4e70-96a5-a0fae044b6f7
I0503 12:04:45.307618 JOB-INS-WORK-56 ResourceModificationJob.cpp:205] Modifying instance in a job: 0010f8ab-cc9c8d35-72e85255-88e4a216-66175042
T0503 12:04:45.307618 JOB-INS-WORK-56 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
I0503 12:04:45.307618 JOB-INS-WORK-57 ResourceModificationJob.cpp:205] Modifying instance in a job: 02f75cc1-8ce55bd9-3fffc5bf-f93ff86c-2f4840b3
I0503 12:04:45.307618 JOB-INS-WORK-58 ResourceModificationJob.cpp:205] Modifying instance in a job: 060dbaa3-6243030c-388bbb39-3f442e9d-e0f6150b
I0503 12:04:45.307618 JOB-INS-WORK-59 ResourceModificationJob.cpp:205] Modifying instance in a job: 079f5946-121a450a-88e9c6a2-544db162-85f844f7
I0503 12:04:45.308587 JOB-INS-WORK-60 ResourceModificationJob.cpp:205] Modifying instance in a job: 0c1db79c-c2a9eb0b-01a7b6e6-600cdc94-a559c5b8
I0503 12:04:45.308587 JOB-INS-WORK-61 ResourceModificationJob.cpp:205] Modifying instance in a job: 1499523a-081a77fc-2cf90a52-1b83a6d0-c5263c2e
I0503 12:04:45.308587 JOB-INS-WORK-62 ResourceModificationJob.cpp:205] Modifying instance in a job: 15a57702-5e548ca9-f7b9b14e-da86b77f-39084c21
I0503 12:04:45.308587 JOB-INS-WORK-63 ResourceModificationJob.cpp:205] Modifying instance in a job: 1ac7c022-5e8bdef3-53a67020-f0179a3b-182ae752
T0503 12:04:45.314169 JOB-INS-WORK-56 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0503 12:04:45.314722 JOB-INS-WORK-56 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0503 12:04:45.314929 JOB-INS-WORK-56 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
T0503 12:04:45.314929 JOB-INS-WORK-56 OrthancPlugins.cpp:5882] (plugins) Calling service 40 from plugin C:\Program Files\Orthanc Server\Plugins\OrthancMySQLIndex.dll
W0503 12:04:45.315436 JOB-INS-WORK-56 ResourceModificationJob.cpp:224] An error occurred while executing a Modification job on instance 0010f8ab-cc9c8d35-72e85255-88e4a216-66175042: 
E0503 12:04:45.315436 JOB-INS-WORK-56 ThreadedSetOfInstancesJob.cpp:273] Error in a non-permissive job: Unknown resource

```

here are the logs, I get an error now when I run the script saying “ThreadedSetOfInstancesJob.cpp:273] Error in a non-permissive job: Unknown resource”

---

<div class="post-metadata">

### Author: ![alainmazy](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/alainmazy/32/1576_2.png) [@alainmazy](https://discourse.orthanc-server.org/u/alainmazy)
#### Post date: [May 4, 2024, 8:31am UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644/12 "2024-05-04T08:31:36Z")

</div>

Is this reproducible ? Does it happen with all studies ?  
Can you access the instance in error ?  
Can you provide a way to reproduce it on a separate system ?

---

<div class="post-metadata">

### Author: ![dnudelman](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@dnudelman](https://discourse.orthanc-server.org/u/dnudelman)
#### Post date: [May 4, 2024, 10:24pm UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644/13 "2024-05-04T22:24:13Z")

</div>

If I call the modify patient endpoint on any patient with the following query it happens.

```auto
    print(patient_id, new_patient_id)
    # Define headers for the request (e.g., content type)
    headers = {'Content-Type': 'application/json'}
    modify_endpoint = f'{orthanc_url}/patients/{patient_id}/modify'
    command = {
        'Replace': {
            'PatientID': str(new_patient_id),
        }, 'Force': True,
        'KeepSource': False
    }
    # Send POST request to modify the instance
    response = requests.post(modify_endpoint, data=json.dumps(command), headers=headers)
    if response.status_code == 200:
        return True
    else:
        return False

```

where patient ID = the internal orthanc id  
and new patient ID = new patient ID id like to change the dicom patient id to.

---

<div class="post-metadata">

### Author: ![alainmazy](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/alainmazy/32/1576_2.png) [@alainmazy](https://discourse.orthanc-server.org/u/alainmazy)
#### Post date: [May 6, 2024, 1:41pm UTC](https://discourse.orthanc-server.org/t/modifying-patient-takes-a-long-time-keepsource-false/4644/14 "2024-05-06T13:41:25Z")

</div>

With the below docker-compose setup which uses the same version as you, I was able to modify a patient.

So, please, if you think this is an Orthanc bug, provide us with [a full reproducible setup](https://orthanc.uclouvain.be/book/users/support.html#discussing-a-minimal-working-example) for us to investigate.

```auto
version: "2"
services:
  orthanc:
    image: osimis/orthanc:improve-mysql-delete-unstable
    depends_on: [index]
    ports: ["104:4242", "80:8042"]
    volumes: ["storage:/var/lib/orthanc/db:Z"]
    environment:
      ORTHANC __MYSQL__ HOST: index
      ORTHANC __MYSQL__ USERNAME: test-user
      ORTHANC __MYSQL__ DATABASE: orthanc
      ORTHANC __MYSQL__ PASSWORD: foo
      ORTHANC__REGISTERED_USERS: |
        {"demo": "demo"}
      ORTHANC__OVERWRITE_INSTANCES: true

    restart: unless-stopped
  index:
    image: mysql:8.0
    ports: ["3306:3306"]
    command:
      [
        mysqld,
        --default-authentication-plugin=mysql_native_password,
        --log-bin-trust-function-creators=1,
      ]
    volumes: ["index:/var/lib/mysql:Z"]
    environment:
      MYSQL_PASSWORD: foo
      MYSQL_USER: test-user
      MYSQL_DATABASE: orthanc
      MYSQL_ROOT_PASSWORD: foo-root
      
    restart: unless-stopped
volumes:
  storage:
  index:

```
