C-FIND SCU for PatientBirthDate is slow...

Hi,

I noticed that a C-FIND SCU query for PatientBirthDate is much slower than anything else. For instance, see this benchmark below:

import time
import RestToolbox

# Login in order to be able to delete anything
RestToolbox.SetCredentials('admin', 'admin')

URL = 'http://pl-torque.dccn.nl:8042' # -> the Orthanc PACS server
patientid = 'p119_p2'

t0 = time.time()
patient = RestToolbox.DoPost('{}/modalities/local/find-patient'.format(URL),
                             {'PatientID':'{}'.format(patientid)})

t1 = time.time()
patient = RestToolbox.DoPost('{}/modalities/local/find-patient'.format(URL),
                             {'PatientBirthDate':'{}'.format(patient[0]['PatientBirthDate'])})

# Loop over the patients using the REST API
t2 = time.time()
for patient_ in RestToolbox.DoGet('{}/patients'.format(URL)):
    patientinfo = RestToolbox.DoGet('{}/patients/{}'.format(URL, patient_))
    if patientinfo['MainDicomTags']['PatientBirthDate'] == patient[0]['PatientBirthDate']:
        print('Patient found!')

t3 = time.time()

print('C-Find SCU PatientID query took {:.2f}s'.format(t1 - t0))
print('C-Find SCU PatientBirthDate query took {:.2f}s'.format(t2 - t1))
print('REST-loop PatientBirthDate query took {:.2f}s'.format(t3 - t2))

Hello,

Thanks for your feedback. This is a direct consequence of the fact that the embedded SQLite database of Orthanc only indexes the PatientID, the StudyInstanceUID, the SeriesInstanceUID and the SOPInstanceUID tags.

In the absence of a PatientID in the query, the C-Find SCU lookup will loop over all the patients and will read the JSON summary for each patient. This involves read accesses to the filesystem, and the parsing of JSON files, which is time-consuming.

I however agree that the REST-loop and the C-Find SCU should have the same performance. I have added a task on the roadmap:
https://trello.com/c/U3qUg63Q

I am also considering extending the plugin SDK to write custom C-Find SCP handlers.

Sébastien-

Hello,

FYI, the mainline of Orthanc now fixes the slowdown problem you noticed. Here are the running time when 150 random patients are stored into Orthanc:

Orthanc 0.8.6:

C-Find SCU PatientID query took 0.06s
C-Find SCU PatientBirthDate query took 0.51s
REST-loop PatientBirthDate query took 0.21s

Orthanc mainline:
C-Find SCU PatientID query took 0.05s

C-Find SCU PatientBirthDate query took 0.05s
REST-loop PatientBirthDate query took 0.19s

The “PatientBirthDate” lookup is thus 10 times faster now. This improvement will be included in the next release.

Sébastien-