medic / cht-core

The CHT Core Framework makes it faster to build responsive, offline-first digital health apps that equip health workers to provide better care in their communities. It is a central resource of the Community Health Toolkit.
https://communityhealthtoolkit.org
GNU Affero General Public License v3.0
441 stars 212 forks source link

Tasks disappearing after adding contactLabel #7677

Open magp18 opened 2 years ago

magp18 commented 2 years ago

Describe the bug Adding a contactLabel to a task, either a string or a function, will correctly display the contactLabel under the tasks tab BUT the tasks will disappear from the patient profile. This is solved by removing the contactLabel, and then the tasks will appear again.

To Reproduce Steps to reproduce the behavior:

  1. Open tasks.js
  2. Add contactLabel to one of the tasks, can be a random string
  3. Upload the new configuration to the server
  4. Perform a form that should trigger the task
  5. Go to the patient the form was performed on and where the task should be
  6. The task does not show

Expected behavior The task after performing the form on a patient, should show on the patient, that the task should be performed.

Logs Console doesn't show anything.

Screenshots Image20220714094813

Environment

garethbowen commented 2 years ago

Similar: #6274

garethbowen commented 2 years ago

Ok, I've tracked down why this is happening. The cht-conf task-emitter outputs the contactLabel as the contact. When the rules engine in cht-core builds the couchdb doc it sets the owner to the contact._id, which because contact is a string is undefined. Finally the tasks_by_contact view then indexes the task as _unassigned which means it shows up under the Tasks tab but not when a specific contact is defined.

I think the fix is to change the task-emitter to emit both the contact and the contactLabel. I think the contactLabel should only be used in the UX, and not in the task logic.

@dianabarsan What do you think?

dianabarsan commented 2 years ago

I think the contactLabel should only be used in the UX, and not in the task logic.

This makes a lot of sense to me, at first read I would never expect an "anythingLABEL" to take part in business logic, but I'm not 100% familiar with the decision process when building the task emitter.

I think the fix is to change the task-emitter to emit both the contact and the contactLabel

I agree.

elvisdorkenoo commented 1 year ago

A PR is created in cht-conf addressing this issue. As the fix would be to update the cht-conf task-emitter to emit the contact object including the contactLabel as well.

elvisdorkenoo commented 1 year ago

After discussion we'll hold off a bit, until we know what would be the best improvement.

For more context : Looking at the original issue that added this code: https://github.com/medic/cht-conf/issues/205

This is the description:

For Muso’s mRDT supervisor workflows, we need to generate tasks for supervisors which are based on the content of reports owned by patients.

And futher down there's a comment from Kenn:

I think things are working as expected (when we set a custom contactLabel, it doesn’t appear in any of the contact pages)

So this behavior of the task with contactLabel not appearing on contact pages is expected ; Also we should change the label for this issue: https://github.com/medic/cht-core/issues/7677 to improvement.

Because it’s not straight forward about why a “name” would change the task owner.