Mercurial > hg > orthanc
comparison Resources/Samples/Python/ArchiveStudiesInTimeRange.py @ 2070:7e6afa0beaf6
samples: improved handling of special characters in paths
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 14 Jul 2016 09:05:22 +0200 |
parents | 65b1ce7cb84f |
children | a3a65de1840f |
comparison
equal
deleted
inserted
replaced
2069:fabf7820d1f1 | 2070:7e6afa0beaf6 |
---|---|
47 TARGET = sys.argv[4] | 47 TARGET = sys.argv[4] |
48 | 48 |
49 CheckIsDate(START) | 49 CheckIsDate(START) |
50 CheckIsDate(END) | 50 CheckIsDate(END) |
51 | 51 |
52 def GetTag(tags, key): | |
53 if key in tags: | |
54 return tags[key] | |
55 else: | |
56 return 'No%s' % key | |
57 | |
52 # Loop over the studies | 58 # Loop over the studies |
53 for studyId in RestToolbox.DoGet('%s/studies' % URL): | 59 for studyId in RestToolbox.DoGet('%s/studies' % URL): |
54 # Retrieve the DICOM tags of the current study | 60 # Retrieve the DICOM tags of the current study |
55 study = RestToolbox.DoGet('%s/studies/%s' % (URL, studyId))['MainDicomTags'] | 61 study = RestToolbox.DoGet('%s/studies/%s' % (URL, studyId))['MainDicomTags'] |
56 | 62 |
59 | 65 |
60 # Check that the StudyDate tag lies within the given range | 66 # Check that the StudyDate tag lies within the given range |
61 studyDate = study['StudyDate'][:8] | 67 studyDate = study['StudyDate'][:8] |
62 if studyDate >= START and studyDate <= END: | 68 if studyDate >= START and studyDate <= END: |
63 # Create a filename | 69 # Create a filename |
64 filename = '%s - %s %s - %s.zip' % (study['StudyDate'], | 70 filename = '%s - %s %s - %s.zip' % (GetTag(study, 'StudyDate'), |
65 patient['PatientID'], | 71 GetTag(patient, 'PatientID'), |
66 patient['PatientName'], | 72 GetTag(patient, 'PatientName'), |
67 study['StudyDescription']) | 73 GetTag(study, 'StudyDescription')) |
68 | 74 |
69 # Remove any non-ASCII character in the filename | 75 # Remove any non-ASCII character in the filename |
70 filename = filename.encode('ascii', errors = 'replace') | 76 filename = filename.encode('ascii', errors = 'replace').translate(None, r"'\/:*?\"<>|!=").strip() |
71 | 77 |
72 # Download the ZIP archive of the study | 78 # Download the ZIP archive of the study |
73 print('Downloading %s' % filename) | 79 print('Downloading %s' % filename) |
74 zipContent = RestToolbox.DoGet('%s/studies/%s/archive' % (URL, studyId)) | 80 zipContent = RestToolbox.DoGet('%s/studies/%s/archive' % (URL, studyId)) |
75 | 81 |