Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hospital emergency room assign patient priority base on symptom of the patient.

ID: 3810065 • Letter: H

Question

Hospital emergency room assign patient priority base on symptom of the patient. Each patient receives an identity number which prioritizes the order of emergency for the patient. The lower the number is, the higher the emergency will be.
Use java.util.PriorityQueue to write a java program to create the emergency room registration database. The patient.txt is the input file for patient record. Download patient.txt, Patient.java to perform following specifications:
Load all records from the input file.
At the end, print the list in assigned priority order.

Patient.java

//*******************************************************************
// Patient.java
//*******************************************************************

public class Patient
{
private int id;
private String name;
private String emergencyCase;

//----------------------------------------------------------------
// Creates a customer with the specified id number.
//----------------------------------------------------------------
public Patient (int number, String custName,String er )
{
id = number;
name = custName;
emergencyCase = er;
}

//----------------------------------------------------------------
// Returns a string description of this customer.
//----------------------------------------------------------------
public String toString()
{
return "Patient priority id: " + id+" Patient name: "+name+" Symptom: "+emergencyCase;
}

public String getName()
{
return name;
}

public int getId()
{
return id;
}

public String getCase()
{
return emergencyCase;
}

}

patient.txt

10,Sam,Bleeding
02,Carla,Stroke
92,Woody,Flu
11,Diane,High-temperature
32,Norm,Stomach
55,Cliff,Broken-bone
06,Tom,Gun-wounds
22,Kristen,Pregnancy

Explanation / Answer

public class Patient {
   private int patientId;
   private String patientName;
   private String emergencyCase;

   public Patient(int patientId, String patientName, String emergencyCase) {
       super();
       this.patientId = patientId;
       this.patientName = patientName;
       this.emergencyCase = emergencyCase;
   }

   public int getPatientId() {
       return patientId;
   }

   public void setPatientId(int patientId) {
       this.patientId = patientId;
   }

   public String getPatientName() {
       return patientName;
   }

   public void setPatientName(String patientName) {
       this.patientName = patientName;
   }

   public String getEmergencyCase() {
       return emergencyCase;
   }

   public void setEmergencyCase(String emergencyCase) {
       this.emergencyCase = emergencyCase;
   }

   public String toString() {
       return "Patient [patientId=" + patientId + ", patientName="
               + patientName + ", emergencyCase=" + emergencyCase + "]";
   }

}


-------------------------------------------------------------------------------------

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;

class PatientComparator implements Comparator<Patient> {

   public int compare(Patient arg0, Patient arg1) {
       if (arg0.getPatientId() > arg1.getPatientId())
           return 1;
       else if (arg0.getPatientId() < arg1.getPatientId())
           return -1;
       else
           return 0;
   }

}

public class HospitalRegistration {

   public static void main(String[] args) {
       BufferedReader br = null;
       String line = "";
       Queue<Patient> patientQueue = new PriorityQueue<Patient>(10,
               new PatientComparator());
       try {
           br = new BufferedReader(new FileReader(new File(
                   "C:/Users/aditya/Desktop/patient.txt")));
           while ((line = br.readLine()) != null) {
               String[] patientDetails = line.split(",");
               // Create a new Patient object
               Patient patient = new Patient(
                       Integer.parseInt(patientDetails[0]), patientDetails[1],
                       patientDetails[2]);
               patientQueue.add(patient);

           }

       } catch (FileNotFoundException e) {
           e.printStackTrace();
       } catch (IOException e) {
           e.printStackTrace();
       } finally {
           try {
               br.close();
           } catch (IOException e) {
               e.printStackTrace();
           }
       }
       System.out.println("patientQueue.size()::::" + patientQueue.size());
       // printing the list in assigned priority order
       while (patientQueue.size() > 0) {
           Patient sortedPatient = patientQueue.poll();
           System.out.println(sortedPatient);
       }

   }

}