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

Objectives » To understand priority queues . To understand triage in a hospital

ID: 3769018 • Letter: O

Question

Objectives » To understand priority queues . To understand triage in a hospital emergency room Instructions For this assignment you are to write a simulator that will simulate a triage situation, taking input fronm In the file, you will have the following format: FName LName TriageCode Where FName is the patient's first name, LName is the patient's last name, and TriageCode is a two letter code indicating the injury or illness. To determine the meaning of the code or the severity of the illness or injury in terms of degree of pain or threat to survival, use the following chart (which includes the priority from 1 to 3, 1 being the most urgent) Priority Code AL HA ST BL IW KS OT HN Meaning Amputated limb or digit Heart attack Stroke Broken leg Infected wound (abscess) Kidney stones Other/Unknown Hangnail 1

Explanation / Answer

working java code.

I have created the queue and the triage implementation in java.

Basically there are 5 priorities for the person name and the code is corresponding to that.

The priorities can range from 1 to 5 with 1 being most important and 5 being least. The priority works in the same order of the priorities in the code. I have made a java gui for the same.

Working java code:

import jdsl.core.api.*;
import java.awt.*;
import java.awt.event.*;

public class Triage extends Frame
implements ActionListener,WindowListener{


public Triage(){
super();
pq_ = new jdsl.core.ref.ArrayHeap(new jdsl.core.ref.IntegerComparator());
setupPanel();
}

protected void enterPatient(){
Object element = name_field_.getText();
int priority = java.lang.Integer.parseInt(priority_bot.getSelectedItem(), 10);
   // key for the queue
Object key = new Integer(priority);
pq_.insert(key, element);
}

protected void getFirstName(){
Object output;
//Remove the top priority person in the queue
try{
   output = pq_.removeMin();
}
catch(EmptyContainerException ece){
   output = "No patients in queue.";
}
top_name.setText((String)output);
}


private PriorityQueue pq_;

private Panel panel_;
  
private TextField name_field_;

private Choice priority_bot;

private Button enter_name;

private Button remove_top;

private TextField top_name;

private Button quit_;


private void setupPanel(){
setLocation(50,50);

panel_ = new Panel();
  
add(panel_);
  
name_field_ = new TextField(25);
name_field_.setEditable(true);
  
priority_bot = new Choice();
priority_bot.add("1");
priority_bot.add("2");
priority_bot.add("3");
priority_bot.add("4");
priority_bot.add("5");
  
enter_name = new Button("Add a person to the PriorityQueue");
enter_name.addActionListener(this);
  
remove_top = new Button("Remove the top-priority person");
remove_top.addActionListener(this);
  
top_name = new TextField(25);
top_name.setEditable(false);
  
quit_ = new Button("Quit");
quit_.addActionListener(this);
  
addWindowListener(this);
  
GridBagLayout layout = new GridBagLayout();
panel_.setLayout(layout);
  
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridy=GridBagConstraints.RELATIVE;//right below the last one
constraints.gridx=1;//1 column
constraints.anchor=GridBagConstraints.CENTER;
constraints.ipady=2;//set vgap to 2 pixels.
constraints.ipadx=3;


panel_.add(new Label("Enter person's name here:"), constraints);
panel_.add(name_field_, constraints);
  
panel_.add(new Label(""), constraints);//blank line
  
panel_.add(new Label("Set the person's triage priority here:"), constraints);
panel_.add(new Label("(1 = most urgent, 5 = least urgent)"), constraints);
panel_.add(priority_bot, constraints);
  
panel_.add(new Label(""), constraints);//blank line
  
panel_.add(enter_name, constraints);
  
panel_.add(new Label(""), constraints);//blank line
  
panel_.add(remove_top, constraints);
  
panel_.add(new Label(""), constraints);//blank line
  
panel_.add(new Label("Ready to treat person:"), constraints);
panel_.add(top_name, constraints);
  
  
panel_.add(new Label(""), constraints);//blank line
panel_.add(new Label(""), constraints);//blank line
panel_.add(new Label(""), constraints);//blank line
  
panel_.add(quit_, constraints);
  
validate();
setVisible(true);
panel_.validate();
panel_.setVisible(true);
pack();
}


public void actionPerformed(ActionEvent e){
  
if(e.getSource() == enter_name){
   enterPatient();
}
else if (e.getSource() == remove_top){
   getFirstName();
}
else if (e.getSource() == quit_){
   System.exit(0);
}
}


public static void main(String args[]){
Triage t = new Triage();
}

public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowClosing(WindowEvent e) {System.exit(0);}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}


}