Advertisement
Guest User

SumViewpat

a guest
May 30th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<string.h>
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #include<ctype.h>
  6. #include<windows.h>
  7.  
  8. struct patient{
  9. char pid[6];
  10. char fname[20];
  11. char lname[20];
  12. char fullname[50];
  13. char gender[2];
  14. char age[3];
  15. char address[30];
  16. char city[20];
  17. char state[20];
  18. char zipcode[6];
  19. char apptype[20];
  20. char doctor[30];
  21. char date[9];
  22. char location[40];
  23. }patientdets, patienttemp;
  24.  
  25. int choice;
  26. FILE *fpatient;
  27. char *token;
  28.  
  29. //MAIN MENU
  30. void menu();
  31. //SUB MENUS
  32. void patmenu();
  33. void appmenu();
  34. //PATIENT MENU
  35. void addpat();
  36. void viewpat();
  37. void searchpat();
  38. void editpat(){};
  39. void deletepat(){};
  40. //SEARCH MENU
  41. void searchpid();
  42. void searchname(){};
  43. char pr_data(struct patient patientdets);
  44. void get_new_item();
  45.  
  46. //APPOINTMENT MENU
  47. void addapp(){};
  48. void viewapp(){};
  49. void searchapp(){};
  50. void editapp(){};
  51. void deleteapp(){};
  52. //STRUCTURE FUNCTIONS
  53. char *getPatientID();
  54.  
  55. COORD coord = { 0, 0 };
  56. void gotoxy(int x, int y)
  57. {
  58. coord.X = x;
  59. coord.Y = y;
  60. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  61. }
  62.  
  63. int main()
  64. {
  65. menu();
  66. }
  67.  
  68. void menu()
  69. {
  70.  
  71. do
  72. {
  73. system("cls");
  74. printf("---------- MAIN MENU ----------\n");
  75. printf("(1)PATIENT\n(2)APPOINTMENT\n(3)EXIT PROGRAM\n");
  76. printf("CHOICE:");
  77. scanf("%d", &choice);
  78. switch (choice)
  79. {
  80. case 1:
  81. {
  82. patmenu();
  83. break;
  84. }
  85. case 2:
  86. {
  87. appmenu();
  88. break;
  89. }
  90. case 3:
  91. {
  92. exit(0);
  93. }
  94. default:
  95. {
  96. printf("PLEASE ENTER A VALID NUMBER!\n");
  97. }
  98. }
  99. } while (1);
  100. }
  101.  
  102. void patmenu()
  103. {
  104. do
  105. {
  106. system("cls");
  107. printf("---------- PATIENT MENU ----------\n");
  108. printf("(1)ADD PATIENT\n(2)VIEW PATIENT\n(3)SEARCH PATIENT\n(4)EDIT PATIENT\n(5)DELETE PATIENT\n(6)RETURN MAIN\n(7)EXIT PROGRAM\n");
  109. printf("CHOICE:");
  110. scanf("%d", &choice);
  111.  
  112. switch (choice)
  113. {
  114. case 1:
  115. {
  116. addpat();
  117. break;
  118. }
  119. case 2:
  120. {
  121. viewpat();
  122. break;
  123. }
  124. case 3:
  125. {
  126. searchpat();
  127. break;
  128. }
  129. case 4:
  130. {
  131. editpat();
  132. break;
  133. }
  134. case 5:
  135. {
  136. deletepat();
  137. break;
  138. }
  139. case 6:
  140. {
  141. return;
  142. }
  143. case 7:
  144. {
  145. exit(0);
  146. }
  147. default:
  148. {
  149. printf("PLEASE ENTER A VALID NUMBER!\n");
  150. }
  151. }
  152. } while (1 == 1);
  153. }
  154.  
  155. void appmenu()
  156. {
  157. system("cls");
  158. int choice;
  159. char pid;
  160. printf("---------- PATIENT MENU ----------\n");
  161. printf("(1)ADD APPOINTMENT\n(2)VIEW APPOINTMENT\n(3)SEARCH APPOINTMENT\n(4)EDIT APPOINTMENT\n(5)DELETE APPOINTMENT\n(6)RETURN MAIN\n(7)EXIT PROGRAM\n");
  162. printf("CHOICE:\n");
  163. scanf("%d", &choice);
  164. while (1 == 1)
  165. {
  166. switch (choice)
  167. {
  168. case 1:
  169. {
  170. addapp();
  171. break;
  172. }
  173. case 2:
  174. {
  175. viewapp();
  176. break;
  177. }
  178. case 3:
  179. {
  180. searchapp();
  181. break;
  182. }
  183. case 4:
  184. {
  185. editapp();
  186. break;
  187. }
  188. case 5:
  189. {
  190. deleteapp();
  191. break;
  192. }
  193. case 6:
  194. {
  195. return;
  196. }
  197. case 7:
  198. {
  199. exit(0);
  200. }
  201.  
  202. }
  203. }
  204. }
  205.  
  206. char *getPatientID()
  207. {
  208. static char pid[6];
  209. printf("Enter Patient ID:\n");
  210. scanf("%s", pid);
  211. return pid;
  212. }
  213.  
  214. char *getFirstName()
  215. {
  216. static char first[20];
  217. printf("Enter First Name:\n");
  218. gets(first);
  219. return first;
  220. }
  221.  
  222. char *getLastName()
  223. {
  224. static char last[20];
  225. printf("Enter Last Name:\n");
  226. gets(last);
  227. return last;
  228. }
  229.  
  230. char *getFullName()
  231. {
  232. static char full[50];
  233. printf("Insert Full name:\n");
  234. gets(full);
  235. return full;
  236. }
  237. char *getGender()
  238. {
  239. static char gender[5];
  240. printf("Enter Gender:\n");
  241. gets(gender);
  242. return gender;
  243. }
  244.  
  245. char *getAge()
  246. {
  247. static char age[3];
  248. printf("Enter Age:\n");
  249. gets(age);
  250. return age;
  251. }
  252.  
  253. char *getAddress()
  254. {
  255. static char address[50];
  256. printf("Enter Address:\n");
  257. gets(address);
  258. return address;
  259. }
  260.  
  261. char *getCity()
  262. {
  263. static char city[10];
  264. printf("Enter City:\n");
  265. gets(city);
  266. return city;
  267. }
  268.  
  269. char *getState()
  270. {
  271. static char state[10];
  272. printf("Enter State:\n");
  273. gets(state);
  274. return state;
  275. }
  276.  
  277. char *getZipcode()
  278. {
  279. static char zipcode[6];
  280. printf("Enter Zipcode:\n");
  281. gets(zipcode);
  282. return zipcode;
  283. }
  284.  
  285. void addpat()
  286. {
  287. int i = 0;
  288. char selection;
  289. char z[30] = " ";
  290. fpatient = fopen("TP038123.txt", "a");
  291.  
  292. if (!fpatient)
  293. {
  294. printf("File does not exists!\n");
  295. }
  296. else
  297. {
  298. system("cls");
  299.  
  300. strcpy(patientdets.pid, getPatientID());
  301. fflush(stdin);
  302. /*strcpy(patientdets.fname, getFirstName());
  303.  
  304. strcpy(patientdets.lname, getLastName());*/
  305. /*strcat(z, patientdets.lname);
  306. strcat(patientdets.fname, z);*/
  307. strcpy(patientdets.fullname, getFullName());
  308. fflush(stdin);
  309. strcpy(patientdets.gender, getGender());
  310. fprintf(fpatient, "%s-->%s-->%s\n", patientdets.pid, patientdets.fullname, patientdets.gender);
  311. fclose(fpatient);
  312. //getch();
  313. }
  314. }
  315.  
  316. void viewpat()
  317. {
  318. system("cls");
  319. int getc(void);
  320. char buffer[1024]="";
  321. char tok[4] = "-->";
  322. char *token;
  323.  
  324. fpatient = fopen("TP038123.txt", "r");
  325.  
  326. if (fpatient == NULL){ //this is to check whether the file exist, this is not exist
  327.  
  328. printf("ERROR:FILE CANNOT BE OPENED!\n");
  329. }
  330. else //this is exist
  331. {
  332. if (feof(fpatient))
  333. {
  334. printf("ERROR:END OF FILE!\n");
  335. fclose(fpatient);
  336. }
  337. else{
  338. fread(&buffer, sizeof(patientdets), 1, fpatient);
  339.  
  340. token = strtok(buffer, tok);
  341.  
  342. printf("Patient ID:\t Fullname:\t Gender:\n");
  343. while (token != NULL)
  344. {
  345. printf("%s\t\t ", token);
  346.  
  347. token = strtok(NULL, tok);
  348. }
  349. fclose(fpatient);
  350. }
  351. }
  352. printf("\n");
  353. system("pause");
  354. }
  355.  
  356. void searchpat()
  357. {
  358. do
  359. {
  360. printf("---------- SEARCH MAIN MENU ----------\n");
  361. printf("(1)SEARCH PID\n(2)SEARCH NAME\n(3)EXIT PROGRAM\n");
  362. printf("CHOICE:");
  363. scanf("%d", &choice);
  364. switch (choice)
  365. {
  366. case 1:
  367. {
  368. searchpid();
  369. break;
  370. }
  371. case 2:
  372. {
  373. searchname();
  374. break;
  375. }
  376. }
  377. } while (1 == 1);
  378. }
  379.  
  380. void searchpid()
  381. {
  382. int i;
  383. system("cls");
  384. fpatient = fopen("TP038123", "r");
  385. fseek(fpatient, 0L, SEEK_SET);
  386. for (i = 0; i<100; i++)
  387. {
  388. if (strcmp(patientdets.pid, getPatientID()) == 0)
  389. {
  390. printf("TRUE");
  391. }
  392. else
  393. {
  394. printf("FALSE");
  395. }
  396. }
  397. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement