How to restrict tasks to various levels

I have 2 levels of users, chp and chp_supervisor. The challenge I am facing is that I need to access reports so as to generate tasks for the chp. However when I do this, the chp_supervisor also views these tasks. This should not be the case.

I have read this post but it assumes that I can interchangeable use ‘reports’ and ‘contacts’. In my case If use ‘contacts’ then I only get the user at that level but I can’t access the reports to analyze.

The attached snippet is what I currently have that correctly creates tasks from reports but does not restrict the hierarchy to display it in. Is there a way out of this?
{
name: ‘follow-up-household-member’,
title: ‘Follow up household member’,
icon: ‘icon-healthcare-assessment’,
appliesTo: ‘reports’,
appliesToType: [‘household_member_assessment’],
appliesIf: function(contact, report){
let userHasDangerSigns = getField(report, ‘household_member_assessment.initial_symptoms’) === ‘yes’;
return userHasDangerSigns;
},
actions: [{form: ‘disease_follow_up’, label:‘Follow Up’}]
events: [{
start: 3,
end: 3,
dueDate: function(event, contact, report){
return new Date(report.reported_date + (event.start * 24 * 60 * 60 * 1000));
}
}],
priority: {level: ‘high’, label: ‘High Priority’},
},

Hey @kembo, could you please try with the following snippet?

{
    name: 'follow-up-household-member',
    title: 'Follow up household member',
    icon: 'icon-healthcare-assessment',
    appliesTo: 'reports',
    appliesToType: ['household_member_assessment'],
    appliesIf: function(contact, report){
    let userHasDangerSigns = getField(report, 'household_member_assessment.initial_symptoms') === 'yes';
    return userHasDangerSigns && user.role === 'chp_supervisor';
    },
    actions: [{form: 'disease_follow_up', label:'Follow Up'}],
    events: [{
    start: 3,
    end: 3,
    dueDate: function(event, contact, report){
    return new Date(report.reported_date + (event.start * 24 * 60 * 60 * 1000));
    }
    }],
    priority: {level: 'high', label: 'High Priority'},
    }

Take note of the appliesIf function where I’ve added the user role.

2 Likes

Aha nice stuff @Japheth_Kiprotich. I think I just didn’t know that the framework makes the current user available to the tasks. Maybe the docs should include this too. I also noticed the same for contact templated summaries that the docs are not clear on what is made available (contact, lineage, reports)

1 Like

Sure! @Esther_Moturi, this feedback sounds helpful.

1 Like

Hey @Japheth_Kiprotich and @kembo , sure, thanks! So we should add other items that can be configured under appliesIf to include restrictions for user roles?

@kembo what is missing under contact templated summaries ?

Yes we could:

  1. Let devs know that CHT avails global variables reports, contact and lineage to contact-summary.templated.js and they could access and use these e.g by
    const thisContact = contact;
    const thisLineage = lineage;
    const allReports = reports;
  2. Let devs know that the current user is made accessible to targets.js and tasks.js by CHT via the global variable user