parent
353146cbd7
commit
d8de1e17fa
2 changed files with 22 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -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<Treatment> treatments) {
|
||||
LocalDate today = LocalDate.now();
|
||||
public LocalDate calculateDeleteDate() {
|
||||
List<Treatment> 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) {
|
||||
|
|
Loading…
Reference in a new issue