Rest API of C-FIND can search with no of limit for work list?

Hi
I am setting orthanc server and trying to get worklist from the orthanc server with below command.

$ curl http://localhost:8042/modalities/sectra/find-worklist -d '{"PatientID":""}'

And now I am able to get the work list but not able to add any limitation for the search results.Is there any way to add no of search results? I tried to use limit keyword but didn't get success.Please let me know is there any possible ways there to limit number of search results for work list.

Thanks in advance,
Rekha devi

Not sure if you are interested in using Python Scripts. To just truncate the result set, I think you can do something like this. The GetTagGroupFromKey you don’t need really, or some of the libraries. It just uses the native find-worklist, although you would have to substitute “sectra” for ORTHANC. There is a way to pass a wildcard for the modality, e.g. /MWL/{}/find. You would call it like before, but now you add the LIMIT:

Maybe someone knows how to use the wildcard for a script like this ? It would also be nice if the result set returned more than just the CharSet and the PatientID.

curl http://localhost:8042/MWL/ORTHANC/find -d ‘{“Query”: {“PatientID”:“”,“StudyDate”:“”}, “LIMIT”:4}’

That seems to work on my system, but the response have this format:

{
“SpecificCharacterSet”: “ISO_IR 192”,
“PatientID”: “‘PatientID’”
},

import json
import orthanc
#import pydicom, not sure how to load that ?
import re
import platform
import logging

def GetTagGroupFromKey(key):

lookup = {

“AccessionNumber”: “MainDicomTags”,
“StudyDate”: “MainDicomTags”,
“AccessionNumber”: “MainDicomTags”,
“StudyDescription”: “MainDicomTags”,
“InstitutionName”: “MainDicomTags”,
“ReferringPhysicianName”: “MainDicomTags”,
“RequestingPhysician”: “MainDicomTags”,
“StudyTime”: “MainDicomTags”,
“StudyID”: “MainDicomTags”,
“StudyInstanceUID”: “MainDicomTags”,
“PatientBirthDate”: “PatientMainDicomTags”,
“PatientSex”: “PatientMainDicomTags”,
“PatientID”: “PatientMainDicomTags”,
“PatientName”: “PatientMainDicomTags”
}
return lookup[key]

#curl http://localhost:8042/modalities/sectra/find-worklist -d ‘{“PatientID”:“”}’

def FindMWLByQuery(output, uri, **request):
if request[‘method’] != ‘POST’:
output.SendMethodNotAllowed(‘POST’)
else:

query = json.loads(request[‘body’])
limit = query[‘LIMIT’]
print limit
print query[‘Query’]
mwls = orthanc.RestApiPost(‘/modalities/ORTHANC/find-worklist’, json.dumps(query[‘Query’]))
mwls = json.loads(mwls)
mwls = mwls[0 : limit]
output.AnswerBuffer(json.dumps(mwls, indent = 3), ‘application/json’)

if int(platform.python_version_tuple()[0]) < 3:
logging.warning("Suggest using Python 3.x.x, using: " + platform.python_version())
else:
print(platform.python_version_tuple()[0])

orthanc.RegisterRestCallback(‘/MWL/ORTHANC/find’, FindMWLByQuery)

Need {id} for the Modality

Hi
Thanks for quick reply
I need for find-worklist and am trying first post man later using qt code.

I have started trying orthanc server since 3 weeks.
Now I am trying to get worklist search using postman app as u said above.
http://localhost:8042/modalities/.../find-worklist -d '{"PatientID":""}'

but I need to limit the search number of search results.

My questions are

1.is there any way to limit max search limits from configuration file for worklist search?

2.can we set any limit while requesting through the rest api.

(For findscu there is cancelling option after receiving the particular no of results, similarly can we do from the rest api also? Rest api results as json at a time. If no of results crosses limit of json file reply size app can crash.Tried with Limit keyword,but not accepting in app and throwing wrong Dicom tag, might be treating that also as a Dicom tag)

Thanks in advance
Rekha devi

After getting reply will be having lots of results.
If in some worst case if it reaches max,app can be crash,so can we limit while initiate querry? Can define any boundary limits for reply json?

You can add Python Scripts to the Orthanc Instance in the Config.json file.

That python script just extends the native find-worklist and allows you to specify a limit in the query. It then returns the truncated results. Funny, but I was just working on something similar to do queries on Studies.

There is a reference about using Python scripts here:

https://book.orthanc-server.com/plugins/python.html?highlight=python

BTW, what is a sample findscu from the CLI to query the Worklist and echo the results to terminal, if there is one ?

Thanks,will check once with python.
I tried cmd lind using dcmtk tools, findscu -w -k "<Dicom tags which we need>" ip port

Thanks Rekhadevi

Thanks alot stephen, able to use the limit key with python script. it was very much helpful.
It’s a nice learning and joyful experience with orthanc for these 3 weeks :slight_smile: .

You are welcome. Just learning myself, for a few months now. Orthanc is really nice to work with. Documentation is better than some commercial products.

Not sure what you are working on, but I put together a little demo using the ServeFolders Plug-In. I wasn’t really aware of what that allowed you to do. It has a lot of potential for some things. With AJAX calls and Python plug-in you can do a lot.

I actually might look into implementing some stuff that I have in another project, like reporting. I have this other project that is sort of like a mini-RIS. It might be possible to move a reporting feature and some HL7 stuff into the ServeFolders site since Python opens up a lot of possibilities, and the way I have it I am using OpenResty as a proxy server. You an actually attach PDF files to studies with Orthanc.

Just learning Python. If it can make CURL calls via a script (not the command line), that would be pretty interesting.

I have an authentication method also, but looking for a better way, like OAuth maybe… OpenResty is running PHP. Not sure it can support Python as well.

Finally have this working: https://sias.dev:8000/browsestudies/index.html, pagination, search tools, Osimis and OHIF viewers, archive and media downloads. There is also a sort of developers page, https://sias.dev:8000/browsestudies/restapi.html. I’m going to leave it open for a couple of days since there are test studies (1 is mine).

Hello,

The maximum number of results returned by a C-FIND query (e.g. for worklist) must be configured on the C-FIND SCP (i.e. on the remote server).

If the remote SCP is itself an Orthanc server, you can configure this by setting the “LimitFindResults” and “LimitFindInstances” configuration option:
https://book.orthanc-server.com/users/configuration.html

If you can’t configure the remote SCP, as pointed out by Stephen, you can implement a C/C++/Python plugin to add a route in the REST API of Orthanc that truncates the results:
https://book.orthanc-server.com/developers/creating-plugins.html#creating-plugins

Sébastien-

Correction: The configuration option to be used in the sample modality worklists plugin is “LimitAnswers” (not “LimitFindResults” and “LimitFindInstances” as written above, as those are not related to worklists). This option will be new in forthcoming release 1.7.3 of Orthanc:
https://book.orthanc-server.com/plugins/worklists-plugin.html