Mercurial > hg > orthanc
annotate Resources/Samples/Python/ManualModification.py @ 2408:26a0cc24d48d
New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 25 Sep 2017 14:50:13 +0200 |
parents | a3a65de1840f |
children | 878b59270859 |
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 |
2244
a3a65de1840f
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2032
diff
changeset
|
6 # Copyright (C) 2017 Osimis, Belgium |
1917
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 # |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 # This program is free software: you can redistribute it and/or |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 # modify it under the terms of the GNU General Public License as |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 # published by the Free Software Foundation, either version 3 of the |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 # License, or (at your option) any later version. |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 # |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 # 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
|
14 # WITHOUT ANY WARRANTY; without even the implied warranty of |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 # General Public License for more details. |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 # |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 # You should have received a copy of the GNU General Public License |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
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 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 # This sample shows how to carry on a manual modification of DICOM |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 # tags spread accross various levels (Patient/Study/Series/Instance) |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 # 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
|
26 # avoid breaking the DICOM hierarchy. This sample can be useful for |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 # more complex anonymization/modification scenarios, or for optimizing |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 # the disk usage (the original and the modified instances never |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 # coexist). |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 from RestToolbox import * |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
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
|
33 URL = 'http://127.0.0.1:8042' |
1917
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 STUDY = '27f7126f-4f66fb14-03f4081b-f9341db2-53925988' |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 identifiers = {} |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 for instance in DoGet('%s/studies/%s/instances' % (URL, STUDY)): |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 # Setup the parameters of the modification |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 replace = { |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 "PatientID" : "Hello", |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 "PatientName" : "Modified", |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 "StationName" : "TEST", |
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 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 # Get the original UIDs of the instance |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 seriesUID = DoGet('%s/instances/%s/content/SeriesInstanceUID' % (URL, instance['ID'])) |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 if seriesUID in identifiers: |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 replace['SeriesInstanceUID'] = identifiers[seriesUID] |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 studyUID = DoGet('%s/instances/%s/content/StudyInstanceUID' % (URL, instance['ID'])) |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 if studyUID in identifiers: |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 replace['StudyInstanceUID'] = identifiers[studyUID] |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 # Manually modify the instance |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 print('Modifying instance %s' % instance['ID']) |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 modified = DoPost('%s/instances/%s/modify' % (URL, instance['ID']), |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 { "Replace" : replace }) |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 # Remove the original instance |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 DoDelete('%s/instances/%s' % (URL, instance['ID'])) |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 # Add the modified instance |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 modifiedId = DoPost('%s/instances' % URL, modified)['ID'] |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 # Register the modified UIDs |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 identifiers[seriesUID] = DoGet('%s/instances/%s/content/SeriesInstanceUID' % (URL, modifiedId)) |
7db4b909bec3
ManualModification sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 identifiers[studyUID] = DoGet('%s/instances/%s/content/StudyInstanceUID' % (URL, modifiedId)) |