57 lines
1.6 KiB
Java
57 lines
1.6 KiB
Java
package at.ionas999.health.model;
|
|
|
|
import at.ionas999.observer.ChangeObserver;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.PriorityQueue;
|
|
|
|
public class WaitingRoom {
|
|
private final List<ChangeObserver<WaitingRoom>> observers = new ArrayList<>();
|
|
private final PriorityQueue<Patient> patients = new PriorityQueue<>();
|
|
private Patient patientUndergoingTreatment = null;
|
|
|
|
public int getPatientCount() {
|
|
return patients.size();
|
|
}
|
|
|
|
public Patient getPatientInPreparation(){
|
|
return patients.peek();
|
|
}
|
|
|
|
public Patient getPatientUndergoingTreatment(){
|
|
return this.patientUndergoingTreatment;
|
|
}
|
|
|
|
public void addObserver(ChangeObserver<WaitingRoom> observer) {
|
|
observers.add(observer);
|
|
observer.update(this);
|
|
}
|
|
|
|
public Collection<Patient> getPatients() {
|
|
return patients.stream().toList();
|
|
}
|
|
|
|
public void removeObserver(ChangeObserver<WaitingRoom> observer) {
|
|
observers.remove(observer);
|
|
}
|
|
|
|
public void addPatient(String name, LocalDateTime appointment, boolean isEmergency) {
|
|
Patient patient = new Patient(name, appointment, isEmergency);
|
|
patients.add(patient);
|
|
notifyObservers();
|
|
}
|
|
|
|
public void treatNextPatient() {
|
|
this.patientUndergoingTreatment = patients.poll();
|
|
notifyObservers();
|
|
}
|
|
|
|
private void notifyObservers() {
|
|
for (ChangeObserver<WaitingRoom> observer : observers) {
|
|
observer.update(this);
|
|
}
|
|
}
|
|
} |