Task trigger to HH member(s) from a HH form

Is it possible to trigger a task to an individual household member(s) from a household form e.g., home visit?

We are trying to explore a way of triggering a task to a household member (or multiple household members) from the submission of one household form. Example:

As a CHW, I would like to conduct a routine home visit to a HH. Within the form, I’d like to know the HH members who are of child bearing age. From subsequent questions about these HH members, I’d should be able to select the HH members where a task should be triggered on their profiles if they satisfy a given condition.

Are there any suggestions on how to go about this?

1 Like

I think maybe there are a couple possibilities here. Unfortunately, there is no easy way (that I know of) to get a list of the current contact’s children (e.g. the persons in the household), with the exception of the primary contact (which is usually set on the parent contact). So, any method of triggering a task for these persons is going to require the user selecting the person(s) in the original report that triggers the task(s) (and, sadly, I don’t know of any way to limit the contacts available to select to just be the ones in a certain household…).

Option 1 - set contact on triggered form

The most straightforward way to trigger a form for a different contact is to just override the contact_id value on the triggered form (in the actions config for your task):

    actions: [
      {
        type: 'report',
        form: 'death_report',
        modifyContent: function (content, contact, report) {
          content.contact._id = getField(report, 'task_contact._id');
        }
      }
    ],

In this example, the death_report form will be triggered for the contact specified in the task_contact._id field of the report that triggered the task.

This approach is pretty simple, but there are a few downsides. In the Task tab, the contact displayed for the generated task will be the household contact (and not the selected person). You could fix that via the contactLabel task config, but then the task would not show on the contact profile page for the person. Additionally, it might be possible to somehow use this method to trigger forms for multiple persons, but I think it would be complex and inflexible…

Option 2 - write reports for each task to be triggered

The other option that comes to mind is to have your household visit form write separate reports (via the db-doc functionality) for each of the selected persons that a task should be triggered for. So, submitting the household visit form would create a household visit report as well as additional reports for each person who needs a task triggered. Then you just can have a normal task definition based on these custom additional reports that will trigger normal tasks for each of these contacts. This seems to be the most flexible/powerful approach.

1 Like