cht-core
cht-core copied to clipboard
Tasks disappearing after adding contactLabel
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:
- Open tasks.js
- Add contactLabel to one of the tasks, can be a random string
- Upload the new configuration to the server
- Perform a form that should trigger the task
- Go to the patient the form was performed on and where the task should be
- 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
Environment
- Browser: Firefox
- Client platform: Windows
- App: webapp
- Version: 3.15.0
Similar: #6274
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?
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.
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.
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.