Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*The program below demonstrate a simple hospital management system that
- allows user,doctor and admin to monitor it and perform features such
- as adding,editing and editing patient's details*/
- // Project Title: HOSPITAL MANAGEMENT SYSTEM
- // Module Code: AAPP005-4-2-PSPD
- // Module Title: Problem Solving & Program Designing using C
- //
- // Name: KHO ZHI YUEN
- // TP Number: TP038123
- // Intake Code: UCDF1505ICT(SE)
- /* ------------------------ Include Headers ------------------------*/
- #include <stdio.h> // Include the Standard Input/Output Header
- #include <stdlib.h> // Include the Standard Library Header
- #include <unistd.h> // Include the POSIX Standard Header
- #include <string.h> // Include the Strings Header
- #include <ctype.h> // Include the Header to Handle Characters
- #include <time.h> // Include the Header to Manipulate Date and Time
- #include <stdbool.h> // Include the Header for Boolean
- #include <windows.h> // Include the Header for graphics
- #define _CRT_SECURE_NO_WARNINGS
- //ASCII CODE
- #define ENTER 13
- #define BKSP 8
- #define ESC 27
- // ------------------------ Structures ------------------------//
- struct patient{
- char pid[20];
- char fname[50];
- char lname[50];
- char fullname[100];
- char gender[10];
- char age[3];
- char address[30];
- char contact[20];
- }patientdets,patienttemp; //patientdets hold patient data, patienttemp to hold temp data during transfer
- struct app{
- char pid[20];
- char date[25];
- char time[15];
- char location[40];
- char doctor[30];
- char apptype[40];
- }appdets; //appdets hold main appointment data
- struct user{
- char u_name[25];
- char u_pass[25];
- }u;
- int choice;
- char *token; //pointer for token to split up strings
- char *tokenA; //pointer for token to split up strings in appointment
- // ------------------------ Functions ------------------------//
- //MAIN MENU
- int menu();
- int receptionist();
- int doctor();
- void user();
- char *dataEntry(int type, int sizelimit);
- //SUB MENUS
- void receptionist_menu(); //Receptionist Menu
- void doctor_menu(); //Doctor Menu
- void receptionist_pat_menu(); //Receptionist Patient Menu
- void receptionist_app_menu(); //Receptionist Appointment Menu
- void doctor_pat_menu(); //Doctor Patient Menu
- void doctor_app_menu(); //Doctor Appointment Menu
- int patMenu(); //Patient's Menu
- int appMenu(); //Appointment's Menu
- //PATIENT MENU
- void addPat(); //Add Patient
- void viewPat(); //View Patient
- void searchPat(); //Search Patient
- void editPat(); //Edit Patient
- void deletePat(); //Delete Patient
- //APPOINTMENT MENU
- int addApp(); //Add Appointment
- void viewApp(); //View Appointment
- int searchApp(); //Search Appointment
- void editApp(); //Edit Appointment
- void deleteApp(); //Delete Appointment
- //SEARCH MENU
- int searchMAIN(); //Main coding for search functions
- void searchPID(); //Search via Patient's ID
- void searchNAME(); //Search via Patient's Name
- //FEEDBACK FORM
- void feedBack(){}; //To retrieve feedback from users
- //LOGIN FUNCTIONS
- int loginval();
- //VALIDATION FUNCTIONS
- int escExit(char askey);
- int backMenu(char askey);
- int isalphaVal(char input[]);
- int isdigitVal(char input[]);
- char *dataEntry(int type, int sizeLimit);
- //AUTO GENERATE PID FUNCTIONS
- int getLine(); //Get number of lines
- int getPID(); //Get PID
- //GOTOXY FUNCTION
- int usertype;
- void gotoxy(int x, int y);
- COORD coord = {0,0};
- void gotoxy(int x, int y)
- {
- coord.X = x;
- coord.Y = y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- }
- // ------------------------ Validations ------------------------//
- int escExit(char askey)
- {
- char selection='Y';
- if(askey==ESC)
- {
- do
- {
- if(!(toupper(selection)=='Y' || toupper(selection)=='N'))
- {
- printf("\aINVALID INPUT!\n");
- }
- printf("\aDo you want to exit?\n");
- selection = getch();
- } while(!(toupper(selection)=='Y' || toupper(selection)=='N'));
- if(toupper(selection)=='Y')
- {
- system("cls");
- exit(0);
- }
- else if(toupper(selection)=='N')
- {
- system("cls");
- return 1;
- }
- }
- }
- int backMenu(char askey)
- {
- int result;
- if(askey==BKSP)
- {
- result = 1;
- }
- return result;
- }
- char *dataEntry(int type, int sizeLimit)
- {
- char input[30], p=' ';
- int i=0;
- while(i<=sizeLimit)
- {
- input[i] = _getch();
- p = input[i];
- if(i==sizeLimit)
- {
- 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
- printf("\aINVALID INPUT!\n");
- i++ ;
- }
- }
- input[i] = '\0' ;
- return input;
- }
- int isalphaVal(char input[])
- {
- int val,i;
- for(i=0;i<(strlen(input));i++)
- {
- if(isalpha(input[i])||(isspace(input[i])))
- val=1;
- else
- {
- val=0;
- break;
- }
- }
- return val;
- }
- int isdigitVal(char input[])
- {
- int val, i;
- for(i=0;i<(strlen(input));i++)
- {
- if(input[i]>=48 && input[i]<=57)
- val=1;
- else
- {
- val=0;
- break;
- }
- }
- return val;
- }
- int main()
- {
- int a, b;
- while(1)
- {
- do
- {
- system("cls");
- system("color F0");
- gotoxy(21,7);
- printf("***************Welcome to SUMHEALTH**************");
- gotoxy(33, 11);
- printf("1. PRESS 1 FOR DOCTOR\n");
- gotoxy(33, 12);
- printf("2. PRESS 2 FOR RECEPTIONIST\n");
- gotoxy(33, 13);
- printf("3. PRESS 3 FOR USER");
- gotoxy(21, 17);
- printf("***************************************************");
- gotoxy(33, 14);
- printf("Enter your choice:");
- scanf("%d", &usertype);
- switch (usertype)
- {
- case 1: a = doctor();
- if (a != 0)
- doctor_menu();
- break;
- case 2: b = receptionist();
- if (b != 0)
- receptionist_menu();
- break;
- case 3: user();
- break;
- }
- }
- while (usertype <1 || usertype > 3);
- }
- }
- int login_validation()
- {
- FILE *fpass;
- char input_name[30], input_pass[30], action;
- int login = 0, fail = 0;
- do{
- if(usertype == 1)
- fpass = fopen("password1.txt", "r+");
- else if(usertype == 2)
- fpass = fopen("password2.txt", "r+");
- rewind(fpass);
- if(fpass != NULL)
- {
- system("cls");
- if(fail ==1)
- {
- gotoxy(25, 13);
- printf("Error!");
- gotoxy(25, 14);
- printf("Please Enter Again!");
- }
- system("color F1");
- gotoxy(25, 8);
- printf("************* WELCOME!****************");
- int checker=0;
- gotoxy(25, 12);
- printf("Username: ");
- fflush(stdin);
- gets(input_name);
- gotoxy(25, 13);
- printf("Password: ");
- fflush(stdin);
- gets(input_pass);
- fscanf(fpass, "%s %s",u.u_name,u.u_pass);
- printf("%s",u.u_name);
- printf("%s",u.u_pass);
- fclose(fpass);
- if((strcmp(u.u_name, input_name)==0) && (strcmp(u.u_pass, input_pass)==0))
- {
- checker=1;
- }
- if(checker==1)
- {
- printf("\a\n\nLogin Successful!");
- login=1;
- }
- else
- fail=1;
- }
- }while(login==0);
- fclose(fpass);
- return 1;
- }
- int doctor()
- {
- int a = 0;
- do
- {
- system("cls");
- fflush(stdin);
- fflush(stdin);
- a=login_validation();
- }
- while (a == 0);
- return a;
- }
- int receptionist()
- {
- int a = 0;
- do
- {
- system("cls");
- fflush(stdin);
- fflush(stdin);
- a=login_validation();
- }
- while (a == 0);
- return a;
- }
- void user()
- {
- printf("Hello");
- }
- void doctor_menu()
- {
- do
- {
- while(1)
- {
- system("cls");
- system("color F5");
- gotoxy(25, 8);
- printf("----------DOCTOR MENU----------");
- gotoxy(25, 10);
- printf("1. Patient\n");
- gotoxy(25, 11);
- printf("2. Appointment\n");
- gotoxy(25, 12);
- printf("3. Logout");
- gotoxy(25, 13);
- printf("4. Exit");
- gotoxy(25, 15);
- printf("Enter your choice:");
- scanf("%d", &choice);
- switch (choice)
- {
- case 1: doctor_pat_menu();
- break;
- case 2: doctor_app_menu();
- break;
- case 3: return 1;
- case 4: exit(0);
- }
- }
- }
- while (choice <1 || choice > 4);
- }
- void receptionist_menu()
- {
- do
- {
- while(1)
- {
- system("cls");
- system("color F8");
- gotoxy(25, 8);
- printf("----------RECEPTIONIST MENU----------");
- gotoxy(25, 10);
- printf("1. Patient\n");
- gotoxy(25, 11);
- printf("2. Appointment\n");
- gotoxy(25, 12);
- printf("3. Logout");
- gotoxy(25, 13);
- printf("4. Exit");
- gotoxy(25, 14);
- printf("Enter your choice:");
- scanf("%d", &choice);
- switch (choice)
- {
- case 1: receptionist_pat_menu();
- break;
- case 2: receptionist_app_menu();
- break;
- case 3: return;
- case 4: exit(0);
- }
- }
- }
- while (choice <1 || choice > 2);
- }
- void doctor_pat_menu()
- {
- do
- {
- while(1)
- {
- system("cls");
- system("color FA");
- gotoxy(25, 10);
- printf("1. Search Patient\n");
- gotoxy(25, 11);
- printf("2. View Patient\n");
- gotoxy(25, 12);
- printf("3. Back\n");
- gotoxy(25, 14);
- printf("Enter your choice:");
- scanf("%d", &choice);
- switch (choice)
- {
- case 1: searchPat();
- break;
- case 2: viewPat();
- break;
- case 3: return;
- }
- }
- }
- while (choice <1 || choice > 2);
- }
- void doctor_app_menu()
- {
- do
- {
- while(1)
- {
- system("cls");
- system("color FD");
- gotoxy(25, 10);
- printf("1. Search Appointment\n");
- gotoxy(25, 11);
- printf("2. View Appointment\n");
- gotoxy(25, 12);
- printf("3. Back\n");
- gotoxy(25, 14);
- printf("Enter your choice:");
- scanf("%d", &choice);
- switch (choice)
- {
- case 1: searchApp();
- break;
- case 2: viewApp();
- break;
- case 3: return;
- }
- }
- }
- while (choice <1 || choice > 2);
- }
- void receptionist_pat_menu()
- {
- do
- {
- while(1)
- {
- system("cls");
- system("color FB");
- gotoxy(25, 8);
- printf("1. Add New Patient\n");
- gotoxy(25, 9);
- printf("2. View Patient\n");
- gotoxy(25, 10);
- printf("3. Search Patient\n");
- gotoxy(25, 11);
- printf("4. Delete Patient\n");
- gotoxy(25, 12);
- printf("5. Modify Patient\n");
- gotoxy(25, 13);
- printf("6. Back\n");
- gotoxy(25, 15);
- printf("Enter your choice:");
- fflush(stdin);
- scanf("%d", &choice);
- switch (choice)
- {
- case 1: addPat();
- break;
- case 2: viewPat();
- break;
- case 3: searchPat();
- break;
- case 4: deletePat();
- break;
- case 5: editPat();
- break;
- case 6: return;
- }
- }
- }
- while ((choice <1 || choice > 5));
- }
- void receptionist_app_menu()
- {
- do
- {
- while(1)
- {
- system("cls");
- system("color FC");
- gotoxy(25, 8);
- printf("1. Add New Appointment\n");
- gotoxy(25, 9);
- printf("2. View Appointment\n");
- gotoxy(25, 10);
- printf("3. Search Appointment\n");
- gotoxy(25, 11);
- printf("4. Delete Appointment\n");
- gotoxy(25, 12);
- printf("5. Modify Appointment\n");
- gotoxy(25 ,13);
- printf("6. Back\n");
- gotoxy(25, 15);
- printf("Enter your choice:");
- fflush(stdin);
- scanf("%d", &choice);
- switch (choice)
- {
- case 1: addApp();
- break;
- case 2: viewApp();
- break;
- case 3: searchApp();
- break;
- case 4: deleteApp();
- break;
- case 5: editApp();
- break;
- case 6: return;
- }
- system("pause");
- }
- }
- while ((choice <1 || choice > 6));
- }
- int getLine()
- {
- int i=1;
- char ch;
- FILE *fpatient;
- fpatient=fopen("PATIENT.txt","r");
- if(fpatient!=NULL)
- {
- while(!feof(fpatient))
- {
- ch = fgetc(fpatient);
- if (ch=='\n')
- i++;
- }
- }
- else
- {
- perror("ERROR\n");
- return(-1);
- }
- fclose(fpatient);
- return i;
- }
- int getPID()
- {
- int i = getLine();
- sprintf(patientdets.pid,"TP%004d",i);
- return i;
- }
- char *getFirstName()
- {
- int val=0;
- static char first[20];
- do
- {
- printf("Enter First Name:\n");
- gets(first);
- val=isalphaVal(first);
- }while(val==0);
- return first;
- }
- char *getLastName()
- {
- int val=0;
- static char last[20];
- do
- {
- printf("Enter Last Name:\n");
- gets(last);
- val=isalphaVal(last);
- }while(val==0);
- return last;
- }
- char *getFullName()
- {
- static char full[50];
- printf("Insert Full name:\n");
- gets(full);
- return full;
- }
- char *getGender()
- {
- static char gender[5];
- printf("Enter Gender:\n");
- gets(gender);
- return gender;
- }
- char *getAge()
- {
- int val=0;
- static char age[3];
- do
- {
- printf("Enter Age:\n");
- gets(age);
- val=isdigitVal(age);
- }while(val==0);
- return age;
- }
- char *getAddress()
- {
- static char address[30];
- printf("Enter Address:\n");
- gets(address);
- return address;
- }
- char *getContact()
- {
- int val=0;
- static char contact[20];
- do
- {
- printf("Enter Contact:\n");
- gets(contact);
- val=isdigitVal(contact);
- }while(val==0);
- return contact;
- }
- char *getDate()
- {
- int val=0;
- static char day[4];
- static char month[4];
- static char year[8];
- static char date[25];
- char slash[2]="/";
- char sslash[2]="/";
- printf("Enter App. Day:\n");
- gets(day);
- printf("Enter App. Month:\n");
- gets(month);
- printf("Enter App. Year:\n");
- gets(year);
- strcpy(date,"");
- strcat(date,day);
- strcat(date,sslash);
- strcat(date,month);
- strcat(date,slash);
- strcat(date,year);
- return date;
- }
- char *getTime()
- {
- static char time[15];
- static char hour[5];
- static char mins[5];
- static char type[3];
- char dot[2]=":";
- printf("Enter App. Hour:\n");
- gets(hour);
- printf("Enter App. Minutes:\n");
- gets(mins);
- printf("(AM/PM):\n");
- gets(type);
- strcpy(time,"");
- strcat(time,hour);
- strcat(time,dot);
- strcat(time,mins);
- strcat(time,type);
- return time;
- }
- char *getLocation()
- {
- static char location[40];
- printf("Enter App. Location:\n");
- gets(location);
- return location;
- }
- char *getDoctor()
- {
- static char doctor[30];
- printf("Enter App. Doctor:\n");
- gets(doctor);
- return doctor;
- }
- char *getAppType()
- {
- int app;
- char sp[]="Specialist";
- char no[]="Normal";
- char he[]="Health Test";
- printf("Choose Appointment Type:\n(1)Specialist\t(2)Normal\t(3)Health Test\n");
- scanf("%d",&app);
- switch(app)
- {
- case 1:
- {
- return(sp);
- }
- case 2:
- {
- return(no);
- }
- case 3:
- {
- return(he);
- }
- default:
- {
- perror("PLEASE ENTER A VALID NUMBER!\n");
- return(-1);
- }
- }
- }
- void addPat()
- {
- system("color FC");
- int i = 0;
- char z[30] = " ";
- int selection = 'N';
- FILE *fpatient;
- i = getPID();
- fpatient = fopen("PATIENT.txt", "a");
- if (!fpatient)
- {
- perror("FILE DOES NOT EXISTS!\n");
- return(-1);
- }
- else
- {
- do
- {
- system("cls");
- i = getPID();
- printf("Patient ID:%s\n",patientdets.pid);
- fflush(stdin);
- strcpy(patientdets.fname,getFirstName());
- strcpy(patientdets.lname,getLastName());
- strcat(z,patientdets.lname);
- strcat(patientdets.fname,z);
- strcpy(patientdets.fullname,patientdets.fname);
- strcpy(patientdets.gender,getGender());
- strcpy(patientdets.age,getAge());
- strcpy(patientdets.address,getAddress());
- strcpy(patientdets.contact,getContact());
- fprintf(fpatient,"%s-->%s-->%s-->%s-->%s-->%s\n",patientdets.pid,patientdets.fullname,patientdets.gender,patientdets.age,patientdets.address,patientdets.contact);
- printf("\nDo You Want To Add Another Patient's Details? (Y/N):");
- fflush(stdin);
- selection = getchar();
- }while(selection == 'Y' || selection == 'y');
- }
- fclose(fpatient);
- return ;
- }
- void viewPat()
- {
- system("cls");
- char buffer[1024]=" ";
- char s[4] = "-->";
- char *token;
- int counter = 1;
- FILE *fpatient;
- fpatient = fopen("PATIENT.txt","r");
- if (fpatient == NULL)
- {
- printf("ERROR:FILE CANNOT BE OPENED!\n");
- }
- else
- {
- if (feof(fpatient))
- {
- printf("ERROR:END OF FILE!\n");
- }
- else
- {
- while( fgets(buffer,1024,fpatient) != NULL )
- {
- token = strtok(buffer, s);
- strcpy(patientdets.pid,token);
- token = strtok(NULL,s);
- strcpy(patientdets.fullname,token);
- token = strtok(NULL,s);
- strcpy(patientdets.gender,token);
- token = strtok(NULL,s);
- strcpy(patientdets.age,token);
- token = strtok(NULL,s);
- strcpy(patientdets.address,token);
- token = strtok(NULL,s);
- strcpy(patientdets.contact,token);
- token = strtok(NULL,s);
- printf("Patient's ID: %s\n",patientdets.pid);
- printf("Patient's name: %s\n",patientdets.fullname);
- printf("Patient's gender: %s\n",patientdets.gender);
- printf("Patient's age: %s\n",patientdets.age);
- printf("Patient's address: %s\n",patientdets.address);
- printf("Patient's contract: %s\n",patientdets.contact);
- printf("------------------------------------------------------\n");
- }
- }
- }
- fclose(fpatient);
- printf("\n");
- system("pause");
- }
- void searchPat()
- {
- do
- {
- system("cls");
- printf("---------- SEARCH MAIN MENU ----------\n");
- printf("(1)SEARCH PID\n(2)SEARCH NAME\n(3)RETURN TO MAIN\n(4)LOGOUT\n");
- do
- {
- printf("CHOICE:");
- scanf("%d", &choice);
- }while(choice<1 || choice > 4);
- switch (choice)
- {
- case 1:
- {
- searchPID();
- break;
- }
- case 2:
- {
- searchNAME();
- break;
- }
- case 3:
- {
- return;
- }
- case 4:
- {
- exit(0);
- }
- default:
- {
- printf("PLEASE ENTER A VALID NUMBER!\n");
- break;
- }
- }
- system("pause");
- }while (1 == 1);
- }
- int searchMAIN()
- {
- int i;
- const char s[4] = "-->";
- char *token;
- int done = 0;
- FILE *fpatient;
- fpatient = fopen("PATIENT.txt","r+");
- if(fpatient==NULL)
- {
- perror("FILE CANNOT OPEN\n");
- return(-1);
- }
- else
- {
- char buffer[200];
- char input[20];
- char tok[200];
- int line=0;
- printf("ENTER ID: ");
- fflush(stdin);
- scanf("%20s",input);
- while(fgets(buffer,200,fpatient) != NULL)
- {
- line++;
- token = strtok(buffer, s);
- if (strcmp(token,input)==0)
- {
- strcpy(patientdets.pid,token);
- token = strtok(NULL,s);
- strcpy(patientdets.fullname,token);
- token = strtok(NULL,s);
- strcpy(patientdets.gender,token);
- token = strtok(NULL,s);
- strcpy(patientdets.age,token);
- token = strtok(NULL,s);
- strcpy(patientdets.address,token);
- token = strtok(NULL,s);
- strcpy(patientdets.contact,token);
- token = strtok(NULL,s);
- fclose(fpatient);
- return line;
- }
- }
- if(feof(fpatient))
- {
- printf("\n**SEARCH COMPLETED!**\n");
- }
- }
- fclose(fpatient);
- return -1;
- }
- void searchPID()
- {
- int found = 0;
- found = searchMAIN();
- if (found != -1)
- {
- printf("Patient ID: %s\n",patientdets.pid);
- printf("Fullname : %s\n",patientdets.fullname);
- printf("Gender : %s\n",patientdets.gender);
- printf("Age : %s\n",patientdets.age);
- printf("Address : %s\n",patientdets.address);
- printf("Contact : %s\n",patientdets.contact);
- }
- else
- {
- printf("\n\nID NOT DETECTED\n!");
- }
- }
- void searchNAME()
- {
- const char s[4] = "-->";
- char *token;
- FILE *fpatient;
- fpatient = fopen("PATIENT.txt","r+");
- if(fpatient==NULL)
- {
- perror("FILE CANNOT OPEN\n");
- exit(1);
- }
- else
- {
- char buffer[1024];
- char input[1024];
- char tok[512];
- int done = 0;
- printf("ENTER NAME: ");
- fflush(stdin);
- gets(input);
- while(fgets(buffer,1024,fpatient) != NULL)
- {
- strcpy(tok,buffer);
- token = strtok(tok,s);
- token = strtok(NULL,s);
- if(strstr(token,input)!=NULL)
- {
- token = strtok(buffer, s);
- strcpy(patientdets.pid,token);
- token = strtok(NULL,s);
- strcpy(patientdets.fullname,token);
- token = strtok(NULL,s);
- strcpy(patientdets.gender,token);
- token = strtok(NULL,s);
- strcpy(patientdets.age,token);
- token = strtok(NULL,s);
- strcpy(patientdets.address,token);
- token = strtok(NULL,s);
- strcpy(patientdets.contact,token);
- token = strtok(NULL,s);
- printf("Patient ID: %s\n",patientdets.pid);
- printf("Fullname : %s\n",patientdets.fullname);
- printf("Gender : %s\n",patientdets.gender);
- printf("Age : %s\n",patientdets.age);
- printf("Address : %s\n",patientdets.address);
- printf("Contact : %s\n",patientdets.contact);
- done =1;
- }
- }
- if(feof(fpatient))
- {
- printf("\nSearch complete\n");
- }
- else
- {
- printf("\nFile can't be searched completely ");
- exit(1);
- }
- if (done!=1)
- {
- printf("Name cannot be found");
- }
- }
- }
- void editPat()
- {
- FILE *fpatient;
- FILE *ftemp;
- int found=0,choice=0,line=0,i;
- char selection=0;
- char buff[512]="",buff2[512];
- found = searchMAIN();
- if (found != -1)
- {
- fflush(stdin);
- printf("Is this the patient ID you want to modify? (Y/N)\n");
- printf("Patient ID: %s\n",patientdets.pid);
- printf("Fullname : %s\n",patientdets.fullname);
- printf("Gender : %s\n",patientdets.gender);
- printf("Age : %s\n",patientdets.age);
- printf("Address : %s\n",patientdets.address);
- printf("Contact : %s\n",patientdets.contact);
- printf("CHOICE:");
- scanf("%c",&selection);
- if(toupper(selection)== 'Y')
- {
- fpatient=fopen("PATIENT.txt","a+");
- ftemp=fopen("EditPatient.txt","w");
- printf("(1)Full Name\n");printf("(2)Gender\n");printf("(3)Age\n");printf("(4)Address\n");printf("(5)Contact\n");printf("(0)Back\n");
- printf("Select option to be modified:");
- scanf("%d",&choice);
- switch(choice)
- {
- case 1:
- {
- fflush(stdin);
- strcpy(patientdets.fullname,getFullName());
- break;
- }
- case 2:
- {
- fflush(stdin);
- strcpy(patientdets.gender,getGender());
- printf("%s",patienttemp.gender);
- break;
- }
- case 3:
- {
- fflush(stdin);
- strcpy(patientdets.age,getAge());
- break;
- }
- case 4:
- {
- fflush(stdin);
- strcpy(patientdets.address,getAddress());
- break;
- }
- case 5:
- {
- fflush(stdin);
- strcpy(patientdets.contact,getContact());
- break;
- }
- }
- strcat(buff, patientdets.pid);strcat(buff,"-->");
- strcat(buff, patientdets.fullname);strcat(buff, "-->");
- strcat(buff, patientdets.gender);strcat(buff, "-->");
- strcat(buff, patientdets.age);strcat(buff, "-->");
- strcat(buff, patientdets.address);strcat(buff,"-->");
- strcat(buff, patientdets.contact);
- printf("test %s",buff);
- rewind(fpatient);
- while (1)
- {
- if(feof(fpatient))
- break;
- line++;
- if(found == line)
- {
- printf("%s",buff);
- fputs(buff,ftemp);
- fgets(buff2,512,fpatient); // store current line into buffer2
- }
- else
- {
- fgets(buff2,512,fpatient);
- fputs(buff2,ftemp);
- }
- }
- fclose(fpatient);
- fclose(ftemp);
- remove("PATIENT.txt");
- rename("EditPatient.txt","PATIENT.txt");
- }
- else
- {
- printf("SEE YOU AGAIN!");
- return;
- system("pause");
- }
- }
- else
- {
- printf("\n\nID NOT DETECTED\n!");
- }
- system("pause");
- }
- void deletePat()
- {
- FILE *fpatient;
- fpatient = fopen("PATIENT.txt","r");
- if(fpatient==NULL)
- {
- printf("FILE CANNOT BE OPENED!\n");
- exit(1);
- }
- else
- {
- int line=0;
- char selection;
- line = searchMAIN();
- rewind(fpatient);
- if(line != -1)
- {
- printf("Patient ID: %s\n",patientdets.pid);
- printf("Fullname : %s\n",patientdets.fullname);
- printf("Gender : %s\n",patientdets.gender);
- printf("Age : %s\n",patientdets.age);
- printf("Address : %s\n",patientdets.address);
- printf("Contact : %s\n",patientdets.contact);
- printf("Are you sure you wanted to delete this patient?\n");
- fflush(stdin);
- printf("CHOICE:");
- selection=getchar();
- if(toupper(selection)=='Y')
- {
- char words[100];
- char *buffer;
- char *ptr;
- int read_line=0;
- char user_input[100];
- int done=0;
- buffer=(char *)malloc(1000*sizeof(char));
- memset(buffer,0,1000*sizeof(char));
- ptr=buffer;
- strcat(patientdets.pid,"\n");
- while(fgets(words,100,fpatient) != NULL)
- {
- read_line ++;
- if(read_line != line)
- {
- strcpy(ptr,words);
- ptr +=strlen(words);
- }
- }
- fclose(fpatient);
- fpatient=fopen("PATIENT.txt","w");
- fprintf(fpatient,"%s",buffer);
- fclose(fpatient);
- }
- }
- }
- system("pause");
- }
- int addApp()
- {
- FILE *fapp;
- int found=-1;
- char selection;
- found = searchMAIN();
- if (found >= 0)
- {
- printf("Add appointment for this patient? (Y/N)\n");
- printf("Patient ID: %s\n",patientdets.pid);
- printf("Fullname : %s\n",patientdets.fullname);
- printf("Gender : %s\n",patientdets.gender);
- printf("Age : %s\n",patientdets.age);
- printf("Address : %s\n",patientdets.address);
- printf("Contact : %s\n",patientdets.contact);
- fflush(stdin);
- scanf("%c",&selection);
- if(toupper(selection)=='Y')
- {
- fapp=fopen("APP.txt","a");
- strcpy(appdets.pid,patientdets.pid);
- fflush(stdin);
- strcpy(appdets.date,getDate());
- fflush(stdin);
- strcpy(appdets.time,getTime());
- fflush(stdin);
- strcpy(appdets.location,getLocation());
- fflush(stdin);
- strcpy(appdets.doctor,getDoctor());
- fflush(stdin);
- strcpy(appdets.apptype,getAppType());
- fprintf(fapp,"%s-->%s-->%s-->%s-->%s-->%s\n",appdets.pid,appdets.date,appdets.time,appdets.location,appdets.doctor,appdets.apptype);
- fclose(fapp);
- }
- else
- {
- printf("<-Back");
- return 1;
- }
- }
- return 0;
- system("pause");
- }
- void viewApp()
- {
- system("cls");
- char buffer[1024]=" ";
- char s[4] = "-->";
- char *token;
- int counter = 1;
- FILE *fapp;
- fapp = fopen("APP.txt","r");
- if (fapp == NULL)
- {
- printf("ERROR:FILE CANNOT BE OPENED!\n");
- }
- else
- {
- if (feof(fapp))
- {
- printf("ERROR:END OF FILE!\n");
- fclose(fapp);
- }
- else
- {
- while( fgets(buffer,1024,fapp) != NULL )
- {
- token = strtok(buffer, s);
- strcpy(appdets.pid,token);
- token = strtok(NULL,s);
- strcpy(appdets.date,token);
- token = strtok(NULL,s);
- strcpy(appdets.time,token);
- token = strtok(NULL,s);
- strcpy(appdets.location,token);
- token = strtok(NULL,s);
- strcpy(appdets.doctor,token);
- token = strtok(NULL,s);
- strcpy(appdets.apptype,token);
- token = strtok(NULL,s);
- printf("Patient's ID: %s\n",appdets.pid);
- printf("Appointment's Date: %s\n",appdets.date);
- printf("Appointment's Time: %s\n",appdets.time);
- printf("Appointment's Location: %s\n",appdets.location);
- printf("Doctor In Charge: %s\n",appdets.doctor);
- printf("Appointment's Type: %s\n",appdets.apptype);
- printf("------------------------------------------------------\n");
- }
- fclose(fapp);
- }
- }
- printf("\n");
- system("pause");
- }
- int searchApp()
- {
- system("cls");
- char buffer[1024]=" ";
- char s[4] = "-->";
- char *token;
- int counter = 0;
- char tempID[100] ;
- FILE *fapp;
- fapp = fopen("APP.txt","r");
- if (fapp == NULL)
- {
- printf("ERROR:FILE CANNOT BE OPENED!\n");
- }
- else
- {
- if (feof(fapp))
- {
- printf("ERROR:END OF FILE!\n");
- fclose(fapp);
- }
- else
- {
- printf("ENTER ID: ");
- fflush(stdin);
- gets(tempID);
- while( fgets(buffer,1024,fapp) != NULL )
- {
- counter ++ ;
- token = strtok(buffer, s);
- if ( strcmp(token,tempID)== 0)
- {
- strcpy(appdets.pid,token);
- token = strtok(NULL,s);
- strcpy(appdets.date,token);
- token = strtok(NULL,s);
- strcpy(appdets.time,token);
- token = strtok(NULL,s);
- strcpy(appdets.location,token);
- token = strtok(NULL,s);
- strcpy(appdets.doctor,token);
- token = strtok(NULL,s);
- strcpy(appdets.apptype,token);
- token = strtok(NULL,s);
- printf("Patient's ID: %s\n",appdets.pid);
- printf("Appointment's Date: %s\n",appdets.date);
- printf("Appointment's Time: %s\n",appdets.time);
- printf("Appointment's Location: %s\n",appdets.location);
- printf("Doctor In Charge: %s\n",appdets.doctor);
- printf("Appointment's Type: %s\n",appdets.apptype);
- printf("------------------------------------------------------\n");
- return counter;
- }
- }
- fclose(fapp);
- }
- }
- printf("Can't find appointment");
- system("pause");
- return counter;
- }
- void deleteApp()
- {
- system("cls");
- FILE *fapp;
- FILE *fpatient;
- fapp = fopen("APP.txt","r");
- char buffer[1024]=" ";
- char s[4] = "-->";
- char *token;
- int counter = 1;
- char tempID[100];
- if(fapp==NULL)
- {
- printf("FILE CANNOT BE OPENED!\n");
- exit(1);
- }
- else
- {
- char selection;
- printf("ENTER ID: ");
- fflush(stdin);
- gets(tempID);
- while(fgets(buffer,1024,fapp) != NULL)
- {
- token = strtok(buffer, s);
- if ( strcmp(token,tempID)== 0)
- {
- strcpy(appdets.pid,token);
- token = strtok(NULL,s);
- strcpy(appdets.date,token);
- token = strtok(NULL,s);
- strcpy(appdets.time,token);
- token = strtok(NULL,s);
- strcpy(appdets.location,token);
- token = strtok(NULL,s);
- strcpy(appdets.doctor,token);
- token = strtok(NULL,s);
- strcpy(appdets.apptype,token);
- token = strtok(NULL,s);
- printf("Patient's ID: %s\n",appdets.pid);
- printf("Appointment's Date: %s\n",appdets.date);
- printf("Appointment's Time: %s\n",appdets.time);
- printf("Appointment's Location: %s\n",appdets.location);
- printf("Doctor In Charge: %s\n",appdets.doctor);
- printf("Appointment's Type: %s\n",appdets.apptype);
- printf("------------------------------------------------------\n");
- printf("Are you sure you wanted to delete this entry?\n");
- fflush(stdin);
- printf("CHOICE:");
- selection=getchar();
- if(toupper(selection)=='Y')
- {
- char words[100];
- char *buffer;
- char *ptr;
- int read_line=0;
- char user_input[100];
- int done=0;
- buffer=(char *)malloc(1000*sizeof(char));
- memset(buffer,0,1000*sizeof(char));
- ptr=buffer;
- strcat(appdets.pid,"\n");
- while(fgets(words,100,fapp) != NULL)
- {
- read_line ++;
- if(read_line != 0)
- {
- strcpy(ptr,words);
- ptr +=strlen(words);
- }
- }
- fclose(fapp);
- fpatient=fopen("APP.txt","w");
- fprintf(fapp,"%s",buffer);
- fclose(fapp);
- }
- }
- }
- }
- }
- void editApp()
- {
- FILE *fapp;
- FILE *fTemp;
- int found=0,choice=0,line=0,i;
- char selection=0,ch;
- char buff[512]="" , buff2[512]="";
- found = searchApp();
- if (found != -1)
- {
- fflush(stdin);
- system("cls");
- printf("%d\n\n",found);
- printf("Patient's ID: %s\n",appdets.pid);
- printf("Appointment's Date: %s\n",appdets.date);
- printf("Appointment's Time: %s\n",appdets.time);
- printf("Appointment's Location: %s\n",appdets.location);
- printf("Doctor In Charge: %s\n",appdets.doctor);
- printf("Appointment's Type: %s\n",appdets.apptype);
- printf("------------------------------------------------------\n");
- printf("Are you sure you wanted to edit this appointment?\n");
- printf("CHOICE:");
- scanf("%c",&selection);
- if(toupper(selection)== 'Y')
- {
- fapp=fopen("APP.txt","a+");
- fTemp=fopen("EditPatient.txt","w");
- printf("(1)Date\n");printf("(2)Time\n");printf("(3)Location\n");printf("(4)Doctor\n");printf("(5)Apptype\n");printf("(0)Back\n");
- printf("Select option to be modified:");
- scanf("%d",&choice);
- switch(choice)
- {
- case 1:
- {
- fflush(stdin);
- strcpy(appdets.date,getDate());
- break;
- }
- case 2:
- {
- fflush(stdin);
- strcpy(appdets.time,getTime());
- break;
- }
- case 3:
- {
- fflush(stdin);
- strcpy(appdets.location,getLocation());
- break;
- }
- case 4:
- {
- fflush(stdin);
- strcpy(appdets.doctor,getDoctor());
- break;
- }
- case 5:
- {
- fflush(stdin);
- strcpy(appdets.apptype,getAppType());
- break;
- }
- }
- strcat(buff, appdets.pid);strcat(buff,"-->");
- strcat(buff, appdets.date);strcat(buff, "-->");
- strcat(buff, appdets.time);strcat(buff, "-->");
- strcat(buff, appdets.location);strcat(buff, "-->");
- strcat(buff, appdets.doctor);strcat(buff,"-->");
- strcat(buff, appdets.apptype);
- rewind(fapp);
- while (!feof(fapp))
- {
- line++;
- if(found == line)
- { printf("test %s",buff);
- fputs(buff,fTemp);
- fgets(buff2,512,fapp); // store current line into buffer2
- }
- else
- {
- fgets(buff2,512,fapp);
- fputs(buff2,fTemp);
- }
- }
- fclose(fapp);
- fclose(fTemp);
- rename("APP.txt","BackupAPP.txt");
- rename("EditApp.txt","APP.txt");
- }
- else
- {
- printf("SEE YOU AGAIN!");
- return;
- system("pause");
- }
- }
- else
- {
- printf("\n\nID NOT DETECTED\n!");
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement