Hello,
I am working on building a patient/medical scheduling application.
In my app, patients are provided a schedule of re-occurring appointments for which I am using the calendar component. The re-occurring appointments have a start date, end date and day frequency (re-occur once/week – Monday for example).
Once the schedule with the re-occurring appointment is set, I need to create separate “scheduled” appointments records to track whether or not the patient showed up to each of those recurring appointments. The appointment records need to be generated for the schedule start date. A new record is then generated that increments to next week. This process happens until the end date is met.
So say I schedule a patient for Mondays for 5 weeks. I would expect 5 records to be generated with the date for the following 5 Mondays.
What I’ve tried so far:
- Form submits, start date, end date, and day of the week
- On submitting this record, I start a server action where I set a Server side variable to store the start date
- Connect to the DB
- Created a While loop whose condition is While the variable date <= the end date
- Inside the While loop, I insert a record whose date = variable date
- Step 2 inside the While loop, I increment the variable by 7
Then, I presume the while loop checks the condition again:
Is the variable date <= the end date? If yes, it stops.
If not, repeat.
This is what it looks like:
The problem I am running into is the dreaded While loop that never ends.
What am I missing here?
Last updated: