/tools/find MetadataQuery

Hi. I need to get the “latest” studies. LastUpdate looks like a good choice for this task. I saw the MetadataQuery parameter on /tools/find, but when I try to use it

-d '{"Level": "Study", "MetadataQuery": {"LastUpdate": "20250314"}}'
"Details" : "Field \"Query\" is missing, or should be a JSON object",

It needs the Query parameter. I don’t have any query to give, but lets do it.

-d '{"Level": "Study", "MetadataQuery": {"LastUpdate": "20250314"}, "Query": {}}'
returns all our studies

It looks like MetadataQuery is ignored. Or maybe I don’t know how to use it?

You might be best to use the changes api (Orthanc REST API) and page backwards from the last change to find the most recent new instances.

Hth james

1 Like

Actually, the LastUpdate is a date time so you should use a filter like

{"LastUpdate": "20250314T*"}

But, if it is ignored, that probably means that you don’t have “ExtendedFind” which is available only with PG and SQLite and Orthanc 1.12.5

HTH,

Alain

1 Like

I wasn’t aware that this feature was just released! It does work perfectly when I use the right version :slight_smile: Thank you.

@alainmazy Is it possible to add the date range, like we can do with "Query"?

"Query": {"StudyDate": "20250330-20250331"}

In fact, I tested and it doesn’t seem to work, with or without T*. Should it work? Do you plan to add this feature?

I might as well explain my actual goal. On StableStudy, we tell an external server about a new study. For some reason, the server might be offline. StableStudy won’t run again when the server is online, so I coded a cron job to compare the studies on the server and on Orthanc. This looks like a good plan, but getting the studies on Orthanc intelligently is somewhat harder.

  • Filtering by StudyDate if wrong, because a client might send us an older study, but it’s still new for us. We don’t really care when the study was acquired, only when we received it.
  • Using a StudyDate range (see last reply) would do the job, but it doesn’t work. I need to do 2 requests?
  • A filter like “all studies updated in the last 10 minutes”, or “all studies, sort by LastUpdate, limit 20” would be perfect, but I can’t seem to find the required feature.

When I open OE2, it looks like the studies are sorted by LastUpdate, but I’m not entirely sure. It’s written “Liste des examens les plus récents”, which might mean that they are sorted by StudyDate. Can you please confirm?

This is actually exactly what OE2 is doing (provided that you are using Orthanc 1.12.5+ and SQLite or PostgreSQL):

Hope this helps (and works for you)

Alain

1 Like

Right, this helped me find getMostRecentStudiesExtended in orthancApi.js where we can see a query like this:

{
    "Level": "Study",
    "Limit": 10,
    "Query": {},
    "OrderBy": [{
        "Type": "Metadata",
        "Key": "LastUpdate",
        "Direction": "DESC"
    }]
}

So, no Query, no MetadataQuery, only an OrderBy.

Thank you again Alain!