Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include<string.h>
- typedef struct node
- {
- char name[50];
- int id;
- int age;
- int cabin;
- char diseases[100];
- char blood[10];
- struct node *next;
- struct node *previous;
- } node;
- node *first,*last,*t;
- void create(int n)
- {
- int i,x;
- first=(node*)malloc(sizeof(node));
- {
- printf("\n\tEnter name:");
- scanf("%s",&first->name);
- printf("\tEnter id:");
- scanf("%d",&first->id);
- printf("\tEnter age:");
- scanf("%d",&first->age);
- printf("\tEnter cabin no:");
- scanf("%d",&first->cabin);
- printf("\tEnter disease:");
- scanf("%s",&first->diseases);
- printf("\tEnter Blood Group:");
- scanf("%s",&first->blood);
- printf("\n\n");
- }
- first->next=NULL;
- first->previous=NULL;
- last=first;
- for(i=1; i<n; i++)
- {
- t=(node*)malloc(sizeof(node));
- printf("\n\tEnter name:");
- scanf("%s",&t->name);
- printf("\tEnter id:");
- scanf("%d",&t->id);
- printf("\tEnter age:");
- scanf("%d",&t->age);
- printf("\tEnter cabin no:");
- scanf("%d",&t->cabin);
- printf("\tEnter disease:");
- scanf("%s",&t->diseases);
- printf("\tEnter Blood Group:");
- scanf("%s",&t->blood);
- printf("\n\n");
- last->next=t;
- t->previous=last;
- t->next=NULL;
- last=t;
- }
- printf("\tDo you want to Save All data?\n\tpress 1 for yes or 2 for no: ");
- scanf("%d",&x);
- if(x==1){
- save_data();
- }
- if(x==2){
- admin_menu();
- }
- }
- void search_id()
- {
- int id, x=0;
- node *p=first;
- printf("\tEnter a ID to search:");
- scanf("%d",&id);
- while(p != NULL)
- {
- if(p->id==id)
- {
- printf("\n\tID IS FOUND!!!!");
- printf("\n\tName:%s\n",p->name);
- printf("\n\tID:%d\n",p->id);
- printf("\n\tAge:%d\n",p->age);
- printf("\n\tCabin No:%d\n",p->cabin);
- printf("\n\tDiseases:%s\n",p->diseases);
- printf("\n\tBlood:%s\n",p->blood);
- x=1;
- break;
- }
- p=p->next;
- }
- if(x==0)
- {
- printf("\n\tID %d is Not Found\n\n",id);
- }
- }
- void search_cabin()
- {
- int cabin, x=0;
- node *p=first;
- printf("\tEnter a Cabin to search:");
- scanf("%d",&cabin);
- while(p != NULL)
- {
- if(p->cabin==cabin)
- {
- printf("\n\tCabin Patient IS FOUND!!!!");
- printf("\n\tName:%s\n",p->name);
- printf("\n\tID:%d\n",p->id);
- printf("\n\tAge:%d\n",p->age);
- printf("\n\tCabin No:%d\n",p->cabin);
- printf("\n\tDiseases:%s\n",p->diseases);
- printf("\n\tBlood:%s\n",p->blood);
- x=1;
- break;
- }
- p=p->next;
- }
- if(x==0)
- {
- printf("\n\tCabin %d is Empty..... \n\n",cabin);
- }
- }
- void displaynode()
- {
- int x;
- node *p=first;
- if(p==NULL)
- {
- printf("\tNO DATABASE IS FOUND\n");
- }
- else
- {
- while (p!=NULL)
- {
- printf("\n\tName:%s\n",p->name);
- printf("\tID:%d\n",p->id);
- printf("\tAge:%d\n",p->age);
- printf("\tCabin No:%d\n",p->cabin);
- printf("\tDiseases:%s\n",p->diseases);
- p=p->next;
- }
- }
- }
- int compare_name(char x[],char y[])
- {
- int i=0;
- while(x[i]!='\0')
- {
- if(x[i]!=y[i])
- return 1;
- i++;
- }
- return 0;
- }
- void search_name()
- {
- node *p=first;
- char name[100];
- printf("\tEnter a name to search:");
- scanf("%s",&name);
- while(p != NULL)
- {
- char x[50];
- strcpy(x,p->name);
- if(compare_name(name,x)==0)
- {
- system("CLS");
- printf("\n\tPatient Information Is Found.....\n\n");
- printf("\tFull Details:\n\n");
- printf("\tName:%s\n",p->name);
- printf("\tID:%d\n",p->id);
- printf("\tAge:%d\n",p->age);
- printf("\tCabin No:%d\n",p->cabin);
- printf("\tDiseases:%s\n\n\n",p->diseases);
- printf("\tBlood:%s\n",p->blood);
- break;
- }
- p=p->next;
- }
- if(p==NULL)
- printf("\tPatient Information Is not Found!!!!!\n\n");
- }
- void record_delete()
- {
- node *p=first,*temp=NULL;
- char name[100];
- printf("\tEnter a name to Delete:");
- scanf("%s",&name);
- while(p != NULL)
- {
- char x[50];
- strcpy(x,p->name);
- if(compare_name(name,x)==0)
- {
- printf("\n\tPatient Information Is Found.....\n\n");
- printf("\tFull Details:\n\n");
- printf("\tName:%s\n",p->name);
- printf("\tID:%d\n",p->id);
- printf("\tAge:%d\n",p->age);
- printf("\tCabin No:%d\n",p->cabin);
- printf("\tDiseases:%s\n\n\n",p->diseases);
- printf("\tBlood:%s\n",p->blood);
- if(temp==NULL)
- {
- first=first->next;
- free(p);
- first->previous=NULL;
- }
- else
- temp->next =p->next;
- if(p->next!=NULL)
- {
- p->next->previous=temp;
- }
- printf("\t%s information is deleted!!!!\n",name);
- free(p);
- main();
- }
- temp = p;
- p = p->next;
- p->previous=temp;
- }
- if(p==NULL)
- printf("\tPatient Information Is not Found!!!!!\n\n");
- }
- int compare_blood(char x[],char y[])
- {
- int i=0;
- while(x[i]!='\0')
- {
- if(x[i]!=y[i])
- return 1;
- i++;
- }
- return 0;
- }
- void search_blood()
- {
- node *p=first;
- char blood[100];
- printf("\tEnter a Blood Group to search:");
- scanf("%s",&blood);
- while(p != NULL)
- {
- char x[50];
- strcpy(x,p->blood);
- if(compare_blood(blood,x)==0)
- {
- system("CLS");
- printf("\n\tBlood Group Is Found.....\n\n");
- printf("\tPatient Details:\n\n");
- printf("\tName:%s\n",p->name);
- printf("\tID:%d\n",p->id);
- printf("\tAge:%d\n",p->age);
- printf("\tCabin No:%d\n",p->cabin);
- printf("\tDiseases:%s\n\n\n",p->diseases);
- printf("\tBlood:%s\n",p->blood);
- break;
- }
- p=p->next;
- }
- if(p==NULL)
- printf("\n\t%s Blood Group Is not Found!!!!!\n\n",blood);
- }
- void record_delete_id()
- {
- node *p=first,*temp=NULL;
- int id;
- printf("\tEnter a Patient Id to Delete:");
- scanf("%d",&id);
- int x = 0;
- while(p != NULL)
- {
- if(p->id==id)
- {
- printf("\n\tPatient Information Is Found.....\n\n");
- printf("\tFull Details:\n\n");
- printf("\tName:%s\n",p->name);
- printf("\tID:%d\n",p->id);
- printf("\tAge:%d\n",p->age);
- printf("\tCabin No:%d\n",p->cabin);
- printf("\tDiseases:%s\n\n\n",p->diseases);
- printf("\tBlood:%s\n",p->blood);
- if(temp==NULL)
- {
- first = first->next;
- first->previous=NULL;
- free(p);
- }
- else
- temp->next = p->next;
- if(p->next!=NULL)
- {
- p->next->previous=temp;
- }
- printf("\t%d is deleted from list\n",id);
- x = 1;
- free(p);
- main();
- }
- temp = p;
- p = p->next;
- p->previous=temp;
- }
- if(x==0)
- printf("\n\tPatient Information Is not Found!!!!!\n\n");
- }
- void bedcount( int x)
- {
- printf("\t%d Beds Are Left",(100-x));
- }
- void otbooking()
- {
- int current=0;
- int total=3;
- int x;
- int i;
- printf("\tDo you want to book? press 1 for yes or 2 for no: ");
- scanf("%d",&x);
- printf("\n\n");
- if(x==1)
- {
- if(current==total)
- {
- printf("\tAll Operation Theater is booked!!!!");
- }
- else
- {
- current++;
- printf("\tYOUR Operation Theater has been booked\n");
- printf("\tTotal OT %d ",total);
- printf("\n\t%d OT are on vacant\n",total-current);
- }
- }
- if(x==2)
- {
- printf("\tYou have take exit from Operation Theater Booking");
- }
- return;
- }
- void save_data()
- {
- struct node *p=first;
- FILE *fp;
- fp=fopen("patient_list.txt","a+");
- while(p)
- {
- fprintf(fp,"\tName :%s\n",p->name);
- fprintf(fp,"\tID :%d\n",p->id);
- fprintf(fp,"\tAge :%d\n",p->age);
- fprintf(fp,"\tCabin :%d\n",p->cabin);
- fprintf(fp,"\tDiseases :%s\n",p->diseases);
- fprintf(fp,"\tBlood Group :%s\n",p->blood);
- fprintf(fp,"\n\n\n");
- p=p->next;
- }
- fclose(fp);
- printf("\n\tData Saved\n\n");
- }
- void history(int n)
- {
- FILE *fp;
- fp=fopen("patient_list.txt","r");
- char Max[1000];
- int totalRead = 0;
- while( fgets(Max,1000, fp) != NULL)
- {
- printf("%s\n", Max);
- }
- fclose(fp);
- return;
- }
- void admin_menu()
- {
- int choice,n=0;
- do
- {
- printf("\n\n\t\t<<<<< Hospital Management System >>>>>\n\n");
- printf("\n\t1.Enter Patient Records");
- printf("\n\t2.Search patient by name");
- printf("\n\t3.Search patient by id");
- printf("\n\t4.Search patient by Cabin No");
- printf("\n\t5.Delete Patient Record");
- printf("\n\t6.Delete Patient Record by id");
- printf("\n\t7.Bed count");
- printf("\n\t8.See patient Record");
- printf("\n\t9.Search Blood");
- printf("\n\t10.Operation Theater Booking");
- printf("\n\t11.All Patient History");
- printf("\n\t12.Delete ALL HISTORY");
- printf("\n\t13.Admin Exit");
- printf("\n");
- printf("\n\n\tSelect Any Option 1-13:");
- scanf("%d",&choice);
- printf("\n");
- switch(choice)
- {
- case 1:
- printf("\tEnter number of Patient Added:");
- scanf("%d",&n);
- printf("\n\n");
- create(n);
- break;
- case 2:
- search_name();
- break;
- case 3:
- search_id();
- break;
- case 4:
- search_cabin();
- break;
- case 5:
- record_delete();
- break;
- case 6:
- record_delete_id();
- break;
- case 7:
- bedcount(n);
- break;
- case 8:
- displaynode();
- break;
- case 9:
- search_blood();
- break;
- case 10:
- otbooking();
- break;
- case 11:
- history(n);
- break;
- case 12:
- erase();
- break;
- }
- }
- while(choice!=13);
- return 0;
- }
- void userbed()
- {
- printf("\t100 Beds Are Available");
- }
- void user()
- {
- int choice;
- printf("\n\n\t\t<<<<< Hospital Management System >>>>>\n\n");
- printf("\n\t1.Search Blood ");
- printf("\n\t2.Search patient by name");
- printf("\n\t3.Available Beds");
- printf("\n\t4.Operation Theater Booking");
- printf("\n\t5.User Exit");
- printf("\n\n\tSelect Any Option 1-5:");
- scanf("%d",&choice);
- printf("\n");
- switch(choice)
- {
- case 1:
- search_blood();
- user();
- break;
- case 2:
- search_name(first);
- user();
- break;
- case 3:
- userbed();
- user();
- break;
- case 4:
- otbooking();
- user();
- break;
- case 5:
- main();
- break;
- }
- }
- void erase()
- {
- system("CLS");
- FILE *old,*newrec;
- old=fopen("patient_list.txt","a+");
- newrec=fopen("new.txt","a+");
- fclose(old);
- fclose(newrec);
- remove("patient_list.txt");
- rename("new.txt","patient_list.txt");
- printf("\tALL FILE IS DELETE FROM HISTORY");
- }
- int main()
- {
- int choice,n;
- printf("\n\n\t\t<<<<< Hospital Management System >>>>>\n\n");
- printf("\n\t1.Admin Login");
- printf("\n\t2.User Login");
- printf("\n\n\tEnter Any Option 1 or 2:");
- scanf("%d",&n);
- printf("\n");
- switch(n)
- {
- case 1:
- admin_menu();
- break;
- case 2:
- user();
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement