fixed the error that it now get initilized when finished loading components
This commit is contained in:
parent
2ebd9b7abb
commit
3b15c593e2
2
.idea/dataSources.xml
generated
2
.idea/dataSources.xml
generated
@ -5,7 +5,7 @@
|
|||||||
<driver-ref>derby.embedded</driver-ref>
|
<driver-ref>derby.embedded</driver-ref>
|
||||||
<synchronize>true</synchronize>
|
<synchronize>true</synchronize>
|
||||||
<jdbc-driver>org.apache.derby.jdbc.EmbeddedDriver</jdbc-driver>
|
<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>
|
<jdbc-additional-properties>
|
||||||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||||
</jdbc-additional-properties>
|
</jdbc-additional-properties>
|
||||||
|
|||||||
@ -21,7 +21,10 @@ public class MedicalPracticeController implements ChangeObserver<WaitingRoom> {
|
|||||||
|
|
||||||
private WaitingRoom waitingRoom;
|
private WaitingRoom waitingRoom;
|
||||||
|
|
||||||
public MedicalPracticeController()
|
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize()
|
||||||
{
|
{
|
||||||
this.waitingRoom = new WaitingRoom();
|
this.waitingRoom = new WaitingRoom();
|
||||||
this.waitingRoom.addObserver(this);
|
this.waitingRoom.addObserver(this);
|
||||||
@ -29,11 +32,6 @@ public class MedicalPracticeController implements ChangeObserver<WaitingRoom> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(WaitingRoom subject) {
|
public void update(WaitingRoom subject) {
|
||||||
if(this.waitingRoomTextField == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
waitingRoomTextField.setText(waitingRoom.getPatients().stream()
|
waitingRoomTextField.setText(waitingRoom.getPatients().stream()
|
||||||
.reduce("", (s, p) -> s + p + "\n", String::concat));
|
.reduce("", (s, p) -> s + p + "\n", String::concat));
|
||||||
preparation.setText(waitingRoom.getPatientInPreparation() == null ? "" : waitingRoom.getPatientInPreparation().toString());
|
preparation.setText(waitingRoom.getPatientInPreparation() == null ? "" : waitingRoom.getPatientInPreparation().toString());
|
||||||
|
|||||||
@ -41,8 +41,9 @@ public class WaitingRoom {
|
|||||||
{
|
{
|
||||||
patientService = new PatientService();
|
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) {
|
public void addObserver(ChangeObserver<WaitingRoom> observer) {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ public abstract class DatabaseUtilsBase {
|
|||||||
|
|
||||||
protected Connection GetDbConnection() throws SQLException {
|
protected Connection GetDbConnection() throws SQLException {
|
||||||
Connection connection = DriverManager.getConnection(DatabaseUtilsBase.connectionString);
|
Connection connection = DriverManager.getConnection(DatabaseUtilsBase.connectionString);
|
||||||
|
connection.setAutoCommit(true);
|
||||||
if(!ExistAnyTables(connection))
|
if(!ExistAnyTables(connection))
|
||||||
{
|
{
|
||||||
CreateTables(connection);
|
CreateTables(connection);
|
||||||
|
|||||||
@ -17,13 +17,13 @@ public class PatientService extends DatabaseUtilsBase implements TableCreation {
|
|||||||
" name VARCHAR(255) NOT NULL PRIMARY KEY,\n" +
|
" name VARCHAR(255) NOT NULL PRIMARY KEY,\n" +
|
||||||
" appointment TIMESTAMP,\n" +
|
" appointment TIMESTAMP,\n" +
|
||||||
" isEmergency BOOLEAN\n" +
|
" isEmergency BOOLEAN\n" +
|
||||||
");";
|
")";
|
||||||
connection.createStatement().executeQuery(createTableSmt);
|
connection.createStatement().executeQuery(createTableSmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean AddPatient(Patient patient) {
|
public boolean AddPatient(Patient patient) {
|
||||||
try (Connection connection = this.GetDbConnection()) {
|
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);
|
PreparedStatement prepStmt = connection.prepareStatement(insertStmt);
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ public class PatientService extends DatabaseUtilsBase implements TableCreation {
|
|||||||
|
|
||||||
public void DeletePatient(String name) {
|
public void DeletePatient(String name) {
|
||||||
try (Connection connection = this.GetDbConnection()) {
|
try (Connection connection = this.GetDbConnection()) {
|
||||||
String stmt = "DELETE FROM Patient WHERE name = ?;";
|
String stmt = "DELETE FROM Patient WHERE name = ?";
|
||||||
PreparedStatement prepStmt = connection.prepareStatement(stmt);
|
PreparedStatement prepStmt = connection.prepareStatement(stmt);
|
||||||
prepStmt.setString(1, name);
|
prepStmt.setString(1, name);
|
||||||
int updates = prepStmt.executeUpdate();
|
int updates = prepStmt.executeUpdate();
|
||||||
@ -57,8 +57,9 @@ public class PatientService extends DatabaseUtilsBase implements TableCreation {
|
|||||||
public ArrayList<Patient> GetAllPatients() {
|
public ArrayList<Patient> GetAllPatients() {
|
||||||
ArrayList<Patient> patients = new ArrayList<>();
|
ArrayList<Patient> patients = new ArrayList<>();
|
||||||
try (Connection connection = this.GetDbConnection()) {
|
try (Connection connection = this.GetDbConnection()) {
|
||||||
String stmt = "select name, appointment, isemergency from PATIENT;";
|
String stmt = "SELECT * FROM Patient";
|
||||||
ResultSet rs = connection.createStatement().executeQuery(stmt);
|
PreparedStatement prepStmt = connection.prepareStatement(stmt);
|
||||||
|
ResultSet rs = prepStmt.executeQuery();
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
Patient p = new Patient(rs.getString(1),
|
Patient p = new Patient(rs.getString(1),
|
||||||
@ -66,7 +67,7 @@ public class PatientService extends DatabaseUtilsBase implements TableCreation {
|
|||||||
rs.getBoolean(3));
|
rs.getBoolean(3));
|
||||||
patients.add(p);
|
patients.add(p);
|
||||||
}
|
}
|
||||||
|
prepStmt.close();
|
||||||
rs.close();
|
rs.close();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user