4
votes

I am trying to anonymize images before sending them to another Orthanc server. According to the documentation on anonymization, Orthanc can anonymize images through the REST api: http://book.orthanc-server.com/users/anonymization.html

Orthanc allows to anonymize a single DICOM instance and to download the resulting anonymized DICOM file. Example:

$ curl http://localhost:8042/instances/6e67da51-d119d6ae-c5667437-87b9a8a5-0f07c49f/anonymize -X POST -d '{}' > Anonymized.dcm

According to the documentation page on Lua scripts, Lua scripts can take advantage of the REST API:

Lua scripts have full access to the REST API of Orthanc

The page goes on to describe how to use call the REST API from Lua:

functions:

    RestApiGet(uri, builtin)
    RestApiPost(uri, body, builtin)
    RestApiPut(uri, body, builtin)
    RestApiDelete(uri, builtin)

The uri arguments specifies the URI against which to make the request, and body is a string containing the body of POST/PUT request.

This means that I should be able to call the REST API from Lua by combining the functions above.

However when calling the RestApiPost as described in the documentation.

instances = RestApiGet(http://localhost:8042/instances, true)

I get the following error

E0313 17:40:40.851840 LuaScripting.cpp:358] Lua: Badly formatted URI
E0313 17:40:40.851884 LuaScripting.cpp:361] Lua: Error in RestApiPost() for URI: http://localhost:8042/instances/b38a8ef0-909f8ac0-7eca907a-75c98187-8e5339f4/anonymize

It's worth noting that I can call this endpoint correctly from curl and from my browser. Removing the 'http://' section didn't solve the issue.

1

1 Answers

3
votes

The RestApiGet function and its family expect the developer to format the uri parameter without 'http://localhost:8042' as follows:

'/instances'

These functions only work for using the REST API provided by the Orthanc the Lua script is running on, so it already knows that you will use the localhost and it will use the correct http scheme and 8042 port automatically.

As described in http://book.orthanc-server.com/users/lua.html#general-purpose-functions, the function HttpGet(url, headers) and its family are the general form of this function and allow the developer to query any http endpoint.