Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<stdio.h>
- #include<string.h>
- #include<ctype.h>
- #include<windows.h>
- #include<stdlib.h>
- int doctor(); //sub function declaration
- int reception(); //int or void is return type
- int doctor_menu();
- int reception_menu();
- int doctor_patient_menu();
- int doctor_appointment_menu();
- int reception_patient_menu();
- int reception_appointmet_menu();
- int add_new_patient();
- int view_patient();
- int search_patient();
- int delete_patient();
- int modify_patient();
- int add_appointment();
- int search_appointment();
- int delete_appointment();
- int modify_appointment();
- int choice;
- void gotoxy();
- struct patient
- {
- char patient_name[100];
- char patient_ID[10];
- char gender[10];
- char age[10];
- char contact_num[30];
- char address[25];
- char city[12];
- char state[10];
- char zipcode[20];
- char doctor_type[20];
- char doctor_name[20];
- char appointment_time[10];
- }p1;
- void getPatientName()
- { int n=0;
- gotoxy(25, 9);
- char buffer[100];
- printf("Enter Name:");
- gets(buffer);
- while(n < sizeof(buffer))
- {
- if(buffer[n] == ' ')
- buffer[n] = '_' ;
- n++ ;
- }
- buffer[n] = '0';
- strcpy(p1.patient_name , buffer);
- }
- void getPatientID()
- {
- gotoxy(25, 10);
- printf("Enter Patient ID:");
- gets(p1.patient_ID);
- }
- void getGender()
- {
- gotoxy(25, 11);
- printf("Enter Gender:");
- gets(p1.gender);
- }
- void getAge()
- {
- gotoxy(25, 12);
- printf("Enter Age:");
- gets(p1.age);
- }
- void getContactNum()
- {
- gotoxy(25, 13);
- printf("Enter Contact Num:");
- gets(p1.contact_num);
- }
- void getAddress()
- {
- gotoxy(25, 14);
- printf("Enter Address:");
- gets(p1.address);
- }
- void getCity()
- {
- gotoxy(25, 15);
- printf("Enter City:");
- gets(p1.city);
- }
- void getState()
- {
- gotoxy(25, 16);
- printf("Enter State:");
- gets(p1.state);
- }
- void getZipCode()
- {
- gotoxy(25, 17);
- printf("Enter ZipCode:");
- gets(p1.zipcode);
- }
- COORD coord = { 0, 0 };
- void main() // Login Process
- {
- int a, b;
- do{
- system("cls");
- gotoxy(25, 8);
- printf("1. Doctor\n");
- gotoxy(25, 9);
- printf("2. Reception\n");
- gotoxy(25, 11);
- printf("Enter your choice:");
- scanf("%d", &choice);
- if (choice < 1 || choice > 2)
- {
- gotoxy(25, 13);
- printf("Invalid Entry\n");
- gotoxy(25, 14);
- printf("Please try again!\n");
- }
- switch (choice)
- {
- case 1: a = doctor();
- if (a != 0)
- doctor_menu();
- break;
- case 2: b = reception();
- if (b != 0)
- reception_menu();
- break;
- }
- } while (choice <1 || choice > 2);
- }
- void gotoxy(int x, int y)
- {
- coord.X = x;
- coord.Y = y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- }
- int doctor()
- {
- char name[30] = "Doctor", password[10] = "1234";
- char user_input[30], user_password[10];
- int a = 0;
- do{
- system("cls");
- gotoxy(25, 8);
- printf("Welcome Doctor!\n");
- fflush(stdin);
- gotoxy(25, 11);
- printf("Name:");
- gets(user_input);
- fflush(stdin);
- gotoxy(25, 13);
- printf("Password:");
- gets(user_password);
- if ((strcmp(name, user_input) == 0) && (strcmp(password, user_password) == 0))
- {
- printf("Login successful");
- a = 1;
- }
- else
- {
- a = 0;
- }
- } while (a == 0);
- return a;
- }
- int reception()
- {
- char name[30] = "Jack", password[10] = "1234";
- char user_input[30], user_password[10];
- int a = 0;
- do{
- system("cls");
- gotoxy(25, 8);
- printf("Welcome Admin!\n");
- fflush(stdin);
- gotoxy(25, 11);
- printf("Name:");
- fflush(stdin);
- gets(user_input);
- gotoxy(25, 13);
- printf("Password:");
- gets(user_password);
- if ((strcmp(name, user_input) == 0) && ((strcmp(password, user_password) == 0)))
- {
- printf("Login successful");
- a = 1;
- }
- else
- {
- a = 0;
- }
- } while (a == 0);
- return a;
- }
- int doctor_menu()
- {
- do{
- system("cls");
- gotoxy(25, 8);
- printf("----------Doctor Menu----------");
- gotoxy(25, 10);
- printf("1. Patient\n");
- gotoxy(25, 11);
- printf("2. Appointment\n");
- if (choice < 1 && choice > 2)
- {
- gotoxy(25, 15);
- printf("Invalid Entry\n");
- gotoxy(25, 16);
- printf("Please try again!\n");
- }
- gotoxy(25, 13);
- printf("Enter your choice:");
- scanf("%d", &choice);
- switch (choice)
- {
- case 1: doctor_patient_menu();
- break;
- case 2: doctor_appointment_menu();
- break;
- }
- } while (choice <1 || choice > 2);
- }
- int reception_menu()
- {
- do{
- system("cls");
- gotoxy(25, 8);
- printf("----------Reception Menu----------");
- gotoxy(25, 10);
- printf("1. Patient\n");
- gotoxy(25, 11);
- printf("2. Appointment\n");
- gotoxy(25, 13);
- printf("Enter your choice:");
- scanf("%d", &choice);
- if (choice < 1 || choice > 2)
- {
- gotoxy(25, 15);
- printf("Invalid Entry\n");
- gotoxy(25, 16);
- printf("Please try again!\n");
- }
- switch (choice)
- {
- case 1: reception_patient_menu();
- break;
- case 2: reception_appointmet_menu();
- break;
- default:;
- }
- } while (choice <1 || choice > 2);
- }
- int doctor_patient_menu()
- {
- do{
- system("cls");
- gotoxy(25, 10);
- printf("1. Search Patient\n");
- gotoxy(25, 11);
- printf("2. Modify Patient\n");
- gotoxy(25, 13);
- printf("Enter your choice:");
- scanf("%d", &choice);
- if ((choice <1 || choice > 2))
- {
- gotoxy(25, 15);
- printf("Invalid Entry\n");
- gotoxy(25, 16);
- printf("Please try again!\n");
- }
- switch (choice)
- {
- case 1: search_patient();
- break;
- case 2: modify_patient();
- break;
- }
- } while (choice <1 || choice > 2);
- }
- int doctor_appointment_menu()
- {
- do{
- system("cls");
- gotoxy(25, 10);
- printf("1. Search Appointment\n");
- gotoxy(25, 11);
- printf("2. Modify Appointment\n");
- gotoxy(25, 13);
- printf("Enter your choice:");
- scanf("%d", &choice);
- if (choice <1 || choice > 2)
- {
- gotoxy(25, 15);
- printf("Invalid Entry\n");
- gotoxy(25, 16);
- printf("Please try again!\n");
- }
- switch (choice)
- {
- case 1: search_appointment();
- break;
- case 2: modify_appointment();
- break;
- }
- } while (choice <1 || choice > 2);
- }
- int reception_patient_menu()
- {
- do{
- system("cls");
- 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, 14);
- printf("Enter your choice:");
- fflush(stdin);
- scanf("%d", &choice);
- if ((choice <1 || choice > 5))
- {
- gotoxy(25, 16);
- printf("Invalid Entry\n");
- gotoxy(25, 17);
- printf("Please try again!\n");
- }
- switch (choice)
- {
- case 1: add_new_patient();
- break;
- case 2: view_patient();
- break;
- case 3: search_patient();
- break;
- case 4: delete_patient();
- break;
- case 5: modify_patient();
- break;
- }
- } while ((choice <1 || choice > 5));
- }
- int reception_appointmet_menu()
- {
- do{
- system("cls");
- gotoxy(25, 8);
- printf("1. Add New Appointment\n");
- gotoxy(25, 9);
- printf("2. Search Appointment\n");
- gotoxy(25, 10);
- printf("3. Delete Appointment\n");
- gotoxy(25, 11);
- printf("4. Modify Appointment\n");
- gotoxy(25, 13);
- printf("Enter your choice:");
- fflush(stdin);
- scanf("%d", &choice);
- if ((choice <1 || choice > 4))
- {
- gotoxy(25, 15);
- printf("Invalid Entry\n");
- gotoxy(25, 16);
- printf("Please try again!\n");
- }
- switch (choice)
- {
- case 1: add_appointment();
- break;
- case 2: search_appointment();
- break;
- case 3: delete_appointment();
- break;
- case 4: modify_appointment();
- break;
- }
- } while ((choice <1 || choice > 4));
- }
- int add_new_patient() // Store patient details
- {
- char selection = 'Y';
- FILE*fp;
- fp = fopen("patient.txt", "a");
- if (!fp)
- {
- printf("File cannot open!");
- reception_patient_menu();
- }
- else
- {
- while (selection = 'Y')
- {
- system("cls");
- fflush(stdin);
- getPatientName();
- getPatientID();
- getGender();
- getAge();
- getContactNum();
- getAddress();
- getCity();
- getState();
- getZipCode();
- fprintf(fp, "%s>\t\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", p1.patient_ID, p1.patient_name, p1.gender, p1.age, p1.contact_num, p1.address, p1.city, p1.state, p1.zipcode);
- gotoxy(25, 19);
- printf("Do You Want To Add Another Patient's Details? (Y/N)");
- fflush(stdin);
- selection = getchar();
- if (toupper(selection) != 'Y')
- {
- fclose(fp);
- reception_patient_menu();
- }
- }
- }
- }
- int view_patient()
- {
- FILE*fp;
- int length = 0;
- fp = fopen("patient.txt", "r");
- if (fp == NULL)
- {
- printf("File Cannot Open!\n");
- system("pause");
- reception_patient_menu();
- }
- else
- {
- while (1) {
- fscanf(fp, "%s", p1.patient_ID);
- if (feof(fp))
- break;
- gotoxy(25, 15);
- length = strlen(p1.patient_ID);
- p1.patient_ID[length - 1] = '\0';
- printf("Patient ID\t:%s\n", p1.patient_ID);
- fscanf(fp, "%s", p1.patient_name);
- printf("Patient Name\t:%s\n", p1.patient_name);
- fscanf(fp, "%s", p1.gender);
- printf("Gender\t\t:%s\n", p1.gender);
- fscanf(fp, "%s", p1.age);
- printf("Age\t\t:%s\n", p1.age);
- fscanf(fp, "%s", p1.contact_num);
- printf("Contact Number\t:%s\n", p1.contact_num);
- fscanf(fp, "%s", p1.address);
- printf("Address\t\t:%s\n", p1.address);
- fscanf(fp, "%s", p1.city);
- printf("City\t\t:%s\n", p1.city);
- fscanf(fp, "%s", p1.state);
- printf("State\t\t:%s\n", p1.state);
- fscanf(fp, "%s", p1.zipcode);
- printf("ZipCode\t\t:%s\n\n", p1.zipcode);
- } ;
- fclose(fp);
- system("pause");
- reception_patient_menu();
- }
- }
- int search_patient()
- {
- FILE*fp;
- const char s[2] = ">";
- char *token;
- long position;
- fp = fopen("patient.txt", "r");
- if(fp==NULL)
- {
- exit(1);
- printf("File cannot open");
- }
- else
- {
- char buffer[200];
- char input[200];
- char tok[200];
- int found = 1;
- printf("Enter the id: ");
- fflush(stdin);
- gets(input);
- position = ftell(fp);
- while(fgets(buffer,200,fp) != NULL)
- {
- strcpy(tok,buffer);
- token = strtok(tok, s);
- if(strstr(token,input)!=NULL)
- {
- fgetpos(fp, position);
- fscanf(fp,"%s %s %s %s %s %s %s %s %s %s",p1.patient_ID
- ,p1.patient_name
- ,p1.gender
- ,p1.contact_num
- ,p1.age
- ,p1.address
- ,p1.city
- ,p1.zipcode
- ,p1.state
- ,p1.appointment_time);
- printf("name: %s\n",p1.patient_name);
- printf("Gender: %s\n",p1.gender);
- printf("age: %s\n",p1.age);
- printf("address: %s\n",p1.address);
- found = 0;
- }
- position = ftell(fp);
- }
- if(found == 1)
- printf("ID not found");
- if(feof(fp))
- {
- printf("\n");
- }
- else
- {
- printf("\nError");
- exit(1);
- }
- }
- fclose(fp);
- system("pause");
- reception_patient_menu();
- }
- int delete_patient()
- {
- FILE*fp;
- system("cls");
- char user_input[30];
- fp = fopen("patient.txt", "r");
- if (fp = NULL)
- {
- printf("File Cannot Open");
- }
- else
- {
- gotoxy(25, 10);
- printf("Enter Your Patient Name:\n");
- fflush(stdin);
- gets(user_input);
- fscanf(fp, "%s", p1.patient_name);
- {
- if (strcmp(user_input, p1.patient_name) == 0)
- {
- fscanf(fp, "%s", p1.patient_name);
- printf("Patient Name :%s\n", p1.patient_name);
- fscanf(fp, "%s", p1.patient_ID);
- printf("Patient ID :%s", p1.patient_ID);
- }
- else
- {
- printf("Patient Name Cannot Find");
- }
- }
- }
- }
- int modify_patient()
- {
- char user_input[30];
- system("cls");
- FILE*fp;
- fp = fopen("patient.txt", "r");
- if (fp = NULL)
- {
- printf("File Cannot Open");
- }
- else
- {
- gotoxy(25, 10);
- fflush(stdin);
- printf("Enter Your Patient Name:\n");
- gets(user_input);
- printf("%s", user_input);
- {
- if (strcmp(user_input, p1.patient_name) == 0)
- {
- fscanf(fp, "%s", p1.patient_name);
- printf("Patient Name :%s\n", p1.patient_name);
- fscanf(fp, "%s", p1.patient_ID);
- printf("Patient ID :%s", p1.patient_ID);
- }
- else
- {
- printf("Patient Name Cannot Find");
- }
- }
- }
- }
- int add_appointment()
- {
- FILE*fp;
- char user_input[30];
- int i = 0;
- system("cls");
- fp = fopen("patient.txt", "r");
- if (fp = NULL)
- {
- printf("File Cannot Open");
- }
- else
- {
- printf("Enter Your Patient ID:");
- fflush(stdin);
- gets(user_input);
- do {
- fscanf(fp, "%s", p1.patient_ID);
- } while (!feof(fp));
- printf("Enter Doctor Type:\n");
- gets(p1.doctor_type);
- fprintf(fp, "%s", p1.doctor_type);
- printf("Enter Doctor Name:\n");
- gets(p1.doctor_name);
- fprintf(fp, "%s", p1.doctor_name);
- printf("Enter Appointment Time\n");
- gets(p1.appointment_time);
- fprintf(fp, "%s\n", p1.appointment_time);
- fclose(fp);
- }
- }
- int search_appointment()
- {
- FILE*fp;
- char user_input[30];
- system("cls");
- fp = fopen("patient.txt", "r");
- if (fp == NULL)
- {
- printf("File Cannot Open");
- }
- else
- {
- gotoxy(25, 10);
- printf("Enter Your Appointment ID:");
- }
- }
- int delete_appointment()
- {
- FILE*fp;
- char user_input[30];
- system("cls");
- fp = fopen("patient.txt", "r");
- if (fp == NULL)
- {
- printf("File Cannot Open");
- }
- else
- {
- gotoxy(25, 10);
- printf("Enter Your Appointment ID:");
- gets(user_input);
- }
- }
- int modify_appointment()
- {
- FILE*fp;
- char user_input[30];
- int i = 0;
- system("cls");
- fp = fopen("patient.txt", "r");
- if (fp == NULL)
- {
- printf("File Cannot Open");
- }
- else
- {
- printf("Enter Your Appointment ID:");
- gets(user_input);
- for (i = 0; i<100; i++)
- {
- fscanf(fp, "%s", p1.patient_ID);
- if (strcmp(user_input, p1.patient_ID) == 0)
- {
- printf("Patient Found");
- }
- else
- {
- printf("Error");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement