Tasks data is not showing on CouchDB

Hi,

I am checking a report uuid on CouchDB, and there is a record of it, but when I check the task for that one, there is no record. Is that even possible?

Or, my thinking is incorrect,

Tasks UUID > (once do a report) > Report UUID
Task data will be saved to couchdb
Report data will be saved to couchdb also.

Is this correct approach of data saving?

Thanks

Hi @Marcelo_De_Guzman!

Are you certain that the report was generated from a task and not from another action?

To verify, check if the report contains the field inputs.source. If it does, does it indicate "task"? This would confirm that the report originated from a task.

If the report was indeed created from a task, the task document should still exist in CouchDB, even though it gets purged from the user’s device 60 days after completion. The deletion from the device shouldn’t affect CouchDB’s records.

You might also want to double-check how you’re retrieving the task UUID and where exactly you’re looking for it. Could you share more details on your approach?

This related discussion might help:

Hi @Binod,


Yes, it has a word “task” on source. But, I can’t see the task data like this one:

task~org.couchdb.user:dumfl-b3-13~00004faa-2334-4de8-84a5-732c4bf903a0~screening~screening~1678236732214

But, there are some that the source doesn’t have a “task”.

There is a button that can access a survery called New Action,

And from this, we can do also a normal task and make an output of report.

Hi @Marcelo_De_Guzman,

Thank you for providing more details. The report is indeed generated from a task.

It’s still not clear to me how you are producing the expected task UUID (task~org.couchdb.user:dumfl-b3-13~00004faa-2334-4de8-84a5-732c4bf903a0~screening~screening~1678236732214) though.

Looking at the source_id on your report, the task UUID is more likely to be something like task~org.couchdb.user:dumfl-b3-13~f07fa423-97df-4aff-b5eb-d5ffce295b46~screening~screening~*

I guess you are using CouchDB Fauxton to inspect the task documents. In that case, this Mango query can be helpful to find all the tasks generated from your source document.

{
   "selector": {
      "type": "task",
      "_id": {
         "$regex": "f07fa423-97df-4aff-b5eb-d5ffce295b46",
      }
   }
}

You can click on Run A Query With Mango on your main CouchDB database to get into the page where you can put the above query.

Please let us know how it goes.

It doesn’t run on the Mango Query.

and when I click explain, this is the result.

Sorry, there was an extra comma earlier, please use this query instead:

{
   "selector": {
      "type": "task",
      "_id": {
         "$regex": "f07fa423-97df-4aff-b5eb-d5ffce295b46"
      }
   }
}

There are 5 documents that is shown.

So, my teams expectation about 1 task = 1 report is incorrect?

We have a calculation called incentives. We have volunteers to help us working out using the app. And once they have done a task and turned to a report, we will count it and based on the number of reports, they will gonna get a gifts in kind amount money. that is twice a month.

If the report is only accessible from tasks, then you can expect that a report is always coming from a task. Technically, it’s still possible to push the report via API, or directly on the database, but I think we can ignore such cases.

In your case, since the report is also available in “New action”, that assumption does not hold true because a report can be generated without having a task. However, for the report we saw above, it must have been generated by a task (assuming that the source field is not hardcoded).

The username palchc-c0br1-4 in these five tasks looks different than what you were looking for: dumfl-b3-13. Are you still not getting the task you were looking for?

You can also look further into the task documents and see their states with history. For example, a completed task would show:

  "stateHistory": [
    {
      "state": "Completed",
      "timestamp": 1664342094677
    }
  ],

Hi @Binod,

Yes, we saw that stateHistory, and it displays the state, so on that we can tag the report if it was completed or not.

I have another question, like if there is another report that doesn’t have a task id saved on database, we can refer the source_id ? is that right?

So, like
Task
'> Report1
'> Report2
'> Report3

So, on report3, we didn’t see the task but the source_id, we can still get the task_id by the source_id, is that right?

But, if we have report5, and the source_id is missing, what can you suggest to get the task_id or the source_id ? Or, is that even possible?

Thank you and God Bless for the help.

Hi @Marcelo_De_Guzman,

According to the CHT docs (Input data available in forms | Community Health Toolkit), the following fields are available in the report under the inputs group when a report is triggered by a task:

  • task_id: The unique identifier of the task in context.
  • source_id: For tasks with appliesTo: 'contacts, this is the id of the contact for the task. For tasks with appliesTo: 'reports', this is the id of the report which triggered the task.

Please note that these fields will only be populated if the corresponding form (XLS/XML) has these fields defined correctly.

On report3, if task_id is not present or empty but source = task, please check your XLS form.

Even if you don’t have task_id, you should still be able to find the corresponding task document in the CouchDB database by using the queries similar to what we tried above.

Here also, if source = task, but source_id is missing, you need to check your form. In that case, it’s still possible to find the task document by querying other contents of the task document, such as:

  • Username (doc.user)
  • Patient UUID (doc.requester or doc.owner)
  • Patient Name (doc.contact.name)
  • Task ID or doc.emission._id with regex (slower)
  • Task Title (doc.emission.title)
  • Due/start/end dates

Please check this document to get familiar with the task schema. You can also have a look at your task documents in CouchDB database to get full understanding. Running the following Mango query on CouchDB Fauxton should give you a plenty of task documents to spectate:

{
  "selector": {
    "type": "task"
  }
}