Task report not on the right contact

Dear,

I am creating a task to have a follow up on a report (all the time). but I have 2 issues:

  1. the task report has as contact the CHW not the patient
    image

  2. I cannot find a way to close the task if there is a single report submitted that was generated from that task

could you help ?

module.exports = [

    {
        name: 'tchad_form_pause',
        icon: 'icon-healthcare-diagnosis',
        title: 'diagnostic',
        appliesTo: 'report',
        appliesToType: IMCI_FORMS,
        actions: [
            {
                type: 'report',
                form: TASK_FORM,
                modifyContent: generateIMCIContent
            }
        ],
        events: [
            {
                id: 'tchad_form_pause',
                days: 0,
                start: 1,
                end: 0
            }
        ],
        resolvedIf: IMCIresolveIf
    }
];
function IMCIresolveIf(contact, report, event) {

    return isFormArrayHasSourceId(contact.reports, event.id, [TASK_FORM]);
}
 
function isFormArrayHasSourceId(reports,id, formArray) {
    reports.forEach(function (report) {
      if (formArray.includes(report.form)) {
        if (report.source_id === id) {
          return true;
        }
      }
    });
    return false;
  }

var generateIMCIContent =  function (content, contact, report){
    //console.log('generateIMCIContent'+ content.source_id);
    content.patient_uuid = getField(report, 'patient_uuid');
    injectDataFromForm(content,'_case_',IMCI_CASE_DATA, IMCI_FORMS , [report]);
    //console.log('generateIMCIContent Done');
};

Hi @dercoip,
Those two issues could be related.

Please check the patient_id or patient_uuid field in the report document. Is it pointing correctly to the patient?

I think you are right, there is no patient_id or patient_uuid even if I should inject it

var generateIMCIContent =  function (content, contact, report){
    //console.log('generateIMCIContent'+ content.source_id);
    
    content.source_report_id = report._id;
    injectDataFromForm(content,'_case_',IMCI_CASE_DATA, IMCI_FORMS , [report]);
    content['patient_id'] = getField(report, 'patient_id');
// i tired content.patient_id = getField(report, 'patient_id');
    console.log('generateIMCIContent for' + content.patient_id);
};

the console log does show it, how should I inject it ?

The fields patient_id, and patient_uuid are usually set in the form itself as calculated fields. Please see this example of pregnancy form in the default configuration of cht-core:

It is similar to the sample form available in the CHT Docs.

Here, the patient_id and patient_uuid are copied from inputs/contact/.

Looking at your example, I don’t think you need to inject them from the task.

In the case you need to modify the patient_id to some other patient, the fields you have added to the content should be available in inputs section of the action form. From there, you can copy the field so that it is available outside of inputs:

Please have a look at this guide on passing data from a task into the app form.

1 Like

thanks

I had it on the inputs but the I deleted the one in the calculate by mistake :sweat_smile:

br

the second issue is worst now,

instead of closing the task it recreate another one …

I will have a look next week