The count function is not working in Target.js

I have gone through the documentation of Target.
I am trying to modify the target.js. The target.js is successfully uploaded.
In the target section, the newly added translation_key is shown.
But the counting is not working. It’s zero, not increasing at all .
// I guess it should increase

In the example below,
I first created an app form. .i.e screening_form .
Then tried counting the form filled as mentioned in the CHT documentation examples.

1. Define an All-Time Target Widge

Define the Total Screening Form Monthly Target Widget

Define the patient with Smoking == yes

module.exports = [
  {
    id: 'screenings-all-time',
    type: 'count',
    goal: -1,
    translation_key: 'targets.screenings.title',
    subtitle_translation_key: 'targets.all_time.subtitle',
    appliesTo: 'reports',
    appliesToType: ['screening_form'],
    date: 'now'
  },
  {
    id: 'screenings-this-month',
    type: 'count',
    goal: 2,
    translation_key: 'targets.screenings.title',
    subtitle_translation_key: 'targets.this_month.subtitle',
    appliesTo: 'reports',
    appliesToType: ['screening_form'],
    date: 'reported'
  },
  {
    id: 'total-contacts-with-smoke-yes',
    type: 'count',
    goal: -1,
    translation_key: 'targets.hypertension.total.smoke.title',
    subtitle_translation_key: 'targets.this_month.subtitle',
    appliesTo: 'reports',
    appliesToType: ['screening_form'],
    appliesIf: function (contact, report) {
      return Utils.getField(report, 'BP_measurement_preparation.smoke_history_30m')  ==='yes';
    },
    idType: 'contact',
    date: 'reported'
  },
];

Is it showing as zero for all three targets?

Yeah, it’s showing zero for all targets.
Is there anything also need to be done on other files ?

Nothing additional should be required. I’ve tested the first target you have above (screenings-all-time) and I see the count incrementing within the app I am testing.

My guess is that the likely difference is within your form (‘screening_form’).

Can we confirm something together? In the Form Schema there are some attributes which link the report to a “subject” (person or place):

Reports about people should have one or more of:

* A patient shortcode, found at doc.patient_id or doc.fields.patient_id
* A patient record’s _id, found at doc.patient_uuid or doc.fields.patient_uuid, as well as potientially in the same locations as the shortcode

Can you complete the screening_form form, view the report which results, and confirm one or more of these attributes are properly set? You can also sometimes confirm this by going to the reports tab and confirming the report is properly associated with the right subject.

2 Likes