Create copy of dicoms files

Hi everyone,

I’m new with Orthanc and I’m using the docker version (basic one without plugins).

My use case is pretty simple, I want to use Orthanc as a Dicom server that will receive some dicoms.
I want to be notified when a new dicom has been saved, from what I’ve seen so far in the docs, I can poll the /changes api and check for changes.

I’m experiencing two issues with this :

  • First, the call to localhost:8042/changes gives me a 401, how to deal with it?
  • Second, I would like to know if there is any notification system (socket for example) ?

If there isn’t a notification system (other than the polling), I would like to watch the db folder where the dicoms are saved.
Since you are using a specific way to save the dicoms (based on their uids), I was wondering if there is a setting where I can input an other path to save the dicoms, so I can watch this folder?

Thanks for your help

I have found the best way to do this is with notifications. Using a Lua script, OnStableStudy, you can send a http post or get notification to anywhere you want. As it is a Lua script, you could do to a file or something like that also, if you wanted. Example code placed in OnStableStudy:

patient = ParseJson(RestApiGet(‘/studies/’ … studyId … ‘/shared-tags?simplify’))
local answer = HttpGet(‘http://localhost:8282/?patientId=’ … patient[‘PatientID’] … ‘&description=’ … urlencode(varDescription) … ‘&RetrieveAETitle=’ … patient[‘RetrieveAETitle’] … ‘&AccessionNumber=’ … patient[‘AccessionNumber’] … ‘&StudyDate=’ … tags[‘StudyDate’] … ‘&StudyTime=’ … tags[‘StudyTime’] … ‘&PriorAE=’ … varPrior … ‘&StudyUID=’ … tags[‘StudyInstanceUID’] … ‘&Originator=’ … varOriginator … ‘&StudyID=’ … studyId)

Thanks for your quick answer.

I’m still confused on what exactly is ‘OnStableStudy’ ? I checked and it is under Resources/Samples/LUA/, are you saying that whatever is in this folder is executed by orthanc? If that’s the case, it’s pretty awesome.
In my use case, I want to transfer the dicoms to NodeJS applications/APIs

Ok, then there are two options, OnReceivedInstance, you can forward the instance, without having to wait for the whole study, or OnStableStudy, check out this page:

There are example if how you can HTTP Post the images, which you could probably do to a NodeJS Application.

The autorouting seems to be exactly what I’m looking for !

On the API tho :

function OnStoredInstance(instanceId, tags, metadata)
  Delete(SendToModality(instanceId, 'sample'))

I seem to have access only to the instanceId, how could I send the whole dicom file ?

function OnStoredInstance(instanceId, tags, metadata)
  RestAPIPOST('', instanceId, 'sample')) #get the whole dicom file here?

I dug deeper and you may not be able to post the file itself outside of Orthanc, I’ll let someone from Orthanc confirm. Just confirming you aren’t running an Orthanc receiver (peer) on NodeJS?

Here is a sample Lua script to forward the just-received DICOM instance to another external REST API:

function OnStoredInstance(instanceId, tags, metadata)
local dicom = RestApiGet(‘/instances/’ … instanceId … ‘/file’)
HttpPost(‘http://localhost:5000/’, dicom)


Very nice, I think I can work with that ! Thanks @Bryan and @Sebastien

When I try to get the return of HttpPost, it’s always empty string… I check the code there but answer is empty string (my express api returns a string ‘ok’)

Looks like issue 77 that was fixed in Orthanc 1.4.0:

Please make sure you use the latest version of Orthanc.

I’m using latest with Docker “FROM jodogne/orthanc”

This is the code that I am using :

local apiPostURL = os.getenv(“API_POST_URL”)

local dicom = RestApiGet(“/instances/” … instanceId … “/file”)

local headers = {
[‘Authorization’] = ‘Bearer token…’

local status = HttpPost(‘http://localhost:3000/test’, dicom, headers)
if status ~= ‘ERROR’ then
print(‘Successfully sent dicom, not deleting the file…’)

Status is always an empty string, or if an error has occurred (inside the HttpPost function) the status value is nil

You have an issue in your back-end server. The following setup works properly:

Orthanc configuration:

“LuaScripts” : [ “sample.lua” ]

Lua script:

function OnStoredInstance(instanceId, tags, metadata)
local dicom = RestApiGet(‘/instances/’ … instanceId … ‘/file’)
local status = HttpPost(‘http://localhost:5000/’, dicom)

Sample server in Python Flask:

from flask import Flask
from flask import request
app = Flask(name)

@app.route(‘/’, methods = [ ‘POST’ ])
def store():
with open(‘/tmp/flask.dcm’, ‘wb’) as f:
return ‘ok’

if name == “main”: = True, host = ‘’)

Output of Orthanc when receiving a DICOM instance:

W0111 16:23:25.575585 main.cpp:712] Orthanc has started
W0111 16:23:27.596104 LuaContext.cpp:103] Lua says: ok

Where the “ok” string comes from the Flask server.

This is my backend api (nodejs) :


  • Test endpoint for the dicom server auto routing
    */‘/dicom/test’, (req, res) => {'received new dicom ! size : ’ + req.headers[‘content-length’]);

I see correctly the logs on the server…

Please post the full code, so that we can reproduce.

@Sebastien, nevermind it works now… I had an ‘async’ remaining in my route, now it’s working fine