comparison Tests/Tests.py @ 735:be8f174d3c9d find-refactoring tip

tools/find: Limit and Since are now forbidden when filtering on DICOM tags that are not stored in DB
author Alain Mazy <am@orthanc.team>
date Thu, 24 Oct 2024 15:08:59 +0200
parents 0ba04367983e
children
comparison
equal deleted inserted replaced
732:0ba04367983e 735:be8f174d3c9d
4332 # Now test "isSimpleLookup_ == false" 4332 # Now test "isSimpleLookup_ == false"
4333 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 4333 a = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series',
4334 'Query' : { 'PatientPosition' : '*' }}) 4334 'Query' : { 'PatientPosition' : '*' }})
4335 self.assertEqual(3, len(a)) 4335 self.assertEqual(3, len(a))
4336 4336
4337 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 4337 if not HasExtendedFind(_REMOTE): # once you have ExtendedFind, usage of Limit and Since is forbidden when filtering on tags that are not in DB because that's just impossible to use on real life DB !
4338 'Query' : { 'PatientPosition' : '*' }, 4338
4339 'Limit' : 0}) 4339
4340 self.assertEqual(3, len(b)) 4340 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series',
4341 self.assertEqual(a[0], b[0]) 4341 'Query' : { 'PatientPosition' : '*' },
4342 self.assertEqual(a[1], b[1]) 4342 'Limit' : 0})
4343 self.assertEqual(a[2], b[2]) 4343 self.assertEqual(3, len(b))
4344 4344 self.assertEqual(a[0], b[0])
4345 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 4345 self.assertEqual(a[1], b[1])
4346 'Query' : { 'PatientPosition' : '*' }, 4346 self.assertEqual(a[2], b[2])
4347 'Limit' : 1}) 4347
4348 self.assertEqual(1, len(b)) 4348 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series',
4349 self.assertEqual(a[0], b[0]) 4349 'Query' : { 'PatientPosition' : '*' },
4350 4350 'Limit' : 1})
4351 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 4351 self.assertEqual(1, len(b))
4352 'Query' : { 'PatientPosition' : '*' }, 4352 self.assertEqual(a[0], b[0])
4353 'Since' : 0, 4353
4354 'Limit' : 1}) 4354 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series',
4355 self.assertEqual(1, len(b)) 4355 'Query' : { 'PatientPosition' : '*' },
4356 self.assertEqual(a[0], b[0]) 4356 'Since' : 0,
4357 4357 'Limit' : 1})
4358 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 4358 self.assertEqual(1, len(b))
4359 'Query' : { 'PatientPosition' : '*' }, 4359 self.assertEqual(a[0], b[0])
4360 'Since' : 0, 4360
4361 'Limit' : 3}) 4361 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series',
4362 self.assertEqual(3, len(b)) 4362 'Query' : { 'PatientPosition' : '*' },
4363 self.assertEqual(a[0], b[0]) 4363 'Since' : 0,
4364 self.assertEqual(a[1], b[1]) 4364 'Limit' : 3})
4365 self.assertEqual(a[2], b[2]) 4365 self.assertEqual(3, len(b))
4366 4366 self.assertEqual(a[0], b[0])
4367 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 4367 self.assertEqual(a[1], b[1])
4368 'Query' : { 'PatientPosition' : '*' }, 4368 self.assertEqual(a[2], b[2])
4369 'Since' : 0, 4369
4370 'Limit' : 4}) 4370 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series',
4371 self.assertEqual(3, len(b)) 4371 'Query' : { 'PatientPosition' : '*' },
4372 self.assertEqual(a[0], b[0]) 4372 'Since' : 0,
4373 self.assertEqual(a[1], b[1]) 4373 'Limit' : 4})
4374 self.assertEqual(a[2], b[2]) 4374 self.assertEqual(3, len(b))
4375 4375 self.assertEqual(a[0], b[0])
4376 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 4376 self.assertEqual(a[1], b[1])
4377 'Query' : { 'PatientPosition' : '*' }, 4377 self.assertEqual(a[2], b[2])
4378 'Since' : 1, 4378
4379 'Limit' : 1}) 4379 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series',
4380 self.assertEqual(1, len(b)) 4380 'Query' : { 'PatientPosition' : '*' },
4381 self.assertEqual(a[1], b[0]) 4381 'Since' : 1,
4382 4382 'Limit' : 1})
4383 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 4383 self.assertEqual(1, len(b))
4384 'Query' : { 'PatientPosition' : '*' }, 4384 self.assertEqual(a[1], b[0])
4385 'Since' : 1, 4385
4386 'Limit' : 2}) 4386 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series',
4387 self.assertEqual(2, len(b)) 4387 'Query' : { 'PatientPosition' : '*' },
4388 self.assertEqual(a[1], b[0]) 4388 'Since' : 1,
4389 self.assertEqual(a[2], b[1]) 4389 'Limit' : 2})
4390 4390 self.assertEqual(2, len(b))
4391 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 4391 self.assertEqual(a[1], b[0])
4392 'Query' : { 'PatientPosition' : '*' }, 4392 self.assertEqual(a[2], b[1])
4393 'Since' : 1, 4393
4394 'Limit' : 3}) 4394 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series',
4395 self.assertEqual(2, len(b)) 4395 'Query' : { 'PatientPosition' : '*' },
4396 self.assertEqual(a[1], b[0]) 4396 'Since' : 1,
4397 self.assertEqual(a[2], b[1]) 4397 'Limit' : 3})
4398 4398 self.assertEqual(2, len(b))
4399 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 4399 self.assertEqual(a[1], b[0])
4400 'Query' : { 'PatientPosition' : '*' }, 4400 self.assertEqual(a[2], b[1])
4401 'Since' : 2, 4401
4402 'Limit' : 1}) 4402 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series',
4403 self.assertEqual(1, len(b)) 4403 'Query' : { 'PatientPosition' : '*' },
4404 self.assertEqual(a[2], b[0]) 4404 'Since' : 2,
4405 4405 'Limit' : 1})
4406 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 4406 self.assertEqual(1, len(b))
4407 'Query' : { 'PatientPosition' : '*' }, 4407 self.assertEqual(a[2], b[0])
4408 'Since' : 2, 4408
4409 'Limit' : 2}) 4409 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series',
4410 self.assertEqual(1, len(b)) 4410 'Query' : { 'PatientPosition' : '*' },
4411 self.assertEqual(a[2], b[0]) 4411 'Since' : 2,
4412 4412 'Limit' : 2})
4413 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 4413 self.assertEqual(1, len(b))
4414 'Query' : { 'PatientPosition' : '*' }, 4414 self.assertEqual(a[2], b[0])
4415 'Since' : 3, 4415
4416 'Limit' : 1}) 4416 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series',
4417 self.assertEqual(0, len(b)) 4417 'Query' : { 'PatientPosition' : '*' },
4418 4418 'Since' : 3,
4419 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series', 4419 'Limit' : 1})
4420 'Query' : { 'PatientPosition' : '*' }, 4420 self.assertEqual(0, len(b))
4421 'Since' : 3, 4421
4422 'Limit' : 10}) 4422 b = DoPost(_REMOTE, '/tools/find', { 'Level' : 'Series',
4423 self.assertEqual(0, len(b)) 4423 'Query' : { 'PatientPosition' : '*' },
4424 'Since' : 3,
4425 'Limit' : 10})
4426 self.assertEqual(0, len(b))
4424 4427
4425 4428
4426 def test_bitbucket_issue_46(self): 4429 def test_bitbucket_issue_46(self):
4427 # "PHI remaining after anonymization" 4430 # "PHI remaining after anonymization"
4428 # https://bugs.orthanc-server.com/show_bug.cgi?id=46 4431 # https://bugs.orthanc-server.com/show_bug.cgi?id=46
11323 self.assertEqual(kneeStudyId, a[0]['ParentStudy']) 11326 self.assertEqual(kneeStudyId, a[0]['ParentStudy'])
11324 self.assertEqual(3, len(a[0]['Instances'])) 11327 self.assertEqual(3, len(a[0]['Instances']))
11325 self.assertEqual('', a[0]['Metadata']['RemoteAET']) 11328 self.assertEqual('', a[0]['Metadata']['RemoteAET'])
11326 11329
11327 def test_pagination_and_limit_find_results(self): 11330 def test_pagination_and_limit_find_results(self):
11328 # if IsOrthancVersionAbove(_REMOTE, 1, 12, 5) and HasExtendedFind(_REMOTE): # TODO: remove HasExtendedFind once find-refactoring branch has been merged
11329
11330 # LimitFindInstances is set to 20 11331 # LimitFindInstances is set to 20
11331 # LimitFindResults is set to 10 11332 # LimitFindResults is set to 10
11332 11333
11333 # Upload 27 instances from KNIX 11334 # Upload 27 instances from KNIX
11334 UploadFolder(_REMOTE, 'Knix/Loc') 11335 UploadFolder(_REMOTE, 'Knix/Loc')
11431 self.assertNotIn(seriesNoLimit[i], seriesSince8Limit6) 11432 self.assertNotIn(seriesNoLimit[i], seriesSince8Limit6)
11432 # the last 3 from last call shall not be in the first answer 11433 # the last 3 from last call shall not be in the first answer
11433 for i in range(3, 5): 11434 for i in range(3, 5):
11434 self.assertNotIn(seriesSince8Limit6[i], seriesNoLimit) 11435 self.assertNotIn(seriesSince8Limit6[i], seriesNoLimit)
11435 11436
11436 if IsOrthancVersionAbove(_REMOTE, 1, 12, 5) and HasExtendedFind(_REMOTE): # TODO: remove HasExtendedFind once find-refactoring branch has been merged and supported by all DB plugins !!! 11437 if IsOrthancVersionAbove(_REMOTE, 1, 12, 5) and HasExtendedFind(_REMOTE):
11437 # query by a tag that is not in the DB (there are 27 instances from Knix/Loc + 10 instances from other series that satisfies this criteria) 11438 # query by a tag that is not in the DB (there are 27 instances from Knix/Loc + 10 instances from other series that satisfies this criteria)
11438 a = DoPost(_REMOTE, '/tools/find', { 11439 a = DoPost(_REMOTE, '/tools/find', {
11439 'Level' : 'Instances', 11440 'Level' : 'Instances',
11440 'Query' : { 11441 'Query' : {
11441 'PhotometricInterpretation' : 'MONOCHROME*' 11442 'PhotometricInterpretation' : 'MONOCHROME*'
11451 11452
11452 # pprint.pprint(a) 11453 # pprint.pprint(a)
11453 # print(len(a)) 11454 # print(len(a))
11454 # TODO: we should have something in the response that notifies us that the response is not "complete" 11455 # TODO: we should have something in the response that notifies us that the response is not "complete"
11455 # TODO: we should receive an error if we try to use "since" in this kind of search ? 11456 # TODO: we should receive an error if we try to use "since" in this kind of search ?
11456 self.assertEqual(17, len(a)) # the fast DB filtering returns 20 instances -> only 17 meet the criteria 11457 self.assertEqual(17, len(a)) # the fast DB filtering returns 20 instances -> only 17 of them meet the criteria but this is not really correct !!!
11458
11459 if IsOrthancVersionAbove(_REMOTE, 1, 12, 5) and HasExtendedFind(_REMOTE):
11460 # make sur an error is returned when using Since or Limit when querying a tag that is not in DB
11461 self.assertRaises(Exception, lambda: DoPost(_REMOTE, '/tools/find', {'Level' : 'Instances',
11462 'Query' : {
11463 'PhotometricInterpretation' : 'MONOCHROME*'
11464 },
11465 'Since': 2
11466 }))
11467
11468 # make sur an error is returned when using Since or Limit when querying a tag that is not in DB
11469 self.assertRaises(Exception, lambda: DoPost(_REMOTE, '/tools/find', {'Level' : 'Instances',
11470 'Query' : {
11471 'PhotometricInterpretation' : 'MONOCHROME*'
11472 },
11473 'Limit': 10
11474 }))