How to set up In-app analytics

You have a target that should count all contacts with type: "person" regardless of their reports, and it is still showing up as zero. So, let’s try to solve it first before moving into targets that depend on reports.

Can you please make sure of these things?

  • the user who is looking at the target should also be able to see the contacts (patients) in the People tab
  • the patient contact doc should have type: "person"

If the above conditions are met, please look in the browser console to see if there are any errors reported when you open the targets tab.

@binod
My target.js file with * the patient contact doc with type: "person"

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

const {
  posCovidPercTested,
  negCovidPercTested,
  pendCovidPercTested,
} = extras; 

module.exports = [  
  {
    id: 'Covid-test-all-time',
    type: 'count',
    icon: 'medic-covid-case',
    goal: -1,
    translation_key: 'targets.Covid.title',
    subtitle_translation_key: 'targets.all_time.subtitle',
    appliesTo: 'reports',
    appliesToType:['person'],
    date:'now',
    idType: 'contact'
   },

  {
    id: 'posCovid-test-this-month',
    type: 'count',
    icon: 'medic-covid-case',
    goal: -1,
    translation_key: 'targets.posCovid.title',
    subtitle_translation_key: 'targets.this_month.subtitle',
    appliesTo: 'contacts',
    appliesToType:['person'],
    appliesIf:posCovidPercTested, 
    date: 'now',
  },

  {
    id: 'negCovid-test-all-time',
    type: 'count',
    icon: 'medic-covid-case',
    goal: -1,
    translation_key: 'targets.negCovid.title',
    subtitle_translation_key: 'targets.this_month.subtitle',
    appliesTo: 'contacts',
    appliesToType:['person'],
    appliesIf: negCovidPercTested,
    date:'now',
  },
  
  {
    id: 'pendCovid-test-all-time',
    type: 'count',
    icon: 'medic-covid-case',
    goal: -1,
    translation_key: 'targets.pendCovid.title',
    subtitle_translation_key: 'targets.this_month.subtitle',
    appliesTo: 'contacts',
    appliesToType:['person'],
    appliesIf: pendCovidPercTested,
    date:'now',
  },

];

I have seen browser errors as below:



Can you please update your first target to have appliesTo: 'contacts', instead of reports?:

{
id: 'Covid-test-all-time',
type: 'count',
icon: 'medic-covid-case',
goal: -1,
translation_key: 'targets.Covid.title',
subtitle_translation_key: 'targets.all_time.subtitle',
appliesTo: 'contacts',
appliesToType:['person'],
date:'now',
idType: 'contact'
}

@binod
The target file on the server reads as above at attached

Target file

Wondering the issue with translations, we didn’t change the file, we however added some fields, especially screening component and the extra tests

After looking at your config (thanks for the access), it looks like your contact_types section in the app_settings.json file does not have a contact type having id: "person".

So please change the targets appliesToType to include something that is in your contact types. You can specify multiple contact types there.

Then please create some contacts matching the contact type specified. After you log in as an offline user who can see the contact just created, your first target should show a number greater than zero.

@binod
I had noted that we don’t have a contact_type person, the reason I changed to contact instead of person

Our hierarchy is two level, a national office (DHARC-JKUAT) and four county offices (DHARC-KJD, DHARC-MKS, DHARC-NRB and DHARC KBU)

I’m trying to edit the contact type from another form to capture the hierarchy above, any ideas?

{
      "id": "person",
      "name_key": "contact.type.person",
      "group_key": "contact.type.person.plural",
      "create_key": "contact.type.person.new",
      "edit_key": "contact.type.person.edit",
      "primary_contact_key": "clinic.field.contact",
      "parents": [
        "district_hospital",
        "health_center",
        "clinic"
      ],
      "icon": "medic-person",
      "create_form": "form:contact:person:create",
      "edit_form": "form:contact:person:edit",
      "person": true
    }
  ],

The two levels you have mentioned (national office and county offices) represent the places.

  1. What are the contact types that represent people?
  2. Which contact types do you want to count in the first target?
  3. When you log in as an offline user, do the contacts appear in the People/Home tab?

Happy New Year Colleagues
Thank you @binod for the support, its been a working holiday, our targets are now up and running as below:


I summarize our experiences as below:

  1. We had picked the wrong contact type to represent the values we wanted to count, and this was sorted by going back to the app settings and reviewing the same. Our functions were not communicating with the back-end, the reason no data was displayed, and we sorted this by specifying the correct contact type
  2. We also had used the wrong type for date:‘reported’ without specifying the dates of interest, date:‘now’ did the work and summarized all our target values.
  3. We realized that the data downloaded was missing the field we wanted to build targets for. Using Fauxton (https://localhost/_utils/), we managed to access the report of interest and include the missing field. By running queries with Mango” in the left pane of Fauxton, it was possible to see which fields had data and which ones were affected by revisions, further making it possible to specify the report fields in the function definitions

Current challenge is now to display target data per place, four places as level 2 hierarchy, will update once it is sorted

1 Like