Open TuyizereBapt opened 2 years ago
I actually realized there can be race conditions for time slots if not careful. What happens if patients try book the same time slot at the same time? When at the time of selecting the time slot, it was free for both of them
Indeed. Can we account for these with atomic transactions?
We currently do this for payments where patients try to spend from the same account at the same time
Does atomic transactions achieve that? I think atomic transactions mean all operations are successful together or all fail together
That's correct. In django, don't they also lock the table for editing?
Whereas in order to prevent race conditions, you need locking like if a thread enters a method and code block, no other thread can execute that block of code until the other one releases the key
Yh. How do we achieve this in django?
This sounds like the way to go: https://hakibenita.com/how-to-manage-concurrency-in-django-models
Yh. How do we achieve this in django? Model.objects.select_for_update().get(...)
https://madil.in/avoid-race-conditions-in-django/ https://stackoverflow.com/questions/1030270/race-conditions-in-django https://docs.djangoproject.com/en/4.0/ref/models/querysets/#django.db.models.query.QuerySet.select_for_update
This sounds like the way to go: https://hakibenita.com/how-to-manage-concurrency-in-django-models
Yup. It's that select_for_update() that does it. It locks the table row for modifications
Can be tricky if you are going to select more rows
Got it. I guess we'd be fine for this use case since it's just one slot. But definitely helpful to know how to do this for multiple rows at the same time
Got it. I guess we'd be fine for this use case since it's just one slot. But definitely helpful to know how to do this for multiple rows at the same time
Yes. It's good to know the caveats just in case you need to use it for other use cases
Tell us about your request! Enable patients who made appointments to see doctors, change the time slot of their appointment to another available convenient time of their choice.
Which app does this concern? Provider portal
What will be benefit of this feature? Efficient use of doctor's time. It eliminates waste of time slots which would be unused because patients are not available and can't change but rather are prompted to make another separate appointment
Describe the solution you'd like Change a slot of an appointment to another specified free future slot. Set the previous slot's status to free. If the new slot is not free, the operation should fail
Describe alternatives you've considered N/A
Additional context N/A