#6: deleting patient assets. #14

Merged
SZUT-Armin merged 1 commit from story/vermogenstand-entfernen into main 2024-04-26 10:55:36 +00:00
6 changed files with 71 additions and 150 deletions
Showing only changes of commit 4d6b0c76c3 - Show all commits

Binary file not shown.

View file

@ -20,8 +20,7 @@ import java.time.LocalDate;
import static de.hitec.nhplus.utils.Validator.*; import static de.hitec.nhplus.utils.Validator.*;
public class AllPatientController public class AllPatientController {
{
@FXML @FXML
private TableView<Patient> tableView; private TableView<Patient> tableView;
@ -38,8 +37,6 @@ public class AllPatientController
@FXML @FXML
private TableColumn<Patient, String> columnRoomNumber; private TableColumn<Patient, String> columnRoomNumber;
@FXML @FXML
private TableColumn<Patient, String> columnAssets;
@FXML
private Button buttonDelete; private Button buttonDelete;
@FXML @FXML
private Button buttonAdd; private Button buttonAdd;
@ -53,14 +50,11 @@ public class AllPatientController
private TextField textFieldCareLevel; private TextField textFieldCareLevel;
@FXML @FXML
private TextField textFieldRoomNumber; private TextField textFieldRoomNumber;
@FXML
private TextField textFieldAssets;
private final ObservableList<Patient> patients = FXCollections.observableArrayList(); private final ObservableList<Patient> patients = FXCollections.observableArrayList();
private PatientDao dao; private PatientDao dao;
public void initialize() public void initialize() {
{
this.readAllAndShowInTableView(); this.readAllAndShowInTableView();
this.columnId.setCellValueFactory(new PropertyValueFactory<>("pid")); this.columnId.setCellValueFactory(new PropertyValueFactory<>("pid"));
@ -80,31 +74,28 @@ public class AllPatientController
this.columnRoomNumber.setCellValueFactory(new PropertyValueFactory<>("roomNumber")); this.columnRoomNumber.setCellValueFactory(new PropertyValueFactory<>("roomNumber"));
this.columnRoomNumber.setCellFactory(TextFieldTableCell.forTableColumn()); this.columnRoomNumber.setCellFactory(TextFieldTableCell.forTableColumn());
this.columnAssets.setCellValueFactory(new PropertyValueFactory<>("assets"));
this.columnAssets.setCellFactory(TextFieldTableCell.forTableColumn());
this.tableView.setItems(this.patients); this.tableView.setItems(this.patients);
this.buttonDelete.setDisable(true); this.buttonDelete.setDisable(true);
this.tableView this.tableView
.getSelectionModel() .getSelectionModel()
.selectedItemProperty() .selectedItemProperty()
.addListener((observableValue, oldPatient, newPatient) -> .addListener((observableValue, oldPatient, newPatient) ->
{ {
AllPatientController.this.buttonDelete.setDisable(newPatient == null); AllPatientController.this.buttonDelete.setDisable(newPatient == null);
} }
); );
this.buttonAdd.setDisable(true); this.buttonAdd.setDisable(true);
ChangeListener<String> inputNewPatientValidationListener = (observableValue, oldText, newText) -> ChangeListener<String> inputNewPatientValidationListener = (observableValue, oldText, newText) ->
{ {
boolean isValid = isValidDate(this.textFieldDateOfBirth.getText()) boolean isValid = isValidDate(this.textFieldDateOfBirth.getText())
&& isValidFirstName(this.textFieldFirstName.getText()) && isValidFirstName(this.textFieldFirstName.getText())
&& isValidSurName(this.textFieldSurname.getText()) && isValidSurName(this.textFieldSurname.getText())
&& isValidDate(this.textFieldDateOfBirth.getText()) && isValidDate(this.textFieldDateOfBirth.getText())
&& isValidCareLevel(this.textFieldCareLevel.getText()) && isValidCareLevel(this.textFieldCareLevel.getText())
&& isValidRoomNumber(textFieldRoomNumber.getText()) && isValidRoomNumber(textFieldRoomNumber.getText());
&& !this.textFieldAssets.getText().isBlank();
AllPatientController.this.buttonAdd.setDisable(!isValid); AllPatientController.this.buttonAdd.setDisable(!isValid);
}; };
@ -114,15 +105,12 @@ public class AllPatientController
this.textFieldDateOfBirth.textProperty().addListener(inputNewPatientValidationListener); this.textFieldDateOfBirth.textProperty().addListener(inputNewPatientValidationListener);
this.textFieldCareLevel.textProperty().addListener(inputNewPatientValidationListener); this.textFieldCareLevel.textProperty().addListener(inputNewPatientValidationListener);
this.textFieldRoomNumber.textProperty().addListener(inputNewPatientValidationListener); this.textFieldRoomNumber.textProperty().addListener(inputNewPatientValidationListener);
this.textFieldAssets.textProperty().addListener(inputNewPatientValidationListener);
} }
@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();
if (!isValidFirstName(newFirstName)) if (!isValidFirstName(newFirstName)) {
{
showValidationError("First Name"); showValidationError("First Name");
event.getTableView().refresh(); event.getTableView().refresh();
return; return;
@ -132,11 +120,9 @@ public class AllPatientController
} }
@FXML @FXML
public void handleOnEditSurname(TableColumn.CellEditEvent<Patient, String> event) public void handleOnEditSurname(TableColumn.CellEditEvent<Patient, String> event) {
{
String newSurName = event.getNewValue(); String newSurName = event.getNewValue();
if (!isValidSurName(newSurName)) if (!isValidSurName(newSurName)) {
{
showValidationError("Sur Name"); showValidationError("Sur Name");
event.getTableView().refresh(); event.getTableView().refresh();
return; return;
@ -146,11 +132,9 @@ public class AllPatientController
} }
@FXML @FXML
public void handleOnEditDateOfBirth(TableColumn.CellEditEvent<Patient, String> event) public void handleOnEditDateOfBirth(TableColumn.CellEditEvent<Patient, String> event) {
{
String newDateString = event.getNewValue(); String newDateString = event.getNewValue();
if (!isValidDate(newDateString)) if (!isValidDate(newDateString)) {
{
showValidationError("Date"); showValidationError("Date");
event.getTableView().refresh(); event.getTableView().refresh();
return; return;
@ -160,11 +144,9 @@ public class AllPatientController
} }
@FXML @FXML
public void handleOnEditCareLevel(TableColumn.CellEditEvent<Patient, String> event) public void handleOnEditCareLevel(TableColumn.CellEditEvent<Patient, String> event) {
{
String newCareLevel = event.getNewValue(); String newCareLevel = event.getNewValue();
if (!isValidCareLevel(newCareLevel)) if (!isValidCareLevel(newCareLevel)) {
{
showValidationError("Care Level"); showValidationError("Care Level");
event.getTableView().refresh(); event.getTableView().refresh();
return; return;
@ -174,11 +156,9 @@ public class AllPatientController
} }
@FXML @FXML
public void handleOnEditRoomNumber(TableColumn.CellEditEvent<Patient, String> event) public void handleOnEditRoomNumber(TableColumn.CellEditEvent<Patient, String> event) {
{
String newRoomNumber = event.getNewValue(); String newRoomNumber = event.getNewValue();
if (!isValidRoomNumber(newRoomNumber)) if (!isValidRoomNumber(newRoomNumber)) {
{
showValidationError("Room Number"); showValidationError("Room Number");
event.getTableView().refresh(); event.getTableView().refresh();
return; return;
@ -187,87 +167,60 @@ public class AllPatientController
this.doUpdate(event); this.doUpdate(event);
} }
@FXML
public void handleOnEditAssets(TableColumn.CellEditEvent<Patient, String> event)
{
String newAssets = event.getNewValue();
if(newAssets.isBlank()){
event.getTableView().refresh();
return;
}
event.getRowValue().setAssets(newAssets);
this.doUpdate(event);
}
private void doUpdate(TableColumn.CellEditEvent<Patient, String> event) private void doUpdate(TableColumn.CellEditEvent<Patient, String> event) {
{ try {
try
{
this.dao.update(event.getRowValue()); this.dao.update(event.getRowValue());
} catch (SQLException exception) } catch (SQLException exception) {
{
exception.printStackTrace(); exception.printStackTrace();
} }
} }
private void readAllAndShowInTableView() private void readAllAndShowInTableView() {
{
this.patients.clear(); this.patients.clear();
this.dao = DaoFactory.getDaoFactory().createPatientDAO(); this.dao = DaoFactory.getDaoFactory().createPatientDAO();
try try {
{
this.patients.addAll(this.dao.readAll()); this.patients.addAll(this.dao.readAll());
} catch (SQLException exception) } catch (SQLException exception) {
{
exception.printStackTrace(); exception.printStackTrace();
} }
} }
@FXML @FXML
public void handleDelete() public void handleDelete() {
{
Patient selectedItem = this.tableView.getSelectionModel().getSelectedItem(); Patient selectedItem = this.tableView.getSelectionModel().getSelectedItem();
if (selectedItem != null) if (selectedItem != null) {
{ try {
try
{
DaoFactory.getDaoFactory().createPatientDAO().deleteById(selectedItem.getPid()); DaoFactory.getDaoFactory().createPatientDAO().deleteById(selectedItem.getPid());
this.tableView.getItems().remove(selectedItem); this.tableView.getItems().remove(selectedItem);
} catch (SQLException exception) } catch (SQLException exception) {
{
exception.printStackTrace(); exception.printStackTrace();
} }
} }
} }
@FXML @FXML
public void handleAdd() public void handleAdd() {
{
String surname = this.textFieldSurname.getText(); String surname = this.textFieldSurname.getText();
String firstName = this.textFieldFirstName.getText(); String firstName = this.textFieldFirstName.getText();
String birthday = this.textFieldDateOfBirth.getText(); String birthday = this.textFieldDateOfBirth.getText();
LocalDate date = DateConverter.convertStringToLocalDate(birthday); LocalDate date = DateConverter.convertStringToLocalDate(birthday);
String careLevel = this.textFieldCareLevel.getText(); String careLevel = this.textFieldCareLevel.getText();
String roomNumber = this.textFieldRoomNumber.getText(); String roomNumber = this.textFieldRoomNumber.getText();
String assets = this.textFieldAssets.getText(); try {
try this.dao.create(new Patient(firstName, surname, date, careLevel, roomNumber));
{ } catch (SQLException exception) {
this.dao.create(new Patient(firstName, surname, date, careLevel, roomNumber, assets));
} catch (SQLException exception)
{
exception.printStackTrace(); exception.printStackTrace();
} }
readAllAndShowInTableView(); readAllAndShowInTableView();
clearTextfields(); clearTextfields();
} }
private void clearTextfields() private void clearTextfields() {
{
this.textFieldFirstName.clear(); this.textFieldFirstName.clear();
this.textFieldSurname.clear(); this.textFieldSurname.clear();
this.textFieldDateOfBirth.clear(); this.textFieldDateOfBirth.clear();
this.textFieldCareLevel.clear(); this.textFieldCareLevel.clear();
this.textFieldRoomNumber.clear(); this.textFieldRoomNumber.clear();
this.textFieldAssets.clear();
} }
} }

View file

@ -32,15 +32,14 @@ public class PatientDao extends DaoImp<Patient> {
protected PreparedStatement getCreateStatement(Patient patient) { protected PreparedStatement getCreateStatement(Patient patient) {
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
try { try {
final String SQL = "INSERT INTO patient (firstname, surname, dateOfBirth, carelevel, roomnumber, assets) " + final String SQL = "INSERT INTO patient (firstname, surname, dateOfBirth, carelevel, roomnumber) " +
"VALUES (?, ?, ?, ?, ?, ?)"; "VALUES (?, ?, ?, ?, ?)";
preparedStatement = this.connection.prepareStatement(SQL); preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setString(1, patient.getFirstName()); preparedStatement.setString(1, patient.getFirstName());
preparedStatement.setString(2, patient.getSurname()); preparedStatement.setString(2, patient.getSurname());
preparedStatement.setString(3, patient.getDateOfBirth()); preparedStatement.setString(3, patient.getDateOfBirth());
preparedStatement.setString(4, patient.getCareLevel()); preparedStatement.setString(4, patient.getCareLevel());
preparedStatement.setString(5, patient.getRoomNumber()); preparedStatement.setString(5, patient.getRoomNumber());
preparedStatement.setString(6, patient.getAssets());
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
@ -80,8 +79,7 @@ public class PatientDao extends DaoImp<Patient> {
result.getString(3), result.getString(3),
DateConverter.convertStringToLocalDate(result.getString(4)), DateConverter.convertStringToLocalDate(result.getString(4)),
result.getString(5), result.getString(5),
result.getString(6), result.getString(6));
result.getString(7));
} }
/** /**
@ -115,7 +113,7 @@ public class PatientDao extends DaoImp<Patient> {
LocalDate date = DateConverter.convertStringToLocalDate(result.getString(4)); LocalDate date = DateConverter.convertStringToLocalDate(result.getString(4));
Patient patient = new Patient(result.getInt(1), result.getString(2), Patient patient = new Patient(result.getInt(1), result.getString(2),
result.getString(3), date, result.getString(3), date,
result.getString(5), result.getString(6), result.getString(7)); result.getString(5), result.getString(6));
list.add(patient); list.add(patient);
} }
return list; return list;
@ -139,7 +137,6 @@ public class PatientDao extends DaoImp<Patient> {
"dateOfBirth = ?, " + "dateOfBirth = ?, " +
"carelevel = ?, " + "carelevel = ?, " +
"roomnumber = ?, " + "roomnumber = ?, " +
"assets = ? " +
"WHERE pid = ?"; "WHERE pid = ?";
preparedStatement = this.connection.prepareStatement(SQL); preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setString(1, patient.getFirstName()); preparedStatement.setString(1, patient.getFirstName());
@ -147,8 +144,7 @@ public class PatientDao extends DaoImp<Patient> {
preparedStatement.setString(3, patient.getDateOfBirth()); preparedStatement.setString(3, patient.getDateOfBirth());
preparedStatement.setString(4, patient.getCareLevel()); preparedStatement.setString(4, patient.getCareLevel());
preparedStatement.setString(5, patient.getRoomNumber()); preparedStatement.setString(5, patient.getRoomNumber());
preparedStatement.setString(6, patient.getAssets()); preparedStatement.setLong(6, patient.getPid());
preparedStatement.setLong(7, patient.getPid());
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }

View file

@ -37,8 +37,7 @@ public class PatientFixture implements Fixture<Patient>
" surname TEXT NOT NULL, " + " surname TEXT NOT NULL, " +
" dateOfBirth TEXT NOT NULL, " + " dateOfBirth TEXT NOT NULL, " +
" carelevel TEXT NOT NULL, " + " carelevel TEXT NOT NULL, " +
" roomnumber TEXT NOT NULL, " + " roomnumber TEXT NOT NULL" +
" assets TEXt NOT NULL" +
");"; ");";
try (Statement statement = connection.createStatement()) try (Statement statement = connection.createStatement())
{ {
@ -59,48 +58,42 @@ public class PatientFixture implements Fixture<Patient>
"Herberger", "Herberger",
convertStringToLocalDate("1945-12-01"), convertStringToLocalDate("1945-12-01"),
"4", "4",
"202", "202"
"vermögend"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Martina", "Martina",
"Gerdsen", "Gerdsen",
convertStringToLocalDate("1954-08-12"), convertStringToLocalDate("1954-08-12"),
"5", "5",
"010", "010"
"arm"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Gertrud", "Gertrud",
"Franzen", "Franzen",
convertStringToLocalDate("1949-04-16"), convertStringToLocalDate("1949-04-16"),
"3", "3",
"002", "002"
"normal"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Ahmet", "Ahmet",
"Yilmaz", "Yilmaz",
convertStringToLocalDate("1941-02-22"), convertStringToLocalDate("1941-02-22"),
"3", "3",
"013", "013"
"normal"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Hans", "Hans",
"Neumann", "Neumann",
convertStringToLocalDate("1955-12-12"), convertStringToLocalDate("1955-12-12"),
"2", "2",
"001", "001"
"sehr vermögend"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Elisabeth", "Elisabeth",
"Müller", "Müller",
convertStringToLocalDate("1958-03-07"), convertStringToLocalDate("1958-03-07"),
"5", "5",
"110", "110"
"arm"
)); ));
PatientDao dao = DaoFactory.getDaoFactory().createPatientDAO(); PatientDao dao = DaoFactory.getDaoFactory().createPatientDAO();

View file

@ -16,62 +16,55 @@ public class Patient extends Person {
private final SimpleStringProperty dateOfBirth; private final SimpleStringProperty dateOfBirth;
private final SimpleStringProperty careLevel; private final SimpleStringProperty careLevel;
private final SimpleStringProperty roomNumber; private final SimpleStringProperty roomNumber;
private final SimpleStringProperty assets;
private final List<Treatment> allTreatments = new ArrayList<>(); private final List<Treatment> allTreatments = new ArrayList<>();
/** /**
* Constructor to initiate an object of class <code>Patient</code> with the given parameter. Use this constructor * Constructor to initiate an object of class <code>Patient</code> with the given parameter. Use this constructor
* to initiate objects, which are not persisted yet, because it will not have a patient id (pid). * to initiate objects, which are not persisted yet, because it will not have a patient id (pid).
* *
* @param firstName First name of the patient. * @param firstName First name of the patient.
* @param surname Last name of the patient. * @param surname Last name of the patient.
* @param dateOfBirth Date of birth of the patient. * @param dateOfBirth Date of birth of the patient.
* @param careLevel Care level of the patient. * @param careLevel Care level of the patient.
* @param roomNumber Room number of the patient. * @param roomNumber Room number of the patient.
* @param assets Assets of the patient.
*/ */
public Patient( public Patient(
String firstName, String firstName,
String surname, String surname,
LocalDate dateOfBirth, LocalDate dateOfBirth,
String careLevel, String careLevel,
String roomNumber, String roomNumber
String assets
) { ) {
super(firstName, surname); super(firstName, surname);
this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth)); this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth));
this.careLevel = new SimpleStringProperty(careLevel); this.careLevel = new SimpleStringProperty(careLevel);
this.roomNumber = new SimpleStringProperty(roomNumber); this.roomNumber = new SimpleStringProperty(roomNumber);
this.assets = new SimpleStringProperty(assets);
} }
/** /**
* Constructor to initiate an object of class <code>Patient</code> with the given parameter. Use this constructor * Constructor to initiate an object of class <code>Patient</code> with the given parameter. Use this constructor
* to initiate objects, which are already persisted and have a patient id (pid). * to initiate objects, which are already persisted and have a patient id (pid).
* *
* @param pid Patient id. * @param pid Patient id.
* @param firstName First name of the patient. * @param firstName First name of the patient.
* @param surname Last name of the patient. * @param surname Last name of the patient.
* @param dateOfBirth Date of birth of the patient. * @param dateOfBirth Date of birth of the patient.
* @param careLevel Care level of the patient. * @param careLevel Care level of the patient.
* @param roomNumber Room number of the patient. * @param roomNumber Room number of the patient.
* @param assets Assets of the patient.
*/ */
public Patient( public Patient(
long pid, long pid,
String firstName, String firstName,
String surname, String surname,
LocalDate dateOfBirth, LocalDate dateOfBirth,
String careLevel, String careLevel,
String roomNumber, String roomNumber
String assets
) { ) {
super(firstName, surname); super(firstName, surname);
this.pid = new SimpleLongProperty(pid); this.pid = new SimpleLongProperty(pid);
this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth)); this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth));
this.careLevel = new SimpleStringProperty(careLevel); this.careLevel = new SimpleStringProperty(careLevel);
this.roomNumber = new SimpleStringProperty(roomNumber); this.roomNumber = new SimpleStringProperty(roomNumber);
this.assets = new SimpleStringProperty(assets);
} }
public long getPid() { public long getPid() {
@ -124,17 +117,6 @@ public class Patient extends Person {
this.roomNumber.set(roomNumber); this.roomNumber.set(roomNumber);
} }
public String getAssets() {
return assets.get();
}
public SimpleStringProperty assetsProperty() {
return assets;
}
public void setAssets(String assets) {
this.assets.set(assets);
}
/** /**
* Adds a treatment to the list of treatments, if the list does not already contain the treatment. * Adds a treatment to the list of treatments, if the list does not already contain the treatment.
@ -157,7 +139,6 @@ public class Patient extends Person {
"\nBirthday: " + this.dateOfBirth + "\nBirthday: " + this.dateOfBirth +
"\nCarelevel: " + this.careLevel + "\nCarelevel: " + this.careLevel +
"\nRoomnumber: " + this.roomNumber + "\nRoomnumber: " + this.roomNumber +
"\nAssets: " + this.assets +
"\n"; "\n";
} }
} }

View file

@ -23,7 +23,6 @@
<TableColumn fx:id="columnDateOfBirth" maxWidth="7500.0" onEditCommit="#handleOnEditDateOfBirth" prefWidth="75.0" text="Geburtstag" /> <TableColumn fx:id="columnDateOfBirth" maxWidth="7500.0" onEditCommit="#handleOnEditDateOfBirth" prefWidth="75.0" text="Geburtstag" />
<TableColumn fx:id="columnCareLevel" onEditCommit="#handleOnEditCareLevel" prefWidth="75.0" text="Pflegegrad" /> <TableColumn fx:id="columnCareLevel" onEditCommit="#handleOnEditCareLevel" prefWidth="75.0" text="Pflegegrad" />
<TableColumn fx:id="columnRoomNumber" onEditCommit="#handleOnEditRoomNumber" prefWidth="75.0" text="Raum" /> <TableColumn fx:id="columnRoomNumber" onEditCommit="#handleOnEditRoomNumber" prefWidth="75.0" text="Raum" />
<TableColumn fx:id="columnAssets" onEditCommit="#handleOnEditAssets" prefWidth="75.0" text="Vermögensstand" />
</columns> </columns>
<columnResizePolicy> <columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /> <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
@ -47,7 +46,6 @@
<TextField fx:id="textFieldDateOfBirth" minWidth="160.0" prefWidth="160.0" promptText="Geburtstag" GridPane.columnIndex="2" /> <TextField fx:id="textFieldDateOfBirth" minWidth="160.0" prefWidth="160.0" promptText="Geburtstag" GridPane.columnIndex="2" />
<TextField fx:id="textFieldCareLevel" prefHeight="26.0" prefWidth="200.0" promptText="Pflegegrad" GridPane.rowIndex="1" /> <TextField fx:id="textFieldCareLevel" prefHeight="26.0" prefWidth="200.0" promptText="Pflegegrad" GridPane.rowIndex="1" />
<TextField fx:id="textFieldRoomNumber" prefHeight="26.0" prefWidth="200.0" promptText="Raum" GridPane.columnIndex="1" GridPane.rowIndex="1" /> <TextField fx:id="textFieldRoomNumber" prefHeight="26.0" prefWidth="200.0" promptText="Raum" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField fx:id="textFieldAssets" minWidth="160.0" prefWidth="160.0" promptText="Vermögensstand" GridPane.columnIndex="2" GridPane.rowIndex="1" />
</children> </children>
<padding> <padding>
<Insets right="10.0" /> <Insets right="10.0" />