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?
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:
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: http://book.orthanc-server.com/users/lua.html
There are example if how you can HTTP Post the images, which you could probably do to a NodeJS Application.
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)
end
local dicom = RestApiGet(“/instances/” … instanceId … “/file”)
local headers = {
[‘Authorization’] = ‘Bearer token…’
}
local status = HttpPost(‘http://localhost:3000/test’, dicom, headers)
print(string.len(status));
PrintRecursive(status)
if status ~= ‘ERROR’ then
print(‘Successfully sent dicom, not deleting the file…’)
–Delete()
else
print(status)
end
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)
print(status)
end
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:
f.write(request.get_data())
return ‘ok’
if name == “main”:
app.run(debug = True, host = ‘0.0.0.0’)
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.
Test endpoint for the dicom server auto routing
*/
api.post(‘/dicom/test’, (req, res) => {
log.info('received new dicom ! size : ’ + req.headers[‘content-length’]);
console.log(req.headers);
res.send(‘sup?’);
});