Bulk Update on a Medic Reports

Hi,

I need some help to bulk update a medic reports on the backside.

This is the story: we develop a form and somehow, there is a condition on the form that it wasn’t met so it will return as error. So, I was thinking if there is a possible solution to create a preload data that there is the corrected data.

What I prepared a document was like for edit-contacts, I gather the uuid and the column variable in it and use this command to update a submitted report.

medic-conf --url=https://username:password@website  --accept-self-signed-certs edit-contacts -- --column=g_malnutrition.g_edema.g_recalculate_zscore.maln_status

But instead, I got this error message.

So, what should I use command on medic-conf ( we don’t have still the cht-conf command), to bulk update a report?

Thanks for helping.

What did you recommend to bulk update a data_report ?

is there a centain command to do that?

What should I prepared a document to do it?

Thanks.

To the best of my knowledge, there is no way to bulk edit reports via cht/medic-conf.

In a production-sized database, it will require quite a bit of care to craft a solution that is performant (and the complexity would make it difficult to generalize into a cht-conf command). My recommendation would be to write a simple NodeJS script that could handle your custom logic. You can have a look at this repo as an example Node script that does basic interactions with Couch via the Couch HTTP api.

Specifically, you will probably want to do a view query against an existing view such as medic-client/reports_by_form view (note some of the medic views would allow for filtering the reports by date/parent. Depending on your situation, those might be better). Then you can make your modifications to the queried documents and upload the updates via the _bulk_docs endpoint.

Actually, I do this, we gather the incorrect reports that has an error in it, and then using medic-conf command

I think the edit-contacts is not correct on this scenario, so, do you think there is another command for this like edit-reports ?

Thanks.

Right, so I don’t think edit-contacts will work in this scenario (since really you need to edit the report documents). That is where the _bulk_docs endpoint comes in. When you pass a doc to that endpoint with _id and _rev values that match a doc that already exists in the DB, then Couch will just replace (update) the doc in the DB to match the data you have provided.