Advertisement
SAADQUAMER

Hospital Management Project

Dec 11th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 12.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<string.h>
  4.  
  5.  
  6.  
  7. typedef struct node
  8. {
  9.     char name[50];
  10.     int id;
  11.     int age;
  12.     int cabin;
  13.     char diseases[100];
  14.     char blood[10];
  15.  
  16.     struct node *next;
  17.     struct node *previous;
  18. } node;
  19.  
  20.  
  21.  
  22. node *first,*last,*t;
  23.  
  24. void create(int n)
  25. {
  26.  
  27.     int i,x;
  28.  
  29.  
  30.     first=(node*)malloc(sizeof(node));
  31.     {
  32.  
  33.  
  34.         printf("\n\tEnter name:");
  35.         scanf("%s",&first->name);
  36.         printf("\tEnter id:");
  37.         scanf("%d",&first->id);
  38.         printf("\tEnter age:");
  39.         scanf("%d",&first->age);
  40.         printf("\tEnter cabin no:");
  41.         scanf("%d",&first->cabin);
  42.         printf("\tEnter disease:");
  43.         scanf("%s",&first->diseases);
  44.         printf("\tEnter Blood Group:");
  45.         scanf("%s",&first->blood);
  46.         printf("\n\n");
  47.     }
  48.     first->next=NULL;
  49.     first->previous=NULL;
  50.     last=first;
  51.     for(i=1; i<n; i++)
  52.     {
  53.         t=(node*)malloc(sizeof(node));
  54.  
  55.  
  56.         printf("\n\tEnter name:");
  57.         scanf("%s",&t->name);
  58.         printf("\tEnter id:");
  59.         scanf("%d",&t->id);
  60.         printf("\tEnter age:");
  61.         scanf("%d",&t->age);
  62.         printf("\tEnter cabin no:");
  63.         scanf("%d",&t->cabin);
  64.         printf("\tEnter disease:");
  65.         scanf("%s",&t->diseases);
  66.         printf("\tEnter Blood Group:");
  67.         scanf("%s",&t->blood);
  68.         printf("\n\n");
  69.  
  70.         last->next=t;
  71.         t->previous=last;
  72.         t->next=NULL;
  73.         last=t;
  74.  
  75.  
  76.     }
  77.  
  78.     printf("\tDo you want to Save All data?\n\tpress 1 for yes or 2 for no: ");
  79.     scanf("%d",&x);
  80.     if(x==1){
  81.         save_data();
  82.     }
  83.     if(x==2){
  84.         admin_menu();
  85.     }
  86.  
  87. }
  88.  
  89. void search_id()
  90. {
  91.  
  92.     int id, x=0;
  93.  
  94.     node *p=first;
  95.     printf("\tEnter a ID to search:");
  96.     scanf("%d",&id);
  97.     while(p != NULL)
  98.     {
  99.         if(p->id==id)
  100.         {
  101.             printf("\n\tID IS FOUND!!!!");
  102.             printf("\n\tName:%s\n",p->name);
  103.             printf("\n\tID:%d\n",p->id);
  104.             printf("\n\tAge:%d\n",p->age);
  105.             printf("\n\tCabin No:%d\n",p->cabin);
  106.             printf("\n\tDiseases:%s\n",p->diseases);
  107.             printf("\n\tBlood:%s\n",p->blood);
  108.             x=1;
  109.             break;
  110.         }
  111.         p=p->next;
  112.  
  113.     }
  114.     if(x==0)
  115.     {
  116.         printf("\n\tID %d is  Not Found\n\n",id);
  117.     }
  118.  
  119. }
  120.  
  121.  
  122.  
  123. void search_cabin()
  124. {
  125.  
  126.     int cabin, x=0;
  127.  
  128.     node *p=first;
  129.     printf("\tEnter a Cabin to search:");
  130.     scanf("%d",&cabin);
  131.     while(p != NULL)
  132.     {
  133.         if(p->cabin==cabin)
  134.         {
  135.             printf("\n\tCabin Patient IS FOUND!!!!");
  136.             printf("\n\tName:%s\n",p->name);
  137.             printf("\n\tID:%d\n",p->id);
  138.             printf("\n\tAge:%d\n",p->age);
  139.             printf("\n\tCabin No:%d\n",p->cabin);
  140.             printf("\n\tDiseases:%s\n",p->diseases);
  141.             printf("\n\tBlood:%s\n",p->blood);
  142.             x=1;
  143.             break;
  144.         }
  145.         p=p->next;
  146.  
  147.     }
  148.     if(x==0)
  149.     {
  150.         printf("\n\tCabin %d is Empty..... \n\n",cabin);
  151.     }
  152.  
  153. }
  154. void displaynode()
  155. {
  156.     int x;
  157.     node *p=first;
  158.  
  159.     if(p==NULL)
  160.     {
  161.         printf("\tNO DATABASE IS FOUND\n");
  162.     }
  163.     else
  164.     {
  165.         while (p!=NULL)
  166.         {
  167.             printf("\n\tName:%s\n",p->name);
  168.             printf("\tID:%d\n",p->id);
  169.             printf("\tAge:%d\n",p->age);
  170.             printf("\tCabin No:%d\n",p->cabin);
  171.             printf("\tDiseases:%s\n",p->diseases);
  172.  
  173.             p=p->next;
  174.  
  175.  
  176.         }
  177.  
  178.     }
  179.  
  180.  
  181. }
  182.  
  183. int compare_name(char x[],char y[])
  184. {
  185.     int i=0;
  186.     while(x[i]!='\0')
  187.     {
  188.         if(x[i]!=y[i])
  189.             return 1;
  190.         i++;
  191.     }
  192.     return 0;
  193. }
  194.  
  195. void search_name()
  196. {
  197.     node *p=first;
  198.     char name[100];
  199.     printf("\tEnter a name to search:");
  200.  
  201.     scanf("%s",&name);
  202.  
  203.  
  204.     while(p != NULL)
  205.     {
  206.         char x[50];
  207.         strcpy(x,p->name);
  208.         if(compare_name(name,x)==0)
  209.         {
  210.             system("CLS");
  211.             printf("\n\tPatient Information Is Found.....\n\n");
  212.             printf("\tFull Details:\n\n");
  213.             printf("\tName:%s\n",p->name);
  214.             printf("\tID:%d\n",p->id);
  215.             printf("\tAge:%d\n",p->age);
  216.             printf("\tCabin No:%d\n",p->cabin);
  217.             printf("\tDiseases:%s\n\n\n",p->diseases);
  218.             printf("\tBlood:%s\n",p->blood);
  219.             break;
  220.         }
  221.         p=p->next;
  222.     }
  223.     if(p==NULL)
  224.         printf("\tPatient Information Is not Found!!!!!\n\n");
  225.  
  226. }
  227.  
  228. void record_delete()
  229. {
  230.  
  231.     node *p=first,*temp=NULL;
  232.     char name[100];
  233.     printf("\tEnter a name to Delete:");
  234.  
  235.     scanf("%s",&name);
  236.  
  237.  
  238.     while(p != NULL)
  239.     {
  240.         char x[50];
  241.         strcpy(x,p->name);
  242.         if(compare_name(name,x)==0)
  243.         {
  244.             printf("\n\tPatient Information Is Found.....\n\n");
  245.             printf("\tFull Details:\n\n");
  246.             printf("\tName:%s\n",p->name);
  247.             printf("\tID:%d\n",p->id);
  248.             printf("\tAge:%d\n",p->age);
  249.             printf("\tCabin No:%d\n",p->cabin);
  250.             printf("\tDiseases:%s\n\n\n",p->diseases);
  251.             printf("\tBlood:%s\n",p->blood);
  252.  
  253.             if(temp==NULL)
  254.             {
  255.                 first=first->next;
  256.                 free(p);
  257.                 first->previous=NULL;
  258.  
  259.             }
  260.             else
  261.                 temp->next =p->next;
  262.  
  263.             if(p->next!=NULL)
  264.             {
  265.                 p->next->previous=temp;
  266.             }
  267.  
  268.             printf("\t%s information is deleted!!!!\n",name);
  269.             free(p);
  270.  
  271.             main();
  272.         }
  273.         temp = p;
  274.         p = p->next;
  275.         p->previous=temp;
  276.  
  277.     }
  278.     if(p==NULL)
  279.         printf("\tPatient Information Is not Found!!!!!\n\n");
  280.  
  281. }
  282.  
  283. int compare_blood(char x[],char y[])
  284. {
  285.     int i=0;
  286.     while(x[i]!='\0')
  287.     {
  288.         if(x[i]!=y[i])
  289.             return 1;
  290.         i++;
  291.     }
  292.     return 0;
  293. }
  294. void search_blood()
  295. {
  296.     node *p=first;
  297.     char blood[100];
  298.     printf("\tEnter a Blood Group to search:");
  299.  
  300.     scanf("%s",&blood);
  301.  
  302.  
  303.     while(p != NULL)
  304.     {
  305.         char x[50];
  306.         strcpy(x,p->blood);
  307.         if(compare_blood(blood,x)==0)
  308.         {
  309.             system("CLS");
  310.             printf("\n\tBlood Group Is Found.....\n\n");
  311.             printf("\tPatient Details:\n\n");
  312.             printf("\tName:%s\n",p->name);
  313.             printf("\tID:%d\n",p->id);
  314.             printf("\tAge:%d\n",p->age);
  315.             printf("\tCabin No:%d\n",p->cabin);
  316.             printf("\tDiseases:%s\n\n\n",p->diseases);
  317.             printf("\tBlood:%s\n",p->blood);
  318.             break;
  319.         }
  320.         p=p->next;
  321.     }
  322.     if(p==NULL)
  323.         printf("\n\t%s Blood Group Is not Found!!!!!\n\n",blood);
  324.  
  325. }
  326.  
  327. void record_delete_id()
  328. {
  329.  
  330.     node *p=first,*temp=NULL;
  331.     int id;
  332.     printf("\tEnter a Patient Id to Delete:");
  333.  
  334.     scanf("%d",&id);
  335.  
  336.     int x = 0;
  337.     while(p != NULL)
  338.     {
  339.  
  340.         if(p->id==id)
  341.         {
  342.             printf("\n\tPatient Information Is Found.....\n\n");
  343.             printf("\tFull Details:\n\n");
  344.             printf("\tName:%s\n",p->name);
  345.             printf("\tID:%d\n",p->id);
  346.             printf("\tAge:%d\n",p->age);
  347.             printf("\tCabin No:%d\n",p->cabin);
  348.             printf("\tDiseases:%s\n\n\n",p->diseases);
  349.             printf("\tBlood:%s\n",p->blood);
  350.  
  351.             if(temp==NULL)
  352.             {
  353.                 first = first->next;
  354.                 first->previous=NULL;
  355.                 free(p);
  356.  
  357.             }
  358.             else
  359.                 temp->next = p->next;
  360.  
  361.             if(p->next!=NULL)
  362.             {
  363.                 p->next->previous=temp;
  364.             }
  365.  
  366.             printf("\t%d is deleted from list\n",id);
  367.             x = 1;
  368.             free(p);
  369.             main();
  370.  
  371.         }
  372.         temp = p;
  373.         p = p->next;
  374.         p->previous=temp;
  375.  
  376.     }
  377.     if(x==0)
  378.         printf("\n\tPatient Information Is not Found!!!!!\n\n");
  379.  
  380. }
  381.  
  382.  
  383. void bedcount( int x)
  384. {
  385.  
  386.     printf("\t%d Beds Are Left",(100-x));
  387. }
  388.  
  389. void otbooking()
  390. {
  391.     int current=0;
  392.     int total=3;
  393.  
  394.     int x;
  395.     int i;
  396.     printf("\tDo you want to book? press 1 for yes or 2 for no: ");
  397.     scanf("%d",&x);
  398.  
  399.     printf("\n\n");
  400.  
  401.     if(x==1)
  402.     {
  403.  
  404.         if(current==total)
  405.         {
  406.             printf("\tAll Operation Theater is booked!!!!");
  407.         }
  408.         else
  409.         {
  410.             current++;
  411.             printf("\tYOUR Operation Theater has been booked\n");
  412.             printf("\tTotal OT %d ",total);
  413.             printf("\n\t%d OT  are on vacant\n",total-current);
  414.  
  415.  
  416.  
  417.         }
  418.     }
  419.     if(x==2)
  420.     {
  421.         printf("\tYou have take exit from Operation Theater Booking");
  422.     }
  423.  
  424.     return;
  425. }
  426.  
  427. void save_data()
  428. {
  429.     struct node *p=first;
  430.  
  431.  
  432.     FILE *fp;
  433.     fp=fopen("patient_list.txt","a+");
  434.     while(p)
  435.     {
  436.  
  437.         fprintf(fp,"\tName :%s\n",p->name);
  438.         fprintf(fp,"\tID :%d\n",p->id);
  439.         fprintf(fp,"\tAge :%d\n",p->age);
  440.         fprintf(fp,"\tCabin :%d\n",p->cabin);
  441.         fprintf(fp,"\tDiseases :%s\n",p->diseases);
  442.         fprintf(fp,"\tBlood Group :%s\n",p->blood);
  443.         fprintf(fp,"\n\n\n");
  444.         p=p->next;
  445.     }
  446.     fclose(fp);
  447.     printf("\n\tData Saved\n\n");
  448.  
  449. }
  450.  
  451. void history(int n)
  452. {
  453.  
  454.     FILE    *fp;
  455.     fp=fopen("patient_list.txt","r");
  456.     char Max[1000];
  457.  
  458.     int totalRead = 0;
  459.  
  460.     while( fgets(Max,1000, fp) != NULL)
  461.     {
  462.  
  463.        printf("%s\n", Max);
  464.  
  465.     }
  466.  
  467.     fclose(fp);
  468.  
  469.  
  470.     return;
  471. }
  472.  
  473. void admin_menu()
  474. {
  475.  
  476.     int choice,n=0;
  477.  
  478.  
  479.     do
  480.     {
  481.         printf("\n\n\t\t<<<<< Hospital Management System >>>>>\n\n");
  482.         printf("\n\t1.Enter Patient Records");
  483.         printf("\n\t2.Search patient by name");
  484.         printf("\n\t3.Search patient by id");
  485.         printf("\n\t4.Search patient by Cabin No");
  486.         printf("\n\t5.Delete Patient Record");
  487.         printf("\n\t6.Delete Patient Record by id");
  488.         printf("\n\t7.Bed count");
  489.         printf("\n\t8.See patient Record");
  490.         printf("\n\t9.Search Blood");
  491.         printf("\n\t10.Operation Theater Booking");
  492.         printf("\n\t11.All Patient History");
  493.         printf("\n\t12.Delete ALL HISTORY");
  494.         printf("\n\t13.Admin Exit");
  495.         printf("\n");
  496.  
  497.         printf("\n\n\tSelect Any Option 1-13:");
  498.         scanf("%d",&choice);
  499.         printf("\n");
  500.  
  501.         switch(choice)
  502.         {
  503.         case 1:
  504.             printf("\tEnter number of Patient Added:");
  505.             scanf("%d",&n);
  506.             printf("\n\n");
  507.             create(n);
  508.  
  509.             break;
  510.         case 2:
  511.             search_name();
  512.             break;
  513.         case 3:
  514.             search_id();
  515.             break;
  516.         case 4:
  517.             search_cabin();
  518.             break;
  519.         case 5:
  520.             record_delete();
  521.             break;
  522.         case 6:
  523.             record_delete_id();
  524.             break;
  525.         case 7:
  526.             bedcount(n);
  527.             break;
  528.         case 8:
  529.             displaynode();
  530.             break;
  531.         case 9:
  532.             search_blood();
  533.             break;
  534.         case 10:
  535.             otbooking();
  536.             break;
  537.         case 11:
  538.             history(n);
  539.             break;
  540.         case 12:
  541.             erase();
  542.             break;
  543.  
  544.         }
  545.     }
  546.     while(choice!=13);
  547.     return 0;
  548.  
  549. }
  550. void userbed()
  551. {
  552.     printf("\t100 Beds Are Available");
  553.  
  554. }
  555.  
  556.  
  557. void user()
  558. {
  559.  
  560.     int choice;
  561.     printf("\n\n\t\t<<<<< Hospital Management System >>>>>\n\n");
  562.     printf("\n\t1.Search Blood ");
  563.     printf("\n\t2.Search patient by name");
  564.     printf("\n\t3.Available Beds");
  565.     printf("\n\t4.Operation Theater Booking");
  566.     printf("\n\t5.User Exit");
  567.  
  568.     printf("\n\n\tSelect Any Option 1-5:");
  569.     scanf("%d",&choice);
  570.     printf("\n");
  571.  
  572.     switch(choice)
  573.     {
  574.     case 1:
  575.         search_blood();
  576.         user();
  577.         break;
  578.     case 2:
  579.         search_name(first);
  580.         user();
  581.         break;
  582.     case 3:
  583.         userbed();
  584.         user();
  585.         break;
  586.     case 4:
  587.         otbooking();
  588.         user();
  589.         break;
  590.     case 5:
  591.         main();
  592.         break;
  593.  
  594.  
  595.  
  596.  
  597.  
  598.     }
  599. }
  600.  
  601.  
  602. void erase()
  603. {
  604.     system("CLS");
  605.     FILE *old,*newrec;
  606.     old=fopen("patient_list.txt","a+");
  607.     newrec=fopen("new.txt","a+");
  608.  
  609.  
  610.     fclose(old);
  611.     fclose(newrec);
  612.     remove("patient_list.txt");
  613.     rename("new.txt","patient_list.txt");
  614.  
  615.     printf("\tALL FILE IS DELETE FROM HISTORY");
  616.  
  617.  
  618. }
  619.  
  620. int main()
  621. {
  622.     int choice,n;
  623.  
  624.     printf("\n\n\t\t<<<<< Hospital Management System >>>>>\n\n");
  625.  
  626.  
  627.     printf("\n\t1.Admin Login");
  628.     printf("\n\t2.User Login");
  629.  
  630.     printf("\n\n\tEnter Any Option 1 or 2:");
  631.     scanf("%d",&n);
  632.     printf("\n");
  633.     switch(n)
  634.     {
  635.  
  636.     case 1:
  637.         admin_menu();
  638.         break;
  639.     case 2:
  640.  
  641.         user();
  642.         break;
  643.  
  644.     }
  645.  
  646. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement