comparison Sphinx/source/plugins/python/excel.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 600da1bb6acd
comparison
equal deleted inserted replaced
703:a589668768d7 704:ba2403ebd4b7
1 import StringIO
2 import json
3 import orthanc
4 import xlwt
5
6 def CreateExcelReport(output, uri, **request):
7 if request['method'] != 'GET' :
8 output.SendMethodNotAllowed('GET')
9 else:
10 # Create an Excel writer
11 excel = xlwt.Workbook()
12 sheet = excel.add_sheet('Studies')
13
14 # Loop over the studies stored in Orthanc
15 row = 0
16 studies = orthanc.RestApiGet('/studies?expand')
17 for study in json.loads(studies):
18 sheet.write(row, 0, study['PatientMainDicomTags'].get('PatientID'))
19 sheet.write(row, 1, study['PatientMainDicomTags'].get('PatientName'))
20 sheet.write(row, 2, study['MainDicomTags'].get('StudyDescription'))
21 row += 1
22
23 # Serialize the Excel workbook to a string, and return it to the caller
24 # https://stackoverflow.com/a/15649139/881731
25 b = StringIO.StringIO()
26 excel.save(b)
27 output.AnswerBuffer(b.getvalue(), 'application/vnd.ms-excel')
28
29 orthanc.RegisterRestCallback('/report.xls', CreateExcelReport)