Community Health Toolkit

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

3 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)
2 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: https://github.com/medic/cht-core/issues/4875

1 Like

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