Advertisement
Guest User

datahipo.c

a guest
Mar 23rd, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.56 KB | None | 0 0
  1. /*
  2.  ============================================================================
  3.  Name        : datahipo.c
  4.  Author      :
  5.  Version     :
  6.  Copyright   : Your copyright notice
  7.  Description :
  8.  ============================================================================
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13.  
  14.  
  15. typedef struct Patient
  16. {
  17.  
  18.     //Increment things with a comma to delimit elements
  19.     //Use a semicolon to do a new line.
  20.     int id;
  21.     char ptnInformation[30];
  22.     //fname,lname,dob,notes;
  23.     char crntPrescriptions[200];
  24.     //medName,dosage,dateFilled;
  25.     char medRecord[200];
  26.     //type,desc,medName,dosage,dateIssued,Note;
  27.     char vtlSigns[200];
  28.     //height,weight,age,bmi,date;
  29.     char smkStatus[1];
  30.     //status(y/n);
  31.     char mdcAllergy[200];
  32.     //medName;
  33.  
  34. }Paitent;
  35.  
  36. //Please for the love of god if you know a better way to do this please do
  37. Paitent readPatient(int id)
  38. {
  39.  
  40.     FILE *infile;
  41.     Paitent temp;
  42.     int tempID;
  43.     int paitentLocation;
  44.     int loopcntr;
  45.  
  46.     //We open the file and check for errors
  47.     infile = fopen("DataHipo.dat","r");
  48.     if(infile == NULL)
  49.     {
  50.         fprintf(stderr, "\nDatabase Error");
  51.         exit(1);
  52.     }
  53.  
  54.     //We look for the location of the patient
  55.     while(!eof(infile) || tempID == id )
  56.     {
  57.         fsetpos(infile,sizeof(Paitent)*loopcntr);
  58.         fscanf(infile,"%d",tempID);
  59.     }
  60.  
  61.     //If it exists we return it.
  62.     if(tempID == id)
  63.         fread(&temp,sizeof(struct Patient),1,infile);
  64.     close(infile);
  65.     return temp;
  66. }
  67.  
  68. void writePatient(int id,struct Paitent johnSmith)
  69. {
  70.  
  71.     FILE *outfile;
  72.     Paitent temp;
  73.     int tempID;
  74.     int paitentLocation;
  75.     int loopcntr;
  76.  
  77.     //We open the file and check for errors
  78.     outfile = fopen("DataHipo.dat","wr");
  79.     if(outfile == NULL)
  80.     {
  81.         fprintf(stderr, "\nDatabase Error");
  82.         exit(1);
  83.     }
  84.  
  85.     //We look for the location of the patient
  86.     while(!eof(outfile) || tempID == id )
  87.     {
  88.         fsetpos(outfile,sizeof(Paitent)*loopcntr);
  89.         fscanf(outfile,"%d",tempID);
  90.     }
  91.  
  92.     //If it exists we write.
  93.     if(tempID == id)
  94.         fwrite(&johnSmith,sizeof(struct Patient),1,outfile);//I'm hoping this writes over the old patient.
  95.     else
  96.     {
  97.         fseek(outfile,0,SEEK_END);
  98.         fwrite(&johnSmith,sizeof(struct Patient),1,outfile);//If patient doesn't exist that means they are new and write eof.
  99.     }
  100.     close(outfile);
  101. }
  102.  
  103. void epatientMenu(struct Patient johnSmith)
  104. {
  105.     char tmp[20];
  106.     char output[120];
  107.     char* fname = strtok(johnSmith->ptnInformation,",");
  108.     char* lname = strtok(johnSmith->ptnInformation,",");
  109.     char* dob = strtok(johnSmith->ptnInformation,",");
  110.     printf("Data Hipo - Doctor Portal\n\nE-Prescription\n\n");
  111.     printf("Patient First Name: %s",fname);
  112.     printf("Patient Last Name: %s", lname);
  113.     printf("Date of Birth (%d)\n",dob);
  114.  
  115.     printf("Drug:");
  116.     scanf("%s",&output);
  117.     printf("Dosage:");
  118.     scanf("%s",&tmp);
  119.     strcat(output,tmp);
  120.     printf("Strength:");
  121.     scanf("%s",&tmp);
  122.     strcat(output,tmp);
  123.     printf("Prescription Length:");
  124.     scanf("%s",&tmp);
  125.     strcat(output,tmp);
  126.     printf("Prescription Quantity:");
  127.     scanf("%s",&tmp);
  128.     strcat(output,tmp);
  129.     printf("Refils(Y/N):");
  130.     scanf("%s",&tmp);
  131.     strcat(output,tmp);
  132.     printf("Directions:");
  133.     scanf("%s",&tmp);
  134.     strcat(output,tmp);
  135.     printf("Notes:");
  136.     scanf("%s",&tmp);
  137.     strcat(output,tmp);
  138.     printf("Pharmacy:");
  139.     scanf("%s",&tmp);
  140.     strcat(output,tmp);
  141.     printf("Doctor Authorizing Prescription:");
  142.     scanf("%s",&tmp);
  143.     strcat(output,tmp);
  144.  
  145.  
  146.     FILE *outfile = fopen("E-Prescription","w");
  147.     if(outfile == NULL)
  148.     {
  149.         fprintf(stderr, "\nWrite to file Error");
  150.         exit(1);
  151.     }
  152.  
  153.     fprintf(outfile,"E-Prescription order for %s,%s\n%s",fname,lname,output);
  154.     close(outfile);
  155. }
  156.  
  157. void activeMedList(struct Patient johnSmith)
  158. {
  159.     char* fname = strtok(johnSmith->ptnInformation,",");
  160.     char* lname = strtok(johnSmith->ptnInformation,",");
  161.     char* dob = strtok(johnSmith->ptnInformation,",");
  162.     char tmp[200];//We copy the string for integrity.
  163.     char output[200];
  164.     char name[15];
  165.     strcpy(tmp,johnSmith->medRecord);
  166.  
  167.     char medRecord[200];
  168.         //type,desc,medName,dosage,dateIssued,Note;
  169.     char* tokenA = strtok(tmp,";");
  170.     while(tokenA)
  171.     {
  172.         char* tokenB = strtok(tokenA,",");//Reads type onto token
  173.         tokenB = strtok(NULL,","); //Reads desc onto token
  174.         name = strtok(NULL,",");//Reads medName onto token
  175.         tokenB = strtok(NULL,",");//Reads dosage onto token
  176.         tokenB = strtok(NULL,",");//Reads dateIssued onto token
  177.         tokenB = strtok(NULL,",");//Reads note onto token
  178.         if(strcmp(tokenB,"Active") != 0)
  179.             strcat(output,name + "\n");
  180.     }
  181.     printf("Data Hipo - Doctor/Nurse\n\nActive Medication List");
  182.     printf("Patient First Name:%s\nPatient Last Name:%s\nPatient Date of Birth:%s\n",fname,lname,dob);
  183.     printf("\nACTIVE MEDICATIONS\n-------------------\n%s",output);
  184.     //function ends
  185. }
  186.  
  187. void doctorMenu(int ptnID)
  188. {
  189.     int userIO = 0;
  190.     int flag = 0;
  191.    struct Patient patient = readPatient(ptnID);
  192.  
  193.     //Menu Options for the a user with doctor privileges.
  194.     printf("Data Hipo - Patient Doctor Portal\n\n");
  195.     printf("Menu: (1) Drug Interaction Checks  (2) Maintain Problem List    (3) E-Prescription\n");
  196.     printf("      (4) Active Medication List   (5) Medication Allergy List  (6) Record Vital Signs\n");
  197.     printf("      (7) Record Smoking Status    (8) Computerized Provider Order Entry (CPOE)\n");
  198.     printf("      (9) Patient Information      (0) Exit\n");
  199.  
  200.     //A quick while loop to verify user input
  201.     while(flag == 0)
  202.     {
  203.         printf("Enter an option from the menu above:");
  204.         scanf("%1d",&userIO);//I limit the user to only entering 1 digit, I also store the input as an int to let me use it in a switch statement.
  205.         if(userIO < 10 && userIO >= 0)//We want our input between 0-9
  206.             flag = 1;
  207.     }
  208.  
  209.     switch(userIO)//Because of simplicity of the cases I felt that a switch statement suited the task
  210.     {
  211.         //Every case just equals a function call to allow easy modularization with other menus
  212.         case(1):
  213.             //Drug Interaction Checks
  214.             //I need to make
  215.             break;
  216.         case(2):
  217.             //Maintain Problem List
  218.             //I need to make
  219.             break;
  220.         case(3):
  221.             epatientMenu(patient);
  222.             break;
  223.         case(4):
  224.             //Active Medacation List
  225.             //from paitent info print all meds that have active in there notes.
  226.             //I need to make
  227.             break;
  228.         case(5):
  229.             //Medication Allergy List
  230.             break;
  231.         case(6):
  232.             //Record Vital Signs
  233.             break;
  234.         case(7):
  235.             //Record Smoking Status
  236.             break;
  237.         case(8):
  238.             //Computerized Provider Order Entry (CPOE)
  239.             //I need to make
  240.             break;
  241.         case(9):
  242.             //Patient Information
  243.             break;
  244.         case(0):
  245.             printf("Exiting.....");
  246.     }
  247. }
  248.  
  249.  
  250. int main(void) {
  251.  
  252.  
  253.     //Variables needed for runtime
  254.     char uname[8];
  255.     char pword[8];
  256.     int patientID;
  257.     int flag = 0;
  258.     Paitent johnSmith;
  259.  
  260.  
  261.     printf("Welcome to Data Hipo - Electronic Medical Record Software (EMS)\n\n\n");
  262.     do
  263.     {
  264.         printf("Please enter your login information.\nUsername:");
  265.         scanf("%8s",uname);
  266.         printf("Password:");
  267.         scanf("%8s",pword);
  268.         printf("Patient#");
  269.         scanf("%5d",patientID);//This will be passed to menu function to load patient info.
  270.  
  271.         if (strcmp(uname, "admin") == 0)
  272.         {
  273.             if (strcmp(pword,"admin!") == 0)
  274.             {
  275.  
  276.                 // run admin menu function
  277.                 //please refer to the SDD for how the functions should operate and what the text should look like
  278.                 /*Create account
  279.                  * Get Number of Accounts
  280.                  * Delete Accounts                   * Write Logs
  281.                  * View Logs
  282.                  */
  283.                 flag = 1;
  284.             }
  285.         }
  286.         else if (strcmp(uname,"doctor") == 0)
  287.         {
  288.             if(strcmp(pword, "doctor!") == 0)
  289.             {
  290.  
  291.                 doctorMenu(0);
  292.                 flag = 1;
  293.             }
  294.         }
  295.         else if (strcmp(uname,"nurse") == 0)
  296.         {
  297.             if(strcmp(pword, "nurse!") == 0)
  298.             {
  299.  
  300.                 //run nurse function
  301.                 //please refer to the SDD for how the functions should operate and what the text should look like
  302.                 /*
  303.                  * Active Mediation List
  304.                  * Patient Information
  305.                  * Record Vital Signs
  306.                  * Record Smoking Status
  307.                  */
  308.                 flag = 1;
  309.             }
  310.         }
  311.         else if (strcmp(uname,"patient") == 0)
  312.         {
  313.             if(strcmp(pword, "patient!") == 0)
  314.             {
  315.                 //run patient function
  316.                 //please refer to the SDD for how the functions should operate and what the text should look like
  317.                 /*
  318.                  *Current Prescriptions
  319.                  * Medical Records
  320.                  * Appointments
  321.                  */
  322.                 flag = 1;
  323.             }
  324.         }
  325.         else
  326.             printf("Invalid username or password.\n");
  327.  
  328.     }while(flag != 1);
  329.  
  330.     printf("Thank you for using Data Hipo\nHave a nice day!");
  331.     return 0;
  332.  
  333. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement