comparison Resources/Samples/Python/ArchiveAllPatients.py @ 1899:6615133a996c

new sample: ArchiveAllPatients.py
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Jan 2016 13:11:13 +0100
parents
children b1291df2f780
comparison
equal deleted inserted replaced
1898:e018037d4d0e 1899:6615133a996c
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Orthanc - A Lightweight, RESTful DICOM Store
5 # Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
6 # Department, University Hospital of Liege, Belgium
7 #
8 # This program is free software: you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21
22
23 import os
24 import os.path
25 import sys
26 import RestToolbox
27
28 def PrintHelp():
29 print('Download one ZIP archive for all the patients stored in Orthanc\n')
30 print('Usage: %s <URL> <Target>\n' % sys.argv[0])
31 print('Example: %s http://localhost:8042/ /tmp/Archive.zip\n' % sys.argv[0])
32 exit(-1)
33
34 if len(sys.argv) != 3:
35 PrintHelp()
36
37 URL = sys.argv[1]
38 TARGET = sys.argv[2]
39
40 patients = RestToolbox.DoGet('%s/patients' % URL)
41
42 print('Downloading ZIP...')
43 zipContent = RestToolbox.DoPost('%s/tools/create-archive' % URL, patients)
44
45 # Write the ZIP archive at the proper location
46 with open(TARGET, 'wb') as f:
47 f.write(zipContent)