Mercurial > hg > orthanc-tests
comparison Tests/Tests.py @ 117:d87bf4fbbf83
merge
author | amazy |
---|---|
date | Thu, 13 Jul 2017 12:40:03 +0200 |
parents | 4a196ebc7a4f 45ebfab035b7 |
children | a954c535fef6 |
comparison
equal
deleted
inserted
replaced
116:4a196ebc7a4f | 117:d87bf4fbbf83 |
---|---|
3193 modified = DoPost(_REMOTE, | 3193 modified = DoPost(_REMOTE, |
3194 '/patients/da128605-e040d0c4-310615d2-3475da63-df2d1ef4/modify', | 3194 '/patients/da128605-e040d0c4-310615d2-3475da63-df2d1ef4/modify', |
3195 '{"Replace":{"PatientID":"Hello","PatientName":"Sample patient name"}}', | 3195 '{"Replace":{"PatientID":"Hello","PatientName":"Sample patient name"}}', |
3196 'application/json') | 3196 'application/json') |
3197 self.assertTrue('PatientID' in modified) | 3197 self.assertTrue('PatientID' in modified) |
3198 | 3198 |
3199 | |
3200 def test_rest_find_limit(self): | |
3201 # Check the "Since" and "Limit" parameters in URI "/tools/find" | |
3202 # Related to issue 53: https://bitbucket.org/sjodogne/orthanc/issues/53 | |
3203 | |
3204 # Upload 6 instances | |
3205 brainix = [] | |
3206 knee = [] | |
3207 for i in range(2): | |
3208 brainix.append(UploadInstance(_REMOTE, 'Brainix/Flair/IM-0001-000%d.dcm' % (i + 1)) ['ID']) | |
3209 brainix.append(UploadInstance(_REMOTE, 'Brainix/Epi/IM-0001-000%d.dcm' % (i + 1)) ['ID']) | |
3210 knee.append(UploadInstance(_REMOTE, 'Knee/T1/IM-0001-000%d.dcm' % (i + 1)) ['ID']) | |
3211 | |
3212 # Check using BRAINIX | |
3213 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Instance', | |
3214 'Query' : { 'PatientName' : 'B*' }, | |
3215 'Limit' : 10 }) | |
3216 self.assertEqual(4, len(a)) | |
3217 | |
3218 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Instance', | |
3219 'Query' : { 'PatientName' : 'B*' }, | |
3220 'Limit' : 4 }) | |
3221 self.assertEqual(4, len(a)) | |
3222 | |
3223 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Instance', | |
3224 'Query' : { 'PatientName' : 'B*' }, | |
3225 'Since' : 2, | |
3226 'Limit' : 4 }) | |
3227 self.assertEqual(2, len(a)) | |
3228 | |
3229 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Instance', | |
3230 'Query' : { 'PatientName' : 'B*' }, | |
3231 'Limit' : 3 }) | |
3232 self.assertEqual(3, len(a)) | |
3233 | |
3234 b = [] | |
3235 for i in range(4): | |
3236 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Instance', | |
3237 'Query' : { 'PatientName' : 'B*' }, | |
3238 'Limit' : 1, | |
3239 'Since' : i }) | |
3240 self.assertEqual(1, len(a)) | |
3241 b.append(a[0]) | |
3242 | |
3243 # Check whether the two sets are equal through symmetric difference | |
3244 self.assertEqual(0, len(set(b) ^ set(brainix))) | |
3245 | |
3246 # Check using KNEE | |
3247 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Instance', | |
3248 'Query' : { 'PatientName' : 'K*' }, | |
3249 'Limit' : 10 }) | |
3250 self.assertEqual(2, len(a)) | |
3251 | |
3252 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Instance', | |
3253 'Query' : { 'PatientName' : 'K*' }, | |
3254 'Limit' : 2 }) | |
3255 self.assertEqual(2, len(a)) | |
3256 | |
3257 b = [] | |
3258 for i in range(2): | |
3259 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Instance', | |
3260 'Query' : { 'PatientName' : 'K*' }, | |
3261 'Limit' : 1, | |
3262 'Since' : i }) | |
3263 self.assertEqual(1, len(a)) | |
3264 b.append(a[0]) | |
3265 | |
3266 self.assertEqual(0, len(set(b) ^ set(knee))) | |
3267 | |
3268 | |
3269 def test_bitbucket_issue_46(self): | |
3270 # "PHI remaining after anonymization" | |
3271 # https://bitbucket.org/sjodogne/orthanc/issues/46 | |
3272 | |
3273 def GetAnonymizedTags(study, version): | |
3274 anonymized = DoPost(_REMOTE, '/studies/%s/anonymize' % study, | |
3275 { 'DicomVersion' : version }, | |
3276 'application/json') ['ID'] | |
3277 a = DoGet(_REMOTE, '/studies/%s/instances' % anonymized) | |
3278 self.assertEqual(1, len(a)) | |
3279 | |
3280 instance = a[0]['ID'] | |
3281 | |
3282 return (instance, DoGet(_REMOTE, '/instances/%s/tags' % instance)) | |
3283 | |
3284 # Use a sample DICOM image that already contains the 0010,1060 | |
3285 # (RequestingService) tag | |
3286 UploadInstance(_REMOTE, 'Issue44/Monochrome1.dcm') | |
3287 origStudy = '6068a14b-d4df27af-9ec22145-538772d8-74f228ff' | |
3288 | |
3289 # Add the 0032,1033 (Requesting Service) and the 0010,1060 | |
3290 # (Patient's Mother's Birth Name) tags | |
3291 newStudy = DoPost(_REMOTE, '/studies/%s/modify' % origStudy, | |
3292 '{"Replace":{"0010,1060":"OSIMIS","0032,1033":"MOTHER"}}', | |
3293 'application/json')['ID'] | |
3294 | |
3295 # Use Table E.1-1 from PS 3.15-2008 | |
3296 # https://raw.githubusercontent.com/jodogne/dicom-specification/master/2008/08_15pu.pdf | |
3297 (instance, tags) = GetAnonymizedTags(newStudy, "2008") | |
3298 self.assertTrue('0032,1033' in tags) | |
3299 self.assertTrue('0010,1060' in tags) | |
3300 | |
3301 # Use Table E.1-1 from PS 3.15-2011 (only if Orthanc >= 1.2.1) | |
3302 # https://raw.githubusercontent.com/jodogne/dicom-specification/master/2008/08_15pu.pdf | |
3303 (instance, tags) = GetAnonymizedTags(newStudy, "2017c") | |
3304 self.assertFalse('0032,1033' in tags) | |
3305 self.assertFalse('0010,1060' in tags) | |
3306 | |
3307 t = {} | |
3308 for (key, value) in tags.iteritems(): | |
3309 t[value['Name']] = value['Value'] | |
3310 | |
3311 self.assertEqual('', t['StudyDate']) # Type 1 tag => cleared | |
3312 self.assertEqual('', t['StudyTime']) # Type 1 tag => cleared | |
3313 self.assertEqual('', t['PatientSex']) # Type 1 tag => cleared | |
3314 self.assertFalse('SeriesDate' in t) # Type 3 tag => null | |
3315 self.assertFalse('SeriesTime' in t) # Type 3 tag => null | |
3316 | |
3317 with tempfile.NamedTemporaryFile(delete = True) as f: | |
3318 # Run "dciodvfy" on the anonymized file to be sure it is still valid | |
3319 f.write(DoGet(_REMOTE, '/instances/%s/file' % instance)) | |
3320 f.flush() | |
3321 subprocess.check_output([ FindExecutable('dciodvfy'), f.name ], | |
3322 stderr = subprocess.STDOUT).split('\n') |