modifying StudyDescription

One of our scanners doesn’t populate StudyDescription enough for my liking - it doesn’t include enough levels of folders, so instead of “Site Investigator Study” I just get “Site Investigator”.

As a workaround, I thought to use StudyComments, which can be populated by the tech at the scanner console.

I tried a Lua script which does:

replace[‘StudyDescription’] = tags[‘StudyDescription’] … ’ ’ … tags[‘RETIRED_StudyComments’]
ModifyInstance(instanceId, replace, remove, true)


which seems to modify StudyDescription the way I want, but, crucially, doesn’t update the Orthanc database! E.g., the new name doesn’t show up in the web interface in the left column. It seems it’s too late - the study is already in the database under the first name it got, and won’t be updated.

Is there a way to force that update? Or a better way to do this?


I think I know this one…you call reconstruct api.


Hmm. Is this going to be super expensive to do within OnStoredInstance?
Is there a better way?

“ModifyInstance()” only downloads a modified version of the instance, but doesn’t store it.

Use “RestApiPost()” on URI “/instances” to upload the modified instance.

Also, check out the following section:


Hmm, this still isn’t working. The instance gets modified, the original gets removed, but the database still shows the original StudyDescription.

function OnStoredInstance(instanceId, tags, metadata, origin)
if origin[‘RequestOrigin’] ~= ‘Lua’ then
if tags[‘StudyDescription’] ~= nil and tags[‘RETIRED_StudyComments’] ~= nil then
local replace = {}
replace[‘StudyDescription’] = tags[‘StudyDescription’] … ’ ’ … tags[‘RETIRED_StudyComments’]
local command = {}
command[‘Replace’] = replace
local modifiedFile = RestApiPost(‘/instances/’ … instanceId … ‘/modify’, DumpJson(command, true))
local modifiedId = ParseJson(RestApiPost(‘/instances/’, modifiedFile)) [‘ID’]
RestApiDelete(‘/instances/’ … instanceId)
RestApiPost(‘/instances/’, modifiedId, ‘/reconstruct’) – tried both with and without this line
print('appended StudyComments to StudyDescription for ’ … instanceId)

Oh, duh. I have , where I should have …


The error is at the last call of RestApiPost() in your Lua script. Replace:

RestApiPost(‘/instances/’, modifiedId, ‘/reconstruct’)


RestApiPost(‘/instances/’ … modifiedId … ‘/reconstruct’, ‘’)

The empty string corresponds to an empty POST body. Everything works properly on my side with this modification.