question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Updating patient causes duplicate due to document version conflict

See original GitHub issue

šŸ› Bug Report

When you update an existing document in PouchDB, you need to give the database the _rev of the document that’s currently in the database. If you supply an older _rev, it will cause a document update conflict. When we update a Patient, this creates a new _rev but we are not pulling that out of the database and updating our Redux state with it. The logic in saveOrUpdate currently falls back to a regular save when an error is thrown from db.put, so if you try to update a Patient twice it creates a duplicate document (the first update works).

To Reproduce

Create a Patient and add two Related Persons. The Patient will be duplicated.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
MatthewDornercommented, Feb 3, 2020

I’m not totally clear on the Redux stuff yet. Maybe try to find other codebases that use PouchDB and Redux and see how they do it?

There is also a concept of ā€œisDirtyā€ for telling when a data model has been modified but not been saved to database yet, that probably connects with this issue somehow.

0reactions
ocBrunocommented, Feb 4, 2020

saveOrUpdate does:

await this.db.put(entityToUpdate)
return this.find(entity.id)

and then updatePatientSuccess is supposed to set that Patient to state. So that all seems like it ought to work. I’d try debugging around those functions and see what the _rev of the patient being passed around it, to see where it’s breaking.

I was mistakened thinking that the related person didn’t have to be created before adding it, maybe we could redirect to create person if the related person doesn’t exist error appear.

I am going to work on a suggestion to abstract the patient and will be back to work on this issue after seeing how that resolves so we don’t need to do any refactoring afterwards!

https://github.com/HospitalRun/hospitalrun/issues/179

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prevalence and Sources of Duplicate Information in the ...
Of the text duplicated, 54.1% came from text written by the same author, whereas 45.9% was duplicated from a different author.
Read more >
2.3. Replication and conflict model - CouchDB Docs
This is because, when you PUT a new version of a document, you must give the _rev of the previous version. If that...
Read more >
Elastic Search Getting Version Conflict even while updating ...
This error means that the document has been updated by another process after your update by query call started running... You can choose...
Read more >
Integrity of the Healthcare Record: Best Practices for EHR ...
Documentation integrity is at risk when the wrong information is documented on the wrong patient health record. Errors in patient identification can affectĀ ......
Read more >
Duplicates, redundancies and inconsistencies in the primary ...
We demonstrate that duplicates not only introduce redundancy, but can lead to inconsistent results for certain tasks. Our findings lead to aĀ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found