Fastest way to get number of studies for all patients?

I have a largish Orthanc instance (~100k studies).

I would like to generate a report of patient name, patient id, count of studies.

What would be the fastest way to generate this?

If you use the Python Plug-in you could just make a callable script, or adapt it.

e.g.

# GETS STUDYCOUNT for an array of patientid's
# e.g. curl -k http://localhost:8042/patient/studycounts -d '["DEV0000001","DEV0000002"]'
# Returns e.g.:  {"DEV0000001": 4, "DEV0000002": 3}

def getPatientStudyCounts(output, uri, **request):

    if request['method'] != 'POST':
        output.SendMethodNotAllowed('POST')
    else:
        answers = dict();
        patients = json.loads(request['body'])
        for patient in patients:
            query = '{"Level":"Study","Expand":false,"Query":{"PatientID":"' + patient +  '"}}'
            answers[patient] = len(json.loads(orthanc.RestApiPost('/tools/find',query)))
        output.AnswerBuffer(json.dumps(answers, indent = 3), 'application/json')
orthanc.RegisterRestCallback('/patient/studycounts', getPatientStudyCounts)

Thanks. It turned out that just calling the API and asking for all patients was far less expensive than I thought it would be; it only took about 30 seconds!

That is pretty fast !!