annotate Resources/Samples/Python/AnonymizeAllPatients.py @ 2743:3f18a64760ee Orthanc-0.5.2

close old branch
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 17 Jul 2018 09:39:08 +0200
parents 61e4c62b8c35
children 44382c8bcd15
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 URL = 'http://localhost:8042'
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 #
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 # 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
9 # Orthanc.
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 #
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 import sys
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 import RestToolbox
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # Loop over the patients
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 for patient in RestToolbox.DoGet('%s/patients' % URL):
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 # Ignore patients whose name starts with "Anonymized", as it is
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 # the result of a previous anonymization
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 infos = RestToolbox.DoGet('%s/patients/%s' % (URL, patient))
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 name = infos['MainDicomTags']['PatientName'].lower()
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 if not name.startswith('anonymized'):
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 # Trigger the anonymization
353
61e4c62b8c35 samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 352
diff changeset
25 RestToolbox.DoPost('%s/patients/%s/anonymize' % (URL, patient),
61e4c62b8c35 samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 352
diff changeset
26 { 'Keep' : [ 'SeriesDescription',
61e4c62b8c35 samples of anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 352
diff changeset
27 'StudyDescription' ] })