"Error fetching tasks" - Tasks not appearing

Hi!

I am not able to see any tasks, neither built-in default tasks as well as the ones I made myself.
For example I filled delivery form and choose alive and unwell in this form so it should initiate task to fill the form: pnc-danger-sign-follow-up-mother but that’s not happening. Also I made two forms of my own and tried to create task which opens another form when one is finished and it failed too.

I tried to debug inserting console.log() to tasks.js in different kind of tasks, but in console I could not not see any of my logs. I enabled debug mode in app and gave all the permissions to every role as it was suggested in documentation.

Maybe it is helpful that in console there is a following error displayed:

Thank you for any advice!

  • Instance: local
  • Browser: Chrome
  • Client platform: Windows subsystem Ubuntu
  • App: webapp
  • Version: 3.7.0, master

Regards
Tamor

Hi Tamor,

The tasks are probably not showing up because of the error shown in the console.
Thanks for attaching the console error. Looks like your task is expecting some object with type attribute in it. But the object itself is in an undefined state, that is never set. It could be getting a non-existent/malformed report or contact. Reports generally have type = data_record, whereas contacts can be one of the types: person, clinic, health_center, district_hospital, or anything else defined as a place type.

As you have mentioned, you have added two forms of your own and tried to create a task. When you remove the extra reports (no need to remove the forms), and extra task logic that you have added, do you still see the same error in the console?

The console.log() should work. Can you please try again by inserting it at the first line of your tasks.js? You might also find debugger; statement useful.

Thanks

Thank you for the quick answer!

You were right that application starts to work properly when I remove extra reports.

I checked from database and my report has the type data_record. I do not believe that any parameter could be wrong or missing for data records since they look similar to working data records.

I tried this: I made an exact copy of death_report and uploaded it as death_report2 but the application continued to malfunctione as before so it seems that the mistake is somewhere else than in my form. I also used only default tasks and targets.

I did not mention before, that targets also stop working when I fill new selfmade report. It just displays loading image.

In console there were various other errors and they occurred quite randomly, for example:

  • Error getting tasks TypeError: Cannot read property ‘dueDate’ of undefined
  • Error fetching targets TypeError: Cannot read property ‘dueDate’ of undefined
  • tasks.resolvedIf is not a function etc

I still struggle with getting those tasks working so I appreciate any help.

Hi Tamor,

When making a copy of death_report as death_report2, did you also change the form_id in settings tab of the XLS form?

Thanks

hello @binod @jkuester

i have configured a task to appear when a blood draw appointment option is select on the appointment of a particular patient as seen below

{
    name: 'blood-appointment-reminder-task',
    title: 'Blood draw Appointment Reminder',
    icon: 'assessment',
    appliesTo: 'reports',
    appliesToType: ['appointment'],
    appliesIf: function(c, r){
      return r.fields.appoint.type_appoint === 'blood draw appointment';
      
    },
    // the form_id of the form to appear in the tasks tab
    actions: [{ form: 'blood_draw_appointment_reminder', 
 
   }],
    events: [{
      start: 1,
      end: 1,
      dueDate: function (event, contact, r) {
        return Utils.addDate(new Date(getField(r, 'appoint.date_appoint')), 0);
      }
    }],
    resolvedIf: function(c, r, event, dueDate) {
      // Resolved if there is a reminder received in time window
      return isFormFromArraySubmittedInWindow(c.reports, 'reminder',
                 Utils.addDate(dueDate, -event.start).getTime(),
                 Utils.addDate(dueDate,  event.end+1).getTime());
    },
  },

Below is a payload doc sample of the appointment form filled out on a patient

{
 "id": "8de6f865-9ee0-4c0b-b000-ea853ddbb70c",
 "key": [
  "appointment",
  "745e0796-3bd3-4df5-aade-fd4f1d1840d2"
 ],
 "value": 1692879479601,
 "doc": {
  "_id": "7de6f865-9ee0-4c0b-b000-ea873ddbb70c",
  "_rev": "1-6dbf73cf81b5b36212fa3f48a86629d8",
  "form": "appointment",
  "type": "data_record",
  "content_type": "xml",
  "reported_date": 1692879479601,
  "contact": {
   "_id": "1868ba20-6b1c-4323-b0fe-99d9261338ae",
   "parent": {
    "_id": "745e0796-3bd3-4df5-aade-fd4f1d1840d2"
   }
  },
  "from": "+256785579890",
  "form_version": {
   "time": 1692564086680,
   "sha256": "8d5e16f69eb30ec5b5030daf54bb5588ca7aa78eb2e8fb6a72bbaa688594474b"
  },
  "hidden_fields": [
   "meta"
  ],
  "fields": {
   "inputs": {
    "meta": {
     "location": {
      "lat": "",
      "long": "",
      "error": "",
      "message": ""
     },
     "deprecatedID": ""
    },
    "source": "contact",
    "source_id": "",
    "contact": {
     "_id": "b0d90405-8390-4dcc-9c35-a93d07b161b9",
     "patient_id": "65444",
     "name": "Jevon Test",
     "date_of_birth": "2022-12-01",
     "sex": "",
     "name1": "Test",
     "aka": "",
     "tsis": "5",
     "at": "male",
     "genda": "gender_male",
     "parent": {
      "contact": {
       "phone": "+256785579890",
       "name": "Cliff Test"
      }
     }
    }
   },
   "patient_id": "65444",
   "patient_name": "Jevon Test",
   "patient_name1": "Test",
   "patient_aka": "",
   "patient_tsis": "5",
   "patient_genda": "gender_male",
   "patient_at": "male",
   "patient_date_of_birth": "2022-12-01",
   "fast_name_ctx": "Jevon Test",
   "last_name_ctx": "",
   "date_of_birth_ctx": "2022-12-01",
   "aka_ctx": "",
   "tsis_ctx": "5",
   "at_ctx": "male",
   "yr_date_of_birth_ctx": "1",
   "gender_ctx": "gender_male",
   "appoint": {
    "first_name": "",
    "nick": "",
    "age_n": "",
    "gender_n": "",
    "dob": "",
    "n_special_instruction_title": "",
    "complete": "hjhhjhjh",
    "type_appoint": "blood draw appointment",
    "welcome": "",
    "lab_test": "viral load",
    "date_appoint1": "2023-08-25"
   },
   "meta": {
    "instanceID": "uuid:aa57273c-50a0-48b1-a4c2-7084c3e5474a"
   }
  },
  "geolocation_log": [
   {
    "timestamp": 1692879479608,
    "recording": {
     "code": 1,
     "message": "User denied Geolocation"
    }
   }
  ],
  "geolocation": {
   "code": 1,
   "message": "User denied Geolocation"
  },
  "_attachments": {
   "content": {
    "content_type": "application/xml",
    "revpos": 1,
    "digest": "md5-pFb/YFC3kH0SNGfxZlKP8Q==",
    "length": 2379,
    "stub": true
   }
  }
 }
}

