Mercurial > hg > orthanc
annotate OrthancServer/Resources/Samples/Python/AutoClassify.py @ 5236:5e0db9eac1f8 db-protobuf
integration mainline->db-protobuf
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Apr 2023 21:43:37 +0200 |
parents | 0ea402b4d901 |
children | 48b8dae6dc77 |
rev | line source |
---|---|
1182
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/python |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 # Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 5 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1184
diff
changeset
|
6 # Department, University Hospital of Liege, Belgium |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
7 # Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
8 # Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1182
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 # |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 # This program is free software: you can redistribute it and/or |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 # modify it under the terms of the GNU General Public License as |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 # published by the Free Software Foundation, either version 3 of the |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 # License, or (at your option) any later version. |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 # |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 # This program is distributed in the hope that it will be useful, but |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 # WITHOUT ANY WARRANTY; without even the implied warranty of |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 # General Public License for more details. |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 # |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 # You should have received a copy of the GNU General Public License |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 import argparse |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 import time |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 import os |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 import os.path |
1184 | 28 import sys |
1182
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 import RestToolbox |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 parser = argparse.ArgumentParser( |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 description = 'Automated classification of DICOM files from Orthanc.', |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 formatter_class = argparse.ArgumentDefaultsHelpFormatter) |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
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
|
35 parser.add_argument('--host', default = '127.0.0.1', |
1182
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 help = 'The host address that runs Orthanc') |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 parser.add_argument('--port', type = int, default = '8042', |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 help = 'The port number to which Orthanc is listening for the REST API') |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 parser.add_argument('--target', default = 'OrthancFiles', |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 help = 'The target directory where to store the DICOM files') |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 parser.add_argument('--all', action = 'store_true', |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 help = 'Replay the entire history on startup (disabled by default)') |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 parser.set_defaults(all = False) |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 parser.add_argument('--remove', action = 'store_true', |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 help = 'Remove DICOM files from Orthanc once classified (disabled by default)') |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 parser.set_defaults(remove = False) |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
1183
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
49 def FixPath(p): |
4665
43f13842bc3b
fix AutoClassify.py sample for compatibility with Python 3.x
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
50 s = p.encode('ascii', errors = 'replace').decode('ascii') |
43f13842bc3b
fix AutoClassify.py sample for compatibility with Python 3.x
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
51 |
43f13842bc3b
fix AutoClassify.py sample for compatibility with Python 3.x
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
52 for c in "'\/:*?\"<>|!=": |
43f13842bc3b
fix AutoClassify.py sample for compatibility with Python 3.x
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
53 s = s.replace(c, '') |
43f13842bc3b
fix AutoClassify.py sample for compatibility with Python 3.x
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
54 |
43f13842bc3b
fix AutoClassify.py sample for compatibility with Python 3.x
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
55 return s.strip() |
1183
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
56 |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
57 def GetTag(resource, tag): |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
58 if ('MainDicomTags' in resource and |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
59 tag in resource['MainDicomTags']): |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
60 return resource['MainDicomTags'][tag] |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
61 else: |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
62 return 'No' + tag |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
63 |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
64 def ClassifyInstance(instanceId): |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
65 # Extract the patient, study, series and instance information |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
66 instance = RestToolbox.DoGet('%s/instances/%s' % (URL, instanceId)) |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
67 series = RestToolbox.DoGet('%s/series/%s' % (URL, instance['ParentSeries'])) |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
68 study = RestToolbox.DoGet('%s/studies/%s' % (URL, series['ParentStudy'])) |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
69 patient = RestToolbox.DoGet('%s/patients/%s' % (URL, study['ParentPatient'])) |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
70 |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
71 # Construct a target path |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
72 a = '%s - %s' % (GetTag(patient, 'PatientID'), |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
73 GetTag(patient, 'PatientName')) |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
74 b = GetTag(study, 'StudyDescription') |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
75 c = '%s - %s' % (GetTag(series, 'Modality'), |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
76 GetTag(series, 'SeriesDescription')) |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
77 d = '%s.dcm' % GetTag(instance, 'SOPInstanceUID') |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
78 |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
79 p = os.path.join(args.target, FixPath(a), FixPath(b), FixPath(c)) |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
80 f = os.path.join(p, FixPath(d)) |
1184 | 81 |
1183
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
82 # Copy the DICOM file to the target path |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
83 print('Writing new DICOM file: %s' % f) |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
84 |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
85 try: |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
86 os.makedirs(p) |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
87 except: |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
88 # Already existing directory, ignore the error |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
89 pass |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
90 |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
91 dcm = RestToolbox.DoGet('%s/instances/%s/file' % (URL, instanceId)) |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
92 with open(f, 'wb') as g: |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
93 g.write(dcm) |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
94 |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
95 |
1182
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 # Parse the arguments |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 args = parser.parse_args() |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 URL = 'http://%s:%d' % (args.host, args.port) |
1183
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
99 print('Connecting to Orthanc on address: %s' % URL) |
1182
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 # Compute the starting point for the changes loop |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 if args.all: |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 current = 0 |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 else: |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 current = RestToolbox.DoGet(URL + '/changes?last')['Last'] |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 |
1183
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
107 # Polling loop using the 'changes' API of Orthanc, waiting for the |
1182
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 # incoming of new DICOM files |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 while True: |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 r = RestToolbox.DoGet(URL + '/changes', { |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 'since' : current, |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 'limit' : 4 # Retrieve at most 4 changes at once |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 }) |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 for change in r['Changes']: |
3338 | 116 # We are only interested in the arrival of new instances |
1182
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 if change['ChangeType'] == 'NewInstance': |
1183
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
118 try: |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
119 ClassifyInstance(change['ID']) |
2075
bec08e9236f5
more robust AutoClassify.py sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2070
diff
changeset
|
120 |
bec08e9236f5
more robust AutoClassify.py sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2070
diff
changeset
|
121 # If requested, remove the instance once it has been |
bec08e9236f5
more robust AutoClassify.py sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2070
diff
changeset
|
122 # properly handled by "ClassifyInstance()". Thanks to |
bec08e9236f5
more robust AutoClassify.py sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2070
diff
changeset
|
123 # the "try/except" block, the instance is not removed |
bec08e9236f5
more robust AutoClassify.py sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2070
diff
changeset
|
124 # if the "ClassifyInstance()" function fails. |
bec08e9236f5
more robust AutoClassify.py sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2070
diff
changeset
|
125 if args.remove: |
bec08e9236f5
more robust AutoClassify.py sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2070
diff
changeset
|
126 RestToolbox.DoDelete('%s/instances/%s' % (URL, change['ID'])) |
bec08e9236f5
more robust AutoClassify.py sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2070
diff
changeset
|
127 |
1183
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
128 except: |
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
129 print('Unable to write instance %s to the disk' % change['ID']) |
1182
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 current = r['Last'] |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 |
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 if r['Done']: |
1183
6ef2c81581cd
more fault-tolerant sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1182
diff
changeset
|
134 print('Everything has been processed: Waiting...') |
1182
d74ac5d0bcaf
New sample: Automated classification of DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 time.sleep(1) |