msupply-foundation / mobile

Open source mobile app for medical inventory control
http://msupply.org.nz/mobile
Other
43 stars 27 forks source link

Kiribati Vax: When new vaccine event is created all other vaccine events of the Patient are updated, causing potential sync race conditions #4911

Closed sworup closed 2 years ago

sworup commented 2 years ago

Describe the bug

When new vaccine event is created all other vaccine events of the Patient are updated along with it causing sync issues.

To reproduce

Steps to reproduce the behaviour:

  1. Go to "Vaccinations"
  2. Search of a Patient with current store as home. One with previous vax events.
  3. Click on the Patient to create new Vaccine event.
  4. You may edit patient details but that is irrelevant.
  5. Complete the steps to create a vaccination event.
  6. Visually you may not see it, but all of the vaccination events of that Patient has been updated, probably with the same data. This creates update sync out records for these vax events (Name Notes).
  7. You may use the Realm explorer to see this happen. Before syncing, go to it and look for SyncOut object string. It will show pending sync out records, and there would be multiple NameNotes updates, there should only be 2 in case of Creating new vaccine event.

Expected behaviour

Proposed Solution

https://github.com/openmsupply/mobile/blob/80824641c7e16273c75d5750d70f2e13d5e02de9/src/database/utilities/createRecord.js#L337

Version and device info

Additional context

Add any other context about the problem here.

sworup commented 2 years ago

Resolved with #4912

nishaDangol-Sussol commented 2 years ago

Testing

Tested in latest apk

Tests

Create new Patient / Vaccination event from Vaccination route

Create Vaccination event for existing patient

@sworup The changes in Tablet2 is overridden. Also, the deleted vax events in Tablet2 ios still showing in the vaccination history when synced in the order explained above in the test case.

Edit Vaccination event for existing patient

nishaDangol-Sussol commented 2 years ago

Re-tested as part of #4920