Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h> //Standard Input Output Header
- #include <windows.h>
- #include <stdlib.h> //Standard Library Header
- #include <string.h> //String Header
- #include <conio.h>
- #include <ctype.h> //Include header to handle character for validation purpose
- #include <time.h> //Time header for server time option.
- /* ASCII Code Declaration */
- #define ENTER 13
- #define BKSP 8
- #define ESC 27
- /* System Function */
- void testing();
- void gotoxy(int x, int y);
- int escexit(char pkey);
- int goback_previousmenu(char pkey);
- void cls();
- void invalid_msg();
- void error_msg();
- /* Validation Function */
- int selection_limiter(int type, int upper_limit, int lower_limit);
- char *data_entry(int type, int size_limit);
- int alpha_str_validation(char input[]);
- int num_str_validation(char input[]);
- /* Login Function */
- void usertype_file_verification();
- void usertype_username_retrieval();
- void usertype_password_retrieval();
- int login_validation();
- /* Data Entry for Patient */
- int pat_numofline_get();
- int pat_id_get();
- void pat_firstname_get();
- void pat_lastname_get();
- void pat_name_merge();
- void pat_gender_get();
- void pat_age_get();
- void pat_ic_get();
- void pat_contact_get();
- int patient_add();
- /* Data Entry for Appointment */
- int app_numofline_get();
- int app_id_get();
- void app_type_get();
- void app_doctor_get();
- void app_time_get();
- void date_merger(int date[], int month[], int year[]);
- int appointment_add();
- /* Data Modification & Display for Patient */
- char *name_splitter(char input[]);
- void patient_info_retrieval(int type);
- void patient_info_print();
- int patient_view();
- int pat_line_locator(char input[]);
- int patient_modify();
- int patient_delete();
- /* Data Modification & Display for Appointment*/
- void appointment_info_retrieval(int type);
- void appointment_info_print();
- int appointment_view();
- /* Search Function */
- char *search_name();
- char *search_id();
- int patient_search();
- int appointment_search();
- int appointment_delete();
- /* Navigation Menu */
- void usertype_nav();
- int actiontype_nav();
- int pat_rec_action_nav();
- int app_rec_action_nav();
- int pat_doc_action_nav();
- int app_doc_action_nav();
- /* Selection Menu */
- void usertype_selection();
- void actiontype_selection();
- int pat_rec_action_selection();
- int app_rec_action_selection();
- int pat_doc_action_selection();
- int app_doc_action_selection();
- void pat_search_selection();
- /* Global Variable for Choice */
- char usertype, actiontype, action, search_choice;
- FILE *fp, *fp2;
- COORD coord={0,0};
- /* Structure for Login User */
- struct user{
- char username[30];
- char password[30];
- }user;
- /* Structure for Patient */
- struct patient{
- char id[10];
- char first_name[25];
- char last_name[25];
- char full_name[50];
- char gender;
- unsigned int age;
- char contact_no[11];
- char ic[12];
- }pat;
- /* Structure for Appointment */
- struct appointment{
- char pat_id[10];
- char app_id[10];
- char name[50];
- char gender;
- char type;
- char doctor[50];
- char time[8];
- char date[10];
- }app;
- /* ------------------------------------------System Function------------------------------------------ */
- void testing()
- {
- printf("lalalalala");
- }
- int escexit(char pkey)
- {
- char reconfirm='Y';
- if(pkey==ESC)
- {
- do{
- if(!(toupper(reconfirm)=='Y' || toupper(reconfirm)=='N'))
- invalid_msg();
- printf("\a\n\nAre you sure you want to exit the program? (Y/N)\nAny unsaved data will be lost\n");
- reconfirm = getch();
- }while(!(toupper(reconfirm)=='Y' || toupper(reconfirm)=='N'));
- if(toupper(reconfirm)=='Y')
- {
- cls();
- printf("Thanks for using.\a");
- exit(0);
- }
- else if(toupper(reconfirm)=='N')
- {
- cls();
- return 1;
- }
- }
- }
- int goback_previousmenu(char pkey)
- {
- int result;
- if(pkey==BKSP)
- result = 1;
- return result;
- }
- void cls()
- {
- system("cls");
- }
- void invalid_msg()
- {
- printf("\aInvalid Input\nPlease try again\n\n");
- }
- void error_msg()
- {
- cls();
- printf("\aError! Please contact Maximus Ooi!");
- exit(1);
- }
- /* ------------------------------------------Validation Function------------------------------------------ */
- int selection_limiter(int type, int upper_limit, int lower_limit) //Allow users to interact with the system by pressing respective key, BACKSPACE and ESC without carriage return.
- {
- int goback_check = 0;
- int exit_check = 0;
- char input = '1';
- do{
- input = getch();
- exit_check = escexit(input); //Check whether input key is ESC
- if(exit_check==1)
- return 0;
- goback_check = goback_previousmenu(input); //Check whether input is BACKSPACE
- if ((type==0 || type==3 || type==4) && goback_check==1) //Special outcome for BACKSPACE in type 0, 3, 4
- {
- printf("\a");
- break;
- }
- }while(!(input>=lower_limit && input<=upper_limit));
- if(type!=0) //Condition type, 0 for only BACKSPACE & ESC; 1 for user type; 2 for action type; 3 for action; 4 for search option
- {
- if(type==1)
- usertype = input;
- else if(type==2)
- actiontype = input;
- else if(type==3)
- action = input;
- else if(type==4)
- search_choice = input;
- else
- error_msg();
- }
- return goback_check;
- }
- char *data_entry(int type, int size_limit) //Limit user input with ASCII codes, type 1 for unmasked, type 2 for masked
- {
- char input[30], p=' ' ;
- int i=0;
- while(i<=size_limit)
- {
- input[i] = getch();
- p = input[i];
- if(i==size_limit)
- {
- if(p==ENTER)
- break;
- else if((p>=48 && p<=57)||(p>=65 && p<=90)||(p>=97 && p<=122))
- {
- i--;
- printf("\b \b");
- }
- }
- if(p!=13 && p!='\b' && !((p>=48 && p<=57)||(p>=65 && p<=90)||(p>=97 && p<=122)))
- {
- p='\0';
- }
- else if(p==ENTER)
- {
- p='\0';
- break;
- }
- else if(p==BKSP)
- {
- i--;
- if(i!=-1)
- {
- p='\0' ;
- printf("\b \b");
- }
- else
- {
- p='\0' ;
- i++;
- }
- }
- else
- {
- if(type==1)
- printf("%c", input[i]);
- else if(type==2)
- printf("*");
- else
- error_msg();
- i++ ;
- }
- }
- input[i] = '\0' ;
- return input;
- }
- int alpha_str_validation(char input[])
- {
- int validation, i;
- for(i=0;i<(strlen(input));i++)
- {
- if(isalpha(input[i])||(isspace(input[i])))
- validation=1;
- else
- {
- validation=0;
- break;
- }
- }
- return validation;
- }
- int num_str_validation(char input[])
- {
- int validation, i;
- for(i=0;i<(strlen(input));i++)
- {
- if(input[i]>=48 && input[i]<=57)
- validation=1;
- else
- {
- validation=0;
- break;
- }
- }
- return validation;
- }
- /* -----------------------------------------------Main---------------------------------------------------- */
- int main()
- {
- int contcheck;
- system("COLOR 0B");
- printf("Welcome to Maximus Hospital.\n");
- system("pause");
- do{
- usertype_selection();
- contcheck=login_validation();
- }while(contcheck==1);
- usertype_nav();
- }
- /* ------------------------------------------Login Function------------------------------------------ */
- void usertype_file_verification()
- {
- switch(usertype)
- {
- case '1':
- fp = fopen("r_password.txt", "r+");
- break;
- case '2':
- fp = fopen("d_password.txt", "r+");
- break;
- case '3':
- fp = fopen("a_password.txt", "r+");
- break;
- }
- }
- void usertype_username_retrieval()
- {
- if(fp!=NULL)
- {
- fscanf(fp, "%s %*s\n", user.username);
- }
- else
- error_msg();
- }
- void usertype_password_retrieval()
- {
- if(fp!=NULL)
- {
- fscanf(fp, "%*s %s\n", user.password);
- }
- }
- int login_validation()
- {
- char input_name[30], input_pass[30], action;
- int login, goback_check;
- do{
- usertype_file_verification();
- int checker=0;
- login =0;
- cls();
- printf("Username: ");
- fflush(stdin);
- strcpy(input_name, data_entry(1, sizeof(input_name)));
- printf("\nPassword: ");
- fflush(stdin);
- strcpy(input_pass, data_entry(2, sizeof(input_name)));
- while(!feof(fp))
- {
- usertype_username_retrieval();
- usertype_password_retrieval();
- if((strcmp(user.username, input_name)==0) && (strcmp(user.password, input_pass)==0))
- {
- checker=1;
- rewind(fp);
- break;
- }
- }
- if(checker==1)
- {
- fp2 = fopen("Login Log.txt", "a+");
- printf("\a\n\nLogin Successful!\n");
- time_t mytime;
- mytime = time(NULL);
- printf(ctime(&mytime));
- fprintf(fp2, "%s\t\t%s", user.username, ctime(&mytime));
- fclose(fp2);
- login=1;
- }
- else
- printf("\a\n\nLogin Failed");
- printf("\n\nPress any key to continue...\nPress BACKSPACE to go back to previous menu\nPress ESC to exit\n");
- goback_check = selection_limiter(0,127,0);
- if (goback_check==1)
- break;
- }while(login==0);
- fclose(fp);
- return goback_check;
- }
- /* ------------------------------------------Data Entry for Patient------------------------------------------ */
- int pat_numofline_get()
- {
- int i=1, checker=1;
- char ch;
- do{
- fp2=fopen("patients.txt", "r");
- if(fp2!=NULL)
- {
- while(!feof(fp2))
- {
- ch = fgetc(fp2);
- if (ch=='\n')
- i++;
- }
- checker = 1;
- }
- else
- {
- fp=fopen("patients.txt", "w");
- fclose(fp);
- checker==0;
- }
- fclose(fp2);
- }while(checker==0);
- return i;
- }
- int pat_id_get()
- {
- int i = pat_numofline_get();
- sprintf(pat.id, "PAT%04d", i);
- printf("Patient ID\t: %s", pat.id );
- return i;
- }
- void pat_firstname_get()
- {
- int validation=0;
- do{
- fflush(stdin);
- printf("\nFirst Name\t: ");
- scanf("%[^\n]s", pat.first_name);
- validation = alpha_str_validation(pat.first_name);
- }while(validation==0);
- }
- void pat_lastname_get()
- {
- int validation=0;
- do{
- fflush(stdin);
- printf("Last Name\t: ");
- scanf("%[^\n]s", pat.last_name);
- validation = alpha_str_validation(pat.last_name);
- }while(validation==0);
- }
- void pat_name_merge() //Merge last name and first name together with delimiters
- {
- int i;
- sprintf(pat.full_name, "%s$%s", pat.first_name, pat.last_name);
- for(i=0;i<strlen(pat.full_name);i++)
- {
- if (pat.full_name[i]==' ')
- pat.full_name[i]=95;
- }
- }
- void pat_gender_get()
- {
- do{
- fflush(stdin);
- printf("Gender(M/F/O)\t: ");
- scanf("%c", &pat.gender);
- }while(!(toupper(pat.gender)=='M' || toupper(pat.gender)=='F' || toupper(pat.gender)=='O'));
- }
- void pat_age_get()
- {
- int validation = 0;
- do{
- fflush(stdin);
- printf("Age\t\t: ");
- scanf("%d", &pat.age);
- }while(!(isdigit(pat.age)==0) || pat.age==0);
- }
- void pat_ic_get()
- {
- int validation = 0;
- do{
- fflush(stdin);
- printf("IC No.\t\t: ");
- scanf("%s", pat.ic);
- validation = num_str_validation(pat.ic);
- }while(validation==0 || (strlen(pat.ic)!=12));
- }
- void pat_contact_get()
- {
- int validation = 0;
- do{
- fflush(stdin);
- printf("Contact No.\t: ");
- scanf(" %s", pat.contact_no);
- validation = num_str_validation(pat.contact_no);
- }while(validation==0 || !(strlen(pat.contact_no)>=10 && strlen(pat.contact_no)<=11));
- }
- int patient_add()
- {
- int goback_check = 0, i;
- do{
- cls();
- printf("Add Patient\n\n");
- i=pat_id_get();
- pat_firstname_get();
- pat_lastname_get();
- pat_gender_get();
- pat_age_get();
- pat_ic_get();
- pat_contact_get();
- pat_name_merge();
- if(i==1)
- fp = fopen("patients.txt", "w");
- else
- fp = fopen("patients.txt", "a+");
- fprintf(fp, "%s\t\t%s\t\t%c\t\t%d\t\t%s\t\t%s\n", pat.id, pat.full_name, pat.gender, pat.age, pat.ic, pat.contact_no);
- fclose(fp);
- printf("\n\nPress BACKSPACE to select another action\nPress ESC to exit");
- goback_check=selection_limiter(0, 0, 0);
- }while(goback_check==0);
- return goback_check;
- }
- /* ------------------------------------------Data Entry for Appointment------------------------------------------ */
- int app_numofline_get()
- {
- int i=1, checker=1;
- char ch;
- do{
- fp2=fopen("appointments.txt", "r");
- if(fp2!=NULL)
- {
- while(!feof(fp2))
- {
- ch = fgetc(fp2);
- if (ch=='\n')
- i++;
- }
- checker = 1;
- }
- else
- {
- fp=fopen("appointments.txt", "w");
- fclose(fp);
- checker==0;
- }
- fclose(fp2);
- }while(checker==0);
- return i;
- }
- int app_id_get()
- {
- int i = app_numofline_get();
- sprintf(app.app_id, "APP%04d", i);
- printf("\nAppointment ID\t: %s", app.app_id );
- return i;
- }
- void app_type_get()
- {
- do{
- fflush(stdin);
- printf("\nType(N/S/H)\t: ");
- scanf("%c",&app.type);
- }while(!(toupper(app.type)=='N' || toupper(app.type)=='S' || toupper(app.type)=='H'));
- }
- void app_doctor_get()
- {
- int validation=0;
- do{
- fflush(stdin);
- printf("Doctor\t\t: ");
- scanf("%[^\n]s", app.doctor);
- validation = alpha_str_validation(app.doctor);
- }while(validation==0);
- }
- void app_time_get()
- {
- int validation = 0;
- do{
- fflush(stdin);
- printf("Time\t\t: ");
- scanf("%s", app.time);
- validation = num_str_validation(app.time);
- }while(validation==0 || (strlen(app.time)!=4));
- }
- void date_merger(int date, int month, int year)
- {
- sprintf(app.date, "%d-%d-%d", date, month, year);
- }
- void app_date_get()
- {
- int date, month, year;
- fflush(stdin);
- printf("Date\t\t: ");
- scanf("%d", &date);
- printf("Month\t\t: ");
- scanf("%d", &month);
- printf("Year\t\t: ");
- scanf("%d", &year);
- date_merger(date, month, year);
- }
- int appointment_add()
- {
- int goback_check = 0, i, validation=0, date, month, year;
- char input_id[10], buffer[50];
- do{
- cls();
- fp=fopen("patients.txt", "r");
- if(fp!=NULL)
- {
- do
- {
- printf("Add Appointment\n\n");
- printf("Patient ID\t: ");
- fflush(stdin);
- strcpy(input_id, data_entry(1, 10));
- rewind(fp);
- while(!(feof(fp)))
- {
- patient_info_retrieval(0);
- if(strcmp(pat.id,input_id)==0)
- {
- validation=1;
- break;
- }
- }
- }while(validation==0);
- }
- else
- error_msg();
- fclose(fp);
- strcpy(app.pat_id,pat.id);
- strcpy(app.name, pat.full_name);
- app.gender=toupper(pat.gender);
- strcpy(buffer, name_splitter(app.name));
- printf("\n\nPatient ID\t: %s\nPatient Name\t: %s\nGender\t\t: %c\n", app.pat_id, buffer, app.gender);
- printf("\nAppointment Detail");
- i=app_id_get();
- app_type_get();
- app_doctor_get();
- app_date_get();
- app_time_get();
- date_merger(date, month, year);
- if(i==0)
- fp = fopen("appointments.txt", "w");
- else
- fp = fopen("appointments.txt", "a+");
- fprintf(fp, "%s\t\t%s\t\t%s\t\t%c\t\t%c\t\t%s\t\t%s\t\t%s\n", app.app_id, app.pat_id, app.name, app.gender, app.type, app.doctor, app.time, app.date);
- fclose(fp);
- printf("\n\nPress BACKSPACE to select another action\nPress ESC to exit");
- goback_check=selection_limiter(0, 0, 0);
- }while(goback_check==0);
- return goback_check;
- }
- int appointment_search()
- {
- int goback_check;
- char keyword[10];
- cls();
- printf("Search Appointment\n\n");
- strcpy(keyword, search_id());
- fp=fopen("appointments.txt", "r");
- if(fp!=NULL)
- {
- while(!feof(fp))
- {
- appointment_info_retrieval(1);
- if(strcmp(app.app_id, keyword)==0)
- {
- appointment_info_print();
- break;
- }
- }
- fclose(fp);
- }
- else
- error_msg();
- do{
- printf("\nPress BACKSPACE to go to previous menu\nPress ESC to exit.");
- goback_check = selection_limiter(0, 0 , 0);
- }while(goback_check==0);
- return goback_check;
- }
- /* ------------------------------------------Data Modification & Display for Patient------------------------------------------ */
- char *name_splitter(char input[]) //Remove delimiters in name
- {
- int i;
- char buffer[50];
- strcpy(buffer,input);
- for(i=0;i<strlen(buffer);i++)
- {
- if(buffer[i]==95 || buffer[i]==36)
- buffer[i]=' ';
- }
- return buffer;
- }
- void patient_info_retrieval(int type) //type determine whether delimiters are added or not
- {
- char buffer[10];
- fscanf(fp, "%s %s %c %d %s %s\n", pat.id, pat.full_name, &pat.gender, &pat.age, pat.ic, pat.contact_no);
- if(type!=0)
- strcpy(pat.full_name, name_splitter(pat.full_name));
- }
- void patient_info_print()
- {
- printf("\n\nPatient ID\t: %s\nName\t\t: %s\nGender\t\t: %c\nAge\t\t: %d\nIC No.\t\t: %s\nContact No.\t: %s\n\n", pat.id, pat.full_name, toupper(pat.gender), pat.age, pat.ic, pat.contact_no);
- }
- int patient_view()
- {
- int goback_check;
- cls();
- printf("View Patients\n");
- fp=fopen("patients.txt", "r");
- if(fp!=NULL)
- {
- while(!feof(fp))
- {
- patient_info_retrieval(1);
- patient_info_print();
- }
- fclose(fp);
- do{
- printf("\nPress BACKSPACE to go to previous menu\nPress ESC to exit.");
- goback_check = selection_limiter(0, 0 , 0);
- }while(goback_check==0);
- }
- else
- error_msg();
- return goback_check;
- }
- int pat_line_locator(char input[])
- {
- int i, validation=0;
- rewind(fp);
- for(i=0;(!feof(fp));i++)
- {
- fscanf(fp, "%s %*s %*c %*d %*s %*s\n", pat.id);
- if(strcmp(pat.id, input)==0)
- {
- validation=1;
- break;
- }
- }
- if(validation==1)
- return i;
- else
- return -1;
- }
- int patient_modify()
- {
- char modify_target[10];
- int target_line, goback_check;
- FILE *fp;
- fp = fopen("patients.txt", "r");
- do
- {
- cls();
- printf("Modify Patient\n\n");
- fflush(stdin);
- strcpy(modify_target, search_id());
- target_line = pat_line_locator(modify_target);
- }while(target_line<0);
- if(fp!=NULL)
- {
- char confirm;
- rewind(fp);
- if(target_line!=-1)
- {
- printf("\nConfirm Edit? (Y/N)");
- confirm = getchar();
- if(toupper(confirm)=='Y')
- {
- char words[1024];
- char *buffer;
- char *ptr;
- int line_counter = 0;
- int checker = 0;
- buffer=(char *)malloc(1024%sizeof(char));
- memset(buffer,0, 1024*sizeof(char));
- ptr=buffer;
- while(fgets(words, 1024, fp) != NULL)
- {
- line_counter++;
- if(line_counter != target_line)
- {
- strcpy(ptr, words);
- ptr +=strlen(words);
- }
- else if(line_counter == target_line)
- {
- char new_line[1024], buffer2[20];
- cls();
- fflush(stdin);
- printf("Modify Patient\n");
- fscanf(fp, "%s" , pat.id);
- pat_firstname_get();
- pat_lastname_get();
- pat_gender_get();
- pat_age_get();
- pat_ic_get();
- pat_contact_get();
- pat_name_merge();
- sprintf(buffer2,"%c\t\t%d", pat.gender, pat.age);
- strcpy(new_line,pat.id);
- strcat(new_line,"\t\t");
- strcat(new_line,pat.full_name);
- strcat(new_line,"\t\t");
- strcat(new_line,buffer2);
- strcat(new_line,"\t\t");
- strcat(new_line,pat.ic);
- strcat(new_line,"\t\t");
- strcat(new_line,pat.contact_no);
- strcat(new_line,"\n");
- strcpy(ptr, new_line);
- ptr +=strlen(new_line);
- }
- }
- fclose(fp);
- fp=fopen("patients.txt","w");
- fprintf(fp, "%s", buffer);
- fclose(fp);
- printf("\n\n\aModify is completed.");
- }
- }
- }
- else
- error_msg();
- do{
- printf("\nPress BACKSPACE to go to previous menu\nPress ESC to exit.");
- goback_check = selection_limiter(0, 0 , 0);
- }while(goback_check==0);
- }
- int patient_delete()
- {
- char modify_target[10];
- int target_line, goback_check;
- FILE *fp;
- fp = fopen("patients.txt", "r");
- do
- {
- cls();
- printf("Delete Patient\n\n");
- fflush(stdin);
- strcpy(modify_target, search_id());
- target_line = pat_line_locator(modify_target);
- }while(target_line<0);
- if(fp!=NULL)
- {
- char confirm;
- rewind(fp);
- if(target_line!=-1)
- {
- printf("\nConfirm Delete? (Y/N)");
- confirm = getchar();
- if(toupper(confirm)=='Y')
- {
- char words[1024];
- char *buffer;
- char *ptr;
- int line_counter = 0;
- int checker = 0;
- buffer=(char *)malloc(1024%sizeof(char));
- memset(buffer,0, 1024*sizeof(char));
- ptr=buffer;
- while(fgets(words, 1024, fp) != NULL)
- {
- if(line_counter != (target_line))
- {
- strcpy(ptr, words);
- ptr +=strlen(words);
- }
- line_counter ++;
- }
- fclose(fp);
- fp=fopen("patients.txt","w");
- fprintf(fp, "%s", buffer);
- fclose(fp);
- printf("\n\nDelete completed!\a\n");
- }
- }
- }
- else
- error_msg();
- do{
- printf("\nPress BACKSPACE to go to previous menu\nPress ESC to exit.");
- goback_check = selection_limiter(0, 0 , 0);
- }while(goback_check==0);
- }
- /* ------------------------------------------------Data Modification & Display for Appointment---------------------------*/
- void appointment_info_retrieval(int type)
- {
- fscanf(fp, "%s %s %s %c %c %s %s %s\n", app.app_id, app.pat_id, app.name, &app.gender, &app.type, app.doctor, app.time, app.date);
- if(type!=0)
- strcpy(app.name, name_splitter(app.name));
- }
- void appointment_info_print()
- {
- printf("\n\nAppointment ID\t: %s\nPatient ID\t: %s\nName\t\t: %s\nGender\t\t: %c\nType\t\t: %c\nDoctor\t\t: %s\nDate\t\t: %s\nTime(24hrs)\t: %s\n", app.app_id, app.pat_id, app.name, toupper(app.gender), toupper(app.type), app.doctor, app.time, app.date);
- }
- int appointment_view()
- {
- int goback_check;
- cls();
- printf("View Appointments\n");
- fp=fopen("appointments.txt", "r");
- if(fp!=NULL)
- {
- while(!feof(fp))
- {
- fflush(stdin);
- appointment_info_retrieval(1);
- fflush(stdin);
- appointment_info_print();
- }
- fclose(fp);
- do{
- printf("\nPress BACKSPACE to go to previous menu\nPress ESC to exit.");
- goback_check = selection_limiter(0, 0 , 0);
- }while(goback_check==0);
- }
- else
- error_msg();
- return goback_check;
- }
- int app_line_locator(char input[])
- {
- int i, validation=0;
- rewind(fp);
- for(i=0;(!feof(fp));i++)
- {
- fscanf(fp, "%s %*s %*s %*c %*c %*s %*s %*s\n", app.app_id);
- if(strcmp(app.app_id, input)==0)
- {
- validation=1;
- break;
- }
- }
- if(validation==1)
- return i;
- else
- return -1;
- }
- int appointment_modify()
- {
- char modify_target[10];
- int target_line, goback_check;
- FILE *fp;
- fp = fopen("appointments.txt", "r");
- do
- {
- cls();
- printf("Modify Appointment\n\n");
- fflush(stdin);
- strcpy(modify_target, search_id());
- target_line = app_line_locator(modify_target);
- }while(target_line<0);
- if(fp!=NULL)
- {
- char confirm;
- rewind(fp);
- if(target_line!=-1)
- {
- printf("\nConfirm Edit? (Y/N)");
- confirm = getchar();
- if(toupper(confirm)=='Y')
- {
- char words[1024];
- char *buffer;
- char *ptr;
- int line_counter = 0;
- int checker = 0;
- buffer=(char *)malloc(1024%sizeof(char));
- memset(buffer,0, 1024*sizeof(char));
- ptr=buffer;
- while(fgets(words, 1024, fp) != NULL)
- {
- line_counter++;
- if(line_counter != target_line)
- {
- strcpy(ptr, words);
- ptr +=strlen(words);
- }
- else if(line_counter == target_line)
- {
- char new_line[1024], buffer2[20];
- cls();
- fflush(stdin);
- printf("Modify Appointment\n");
- fscanf(fp, "%s %s %s %c", app.app_id, app.pat_id, app.name, &app.gender);
- app_type_get();
- app_doctor_get();
- app_date_get();
- app_time_get();
- sprintf(buffer2,"%c\t\t%d", app.gender, app.type);
- strcpy(new_line,app.app_id);
- strcat(new_line,"\t\t");
- strcat(new_line,app.pat_id);
- strcat(new_line,"\t\t");
- strcat(new_line,buffer2);
- strcat(new_line,"\t\t");
- strcat(new_line,app.doctor);
- strcat(new_line,"\t\t");
- strcat(new_line,app.date);
- strcat(new_line,"\t\t");
- strcat(new_line,app.time);
- strcat(new_line,"\n");
- strcpy(ptr, new_line);
- ptr +=strlen(new_line);
- }
- }
- fclose(fp);
- fp=fopen("appointments.txt","w");
- fprintf(fp, "%s", buffer);
- fclose(fp);
- printf("\n\n\aModify is completed.");
- }
- }
- }
- else
- error_msg();
- do{
- printf("\nPress BACKSPACE to go to previous menu\nPress ESC to exit.");
- goback_check = selection_limiter(0, 0 , 0);
- }while(goback_check==0);
- }
- int appointment_delete()
- {
- char modify_target[10];
- int target_line, goback_check;
- FILE *fp;
- fp = fopen("appointments.txt", "r");
- do
- {
- cls();
- printf("Delete Patient\n\n");
- fflush(stdin);
- strcpy(modify_target, search_id());
- target_line = app_line_locator(modify_target);
- }while(target_line<0);
- if(fp!=NULL)
- {
- char confirm;
- rewind(fp);
- if(target_line!=-1)
- {
- printf("\nConfirm Delete? (Y/N)");
- confirm = getchar();
- if(toupper(confirm)=='Y')
- {
- char words[1024];
- char *buffer;
- char *ptr;
- int line_counter = 0;
- int checker = 0;
- buffer=(char *)malloc(1024%sizeof(char));
- memset(buffer,0, 1024*sizeof(char));
- ptr=buffer;
- while(fgets(words, 1024, fp) != NULL)
- {
- if(line_counter != (target_line))
- {
- strcpy(ptr, words);
- ptr +=strlen(words);
- }
- line_counter ++;
- }
- fclose(fp);
- fp=fopen("appointments.txt","w");
- fprintf(fp, "%s", buffer);
- fclose(fp);
- printf("\n\nDelete completed!\a\n");
- }
- }
- }
- else
- error_msg();
- do{
- printf("\nPress BACKSPACE to go to previous menu\nPress ESC to exit.");
- goback_check = selection_limiter(0, 0 , 0);
- }while(goback_check==0);
- }
- /* ------------------------------------------Search Function------------------------------------------------ */
- char *search_name()
- {
- int validation=0;
- char input[30];
- do{
- fflush(stdin);
- printf("Search Name\t: ");
- scanf("%[^\n]s", input);
- validation = alpha_str_validation(input);
- }while(validation==0);
- return input;
- }
- char *search_id()
- {
- char input[10];
- fflush(stdin);
- printf("Search ID\t: ");
- strcpy(input,data_entry(1,10));
- return input;
- }
- int patient_search()
- {
- int goback_check;
- char keyword[30];
- pat_search_selection();
- if(search_choice=='0')
- return 1;
- cls();
- printf("Search Patient\n\n");
- switch(search_choice)
- {
- case '1':
- strcpy(keyword, search_name());
- break;
- case '2':
- strcpy(keyword, search_id());
- break;
- default:
- error_msg();
- }
- fp=fopen("patients.txt", "r");
- if(fp!=NULL)
- {
- while(!feof(fp))
- {
- patient_info_retrieval(1);
- if(strstr(pat.full_name, keyword)!=NULL)
- patient_info_print();
- if(strcmp(pat.id, keyword)==0)
- {
- patient_info_print();
- break;
- }
- }
- fclose(fp);
- }
- else
- error_msg();
- do{
- printf("\nPress BACKSPACE to go to previous menu\nPress ESC to exit.");
- goback_check = selection_limiter(0, 0 , 0);
- }while(goback_check==0);
- return goback_check;
- }
- /* ------------------------------------------Navigation Menu------------------------------------------------ */
- void usertype_nav()
- {
- int contcheck=0;
- do
- {
- cls();
- switch(usertype)
- {
- case '1':
- actiontype_selection();
- contcheck = actiontype_nav(); //based on action type, call menu
- break;
- case '2':
- actiontype_selection();
- contcheck = actiontype_nav();
- break;
- case '3':
- testing();
- break;
- }
- }while(contcheck==1);
- }
- int actiontype_nav()
- {
- int contcheck = 0;
- do{
- cls();
- switch(actiontype)
- {
- case '1':
- if(usertype=='1')
- {
- contcheck = pat_rec_action_selection();
- if(contcheck==1)
- return contcheck;
- else
- {
- contcheck = pat_rec_action_nav();
- break;
- }
- }
- else if(usertype=='2')
- {
- contcheck = pat_doc_action_selection();
- if(contcheck==1)
- return contcheck;
- else
- contcheck = pat_doc_action_nav();
- break;
- }
- case '2':
- if(usertype=='1')
- {
- contcheck = app_rec_action_selection();
- if(contcheck==1)
- return contcheck;
- else
- {
- contcheck = app_rec_action_nav();
- break;
- }
- }
- else if(usertype=='2')
- {
- contcheck = app_doc_action_selection();
- if(contcheck==1)
- return contcheck;
- else
- {
- contcheck = app_doc_action_nav();
- break;
- }
- }
- }
- }while(contcheck==1);
- }
- int pat_rec_action_nav()
- {
- int contcheck = 0;
- cls();
- switch(action)
- {
- case '1':
- contcheck = patient_add();
- if(contcheck==1)
- return contcheck;
- case '2':
- contcheck = patient_view();
- if(contcheck==1)
- return contcheck;
- break;
- case '3':
- contcheck = patient_search();
- if(contcheck==1)
- return contcheck;
- break;
- case '4':
- contcheck = patient_modify();
- if(contcheck==1)
- return contcheck;
- break;
- case '5':
- contcheck = patient_delete();
- if(contcheck==1)
- return contcheck;
- break;
- default:
- error_msg();
- }
- }
- int app_rec_action_nav()
- {
- int contcheck = 0;
- cls();
- switch(action)
- {
- case '1':
- contcheck = appointment_add();
- if(contcheck==1)
- return contcheck;
- case '2':
- contcheck = appointment_view();
- if(contcheck==1)
- return contcheck;
- break;
- case '3':
- contcheck = appointment_search();
- if(contcheck==1)
- return contcheck;
- break;
- case '4':
- contcheck = appointment_modify();
- if(contcheck==1)
- return contcheck;
- break;
- case '5':
- contcheck = appointment_delete();
- if(contcheck==1)
- return contcheck;
- break;
- default:
- error_msg();
- }
- }
- int pat_doc_action_nav()
- {
- int contcheck = 0;
- cls();
- switch(action)
- {
- case '1':
- contcheck = patient_view();
- if(contcheck==1)
- return contcheck;
- case '2':
- contcheck = patient_search();
- if(contcheck==1)
- return contcheck;
- break;
- default:
- error_msg();
- }
- }
- int app_doc_action_nav()
- {
- int contcheck = 0;
- cls();
- switch(action)
- {
- case '1':
- contcheck = appointment_view();
- if(contcheck==1)
- return contcheck;
- case '2':
- contcheck = appointment_search();
- if(contcheck==1)
- return contcheck;
- break;
- default:
- error_msg();
- }
- }
- /* --------------------------------------------Selection Menu------------------------------------------------------ */
- void usertype_selection()
- {
- do
- {
- cls();
- printf("1. Receptionist\n2. Doctor\n\nPress respective key to select a type...\nPress ESC to exit\n");
- selection_limiter(1, 50, 49);
- }while(!(usertype>=49 && usertype<=50));
- }
- void actiontype_selection()
- {
- do
- {
- cls();
- printf("1. Patient Management\n2. Appointment Management\n\nPress respective key to select an option...\nPress ESC to logout\n");
- selection_limiter(2, 50, 49);
- }while(!(actiontype>=49 && actiontype<=50));
- }
- int pat_rec_action_selection()
- {
- int goback_check;
- do
- {
- cls();
- printf("1. Add Patient\n2. View Patient\n3. Search Patient\n4. Modify Patient\n5. Delete Patient\n\nPress respective key to select an action...\nPress BACKSPACE to go to previous menu\nPress ESC to exit\n");
- goback_check = selection_limiter(3, 53, 49);
- if(goback_check==1)
- break;
- }while(!(action>=49 && action<=53));
- return goback_check;
- }
- int app_rec_action_selection()
- {
- int goback_check;
- do
- {
- cls();
- printf("1. Add Appointment\n2. View Appointment\n3. Search Appointment\n4. Modify Appointment\n5. Delete Appointment\n\nPress respective key to select action...\nPress BACKSPACE to go to previous menu\nPress ESC to exit\n");
- goback_check = selection_limiter(3, 53, 49);
- if(goback_check==1)
- break;
- }while(!(action>=49 && action<=53));
- return goback_check;
- }
- int pat_doc_action_selection()
- {
- int goback_check;
- do
- {
- cls();
- printf("1. View Patient\n2. Search Patient\n\nPress respective key to select an action...\nPress BACKSPACE to go to previous menu\nPress ESC to exit\n");
- goback_check = selection_limiter(3, 53, 49);
- if(goback_check==1)
- break;
- }while(!(action>=49 && action<=50));
- return goback_check;
- }
- int app_doc_action_selection()
- {
- int goback_check;
- do
- {
- cls();
- printf("1. Add Appointment\n2. View Appointment\n3. Search Appointment\n4. Modify Appointment\n5. Delete Appointment\n\nPress respective key to select action...\nPress BACKSPACE to go to previous menu\nPress ESC to exit\n");
- goback_check = selection_limiter(3, 53, 49);
- if(goback_check==1)
- break;
- }while(!(action>=49 && action<=53));
- return goback_check;
- }
- void pat_search_selection()
- {
- int goback_check;
- do
- {
- cls();
- printf("Search Patient\n\n1. Search with name\n2. Search with patient ID\n\nPress respective key to select action\nPress BACKSPACE to go to previous menu\nPress ESC to exit\n");
- goback_check = selection_limiter(4, 50, 49);
- if(goback_check==1)
- {
- search_choice='0';
- return;
- }
- }while(!(search_choice>=49 && search_choice<=50));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement