From 4d6b0c76c3ad90ee1a5cf9b7841d5b0fd46783b6 Mon Sep 17 00:00:00 2001 From: arminribic Date: Tue, 23 Apr 2024 14:15:39 +0200 Subject: [PATCH] #6: deleting patient assets. --- db/nursingHome.db | Bin 16384 -> 16384 bytes .../controller/AllPatientController.java | 125 ++++++------------ .../hitec/nhplus/datastorage/PatientDao.java | 14 +- .../hitec/nhplus/fixtures/PatientFixture.java | 21 +-- .../java/de/hitec/nhplus/model/Patient.java | 59 +++------ .../de/hitec/nhplus/AllPatientView.fxml | 2 - 6 files changed, 71 insertions(+), 150 deletions(-) diff --git a/db/nursingHome.db b/db/nursingHome.db index c3696b835772e8cd9917759693a7968f576437cf..fbd08333f7accb96ed84b67eae167f5eb8350dca 100644 GIT binary patch delta 407 zcmZo@U~Fh$oFFZ@l!1YP1&ColZlaDcP*AUEAur!w24>z22ENt&VjBy7@i201&gPxO zs0>soDK0I|*c@Jxn3R)RkjTct2G-q}&dv^&P@T-qe_vLU7bwcb^?`w3h)KYmWk&%Icp#lp#gSaG6#pD=!NnK@T zb_QvXdiT_#lA_WSx1z+ns#KsB6H8qK6J0|yV*>*tWhRKC$s6otIh7fK`sG3TZ`sQL E0GJeA)Bpeg delta 443 zcmZo@U~Fh$oFFY&%fP_E0>m&NHc`hID5#grzzY;&=FMQ>Tg~@(W5F*TMwZRlyptHY zni!bb#igYgo5Lq7@ZUGnQ2>I(;^NejVucXbh!O=q{}2VgP#+&nkO5p=ZyERn_|$l} z@ka8T=PBZ0;=aP|#r1Y$<3+B`AEd09xzm|A88{Wi#pRp%C!5Lv&7XW+&WAgf5hf}< zSx!EKQDJhMyf#p7qkI52&{!t^Ck*_b`JZeSR5;8(ae}A;FB7voV@XkJVo7dlUI`aB zBeOJPL1IZJki!OY2OHm42L22D%lWJMgZLHrz5+Eqv@|i)H89dOGBP$WG|tN}%1zACV&-6w1{p0md6vBlKSWTS2`V^wpS`ScVo|Oh mBhWZ`pen`S)PjN>kJO^1)S~p%BA|(2Hy9Y27#SELtOo!jUU69f diff --git a/src/main/java/de/hitec/nhplus/controller/AllPatientController.java b/src/main/java/de/hitec/nhplus/controller/AllPatientController.java index 9aa813f..bdd5f92 100644 --- a/src/main/java/de/hitec/nhplus/controller/AllPatientController.java +++ b/src/main/java/de/hitec/nhplus/controller/AllPatientController.java @@ -20,8 +20,7 @@ import java.time.LocalDate; import static de.hitec.nhplus.utils.Validator.*; -public class AllPatientController -{ +public class AllPatientController { @FXML private TableView tableView; @@ -38,8 +37,6 @@ public class AllPatientController @FXML private TableColumn columnRoomNumber; @FXML - private TableColumn 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 patients = FXCollections.observableArrayList(); private PatientDao dao; - public void initialize() - { + public void initialize() { this.readAllAndShowInTableView(); this.columnId.setCellValueFactory(new PropertyValueFactory<>("pid")); @@ -80,31 +74,28 @@ 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); this.buttonDelete.setDisable(true); this.tableView - .getSelectionModel() - .selectedItemProperty() - .addListener((observableValue, oldPatient, newPatient) -> - { - AllPatientController.this.buttonDelete.setDisable(newPatient == null); - } - ); + .getSelectionModel() + .selectedItemProperty() + .addListener((observableValue, oldPatient, newPatient) -> + { + AllPatientController.this.buttonDelete.setDisable(newPatient == null); + } + ); this.buttonAdd.setDisable(true); ChangeListener inputNewPatientValidationListener = (observableValue, oldText, newText) -> { boolean isValid = isValidDate(this.textFieldDateOfBirth.getText()) - && isValidFirstName(this.textFieldFirstName.getText()) - && isValidSurName(this.textFieldSurname.getText()) - && isValidDate(this.textFieldDateOfBirth.getText()) - && isValidCareLevel(this.textFieldCareLevel.getText()) - && isValidRoomNumber(textFieldRoomNumber.getText()) - && !this.textFieldAssets.getText().isBlank(); + && isValidFirstName(this.textFieldFirstName.getText()) + && isValidSurName(this.textFieldSurname.getText()) + && isValidDate(this.textFieldDateOfBirth.getText()) + && isValidCareLevel(this.textFieldCareLevel.getText()) + && 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 event) - { + public void handleOnEditFirstname(TableColumn.CellEditEvent 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 event) - { + public void handleOnEditSurname(TableColumn.CellEditEvent 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 event) - { + public void handleOnEditDateOfBirth(TableColumn.CellEditEvent 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 event) - { + public void handleOnEditCareLevel(TableColumn.CellEditEvent 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 event) - { + public void handleOnEditRoomNumber(TableColumn.CellEditEvent 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 event) - { - String newAssets = event.getNewValue(); - if(newAssets.isBlank()){ - event.getTableView().refresh(); - return; - } - event.getRowValue().setAssets(newAssets); - this.doUpdate(event); - } - private void doUpdate(TableColumn.CellEditEvent event) - { - try - { + private void doUpdate(TableColumn.CellEditEvent 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(); } } diff --git a/src/main/java/de/hitec/nhplus/datastorage/PatientDao.java b/src/main/java/de/hitec/nhplus/datastorage/PatientDao.java index 7ce270c..803286b 100644 --- a/src/main/java/de/hitec/nhplus/datastorage/PatientDao.java +++ b/src/main/java/de/hitec/nhplus/datastorage/PatientDao.java @@ -32,15 +32,14 @@ public class PatientDao extends DaoImp { 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 { 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 { 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 { "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 { 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(); } diff --git a/src/main/java/de/hitec/nhplus/fixtures/PatientFixture.java b/src/main/java/de/hitec/nhplus/fixtures/PatientFixture.java index 2ab631a..d4574ee 100644 --- a/src/main/java/de/hitec/nhplus/fixtures/PatientFixture.java +++ b/src/main/java/de/hitec/nhplus/fixtures/PatientFixture.java @@ -37,8 +37,7 @@ public class PatientFixture implements Fixture " 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 "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(); diff --git a/src/main/java/de/hitec/nhplus/model/Patient.java b/src/main/java/de/hitec/nhplus/model/Patient.java index ac110af..43d6d8f 100644 --- a/src/main/java/de/hitec/nhplus/model/Patient.java +++ b/src/main/java/de/hitec/nhplus/model/Patient.java @@ -16,62 +16,55 @@ public class Patient extends Person { private final SimpleStringProperty dateOfBirth; private final SimpleStringProperty careLevel; private final SimpleStringProperty roomNumber; - private final SimpleStringProperty assets; private final List allTreatments = new ArrayList<>(); /** * Constructor to initiate an object of class Patient with the given parameter. Use this constructor * 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 surname Last name of the patient. + * @param firstName First name of the patient. + * @param surname Last name of the patient. * @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. + * @param careLevel Care level of the patient. + * @param roomNumber Room number of the patient. */ public Patient( - String firstName, - String surname, - LocalDate dateOfBirth, - String careLevel, - String roomNumber, - String assets + String firstName, + String surname, + LocalDate dateOfBirth, + String careLevel, + 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); } /** * Constructor to initiate an object of class Patient with the given parameter. Use this constructor * to initiate objects, which are already persisted and have a patient id (pid). * - * @param pid Patient id. - * @param firstName First name of the patient. - * @param surname Last name of the patient. + * @param pid Patient id. + * @param firstName First name of the patient. + * @param surname Last name of the patient. * @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. + * @param careLevel Care level of the patient. + * @param roomNumber Room number of the patient. */ public Patient( - long pid, - String firstName, - String surname, - LocalDate dateOfBirth, - String careLevel, - String roomNumber, - String assets + long pid, + String firstName, + String surname, + LocalDate dateOfBirth, + String careLevel, + 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"; } } diff --git a/src/main/resources/de/hitec/nhplus/AllPatientView.fxml b/src/main/resources/de/hitec/nhplus/AllPatientView.fxml index 396e444..8b93fd1 100644 --- a/src/main/resources/de/hitec/nhplus/AllPatientView.fxml +++ b/src/main/resources/de/hitec/nhplus/AllPatientView.fxml @@ -23,7 +23,6 @@ - @@ -47,7 +46,6 @@ - -- 2.45.2