fixed the error that it now get initilized when finished loading components

This commit is contained in:
Jonas Hinterdorfer 2025-03-27 12:44:22 +01:00
parent 2ebd9b7abb
commit 3b15c593e2
5 changed files with 17 additions and 17 deletions

2
.idea/dataSources.xml generated
View File

@ -5,7 +5,7 @@
<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-url>jdbc:derby:DerbyDb;create=true</jdbc-url>
<jdbc-additional-properties>
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
</jdbc-additional-properties>

View File

@ -21,7 +21,10 @@ public class MedicalPracticeController implements ChangeObserver<WaitingRoom> {
private WaitingRoom waitingRoom;
public MedicalPracticeController()
@FXML
public void initialize()
{
this.waitingRoom = new WaitingRoom();
this.waitingRoom.addObserver(this);
@ -29,11 +32,6 @@ public class MedicalPracticeController implements ChangeObserver<WaitingRoom> {
@Override
public void update(WaitingRoom subject) {
if(this.waitingRoomTextField == null)
{
return;
}
waitingRoomTextField.setText(waitingRoom.getPatients().stream()
.reduce("", (s, p) -> s + p + "\n", String::concat));
preparation.setText(waitingRoom.getPatientInPreparation() == null ? "" : waitingRoom.getPatientInPreparation().toString());

View File

@ -41,8 +41,9 @@ public class WaitingRoom {
{
patientService = new PatientService();
this.patients.addAll(this.patientService.GetAllPatients());
ArrayList<Patient> allPatients = this.patientService.GetAllPatients();
this.patients.addAll(allPatients);
notifyObservers();
}
public void addObserver(ChangeObserver<WaitingRoom> observer) {

View File

@ -10,7 +10,7 @@ public abstract class DatabaseUtilsBase {
protected Connection GetDbConnection() throws SQLException {
Connection connection = DriverManager.getConnection(DatabaseUtilsBase.connectionString);
connection.setAutoCommit(true);
if(!ExistAnyTables(connection))
{
CreateTables(connection);

View File

@ -17,13 +17,13 @@ public class PatientService extends DatabaseUtilsBase implements TableCreation {
" name VARCHAR(255) NOT NULL PRIMARY KEY,\n" +
" appointment TIMESTAMP,\n" +
" isEmergency BOOLEAN\n" +
");";
")";
connection.createStatement().executeQuery(createTableSmt);
}
public boolean AddPatient(Patient patient) {
try (Connection connection = this.GetDbConnection()) {
String insertStmt = "INSERT INTO Patient (name, appointment, isEmergency) VALUES (?, ?, ?);";
String insertStmt = "INSERT INTO Patient (name, appointment, isEmergency) VALUES (?, ?, ?)";
PreparedStatement prepStmt = connection.prepareStatement(insertStmt);
@ -41,7 +41,7 @@ public class PatientService extends DatabaseUtilsBase implements TableCreation {
public void DeletePatient(String name) {
try (Connection connection = this.GetDbConnection()) {
String stmt = "DELETE FROM Patient WHERE name = ?;";
String stmt = "DELETE FROM Patient WHERE name = ?";
PreparedStatement prepStmt = connection.prepareStatement(stmt);
prepStmt.setString(1, name);
int updates = prepStmt.executeUpdate();
@ -57,16 +57,17 @@ public class PatientService extends DatabaseUtilsBase implements TableCreation {
public ArrayList<Patient> GetAllPatients() {
ArrayList<Patient> patients = new ArrayList<>();
try (Connection connection = this.GetDbConnection()) {
String stmt = "select name, appointment, isemergency from PATIENT;";
ResultSet rs = connection.createStatement().executeQuery(stmt);
String stmt = "SELECT * FROM Patient";
PreparedStatement prepStmt = connection.prepareStatement(stmt);
ResultSet rs = prepStmt.executeQuery();
while (rs.next()) {
while (rs.next()) {
Patient p = new Patient(rs.getString(1),
rs.getTimestamp(2).toLocalDateTime(),
rs.getBoolean(3));
patients.add(p);
}
prepStmt.close();
rs.close();
} catch (SQLException e) {