0% found this document useful (0 votes)
9 views20 pages

Patient Queue Management System Code

Uploaded by

samirdjili49
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views20 pages

Patient Queue Management System Code

Uploaded by

samirdjili49
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <stdio.

h>
#include <stdlib.h>
#include <stdbool.h>
#include <conio.h>
#include <Windows.h>
#include <math.h>

typedef struct Filedattente_Fi *Pointer_Fi;


typedef struct Maillon_Fi *Ptliste_Fi;
HANDLE hConsole;
bool emergencymode = false;

struct Filedattente_Fi mainfil;


struct Filedattente_Fi Internal_Medicine_fil;
struct Filedattente_Fi Pediatrics_fil;
struct Filedattente_Fi Obstetrics_and_Gynecology_fil;
struct Filedattente_Fi Orthopedics_fil;
struct Filedattente_Fi Dermatology_fil;
struct Filedattente_Fi Ophtalmology_fil;
bool PAT_NEED = false;

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 ;
}

bool Empty_queue_Fi(Pointer_Fi Fil) {


return Fil->Tete == NULL;
}
void Enqueue_Fi(Pointer_Fi Fil, Patient data) {
Ptliste_Fi Q;
Q = (struct Maillon_Fi *)malloc(sizeof(struct Maillon_Fi));
Q->data = data;
Q->Suiv = NULL;
if (!Empty_queue_Fi(Fil))
Fil->Queue->Suiv = Q;
else
Fil->Tete = Q;
Fil->Queue = Q;
}
Patient dequeue(Pointer_Fi Fil) {
Patient dequeuedPatient;
if (Empty_queue_Fi(Fil)) {
printf("Queue is empty. Cannot dequeue.\n");
// Returning a dummy patient to indicate failure
strcpy(dequeuedPatient.p_name, "");
return dequeuedPatient;
}
// Get data of the front node
dequeuedPatient = Fil->Tete->data;
// Move front pointer to the next node
Ptliste_Fi temp = Fil->Tete;
Fil->Tete = Fil->Tete->Suiv;
if (Fil->Tete == NULL) {
// If the queue becomes empty after dequeue
Fil->Queue = NULL; // Reset rear pointer
}
free(temp);
return dequeuedPatient;
}
void display_fil(Pointer_Fi fil) {
Pointer_Fi adr = fil;
int i = 1;

if (Empty_queue_Fi(adr)) {
printf("the queue is empty \n");
} else {
Ptliste_Fi current = adr->Tete;

while (current != NULL) {


printf("patient number %d \n", i);
printf("-----------------------------------------------------------\
n");
printf(" the patient name is %s \n", current->data.p_name);
printf(" the patient surname is %s \n", current->data.p_surname);
printf(" the patient social security number is %s \n", current-
>data.p_snumber);
printf(" the patient department is %s \n", current->data.p_need);
printf(" O\n");
printf(" /|\\\n");
printf(" / \\\n");

current = current->Suiv;
i = i + 1;
}
}
}

void generatePatients(Patient patients[], int numPatients) {


const char *departments[] = {"Internal Medicine", "Pediatrics", "Obstetrics and
Gynecology",
"Orthopedics", "Dermatology", "Ophthalmology",""};
const int numDepartments = sizeof(departments) / sizeof(departments[0]);
// Arabic surnames dataset transliterated into English
const char *arabicNames[] = {"Hachache", "Abdullah", "Alawi", "Bahri", "Daher",
"Mostafaoui", "Ghannam", "Khelifi",
"Ibrahim", "Hadan", "Khalil", "Mansour",
"Nasir", "Omar", "Taleb", "Ben Mouloud"};
// Arabic names dataset transliterated into English
const char *arabicSurnames[] = {"Mohammed", "Ali", "Ahmed", "Fatimah",
"Zainab", "Reem", "Sara", "Lina",
"Yousef", "Hassan", "Omar", "Nour", "Aisha",
"Mariam", "Faisal", "Mounir"};
const int numArabicNames = sizeof(arabicNames) / sizeof(arabicNames[0]);

const int numArabicSurnames = sizeof(arabicSurnames) /


sizeof(arabicSurnames[0]);

// 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';

patients[i].p_emergency = (rand() % 2 == 0); // Randomly assign emergency


status

// Randomly select name and surname for each patient


strcpy(patients[i].p_name, arabicNames[rand() % numArabicNames]);
strcpy(patients[i].p_surname, arabicSurnames[rand() % numArabicSurnames]);

// Randomly select department for each patient


int deptIndex = rand() % numDepartments;
strcpy(patients[i].p_need, departments[deptIndex]);
}
}

// Function to transfer a patient from an array to a single variable


Patient getPatientFromArray(Patient patients[], int index) {
Patient singlePatient;

// 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
}

// Function to generate the number of redirected patients based on redirection


probability
int generateRedirectedPatients(double redirectionProbability) {
// Use Bernoulli trial to determine redirection
int redirectedPatients = 0;
double randomValue = (double)rand() / RAND_MAX;
if (randomValue < redirectionProbability) {
redirectedPatients = 1;
}
return redirectedPatients;
}

void simulatequeue(Pointer_Fi mainfil,Pointer_Fi Internal_Medicine_fil,Pointer_Fi


Pediatrics_fil,Pointer_Fi Obstetrics_and_Gynecology_fil,Pointer_Fi Orthopedics_fil,
Pointer_Fi Dermatology_fil, Pointer_Fi Ophtalmology_fil){
Patient patients[30];
bool first1 = false;
bool loop= true;
char c[40];
int k;
Ptliste_Fi Q;
generatePatients(patients, 15);
int i ;
int ch;
// Get console window dimensions
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
int screenWidth = [Link] - [Link] + 1 - 10;
int screenHeight = [Link] - [Link] + 1 ;

// Calculate Y position for the first option


int startY = (screenHeight - 5) / 2;
COORD coord;
for (i=1 ;i<15;++i){
Enqueue_Fi(mainfil, patients[i]);
}

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 :

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);
printf("simulation parameters\n");
do {
coord.X = 10; // Center X position for main menu text
coord.Y = startY + 1; // Increment Y position for main menu texte
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
printf(" %s1- set the average arrival rate per minute (by default
its 2 persons per minute)\n", x == 1 ? ">" : " ");
printf(" %s2- set the average exit rate per minute (by
default its 1 person per minute)\n", x == 2 ? ">" : " ");
printf(" %s3- set the redirections per time skip (by
default its 25%)\n", x == 3 ? ">" : " ");
printf(" %s4- set simulation time skip (by default its
5 minutes)\n", x == 4 ? ">" : " ");
printf(" %s5- return to simulation menu\n", x == 5 ?
">" : " ");
deptKey = getMenuOption(5);
switch (deptKey) {
case -1: // Up arrow
if (x > 1)
x--;
break;
case 1: // Down arrow
if (x < 5)
x++;
break;
}
clearScreen();
coord.Y = startY ; // Increment Y position for main menu texte
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
printf(" simulation parameters\n");
} while (deptKey != 0);
switch (x) {
case 1:

printf(" please enter the average arrival rate per minute


: \n");
scanf("%lf",&avgArrivalRate);
break;
case 2:
printf(" please enter the average exit rate per
minute : \n");
scanf("%lf",&avgExitRate);
break;
case 3:
printf(" please enter the redirections per time skip : \
n");
scanf("%lf",&redirectionProbability);

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);

for (i=0 ;i<numberOfNewPatients;++i){


Enqueue_Fi(mainfil, patients[i]);
}

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:

printf("Choose the departement to display:");


printf("1- Internal Medicine\n");
printf("2- Pediatrics\n");
printf("3- Obstetrics and Gynecology\n");
printf("4- Orthopedics\n");
printf("5- Dermatology\n");
printf("6- Ophthalmology\n");
printf("7-Main\n");
scanf("%d",&a);
switch (a){
case 1:
display_fil(Internal_Medicine_fil);
getchar();
break;
case 2:
display_fil(Pediatrics_fil);
getchar();
break;
case 3:
display_fil(Obstetrics_and_Gynecology_fil);
getchar();
break;
case 4:
display_fil(Orthopedics_fil);
getchar();
break;
case 5:
display_fil(Dermatology_fil);
getchar();
break;
case 6:
display_fil(Ophtalmology_fil);
getchar();
break;
case 7:
display_fil(mainfil);
getchar();
break;
Sleep(10);
}
getchar();
break;
case 4 :

add_Patient(mainfil);

break;
case 5 :
loop = false;
break;
}

void clearScreen() {
system("cls"); // for Windows
}

void setColor(int color) {


SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
void displayMenu(int selectedOption) {
clearScreen();

// Get console window dimensions


CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
int screenWidth = [Link] - [Link] + 1 - 10;
int screenHeight = [Link] - [Link] + 1 ;

// Calculate Y position for the first option


int startY = (screenHeight - 5) / 2;
COORD coord;
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);
printf("Main Menu\n");

for (int i = 1; i <= 6; ++i) {

coord.X = (screenWidth - 20) / 2; // Center X position for each option


coord.Y = startY + i; // Increment Y position for each option
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

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;
}
}
}

