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

View file

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

View file

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

View file

@ -16,7 +16,6 @@ public class Patient extends Person {
private final SimpleStringProperty dateOfBirth;
private final SimpleStringProperty careLevel;
private final SimpleStringProperty roomNumber;
private final SimpleStringProperty assets;
private final List<Treatment> allTreatments = new ArrayList<>();
/**
@ -28,21 +27,18 @@ public class Patient extends Person {
* @param dateOfBirth Date of birth of the patient.
* @param careLevel Care level of the patient.
* @param roomNumber Room number of the patient.
* @param assets Assets of the patient.
*/
public Patient(
String firstName,
String surname,
LocalDate dateOfBirth,
String careLevel,
String roomNumber,
String assets
String roomNumber
) {
super(firstName, surname);
this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth));
this.careLevel = new SimpleStringProperty(careLevel);
this.roomNumber = new SimpleStringProperty(roomNumber);
this.assets = new SimpleStringProperty(assets);
}
/**
@ -55,7 +51,6 @@ public class Patient extends Person {
* @param dateOfBirth Date of birth of the patient.
* @param careLevel Care level of the patient.
* @param roomNumber Room number of the patient.
* @param assets Assets of the patient.
*/
public Patient(
long pid,
@ -63,15 +58,13 @@ public class Patient extends Person {
String surname,
LocalDate dateOfBirth,
String careLevel,
String roomNumber,
String assets
String roomNumber
) {
super(firstName, surname);
this.pid = new SimpleLongProperty(pid);
this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth));
this.careLevel = new SimpleStringProperty(careLevel);
this.roomNumber = new SimpleStringProperty(roomNumber);
this.assets = new SimpleStringProperty(assets);
}
public long getPid() {
@ -124,17 +117,6 @@ public class Patient extends Person {
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.
@ -157,7 +139,6 @@ public class Patient extends Person {
"\nBirthday: " + this.dateOfBirth +
"\nCarelevel: " + this.careLevel +
"\nRoomnumber: " + this.roomNumber +
"\nAssets: " + this.assets +
"\n";
}
}

View file

@ -23,7 +23,6 @@
<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="columnRoomNumber" onEditCommit="#handleOnEditRoomNumber" prefWidth="75.0" text="Raum" />
<TableColumn fx:id="columnAssets" onEditCommit="#handleOnEditAssets" prefWidth="75.0" text="Vermögensstand" />
</columns>
<columnResizePolicy>
<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="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="textFieldAssets" minWidth="160.0" prefWidth="160.0" promptText="Vermögensstand" GridPane.columnIndex="2" GridPane.rowIndex="1" />
</children>
<padding>
<Insets right="10.0" />