# Prefetching Orhtanc pancs to AW server

**URL:** https://discourse.orthanc-server.org/t/prefetching-orhtanc-pancs-to-aw-server/5696
**Category:** General
**Created:** [March 28, 2025, 5:34pm UTC](https://discourse.orthanc-server.org/t/prefetching-orhtanc-pancs-to-aw-server/5696 "2025-03-28T17:34:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Relam](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/r/a88e57/32.png) [@Relam](https://discourse.orthanc-server.org/u/Relam)
#### Post date: [March 28, 2025, 5:34pm UTC](https://discourse.orthanc-server.org/t/prefetching-orhtanc-pancs-to-aw-server/5696/1 "2025-03-28T17:34:17Z")

</div>

Hello,  
I am a radiologist and my computer skills are average.  
I’m looking for a solution for prefetching. I installed Orhtanc as a PACS and I view the exams on an AW server (GE) client.  
Is it possible for Orhtanc to search the history of the same patient’s ID and push all the old exams directly to the AW server when it receives a new study?  
Thank you very much.

---

<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: [April 1, 2025, 8:36am UTC](https://discourse.orthanc-server.org/t/prefetching-orhtanc-pancs-to-aw-server/5696/2 "2025-04-01T08:36:57Z")

</div>

Hi @Relam,

A while ago, I made this [sample](https://github.com/orthanc-server/orthanc-setup-samples/blob/master/windows/prefetching/README.md) that implements prefetching but, in this sample, Orthanc is acting as a middleman between a PACS and a Workstation. So you’ll have to adapt the [lua script](https://github.com/orthanc-server/orthanc-setup-samples/blob/master/windows/prefetching/prefetching.lua) to your use case.

If you need support to adapt the script and configure your system, there are a bunch of [professionals who can provide support](https://orthanc.uclouvain.be/book/users/support.html#finding-professional-assistance).

Hope this helps,

Alain.

---

<div class="post-metadata">

### Author: ![benjamin.golinvaux](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/benjamin.golinvaux/32/1508_2.png) [@benjamin.golinvaux](https://discourse.orthanc-server.org/u/benjamin.golinvaux)
#### Post date: [April 1, 2025, 9:08am UTC](https://discourse.orthanc-server.org/t/prefetching-orhtanc-pancs-to-aw-server/5696/3 "2025-04-01T09:08:48Z")

</div>

Hello,

The following simple Python script will forward all the studies of the same patient upon receiving a stable study (to a modality whose symbolic name is `local1_dicom`, in this case). This includes the study just received.

This is done synchronously, without a job, and there is no error handling, so this is clearly not production-ready.

HTH

```python

import json
import orthanc

def OnStableStudy(study_id: str):

    study_data = json.loads(orthanc.RestApiGet(f"/studies/{study_id}"))

    orthanc.LogInfo(f"TRANSFER_20250401: {study_data=}")
   
    patient_uuid = study_data["ParentPatient"]

    orthanc.LogInfo(f"TRANSFER_20250401: study_id: {study_id=} belongs to {patient_uuid=}")

    payload = {
        "Resources": [patient_uuid]
    }

    orthanc.LogInfo(f"TRANSFER_20250401: About to POST to /store with {payload=}")

    try:
        store_response = json.loads(orthanc.RestApiPost("/modalities/local1_dicom/store", json.dumps(payload)))
        orthanc.LogInfo(f"TRANSFER_20250401: {store_response=}")
    except Exception as exc:
        orthanc.LogError(f"TRANSFER_20250401: Error storing patient {payload=}: {exc=}")

def OnChange(changeType, level, resource):
    if changeType == orthanc.ChangeType.STABLE_STUDY:
        orthanc.LogInfo(f"STABLE_STUDY: {resource=}")
        OnStableStudy(resource)

orthanc.RegisterOnChangeCallback(OnChange)

```