int getMenuOption(int menuSize) {


int key = 0;
do {
key = getch();
} while (key != 224 && key != 13 && key != 27 && key != 0);

if (key == 224) { // Arrow key


key = getch();
switch (key) {
case 72: // Up arrow
return -1;
case 80: // Down arrow
return 1;
case 75: // Left arrow
return -2;
case 77: // Right arrow
return 2;
}
} else if (key == 13) { // Enter key
return 0;
} else if (key == 27) { // Escape key
return -3;
}
return 0;
}

void redirect_to_specified_queue(Patient mypatient) {


if (strcmp("Internal Medicine", mypatient.p_need) == 0) {
Enqueue_Fi(&Internal_Medicine_fil, mypatient);
} else if (strcmp("Pediatrics", mypatient.p_need) == 0) {
Enqueue_Fi(&Pediatrics_fil, mypatient);
} else if (strcmp("Obstetrics and Gynecology", mypatient.p_need) == 0) {
Enqueue_Fi(&Obstetrics_and_Gynecology_fil, mypatient);
} else if (strcmp("Orthopedics", mypatient.p_need) == 0) {
Enqueue_Fi(&Orthopedics_fil, mypatient);
} else if (strcmp("Dermatology", mypatient.p_need) == 0) {
Enqueue_Fi(&Dermatology_fil, mypatient);
} else if (strcmp("Ophthalmology", mypatient.p_need) == 0) {
Enqueue_Fi(&Ophtalmology_fil, mypatient);
}
}

void add_Patient(Pointer_Fi Fill) {


Patient mypatient;
bool NAME = false;
bool SNAME = false;
bool SNUMBER = false;
bool loop = true;
int selectedOption = 1;
int key;
mypatient.p_emergency = false ;
strcpy(mypatient.p_need, "");

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 setCursorPosition(int x, int y) {


COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(hConsole, coord);
}

void printCenteredText(const char* text) {


CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hConsole, &csbi);
int screenWidth = [Link].X;

// Calculate the position to center the text


int textLength = strlen(text);
int startPos = (screenWidth - textLength) / 2;

// Set the cursor position and print the text


setCursorPosition(startPos, [Link].Y);
printf("%s", text);
};

