What do the various `source` types represent on reports

Reports normally have a source field. I’ve seen 3 different values in this field: task, contact, and user. Are these the only possible values and are the assumptions below correct?

task - report was submitted from the #/tasks/ tab
contact - report was submitted from the #/contacts/tab
user - report was submitted from the #/reports/ tab

5 Likes

Yes, that is the way we’ve used them. That said, the field is created and set within forms, so it is more of a convention that we’ve used so far. A community health app using the Core Framework could have other values set, or not use this field at all.

1 Like

Thanks. Looking at the pregnancy form in the Antenatal Care Reference App as an example…


… I see a reference to ./source ='user' in the relevant field for the inputs group. There is also a default value set to user.

This is a form that is most likely accessed from the contacts tab. How/where/when does ./source get set… and if it gets set to contact, wouldn’t the entire inputs group be skipped?

1 Like

As you’ve already noted, the source field default (conventional) value of user is set directly in the form.

When the report is submitted from the Contacts tab, the value is changed to contact by webapp code here:

var instanceData = {
  source: 'contact',
  contact: contact.doc,
};
....
Enketo.render('#contact-report', form, instanceData)

When the report is submitted from the Task tab, the value is changed to task by the configuration code generated by medic-conf here:

var content = {
  source: 'task',
  contact: c.contact,
};

This value is used by webapp when rendering the form in the Task tab here

Enketo.render('#task-report', form, content)
4 Likes

if it gets set to contact , wouldn’t the entire inputs group be skipped?

Correct, that is intended. When accessing a form from the Reports tab the form doesn’t have the context to know who the form is about, so fields in the inputs section are used to ask the user to explicitly select the person (or place). When completing the form from the Contact or the Task tab the form knows who the report will be about so that whole inputs section is not displayed to the user.

Although this is mostly based on convention, there are a couple of things to note. As @diana mentioned, the Core Framework populates the source field when coming from a Contact or Task. Also, the inputs section is always saved with a report, even if the relevant condition is false.

Some additional background: Non-relevant fields used to always be saved with reports. This changed in 2.18. When this change occurred we updated the Core Framework to always save the inputs section, regardless of the relevant condition. More info can be seen in this GitHub issue: Inputs group not saved when its relevance is set to false · Issue #4875 · medic/cht-core · GitHub

2 Likes

Writing up the response made me think that we should be more explicit than our current documentation [link1, link2] is about the inputs section as something important for forms used by the Core Framework.

Aside from updating documentation, perhaps medic-conf should verify for a decently formed inputs section in all forms, and post a warning otherwise.

1 Like

Do you think it would be reasonable to have the source changed to task-group (or something like that) if the report was submitted from the Household Tasks screen?

I think we would be creating a little bit of inconsistency.
Right now, there are three ways for a user to get to open a task:

  1. directly from the tasks tab
  2. link from the task list from the contact page
  3. link from household task popup

If the way the user got to a specific task is significant enough to replace the “source”, then we should probably have a second source for the link from contact page as well.

I actually thought that the source would have been set to contact if the user tapped on the Task from the Contacts tab. Based on your list and specification of “directly from” vs. “link from”, now I understand that even if the user tapped on the Task from the Contacts tab and completed the from, the report source would actually be task instead of contact. Is my understanding correct?

If so, it makes sense why you’d suggest a second source for the link from Contact page.

The reason I’m interested in all of this is that I want to know where users are completing Tasks from

  • directly from the Tasks page
  • accessing from the Contact page
  • are they completing any tasks from the household tasks page (haven’t found this in telemetry yet)

I don’t think it’s possible to know any of this today, but setting the source would actually make it really easy.

I believe that when completing a task, no matter where from where the user navigated to the task, the source will always be task, I think source: 'contact' is when a report is submitted directly from the contacts page.

1 Like