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
438 stars 209 forks source link

accept_case_reports transition broken - report not updated #9381

Open jkuester opened 3 weeks ago

jkuester commented 3 weeks ago

Describe the bug So, this is some ancient history (and I do not fully understand the workflow). But, I was trying to manually configure and test case_id functionality by using the accept_case_reports transition to set the place_uuid field on a report based on its case_id value.

Unfortunately, I could not get this to work. The transition code would get triggered as expected, but the onMatch function returns the result of silenceRegistrations. In order to trigger the updates to the doc to be written to the DB, the onMatch function should resolve a truthy value. However, the silenceRegistrations function does not seem to ever resolve something truthy.

To Reproduce

Once again, I am not super familiar with the "proper" case_id workflow, so maybe I am just doing something wrong here....

I started with a register_case app form that is associated with a contact when it gets saved. With this form, I enabled the registration transition and added the following app_settings config:

  "registrations": [{
    "form": "register_case",
    "events": [{
      "name": "on_create",
      "trigger": "add_case"
    }]
  }],

When I submitted a register_case form, the transition would automatically update the report with a generated case_id.

Then I created a case_event form that contained nothing but a field to set the case_id (no linkage to any kind of contact). I enabled the accept_case_reports transition with the following config:

  "accept_case_reports": [{
    "form": "case_event",
    "validations": {},
    "messages": []
  }],

When I submit a case_event report (with the case_id assigned to my previous register_case report), I can see the accept_case_reports transition is triggered. It finds the existing case registration and sets the expected place_uuid field onto the case_event doc. However, since the silenceRegistrations function resolves undefined, this doc update is not persisted to the DB.

Expected behavior I was expecting the case_event report to be assigned to the place associated with my register_case report.

Additional context

It seems like this workflow was broken in 3.9.0 :sweat: with these changes to the accept_patient_reports.silenceRegistrations logic. Previously that function resolved true when it successfully completed. Afterwards, it resolves undefined.

jkuester commented 3 weeks ago

Not sure if something that has been broken since 3.9 counts as a "regression"... :sweat_smile: