#10 story/pfleger-modul-sperren-und-loschen-von-pflegern #37
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.beans.property.SimpleStringProperty;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.collections.ObservableMap;
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
import javafx.scene.control.cell.PropertyValueFactory;
|
import javafx.scene.control.cell.PropertyValueFactory;
|
||||||
import javafx.scene.control.cell.TextFieldTableCell;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -50,18 +47,12 @@ public class LockedNurseController {
|
||||||
this.readAllAndShowInTableView();
|
this.readAllAndShowInTableView();
|
||||||
|
|
||||||
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
|
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
|
||||||
|
|
||||||
this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
|
this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
|
||||||
this.columnFirstName.setCellFactory(TextFieldTableCell.forTableColumn());
|
|
||||||
|
|
||||||
this.columnSurName.setCellValueFactory(new PropertyValueFactory<>("surName"));
|
this.columnSurName.setCellValueFactory(new PropertyValueFactory<>("surName"));
|
||||||
this.columnSurName.setCellFactory(TextFieldTableCell.forTableColumn());
|
|
||||||
|
|
||||||
this.columnPhoneNumber.setCellValueFactory(new PropertyValueFactory<>("phoneNumber"));
|
this.columnPhoneNumber.setCellValueFactory(new PropertyValueFactory<>("phoneNumber"));
|
||||||
this.columnPhoneNumber.setCellFactory(TextFieldTableCell.forTableColumn());
|
this.columnDeleteDate.setCellValueFactory(cellData -> new SimpleStringProperty(
|
||||||
|
DateConverter.convertLocalDateToString(cellData.getValue().calculateDeleteDate()))
|
||||||
this.columnDeleteDate.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().calculateDeleteDate(treatmentsPerNurse.get(cellData.getValue()))));
|
);
|
||||||
//this.columnDeleteDate.setCellFactory(TextFieldTableCell.forTableColumn());
|
|
||||||
|
|
||||||
buttonDelete.setDisable(true);
|
buttonDelete.setDisable(true);
|
||||||
|
|
||||||
|
@ -110,7 +101,8 @@ public class LockedNurseController {
|
||||||
@FXML
|
@FXML
|
||||||
public void handleMouseClick() {
|
public void handleMouseClick() {
|
||||||
Nurse nurse = tableView.getSelectionModel().getSelectedItem();
|
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
|
@FXML
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package de.hitec.nhplus.nurse;
|
package de.hitec.nhplus.nurse;
|
||||||
|
|
||||||
|
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||||
import de.hitec.nhplus.main.Person;
|
import de.hitec.nhplus.main.Person;
|
||||||
import de.hitec.nhplus.treatment.Treatment;
|
import de.hitec.nhplus.treatment.Treatment;
|
||||||
import de.hitec.nhplus.utils.DateConverter;
|
import de.hitec.nhplus.utils.DateConverter;
|
||||||
|
@ -7,6 +8,7 @@ import javafx.beans.property.SimpleBooleanProperty;
|
||||||
import javafx.beans.property.SimpleIntegerProperty;
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -66,17 +68,26 @@ public class Nurse extends Person {
|
||||||
this.locked = new SimpleBooleanProperty(isLocked);
|
this.locked = new SimpleBooleanProperty(isLocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String calculateDeleteDate(List<Treatment> treatments) {
|
public LocalDate calculateDeleteDate() {
|
||||||
LocalDate today = LocalDate.now();
|
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);
|
LocalDate newestDate = LocalDate.of(1980, 1, 1);
|
||||||
for (Treatment treatment : treatments) {
|
for (Treatment treatment : treatments) {
|
||||||
if (DateConverter.convertStringToLocalDate(treatment.getDate()).isAfter(newestDate)) {
|
LocalDate date = DateConverter.convertStringToLocalDate(treatment.getDate());
|
||||||
newestDate = DateConverter.convertStringToLocalDate(treatment.getDate());
|
if (date.isAfter(newestDate)) {
|
||||||
|
newestDate = date;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return newestDate.plusYears(10);
|
||||||
return DateConverter.convertLocalDateToString(newestDate.plusYears(10));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPhoneNumber(String phoneNumber) {
|
public void setPhoneNumber(String phoneNumber) {
|
||||||
|
|
Loading…
Reference in a new issue