annotate OrthancServer/Resources/Samples/Python/ArchiveAllPatients.py @ 5825:881cd0965146 find-refactoring tip

added OrderBy support in SQLite
author Alain Mazy <am@orthanc.team>
date Fri, 04 Oct 2024 19:03:14 +0200
parents f7adfb22e20e
children
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
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
7 # Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
8 # Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
9 # Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1899
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 #
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # 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
12 # 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
13 # 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
14 # License, or (at your option) any later version.
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 #
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 # 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
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 # General Public License for more details.
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 # 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
22 # 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
23
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 import os
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 import os.path
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 import sys
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 import RestToolbox
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 def PrintHelp():
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 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
33 print('Usage: %s <URL> <Target>\n' % sys.argv[0])
2032
65b1ce7cb84f Replaced "localhost" by "127.0.0.1", as it might impact performance on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
34 print('Example: %s http://127.0.0.1:8042/ /tmp/Archive.zip\n' % sys.argv[0])
1899
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 exit(-1)
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 if len(sys.argv) != 3:
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 PrintHelp()
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 URL = sys.argv[1]
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 TARGET = sys.argv[2]
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 patients = RestToolbox.DoGet('%s/patients' % URL)
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 print('Downloading ZIP...')
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 zipContent = RestToolbox.DoPost('%s/tools/create-archive' % URL, patients)
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 # Write the ZIP archive at the proper location
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 with open(TARGET, 'wb') as f:
6615133a996c new sample: ArchiveAllPatients.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 f.write(zipContent)