# Help to create a CUSTOM DICOM SERVER

**URL:** <https://discourse.orthanc-server.org/t/help-to-create-a-custom-dicom-server/5435>\
**Category:** General\
**Created:** [December 30, 2024, 4:15pm UTC](https://discourse.orthanc-server.org/t/help-to-create-a-custom-dicom-server/5435 "2024-12-30T16:15:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafaapcode](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/r/a698b9/32.png) [@rafaapcode](https://discourse.orthanc-server.org/u/rafaapcode)\
**Post date:** [December 30, 2024, 4:15pm UTC](https://discourse.orthanc-server.org/t/help-to-create-a-custom-dicom-server/5435/1 "2024-12-30T16:15:52Z")

</div>

Hello guys !

I want to create a DICOM server using the Docker image. This server will use S3 integration to send files directly to S3. However, I would like to know if it is mandatory to define PostgreSQL as storage or if I can use only S3. Another question: Is it possible to filter the images based on the AETITLE so that they are stored in different folders in my BUCKET?

I want only use the ORTHANC to receive the IMAGES and send to S3.

Another question is : When I create the Server with the S3 integration, how do I send the equipment images directly to ORTHANC? Can I test sending the images using DCMTK?

---

<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:** [January 3, 2025, 3:35pm UTC](https://discourse.orthanc-server.org/t/help-to-create-a-custom-dicom-server/5435/2 "2025-01-03T15:35:17Z")

</div>

Hello

You do not need to use Postgres with S3 : you can still use the default SQLite if you wish.

As far as I know, it is not possible to use several different buckets _in the same Orthanc instance_.

However, you should not hesitate to use several “routing” Orthanc instances for this purpose : you can maybe use a central dispatcher Orthanc that contains logic that dispatches the study to a different Orthanc based on the originating AET. These difference Orthanc instances would be configured with the different buckets you want to use.

Something like this maybe?:

```py
import orthanc
import json
import pprint

def OnChange(changeType, level, resourceId):
    if changeType == orthanc.ChangeType.STABLE_STUDY:
        print('Stable study: %s' % resourceId)

        instances_ids = json.loads(orthanc.RestApiGet(f"/studies/{resourceId}/instances"))
        instance_metadata = json.loads(orthanc.RestApiGet(f"/instances/{instances_ids[0]['ID']}/metadata?expand"))
        
        pprint.pprint(instance_metadata)
        if "CalledAET" in instance_metadata and "RemoteAET" in instance_metadata:
            print(f"This study orginates from {instance_metadata['RemoteAET']} and was addressed to {instance_metadata['CalledAET']}")
            orthanc.RestApiPost(f'/modalities/{instance_metadata['RemoteAET']}_modality/store', resourceId)
            # delete the study once it has been transferred
            # TODO: make this more robust and deal with failures during transfer.
            orthanc.RestApiDelete(f'/studies/{resourceId}')
        else: 
            # if not a DICOM-based transfer, do something?...
            ...

```

(there’s also an example of a C-Store filter that examines the incoming AET [here](https://github.com/orthanc-server/orthanc-setup-samples/blob/master/python-samples/filter-incoming-cstore-instance.py).)

---

<div class="post-metadata">

**Author:** ![rafaapcode](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/r/a698b9/32.png) [@rafaapcode](https://discourse.orthanc-server.org/u/rafaapcode)\
**Post date:** [January 3, 2025, 8:22pm UTC](https://discourse.orthanc-server.org/t/help-to-create-a-custom-dicom-server/5435/3 "2025-01-03T20:22:27Z")

</div>

Thanks Benjamin !!
