From 353146cbd793e78538143ed9807ef8c327d9c49b Mon Sep 17 00:00:00 2001 From: arminribic Date: Thu, 16 May 2024 10:20:23 +0200 Subject: [PATCH] #10: Deletedate calculated & DeletreBurtton enabled/disabled --- db/nursingHome.db | Bin 20480 -> 28672 bytes .../nhplus/nurse/LockedNurseController.java | 37 ++++++++++++++++-- .../java/de/hitec/nhplus/nurse/Nurse.java | 20 ++++++++-- .../hitec/nhplus/nurse/LockedNurseView.fxml | 3 +- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/db/nursingHome.db b/db/nursingHome.db index e381a1f87f2d2e69154d7668a6e22ccb3f3c8bb7..df596e05e2ebebaf5fb16a358f7204e2cf400f90 100644 GIT binary patch delta 2215 zcmZ`)U2NM_6!wi1XSNexLYrkJ>*7#ttfJYHwAniTM%sB@Mf#(rFl{iSd}`DzxO-?$ed?=PFwJZyI zS9Hu$y+^&Z3)1l8^l&hiNT8<%+-W)CUXbg9tYz7B+H2Z%+UEWt|2DneyZ>~o8}y&H zb>`NaIX9~w(Fz*)Rn*oEkcQ83cV4~}eh|q*Ug+$YRpTzVAOEV#(i(>&%AW8$;rl|L zh79>H`BV9@^pmtEt-w`$YjwZW9#TXOp=2x;i3I)GbapJ2&ZV;H%-C(Yu}to^bS^)U zpGbzgAdF=XlOnGxfM+b-flN#!gt|Lc+0Q38p5g2XVv3KU zj(vV`MiF~aiccQlHV@cdMLz!KwjV@B#8O7s(`HDfS)XJvEGr3&UFL2R#w6oG(NRMZ8P+G!$b8g{)SA9$&9^*IoGkgWV zjGw`eV2T&<6duPnV@df_xu$%je5|~uyrx`Go={FJ1hVc{+6O@B;81^zM=4>3R2jAP zR>O8EffFrn=TTfJI#(}Rbt*@_L4njA)24m>Ji1jlPOJ*CbjFBdLDUU>JlY+|*U4Eh zr`l>XbooYz32YEVyg`>Bb_0(_0|nY%Hl5lT%UtQPNSH?h{^P{9sTEOpbc=t2va@Fl zV${u=X>1SkDC5_dxk8#=?$qph^8OH1z;CS}Eb}PAPg28Z86aDhKmy;DfJGh+wfUmn zSSGduMza2Gz~S4<(HDeTeUro}L5cXb()p-O&Bew#j2EzsNN&Bs#o8K#?D#9 zVB>)xw|gKTMFsk=2}Q!n=GkM^I%^Tz3!9>+^-|5Tm#Jm6Y{!c{dE6i5k^|KY@@#0Y z`v8GvMcNWgw_VTG09K!pa06^uG*4H7E>Wv#nM-Z&tG(BzhC|t~CvX0!59H-0qniv_q{~E|uMw+3 zN)!^7h+!8?wbME)Q)5JRpv`s4K;to}kur~ld%l3+3=h#L>KT&vK6EDmSRz+nTB1gs e>dxK~^+?Mq)hfgQCU0*M2Tnj4wwtWae}mDQJXQI&2yiDng1{k|117;{D*-qn#@0Of>{*(NxAeIMkvdA*CF-%_P9|QnrhHAC| diff --git a/src/main/java/de/hitec/nhplus/nurse/LockedNurseController.java b/src/main/java/de/hitec/nhplus/nurse/LockedNurseController.java index 22fd6cd..02746e5 100644 --- a/src/main/java/de/hitec/nhplus/nurse/LockedNurseController.java +++ b/src/main/java/de/hitec/nhplus/nurse/LockedNurseController.java @@ -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 { @FXML @@ -33,7 +42,9 @@ public class LockedNurseController { public TableColumn columnDeleteDate; private final ObservableList nurses = FXCollections.observableArrayList(); + private final Map> 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() { 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 diff --git a/src/main/java/de/hitec/nhplus/nurse/Nurse.java b/src/main/java/de/hitec/nhplus/nurse/Nurse.java index 6d76adc..6da3b08 100644 --- a/src/main/java/de/hitec/nhplus/nurse/Nurse.java +++ b/src/main/java/de/hitec/nhplus/nurse/Nurse.java @@ -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 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) { diff --git a/src/main/resources/de/hitec/nhplus/nurse/LockedNurseView.fxml b/src/main/resources/de/hitec/nhplus/nurse/LockedNurseView.fxml index c62dd2a..c17e83c 100644 --- a/src/main/resources/de/hitec/nhplus/nurse/LockedNurseView.fxml +++ b/src/main/resources/de/hitec/nhplus/nurse/LockedNurseView.fxml @@ -12,7 +12,7 @@
- +