Mercurial > hg > orthanc
annotate OrthancServer/Resources/Samples/Python/AnonymizeAllPatients.py @ 5485:48b8dae6dc77
upgrade to year 2024
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Jan 2024 15:10:42 +0100 |
parents | 0ea402b4d901 |
children | f7adfb22e20e |
rev | line source |
---|---|
352
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/python |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 |
747
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
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:
747
diff
changeset
|
6 # Department, University Hospital of Liege, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
7 # Copyright (C) 2017-2024 Osimis S.A., Belgium |
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
8 # Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
747
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
9 # |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
10 # This program is free software: you can redistribute it and/or |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
11 # modify it under the terms of the GNU General Public License as |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
12 # published by the Free Software Foundation, either version 3 of the |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
13 # License, or (at your option) any later version. |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
14 # |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
15 # This program is distributed in the hope that it will be useful, but |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
16 # WITHOUT ANY WARRANTY; without even the implied warranty of |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
18 # General Public License for more details. |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
19 # |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
20 # You should have received a copy of the GNU General Public License |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
21 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
22 |
44382c8bcd15
added explicit licensing terms for samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
353
diff
changeset
|
23 |
352
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
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
|
25 URL = 'http://127.0.0.1:8042' |
352
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 # |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 # This sample code will anonymize all the patients that are stored in |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 # Orthanc. |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 # |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 import sys |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 import RestToolbox |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 # Loop over the patients |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 for patient in RestToolbox.DoGet('%s/patients' % URL): |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 # Ignore patients whose name starts with "Anonymized", as it is |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 # the result of a previous anonymization |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 infos = RestToolbox.DoGet('%s/patients/%s' % (URL, patient)) |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 name = infos['MainDicomTags']['PatientName'].lower() |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 if not name.startswith('anonymized'): |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
cc9eddbf07d3
sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 # Trigger the anonymization |
353
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
352
diff
changeset
|
45 RestToolbox.DoPost('%s/patients/%s/anonymize' % (URL, patient), |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
352
diff
changeset
|
46 { 'Keep' : [ 'SeriesDescription', |
61e4c62b8c35
samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
352
diff
changeset
|
47 'StudyDescription' ] }) |