Untitled

 avatar
unknown
plain_text
8 months ago
7.8 kB
15
Indexable
// Raquel Pedraza-Blanco
// 11/12/2024
// CSE 121
// P2 - Prioritizing Patients
// TA: Ronald Lin
// This program asks a medical worker to input some information about the hospital and patient
// in question, and then it will use that information to assign that patient a priority score.
// A higher priority score indicates the patient should be treated as high priority and seen
// sooner than other patients who have lower priority scores.
import java.util.*;

public class PatientPrioritizer {
    public static final int HOSPITAL_ZIP = 12345;

    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);

        String patientName = "";
        int numPatients = 0;
        int maxScore = 0;
        introMessage();

        // Start loop to continuously prompt for patient information.
        while (true) {
        System.out.println("Please enter the next patient's name"
                            + " or \"quit\" to end the program.");
        System.out.print("Patient's name: ");
        patientName = patient(console);
        if(patientName.equals("quit")) {    
            break;
        } else{
            numPatients++;
            int priorityScore = priorityScore(console);
            System.out.print("We have found patient " + patientName 
                            + " to have a priority score of: " );
            System.out.print(priorityScore);
            patientPriority(patientName, priorityScore);
            if(priorityScore > maxScore) {
                maxScore = priorityScore;
            }
            System.out.println();
            System.out.println("Thank you for using our system!");
            System.out.println("We hope we have helped you do your best!");
            System.out.println();
        }
        }
        stats(numPatients, maxScore);
    }

    // This method prints the program's introduction message.
    public static void introMessage() {
        System.out.println("Hello! We value you and your time, so we will help");
        System.out.println("you prioritize which patients to see next!");
        System.out.println("Please answer the following questions about the next patient so");
        System.out.println("we can help you do your best work :)");
        System.out.println();
    }

    // This method gets a patients name through user input by taking one scanner
    // parameter and returning the name read from input.
    public static String patient(Scanner console) {
        String name = console.next();
        return name;
    }

    // This method uses a scanner parameter to collect the required patient information
    // such as the patients age, their zip code, insurance information, pain level
    // and temperature.
    // It then computes the priority score by calling the score method and
    // returns the computed score
    public static int priorityScore(Scanner console) {
        System.out.print("Patient age: ");
        int age = console.nextInt();

        System.out.print("Patient zip code: ");
        int zipCode = console.nextInt();
        while(fiveDigits(zipCode) == false) {
            System.out.print("Invalid zip code, enter valid zip code: ");
            zipCode = console.nextInt();
        }

        System.out.print("Is our hospital \"in network\" for the patient's insurance? ");
        String insurance = console.next();

        System.out.print("Patient pain level (1-10): ");
        int pain = console.nextInt();
        while((pain < 1) || (pain > 10)) {
            System.out.print("Invalid pain level, enter valid pain level (1-10): ");
            pain = console.nextInt();
        }

        System.out.print("Patient temperature (in degrees Fahrenheit): ");
        double temp = console.nextDouble();
        System.out.println();

        int priorityScore = score(age, zipCode, insurance, pain, temp);
        return priorityScore;
    }

    // This method calculates the priority score by adding points based on the patients age (int),
    // zip code (int), whether this hospital is "in network" (String), pain level (int),
    // and their temperature (String).
    // This method then returns the patients total priority score after adding more points.
    public static int score(int age, int zipCode, String insurance, int pain, double temp) {
        int score = 100;

        if((age < 12) || (age >= 75)) {
            score += 50;
        }
        if((zipCode/10000) == (HOSPITAL_ZIP/10000)) {
            score += 25;
            if(((zipCode/10000) == (HOSPITAL_ZIP/10000))/ && 
                ((zipCode/1000) == (HOSPITAL_ZIP/1000))) {
                score += 15;
            }
        }
        if(insurance.equals("y") || insurance.equals("yes")) {
            score += 33;
        }
        if(pain < 7) {
            score = score + pain + 10;
        } else if(pain >= 7) {
          score = score + pain + 70;
          }
        if(temp > 99.5) {
        score += 8;
        }
        return score;
    }

    // Once the priority score is determined, each patient is placed into one of the three
    // different priority groups based on their score (int).
    // So, this method prints whether the patient (String) should be taken care of ASAP, 
    // medium priority, or is put on the waitlist for when a medical provider becomes available.
    public static void patientPriority(String name, int score) {
        String patientName = name;
        int priorityScore = score;
        System.out.println();

        if(priorityScore >= 270){
            System.out.println("We have determined this patient is high priority,");
            System.out.println("and it is advised to call an appropriate medical provider ASAP.");
        } else if((priorityScore >= 164) && (priorityScore < 270)) {
            System.out.println("We have determined this patient is medium priority.");
            System.out.println("Please assign an appropriate medical provider to their case");
            System.out.println("and check back in with the patient's condition "
                                + "in a little while.");
        } else if(priorityScore < 164) {
            System.out.println("We have determined this patient is low priority.");
            System.out.println("Please put them on the waitlist for when a medical provider "
                                + "becomes available.");
        }
    }

    // Determines if the given integer has five digits.
    // Parameters:
    //   - val: the integer whose digits will be counted
    // Returns:
    //   - boolean: true if the given integer has 5 digits, and false otherwise.
    public static boolean fiveDigits(int val) {
        val = val / 10000; // get first digit
        if (val == 0) { // has less than 5 digits
            return false;
        } else if (val / 10 == 0) { // has 5 digits
            return true;
        } else { // has more than 5 digits
            return false; 
        }
        // NOTE: the above can be written with improved "boolean zen" as follows: 
        // return val != 0 && val / 10 == 0;
    }

    // This method prints out the overall statistics for the day by taking in the 
    // number of patients (int) and using the maximum score (int).
    public static void stats(int numPatients, int maxScore) {
        System.out.println("Statistics for the day:");
        System.out.println("..." + numPatients + " patients were helped");
        System.out.println("...the highest priority patient we saw had a score of " + maxScore);
        System.out.println("Good job today!");
    }
}
Editor is loading...
Leave a Comment