How to set up In-app analytics

jkuester
Used date: ‘now’ to see if we can consider all contacts and data not showing still, I take a break and review later

Colleagues
My widgets are visible, but data not visible still as shown below, any ideas on possible areas of problem

@oyierphil
Looking at the logic you’ve shared here, is there a chance you are comparing report.fields.testing.cov_test to the field label rather than the field value positive vs Positive? (Unsure how you’ve coded your forms)

Also, if the data was collected last month, the target widgets would not show any values (since you are using date:'reported' in your target definition)

@derick,
report.fields.testing.cov_test refers to the group label testing, field name cov_test and field type select_one test, with test choices as either Positive, Negative, Inconclusive or Pending

Choices have a label and a value. Do Positive, Negative, Inconclusive or Pending correspond to the choice labels or choice values?

Choice label is test, values are (test = Positive, Negative, Inconclusive or Pending) as shown below:

I was mistaken here
I see you aren’t implementing appliesIf. In essence, all the documents would not be considered for the target calculations since appliesIf would be falsy. Linking @jkuester’s earlier comment here for more context

Section of the current code for your review:
targets.js

const extras = require('./nools-extras');
const {
  posCovidPercTested,
  } = 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: 'contacts',
    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',
    idType: 'contact',
  },

nools-extras.js

const posCovidPercTested = contact => {

  return contact.reports.some(report => report.form === 'case_investigation' && report.fields.testing.test === 'Positive');
};

I made a correction to a wrong assertion here

Not having an appliesIf would not affect your current target calculation.

No worries, this has given me nightmares, will appreciate any more insights

Good morning
I am reviewing this file, Building Contact Summary | Community Health Toolkit

Do the Variable Definitions change when grouping is used? We grouped our sections as inputs [{ …, contact {…} …}], screening {…}, sampling {…}, lab {…}, testing {…}, r_summary{…}
Thus for example a field on the report reads inputs.contact.phone, while the variable in the file reads contact.phone
Could this affect the variables, thus the reason data isn’t displayed on the dashboard?

Please share the JSON of an actual saved report that you expect would appear in the counts for your dashboard. If it has any form of PII (Personally Identifiable Information), you can send it to me via DM.

Also. do you have any errors logged in your browser console log?

@derick
Sorry have taken long to respond, was away but came back today, could we do a call at your convenience to review? This is my holiday assignment and will relax if it is done

@derick
Didn’t understand the question, the report are downloaded in .csv format, while the case investigation forms are also in .csv format. I shared the json file for the targets and nools-extra above, please clarify

@oyierphil

I will try to help you get a report in the JSON format.

If you add /_utils/ to your root URL, then you can go to CouchDB Fauxton. From there, you can access the reports in JSON format.

Steps:

  1. Log in as an admin user
  2. Go to Fauxton e.g. https://localhost/_utils/
  3. From the list of databases, click on your database. It is usually medic.
  4. Click on “Run a Query with Mango” in the left pane
  5. Edit your query to look like this:
{
   "selector": {
      "form": "case_investigation"
   }
}
  1. Click on Run Query. You should now see the list of your reports matching the query.
  2. Click on one of them and share the contents here (after removing sensitive information).

Once you are inside a database in Fauxton, you can also go to a report or contact directly using its UUID.

In Fauxton, after entering a database, you can enter the document UUID in the text box named Document ID and go to the specified document.

UUID is the unique id of your document (contact, report, etc.). You can see the UUID of your contact or report in the URL of the web app when accessing it from a web browser.

e.g.
When you click on a report in the web app, the URL should be similar to this:
https://localhost/#/reports/d1d9af0f-011d-485f-98a1-76b12fe3df0c
Here, d1d9af0f-011d-485f-98a1-76b12fe3df0c is the UUID of this report.

When you go to a contact, the URL should be similar to this:
https://localhost/#/contacts/41c36e07-1a56-466b-88a7-7141938e0a2d
Here, 41c36e07-1a56-466b-88a7-7141938e0a2d is the UUID of this contact.

@Bhoola, Manoj
Thank you for the steps, I share the JSON file for the form case_investigation as below:

{
"_id": "002c45ee-79e1-4a3e-be07-4838788cf608",
"_rev": "2-57f32f1d6f3a8fe83b7e71dc756f2d10",
"form": "case_investigation",
"type": "data_record",
"content_type": "xml",
"reported_date": 1639651603504,
"contact": {
"_id": "f639b3a4-74ef-4bf3-83a1-bfbc8b561ba6",
"parent": {
"_id": "22a6a91c-2d1c-4fe4-8039-c69ab9782492",
"parent": {
"_id": "a76c9b24-371c-49d3-a701-09c7ef6112f4"
}
}
},
"from": "",
"hidden_fields": [
"meta"
],
"fields": {
"inputs": {
"meta": {
"location": {
"lat": "",
"long": "",
"error": "",
"message": ""
},
"deprecatedID": ""
},
"source": "contact",
"source_id": "",
"user": {
"name": "rrt1_mks"
},
"contact": {
"_id": "510b5d64-c895-44ad-99cf-c87cd22b4037",
"type": "contact",
"contact_type": "suspected_case",
"parent": "78e00e12-24ce-43c7-9e87-96eeff9538b0",
"role": "",
"case_id": "",
"case_name": "",
"national_id": "",
"passport_number": "",
"alien_number": "",
"s_name": "",
"f_name": "",
"o_name": "",
"name": "XXXX YYYY",
"sex": "",
"dob_known": "",
"date_of_birth": "",
"marital_status": "",
"education": "",
"nationality": "",
"phone": "",
"alternate_phone": "",
"county": "",
"subcounty": "",
"ward": "",
"village": "",
"pick_up": "",
"residence": "",
"nearest_health_center": "",
"kin_name": "",
"kin_relationship": "",
"kin_phone_number": "",
"nhif_cover": ""
}
},
"patient_id": "510b5d64-c895-44ad-99cf-c87cd22b4037",
"patient_name": "XXXX YYYY",
"username": "RRT1_MKS",
"uppercase_alphabet": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"lowercase_alphabet": "abcdefghijklmnopqrstuvwxyz",
"group_patient_information": {
"patient_info": "",
"n_national_id": ""
},
"screening": {
"biscreen": "",
"bi": "fever",
"cov": "fatigue headache",
"tb": "",
"cov_suspect": ""
},
"sampling": {
"nasal": ""
},
"lab": {
"monotonic_counter": "",
"specimen_id": "RRT1_MKS-",
"r_specimen_id": "",
"date_spec_coll": "2021-12-16",
"testing_lab": "Ag-RDT"
},
"testing": {
"cov_test": "Negative"
},
"rtpcr": "\n \n \n ",
"r_summary": {
"r_submit": "",
"r_summary": "",
"r_patient_info": "",
"n_national_id": "",
"r_screening": "",
"fever": "",
"fatigue": "",
"headache": "",
"ag_test": "",
"r_specimen": ""
},
"meta": {
"instanceID": "uuid:2c5753d6-4d6d-427c-83b9-9f63985f1f14"
}
},
"geolocation_log": [
{
"timestamp": 1639651603974,
"recording": {
"latitude": 0,
"longitude": 0,
"altitude": 0,
"accuracy": 4,
"altitudeAccuracy": null,
"heading": 0,
"speed": 0
}
},
{
"timestamp": 1639653364331,
"recording": {
"latitude": 0,
"longitude": 0,
"altitude": 0,
"accuracy": 4,
"altitudeAccuracy": null,
"heading": 0,
"speed": 0
}
}
],
"geolocation": {
"latitude": 0,
"longitude": 0,
"altitude": 0,
"accuracy": 4,
"altitudeAccuracy": null,
"heading": 0,
"speed": 0
},
"_attachments": {
"content": {
"content_type": "application/xml",
"revpos": 2,
"digest": "md5-E+CmuFaRtXhR5PmzzL7iqA==",
"length": 3856,
"stub": true
}
}
}

Edit: Latitude/longitude/altitude replaced by 0.

Thanks for the report in JSON, it looks like your test results are stored here:
report.fields.testing.cov_test

So you might want to update your posCovidPercTested function to match it.

Are you still getting all zeroes in the targets?

@binod
My current nools-extra.js file, the report.fields.testing.cov_test is properly indicated as shown, and I still get zeros:

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');
};

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

module.exports = {
  posCovidPercTested,
  negCovidPercTested,
  pendCovidPercTested,
};