added it in the patient waiting room

This commit is contained in:
Jonas Hinterdorfer 2025-03-27 12:27:29 +01:00
parent 6bd8fda834
commit 2ebd9b7abb
7 changed files with 50 additions and 9 deletions

15
.idea/dataSources.xml generated Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="DerbyDb" uuid="031a850b-594c-421e-abe6-800a47ea61ed">
<driver-ref>derby.embedded</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.apache.derby.jdbc.EmbeddedDriver</jdbc-driver>
<jdbc-url>jdbc:derby:DerbyDb</jdbc-url>
<jdbc-additional-properties>
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
</jdbc-additional-properties>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

7
.idea/sqldialects.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/src/main/java/at/ionas999/health/services/DatabaseUtilsBase.java" dialect="GenericSQL" />
<file url="PROJECT" dialect="Derby" />
</component>
</project>

View File

@ -1,6 +1,6 @@
package at.ionas999.health.controller;
import at.ionas999.health.model.WaitingRoom;
import at.ionas999.health.repositories.WaitingRoom;
import at.ionas999.observer.ChangeObserver;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;

View File

@ -1,5 +1,7 @@
package at.ionas999.health.model;
package at.ionas999.health.repositories;
import at.ionas999.health.model.Patient;
import at.ionas999.health.services.PatientService;
import at.ionas999.observer.ChangeObserver;
import java.time.LocalDateTime;
@ -9,6 +11,8 @@ import java.util.List;
import java.util.PriorityQueue;
public class WaitingRoom {
private PatientService patientService;
private final List<ChangeObserver<WaitingRoom>> observers = new ArrayList<>();
private final PriorityQueue<Patient> patients = new PriorityQueue<>();
private Patient patientUndergoingTreatment = null;
@ -25,11 +29,6 @@ public class WaitingRoom {
return this.patientUndergoingTreatment;
}
public void addObserver(ChangeObserver<WaitingRoom> observer) {
observers.add(observer);
observer.update(this);
}
public Collection<Patient> getPatients() {
return patients.stream().toList();
}
@ -38,14 +37,32 @@ public class WaitingRoom {
observers.remove(observer);
}
public WaitingRoom()
{
patientService = new PatientService();
this.patients.addAll(this.patientService.GetAllPatients());
}
public void addObserver(ChangeObserver<WaitingRoom> observer) {
observers.add(observer);
observer.update(this);
}
public void addPatient(String name, LocalDateTime appointment, boolean isEmergency) {
Patient patient = new Patient(name, appointment, isEmergency);
patients.add(patient);
patientService.AddPatient(patient);
notifyObservers();
}
public void treatNextPatient() {
this.patientUndergoingTreatment = patients.poll();
if(this.patientUndergoingTreatment != null)
{
this.patientService.DeletePatient(this.patientUndergoingTreatment.getName());
}
notifyObservers();
}

View File

@ -15,8 +15,8 @@ public class PatientService extends DatabaseUtilsBase implements TableCreation {
public void CreateTable(Connection connection) throws SQLException {
String createTableSmt = "CREATE TABLE Patient (\n" +
" name VARCHAR(255) NOT NULL PRIMARY KEY,\n" +
" appointment TIMESTAMP NOT NULL,\n" +
" isEmergency BOOLEAN NOT NULL\n" +
" appointment TIMESTAMP,\n" +
" isEmergency BOOLEAN\n" +
");";
connection.createStatement().executeQuery(createTableSmt);
}

View File

@ -1,6 +1,7 @@
package at.ionas999.health.model;
import at.ionas999.health.repositories.WaitingRoom;
import at.ionas999.observer.ChangeObserver;
public class UpdateObserver implements ChangeObserver<WaitingRoom> {

View File

@ -1,5 +1,6 @@
package at.ionas999.health.model;
import at.ionas999.health.repositories.WaitingRoom;
import at.ionas999.observer.ChangeObserver;
import org.junit.jupiter.api.Test;