# Missing task ids

**URL:** <https://forum.communityhealthtoolkit.org/t/missing-task-ids/4697>\
**Category:** Technical Support\
**Tags:** tasks\
**Created:** [February 27, 2025, 8:34am UTC](https://forum.communityhealthtoolkit.org/t/missing-task-ids/4697 "2025-02-27T08:34:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerald](https://communityhealthtoolkit.b-cdn.net/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@Gerald](https://forum.communityhealthtoolkit.org/u/Gerald)\
**Post date:** [February 27, 2025, 8:34am UTC](https://forum.communityhealthtoolkit.org/t/missing-task-ids/4697/1 "2025-02-27T08:34:09Z")

</div>

I’m currently exploring task management features within Medic Mobile and am interested in understanding how tasks are created, stored, and monitored within the system—particularly any details on checking or retrieving tasks (including those that may not appear in the standard user interface).

Currently, I have report uuids whose task\_uuids I can not see in my tasks data.  
And also what cpould be causing this, to have a report submitted but the task from which a report was triggered can not be seen?

---

<div class="post-metadata">

**Author:** ![Prajwol](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/prajwol/32/1328_2.png) [@Prajwol](https://forum.communityhealthtoolkit.org/u/Prajwol)\
**Post date:** [February 27, 2025, 2:29pm UTC](https://forum.communityhealthtoolkit.org/t/missing-task-ids/4697/2 "2025-02-27T14:29:56Z")

</div>

Hey Gerald,

You can read more about the task schema, configuration and its creation [here](https://docs.communityhealthtoolkit.org/building/tasks/tasks-js/) and an easy to understand example can be found [here](https://docs.communityhealthtoolkit.org/building/tasks/simple-tasks/#1-define-a-simple-task).

If I can understand correctly you are submitting a report that should trigger a task, but that task isn’t appearing? If you submitted a report and are expecting a task there are several reasons a task might not appear:

**Task Creation Logic checks:**

- Task start date is yet to come or due date or end date has passed _(corresponding task schema parameter: appliesTo,appliesToType)_: Say you submit a pregnancy report and are expecting an ANC visit task, the ANC visit might be configured to appear 20 days after the reported days for 7 days. So until 20 days after the pregnancy was reported (start\_date) has not passed the task will not appear. Alternatively, consider that the report was submitted 30 days ago but the task was configured to only show for 20+7 i.e. upto the 27th day of reporting(due\_date) the task would not appear when you check on the 30th day.

- The conditions to trigger the task creation is not met _(corresponding task schema parameter: appliesIf)_: We have another parameter called **applies\_if** in task schema, which can be used to control which reports, patient attributes, reports’ parameters etc would trigger a task creation, if this is not met, the task will not be created as well.

**“Currently I report uuids whose task\_uuids I can not see in my tasks data”** - Could you please tell me how you are currently checking this data? Also, you mention task\_uuids which doesn’t seem to be a standard named variable for tasks in CHT so could you please elaborate on this?

**For Task monitoring:**  
If you have access to the underlying CouchDB docs in postgres via [couch2pg](https://docs.communityhealthtoolkit.org/building/tutorials/couch2pg-setup/) or [CHT Sync](https://docs.communityhealthtoolkit.org/hosting/analytics/), you can use a query like follows to get the task details for each task and fiddle over them in excel or any dashboarding tool like superset.

Supposing you have the couchDb table. The following query skeleton should work to extract task data.

```auto
SELECT 
    ---- contact hierarchical info ----
    couchdb.doc ->> '_id' AS task_id,
    couchdb.doc ->> 'type' AS type,
    Date(TO_TIMESTAMP((couchdb.doc ->> 'authoredOn')::BIGINT / 1000)) AS authored_on,
    couchdb.doc -> 'stateHistory' AS state_history,
    couchdb.doc ->> 'user' AS "user",
    (couchdb.doc -> 'emission') ->> '_id' AS emission_id,
    (couchdb.doc -> 'emission') ->> 'title' AS task_title,
    (couchdb.doc -> 'emission') ->> 'icon' AS emission_icon,
    (couchdb.doc -> 'emission') ->> 'deleted' AS emission_deleted,
    (couchdb.doc -> 'emission') ->> 'resolved' AS emission_resolved,
    (couchdb.doc -> 'emission') -> 'actions' AS emission_actions,
    ((couchdb.doc -> 'emission') -> 'contact') ->> 'name' AS contact_name,
    ((couchdb.doc -> 'emission') ->> 'dueDate')::DATE AS due_date,
    ((couchdb.doc -> 'emission') ->> 'startDate')::DATE AS start_date,
    ((couchdb.doc -> 'emission') ->> 'endDate')::DATE AS end_date,
    (couchdb.doc -> 'emission') ->> 'forId' AS patient_uuid_from_task,
    (((couchdb.doc -> 'emission') -> 'actions') -> 0) ->> 'type' AS action_type,
    (((couchdb.doc -> 'emission') -> 'actions') -> 0) ->> 'form' AS action_form,
    (((couchdb.doc -> 'emission') -> 'actions') -> 0) ->> 'label' AS action_label,
    ((((couchdb.doc -> 'emission') -> 'actions') -> 0) -> 'content') ->> 'source' AS action_content_source,
    ((((couchdb.doc -> 'emission') -> 'actions') -> 0) -> 'content') ->> 'source_id' AS action_content_source_id,
    ((((couchdb.doc -> 'emission') -> 'actions') -> 0) -> 'content') ->> 'danger_sign_code' AS action_content_danger_sign_code,
    couchdb.doc ->> 'state' AS state
FROM couchdb
--- join contact Hierarchy tables ---
WHERE (couchdb.doc ->> 'type') = 'task'

```

Then you can create a chart like this in superset tracking each Community health workers’ due task across various time ranges.

 ![image](https://communityhealthtoolkit.b-cdn.net/uploads/default/original/2X/7/75cf6a033391ef19ab6d4455711865a614f5af49.png)

Let me know if this helps. Also, Feel free to set up a meeting with me if necessary.

---

<div class="post-metadata">

**Author:** ![Gerald](https://communityhealthtoolkit.b-cdn.net/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@Gerald](https://forum.communityhealthtoolkit.org/u/Gerald)\
**Post date:** [February 28, 2025, 1:15am UTC](https://forum.communityhealthtoolkit.org/t/missing-task-ids/4697/3 "2025-02-28T01:15:49Z")

</div>

Hi Prajwol, thanks for the reply,

Let me put it this way, I have two queries where I’m extracting id for analysis.

1. Query with all Tasks  
SELECT  
tasks.doc -\>\> ‘\_id’::text AS task\_uuid,  
to\_timestamp((((tasks.doc -\>\> ‘authoredOn’::text)::bigint) / 1000)::double precision) AS task\_date,  
tasks.doc -\>\> ‘state’::text AS task\_current\_state,  
tasks.doc -\>\> ‘stateHistory’::text AS task\_hist,  
((tasks.doc → ‘stateHistory’::text) → 0) -\>\> ‘state’::text AS task\_hist\_s1,  
to\_timestamp((((((tasks.doc → ‘stateHistory’::text) → 0) -\>\> ‘timestamp’::text)::bigint) / 1000)::double precision) AS task\_histtime\_s1,  
((tasks.doc → ‘stateHistory’::text) → 1) -\>\> ‘state’::text AS task\_hist\_s2,  
to\_timestamp((((((tasks.doc → ‘stateHistory’::text) → 1) -\>\> ‘timestamp’::text)::bigint) / 1000)::double precision) AS task\_histtime\_s2,  
((tasks.doc → ‘stateHistory’::text) → 2) -\>\> ‘state’::text AS task\_hist\_s3,  
to\_timestamp((((((tasks.doc → ‘stateHistory’::text) → 2) -\>\> ‘timestamp’::text)::bigint) / 1000)::double precision) AS task\_histtime\_s3,  
split\_part(tasks.doc -\>\> ‘user’::text, ‘:’::text, 2) AS task\_chc\_userid,  
tasks.doc #\>\> ‘{emission,actions,form}’::text AS task\_report,  
tasks.doc #\>\> ‘{emission,actions,label}’::text AS task\_report\_name,  
tasks.doc #\>\> ‘{emission,title}’::text AS task\_title,  
(tasks.doc #\>\> ‘{emission,dueDate}’::text)::date AS task\_duedate,  
(tasks.doc #\>\> ‘{emission,startDate}’::text)::date AS task\_startdate,  
(tasks.doc #\>\> ‘{emission,endDate}’::text)::date AS task\_enddate,  
tasks.doc #\>\> ‘{emission,forId}’::text AS task\_hhmem\_uuid,  
tasks.doc #\>\> ‘{emission,deleted}’::text AS task\_deleted,  
tasks.doc #\>\> ‘{emission,resolved}’::text AS task\_resolved ,  
split\_part(tasks.doc -\>\> ‘\_id’::text, ‘~’::text, 3) AS report\_uuid  
FROM couchdb tasks  
WHERE (tasks.doc -\>\> ‘type’::text) = ‘task’::text;

2. Query with all the submitted finished tasks (reports)  
SELECT  
rr.doc -\>\> ‘\_id’::text AS report\_uuid,  
to\_timestamp((((rr.doc -\>\> ‘reported\_date’::text)::bigint) / 1000)::double precision) AS report\_date,  
rr.doc -\>\> ‘form’::text AS which\_report,  
rr.doc #\>\> ‘{fields,g\_introduction,screenings}’::text AS screenings,  
rr.doc #\>\> ‘{fields,health\_topic}’::text AS health\_topic,  
rr.doc #\>\> ‘{fields,inputs,contact,\_id}’::text AS hhmem\_uuid,  
rr.doc #\>\> ‘{fields,inputs,contact,name}’::text AS patient\_name,  
rr.doc #\>\> ‘{fields,inputs,contact,patient\_id}’::text AS patient\_id,  
rr.doc #\>\> ‘{fields,inputs,contact,date\_of\_birth}’::text AS date\_of\_birth,  
rr.doc #\>\> ‘{fields,inputs,contact,gender}’::text AS gender,  
rr.doc #\>\> ‘{contact,\_id}’::text AS chc\_uuid,  
CASE  
WHEN (base.doc -\>\> ‘name’::text) = ‘GenSan’::text THEN ‘General Santos’::text  
ELSE base.doc -\>\> ‘name’::text  
END AS base\_name,  
“left”(branch.doc -\>\> ‘name’::text, 8) AS branch\_name,  
cluster.doc -\>\> ‘name’::text AS cluster\_name,  
mincluster.doc -\>\> ‘name’::text AS minicluster\_name,  
community.doc -\>\> ‘name’::text AS community\_name,  
community.doc -\>\> ‘sys\_community\_id’::text AS sys\_community\_id,  
CASE  
WHEN cm.which\_report = ‘mute’::text THEN ‘muted’::text  
WHEN cm.which\_report = ‘unmute’::text THEN ‘re-active (unmute)’::text  
ELSE ‘active’::text  
END AS hhmem\_status,  
parent.doc -\>\> ‘name’::text AS hh\_name,  
rr.doc #\>\> ‘{fields,data,meta,\_\_household\_uuid}’::text AS hh\_uuid  
FROM raw\_reports rr  
LEFT JOIN raw\_contacts parent ON (rr.doc #\>\> ‘{fields,data,meta,\_\_household\_uuid}’::text) = (parent.doc -\>\> ‘\_id’::text)  
LEFT JOIN raw\_contacts chc ON (rr.doc #\>\> ‘{contact,\_id}’::text) = (chc.doc -\>\> ‘\_id’::text)  
LEFT JOIN raw\_contacts community ON (chc.doc #\>\> ‘{parent,\_id}’::text) = (community.doc -\>\> ‘\_id’::text)  
LEFT JOIN raw\_contacts mincluster ON (community.doc #\>\> ‘{parent,\_id}’::text) = (mincluster.doc -\>\> ‘\_id’::text)  
LEFT JOIN raw\_contacts cluster ON (mincluster.doc #\>\> ‘{parent,\_id}’::text) = (cluster.doc -\>\> ‘\_id’::text)  
LEFT JOIN raw\_contacts branch ON (cluster.doc #\>\> ‘{parent,\_id}’::text) = (branch.doc -\>\> ‘\_id’::text)  
LEFT JOIN raw\_contacts base ON (branch.doc #\>\> ‘{parent,\_id}’::text) = (base.doc -\>\> ‘\_id’::text)  
LEFT JOIN contactview\_mutestatus cm ON (rr.doc #\>\> ‘{fields,inputs,contact,\_id}’::text) = cm.hhmem\_uuid  
WHERE (rr.doc -\>\> ‘form’::text) = ANY (ARRAY[‘screening’::text, ‘screening\_adulthood’::text, ‘cmami\_screening’::text, ‘lactating\_mother\_screening’::text])  
ORDER BY (rr.doc -\>\> ‘reported\_date’::text)

Explaination

- You can see in both queries I have a column called report\_uuid.
- If a task is completed, its report ID (in this case report\_uuid ) appears in query 2.

Problem  
I have report IDs ( report\_uuid ) in query 2 I can not trace back in query 1 (Tasks)

---

<div class="post-metadata">

**Author:** ![antony](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/antony/32/69_2.png) [@antony](https://forum.communityhealthtoolkit.org/u/antony)\
**Post date:** [March 11, 2025, 10:22am UTC](https://forum.communityhealthtoolkit.org/t/missing-task-ids/4697/4 "2025-03-11T10:22:08Z")

</div>

Hi @Prajwol, do you have any additional insights that can help @Gerald to access the required task data?

---

<div class="post-metadata">

**Author:** ![Prajwol](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/prajwol/32/1328_2.png) [@Prajwol](https://forum.communityhealthtoolkit.org/u/Prajwol)\
**Post date:** [March 11, 2025, 11:36am UTC](https://forum.communityhealthtoolkit.org/t/missing-task-ids/4697/5 "2025-03-11T11:36:01Z")

</div>

@Gerald

1. Can you try to get the task\_report\_Id by querying the task document itself and check.

```auto
SELECT 
    couchdb.doc -> 'emission'-> 'actions'->'content'->>'source_id' AS task_source
    from couchdb
WHERE (couchdb.doc ->> 'type') = 'task';

```

1. Could you tell me how you are searching for the report? Are you looking into both the CouchDB and RDS?

Let me know

---

<div class="post-metadata">

**Author:** ![Gerald](https://communityhealthtoolkit.b-cdn.net/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@Gerald](https://forum.communityhealthtoolkit.org/u/Gerald)\
**Post date:** [March 17, 2025, 3:19am UTC](https://forum.communityhealthtoolkit.org/t/missing-task-ids/4697/6 "2025-03-17T03:19:03Z")

</div>

@Prajwol  
I’m getting the task\_id the same way you illustrate it above.

I think there might be an issues with my task configuration. There some report ids that were missing in my task data over 10 days ago but now I can see them.

Let me keep investigating and see what I find.

---

<div class="post-metadata">

**Author:** ![Prajwol](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/prajwol/32/1328_2.png) [@Prajwol](https://forum.communityhealthtoolkit.org/u/Prajwol)\
**Post date:** [March 17, 2025, 5:26am UTC](https://forum.communityhealthtoolkit.org/t/missing-task-ids/4697/7 "2025-03-17T05:26:59Z")

</div>

Sure. Let me know if you need any more help.
