How to set up In-app analytics

jkuester,
Thank you, I have modified my code as below:

module.exports = [
  {
    id: 'percentage-covid-test',
    type: 'percent',
    icon: 'icon-healthcare-assessment',
    goal: -1,
    translation_key: 'targets.covid.title',
    subtitle_translation_key: 'targets.this_month.subtitle',
    appliesTo: 'contacts',
    appliesToType: ['person'],  
    passesIf: function covidPercTested(contact)
  {
      return contact.reports.some(report => report.form === 'screening' && report.fields.cov === 'true');
  }
  
    date:'reported'
  },

];

I get ..../targets.js. SyntaxError: Unexpected identifier

Now that we have the function defined, I think we donā€™t need to define any function in the nools-extras.jsfile

Still getting errors, need to figure this out today and define targets for the other items
If it works for Covid, it will work for the others

Right. If you just want to define the passesIf function inline, you can just put:

passesIf: function(contact)
{
return contact.reports.some(report => report.form === ā€˜screeningā€™ && report.fields.cov === ā€˜trueā€™);
},

(Donā€™t forget the comma before date:'reported')

jkuester
For ease of adding the other target values later, I went back to declaration in target and definition in nools-extras as below:
target.js

const extras = require('./nools-extras');
const {
  covidPercTested,
  } = extras; 

module.exports = [
  {
    id: 'percentage-covid-test',
    type: 'percent',
    icon: 'icon-healthcare-assessment',
    goal: -1,
    translation_key: 'targets.covid.title',
    subtitle_translation_key: 'targets.this_month.subtitle',

    appliesTo: 'contacts',
    appliesToType: ['person'],
    
    passesIf: covidPercTested,
  
    date:'reported',
  },

];

nools-extras

function covidPercTested(contact)
{
  return contact.reports.some(report => report.form === 'screening' && report.fields.cov === 'true');
},

module.exports = {
  covidPercTested,
};

I still get an error, have to figure this out before I leave for home today
ā€¦/targets.js. SyntaxError: Unexpected token ,

I was able to recreate your error. I think it is being caused by the extra comma that you have in your nools-extras.js file. At the end of the covidPercTested and before the module.exports = { line you have:

},

when It should just be:

}

One thing that might be helpful when trying to track down these syntax errors would be to just parse your targets.js file with Node (e.g. just run node targets.js). If there is a syntax error, the output from node will be a lot more helpful in identifying it then the output from cht-conf. Here is the output that I got:

āÆ node targets.js
/home/jlkuester7/git/cht-core/config/covid-19/nools-extras.js:46
},
 ^

SyntaxError: Unexpected token ','
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/jlkuester7/git/cht-core/config/covid-19/targets.js:1:16)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

1 Like

Dear jkuester
Thank you, our server is currently down due to power issues, thus not able to test, will test tomorrow
Wanted to create analytics for the whole National Office (Totals for the project) and the four branches (County1, County2,County3, County4), any ideas

Dear jkuester
From my understanding so far based on feedback and online documentation, I only need to configure targets.js and ā€˜nools-extras.jsā€™ for my dashboard widgets. Iā€™ve seen and read about the file tasks.js and now confused, do I need to configure this for the analytics dashboard to work?

My errors arenā€™t ending and Iā€™m figuring out why, we have a presentation of the dashboard tomorrow and will appreciate any ideas

@oyierphil I am sorry to hear that things are not working for you yet. You should not need any special configuration for your tasks.js to have working targets on your dashboard. I tried the following targets.js code on a test CHT instance and the widget displayed successfully for both a CHW user and a supervisor.

const covidPercTested = (contact) =>
{
  return contact.reports.some(report => report.form === 'screening' && report.fields.cov === 'true');
};

module.exports = [
  {
    id: 'percentage-covid-test',
    type: 'percent',
    icon: 'icon-healthcare-assessment',
    goal: -1,
    translation_key: 'targets.covid.title',
    subtitle_translation_key: 'targets.this_month.subtitle',
    appliesTo: 'contacts',
    appliesToType: ['person'],
    passesIf: covidPercTested,
    date: 'reported',
  },
];

covid_screenshot

Regarding the analytics for the whole National Office, something at that scale might be outside the scope of what is recommended for the targets.js file. This is outside my experience, so I cannot say for sure. But I will reach out to some other folks and see if they can weigh in here on the best way to do analytics at that scale.

Okay, so I was able to confirm with my colleagues that the targets defined in the targets.js file are really only intended to be used at the level of CHWs and their supervisors. Trying to use that framework to analyze very large numbers of documents (such as for the whole National Office) can cause performance issues.

For reporting and analytics on that large of a scale, we recommend sending the CHT data to a PostgreSQL database and then using a third-party visualization platform to create the desired dashboards based on that data. That process is described here in the CHT docs.

