Getting studies by date range using RestAPI

Is there any way to get all studies between a specified date range using /tools/find ? Im able to fetch studies for a single date using { “Expand”: true, “Level”: “Studies”, “CaseSensitive”: false, “Query”: { “StudyDate”: “20120929” }}

Also how can one tell what type of modality(CR,MR etc) performed a study ?

Hi,

Is there any way to get all studies between a specified date range
using /tools/find ? Im able to fetch studies for a single date using
{ "Expand": true, "Level": "Studies", "CaseSensitive": false,
"Query": { "StudyDate": "20120929" }}

AFAICT it uses standard DICOM date/time range matching[1].

$ http --body sandbox.local/tools/find Level=Studies Expand:=true
Query:='{"StudyDate": "2002-2007"}' | jq ..MainDicomTags.StudyDate
"20061005"
"20040305"

Also how can one tell what type of modality(CR,MR etc) performed a
study ?

You'll want to look at the relevant DICOM attribute[2] value, in this
case (0008,0060).

[1] http://dicom.nema.org/medical/dicom/current/output/chtml/part04/sec
t_C.2.2.2.5.html
[2] http://dicom.nema.org/medical/dicom/current/output/html/part06.html

Hello,

Is there any way to get all studies between a specified date range using /tools/find ? Im able to fetch studies for a single date using { “Expand”: true, “Level”: “Studies”, “CaseSensitive”: false, “Query”: { “StudyDate”: “20120929” }}

Here is a sample curl command-line to this end:

curl -X POST http://localhost:8042/tools/find -d ‘{“Level”:“Study”,“Expand”:true,“Query”:{“StudyDate”:“20120101-20121231”}}’

This command will return all studies whose “StudyDate” corresponds to year 2012 (i.e. lies in the inclusive range from January 1st, 2012 to December 31rd, 2012).

Also how can one tell what type of modality(CR,MR etc) performed a study ?

The “Modality (0008,0060)” DICOM tag is a series-related property (it is not at the study level). As a consequence, you will have to do another GET query against the “/studies/{id}/series” URI for each matching study, where “{id}” is the Orthanc identifier [1] that can be found in the “ID” field of the aforementioned curl result. For instance:

curl http://localhost:8042/studies/6e2c0ec2-5d99c8ca-c1c21cee-79a09605-68391d12/series

Sébastien-

[1] Orthanc identifiers — Orthanc Book documentation

Thanks a bunch for your help

Hello,

I’m having similar problem, I’m using orthanc compiled by osmis on windows what i want to do is select studies using data range and delete those studies, like I want to delete all studies older than 6 month. So I used this command

curl -X POST http://localhost:8042/tools/find -d ‘{“Level”:“Study”,“Expand”:true,“Query”:{“StudyDate”:“20200101-20200301”}}’

“Details” : “The body must contain a JSON object”,
“HttpError” : “Bad Request”,
“HttpStatus” : 400,
“Message” : “Bad request”,
“Method” : “POST”,
“OrthancError” : “Bad request”,
“OrthancStatus” : 8,
“Uri” : “/tools/find”

and it returns this error tried with port 4242 and It says curl: <52> Empty reply from server. I need help thanks for your time.

regards,

I have just tried your query against the Orthanc demo server, and it runs perfectly fine:

$ curl -X POST http://demo.orthanc-server.com:8042/tools/find -d ‘{“Level”:“Study”,“Expand”:true,“Query”:{“StudyDate”:“20120101-20200301”}}’

Make sure to upgrade Orthanc to the latest version.

Sébastien-

Sorry, copy/paste error, here is the correct command:

$ curl -X POST https://demo.orthanc-server.com/tools/find -d ‘{“Level”:“Study”,“Expand”:true,“Query”:{“StudyDate”:“20050101-20051231”}}’

It’s just an escaping problem in curl under Windows. You should run it this way:

curl -X POST https://demo.orthanc-server.com/tools/find -d “{"Level":"Study","Expand":true,"Query":{"StudyDate":"20050101-20051231"}}”

Thanks this has worked. Now I got a list of Patients but how do you delete the listed patients? I’m planning to keep only the patients done in the last 6 month and remove the others due to space limitation. Thanks.

You’ll have to delete them one by one, by making a sequence of calls such as:

$ curl -X DELETE http://localhost:8042/studies/66c8e41e-ac3a9029-0b85e42a-8195ee0a-92c2e62e

If this call, the ID is available in the result of the call to “/tools/find”.

If you want to avoid such a loop on the REST API, you could consider implementing a plugin that chains the call to “/tools/find” and the DELETEs on “/studies/”:
https://book.orthanc-server.com/developers/creating-plugins.html

Sébastien-