2. (70) The local medical clinic has decided to automate its scheduling services
ID: 3802557 • Letter: 2
Question
2. (70) 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- 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. Ifso, 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 ofrules that are described here. If there is a match, the patient is seenby the assigned doctor. Ifthis doctor is currently seeing a patient, the new patient is queued to see the doctor. Ifit is the emergency case, the patient s 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 forcheckout: 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 nameExplanation / Answer
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#define PATIENTMAX 100
struct person
{
char FName[50];
char LName[50];
char ID[20];
};
class hospQueue
{
public:
hospQueue (void);
int LastAddPerson(person p);
int BegingAddPerson(person p);
person GetNxtPerson(void);
int RemvDeadPerson(person* p);
void OutPatientList (void);
char DeptName[50];
private:
int NumPatients;
person PatientList[PATIENTMAX];
};
hospQueue::hospQueue ()
{
NumPatients = 0;
}
int hospQueue::LastAddPerson(person p)
{
if (NumPatients >= PATIENTMAX)
{
return 0;
}
else
PatientList[NumPatients] = p; NumPatients++;
return 1;
}
int hospQueue::BegingAddPerson(person p)
{
int i;
if (NumPatients >= PATIENTMAX)
{
return 0;
}
for (i = NumPatients-1; i >= 0; i--)
{
PatientList[i+1] = PatientList[i];
}
PatientList[0] = p;
NumPatients++;
return 1;
}
person hospQueue::GetNxtPerson(void)
{
int i; person p;
if (NumPatients == 0) {
strcpy(p.ID,"");
return p;}
p = PatientList[0];
NumPatients--;
for (i=0; i<NumPatients; i++)
{
PatientList[i] = PatientList[i+1];
}
return p;
}
int hospQueue::RemvDeadPerson(person* p)
{
int i, j, found = 0;
for (i=0; i<NumPatients; i++)
{
if (stricmp(PatientList[i].ID, p->ID) == 0)
{
*p = PatientList[i]; found = 1;
NumPatients--;
for (j=i; j<NumPatients; j++)
{
PatientList[j] = PatientList[j+1];
}
}
}
return found;
}
void hospQueue::OutPatientList (void)
{
int i;
if (NumPatients == 0)
{
cout << "Queue is empty";
}
else
{
for (i=0; i<NumPatients; i++)
{
cout << "" << PatientList[i].FName;
cout << " " << PatientList[i].LName;
cout << " " << PatientList[i].ID;
}
}
}
person IpPerson(void)
{
person p;
cout << "Please enter data for new person First name: ";
cin.getline(p.FName, sizeof(p.FName));
cout << "Last name: ";
cin.getline(p.LName, sizeof(p.LName));
cout << "Social security number: ";
cin.getline(p.ID, sizeof(p.ID));
if (p.FName[0]==0 || p.LName[0]==0 || p.ID[0]==0)
{
strcpy(p.ID,"");
cout << "Error: Data not valid. Operation cancelled.";
getch();
}
return p;
}
void OpPerson(person* p)
{
if (p == NULL || p->ID[0]==0)
{
cout << "No patient";
return;
}
else
cout << "Persondata:";
cout << "First name: " << p->FName;
cout << "Last name: " << p->LName;
cout << "Social security number: " << p->ID;
}
int NumRead()
{
char buff[20];
cin.getline(buff, sizeof(buff));
return atoi(buff);
}
void DptMenu (hospQueue * q)
{
int choice = 0, succ;
person p;
while (choice != 6)
{
clrscr();
cout << "Welcome to department: " << q->DeptName;
cout << "Please enter your choice:";
cout << "1: Add normal patient ";
cout << "2: Add critically ill patient ";
cout << "3: Take out personfor operation ";
cout << "4: Remove dead personfrom hospQueue ";
cout << "5: PatientList hospQueue ";
cout << "6: Change department or exit ";
choice = NumRead();
switch (choice)
{
case 1:
p = IpPatient();
if (p.ID[0])
{
succ = q->LastAddPatient(p);
clrscr();
if (succ)
{
cout << "Patient added:";
}
else
{
cout << "Error: The hospQueue is full. Cannot add patient:";
}
OpPatient(&p);
cout << "Press any key";
getch();
}
break;
case 2:
p = IpPatient();
if (p.ID[0])
{
succ = q->BegingAddPatient(p);
clrscr();
if (succ)
{
cout << "Patient added:";
}
else
{
cout << "Error: The hospQueue is full. Cannot add patient:";
}
OpPatient(&p);
cout << "Press any key";
getch();
}
break;
case 3:
p = q->GetNxtPatient();
clrscr();
if (p.ID[0])
{
cout << "Patient to operate:";
OpPatient(&p);}
else
{
cout << "There is no patient to operate.";
}
cout << "Press any key";
getch();
break;
case 4:
p = IpPatient();
if (p.ID[0])
{
succ = q->RemvDeadPatient(&p);
clrscr();
if (succ)
{
cout << "Patient removed:";
}
else
{
cout << "Error: Cannot find patient:";
}
OpPatient(&p);
cout << "Press any key";
getch();
}
break;
case 5:
clrscr();
q->OutPatientList();
cout << "Press any key";
getch(); break;
}
}
}
void main ()
{
int i, ChoiceMenu = 0;
hospQueue depts[3];
strcpy (depts[0].DeptName, "Heart clinic");
strcpy (depts[1].DeptName, "Lung clinic");
strcpy (depts[2].DeptName, "Plastic surgery");
while (ChoiceMenu != 4)
{
clrscr();
cout << "Welcome to Software City Hospital";
cout << "Please enter your choice:";
for (i = 0; i < 3; i++)
{
cout << "" << (i+1) << ": " << depts[i].DeptName;
}
cout << "4: Exit";
ChoiceMenu = NumRead();
if (ChoiceMenu >= 1 && ChoiceMenu <= 3)
{
DptMenu (depts + (ChoiceMenu-1));
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.