1 Like

Hey @oyierphil how did it go after the session we had today?

Kitsao
After pushing the targets.js and nools.js to both the test and production servers, the widgets are available on the test server but not showing data, while production server doesnā€™t show even the widgets from the form as below

;

I have also noted despite pushing the same forms to both the production and test servers, the Covid results are displayed in the downloaded data for the test server while the same is not displayed in the downloaded data for the production server as shown below:

Trying to figure out why, I can see the data captured but canā€™t see the same when I download?

jkuester
Thank you very much, I actually managed to debug the codes yesterday and see the widget
I have established that to pull data from the forms for targets, we need the formID, then groupname and finally fieldname for our case (Would appreciate any link to this)

Thus the widget is displayed on my test server and not on the production, and no data in both instances, the struggle continues :sweat_smile:

@oyierphil Iā€™ll point you to @jkuester 's comment above. Check that the role you want to avail in-app analytics to has can_view_analytics, can_view_analytics_tab and that they have direct access to reports of the type <form-id> you use in your targets. I think that would be the rapid response officer role. Also ensure that the contact linked to the account youā€™re testing with belongs to a place served directly by the role e.g. rapid response team in your case. Let us know how it goes.

1 Like

Kitsao
We tried all the roles, online and offline, data still not displayed
Do we have a situation where the widgets are visible but data not displayed because of roles and hierarchy?
What I have seen is targets either visible or not visible because of roles and hierarchy?

Do we have a situation where the widgets are visible but data not displayed because of roles and hierarchy?

Data will only be displayed for persons accessible to the user. (So for a given CHW, the widget would only display data for their patients.) Otherwise, I donā€™t think there is anything that would prevent a user that can see the widget from seeing data for patients accessible to them.

Did you end up implementing an appliesIf function in your target? If something is wrong with that function it might cause the 0 of 0 behavior in your screenshot.

Hey @oyierphil how did it go?

jkuester
We are preparing for end of semester exams, thus took a break, I still cant be able to display the data, only widgets available, and my code is as below:
target config

const extras = require('./nools-extras');

const {
  posCovidPercTested,
  negCovidPercTested,
 } = extras; 

module.exports = [  
  {
    id: 'percentage-positive-covid-test',
    type: 'percent',
    icon: 'medic-covid-case',
    goal: -1,
    translation_key: 'targets.posCovid.title',
    subtitle_translation_key: 'targets.this_month.subtitle',
    appliesTo: 'contacts',
    appliesToType: ['person'],
    passesIf: posCovidPercTested,
    date:'reported',
  },

  {
    id: 'percentage-negative-covid-test',
    type: 'percent',
    icon: 'medic-covid-case',
    goal: -1,
    translation_key: 'targets.negCovid.title',
    subtitle_translation_key: 'targets.this_month.subtitle',
    appliesTo: 'contacts',
    appliesToType: ['person'],
    passesIf: negCovidPercTested,
    date:'reported',
  },

];

nools-extra

const posCovidPercTested = contact => {
  return contact.reports.some(report => report.form === 'case_investigation' && report.fields.testing.cov_test === 'Positive');
};

const negCovidPercTested = contact => {
  return contact.reports.some(report => report.form === 'case_investigation' && report.fields.testing.cov_test === 'Negative');
};

module.exports = {
  posCovidPercTested,
  negCovidPercTested,
 }; 

On it now and was following your thread, Did you end up implementing an appliesIf function in your target? No I didnā€™t
Given I just want to get percentage of people with Covid, how will the appliesif function look like?
Trying to figure this out

form_id: case_investigation
begin group testing
select_one test cov_test
end group

Test Choices
test Positive
test Negative

Tried some ideas and so far, no data shown, back to research, will appreciate any guide on what I am missing

Spent time yesterday looking at the server logs and didnā€™t find any errors, still stuck

Okay @oyierphil I think I figured out our problem here. After a bunch more debugging this morning (and some help from @diana :+1:) I realized that the issue is probably with the date:ā€˜reportedā€™ configuration.

The targets.js documentation says that when date is set to reported, ā€œthe target will count documents with a reported_date within the current month.ā€

The thing that I missed when reading that earlier is that, for targets with appliesTo: 'contacts', it is actually the reported_date on the contact doc that is checked (and not the reported_date on the reports for the contact). So, by having date:ā€˜reportedā€™ set for your targets, you are making those targets only consider contacts that were added this month.

Switching to date:'now' should make the targets consider all contacts (regardless of their reported_date). Then, you can update your posCovidPercTested/negCovidPercTested functions to filter the reports by their own reported_date so that you only apply if the report was in the last month (or whatever time range you define).