HaS5HeM

Clinic Management System

Aug 13th, 2021 (edited)
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.55 KB | None | 0 0
  1. /********************************************
  2.  *         Clinic Management System         *
  3.  *          Author: Mahmoud Hashem          *
  4.  *              Version: v0.1               *
  5.  ********************************************/
  6.  
  7. /* Headers */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. /* Defining Data types used */
  12. typedef unsigned char u8;       // 1 byte  unsigned char     variable %c
  13. typedef signed char s8;         // 1 byte  signed   char     variable %c
  14.  
  15. typedef unsigned short u16;     // 2 bytes unsigned integer  variable %hu
  16. typedef signed short s16;       // 2 bytes signed   integer  variable %hd
  17.  
  18. typedef unsigned long u32;      // 4 bytes unsigned integer  variable %lu
  19. typedef signed long s32;        // 4 bytes signed   integer  variable %ld
  20.  
  21. typedef unsigned long long u64; // 8 bytes unsigned integer  variable %llu
  22. typedef signed long long s64;   // 8 bytes signed   integer  variable %lld
  23.  
  24. typedef float f32;              // 4 bytes signed   floating variable %f
  25. typedef double f64;             // 8 bytes signed   floating variable %lf
  26.  
  27. #define STRING_MAX_LENGTH 127
  28.  
  29. void modeSelect(void);  // Mode select function         DONE
  30. void checkAdmin(void);  // Check admin mode password    DONE
  31. void userMode(void);    // User mode function           TODO
  32. void adminMode(void);   // Admin mode function          TODO
  33. void getData(void);     // Get patient data             TODO
  34. void addPatient(void);  // Function too add patients    TODO
  35. void checkID(u8 ID);    // Check if ID exists           TODO
  36. void editPatient(void); // Edit patient record          TODO
  37. void manageSlot(void);  // Reserve or cancel a slot     TODO
  38. u8 scanChoice(void);    // Scanf admin choice           DONE
  39.  
  40. void writeToFile(u16 id, s8 *name, u8 age, s8 *gender);
  41.  
  42. typedef struct patient patient; // Declaring structure of patient
  43.  
  44. struct patient {
  45.     u16 id;
  46.     s8 name[STRING_MAX_LENGTH];
  47.     u16 age;
  48.     s8 gender[STRING_MAX_LENGTH];
  49.     patient *link;
  50. };
  51.  
  52. patient *head;
  53.  
  54. /* Main */
  55. int main() {
  56.     printf("*****************************************\n"
  57.            "*\t\tWELCOME TO\t\t*\n"
  58.            "*\tClinic Management System v1.0\t*\n"
  59.            "*****************************************\n");
  60.     modeSelect();
  61.  
  62.     return 0;
  63. }
  64. void modeSelect() {
  65.     printf("*\tFor admin mode, Enter 1\t\t*\n"
  66.            "*\tFor user mode, Enter 2\t\t*\n"
  67.            "*\tTo exit, Enter 3\t\t*\n"
  68.            "*****************************************\n");
  69.  
  70.     u8 mode;
  71.     printf("Your choice:");
  72.     scanf("%c", &mode);
  73.     if (mode == '1') adminMode();
  74.     /*else if (mode == '2');
  75.     else if (mode == '3') exit(0);
  76.     else {
  77.         printf("Please use the options given, Try again...");
  78.         modeSelect();
  79.     }*/
  80. }
  81.  
  82. void checkAdmin() {
  83.     u8 i = '2';
  84.     u16 pass;
  85.     printf("\nPlease enter the password to enter admin mode\nPassword:");
  86.     while (1) {
  87.         scanf("%hu", &pass);
  88.         if (pass == 1234) return;
  89.         else if (i == '0') {
  90.             printf("You have no remaining trails! Exiting the program...");
  91.             exit(0);
  92.         } else
  93.             printf("Incorrect password!\nYou have remaining %c trails\nEnter the password:", i);
  94.         i--;
  95.     }
  96. }
  97.  
  98. void adminMode() {
  99.     printf("+-----------------------------------------------+\n"
  100.            "|\tWelcome To Admin Mode\t\t\t|\n"
  101.            "|\tYou here can edit, add patient\t\t|\n"
  102.            "|\trecords, reserve and cancel slots\t|\n"
  103.            "|\tPlease enter the password.\t\t|\n"
  104.            "+-----------------------------------------------+\n"
  105.     );
  106.     checkAdmin();
  107.     printf("+-------------------------------------------------------+\n"
  108.            "|\tTo add a new patient, Enter 1\t\t\t+\n"
  109.            "|\tTo edit a patient record, Enter 2\t\t+\n"
  110.            "|\tTo reserve a slot with the doctor, or\t\t+\n"
  111.            "|\tto cancel a reservation, Enter 3\t\t+\n"
  112.            "+-------------------------------------------------------+\n"
  113.     );
  114.     u8 choice = '1';
  115.     printf("Your choice: ");
  116.     scanf(" %c", &choice);
  117.     if (choice == '1') addPatient();
  118.     /*else if (choice == 2) editPatient();
  119.     else if (choice == 3) manageSlot();*/
  120. }
  121.  
  122. u16 NUMBER_OF_PATIENTS = 0;
  123. u8 FIRST_NODE = 0;
  124.  
  125. void addPatient() {
  126.     patient *ptr, *temp;
  127.     ptr = head;
  128.     printf("Enter patient data\n");
  129.     temp = (patient*) malloc(sizeof(patient));
  130.     if (FIRST_NODE == 0) {
  131.         printf("aaEnter patient ID: ");
  132.         scanf(" %hu", &temp->id);
  133.         printf("\nEnter patient name: ");
  134.         scanf(" %[^\n]s", temp->name);
  135.         printf("\nEnter patient age: ");
  136.         scanf(" %hu", &temp->age);
  137.         printf("\nEnter patient gender: ");
  138.         scanf(" %s", temp->gender);
  139.         temp->link = NULL;
  140.         writeToFile(temp->id, temp->name, temp->age, temp->gender);
  141.         head = temp;
  142.         FIRST_NODE = 1;
  143.     }
  144.  
  145.     else {
  146.         printf("ssEnter patient ID: ");
  147.         scanf(" %hu", &temp->id);
  148.         printf("Enter patient name: ");
  149.         scanf(" %[^\n]s", temp->name);
  150.         printf("Enter patient age: ");
  151.         scanf(" %hu", &temp->age);
  152.         printf("Enter patient gender: ");
  153.         scanf(" %s", temp->gender);
  154.         writeToFile(temp->id, temp->name, temp->age, temp->gender);
  155.         temp->link = NULL;
  156.         while (ptr->link != NULL) {
  157.             ptr = ptr -> link;
  158.         }
  159.         ptr -> link = temp;
  160.     }
  161. }
  162.  
  163. void writeToFile(u16 id, s8 *name, u8 age, s8 *gender) {
  164.     FILE *fp = fopen("patients.txt", "w");
  165.     fprintf(fp, "%hu\t%s\t%hu\t%s\n", id, name, age, gender);
  166. }
  167.  
  168.  
Add Comment
Please, Sign In to add comment