Patient scheduler for doctors clinic (alternate)
The local medical clinic has decided to automate its scheduling services. You have been
assigned to design the initial version of the schedules. The basic functions that the clinic
has in mind are doctor check-in and check-out and patient check-in and check-out.
A doctor checks in by telling the scheduler his or her name, an examination room number,
and a medical specialty code. Each doctor has a favorite room. The scheduler checks to
see whether the room is free. If so, it assigns this doctor to the room; if not, it rejects the
request with a message, and the doctor can try again to check in. When a doctor checks
out, the examination room is freed.
A patient checking in gives a name, age, specialist code, and emergency indication. The
scheduler tries to match up the patient with a doctor according to a set of rules that are
described here. If there is a match, the patient is seen by the assigned doctor. If this
doctor is currently seeing a patient, the new patient is queued to see the doctor. If it is the
emergency case, the patient should be moved to the front of the waiting list.
The rules for assigning doctors to patients are as follows:
l. Any patient under age 16 is assigned to see a pediatrician.
2. Patients age 16 and older are assigned a doctor according to the specialty requested. If
there is no doctor in the clinic with the requested specialty, the patient is assigned to a
general practitioner (GP). If there is no GP, the patient can be assigned to any doctor.
3. If there is more than one doctor of the requested specialty, the patient is assigned to the
doctor with the shortest waiting list.
When a patient checks out, the doctor he or she was assigned to is available to see the
next patient if there is anyone in the waiting list.
Input
Because this is an interactive system, your program should prompt the users to input the
correct information. The initial prompt is
Type D for Doctor or P for Patient:
The next prompt is
Type I for check-in or O for checkout:
According to the request, your program should prompt the user for any other needed
information, as indicated in the following table:
Action Additional Information
Doctor check-in
Doctor check-out
Patient check-in
Patient check-out
Doctor’s name
Room number
Specialty code
Doctor’s name
Patient’s name
Age
Specialty (code requested)
Patient’s name
Room number
You may define the format for the input processed by your program.
Output
The output for each request is in the form of messages to the user, according to the
request, as indicated in the following table.
Action Message
Doctor check-in
Doctor check-out
Patient check-in
Patient check-out
Confirmation that room is available or Error message if room is in use.
Good-bye message
Message telling patient which room to go to and which doctor has been assigned. If no
doctor is available, show apologetic message.
Good-bye message. At a later time we may add billing information at this point.
In addition to printing the messages on the screen, you should also write the requests and
messages to a transaction file (trans.out), to be turned in with your program listing.
Details and Assumptions
(1) There are l00 examination rooms at the clinic, each with a waiting room attached.
(2) Specialty codes are as follows:
Pediatrics PED
General practice GEN (or GP)
Internal medicine INT
Cardiology CAR
Surgeon SUR
Obstetrics OBS
Psychiatry PSY
Neurology NEU
Orthopedics ORT
Dermatology DET
Ophthalmology OPT
Ear, Nose, and Throat ENT
(3) You may assume that no patient leaves without checking out.
(4) No one leaves before he or she sees the assigned doctor. (That is, no one has to be
taken out of the waiting queue.) The clinic is open 24 hours a day, 7 days a week.
(5) If a doctor checks out while there is still a waiting list of patients assigned to him or
her, the patients must be reassigned to other doctors.
Data Structures
The basic data structure is a list of examination rooms with waiting lists attached to each.
Because the number of rooms is fixed, you may use an array of records to represent it. It
is the waiting list attached to each examination room that is of interest to us. We have
seen that patients are seen in the order in which they are added to the list (a simple queue).
Write a program to convert an infix expression to a postfix expression using a stack.
The algorithm for converting from infix to postfix notation is given as follows.
Algorithm:
initialize an operator stack, s
while not at the end of the infix expression do the following:
read the next symbol in case the symbol is
an operand : write the operand
‘(‘ : push ‘(‘ onto s
‘)’ : pop and write all operators until
encountering ‘(‘, then pop ‘(‘
‘*’or ‘/’ : pop and write all ‘*’ and ‘/’
operators from the top down to,
but not including, the top-most
‘(‘, ‘+’ or ‘-‘ or to the bottom
of the stack
push the new symbol, ‘*’ or ‘/’
‘+’or’-‘ : pop and write all operators from
the top down to, but not
including, the topmost ‘(‘ or to
the bottom of the stack
push the new symbol, ‘+’ or ‘-‘
end-of-expression: pop and write all operators
Show the testing of your program and your program should be well documented.
Solution
main.cpp
#include “Rooms.h”
int main(){
Rooms array[100];
for (int i = 0; i < 100; ++i)
{
array[i].doc = NULL;
array[i].number = i+1;
array[i].doc = NULL;
}
while(1){
char type;
cout<< “Type D for Doctor or P for Patient: “;
cin>> type;
if(type==’D’){
char check;
cout<< “Type I for check-in or O for checkout: “;
cin>> check;
if(check==’I’){ //doctor checking in
string name, code;
int room;
cout<< “Enter your name: “;
cin>> name;
cout<< “Enter your preferred room number: “;
cin>> room;
cout<< “Enter your speciality code: “;
cin>> code;
if(array[room-1].doc == NULL){ //assigning him to the prefered room
array[room-1].doc = new Doctor;
array[room-1].doc->name = name;
array[room-1].doc->specialitycode = code;
cout<< “Welcome Dr. ” << name <
}
else{
cout<< “Sorry the room is not available right now!!” <
}
}
else if(check==’O’){ //doctor checking out
string name;
cout<< “Enter your name: “;
cin>> name;
for (int i = 0; i < 100; ++i){
if(array[i].doc != NULL && array[i].doc->name == name){ //finding the doc’s room
if(array[i].q.empty()) array[i].doc = NULL; //doc’s queue is empty
else{ //not empty
for(int j=0;j<100;j++){
if(array[j].doc != NULL && i!=j){ //a doc is found and it is not same as
while(!array[i].q.empty()){ //copying the queue
Patient temp = array[i].q.front();
array[j].q.push(temp);
array[i].q.pop();
}
array[i].doc = NULL; //removing the doctor
break;
}
}
}
}
}
cout<< “Good bye Dr. ” << name << “!! Have a nice day.” <
}
}
else if(type==’P’){
char check;
cout<< “Type I for check-in or O for checkout: “;
cin>> check;
if(check==’I’){ //patient checking in
string name, code;
int age;
cout<< “Enter your name: “;
cin>> name;
cout<< “Enter your age: “;
cin>> age;
cout<< “Enter your requested speciality code: “;
cin>> code;
Patient p;
p.name = name;
p.age = age;
int min = -1;
if(age < 16){ //checking the age
for (int i = 0; i < 100; ++i){
if(array[i].doc != NULL && array[i].doc->specialitycode == “PED”){ //assigning to the pedtrician having minimum waiting list
if(min == -1) min = i; //assigning first peditrician
else{
if(array[min].q.size() > array[i].q.size()) min = i; //current is the minimum waiting list
}
}
}
if(min == -1) cout<< “Sorry no peditricians are available!!” <
else{
cout<< “Go to Room number ” << min+1 <
array[min].q.push(p); //assigned to the min peditrician
}
}
else{ //elder patient
for (int i = 0; i < 100; ++i){
if(array[i].doc != NULL && array[i].doc->specialitycode == code){ //assigning to desirable code
if(min == -1) min = i;
else{
if(array[min].q.size() > array[i].q.size()) min = i; //same as before
}
}
}
if(min != -1){
cout<< “Go to Room number ” << min+1 <
array[min].q.push(p); //assigned to the preferred code
}
else{ //preferred code is not available
for (int i = 0; i < 100; ++i){
if(array[i].doc != NULL && array[i].doc->specialitycode == “GEN”){ //searching for the general
if(min == -1) min = i;
else{
if(array[min].q.size() > array[i].q.size()) min = i; //same as before
}
}
}
if(min != -1){
cout<< “Go to Room number ” << min+1 <
array[min].q.push(p); //found min waiting list for gen
}
else{ //gen is not available
for (int i = 0; i < 100; ++i){
if(array[i].doc != NULL){ //searching for any other doc
if(min == -1) min = i;
else{
if(array[min].q.size() > array[i].q.size()) min = i; //same as before
}
}
}
if(min != -1){
cout<< “Go to Room number ” << min+1 <
array[min].q.push(p); //found any other doc with min waiting list
}
elsecout<< “Sorry no doctors are available!!” <
}
}
}
}
else if(check==’O’){ //patient checking out
string name;
int room;
cout<< “Enter your name: “;
cin>> name;
cout<< “Enter your room number: “;
cin>> room;
cout<< “Good bye, ” << name << “! Have a nice day.” <
array[room-1].q.pop(); //popping him from the queue
}
}
}
}
People.h
#include
#include
#include
#include
using namespace std;
class Doctor
{
public:
string name;
stringspecialitycode;
};
class Patient
{
public:
string name;
int age;
};
Rooms.h
#include “People.h”
class Rooms
{
public:
int number;
Doctor* doc;
queue q;
};