Getting studies by date range using RestAPI

1,750 views
Skip to first unread message

Rana Asim Wajid

unread,
Aug 17, 2017, 10:16:52 AM8/17/17
to Orthanc Users
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 ?

Thibault Nélis

unread,
Aug 18, 2017, 4:20:07 AM8/18/17
to orthan...@googlegroups.com
Hi,

On Thu, 2017-08-17 at 07:16 -0700, Rana Asim Wajid wrote:
> 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
--
Thibault Nélis <t...@osimis.io>
Osimis

Sébastien Jodogne

unread,
Aug 18, 2017, 7:29:45 AM8/18/17
to Orthanc Users
Hello,


On Thursday, August 17, 2017 at 4:16:52 PM UTC+2, Rana Asim Wajid wrote:
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:


Sébastien-

Rana Asim Wajid

unread,
Aug 18, 2017, 9:27:17 AM8/18/17
to Sébastien Jodogne, Orthanc Users

Thanks a bunch for your help

--

Regards,
Rana Asim Wajid

Walid Ali

unread,
Mar 5, 2020, 1:55:34 AM3/5/20
to Orthanc Users
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,

Sébastien Jodogne

unread,
Mar 5, 2020, 3:53:33 AM3/5/20
to Orthanc Users
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-

Sébastien Jodogne

unread,
Mar 5, 2020, 5:08:00 AM3/5/20
to Orthanc Users
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"}}'

Alain Mazy

unread,
Mar 5, 2020, 10:24:25 AM3/5/20
to Sébastien Jodogne, Orthanc Users
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\"}}"

--
You received this message because you are subscribed to the Google Groups "Orthanc Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orthanc-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/orthanc-users/7307febc-d6c0-4a00-a8ec-35477e15a5ff%40googlegroups.com.


--

Alain Mazy / Software Developer
a...@osimis.io / +32 494 31 67 27

Osimis

OSIMIS S.A. 
Quai Banning 6BE-4000 Liège 
www.osimis.io

Twitter LinkedIn


Walid Ali

unread,
Mar 6, 2020, 8:41:08 AM3/6/20
to Orthanc Users
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.
To unsubscribe from this group and stop receiving emails from it, send an email to orthan...@googlegroups.com.

Sébastien Jodogne

unread,
Mar 7, 2020, 5:30:34 AM3/7/20
to Orthanc Users
You'll have to delete them one by one, by making a sequence of calls such as:


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/":

Sébastien-
Reply all
Reply to author
Forward
0 new messages