Missing task ids

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?

Hey Gerald,

You can read more about the task schema, configuration and its creation here and an easy to understand example can be found here.

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 or CHT Sync, 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.

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.

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

1 Like

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)

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

@Gerald

  1. Can you try to get the task_report_Id by querying the task document itself and check.
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

1 Like

@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.

2 Likes

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

1 Like