#10 story/pfleger-modul-sperren-und-loschen-von-pflegern #37

Merged
SZUT-Dorian merged 11 commits from story/pfleger-modul-sperren-und-loschen-von-pflegern into main 2024-05-16 11:57:12 +00:00
4 changed files with 53 additions and 7 deletions
Showing only changes of commit 353146cbd7 - Show all commits

Binary file not shown.

View file

@ -2,9 +2,13 @@ package de.hitec.nhplus.nurse;
import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.nurse.database.NurseDao;
import de.hitec.nhplus.treatment.Treatment;
import de.hitec.nhplus.treatment.database.TreatmentDao;
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;
@ -13,6 +17,11 @@ 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;
public class LockedNurseController {
SZUT-Dominik marked this conversation as resolved
Review
  • Author alleine reicht Heidemann hier nicht, kurze Beschreibung wie bei den anderen Controllern hier hin, muss nix Langes sein.
- [x] Author alleine reicht Heidemann hier nicht, kurze Beschreibung wie bei den anderen Controllern hier hin, muss nix Langes sein.
@FXML
@ -33,7 +42,9 @@ public class LockedNurseController {
public TableColumn<Nurse, String> columnDeleteDate;
private final ObservableList<Nurse> nurses = FXCollections.observableArrayList();
private final Map<Nurse, List<Treatment>> treatmentsPerNurse = new HashMap<>();
private NurseDao dao;
private TreatmentDao treatmentDao;
public void initialize() {
this.readAllAndShowInTableView();
@ -49,20 +60,32 @@ public class LockedNurseController {
this.columnPhoneNumber.setCellValueFactory(new PropertyValueFactory<>("phoneNumber"));
this.columnPhoneNumber.setCellFactory(TextFieldTableCell.forTableColumn());
this.columnDeleteDate.setCellValueFactory(cellData -> {
return new SimpleStringProperty(cellData.getValue().calculateDeleteDate());
});
this.columnDeleteDate.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().calculateDeleteDate(treatmentsPerNurse.get(cellData.getValue()))));
//this.columnDeleteDate.setCellFactory(TextFieldTableCell.forTableColumn());
buttonDelete.setDisable(true);
this.tableView.setItems(this.nurses);
}
private void readAllAndShowInTableView() {
SZUT-Dominik marked this conversation as resolved
Review
  • Refernz für Nurse hier bitte rein {@link Nurse}
- [x] Refernz für Nurse hier bitte rein {@link Nurse}
this.nurses.clear();
this.treatmentsPerNurse.clear();
this.dao = DaoFactory.getInstance().createNurseDAO();
this.treatmentDao = DaoFactory.getInstance().createTreatmentDao();
try {
this.nurses.addAll(this.dao.readAllLocked());
this.nurses.forEach(
nurse -> {
try {
this.treatmentsPerNurse.put(nurse, this.treatmentDao.readTreatmentsByNurse(nurse.getId()));
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
);
} catch (SQLException exception) {
exception.printStackTrace();
}
@ -80,6 +103,14 @@ public class LockedNurseController {
exception.printStackTrace();
}
readAllAndShowInTableView();
}
@FXML
public void handleMouseClick() {
Nurse nurse = tableView.getSelectionModel().getSelectedItem();
buttonDelete.setDisable(!(DateConverter.convertStringToLocalDate(nurse.calculateDeleteDate(treatmentsPerNurse.get(nurse))).isBefore(LocalDate.now())));
}
@FXML

View file

@ -1,10 +1,15 @@
package de.hitec.nhplus.nurse;
import de.hitec.nhplus.main.Person;
import de.hitec.nhplus.treatment.Treatment;
import de.hitec.nhplus.utils.DateConverter;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.StringJoiner;
/**
@ -33,6 +38,7 @@ public class Nurse extends Person {
this.phoneNumber = new SimpleStringProperty(phoneNumber);
this.locked = new SimpleBooleanProperty(false);
}
public Nurse(
String firstName,
String surName,
@ -60,9 +66,17 @@ public class Nurse extends Person {
this.locked = new SimpleBooleanProperty(isLocked);
}
public String calculateDeleteDate() {
//TODO: Lese alle Behandlungen die Dieser Pfleger Durchgefürt hat & brechene mit ihnen das Datum
return "Comming soon";
public String calculateDeleteDate(List<Treatment> treatments) {
LocalDate today = LocalDate.now();
LocalDate newestDate = LocalDate.of(1980, 1, 1);
for (Treatment treatment : treatments) {
if (DateConverter.convertStringToLocalDate(treatment.getDate()).isAfter(newestDate)) {
newestDate = DateConverter.convertStringToLocalDate(treatment.getDate());
}
}
return DateConverter.convertLocalDateToString(newestDate.plusYears(10));
}
public void setPhoneNumber(String phoneNumber) {

View file

@ -12,7 +12,7 @@
<Insets top="8" left="8" right="8" bottom="8"/>
</padding>
<center>
<TableView fx:id="tableView" layoutX="31.0" layoutY="40">
<TableView fx:id="tableView" layoutX="31.0" layoutY="40" onMouseClicked="#handleMouseClick" >
<columns>
<TableColumn
fx:id="columnId"
@ -74,6 +74,7 @@
onAction="#handleDelete"
prefWidth="90.0"
text="Löschen"
/>
</HBox>
</right>