Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<string.h>
- #include<stdio.h>
- #include<stdlib.h>
- #include<ctype.h>
- #include<windows.h>
- struct patient{
- char pid[6];
- char fname[20];
- char lname[20];
- char fullname[50];
- char gender[2];
- char age[3];
- char address[30];
- char city[20];
- char state[20];
- char zipcode[6];
- char apptype[20];
- char doctor[30];
- char date[9];
- char location[40];
- }patientdets, patienttemp;
- int choice;
- FILE *fpatient;
- char *token;
- //MAIN MENU
- void menu();
- //SUB MENUS
- void patmenu();
- void appmenu();
- //PATIENT MENU
- void addpat();
- void viewpat();
- void searchpat();
- void editpat(){};
- void deletepat(){};
- //SEARCH MENU
- void searchpid();
- void searchname(){};
- char pr_data(struct patient patientdets);
- void get_new_item();
- //APPOINTMENT MENU
- void addapp(){};
- void viewapp(){};
- void searchapp(){};
- void editapp(){};
- void deleteapp(){};
- //STRUCTURE FUNCTIONS
- char *getPatientID();
- COORD coord = { 0, 0 };
- void gotoxy(int x, int y)
- {
- coord.X = x;
- coord.Y = y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- }
- int main()
- {
- menu();
- }
- void menu()
- {
- do
- {
- system("cls");
- printf("---------- MAIN MENU ----------\n");
- printf("(1)PATIENT\n(2)APPOINTMENT\n(3)EXIT PROGRAM\n");
- printf("CHOICE:");
- scanf("%d", &choice);
- switch (choice)
- {
- case 1:
- {
- patmenu();
- break;
- }
- case 2:
- {
- appmenu();
- break;
- }
- case 3:
- {
- exit(0);
- }
- default:
- {
- printf("PLEASE ENTER A VALID NUMBER!\n");
- }
- }
- } while (1);
- }
- void patmenu()
- {
- do
- {
- system("cls");
- printf("---------- PATIENT MENU ----------\n");
- printf("(1)ADD PATIENT\n(2)VIEW PATIENT\n(3)SEARCH PATIENT\n(4)EDIT PATIENT\n(5)DELETE PATIENT\n(6)RETURN MAIN\n(7)EXIT PROGRAM\n");
- printf("CHOICE:");
- scanf("%d", &choice);
- switch (choice)
- {
- case 1:
- {
- addpat();
- break;
- }
- case 2:
- {
- viewpat();
- break;
- }
- case 3:
- {
- searchpat();
- break;
- }
- case 4:
- {
- editpat();
- break;
- }
- case 5:
- {
- deletepat();
- break;
- }
- case 6:
- {
- return;
- }
- case 7:
- {
- exit(0);
- }
- default:
- {
- printf("PLEASE ENTER A VALID NUMBER!\n");
- }
- }
- } while (1 == 1);
- }
- void appmenu()
- {
- system("cls");
- int choice;
- char pid;
- printf("---------- PATIENT MENU ----------\n");
- printf("(1)ADD APPOINTMENT\n(2)VIEW APPOINTMENT\n(3)SEARCH APPOINTMENT\n(4)EDIT APPOINTMENT\n(5)DELETE APPOINTMENT\n(6)RETURN MAIN\n(7)EXIT PROGRAM\n");
- printf("CHOICE:\n");
- scanf("%d", &choice);
- while (1 == 1)
- {
- switch (choice)
- {
- case 1:
- {
- addapp();
- break;
- }
- case 2:
- {
- viewapp();
- break;
- }
- case 3:
- {
- searchapp();
- break;
- }
- case 4:
- {
- editapp();
- break;
- }
- case 5:
- {
- deleteapp();
- break;
- }
- case 6:
- {
- return;
- }
- case 7:
- {
- exit(0);
- }
- }
- }
- }
- char *getPatientID()
- {
- static char pid[6];
- printf("Enter Patient ID:\n");
- scanf("%s", pid);
- return pid;
- }
- char *getFirstName()
- {
- static char first[20];
- printf("Enter First Name:\n");
- gets(first);
- return first;
- }
- char *getLastName()
- {
- static char last[20];
- printf("Enter Last Name:\n");
- gets(last);
- 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()
- {
- static char age[3];
- printf("Enter Age:\n");
- gets(age);
- return age;
- }
- char *getAddress()
- {
- static char address[50];
- printf("Enter Address:\n");
- gets(address);
- return address;
- }
- char *getCity()
- {
- static char city[10];
- printf("Enter City:\n");
- gets(city);
- return city;
- }
- char *getState()
- {
- static char state[10];
- printf("Enter State:\n");
- gets(state);
- return state;
- }
- char *getZipcode()
- {
- static char zipcode[6];
- printf("Enter Zipcode:\n");
- gets(zipcode);
- return zipcode;
- }
- void addpat()
- {
- int i = 0;
- char selection;
- char z[30] = " ";
- fpatient = fopen("TP038123.txt", "a");
- if (!fpatient)
- {
- printf("File does not exists!\n");
- }
- else
- {
- system("cls");
- strcpy(patientdets.pid, getPatientID());
- fflush(stdin);
- /*strcpy(patientdets.fname, getFirstName());
- strcpy(patientdets.lname, getLastName());*/
- /*strcat(z, patientdets.lname);
- strcat(patientdets.fname, z);*/
- strcpy(patientdets.fullname, getFullName());
- fflush(stdin);
- strcpy(patientdets.gender, getGender());
- fprintf(fpatient, "%s-->%s-->%s\n", patientdets.pid, patientdets.fullname, patientdets.gender);
- fclose(fpatient);
- //getch();
- }
- }
- void viewpat()
- {
- system("cls");
- int getc(void);
- char buffer[1024]="";
- char tok[4] = "-->";
- char *token;
- fpatient = fopen("TP038123.txt", "r");
- if (fpatient == NULL){ //this is to check whether the file exist, this is not exist
- printf("ERROR:FILE CANNOT BE OPENED!\n");
- }
- else //this is exist
- {
- if (feof(fpatient))
- {
- printf("ERROR:END OF FILE!\n");
- fclose(fpatient);
- }
- else{
- fread(&buffer, sizeof(patientdets), 1, fpatient);
- token = strtok(buffer, tok);
- printf("Patient ID:\t Fullname:\t Gender:\n");
- while (token != NULL)
- {
- printf("%s\t\t ", token);
- token = strtok(NULL, tok);
- }
- fclose(fpatient);
- }
- }
- printf("\n");
- system("pause");
- }
- void searchpat()
- {
- do
- {
- printf("---------- SEARCH MAIN MENU ----------\n");
- printf("(1)SEARCH PID\n(2)SEARCH NAME\n(3)EXIT PROGRAM\n");
- printf("CHOICE:");
- scanf("%d", &choice);
- switch (choice)
- {
- case 1:
- {
- searchpid();
- break;
- }
- case 2:
- {
- searchname();
- break;
- }
- }
- } while (1 == 1);
- }
- void searchpid()
- {
- int i;
- system("cls");
- fpatient = fopen("TP038123", "r");
- fseek(fpatient, 0L, SEEK_SET);
- for (i = 0; i<100; i++)
- {
- if (strcmp(patientdets.pid, getPatientID()) == 0)
- {
- printf("TRUE");
- }
- else
- {
- printf("FALSE");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement