Advertisement
Guest User

patientPrioritizer

a guest
Feb 22nd, 2023
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.83 KB | None | 0 0
  1. import java.util.*;
  2. public class PatientPrioritizer {
  3. public static final int HOSPITAL_ZIP = 12345;
  4.  
  5. public static void main(String[] args) {
  6. Scanner console = new Scanner(System.in);
  7.  
  8. //Variable Intialization
  9. int priorityScore = 0;
  10. int patientNum = 0;
  11. String scoreZ = "";
  12.  
  13. welcomeMessage();
  14. String patientName = usersName(console);
  15. while (!patientName.equals("quit")){
  16. patientNum++;
  17. priorityScore = theNums(console, patientName, priorityScore);
  18. scoreZ += priorityScore;
  19. patientName = usersName(console);
  20. } // end of while loop
  21. dailyStatistics(scoreZ, patientNum);
  22. } // end of main method
  23.  
  24. //This method prints out a series of strings to welcome/instruct the user
  25. //Parameters: none
  26. //Return: none
  27. public static void welcomeMessage(){
  28. System.out.println("Hello! We value you and your time, so we will help");
  29. System.out.println("you prioritize which patients to see next!");
  30. System.out.println("Please answer the following questions about the next patient so");
  31. System.out.println("we can help you do your best work :)");
  32. System.out.println();
  33. } // end of welcomeMessage method
  34.  
  35. //This method collects the patient's name or recieves a respone "quit" which quits the program
  36. //Parameters: Scanner console
  37. //Return: String name (also known as patientName)
  38. public static String usersName(Scanner console){
  39. System.out.println("Please enter the next patient\'s name"
  40. + " or \"quit\" to end the program.");
  41. System.out.print("Patient\'s name: ");
  42. String name = console.nextLine();
  43.  
  44. return name;
  45. } // end of usersName method
  46.  
  47. //This method holds & stores user input values for priority score calculation
  48. //Parameters: Scanner Console, String patientName, int priorityScore (final calculation)
  49. //Return: priorityScore (so it can be used in a later method)
  50. public static int theNums(Scanner console, String patientName, int priorityScore){
  51. System.out.print("Patient age: ");
  52. int age = console.nextInt();
  53. System.out.print("Patient zip code: ");
  54. int zipCode = console.nextInt();
  55. boolean five = fiveDigits(zipCode);
  56. while(!five){
  57. zipCode = console.nextInt();
  58. five = fiveDigits(zipCode);
  59. } // end of while loop
  60. System.out.print("Is our hospital \"in network\" for the patient's insurance? ");
  61. String insurance = console.next();
  62. insuranceCheck(insurance);
  63. System.out.print("Patient pain level (1-10): ");
  64. int painLevel = console.nextInt();
  65. boolean pLT = painLevelTest(painLevel);
  66. while(!pLT){
  67. painLevel = console.nextInt();
  68. pLT = painLevelTest(painLevel);
  69. } // end of while loop
  70. System.out.print("Patient temperature (in degrees Fahrenheit): ");
  71. double temperature = console.nextDouble();
  72. console.nextLine();
  73. priorityScore = calculatingPriorityScore(age, zipCode, painLevel,
  74. temperature, insurance, priorityScore);
  75. priorityLevel(patientName, priorityScore);
  76. System.out.println();
  77. System.out.println("Thank you for using our system!");
  78. System.out.println("We hope we have helped you do your best!");
  79. System.out.println();
  80.  
  81. return priorityScore;
  82. } // end of theNums method
  83.  
  84. //This method takes in numerous variables and calculates a score using if statments
  85. /*Parameters: int age, int zipCode, int painLevel,
  86. double temperature, String insurance, int priorityScore*/
  87. //Return: priorityScore (updated through calculations)
  88. public static int calculatingPriorityScore(int age, int zipCode, int painLevel,
  89. double temperature, String insurance,
  90. int priorityScore){
  91. int baseScore = 100;
  92. if(age >= 75 || age < 12){
  93. baseScore += 50;
  94. }
  95. if(HOSPITAL_ZIP/10000 == zipCode/10000){
  96. baseScore += 25;
  97. }
  98. if((HOSPITAL_ZIP/10000 == zipCode/10000) && (HOSPITAL_ZIP/1000 == zipCode/1000)){
  99. baseScore += 15;
  100. }
  101. if(insurance.equals("y") || insurance.equals("yes")){
  102. baseScore += 50;
  103. }
  104. baseScore += (painLevel * 10);
  105. if (temperature > 99.5){
  106. baseScore += 8;
  107. }
  108. priorityScore = baseScore;
  109.  
  110. return priorityScore;
  111. } //end of calculatingPriorityScore method
  112.  
  113.  
  114. //This method prints out the patient's priority and priority level
  115. //Parameters: String patientsName, int priorityScore
  116. //Return: none
  117. public static void priorityLevel(String patientName, int priorityScore){
  118. System.out.print("We have found patient " + patientName);
  119. System.out.println(" to have a priority score of: " + priorityScore);
  120. System.out.print("We have determined this patient is ");
  121.  
  122. if (priorityScore >= 333){
  123. System.out.println("high priority,");
  124. System.out.println("and it is advised to call an appropriate medical provider ASAP.");
  125. }else if (priorityScore < 333 && priorityScore >= 168){
  126. System.out.println("medium priority.");
  127. System.out.println("Please assign an appropriate medical provider to their case");
  128. System.out.println("and check back in with the patient's condition in a little while.");
  129. }else {
  130. System.out.println("low priority.");
  131. System.out.print("Please put them on the waitlist for");
  132. System.out.println(" when a medical provider becomes available.");
  133. }
  134. } // end of priorityLevel method
  135.  
  136. //This method finds the max score and prints out the max & the # of patients
  137. /*Parameters: String scoreZ (priorityScores as a String to run comparisions),
  138. int patientNum (number of patients helped that day)*/
  139. //Return: none
  140. public static void dailyStatistics(String scoreZ, int patientNum){
  141. int scorezLength = scoreZ.length();
  142. int maxPriorityScore = 0;
  143. if(scorezLength != 0){
  144. maxPriorityScore = Integer.valueOf(scoreZ.substring(0,3));
  145. for(int i = 3; i < scorezLength; i += 3){
  146. int otherScore = Integer.valueOf(scoreZ.substring (i, i + 3));
  147. if(maxPriorityScore < otherScore){
  148. maxPriorityScore = otherScore;
  149. } // end of inner if statment
  150. } // end of for loop
  151. } // end of outer if statement
  152. System.out.println("Statistics for the day:");
  153. System.out.println("..." + patientNum + " patients were helped");
  154. System.out.println("...the highest priority patient we saw had a score of "
  155. + maxPriorityScore);
  156. System.out.println("Good job today!");
  157. } // end of dailyStatistics method
  158.  
  159. //This method tests to see if user input, zipCode, is 5 digits or not
  160. //Parameters: int val (the zipCode that the user inputed)
  161. //Return: returns whether or not the zipCode is 5 digits
  162. public static boolean fiveDigits(int val) {
  163. val = val / 10000; // get first digit
  164. if (val == 0) { // has less than 5 digits
  165. System.out.print("Invalid zip code, enter valid zip code: ");
  166. return false;
  167. } else if (val / 10 == 0) { // has 5 digits
  168. return true;
  169. } else { // has more than 5 digits
  170. System.out.print("Invalid zip code, enter valid zip code: ");
  171. return false;
  172. }
  173. } // end of fiveDigits method
  174.  
  175. //This method checks whether or not the painLevel is within the range of 1-10
  176. //Parameters: int val (the painLevel the user inputed)
  177. //Return: returns whether or not the painLevel is within range
  178. public static boolean painLevelTest (int val) {
  179. if (val >= 1 && val <= 10) {
  180. return true;
  181. } else {
  182. System.out.print("Invalid pain level, enter valid pain level (1-10): ");
  183. return false;
  184. }
  185. } // end of painLevelTest method
  186.  
  187. //This method checks to see if the user has insurance or not
  188. //Parameters: String insurance (String-based user input)
  189. //Return: returns whether or not the user has insurance
  190. public static boolean insuranceCheck (String insurance){
  191. if(insurance.equals("yes") || insurance.equals("y")){
  192. return true;
  193. } else
  194. return false;
  195. } // end of insuranceCheck method
  196.  
  197. } // end of public class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement