Advertisement
ak02

HOSTO.c

May 26th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.50 KB | None | 0 0
  1. #include "hosto.h"
  2.  
  3. /* Creation d'une nouvelle liste */
  4. List new_list(void)        
  5. {
  6.     return NULL;
  7. }
  8.  
  9. ListMedecin new_ListOf_Medecine(void)
  10. {
  11.     return NULL;
  12. }
  13.  
  14. /*---------------------------------------------------------*/
  15. /* Verification si la liste est vide ou non */
  16.  
  17. Bool is_empty_list_Of_Medecine(ListMedecin mylist)
  18. {
  19.     if (mylist == NULL)
  20.         return true;
  21.  
  22.     return false;
  23. }
  24.  
  25. Bool is_empty_list(List mylist)
  26. {
  27.     if (mylist == NULL)
  28.         return true;
  29.  
  30.     return false;
  31. }
  32.  
  33. Bool salle_vide(void)
  34. {
  35.     if (premiere == NULL && derniere == NULL)
  36.         return true;
  37.  
  38.     return false;
  39. }
  40.  
  41. /* GESTIONS DES SALLES */
  42. /* Créer une salle*/
  43. void occuper_une_salle(Lit p)
  44. {
  45.     Salle *disponible;
  46.  
  47.     disponible = malloc(sizeof(*disponible));
  48.  
  49.     if (disponible == NULL)
  50.     {
  51.         fprintf(stderr,"Error : allocation echouee %s %d\n", __FILE__, __LINE__);
  52.         exit(EXIT_FAILURE);
  53.     }
  54.  
  55.     disponible->nombreDeLit.nbLit = p.nbLit;
  56.     disponible->nombreDeLit.uniteDeSoin = p.uniteDeSoin;
  57.     disponible->next = NULL;
  58.  
  59.     if (salle_vide())
  60.     {
  61.         premiere = disponible;
  62.         derniere = disponible;
  63.     }
  64.     else
  65.     {
  66.         derniere->next = disponible;
  67.         derniere = disponible;
  68.     }
  69.  
  70.     nb_salle++;
  71. }
  72.  
  73. /* Vider une salle */
  74. void vider_une_salle(void)
  75. {
  76.     if (salle_vide())
  77.     {
  78.         return;
  79.     }
  80.  
  81.     Salle *tmp = premiere;
  82.  
  83.     if (premiere == derniere)
  84.     {
  85.         premiere = NULL;
  86.         derniere = NULL;
  87.     }
  88.     else
  89.         premiere = premiere->next;
  90.  
  91.     free(tmp);
  92.  
  93.     tmp = NULL;
  94.  
  95.     nb_salle--;
  96. }
  97.  
  98. /* Afficher les salles */
  99. void lister_les_salles(void)
  100. {
  101.     if (salle_vide())
  102.     {
  103.         printf("Les salles sont vides\n");
  104.         return;
  105.     }
  106.  
  107.     Salle *tmp = premiere;
  108.  
  109.     while(tmp != NULL)
  110.     {
  111.         printf("[lit] : %d\n", tmp->nombreDeLit.nbLit);
  112.         printf("[Unite de soin] : %d\n", tmp->nombreDeLit.uniteDeSoin);
  113.         tmp = tmp->next;
  114.     }
  115.     puts("");
  116. }
  117.  
  118. /* Fermer les salles */
  119. void fermer_les_salles(void)
  120. {
  121.     if (salle_vide())
  122.     {
  123.         exit(1);
  124.     }
  125.  
  126.     while(salle_vide())
  127.         vider_une_salle();
  128. }
  129.  
  130. /* Nombre de salle*/
  131. int nombre_salle(void)
  132. {
  133.     return nb_salle;
  134. }
  135.  
  136. /*---------------------------------------------------------*/
  137. /* Affichage de la liste de patients */
  138.  
  139. void print_list(List mylist)
  140. {
  141.     if (is_empty_list(mylist))
  142.     {
  143.         printf("Rien a afficher\n");
  144.         return;
  145.     }
  146.  
  147.     temps();
  148.     while(mylist != NULL)
  149.     {
  150.         printf("[Patient]------------------------------------------------------\n");
  151.         puts("");
  152.         printf("[Numero d\'admission]      : %s\n", mylist->patient.num);
  153.         printf("[Nom]     : %s\t\t\t", mylist->patient.name);
  154.         printf("[Prenom] : %s\n", mylist->patient.surname);
  155.         printf("[Date de naissance] : %02d/%02d/%02d\t", mylist->patient.birthDate, mylist->patient.birthMonth, mylist->patient.birthYear);
  156.         printf("[S matrimoniale] : %s\n", mylist->patient.maritalSituation);
  157.         puts("");
  158.         printf("[Contact]-------------------------------------------------------\n");
  159.         puts("");
  160.         printf("[Telephone]   : %s\t\t", mylist->patient.phone);
  161.         printf("[Adresse] : %s\n", mylist->patient.address);
  162.         puts("");
  163.         mylist = mylist->next;
  164.  
  165.         printf("\n---------------------------------------------------------------\n");
  166.         puts("");
  167.     }
  168.     printf("\n");
  169. }
  170.  
  171. /*---------------------------------------------------------*/
  172. /* Ajout de patients */
  173.  
  174. List addPatient(List mylist, Sick patient)
  175. {
  176.     ListElement *element;
  177.  
  178.     element = malloc(sizeof(*element));
  179.  
  180.     if (element == NULL)
  181.     {
  182.         fprintf(stderr,"Error : allocation echouee %s %d\n", __FILE__, __LINE__);
  183.         exit(EXIT_FAILURE);
  184.     }
  185.  
  186.     strcpy(element->patient.num, patient.num);
  187.     strcpy(element->patient.name, patient.name);
  188.     strcpy(element->patient.surname, patient.surname);
  189.     strcpy(element->patient.address, patient.address);
  190.     strcpy(element->patient.maritalSituation, patient.maritalSituation);
  191.     strcpy(element->patient.phone, patient.phone);
  192.     element->patient.birthDate = patient.birthDate;
  193.     element->patient.birthMonth = patient.birthMonth;
  194.     element->patient.birthYear = patient.birthYear;
  195.     //element->patient.unity = patient.unity;
  196.  
  197.     if (is_empty_list(mylist))
  198.     {
  199.         element->next = NULL;
  200.     }
  201.     else
  202.         element->next = mylist;
  203.  
  204.     return element;
  205. }
  206.  
  207. /*---------------------------------------------------------*/
  208. /* Nombre de patient */
  209.  
  210. int length(List mylist)
  211. {
  212.     int size = 0;
  213.  
  214.     if (is_empty_list(mylist))
  215.         return size;
  216.  
  217.     while(mylist != NULL)
  218.     {
  219.         ++size;
  220.         mylist = mylist->next;
  221.     }
  222.  
  223.     return size;
  224. }
  225.  
  226. /*---------------------------------------------------------*/
  227. /* Supprimer un patient */
  228.  
  229. List deletePatient(List mylist)
  230. {
  231.     ListElement *element;
  232.  
  233.     if (is_empty_list(mylist))
  234.     {
  235.         return new_list();
  236.     }
  237.     else
  238.         element = mylist->next;
  239.  
  240.     free(mylist);
  241.     mylist = NULL;
  242.  
  243.     return element;
  244.  
  245. }
  246.  
  247. /*--------------------------------------------------------------------*/
  248. /* Ajouter un docteur*/
  249.  
  250. ListMedecin addDoctor(ListMedecin mylist, Medecin doctor)
  251. {
  252.     Pile *element;
  253.  
  254.     element = malloc(sizeof(*element));
  255.  
  256.     if (element == NULL)
  257.     {
  258.         fprintf(stderr,"Error : allocation echouee %s %d\n", __FILE__, __LINE__);
  259.         exit(EXIT_FAILURE);
  260.     }
  261.  
  262.     element->liste.numID = doctor.numID;
  263.     strcpy(element->liste.name, doctor.name);
  264.     strcpy(element->liste.surname, doctor.surname);
  265.     strcpy(element->liste.speciality, doctor.speciality);
  266.     strcpy(element->liste.phone, doctor.phone);
  267.     element->next = mylist;
  268.  
  269.     return element;
  270. }
  271.  
  272. /*---------------------------------------------------------------------*/
  273. /*Afficher la liste des docteurs*/
  274.  
  275. void ListDoctor(ListMedecin mylist)
  276. {
  277.     if (is_empty_list_Of_Medecine(mylist))
  278.     {
  279.         printf("Aucun docteur present\n");
  280.         return;
  281.     }
  282.  
  283.     while(!is_empty_list_Of_Medecine(mylist))
  284.     {
  285.         //printf("%d\n", mylist->liste.numID);
  286.         printf("[Medecin traitant]-------------------------------------------\n");
  287.  
  288.         printf("[Nom]    : %s\t\t\t", mylist->liste.name);
  289.         printf("[Prenom] : %s\n", mylist->liste.surname);
  290.         printf("[Specialite] : %s\t\t", mylist->liste.speciality);
  291.         printf("[Telephone] : %s\n", mylist->liste.phone);
  292.         puts("");
  293.         printf("-------------------------------------------------------------\n");
  294.         puts("");
  295.         mylist = mylist->next;
  296.     }
  297.     printf("\n");
  298. }
  299.  
  300. /*---------------------------------------------------------------------*/
  301. /*Nombre de docteurs disponibles*/
  302.  
  303. int doctorNumber(ListMedecin mylist)
  304. {
  305.     int size = 0;
  306.  
  307.     if (is_empty_list_Of_Medecine(mylist))
  308.         return size;
  309.  
  310.     while(!is_empty_list_Of_Medecine(mylist))
  311.     {
  312.         ++size;
  313.         mylist = mylist->next;
  314.     }
  315.  
  316.     return size;
  317. }
  318.  
  319. /*---------------------------------------------------------------------*/
  320. /* Licencier un docteur (C'est à dire le supprimer)*/
  321.  
  322. ListMedecin deleteDoctor(ListMedecin mylist)
  323. {
  324.     Pile *element;
  325.  
  326.     element = malloc(sizeof(*element));
  327.  
  328.     if (element == NULL)
  329.     {
  330.         fprintf(stderr,"allocation echouee %s %d\n", __FILE__, __LINE__);
  331.         exit(EXIT_FAILURE);
  332.     }
  333.  
  334.     if (is_empty_list_Of_Medecine(mylist))
  335.     {
  336.         return new_ListOf_Medecine();
  337.     }
  338.  
  339.     element = mylist->next;
  340.  
  341.     free(mylist);
  342.     mylist = NULL;
  343.  
  344.     return deleteDoctor(element);
  345. }
  346.  
  347. ListMedecin pop_doctor(ListMedecin mylist)
  348. {
  349.     Pile *element;
  350.  
  351.     if (is_empty_list_Of_Medecine(mylist))
  352.     {
  353.         return new_ListOf_Medecine();
  354.     }
  355.  
  356.     element = mylist->next;
  357.  
  358.     free(mylist);
  359.  
  360.     return element;
  361. }
  362.  
  363. void medecin(void)
  364. {
  365.     ListMedecin medecin = new_ListOf_Medecine();
  366.     Medecin infoMedecin0 = {1, "Bernard", "Gabriel", "+33 3 45 29 30 21", "Radiologue"};
  367.     Medecin infoMedecin1 = {2, "Martin", "Raphael", "+33 1 03 15 67 99", "Cardiologue"};
  368.     Medecin infoMedecin2 = {3, "Dubois", "Arthur", "+33 9 82 49 20 11", "Chirurgien"};
  369.     Medecin infoMedecin3 = {4, "Keita", "Abdul Kabir", "+33 8 03 77 20", "Neurologue"};
  370.     Medecin infoMedecin4 = {5, "Leroy", "Camille", "+33 4 29 44 72", "Odontologue"};
  371.     Medecin infoMedecin5 = {6, "Garcia", "Sarah", "+33 0 48 71 09", "Medecin generaliste"};
  372.     Medecin infoMedecin6 = {7, "Martinez", "Charlotte", "+33 6 88 91 05", "Psychiatre"};
  373.  
  374.     medecin = addDoctor(medecin, infoMedecin0);
  375.     medecin = addDoctor(medecin, infoMedecin1);
  376.     medecin = addDoctor(medecin, infoMedecin2);
  377.     medecin = addDoctor(medecin, infoMedecin3);
  378.     //medecin = pop_doctor(medecin);
  379.     medecin = addDoctor(medecin, infoMedecin4);
  380.     medecin = addDoctor(medecin, infoMedecin5);
  381.     medecin = addDoctor(medecin, infoMedecin6);
  382.  
  383.     puts("");
  384.     ListDoctor(medecin);
  385.     //printf("Medecin diponible %d\n", doctorNumber(medecin));
  386.  
  387.     medecin = deleteDoctor(medecin);
  388. }
  389.  
  390. void patient(void)
  391. {
  392.     List malade = new_list();
  393.    
  394.     int size = 0;
  395.     Sick *patient;
  396.     int i = 0;
  397.     puts("");
  398.     system("cls");
  399.     //timer();
  400.     temps();
  401.     puts("");
  402.     printf("\t\t\t[CENTRE HOSPATALIER UNIVERSITAIRE STEEVE]\n\n");
  403.  
  404.     printf("Liste de patient\n");
  405.     scanf("%d", &size);
  406.  
  407.     patient = (Sick *)malloc(size * sizeof(Sick));
  408.  
  409.     if (patient == NULL)
  410.     {
  411.         fprintf(stderr,"Error : Allocation echouee %s %d\n", __FILE__, __LINE__);
  412.         exit(EXIT_FAILURE);
  413.     }
  414.  
  415.     for (int i = 0; i < size; ++i)
  416.     {
  417.         printf("ID : ");
  418.         scanf("%s", (patient + i)->num);
  419.         printf("Name : ");
  420.         scanf("%s", (patient + i )->name);
  421.         printf("Surname : ");
  422.         scanf("%s", (patient + i )->surname);
  423.         printf("Marital Situation : ");
  424.         scanf("%s", (patient + i)->maritalSituation);
  425.         printf("Birth date : ");
  426.         scanf("%d", &(patient + i)->birthDate);
  427.         scanf("%d", &(patient + i)->birthMonth);
  428.         scanf("%d", &(patient + i)->birthYear);
  429.         printf("Phone : ");
  430.         scanf("%s", (patient + i )->phone);
  431.         printf("Address : ");
  432.         scanf("%s", (patient + i )->address);
  433.         puts("");
  434.  
  435.         malade = addPatient(malade, patient[i]);
  436.     }
  437.  
  438.     system("cls");
  439.     puts("");
  440.     print_list(malade);
  441.     printf("patients admis %d\n", length(malade));
  442.  
  443.     malade = deletePatient(malade);
  444. }
  445.  
  446. void temps(void)
  447. {
  448.     char format[128];
  449.     time_t temps;
  450.     struct tm date;
  451.  
  452.     // On récupère la date et l'heure actuelles.
  453.     time(&temps);
  454.     date=*localtime(&temps);
  455.  
  456.     // On remplit la chaîne avec le format choisi, puis on l'affiche.
  457.     strftime(format, 128, "%a %x\n%X %Z\n", &date);
  458.     puts("");
  459.     puts(format);
  460. }
  461.  
  462. int soin(int choix)
  463. {
  464.     puts("");
  465.  
  466.     printf("1\tCardiologie\n");
  467.     printf("2\tNeurologie\n");
  468.     printf("3\tOdontologie\n");
  469.     printf("4\tRadiologie\n");
  470.     printf("5\tPsychiatrie\n");
  471.     printf("6\tGeneraliste\n");
  472.     printf("7\tChirurgie\n");
  473.  
  474.     scanf("%d", &choix);
  475.  
  476.     do
  477.     {
  478.         switch(choix)
  479.         {
  480.             case 1:
  481.             {
  482.  
  483.             }
  484.             break;
  485.  
  486.             case 2:
  487.             {
  488.  
  489.             }
  490.             break;
  491.  
  492.             case 3:
  493.             {
  494.  
  495.             }
  496.             break;
  497.  
  498.             case 4:
  499.             {
  500.  
  501.             }
  502.             break;
  503.  
  504.             case 5:
  505.             {
  506.  
  507.             }
  508.             break;
  509.  
  510.             case 6:
  511.             {
  512.  
  513.             }
  514.             break;
  515.  
  516.             case 7:
  517.             {
  518.  
  519.             }
  520.             break;
  521.  
  522.             default:
  523.                 printf("Faites un bon choix svp !!!\n");
  524.                 break;
  525.         }
  526.     }while(choix != 7);
  527. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement