From fcca90288c52bb2ef5232b33672b4de827255aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Mon, 29 Apr 2024 11:20:02 +0200 Subject: [PATCH] NOTICKET: Cleanup Treatment Views and Controllers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dominik Säume --- src/main/java/de/hitec/nhplus/Main.java | 1 - .../treatment/AllTreatmentController.java | 64 ++++++-- .../treatment/NewTreatmentController.java | 138 ----------------- .../de/hitec/nhplus/treatment/Treatment.java | 8 +- .../nhplus/treatment/TreatmentController.java | 120 --------------- .../treatment/TreatmentModalController.java | 143 ++++++++++++++++++ .../hitec/nhplus/patient/AllPatientView.fxml | 10 +- .../nhplus/treatment/AllTreatmentView.fxml | 13 +- .../nhplus/treatment/NewTreatmentView.fxml | 87 ----------- .../nhplus/treatment/TreatmentModal.fxml | 127 ++++++++++++++++ .../hitec/nhplus/treatment/TreatmentView.fxml | 88 ----------- 11 files changed, 332 insertions(+), 467 deletions(-) delete mode 100644 src/main/java/de/hitec/nhplus/treatment/NewTreatmentController.java delete mode 100644 src/main/java/de/hitec/nhplus/treatment/TreatmentController.java create mode 100644 src/main/java/de/hitec/nhplus/treatment/TreatmentModalController.java delete mode 100644 src/main/resources/de/hitec/nhplus/treatment/NewTreatmentView.fxml create mode 100644 src/main/resources/de/hitec/nhplus/treatment/TreatmentModal.fxml delete mode 100644 src/main/resources/de/hitec/nhplus/treatment/TreatmentView.fxml diff --git a/src/main/java/de/hitec/nhplus/Main.java b/src/main/java/de/hitec/nhplus/Main.java index 54ef1bc..bab1c27 100644 --- a/src/main/java/de/hitec/nhplus/Main.java +++ b/src/main/java/de/hitec/nhplus/Main.java @@ -7,7 +7,6 @@ import javafx.application.Platform; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.control.TabPane; -import javafx.scene.layout.BorderPane; import javafx.stage.Stage; import java.io.IOException; diff --git a/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java b/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java index 1e4f8a9..919433b 100644 --- a/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java +++ b/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java @@ -11,7 +11,7 @@ import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.control.cell.PropertyValueFactory; -import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.BorderPane; import javafx.stage.Stage; import java.io.IOException; @@ -176,19 +176,24 @@ public class AllTreatmentController { public void newTreatmentWindow(Patient patient) { try { FXMLLoader loader = new FXMLLoader( - Main.class.getResource("/de/hitec/nhplus/treatment/NewTreatmentView.fxml") + Main.class.getResource("/de/hitec/nhplus/treatment/TreatmentModal.fxml") ); - AnchorPane pane = loader.load(); + BorderPane pane = loader.load(); Scene scene = new Scene(pane); - - // the primary stage should stay in the background Stage stage = new Stage(); - NewTreatmentController controller = loader.getController(); - controller.initialize(this, stage, patient); + TreatmentModalController controller = loader.getController(); + controller.initialize( + this, + stage, + null, + patient + ); stage.setScene(scene); - stage.setResizable(false); + stage.setTitle("NHPlus - Neue Behandlung"); + stage.setResizable(true); + stage.setAlwaysOnTop(true); stage.showAndWait(); } catch (IOException exception) { exception.printStackTrace(); @@ -197,19 +202,46 @@ public class AllTreatmentController { public void treatmentWindow(Treatment treatment) { try { - FXMLLoader loader = new FXMLLoader(Main.class.getResource("/de/hitec/nhplus/treatment/TreatmentView.fxml")); - AnchorPane pane = loader.load(); + FXMLLoader loader = new FXMLLoader( + Main.class.getResource("/de/hitec/nhplus/treatment/TreatmentModal.fxml") + ); + BorderPane pane = loader.load(); Scene scene = new Scene(pane); - - // the primary stage should stay in the background Stage stage = new Stage(); - TreatmentController controller = loader.getController(); - controller.initializeController(this, stage, treatment); + + TreatmentModalController controller = loader.getController(); + PatientDao pDao = DaoFactory.getDaoFactory().createPatientDAO(); + controller.initialize( + this, + stage, + treatment, + pDao.read(treatment.getPatientId()) + ); stage.setScene(scene); - stage.setResizable(false); + stage.setTitle("NHPlus - Behandlung"); + stage.setResizable(true); + stage.setAlwaysOnTop(true); stage.showAndWait(); - } catch (IOException exception) { + } catch (IOException | SQLException exception) { + exception.printStackTrace(); + } + } + + public void createTreatment(Treatment treatment) { + TreatmentDao dao = DaoFactory.getDaoFactory().createTreatmentDao(); + try { + dao.create(treatment); + } catch (SQLException exception) { + exception.printStackTrace(); + } + } + + public void updateTreatment(Treatment treatment) { + TreatmentDao dao = DaoFactory.getDaoFactory().createTreatmentDao(); + try { + dao.update(treatment); + } catch (SQLException exception) { exception.printStackTrace(); } } diff --git a/src/main/java/de/hitec/nhplus/treatment/NewTreatmentController.java b/src/main/java/de/hitec/nhplus/treatment/NewTreatmentController.java deleted file mode 100644 index a1053ab..0000000 --- a/src/main/java/de/hitec/nhplus/treatment/NewTreatmentController.java +++ /dev/null @@ -1,138 +0,0 @@ -package de.hitec.nhplus.treatment; - -import de.hitec.nhplus.datastorage.DaoFactory; -import de.hitec.nhplus.patient.Patient; -import de.hitec.nhplus.utils.DateConverter; -import javafx.beans.value.ChangeListener; -import javafx.fxml.FXML; -import javafx.scene.control.*; -import javafx.stage.Stage; -import javafx.util.StringConverter; - -import java.sql.SQLException; -import java.time.LocalDate; -import java.time.LocalTime; - -import static de.hitec.nhplus.utils.Validator.*; - -public class NewTreatmentController -{ - - @FXML - private Label labelFirstName; - - @FXML - private Label labelSurname; - - @FXML - private TextField textFieldBegin; - - @FXML - private TextField textFieldEnd; - - @FXML - private TextField textFieldDescription; - - @FXML - private TextArea textAreaRemarks; - - @FXML - private DatePicker datePicker; - - @FXML - private Button buttonAdd; - - private AllTreatmentController controller; - private Patient patient; - private Stage stage; - - public void initialize(AllTreatmentController controller, Stage stage, Patient patient) - { - this.controller = controller; - this.patient = patient; - this.stage = stage; - - this.buttonAdd.setDisable(true); - ChangeListener inputNewTreatmentTextValidationListener = (observableValue, oldText, newText) -> - { - boolean isValid = isValidDate(this.datePicker.getValue()) - && isValidTimeRange(this.textFieldBegin.getText(), this.textFieldEnd.getText()) - && isValidDescription(this.textFieldDescription.getText()); - - NewTreatmentController.this.buttonAdd.setDisable(!isValid); - }; - ChangeListener inputNewTreatmentDateValidationListener = (observableValue, localDate, t1) -> - { - boolean isValid = isValidDate(this.datePicker.getValue()) - && isValidTimeRange(this.textFieldBegin.getText(), this.textFieldEnd.getText()) - && isValidDescription(this.textFieldDescription.getText()); - - NewTreatmentController.this.buttonAdd.setDisable(!isValid); - }; - - this.textFieldBegin.textProperty().addListener(inputNewTreatmentTextValidationListener); - this.textFieldEnd.textProperty().addListener(inputNewTreatmentTextValidationListener); - this.textFieldDescription.textProperty().addListener(inputNewTreatmentTextValidationListener); - this.textAreaRemarks.textProperty().addListener(inputNewTreatmentTextValidationListener); - this.datePicker.valueProperty().addListener(inputNewTreatmentDateValidationListener); - - this.datePicker.setConverter(new StringConverter<>() - { - @Override - public String toString(LocalDate localDate) - { - return (localDate == null) ? "" : DateConverter.convertLocalDateToString(localDate); - } - - @Override - public LocalDate fromString(String localDate) - { - if (!isValidDate(localDate)) - { - return null; - } - return DateConverter.convertStringToLocalDate(localDate); - } - }); - this.showPatientData(); - } - - private void showPatientData() - { - this.labelFirstName.setText(patient.getFirstName()); - this.labelSurname.setText(patient.getSurname()); - } - - @FXML - public void handleAdd() - { - LocalDate date = this.datePicker.getValue(); - LocalTime begin = DateConverter.convertStringToLocalTime(textFieldBegin.getText()); - LocalTime end = DateConverter.convertStringToLocalTime(textFieldEnd.getText()); - String description = textFieldDescription.getText(); - String remarks = textAreaRemarks.getText(); - Treatment treatment = new Treatment(patient.getId(), date, begin, end, description, remarks); - createTreatment(treatment); - controller.readAllAndShowInTableView(); - stage.close(); - } - - private void createTreatment(Treatment treatment) - { - TreatmentDao dao = DaoFactory.getDaoFactory().createTreatmentDao(); - try - { - dao.create(treatment); - } catch (SQLException exception) - { - exception.printStackTrace(); - } - } - - @FXML - public void handleCancel() - { - stage.close(); - } - -} diff --git a/src/main/java/de/hitec/nhplus/treatment/Treatment.java b/src/main/java/de/hitec/nhplus/treatment/Treatment.java index 57d73b6..df6b831 100644 --- a/src/main/java/de/hitec/nhplus/treatment/Treatment.java +++ b/src/main/java/de/hitec/nhplus/treatment/Treatment.java @@ -59,12 +59,12 @@ public class Treatment { this.date = DateConverter.convertStringToLocalDate(date); } - public void setBegin(String begin) { - this.begin = DateConverter.convertStringToLocalTime(begin); + public void setBegin(LocalTime begin) { + this.begin = begin; } - public void setEnd(String end) { - this.end = DateConverter.convertStringToLocalTime(end); + public void setEnd(LocalTime end) { + this.end = end; } public String getDescription() { diff --git a/src/main/java/de/hitec/nhplus/treatment/TreatmentController.java b/src/main/java/de/hitec/nhplus/treatment/TreatmentController.java deleted file mode 100644 index 08e88cf..0000000 --- a/src/main/java/de/hitec/nhplus/treatment/TreatmentController.java +++ /dev/null @@ -1,120 +0,0 @@ -package de.hitec.nhplus.treatment; - -import de.hitec.nhplus.datastorage.DaoFactory; -import de.hitec.nhplus.patient.PatientDao; -import javafx.fxml.FXML; -import javafx.scene.control.*; -import javafx.stage.Stage; -import de.hitec.nhplus.patient.Patient; -import de.hitec.nhplus.utils.DateConverter; - -import java.sql.SQLException; -import java.time.LocalDate; - -import static de.hitec.nhplus.utils.Validator.*; - -public class TreatmentController { - - @FXML - private Label labelPatientName; - - @FXML - private Label labelCareLevel; - - @FXML - private TextField textFieldBegin; - - @FXML - private TextField textFieldEnd; - - @FXML - private TextField textFieldDescription; - - @FXML - private TextArea textAreaRemarks; - - @FXML - private DatePicker datePicker; - - private AllTreatmentController controller; - private Stage stage; - private Patient patient; - private Treatment treatment; - - public void initializeController(AllTreatmentController controller, Stage stage, Treatment treatment) { - this.stage = stage; - this.controller= controller; - - PatientDao pDao = DaoFactory.getDaoFactory().createPatientDAO(); - try { - this.patient = pDao.read(treatment.getPatientId()); - this.treatment = treatment; - showData(); - } catch (SQLException exception) { - exception.printStackTrace(); - } - } - - private void showData(){ - this.labelPatientName.setText(patient.getSurname()+", "+patient.getFirstName()); - this.labelCareLevel.setText(patient.getCareLevel()); - LocalDate date = DateConverter.convertStringToLocalDate(treatment.getDate()); - this.datePicker.setValue(date); - this.textFieldBegin.setText(this.treatment.getBegin()); - this.textFieldEnd.setText(this.treatment.getEnd()); - this.textFieldDescription.setText(this.treatment.getDescription()); - this.textAreaRemarks.setText(this.treatment.getRemarks()); - } - - @FXML - public void handleChange(){ - LocalDate newDate = this.datePicker.getValue(); - if(!isValidDate(newDate)){ - showValidationError("Date"); - return; - } - - String newDescription = textFieldDescription.getText(); - if(!isValidDescription(newDescription)){ - showValidationError("Description"); - return; - } - - String newBegin = textFieldBegin.getText(); - String newEnd = textFieldEnd.getText(); - if(!isValidTimeRange(newBegin, newEnd)){ - showValidationError("Time Range"); - return; - } - - String newRemarks = textAreaRemarks.getText(); - if(!isValidDescription(newRemarks)){ - showValidationError("Remarks"); - return; - } - - this.treatment.setDate(newDate.toString()); - this.treatment.setDescription(newDescription); - this.treatment.setBegin(newBegin); - this.treatment.setEnd(newEnd); - this.treatment.setRemarks(newRemarks); - - doUpdate(); - controller.readAllAndShowInTableView(); - stage.close(); - } - - private void doUpdate(){ - TreatmentDao dao = DaoFactory.getDaoFactory().createTreatmentDao(); - try { - dao.update(treatment); - } catch (SQLException exception) { - exception.printStackTrace(); - } - } - - @FXML - public void handleCancel(){ - stage.close(); - } -} diff --git a/src/main/java/de/hitec/nhplus/treatment/TreatmentModalController.java b/src/main/java/de/hitec/nhplus/treatment/TreatmentModalController.java new file mode 100644 index 0000000..2d61fae --- /dev/null +++ b/src/main/java/de/hitec/nhplus/treatment/TreatmentModalController.java @@ -0,0 +1,143 @@ +package de.hitec.nhplus.treatment; + +import de.hitec.nhplus.patient.Patient; +import de.hitec.nhplus.utils.DateConverter; +import javafx.beans.value.ChangeListener; +import javafx.fxml.FXML; +import javafx.scene.control.*; +import javafx.stage.Stage; +import javafx.util.StringConverter; + +import java.time.LocalDate; +import java.time.LocalTime; + +import static de.hitec.nhplus.utils.Validator.*; + +public class TreatmentModalController { + @FXML + private Label labelFirstName; + @FXML + private Label labelSurname; + @FXML + private TextField textFieldBegin; + @FXML + private TextField textFieldEnd; + @FXML + private TextField textFieldDescription; + @FXML + private TextArea textAreaRemarks; + @FXML + private DatePicker datePicker; + @FXML + private Button buttonSave; + private AllTreatmentController controller; + private Stage stage; + private Patient patient; + private Treatment treatment; + private boolean isNewTreatment = false; + + public void initialize(AllTreatmentController controller, Stage stage, Treatment treatment, Patient patient) { + this.controller = controller; + this.stage = stage; + this.patient = patient; + if (treatment == null) { + isNewTreatment = true; + LocalTime currentTime = LocalTime.now(); + this.treatment = new Treatment( + patient.getId(), + LocalDate.now(), + LocalTime.of(currentTime.getHour(), currentTime.getMinute()), + LocalTime.of(currentTime.getHour(), currentTime.getMinute()), + "", + "" + ); + this.buttonSave.setDisable(true); + } else { + this.treatment = treatment; + } + showData(); + + ChangeListener inputNewTreatmentTextValidationListener = (observableValue, oldText, newText) -> + { + boolean isValid = isValidDate(this.datePicker.getValue()) + && isValidTimeRange(this.textFieldBegin.getText(), this.textFieldEnd.getText()) + && isValidDescription(this.textFieldDescription.getText()); + + this.buttonSave.setDisable(!isValid); + }; + ChangeListener inputNewTreatmentDateValidationListener = (observableValue, localDate, t1) -> + { + boolean isValid = isValidDate(this.datePicker.getValue()) + && isValidTimeRange(this.textFieldBegin.getText(), this.textFieldEnd.getText()) + && isValidDescription(this.textFieldDescription.getText()); + + this.buttonSave.setDisable(!isValid); + }; + + this.textFieldBegin.textProperty().addListener(inputNewTreatmentTextValidationListener); + this.textFieldEnd.textProperty().addListener(inputNewTreatmentTextValidationListener); + this.textFieldDescription.textProperty().addListener(inputNewTreatmentTextValidationListener); + this.textAreaRemarks.textProperty().addListener(inputNewTreatmentTextValidationListener); + this.datePicker.valueProperty().addListener(inputNewTreatmentDateValidationListener); + + this.datePicker.setConverter(new StringConverter<>() { + @Override + public String toString(LocalDate localDate) { + return (localDate == null) ? "" : DateConverter.convertLocalDateToString(localDate); + } + + @Override + public LocalDate fromString(String localDate) { + if (!isValidDate(localDate)) { + return null; + } + return DateConverter.convertStringToLocalDate(localDate); + } + }); + + } + + private void showData() { + this.labelFirstName.setText(patient.getFirstName()); + this.labelSurname.setText(patient.getSurname()); + LocalDate date = DateConverter.convertStringToLocalDate(treatment.getDate()); + this.datePicker.setValue(date); + this.textFieldBegin.setText(this.treatment.getBegin()); + this.textFieldEnd.setText(this.treatment.getEnd()); + this.textFieldDescription.setText(this.treatment.getDescription()); + this.textAreaRemarks.setText(this.treatment.getRemarks()); + } + + @FXML + public void handleSave() { + LocalDate newDate = this.datePicker.getValue(); + LocalTime newBegin = DateConverter.convertStringToLocalTime(textFieldBegin.getText()); + LocalTime newEnd = DateConverter.convertStringToLocalTime(textFieldEnd.getText()); + String newDescription = textFieldDescription.getText(); + String newRemarks = textAreaRemarks.getText(); + + this.treatment.setDate(newDate.toString()); + this.treatment.setDescription(newDescription); + this.treatment.setBegin(newBegin); + this.treatment.setEnd(newEnd); + this.treatment.setRemarks(newRemarks); + + if (isNewTreatment) { + controller.createTreatment(treatment); + } else { + controller.updateTreatment(treatment); + } + + controller.readAllAndShowInTableView(); + stage.close(); + } + + @FXML + public void handleCancel() { + stage.close(); + } + + public Treatment getTreatment() { + return treatment; + } +} diff --git a/src/main/resources/de/hitec/nhplus/patient/AllPatientView.fxml b/src/main/resources/de/hitec/nhplus/patient/AllPatientView.fxml index e1a2e5a..e921ec2 100644 --- a/src/main/resources/de/hitec/nhplus/patient/AllPatientView.fxml +++ b/src/main/resources/de/hitec/nhplus/patient/AllPatientView.fxml @@ -67,12 +67,12 @@
- + - - - + + + @@ -97,7 +97,6 @@ fx:id="textFieldDateOfBirth" minWidth="160.0" prefWidth="160.0" - promptText="Geburtstag" GridPane.columnIndex="2" /> @@ -105,7 +104,6 @@ fx:id="textFieldCareLevel" prefHeight="26.0" prefWidth="200.0" - promptText="Pflegegrad" GridPane.rowIndex="1" /> diff --git a/src/main/resources/de/hitec/nhplus/treatment/AllTreatmentView.fxml b/src/main/resources/de/hitec/nhplus/treatment/AllTreatmentView.fxml index ec89105..cf11aba 100644 --- a/src/main/resources/de/hitec/nhplus/treatment/AllTreatmentView.fxml +++ b/src/main/resources/de/hitec/nhplus/treatment/AllTreatmentView.fxml @@ -63,20 +63,19 @@
+
diff --git a/src/main/resources/de/hitec/nhplus/treatment/NewTreatmentView.fxml b/src/main/resources/de/hitec/nhplus/treatment/NewTreatmentView.fxml deleted file mode 100644 index 0e14533..0000000 --- a/src/main/resources/de/hitec/nhplus/treatment/NewTreatmentView.fxml +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -