annotate Resources/Samples/Python/AnonymizeAllPatients.py @ 352:cc9eddbf07d3

sample to anonymize patients
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 28 Jan 2013 16:43:49 +0100
parents
children 61e4c62b8c35
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
cc9eddbf07d3 sample to anonymize patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 RestToolbox.DoPost('%s/patients/%s/anonymize' % (URL, patient))