diff --git a/src/main/java/de/hitec/nhplus/patient/AllPatientController.java b/src/main/java/de/hitec/nhplus/patient/AllPatientController.java index 1e99995..16a363e 100644 --- a/src/main/java/de/hitec/nhplus/patient/AllPatientController.java +++ b/src/main/java/de/hitec/nhplus/patient/AllPatientController.java @@ -19,6 +19,13 @@ import java.time.LocalDate; import static de.hitec.nhplus.utils.Validator.*; +/** + * The controller for viewing all {@link Patient}s. + * + * @author Bernd Heideman + * @author Dominik Säume + * @author Armin Ribic + */ public class AllPatientController { @FXML @@ -53,6 +60,10 @@ public class AllPatientController { private final ObservableList patients = FXCollections.observableArrayList(); private PatientDao dao; + /** + * Initialization method that is called after the binding of all the fields. + */ + @FXML public void initialize() { this.readAllAndShowInTableView(); @@ -104,6 +115,41 @@ public class AllPatientController { this.textFieldRoomNumber.textProperty().addListener(inputNewPatientValidationListener); } + /** + * Internal method to read all data and set it to the table view. + */ + private void readAllAndShowInTableView() { + this.patients.clear(); + this.dao = DaoFactory.getInstance().createPatientDAO(); + try { + this.patients.setAll(this.dao.readAll()); + } catch (SQLException exception) { + exception.printStackTrace(); + } + } + + /** + * Internal method that stores the changes in the database. + */ + private void doUpdate(TableColumn.CellEditEvent event) { + try { + this.dao.update(event.getRowValue()); + } catch (SQLException exception) { + exception.printStackTrace(); + } + } + + /** + * Internal method that clears the text fields used for creating a new {@link Patient}. + */ + private void clearTextfields() { + this.textFieldFirstName.clear(); + this.textFieldSurName.clear(); + this.textFieldDateOfBirth.clear(); + this.textFieldCareLevel.clear(); + this.textFieldRoomNumber.clear(); + } + @FXML public void handleOnEditFirstname(TableColumn.CellEditEvent event) { String newFirstName = event.getNewValue(); @@ -164,25 +210,6 @@ public class AllPatientController { this.doUpdate(event); } - - private void doUpdate(TableColumn.CellEditEvent event) { - try { - this.dao.update(event.getRowValue()); - } catch (SQLException exception) { - exception.printStackTrace(); - } - } - - private void readAllAndShowInTableView() { - this.patients.clear(); - this.dao = DaoFactory.getInstance().createPatientDAO(); - try { - this.patients.addAll(this.dao.readAll()); - } catch (SQLException exception) { - exception.printStackTrace(); - } - } - @FXML public void handleDelete() { Patient selectedItem = this.tableView.getSelectionModel().getSelectedItem(); @@ -212,12 +239,4 @@ public class AllPatientController { readAllAndShowInTableView(); clearTextfields(); } - - private void clearTextfields() { - this.textFieldFirstName.clear(); - this.textFieldSurName.clear(); - this.textFieldDateOfBirth.clear(); - this.textFieldCareLevel.clear(); - this.textFieldRoomNumber.clear(); - } } diff --git a/src/main/java/de/hitec/nhplus/patient/Patient.java b/src/main/java/de/hitec/nhplus/patient/Patient.java index c7c72ee..6c91229 100644 --- a/src/main/java/de/hitec/nhplus/patient/Patient.java +++ b/src/main/java/de/hitec/nhplus/patient/Patient.java @@ -11,6 +11,13 @@ import java.util.ArrayList; import java.util.List; import java.util.StringJoiner; +/** + * The model for a {@link Patient}. + * + * @author Bernd Heideman + * @author Dominik Säume + * @author Armin Ribic + */ public class Patient extends Person { private SimpleIntegerProperty id; private final SimpleStringProperty dateOfBirth; @@ -18,6 +25,13 @@ public class Patient extends Person { private final SimpleStringProperty roomNumber; private final List allTreatments = new ArrayList<>(); + /** + * This constructor allows instantiating a {@link Patient} object, + * before it is stored in the database, by omitting the {@link Patient#id ID} value. + * + * @implSpec Instances created with this constructor can be directly passed to + * {@link de.hitec.nhplus.patient.database.PatientDao#create PatientDao.create}. + */ public Patient( String firstName, String surName, @@ -31,6 +45,9 @@ public class Patient extends Person { this.roomNumber = new SimpleStringProperty(roomNumber); } + /** + * This constructor allows instantiating a {@link Patient} object with all existing fields. + */ public Patient( int id, String firstName, diff --git a/src/main/java/de/hitec/nhplus/patient/database/PatientDao.java b/src/main/java/de/hitec/nhplus/patient/database/PatientDao.java index 90ba560..1880005 100644 --- a/src/main/java/de/hitec/nhplus/patient/database/PatientDao.java +++ b/src/main/java/de/hitec/nhplus/patient/database/PatientDao.java @@ -11,6 +11,12 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +/** + * The {@link PatientDao} is an implementation of the {@link de.hitec.nhplus.datastorage.Dao Dao} for the {@link Patient} model. + * + * @author Bernd Heidemann + * @author Dominik Säume + */ public class PatientDao extends DaoImp { public PatientDao(Connection connection) {