cht-core icon indicating copy to clipboard operation
cht-core copied to clipboard

Tasks disappearing after adding contactLabel

Open magp18 opened this issue 2 years ago • 3 comments

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

  • Browser: Firefox
  • Client platform: Windows
  • App: webapp
  • Version: 3.15.0

magp18 avatar Jul 14 '22 07:07 magp18

Similar: #6274

garethbowen avatar Jul 14 '22 21:07 garethbowen

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?

garethbowen avatar Jul 14 '22 22:07 garethbowen

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.

dianabarsan avatar Jul 15 '22 06:07 dianabarsan

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 avatar Nov 28 '22 12:11 elvisdorkenoo

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.

elvisdorkenoo avatar Nov 29 '22 14:11 elvisdorkenoo