From d8de1e17fa2375d5970c6ff77e58d1fcbd64ac97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Thu, 16 May 2024 10:37:55 +0200 Subject: [PATCH] #10: Cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dominik Säume --- .../nhplus/nurse/LockedNurseController.java | 18 ++++----------- .../java/de/hitec/nhplus/nurse/Nurse.java | 23 ++++++++++++++----- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/main/java/de/hitec/nhplus/nurse/LockedNurseController.java b/src/main/java/de/hitec/nhplus/nurse/LockedNurseController.java index 02746e5..f1f5187 100644 --- a/src/main/java/de/hitec/nhplus/nurse/LockedNurseController.java +++ b/src/main/java/de/hitec/nhplus/nurse/LockedNurseController.java @@ -8,17 +8,14 @@ import de.hitec.nhplus.utils.DateConverter; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import javafx.collections.ObservableMap; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; -import javafx.scene.control.cell.TextFieldTableCell; import java.sql.SQLException; import java.time.LocalDate; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -50,18 +47,12 @@ public class LockedNurseController { this.readAllAndShowInTableView(); this.columnId.setCellValueFactory(new PropertyValueFactory<>("id")); - this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName")); - this.columnFirstName.setCellFactory(TextFieldTableCell.forTableColumn()); - this.columnSurName.setCellValueFactory(new PropertyValueFactory<>("surName")); - this.columnSurName.setCellFactory(TextFieldTableCell.forTableColumn()); - this.columnPhoneNumber.setCellValueFactory(new PropertyValueFactory<>("phoneNumber")); - this.columnPhoneNumber.setCellFactory(TextFieldTableCell.forTableColumn()); - - this.columnDeleteDate.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().calculateDeleteDate(treatmentsPerNurse.get(cellData.getValue())))); - //this.columnDeleteDate.setCellFactory(TextFieldTableCell.forTableColumn()); + this.columnDeleteDate.setCellValueFactory(cellData -> new SimpleStringProperty( + DateConverter.convertLocalDateToString(cellData.getValue().calculateDeleteDate())) + ); buttonDelete.setDisable(true); @@ -110,7 +101,8 @@ public class LockedNurseController { @FXML public void handleMouseClick() { Nurse nurse = tableView.getSelectionModel().getSelectedItem(); - buttonDelete.setDisable(!(DateConverter.convertStringToLocalDate(nurse.calculateDeleteDate(treatmentsPerNurse.get(nurse))).isBefore(LocalDate.now()))); + boolean canBeDeleted = nurse.calculateDeleteDate().isBefore(LocalDate.now()); + buttonDelete.setDisable(!canBeDeleted); } @FXML diff --git a/src/main/java/de/hitec/nhplus/nurse/Nurse.java b/src/main/java/de/hitec/nhplus/nurse/Nurse.java index 6da3b08..4cfca53 100644 --- a/src/main/java/de/hitec/nhplus/nurse/Nurse.java +++ b/src/main/java/de/hitec/nhplus/nurse/Nurse.java @@ -1,5 +1,6 @@ package de.hitec.nhplus.nurse; +import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.main.Person; import de.hitec.nhplus.treatment.Treatment; import de.hitec.nhplus.utils.DateConverter; @@ -7,6 +8,7 @@ import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; +import java.sql.SQLException; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.List; @@ -66,17 +68,26 @@ public class Nurse extends Person { this.locked = new SimpleBooleanProperty(isLocked); } - public String calculateDeleteDate(List treatments) { - LocalDate today = LocalDate.now(); + public LocalDate calculateDeleteDate() { + List treatments; + try { + treatments = DaoFactory.getInstance().createTreatmentDao().readTreatmentsByNurse(this.getId()); + }catch (SQLException exception){ + treatments = null; + } + if(treatments == null){ + return LocalDate.now().plusDays(1); + } + LocalDate newestDate = LocalDate.of(1980, 1, 1); for (Treatment treatment : treatments) { - if (DateConverter.convertStringToLocalDate(treatment.getDate()).isAfter(newestDate)) { - newestDate = DateConverter.convertStringToLocalDate(treatment.getDate()); + LocalDate date = DateConverter.convertStringToLocalDate(treatment.getDate()); + if (date.isAfter(newestDate)) { + newestDate = date; } } - - return DateConverter.convertLocalDateToString(newestDate.plusYears(10)); + return newestDate.plusYears(10); } public void setPhoneNumber(String phoneNumber) {