void logo2() {

printf(" .----------------. .----------------. .----------------. .----------------


. .----------------. .----------------. .----------------. "R"( .----------------.
.----------------. .----------------. .----------------. .----------------. )""\
n");
printf("| .--------------. | .--------------. | .--------------. | .--------------.
| .--------------. | .--------------. | .--------------. |"R"( | .--------------. |
.--------------. | | .--------------. | .--------------. | .--------------. |)""\
n");
printf("| | _____ _____ | | | _________ | | | _____ | | | ______ |
| | ____ | | | ____ ____ | | | _________ | |"R"( | | _________ | |
| ____ | | | | ____ | | | _____ _____ | | | _______ | |)""\
n");
printf("| ||_ _||_ _|| | | |_ ___ | | | | |_ _| | | | .' ___ | |
| | .' `. | | ||_ \\ / _|| | | |_ ___ | | |"R"( | | | _ _ | |
| | .' `. | | | | .' `. | | ||_ _||_ _|| | | |_ __ \ | |)""\
n");
printf("| | | | /\\ | | | | | | |_ \\_| | | | | | | | | / .' \\_|
| | | / .--. \\ | | | | \\/ | | | | | |_ \\_| | |"R"( | | |_/ | | \_|
| | | / .--. \ | | | | / .--. \ | | | | | | | | | | | |__) | |
|)""\n");
printf("| | | |/ \\| | | | | | _| _ | | | | | _ | | | | |
| | | | | | | | | | | |\\ /| | | | | | _| _ | |"R"( | | | |
| | | | | | | | | | | | | | | | | | | ' ' | | | | | __ / |
|)""\n");
printf("| | | /\\ | | | | _| |___/ | | | | _| |__/ | | | | \\ `.___.'\\
| | | \\ `--' / | | | _| |_\\/_| |_ | | | _| |___/ | | |"R"( | | _| |_
| | | \ `--' / | | | | \ `--' / | | | \ `--' / | | | _| | \ \_ |
|)""\n");
printf("| | |__/ \\__| | | | |_________| | | | |________| | | | `._____.'
| | | `.____.' | | ||_____||_____|| | | |_________| | |"R"( | | |_____| |
| | `.____.' | | | | `.____.' | | | `.__.' | | | |____| |___| | |)""\
n");
printf("| | | | | | | | | | | |
| | | | | | | | | |"R"( | | | |
| | | | | | | | | | | | |)""\
n");
printf("| '--------------' | '--------------' | '--------------' | '--------------'
| '--------------' | '--------------' | '--------------' |"R"( | '--------------' |
'--------------' | | '--------------' | '--------------' | '--------------' |)""\
n");
printf(" '----------------' '----------------' '----------------'
'----------------' '----------------' '----------------' '----------------'
"R"( '----------------' '----------------' '----------------' '----------------'
'----------------' )""\n"

" .----------------. .----------------. .----------------. .-----------


-----. .----------------. .----------------. .----------------. .--------------
---. .----------------. .----------------. \n"
" | .--------------. || .--------------. || .--------------.
|| .--------------. || .--------------. || .--------------. || .--------------.
|| .--------------. || .--------------. || .--------------. |\n"
" | | ______ | || | ____ | || | _____ | || |
____ ____ | || | ______ | || | _____ | || | _____ | || | ____
_____ | || | _____ | || | ______ | |\n"
" | | |_ __ \\ | || | .' `. | || | |_ _| | || | |
_ _||_ _| | || | .' ___ | | || | |_ _| | || | |_ _| | || ||
_ \\|_ _| | || | |_ _| | || | .' ___ | | |\n"
" | | | |__) | | || | / .--. \\ | || | | | | || |
\\ \\ / / | || | / .' \\_| | || | | | | || | | | | || | |
\\ | | | || | | | | || | / .' \\_| | |\n"
" | | | ___/ | || | | | | | | || | | | _ | || |
\\ \\/ / | || | | | | || | | | _ | || | | | | || | |
|\\ \\| | | || | | | | || | | | | |\n"
" | | _| |_ | || | \\ `--' / | || | _| |__/ | | || |
_| |_ | || | \\ `.___.'\\ | || | _| |__/ | | || | _| |_ | || | _| |
_\\ |_ | || | _| |_ | || | \\ `.___.'\\ | |\n"
" | | |_____| | || | `.____.' | || | |________| | || |
|______| | || | `._____.' | || | |________| | || | |_____| | || ||
_____|\____| | || | |_____| | || | `._____.' | |\n"
" | | | || | | || | | || |
| || | | || | | || | | || | |
|| | | || | | |\n"
" | '--------------' || '--------------' || '--------------' ||
'--------------' || '--------------' || '--------------' || '--------------' ||
'--------------' || '--------------' || '--------------' |\n"
" '----------------' '----------------' '----------------'
'----------------' '----------------' '----------------' '----------------'
'----------------' '----------------' '----------------' \n");

}
void logo32(){
setColor(FOREGROUND_BLUE);
printf(R"( __
/ |
__ __ __ ______ $$ | _______ ______ _____ ____ ______
/ | / | / | / \ $$ | / | / \ / \/ \ / \
$$ | $$ | $$ |/$$$$$$ |$$ |/$$$$$$$/ /$$$$$$ |$$$$$$ $$$$ |/$$$$$$ |
$$ | $$ | $$ |$$ $$ |$$ |$$ | $$ | $$ |$$ | $$ | $$ |$$ $$ |
$$ \_$$ \_$$ |$$$$$$$$/ $$ |$$ \_____ $$ \__$$ |$$ | $$ | $$ |$$$$$$$$/
$$ $$ $$/ $$ |$$ |$$ |$$ $$/ $$ | $$ | $$ |$$ |
$$$$$/$$$$/ $$$$$$$/ $$/ $$$$$$$/ $$$$$$/ $$/ $$/ $$/ $$$$$$$/

__
/ |
_$$ |_ ______ ______ __ __ ______
/ $$ | / \ / \ / | / | / \
$$$$$$/ /$$$$$$ | /$$$$$$ |$$ | $$ |/$$$$$$ |
$$ | __ $$ | $$ | $$ | $$ |$$ | $$ |$$ | $$/
$$ |/ |$$ \__$$ | $$ \__$$ |$$ \__$$ |$$ |
$$ $$/ $$ $$/ $$ $$/ $$ $$/ $$ |
$$$$/ $$$$$$/ $$$$$$/ $$$$$$/ $$/

__ __ __ __
/ | / |/ | / |
______ ______ $$ | __ __ _______ $$ |$$/ _______ $$/ _______
/ \ / \ $$ |/ | / | / |$$ |/ |/ \ / | / |
/$$$$$$ |/$$$$$$ |$$ |$$ | $$ |/$$$$$$$/ $$ |$$ |$$$$$$$ |$$ |/$$$$$$$/
$$ | $$ |$$ | $$ |$$ |$$ | $$ |$$ | $$ |$$ |$$ | $$ |$$ |$$ |
$$ |__$$ |$$ \__$$ |$$ |$$ \__$$ |$$ \_____ $$ |$$ |$$ | $$ |$$ |$$ \_____
$$ $$/ $$ $$/ $$ |$$ $$ |$$ |$$ |$$ |$$ | $$ |$$ |$$ |
$$$$$$$/ $$$$$$/ $$/ $$$$$$$ | $$$$$$$/ $$/ $$/ $$/ $$/ $$/ $$$$$$$/
$$ | / \__$$ |
$$ | $$ $$/
$$/ $$$$$$/ )""\
n");
}

void logo4(){
setColor(FOREGROUND_BLUE);
printf(R"(
__ __
/ | / |
__ __ __ ______ $$ | _______ ______ _____ ____ ______ _$$ |_
______ ______ __ __ ______
/ | / | / |/ \$$ |/ |/ \/ \/ \ / \ / $$ | /
\ / \/ | / |/ \
$$ | $$ | $$ /$$$$$$ $$ /$$$$$$$//$$$$$$ $$$$$$ $$$$ /$$$$$$ | $$$$$$/ /$
$$$$$ | /$$$$$$ $$ | $$ /$$$$$$ |
$$ | $$ | $$ $$ $$ $$ $$ | $$ | $$ $$ | $$ | $$ $$ $$ | $$ | __$$
| $$ | $$ | $$ $$ | $$ $$ | $$/
$$ \_$$ \_$$ $$$$$$$$/$$ $$ \_____$$ \__$$ $$ | $$ | $$ $$$$$$$$/ $$ |/ $$
\__$$ | $$ \__$$ $$ \__$$ $$ |
$$ $$ $$/$$ $$ $$ $$ $$/$$ | $$ | $$ $$ | $$ $$/$$
$$/ $$ $$/$$ $$/$$ |
$$$$$/$$$$/ $$$$$$$/$$/ $$$$$$$/ $$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$$$/ $
$$$$$/ $$$$$$/ $$$$$$/ $$/
__ __ __ __
/ | / / | / |
______ ______ $$ |__ __ _______$$ $$/ _______ $$/ _______
/ \ / \$$ / | / |/ $$ / / \/ |/ |
/$$$$$$ /$$$$$$ $$ $$ | $$ /$$$$$$$/$$ $$ $$$$$$$ $$ /$$$$$$$/
$$ | $$ $$ | $$ $$ $$ | $$ $$ | $$ $$ $$ | $$ $$ $$ |
$$ |__$$ $$ \__$$ $$ $$ \__$$ $$ \_____$$ $$ $$ | $$ $$ $$ \_____
$$ $$/$$ $$/$$ $$ $$ $$ $$ $$ $$ | $$ $$ $$ |
$$$$$$$/ $$$$$$/ $$/ $$$$$$$ |$$$$$$$/$$/$$/$$/ $$/$$/ $$$$$$$/
$$ | / \__$$ |
$$ | $$ $$/
$$/ $$$$$$/
)""\n");

/*void setConsoleFontSize(int size) {


CONSOLE_FONT_INFOEX font;
[Link] = sizeof(CONSOLE_FONT_INFOEX);
GetCurrentConsoleFontEx(hConsole, FALSE, &font);
[Link].X = size;
[Link].Y = size;
SetCurrentConsoleFontEx(hConsole, FALSE, &font);
}*/

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);

// Show console window


ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

// Call simulatequeue function to simulate patient queue management


simulatequeue(&mainfil, &Internal_Medicine_fil, &Pediatrics_fil,
&Obstetrics_and_Gynecology_fil, &Orthopedics_fil,
&Dermatology_fil, &Ophtalmology_fil);

// Free allocated memory for queue structures


//free(&p_mainfil);
//free(&p_Internal_Medicine_fil);
}

You might also like