Patient Queue Management System Code
Patient Queue Management System Code
h>
#include <stdlib.h>
#include <stdbool.h>
#include <conio.h>
#include <Windows.h>
#include <math.h>
typedef struct {
char p_name[15];
char p_surname[15];
char p_snumber[10];
char p_need[40];
bool p_emergency;
} Patient;
struct Maillon_Fi {
Patient data;
Ptliste_Fi Suiv;
};
struct Filedattente_Fi {
Ptliste_Fi Tete, Queue;
};
void Enqueue_Fi(Pointer_Fi Fil, Patient data);
void add_Patient(Pointer_Fi Fil);
void Createqueue_Fi ( Pointer_Fi *Fil );
bool Empty_queue_Fi(Pointer_Fi Fil) ;
void display_fil(Pointer_Fi fil) ;
void generatePatients(Patient patients[], int numPatients) ;
Patient getPatientFromArray(Patient patients[], int index) ;
int comparePatients(Patient p1, Patient p2) ;
void simulatequeue() ;
void clearScreen() ;
void setColor(int color) ;
void displayMenu(int selectedOption) ;
int getMenuOption(int menuSize) ;
void redirect_to_specified_queue(Patient mypatient) ;
void setCursorPosition(int x, int y) ;
void printCenteredText(const char* text) ;
int generateNewPatients(double avgArrivalRate) ;
int generateExitPatients(double avgExitRate) ;
int generateRedirectedPatients(double redirectionProbability) ;
void Createqueue_Fi ( Pointer_Fi *Fil )
{
*Fil = (struct Filedattente_Fi *) malloc( sizeof( struct Filedattente_Fi)) ;
(*Fil)->Tete = NULL ;
(*Fil)->Queue = NULL ;
}
if (Empty_queue_Fi(adr)) {
printf("the queue is empty \n");
} else {
Ptliste_Fi current = adr->Tete;
current = current->Suiv;
i = i + 1;
}
}
}
// Generate patients
for (int i = 0; i < numPatients; i++) {
// Randomize social number
for (int j = 0; j < 9; j++) {
patients[i].p_snumber[j] = '0' + rand() % 10;
}
patients[i].p_snumber[9] = '\0';
// Copy the patient data from the array to the single variable
strcpy(singlePatient.p_name, patients[index].p_name);
strcpy(singlePatient.p_surname, patients[index].p_surname);
strcpy(singlePatient.p_snumber, patients[index].p_snumber);
singlePatient.p_emergency = patients[index].p_emergency;
strcpy(singlePatient.p_need, patients[index].p_need);
return singlePatient;
}
int comparePatients(Patient p1, Patient p2) {
// Compare each field of the patients
if (strcmp(p1.p_name, p2.p_name) != 0)
return 0; // Names are different
if (strcmp(p1.p_surname, p2.p_surname) != 0)
return 0; // Surnames are different
if (strcmp(p1.p_snumber, p2.p_snumber) != 0)
return 0; // Social numbers are different
if (strcmp(p1.p_need, p2.p_need) != 0)
return 0; // Needs are different
if (p1.p_emergency != p2.p_emergency)
return 0; // Emergency status is different
// If all fields are equal, return 1 (true)
return 1;
}
// Function to generate the number of new patients based on average arrival rate
int generateNewPatients(double avgArrivalRate) {
// Use Poisson distribution for arrivals
int newPatients = 0;
double p = 1.0;
double L = exp(-avgArrivalRate);
while (p > L) {
p *= (double)rand() / RAND_MAX;
newPatients++;
}
return newPatients - 1; // Subtract 1 because the loop exits after generating
one extra patient
}
// Function to generate the number of exit patients based on average exit rate
int generateExitPatients(double avgExitRate) {
// Use Poisson distribution for exits
int exitPatients = 0;
double p = 1.0;
double L = exp(-avgExitRate);
while (p > L) {
p *= (double)rand() / RAND_MAX;
exitPatients++;
}
return exitPatients - 1; // Subtract 1 because the loop exits after generating
one extra patient
}
while ( loop==true ){
clearScreen();
int a = 1;
int ptKey;
logo32();
do {
coord.X = (screenWidth - 20) / 2; // Center X position for main menu text
coord.Y = startY; // Increment Y position for main menu texte
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
if(a==1){setColor(FOREGROUND_BLUE | BACKGROUND_BLUE | BACKGROUND_GREEN |
BACKGROUND_RED);} // Blue background
printf(" %s1- set the simulation settings \n", a == 1 ? ">" : " ");
setColor(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); // Reset
color
coord.X = (screenWidth - 20) / 2; // Center X position for main menu text
coord.Y = startY + 1; // Increment Y position for main menu texte
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
if(a==2){setColor(FOREGROUND_BLUE | BACKGROUND_BLUE | BACKGROUND_GREEN |
BACKGROUND_RED);}
printf(" %s2- Continue Simulation \n", a == 2 ? ">" : " ");
setColor(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); // Reset
color
coord.X = (screenWidth - 20) / 2; // Center X position for main menu text
coord.Y = startY + 2 ; // Increment Y position for main menu texte
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
if(a==3){setColor(FOREGROUND_BLUE | BACKGROUND_BLUE | BACKGROUND_GREEN |
BACKGROUND_RED);}
printf(" %s3- Display\n", a == 3 ? ">" : " ");
setColor(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); // Reset
color
coord.X = (screenWidth - 20) / 2; // Center X position for main menu text
coord.Y = startY + 3; // Increment Y position for main menu texte
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
if(a==4){setColor(FOREGROUND_BLUE | BACKGROUND_BLUE | BACKGROUND_GREEN |
BACKGROUND_RED);}
printf(" %s4- Add a new patient\n", a == 4 ? ">" : " ");
setColor(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); // Reset
color
coord.X = (screenWidth - 20) / 2; // Center X position for main menu text
coord.Y = startY + 4; // Increment Y position for main menu texte
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
if(a==5){setColor(FOREGROUND_BLUE | BACKGROUND_BLUE | BACKGROUND_GREEN |
BACKGROUND_RED);}
printf(" %s5- Quit\n", a == 5 ? ">" : " ");
setColor(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); // Reset
color
coord.X = (screenWidth - 20) / 2; // Center X position for main menu text
coord.Y = startY + 5; // Increment Y position for main menu texte
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
setColor(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); // Reset
color
ptKey = getMenuOption(5);
switch (ptKey) {
case -1: // Up arrow
if (a > 1)
a--;
break;
case 1: // Down arrow
if (a < 5)
a++;
break;
}
//clearScreen();
} while (ptKey != 0);
Patient removedPatient;
Patient savedPatient;
int numberOfNewPatients;
int numberOfExitPatients;
int numberofRedirectedPatient;
int x = 1;
int deptKey;
double avgArrivalRate = 2.0;
double avgExitRate = 0.5;
double redirectionProbability = 0.2;
int timeSkip = 5;
bool skip = false;
switch (a){
case 1 :
break;
case 4:
while(skip == false){
printf(" please enter the simulation time skip : ");
scanf("%d",&timeSkip);
if (timeSkip < 5){
printf("Please entre a time skip greater than 5 minutes.\
n");}
else{
skip = true;
}}
break;
case 5:
printf(" Thank you! \n");
break;
}
case 2 :
printf("timeSkip: %d\n", timeSkip);
timeSkip = timeSkip / 5;
printf("timeSkip after division: %d\n", timeSkip);
for(k=1;k<=timeSkip;++k){
numberOfNewPatients= generateNewPatients(avgArrivalRate);
generatePatients(patients, numberOfNewPatients);
strcpy(c, mainfil->Tete->data.p_need);
if (strcmp(c, "")==0){
removedPatient = dequeue(mainfil);
Enqueue_Fi(mainfil, removedPatient);
if (first1 == false){
Patient savedPatient;
savedPatient = removedPatient;
first1= true;
}else{
if (comparePatients(savedPatient, removedPatient) == 1){
printf("There will be no more Redirections.");
}
}
}
numberOfExitPatients= generateExitPatients(avgExitRate);
for (i=0;i<numberOfExitPatients;i++){
removedPatient = dequeue(mainfil);
};
numberofRedirectedPatient=generateRedirectedPatients(redirectionProbability);
for (i=0;i<numberofRedirectedPatient;++i){
removedPatient = dequeue(mainfil);
redirect_to_specified_queue( removedPatient);
};
}
break;
case 3:
add_Patient(mainfil);
break;
case 5 :
loop = false;
break;
}
void clearScreen() {
system("cls"); // for Windows
}
printf("%s", selectedOption == i ? " > " : " "); // Display '>' for
selected option
if (selectedOption == i) {
setColor(FOREGROUND_BLUE | BACKGROUND_BLUE | BACKGROUND_GREEN |
BACKGROUND_RED); // Blue background
printf("%d- ", i);
setColor(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); // Reset
color
} else {
printf(" ");
}
switch (i) {
case 1:
setColor(FOREGROUND_BLUE | BACKGROUND_BLUE | BACKGROUND_GREEN |
BACKGROUND_RED); // Blue background
printf(" Enter Patient Name\n");
setColor(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); //
Reset color
break;
case 2:
setColor(FOREGROUND_BLUE | BACKGROUND_BLUE | BACKGROUND_GREEN |
BACKGROUND_RED); // Blue background
printf(" Enter Patient Surname\n");
setColor(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); //
Reset color
break;
case 3:
setColor(FOREGROUND_BLUE | BACKGROUND_BLUE | BACKGROUND_GREEN |
BACKGROUND_RED); // Blue background
printf(" Enter Patient Social Number\n");
setColor(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); //
Reset color
break;
case 4:
setColor(FOREGROUND_BLUE | BACKGROUND_BLUE | BACKGROUND_GREEN |
BACKGROUND_RED); // Blue background
printf(" Enter Patient need (optional)\n");
setColor(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); //
Reset color
break;
case 5:
setColor(FOREGROUND_BLUE | BACKGROUND_BLUE | BACKGROUND_GREEN |
BACKGROUND_RED); // Blue background
printf(" Enter Patient Emergency Status (optional)\n");
setColor(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); //
Reset color
break;
case 6:
setColor(FOREGROUND_BLUE | BACKGROUND_BLUE | BACKGROUND_GREEN |
BACKGROUND_RED); // Blue background
printf(" Quit\n");
setColor(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); //
Reset color
break;
}
}
}
while (loop) {
displayMenu(selectedOption);
key = getMenuOption(6);
switch (key) {
case -1: // Up arrow
if (selectedOption > 1)
selectedOption--;
break;
case 1: // Down arrow
if (selectedOption < 6)
selectedOption++;
break;
case 0: // Enter key
switch (selectedOption) {
case 1:
clearScreen();
printf("Enter Patient Name: ");
scanf("%s", mypatient.p_name);
printf("Thank you!\n");
Sleep(1000);
NAME = true;
break;
case 2:
clearScreen();
printf("Enter Patient Surname: ");
scanf("%s", mypatient.p_surname);
printf("Thank you!\n");
Sleep(1000);
SNAME = true;
break;
case 3:
clearScreen();
printf("Enter Patient Social Number: ");
scanf("%s", mypatient.p_snumber);
printf("Thank you!\n");
Sleep(1000);
SNUMBER = true;
break;
case 4:
clearScreen();
printf("Choose the patient need:\n");
int x = 1;
int deptKey;
do {
printf(" %s1- Internal Medicine\n", x == 1 ? ">" : "
");
printf(" %s2- Pediatrics\n", x == 2 ? ">" : " ");
printf(" %s3- Obstetrics and Gynecology\n", x == 3 ?
">" : " ");
printf(" %s4- Orthopedics\n", x == 4 ? ">" : " ");
printf(" %s5- Dermatology\n", x == 5 ? ">" : " ");
printf(" %s6- Ophthalmology\n", x == 6 ? ">" : " ");
deptKey = getMenuOption(6);
switch (deptKey) {
case -1: // Up arrow
if (x > 1)
x--;
break;
case 1: // Down arrow
if (x < 6)
x++;
break;
}
clearScreen();
printf("Choose the department:\n");
} while (deptKey != 0);
switch (x) {
case 1:
strcpy(mypatient.p_need, "Internal Medicine");
break;
case 2:
strcpy(mypatient.p_need, "Pediatrics");
break;
case 3:
strcpy(mypatient.p_need, "Obstetrics and
Gynecology");
break;
case 4:
strcpy(mypatient.p_need, "Orthopedics");
break;
case 5:
strcpy(mypatient.p_need, "Dermatology");
break;
case 6:
strcpy(mypatient.p_need, "Ophthalmology");
break;
}
printf("Thank you!\n");
Sleep(1000);
PAT_NEED = true;
break;
case 5:
clearScreen();
printf("Choose emergency status :\n");
int y = 1;
int skey;
do {
printf(" %s1- Emergency\n", y == 1 ? ">" : " ");
printf(" %s2- Not an emergency\n", y == 2 ? ">" : "
");
skey = getMenuOption(2);
switch (skey) {
case -1: // Up arrow
if (y > 1)
y--;
break;
case 1: // Down arrow
if (y < 2)
y++;
break;
}
clearScreen();
printf("Choose emergency status :\n");
} while (skey != 0);
switch (y) {
case 1:
mypatient.p_emergency = true;
break;
case 2:
mypatient.p_emergency = false;
break;
}
printf("Thank you!\n");
Sleep(1000);
break;
case 6:
clearScreen();
printf("Exiting...\n");
Sleep(2000);
if (NAME && SNAME && SNUMBER) {
loop = false;
printf("Do you want to enter this patient to the main
queue or directly to the specified department?\n");
int d2 = 0;
int detKey;
do {
printf(" %s1- MAIN\n", d2 == 1 ? ">" : " ");
printf(" %s2- SPECIFIED based on their need\n",
d2 == 2 ? ">" : " ");
detKey = getMenuOption(2);
switch (detKey) {
case -1: // Up arrow
if (d2 > 1)
d2--;
break;
case 1: // Down arrow
if (d2 < 2)
d2++;
break;
}
clearScreen();
printf("Do you want to enter this patient to the
main queue or directly to the specified department?\n");
} while (detKey != 0);
if (d2 == 1) {
printf("LOADING.");
Sleep(1000);
printf(".");
Sleep(1000);
printf(".\n");
printf("The Patient has been added.\n");
Enqueue_Fi(&mainfil, mypatient);
} else {
if (PAT_NEED == true) {
printf("LOADING.");
Sleep(1000);
printf(".");
Sleep(1000);
printf(".\n");
printf("The Patient has been added.\n");
redirect_to_specified_queue(mypatient);
} else {
printf("please enter the patient need \n");
clearScreen();
printf("Choose the patient need:\n");
int z = 1;
int deKey;
do {
printf(" %s1- Internal Medicine\n", z ==
1 ? ">" : " ");
printf(" %s2- Pediatrics\n", z == 2 ? ">"
: " ");
printf(" %s3- Obstetrics and Gynecology\
n", z == 3 ? ">" : " ");
printf(" %s4- Orthopedics\n", z == 4 ?
">" : " ");
printf(" %s5- Dermatology\n", z == 5 ?
">" : " ");
printf(" %s6- Ophthalmology\n", z == 6 ?
">" : " ");
deKey = getMenuOption(6);
switch (deKey) {
case -1: // Up arrow
if (z > 1)
z--;
break;
case 1: // Down arrow
if (z < 6)
z++;
break;
}
clearScreen();
printf("Choose the patient need:\n");
} while (deKey != 0);
switch (z) {
case 1:
strcpy(mypatient.p_need, "Internal
Medicine");
break;
case 2:
strcpy(mypatient.p_need, "Pediatrics");
break;
case 3:
strcpy(mypatient.p_need, "Obstetrics
and Gynecology");
break;
case 4:
strcpy(mypatient.p_need,
"Orthopedics");
break;
case 5:
strcpy(mypatient.p_need,
"Dermatology");
break;
case 6:
strcpy(mypatient.p_need,
"Ophthalmology");
break;
}
redirect_to_specified_queue(mypatient);
printf("The Patient has been added.\n");
printf("Thank you!\n");
Sleep(1000);
PAT_NEED = true;
break;
}
}
} else {
printf("You didn't enter all the necessary information
for the patient.\n");
Sleep(2000);
}
break;
}
break;
case -3: // Escape key
loop = false;
break;
}
}
}
void logo2() {
}
void logo32(){
setColor(FOREGROUND_BLUE);
printf(R"( __
/ |
__ __ __ ______ $$ | _______ ______ _____ ____ ______
/ | / | / | / \ $$ | / | / \ / \/ \ / \
$$ | $$ | $$ |/$$$$$$ |$$ |/$$$$$$$/ /$$$$$$ |$$$$$$ $$$$ |/$$$$$$ |
$$ | $$ | $$ |$$ $$ |$$ |$$ | $$ | $$ |$$ | $$ | $$ |$$ $$ |
$$ \_$$ \_$$ |$$$$$$$$/ $$ |$$ \_____ $$ \__$$ |$$ | $$ | $$ |$$$$$$$$/
$$ $$ $$/ $$ |$$ |$$ |$$ $$/ $$ | $$ | $$ |$$ |
$$$$$/$$$$/ $$$$$$$/ $$/ $$$$$$$/ $$$$$$/ $$/ $$/ $$/ $$$$$$$/
__
/ |
_$$ |_ ______ ______ __ __ ______
/ $$ | / \ / \ / | / | / \
$$$$$$/ /$$$$$$ | /$$$$$$ |$$ | $$ |/$$$$$$ |
$$ | __ $$ | $$ | $$ | $$ |$$ | $$ |$$ | $$/
$$ |/ |$$ \__$$ | $$ \__$$ |$$ \__$$ |$$ |
$$ $$/ $$ $$/ $$ $$/ $$ $$/ $$ |
$$$$/ $$$$$$/ $$$$$$/ $$$$$$/ $$/
__ __ __ __
/ | / |/ | / |
______ ______ $$ | __ __ _______ $$ |$$/ _______ $$/ _______
/ \ / \ $$ |/ | / | / |$$ |/ |/ \ / | / |
/$$$$$$ |/$$$$$$ |$$ |$$ | $$ |/$$$$$$$/ $$ |$$ |$$$$$$$ |$$ |/$$$$$$$/
$$ | $$ |$$ | $$ |$$ |$$ | $$ |$$ | $$ |$$ |$$ | $$ |$$ |$$ |
$$ |__$$ |$$ \__$$ |$$ |$$ \__$$ |$$ \_____ $$ |$$ |$$ | $$ |$$ |$$ \_____
$$ $$/ $$ $$/ $$ |$$ $$ |$$ |$$ |$$ |$$ | $$ |$$ |$$ |
$$$$$$$/ $$$$$$/ $$/ $$$$$$$ | $$$$$$$/ $$/ $$/ $$/ $$/ $$/ $$$$$$$/
$$ | / \__$$ |
$$ | $$ $$/
$$/ $$$$$$/ )""\
n");
}
void logo4(){
setColor(FOREGROUND_BLUE);
printf(R"(
__ __
/ | / |
__ __ __ ______ $$ | _______ ______ _____ ____ ______ _$$ |_
______ ______ __ __ ______
/ | / | / |/ \$$ |/ |/ \/ \/ \ / \ / $$ | /
\ / \/ | / |/ \
$$ | $$ | $$ /$$$$$$ $$ /$$$$$$$//$$$$$$ $$$$$$ $$$$ /$$$$$$ | $$$$$$/ /$
$$$$$ | /$$$$$$ $$ | $$ /$$$$$$ |
$$ | $$ | $$ $$ $$ $$ $$ | $$ | $$ $$ | $$ | $$ $$ $$ | $$ | __$$
| $$ | $$ | $$ $$ | $$ $$ | $$/
$$ \_$$ \_$$ $$$$$$$$/$$ $$ \_____$$ \__$$ $$ | $$ | $$ $$$$$$$$/ $$ |/ $$
\__$$ | $$ \__$$ $$ \__$$ $$ |
$$ $$ $$/$$ $$ $$ $$ $$/$$ | $$ | $$ $$ | $$ $$/$$
$$/ $$ $$/$$ $$/$$ |
$$$$$/$$$$/ $$$$$$$/$$/ $$$$$$$/ $$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$$$/ $
$$$$$/ $$$$$$/ $$$$$$/ $$/
__ __ __ __
/ | / / | / |
______ ______ $$ |__ __ _______$$ $$/ _______ $$/ _______
/ \ / \$$ / | / |/ $$ / / \/ |/ |
/$$$$$$ /$$$$$$ $$ $$ | $$ /$$$$$$$/$$ $$ $$$$$$$ $$ /$$$$$$$/
$$ | $$ $$ | $$ $$ $$ | $$ $$ | $$ $$ $$ | $$ $$ $$ |
$$ |__$$ $$ \__$$ $$ $$ \__$$ $$ \_____$$ $$ $$ | $$ $$ $$ \_____
$$ $$/$$ $$/$$ $$ $$ $$ $$ $$ $$ | $$ $$ $$ |
$$$$$$$/ $$$$$$/ $$/ $$$$$$$ |$$$$$$$/$$/$$/$$/ $$/$$/ $$$$$$$/
$$ | / \__$$ |
$$ | $$ $$/
$$/ $$$$$$/
)""\n");
int main() {
logo2();
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
/*CONSOLE_FONT_INFOEX cfi;
[Link] = sizeof(CONSOLE_FONT_INFOEX);
GetCurrentConsoleFontEx(hConsole, FALSE, &cfi);
[Link].X = 900;
[Link].Y = 25;
SetCurrentConsoleFontEx(hConsole, FALSE, &cfi);*/
// Create pointers to queue structures for each department and initialize them
Pointer_Fi p_mainfil = &mainfil ;
Pointer_Fi p_Internal_Medicine_fil = &Internal_Medicine_fil ;
Pointer_Fi p_Pediatrics_fil = &Pediatrics_fil ;
Pointer_Fi p_Obstetrics_and_Gynecology_fil = &Pediatrics_fil ;
Pointer_Fi p_Orthopedics_fil = &Orthopedics_fil ;
Pointer_Fi p_Dermatology_fil = &Dermatology_fil ;
Pointer_Fi p_Ophtalmology_fil = &Ophtalmology_fil ;
Createqueue_Fi(&p_mainfil);
Createqueue_Fi(&p_Internal_Medicine_fil);
Createqueue_Fi(&p_Pediatrics_fil);
Createqueue_Fi(&p_Obstetrics_and_Gynecology_fil);
Createqueue_Fi(&p_Orthopedics_fil);
Createqueue_Fi(&p_Dermatology_fil);
Createqueue_Fi(&p_Ophtalmology_fil);