serenity-health / roadmap

Public roadmap for development of Serenity's apps reported by our community of users
0 stars 1 forks source link

feature/appointment-reassignement #130

Open TuyizereBapt opened 2 years ago

TuyizereBapt commented 2 years ago

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

TuyizereBapt commented 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

chris-dare commented 2 years ago

Indeed. Can we account for these with atomic transactions?

chris-dare commented 2 years ago

We currently do this for payments where patients try to spend from the same account at the same time

TuyizereBapt commented 2 years ago

Does atomic transactions achieve that? I think atomic transactions mean all operations are successful together or all fail together

chris-dare commented 2 years ago

That's correct. In django, don't they also lock the table for editing?

TuyizereBapt commented 2 years ago

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

chris-dare commented 2 years ago

Yh. How do we achieve this in django?

chris-dare commented 2 years ago

This sounds like the way to go: https://hakibenita.com/how-to-manage-concurrency-in-django-models

TuyizereBapt commented 2 years ago

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

TuyizereBapt commented 2 years ago

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

TuyizereBapt commented 2 years ago

Can be tricky if you are going to select more rows

image

chris-dare commented 2 years ago

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

TuyizereBapt commented 2 years ago

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