comparison Sphinx/source/plugins/python/paging.py @ 704:ba2403ebd4b7

moving python samples in separate files (3)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 11 Jun 2021 10:24:08 +0200
parents
children
comparison
equal deleted inserted replaced
703:a589668768d7 704:ba2403ebd4b7
1 import json
2 import orthanc
3
4 def GetStudyDate(study):
5 if 'StudyDate' in study['MainDicomTags']:
6 return study['MainDicomTags']['StudyDate']
7 else:
8 return ''
9
10 def SortStudiesByDate(output, uri, **request):
11 if request['method'] == 'GET':
12 # Retrieve all the studies
13 studies = json.loads(orthanc.RestApiGet('/studies?expand'))
14
15 # Sort the studies according to the "StudyDate" DICOM tag
16 studies = sorted(studies, key = GetStudyDate)
17
18 # Read the limit/offset arguments provided by the user
19 offset = 0
20 if 'offset' in request['get']:
21 offset = int(request['get']['offset'])
22
23 limit = 0
24 if 'limit' in request['get']:
25 limit = int(request['get']['limit'])
26
27 # Truncate the list of studies
28 if limit == 0:
29 studies = studies[offset : ]
30 else:
31 studies = studies[offset : offset + limit]
32
33 # Return the truncated list of studies
34 output.AnswerBuffer(json.dumps(studies), 'application/json')
35 else:
36 output.SendMethodNotAllowed('GET')
37
38 orthanc.RegisterRestCallback('/sort-studies', SortStudiesByDate)