Mercurial > hg > orthanc-tests
comparison Tests/Tests.py @ 115:45ebfab035b7
test_bitbucket_issue_46
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 12 Jul 2017 22:10:00 +0200 |
parents | 3e5934363e76 |
children | d87bf4fbbf83 |
comparison
equal
deleted
inserted
replaced
114:a6019560272f | 115:45ebfab035b7 |
---|---|
3260 'Since' : i }) | 3260 'Since' : i }) |
3261 self.assertEqual(1, len(a)) | 3261 self.assertEqual(1, len(a)) |
3262 b.append(a[0]) | 3262 b.append(a[0]) |
3263 | 3263 |
3264 self.assertEqual(0, len(set(b) ^ set(knee))) | 3264 self.assertEqual(0, len(set(b) ^ set(knee))) |
3265 | |
3266 | |
3267 def test_bitbucket_issue_46(self): | |
3268 # "PHI remaining after anonymization" | |
3269 # https://bitbucket.org/sjodogne/orthanc/issues/46 | |
3270 | |
3271 def GetAnonymizedTags(study, version): | |
3272 anonymized = DoPost(_REMOTE, '/studies/%s/anonymize' % study, | |
3273 { 'DicomVersion' : version }, | |
3274 'application/json') ['ID'] | |
3275 a = DoGet(_REMOTE, '/studies/%s/instances' % anonymized) | |
3276 self.assertEqual(1, len(a)) | |
3277 | |
3278 instance = a[0]['ID'] | |
3279 | |
3280 return (instance, DoGet(_REMOTE, '/instances/%s/tags' % instance)) | |
3281 | |
3282 # Use a sample DICOM image that already contains the 0010,1060 | |
3283 # (RequestingService) tag | |
3284 UploadInstance(_REMOTE, 'Issue44/Monochrome1.dcm') | |
3285 origStudy = '6068a14b-d4df27af-9ec22145-538772d8-74f228ff' | |
3286 | |
3287 # Add the 0032,1033 (Requesting Service) and the 0010,1060 | |
3288 # (Patient's Mother's Birth Name) tags | |
3289 newStudy = DoPost(_REMOTE, '/studies/%s/modify' % origStudy, | |
3290 '{"Replace":{"0010,1060":"OSIMIS","0032,1033":"MOTHER"}}', | |
3291 'application/json')['ID'] | |
3292 | |
3293 # Use Table E.1-1 from PS 3.15-2008 | |
3294 # https://raw.githubusercontent.com/jodogne/dicom-specification/master/2008/08_15pu.pdf | |
3295 (instance, tags) = GetAnonymizedTags(newStudy, "2008") | |
3296 self.assertTrue('0032,1033' in tags) | |
3297 self.assertTrue('0010,1060' in tags) | |
3298 | |
3299 # Use Table E.1-1 from PS 3.15-2011 (only if Orthanc >= 1.2.1) | |
3300 # https://raw.githubusercontent.com/jodogne/dicom-specification/master/2008/08_15pu.pdf | |
3301 (instance, tags) = GetAnonymizedTags(newStudy, "2017c") | |
3302 self.assertFalse('0032,1033' in tags) | |
3303 self.assertFalse('0010,1060' in tags) | |
3304 | |
3305 t = {} | |
3306 for (key, value) in tags.iteritems(): | |
3307 t[value['Name']] = value['Value'] | |
3308 | |
3309 self.assertEqual('', t['StudyDate']) # Type 1 tag => cleared | |
3310 self.assertEqual('', t['StudyTime']) # Type 1 tag => cleared | |
3311 self.assertEqual('', t['PatientSex']) # Type 1 tag => cleared | |
3312 self.assertFalse('SeriesDate' in t) # Type 3 tag => null | |
3313 self.assertFalse('SeriesTime' in t) # Type 3 tag => null | |
3314 | |
3315 with tempfile.NamedTemporaryFile(delete = True) as f: | |
3316 # Run "dciodvfy" on the anonymized file to be sure it is still valid | |
3317 f.write(DoGet(_REMOTE, '/instances/%s/file' % instance)) | |
3318 f.flush() | |
3319 subprocess.check_output([ FindExecutable('dciodvfy'), f.name ], | |
3320 stderr = subprocess.STDOUT).split('\n') |