annotate Resources/Samples/Python/ArchiveAllPatients.py @ 1900:b1291df2f780

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