NOTICKET: Add Patient Module Javadoc

This commit is contained in:
Dominik Säume 2024-05-15 00:27:20 +02:00
parent 2b6efbc618
commit 87cf330dce
Signed by: SZUT-Dominik
GPG key ID: DACB4B96EB59ABA8
3 changed files with 69 additions and 27 deletions

View file

@ -19,6 +19,13 @@ import java.time.LocalDate;
import static de.hitec.nhplus.utils.Validator.*; 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 { public class AllPatientController {
@FXML @FXML
@ -53,6 +60,10 @@ public class AllPatientController {
private final ObservableList<Patient> patients = FXCollections.observableArrayList(); private final ObservableList<Patient> patients = FXCollections.observableArrayList();
private PatientDao dao; private PatientDao dao;
/**
* Initialization method that is called after the binding of all the fields.
*/
@FXML
public void initialize() { public void initialize() {
this.readAllAndShowInTableView(); this.readAllAndShowInTableView();
@ -104,6 +115,41 @@ public class AllPatientController {
this.textFieldRoomNumber.textProperty().addListener(inputNewPatientValidationListener); 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<Patient, String> 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 @FXML
public void handleOnEditFirstname(TableColumn.CellEditEvent<Patient, String> event) { public void handleOnEditFirstname(TableColumn.CellEditEvent<Patient, String> event) {
String newFirstName = event.getNewValue(); String newFirstName = event.getNewValue();
@ -164,25 +210,6 @@ public class AllPatientController {
this.doUpdate(event); this.doUpdate(event);
} }
private void doUpdate(TableColumn.CellEditEvent<Patient, String> 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 @FXML
public void handleDelete() { public void handleDelete() {
Patient selectedItem = this.tableView.getSelectionModel().getSelectedItem(); Patient selectedItem = this.tableView.getSelectionModel().getSelectedItem();
@ -212,12 +239,4 @@ public class AllPatientController {
readAllAndShowInTableView(); readAllAndShowInTableView();
clearTextfields(); clearTextfields();
} }
private void clearTextfields() {
this.textFieldFirstName.clear();
this.textFieldSurName.clear();
this.textFieldDateOfBirth.clear();
this.textFieldCareLevel.clear();
this.textFieldRoomNumber.clear();
}
} }

View file

@ -11,6 +11,13 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.StringJoiner; 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 { public class Patient extends Person {
private SimpleIntegerProperty id; private SimpleIntegerProperty id;
private final SimpleStringProperty dateOfBirth; private final SimpleStringProperty dateOfBirth;
@ -18,6 +25,13 @@ public class Patient extends Person {
private final SimpleStringProperty roomNumber; private final SimpleStringProperty roomNumber;
private final List<Treatment> allTreatments = new ArrayList<>(); private final List<Treatment> 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( public Patient(
String firstName, String firstName,
String surName, String surName,
@ -31,6 +45,9 @@ public class Patient extends Person {
this.roomNumber = new SimpleStringProperty(roomNumber); this.roomNumber = new SimpleStringProperty(roomNumber);
} }
/**
* This constructor allows instantiating a {@link Patient} object with all existing fields.
*/
public Patient( public Patient(
int id, int id,
String firstName, String firstName,

View file

@ -11,6 +11,12 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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<Patient> { public class PatientDao extends DaoImp<Patient> {
public PatientDao(Connection connection) { public PatientDao(Connection connection) {