slot booking problem - php

I am making a doctor appointment slot booking mechanism,where in doctor appointment slots will be divided into 30 mins slot each...i have achieved all the working code.. 1 problem i am facing is that..this booking is made at 2 places i.e 2 receptions..so when 1 selects a slot(radio button) not yet confirmed and saved in DB.other reception must not be able to select .how do i do it.any help on this...how do i go abt it.

This is a case of accessing "shared data". You'll need thread to make sure that only one thread has access to the data at a time to ensure it's integrity. The following might provide some ideas
http://www.alternateinterior.com/2007/05/communicating-with-threads-in-php.html

I would use some AJAX/AJAJ functions to periodically refresh data about free slots, or I would do that much more simple - when saving the appointment, just check it, if the slot will be taken, your app redirects user back to form to choose another slot.

In essence,
I will just ask for the slot timings upfront and the remaining details later.
In case the slot is available, it sends a request to the server to lock it, so that the other client cannot use it.
In case, it is not available, it will receive a small notification that this slot is unavailable, click to see available slots.
I would go with AJAX (if this is a web app). This is a distributed systems problem which resembles Blue Army - White Army problem.

Add a "Locked By" field to the table.
When booking a slot, do something like:
UPDATE tablename
SET LockedBy = userid, ...
WHERE LockedBy IS NULL
After the update, you can select to see if LockedBy is set to your userid.
If not, then someone else must have beaten you to the punch, and you need to tell the user to pick a different slot.

Related

How to handle same time request with Apache and MySQL [duplicate]

I am writing a hotel booking software using PHP and MySQL. I am pretty much done with it but I ran into a race condition problem. For example there is only one standard room left and when 2 guests both select it it shows available to both of them. I tried fixing it by checking the room again when the guest clicks confirm before payment but that still has issues. I also tried making the room status to pending when whoever clicks the confirm first but I can't figure out how to change it back to available if the guest decides not to pay or just closes the browser. I searched SO for answers but I didn't really find a definitive answer. Thanks in advance
One solution is to add two columns to a table in the database. One column is the session ID or user ID or whatever of the user that is being offered the room. The second column is a timestamp indicating when that offer will expire.
Then, in your app, only show rooms that have an expired timestamp in the hold column. (Set the initial timestamp to 0 so that it starts out expired.) When a room is selected, check the column again. If there's an unexpired timestamp there, the user gets a "sorry, you were too slow" message. Otherwise, put a timestamp there for 15 minutes into the future or whatever, and proceed.
You see this on travel sites and ticket-purchasing sites a lot where it says something like "We're holding these seats for you for another 14 minutes. Please complete the transaction by then or it will be released blah blah blah."
I would also go with the pending state. You could save the state together with the session id of this user and have a cronjob that deletes all pending states that have expired session ids associated to them.

Whats the best way to store booking information over multiple pages without DB in Laravel?

I'll try and cover most of the important details here...
I'm currently working on a booking system for a transport provider. I am using Laravel and originally started by having the Booking model attached to a User.
The client now however wants them to not have to login or register until the last step of the booking process. I have done carts etc in Session / Local Storage before but I thought before I start I would get some input from the friendly folks over at StackOverflow!
The most ideal way for me at this point would be to make the user_id on the Booking model nullable, but then when the visitor returns to the site how will I then know which booking is theirs?
I hope this makes sense & I hope someone out there has dealt with a similar problem to this one and can shed some light on the best strategy going forward!
I created something similar to what you say in a company that has been working for some time, I indicate how I proposed it, to see if it can help you achieve what you want to achieve in the most optimal way.
As you indicated, I created the reservations with the nullable user_id, as it usually happens in almost all reserve applications, they are not eternal, so I added a field (max_datetime) of maximum time that reservation would last and a field (token) with code only for the reservation, in addition to a field (ip) for the ip of the session. (In the application that I made, the reservation was maintained 12 hours maximum or until 11:59 pm on the same day, which may be less than 12 hours).
Then create a Task Scheduling for a custom Artisan Console. What it did was eliminate the reserves that fulfilled the condition to be eliminated.
When the reservation was completed it was associated with the user_id and the other fields with null (max_datetime, token, ip). Ah! Yes and a field (confirmed) to confirm with "true" that the reservation has been completed, by default to "false".
I used session to check the "ip" and the "token", and if not, I asked that if they had the token, to indicate it.
The system allowed you to obtain the "token" in case you did not want to continue at that moment, warning you of the time the reservation was kept.
I do not have access to the code since it was from a company and I only kept the idea. I hope it helps you. A cordial greeting.

How to solve this, 2 people working on same form

