I have a Orthanc server that checks when a study is stable, and runs some scripts when stable event is detected.
These scripts generate new instances which are uploaded into the Study. And here, the problem. After “StableAge” seconds, the scripts are ran again, and an infinite loop appears. How could I avoid these infinite loop using the Lua scripts?
Thanks in advance.
Off the top of my head, I would look to write something to the metadata for example to indicate the script has been run once, then do a filter on OnstableStudy to check for that metadata and if exists, don’t run again.
Thanks Robert. But origin is only available when deciding to store or not a new Instance. How can I store the generated instance but not call the stable event because of that addition?
Hmm you’re right.
Maybe install a 2nd Orthanc, do all the processing and transmit the whole new study to the main Orthanc, then delete?
The rest API is stateless, but you need state for your problem, so you probably need to add a layer of logic. You could use a python script that monitors “changes” and discards changes it has already handled. A 2-node setup as suggested by Robert could do it too. I use a tiered setup like that for anonymization queues: stable on the ingress node triggers anonymization and forward. Stable on the terminal node is ignored.
In your OnStableStudy script, check the associated meta data. I used the ‘AnonymizedFrom’ and ‘ModifiedFrom’ tags to weed out already anonymized studies:
local loStudyMeta = ParseJson(RestApiGet(‘/studies/’ … aoStudyID, false))
if (not loStudyMeta[‘ModifiedFrom’]) and (not loStudyMeta[‘AnonymizedFrom’]) then
… proceed with anonymization lua …
In fact, the OnStableStudy hook should already provide the meta data as the third incoming argument. So you don’t necessarily have to retrieve the information yourself. But in general, when you want to know whether a study is anonymized or modified, you can pull down the meta data and check it.