Mercurial > hg > orthanc
annotate Resources/Samples/Python/ManualModification.py @ 2143:fd5875662670
creation of namespace SystemToolbox
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Nov 2016 16:54:23 +0100 |
parents | 65b1ce7cb84f |
children | a3a65de1840f |
rev | line source |
---|---|
1917
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/python |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 # Orthanc - A Lightweight, RESTful DICOM Store |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 # Department, University Hospital of Liege, Belgium |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 # |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 # modify it under the terms of the GNU General Public License as |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 # published by the Free Software Foundation, either version 3 of the |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 # License, or (at your option) any later version. |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 # |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, but |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 # WITHOUT ANY WARRANTY; without even the implied warranty of |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 # General Public License for more details. |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 # |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU General Public License |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 # This sample shows how to carry on a manual modification of DICOM |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 # tags spread accross various levels (Patient/Study/Series/Instance) |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 # that would normally forbidden as such by the REST API of Orthanc to |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 # avoid breaking the DICOM hierarchy. This sample can be useful for |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 # more complex anonymization/modification scenarios, or for optimizing |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 # the disk usage (the original and the modified instances never |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 # coexist). |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 from RestToolbox import * |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
2032
65b1ce7cb84f
Replaced "localhost" by "127.0.0.1", as it might impact performance on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1917
diff
changeset
|
32 URL = 'http://127.0.0.1:8042' |
1917
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 STUDY = '27f7126f-4f66fb14-03f4081b-f9341db2-53925988' |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 identifiers = {} |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 for instance in DoGet('%s/studies/%s/instances' % (URL, STUDY)): |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 # Setup the parameters of the modification |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 replace = { |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 "PatientID" : "Hello", |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 "PatientName" : "Modified", |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 "StationName" : "TEST", |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 } |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 # Get the original UIDs of the instance |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 seriesUID = DoGet('%s/instances/%s/content/SeriesInstanceUID' % (URL, instance['ID'])) |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 if seriesUID in identifiers: |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 replace['SeriesInstanceUID'] = identifiers[seriesUID] |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 studyUID = DoGet('%s/instances/%s/content/StudyInstanceUID' % (URL, instance['ID'])) |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 if studyUID in identifiers: |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 replace['StudyInstanceUID'] = identifiers[studyUID] |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 # Manually modify the instance |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 print('Modifying instance %s' % instance['ID']) |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 modified = DoPost('%s/instances/%s/modify' % (URL, instance['ID']), |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 { "Replace" : replace }) |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 # Remove the original instance |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 DoDelete('%s/instances/%s' % (URL, instance['ID'])) |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 # Add the modified instance |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 modifiedId = DoPost('%s/instances' % URL, modified)['ID'] |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 # Register the modified UIDs |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 identifiers[seriesUID] = DoGet('%s/instances/%s/content/SeriesInstanceUID' % (URL, modifiedId)) |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 identifiers[studyUID] = DoGet('%s/instances/%s/content/StudyInstanceUID' % (URL, modifiedId)) |