Conditional muting without causing errors

@Femi and I are working on a project where we would like to be able to conditionally mute contacts when a certain form is submitted, but only when a particular value is given for a field on that form.

The muting.validations configuration seems to provide the functionality we need. However, in the false case where we do not want to mute the contact (and so the validation check fails), an error is generated (for the failed validation) and attached to the report. This causes the red error icon to show up on the report:

image

This does not really make sense in our use case since there was no error with the report. Everything functioned properly and the muting was not applied (which is what we wanted to happen).

So, my question is if there is a different way to conditionally mute contacts besides the muting.validations and/or if there is a way to fail the validation without getting an error? (I did not see any way to do this in the muting logic…)

Could you try to use extra docs functionality?
Change your submitted form to not trigger muting by default, and instead, conditionally, create an extra doc that is a muting form.

We already use this logic heavily across reference apps, for example, in the delivery form in default config, we conditionally create a death_report for the mother: cht-core/delivery.xml at master · medic/cht-core · GitHub

1 Like

Thanks @diana! That is a good idea!

For the record, I did confirm that this logic works as expected. In my test config, I set the muting.mute_forms in my app_settings.json to contain “mute_person”. Then I created a separate form (not mute_person) that just has a text field question. If the user enters “mute” into the text box, then a new mute_person report is created for the patient and the patient is muted as expected.

type name label::en appearance bind:jr:constraintMsg calculation instance::db-doc relevant
begin group inputs NO_LABEL field-list ./source = ‘user’
begin group contact Contact
db:person _id What is the patient’s name? db-object
hidden patient_id Patient ID
end group
end group
text text Text widget
begin_group mute_doc NO_LABEL true ${text} = mute
begin_group fields NO_LABEL
calculate patient_uuid NO_LABEL …/…/…/inputs/contact/_id
calculate patient_id NO_LABEL …/…/…/inputs/contact/patient_id
end_group
calculate form NO_LABEL mute_person
calculate type Type data_record
calculate content_type NO_LABEL xml
end_group