Community Health Toolkit

Syntax for filters on reports API

Hi hi! I’m trying to run a filter for specific report types based on the form used to create them. I’m using the reports API and can get the basic call to export everything working no problem:

curl "https://medic:PASSWORD-HERE@SERVERHERE.org/api/v2/export/reports" > output.csv

However, when I go to filter this to only show reports named covid19_rdt_capture using the example on the docs page, it doesn’t work. The call I’m using is:

curl "https://medic:PASSWORD-HERE@SERVERHERE.org/api/v2/export/reports?filters[search]=&filters[forms][selected][0][code]=covid19_rdt_capture" > output.csv

Instead of CSV output in output.csv, I get JSON:

{"error":"not_found","reason":"Database does not exist."}

Calling the /api/v1/forms to validate the form name is correct endpoint gives me this JSON:

["contact:clinic:create.xml","contact:clinic:edit.xml","contact:district_hospital:create.xml","contact:district_hospital:edit.xml","contact:health_center:create.xml","contact:health_center:edit.xml","contact:person:create.xml","contact:person:edit.xml","covid19_rdt_capture.xml","covid19_rdt_provision.xml"]

I’m not familiar enough with the underlying search API to know why I’m hitting the wrong database, presumably the wrong CouchDB database? I can find the record I’m after in fauxton here:

/_utils/#database/medic/ID_OF_RECORD_HERE

This all based on the COVID-19 reference app we’re developing.

Your request looks correct. I tried it against my local install and against a test instance and got expected results:

curl -g "http://admin:pass@127.0.0.1:6500/api/v2/export/reports?filters[search]=&filters[forms][selected][0][code]=covid19_rdt_capture"
_id,form,patient_id,reported_date,from,contact.name,contact.parent.name,contact.parent.parent.name,contact.parent.parent.parent.name
curl -g "https://<redacted>@gamma.dev.medicmobile.org/api/v2/export/reports?filters[search]=&filters[forms][selected][0][code]=undo_death_report" 
_id,form,patient_id,reported_date,from,contact.name,contact.parent.name,contact.parent.parent.name,contact.parent.parent.parent.name,data.__confirm_undo,data.meta.__household_uuid,data.meta.__patient_id,data.meta.__patient_uuid,data.meta.__source,data.meta.__source_id,inputs.contact._id,inputs.contact.date_of_birth,inputs.contact.name,inputs.contact.parent.parent.contact.name,inputs.contact.parent.parent.contact.phone,inputs.contact.patient_id,inputs.contact.sex,inputs.contact.short_name,inputs.meta.deprecatedID,inputs.meta.location.error,inputs.meta.location.lat,inputs.meta.location.long,inputs.meta.location.message,inputs.source,inputs.source_id,meta.instanceID,patient_age_in_days,patient_age_in_months,patient_age_in_years,patient_display_name,patient_id,patient_name,patient_short_name,patient_uuid,undo.undo_information
"64bf7c75-e203-456b-8059-6196e5ffd160","undo_death_report",,<redacted>,"<redacted>","patient","hello",,,"yes","","07651","aef84016-a06d-48b7-8701-dc3334ce4ddd","user","","aef84016-a06d-48b7-8701-dc3334ce4ddd","2021-09-01","Steve Kshlerin I","","","07651","female","","","","","","","user","","uuid:7ce296fb-dd0a-4d82-bf61-5b3e393546a5","13","0","0","Steve Kshlerin I","07651","Steve Kshlerin I","","aef84016-a06d-48b7-8701-dc3334ce4ddd","yes"

Goodness me. I was baffled because indeed both your and my URIs worked. Checking my bash history more closely, I see all my earlier calls had an extra / in there every time, but I corrected that when I was crafting my post here. So this is wrong:

curl  "https://medic:PASSWORD-HERE@SERVERHERE.org//api/v2/export/reports?filters[search]=&filters[forms][selected][0][code]=covid19_rdt_capture"

And will result in the Database does not exist. error :sweat_smile:

Thanks for pointing me in the right direction @diana !