Not sure why the Blood draw Appointment Reminder task is still not appearing in the tasks tab

@cliff I tried to recreate the issue with your task config here, but it seems to work as expected for me!

Maybe you could add some console.log statements to the functions in your task config block and try printing some of the values you are getting to double-check the logic. Then on the browser open the Tasks tab and check the browser logs for your messages (and/or any other errors).

1 Like

hello @jkuester
i have logged to the console the task triggering logic

 {
    name: 'blood-appointment-reminder-task',
    title: 'Blood draw Appointment Reminder',
    icon: 'assessment',
    appliesTo: 'reports',
    appliesToType: ['appointment'],
    appliesIf: function(c, r){

      console.log( r.fields.appoint.type_appoint);
      return r.fields.appoint.type_appoint === 'blood draw appointment';
      
    },
    actions: [{ form: 'blood_draw_appointment_reminder', 
  
   }],
    events: [{
      start: 1,
      end: 1,
      dueDate: function (event, contact, r) {
        return Utils.addDate(new Date(getField(r, 'appoint.date_appoint')), 0);
      }
    }],
    resolvedIf: function(c, r, event, dueDate) {
      // Resolved if there is a reminder received in time window
      return isFormFromArraySubmittedInWindow(c.reports, 'reminder',
                 Utils.addDate(dueDate, -event.start).getTime(),
                 Utils.addDate(dueDate,  event.end+1).getTime());
    },
  },

and it displays the desired results

Okay, so this is a start! We know your task config has been successfully deployed and is being recognized:

  • :ballot_box_with_check:appliesTo
  • :ballot_box_with_check:appliesToType
  • :ballot_box_with_check:appliesIf
  • actions
  • events
  • resolvedIf

The next thing to check is the events. In your appliesIf function, can you also log out Utils.addDate(new Date(getField(r, 'appoint.date_appoint')), 0) and see what value that gives you? Task visibility is going to be determined by the dueDate so we want to be sure that is what we expect. Also, now is a good time to double-check your resolvedIf. In this case, you want to look for any existing reminder reports for the contact with a reported_date that is near the dueDate. (Remember that the reminder reports found by the resolvedIf function do not have to be created after the initial appointment report that triggers the task. Existing reminder reports can suppress the creation of new instances of blood-appointment-reminder-task.)

hello @jkuester

the inspecting feedback of the due date from the browser shows an invalid date

@jkuester the tricky bit is that for another Appointment Reminder task configuration, the due date is captured as seen below

{
    name: 'appointment-reminder-task',
    title: 'Appointment Reminder',
    icon: 'assessment',
    appliesTo: 'reports',
    appliesToType: ['appointment'],
    appliesIf: function(c, r){
      return r.fields.appoint.type_appoint === 'clinical appointment' 
    },
    actions: [{ form: 'appointment_reminder', 
   }],
    events: [{
      start: 1,
      end: 1,
      dueDate: function (event, contact, r) {
      /console.log(Utils.addDate(new Date(getField(r, 'appoint.date_appoint')), 0));

        return Utils.addDate(new Date(getField(r, 'appoint.date_appoint')), 0);
      }
    }],
    resolvedIf: function(c, r, event, dueDate) {
      // Resolved if there is a reminder received in time window
      return isFormFromArraySubmittedInWindow(c.reports, 'reminder',
                 Utils.addDate(dueDate, -event.start).getTime(),
                 Utils.addDate(dueDate,  event.end+1).getTime());
    },
  },

the inspecting feedback of the due date from the browser shows an invalid date

Definitely seems like it is not able to load the date from the report.

the tricky bit is that for another Appointment Reminder task configuration, the due date is captured

This was a very interesting to me since the task configs are basically identical. That made me go back and have a much closer look at the doc JSON in your original post. It was then that I noticed that in the JSON, your appoint.date_appoint field is actually named date_appoint1!!! Can you double-check this name in your form config? Our trouble here might be as simple as a naming mismatch between the form field and the task config…

@jkuester yeah you are right its the same issue i have discovered while i was do some more debuggings :slightly_smiling_face:

it works fine now

thanks a bunch for your time :100:

1 Like