I've built a page with POST method form.
The form has a list of orders and tracking number for each order.
On this page two people are working at the same time, updating tracking numbers for order.
Example: when person 1 is updating the form with tracking number for order #126792 and click Submit, the database will be update tracking number for order #126792 and leave empty field for order #127299
At the same time person 2 is updating tracking number for order #127299, the database will update tracking number for order #127299 BUT insert empty tracking number for order #126792
You can see the form below in attached image, how can this situation be solved ?
Thank you.
Your question is too broad since it really depends on how your system and your users behave. Also, without you providing any code, I can't really answer with code.
However, I can provide a kind of decision alghorithm that might help you...
Questions:
Can the same record be updated by 2 different users at the same time?
No: Proceed to 2
Yes: Solution C, D or E
Can a user update 2 orders at the same time?
No: Solution A
Yes: Proceed to 3
Are empty values meaningful? (that is, can a user update/delete a record by submitting an empty "tracking code"?)
No: Solution B
Yes: Solution C, D or E
Solutions:
A. Change the frontend so that the user can only update 1 order BOX at a time
B. Ignore empty/false/null values in the backend.
C. Lock the records being edited:
User selects the records to update and informs the backend
The backend locks the records being updated until the user updates it or the "update time" expires
D. Use a version system: make each update a new version of the records and if a conflict arises, ask the last user that tried to update to resolve before committing the data.
E. Make the records "real time" (with short polling or long polling)
NOTE: Keep in mind that this assumes users are "smart", that is, they only behave in a predictable way (that you can specify without code) and they will oblige and won't try funny stuff.

Update information at specific timestamp

I'll try to explain my question the best way I can.
I'm not asking for codes, only for the best method of doing it.
I want to create a browser game and use time for upgrading stuff, building etc.
For example, to build 1 house will take 1 hour.
So I will began with saving the timestamp+(60*60) at the moment the user did his action.
My question is, how to update it the best way?
One way I thought of was to add function that check every page view of the user if it's done.
But then if he's not logged in the update wont happen.
Second way i thought about is for every page view of any user to check for every user registered. But it's not effective and there is a problem if no user is logged in.
Any suggestions?
I had my game doing it simply, without crons.
When a player wanted something that takes time, i just updated his database information with the appropriate time of ending that job (columns are just examples)
UPDATE player SET jobend = UNIX_TIMESTAMP() + (60*60*4) # ending in 4 hours
Then, every page that had an information about the remaining time, i just used something like this:
SELECT (jobend - UNIX_TIMESTAMP()) AS jobremaining FROM player
I formatted correctly the time using strftime and i displayed that to the user.
In the case the remaining time was negative, the job was done.
There was no-need for absolute counting since user was able to do something with the job when he was connected.
When the player just changed pages or doing something else i had a function where i just checked all timely events while the user was online (so to catch any negative timer), then presented with javascript any change (i posted javascript counters for every page)
Now, if you talk about updating in real-time, cron is the way but are you sure you're going to need it for a game? I asked that question myself too and the answer was not.
EDIT
If another player sees the buildings on schedule page (an hypothetical page) i am doing the same calculations; if a time just got negative for a specific player (regardless if another player see the page), i just reward him with the building (in database i make all the changes), even if he's offline. There's no harm in this, since he can't do anything anyway. The other players will just see he has a building. The key here is that i execute the required updating PHP code regardless of player's connection to the game; as long at least ONE player is logged-in i'm executing the progress function for everything.
This isn't so slow as it sounds (updating all players by using just a connected player that visits a specific page). You just have a table of 'jobs' and check timers against the current time. More like a single query of getting the negative ones.

where to keep temporary data?

I'm doing a system with Codeigniter , this is my first system with CI, and i'm also novice to PHP too.
I'm doing this for a hospital, in this i have the following problem
junior doctor first check the 1st visit patients and then if he can't handle them he refer them to the senior doctor
from registration room some patients are send to the eye checking room to check their eyes and then they go to the junior doctor
like wise i have temporary data to be kept on the system, references from one room to another and so on...
i need to get this details to the main GUI of the each person; for example in the Senior doctors UI there will be a tab named 1St time patients, in that the patients that was referred by the junior doctor will be shown to him! so i need to refer to the patients that was sent to senior doctor from the junior doctor and show them in the senior doctor's UI.
so my problem is how can i keep this temporary data to be referenced by the system? keeping them in the tables is not appropriate as i think because at the end of the day these data is not stored any where, only the patient table and few other tables will be keeping the data.
guys how can i achieve this kind of thing? any method of achieving this? technology that is easier to master that will allow me to keep temporary data?please give me some references or help by code to over come this problem.
regards,
Rangana
If the data is truly temporary, and has to be used by only one user at a time you need to stick it in session.
An entry level tuorial is here:
http://www.w3schools.com/PHP/php_sessions.asp
However if data is accessed by different users, but is simply not needed on following days, or you are storing a significant amount of data, you should probably keep it in the DB.
The DB should be able to store lots of data, so on a smallish app there is not much reason to keep clearing it out, but you could also include a housekeeping function that clears data that is old or irrelevant.
However when working with medical data, it may be a good idea to hang on to everything.
everything will do with ajax (or something that always refresh the browser for number of time like meta refresh tag) that will notify senior / junior doctor if any patient referred to them.
you need to add a flag at database if the doctor already retrieve the notification so it will not notify the doctor twice.
for example your database table :
Name of patient | referral | referrer | flag_retrieved
you need to specify referral doctor at the session so it can retrieve the correct record and then notify the doctor
then your system should :
request to database if any doctor to
refer patient to them over time (you can use ajax or meta tag)
database will check if any record match and not yet retrieved
send request to browser, than notify the doctor if any referred patient.
if you need to clean up the database, you can use cron every end of day for deleting any record at the table.

Categories