From 54bdc210408c503c69a3cc9b7e64ca19d22c727c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Wed, 15 May 2024 08:49:06 +0200 Subject: [PATCH] #17: Update Views to show the Nurse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dominik Säume --- .../treatment/AllTreatmentController.java | 70 ++++++++++++++----- .../treatment/TreatmentModalController.java | 23 ++++-- .../nhplus/treatment/AllTreatmentView.fxml | 11 ++- .../nhplus/treatment/TreatmentModal.fxml | 18 ++++- 4 files changed, 97 insertions(+), 25 deletions(-) diff --git a/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java b/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java index c0f01c3..854c155 100644 --- a/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java +++ b/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java @@ -2,6 +2,8 @@ package de.hitec.nhplus.treatment; import de.hitec.nhplus.Main; import de.hitec.nhplus.datastorage.DaoFactory; +import de.hitec.nhplus.nurse.Nurse; +import de.hitec.nhplus.nurse.database.NurseDao; import de.hitec.nhplus.patient.Patient; import de.hitec.nhplus.patient.database.PatientDao; import de.hitec.nhplus.treatment.database.TreatmentDao; @@ -31,6 +33,9 @@ public class AllTreatmentController { @FXML private TableColumn columnPatientName; + @FXML + private TableColumn columnNurseName; + @FXML private TableColumn columnDate; @@ -46,6 +51,9 @@ public class AllTreatmentController { @FXML private ComboBox comboBoxPatientSelection; + @FXML + public ComboBox comboBoxNurseSelection; + @FXML private Button buttonDelete; @@ -53,19 +61,29 @@ public class AllTreatmentController { private TreatmentDao dao; private final ObservableList patientSelection = FXCollections.observableArrayList(); private ArrayList patientList; + private final ObservableList nurseSelection = FXCollections.observableArrayList(); + private ArrayList nurseList; public void initialize() { readAllAndShowInTableView(); comboBoxPatientSelection.setItems(patientSelection); - comboBoxPatientSelection.getSelectionModel().select(0); + comboBoxPatientSelection.getSelectionModel().select("alle"); + + comboBoxNurseSelection.setItems(nurseSelection); this.columnId.setCellValueFactory(new PropertyValueFactory<>("id")); this.columnPatientName.setCellValueFactory( - cellData -> { + cellData -> { Patient patient = cellData.getValue().getPatient(); return new SimpleStringProperty(patient.getSurName() + ", " + patient.getFirstName()); } ); + this.columnNurseName.setCellValueFactory( + cellData -> { + Nurse nurse = cellData.getValue().getNurse(); + return new SimpleStringProperty(nurse.getSurName() + ", " + nurse.getFirstName()); + } + ); this.columnDate.setCellValueFactory(new PropertyValueFactory<>("date")); this.columnBegin.setCellValueFactory(new PropertyValueFactory<>("begin")); this.columnEnd.setCellValueFactory(new PropertyValueFactory<>("end")); @@ -84,7 +102,6 @@ public class AllTreatmentController { } public void readAllAndShowInTableView() { - comboBoxPatientSelection.getSelectionModel().select(0); this.dao = DaoFactory.getInstance().createTreatmentDao(); try { this.treatments.setAll(dao.readAll()); @@ -94,13 +111,19 @@ public class AllTreatmentController { } private void createComboBoxData() { - PatientDao dao = DaoFactory.getInstance().createPatientDAO(); + PatientDao patientDAO = DaoFactory.getInstance().createPatientDAO(); + NurseDao nurseDao = DaoFactory.getInstance().createNurseDAO(); try { - patientList = (ArrayList) dao.readAll(); + patientList = (ArrayList) patientDAO.readAll(); this.patientSelection.add("alle"); for (Patient patient : patientList) { this.patientSelection.add(patient.getSurName()); } + + nurseList = (ArrayList) nurseDao.readAll(); + for (Nurse nurse : nurseList) { + this.nurseSelection.add(nurse.getSurName()); + } } catch (SQLException exception) { exception.printStackTrace(); } @@ -108,7 +131,7 @@ public class AllTreatmentController { @FXML - public void handleComboBox() { + public void handleComboBoxPatient() { String selectedPatient = this.comboBoxPatientSelection.getSelectionModel().getSelectedItem(); this.treatments.clear(); this.dao = DaoFactory.getInstance().createTreatmentDao(); @@ -121,17 +144,17 @@ public class AllTreatmentController { } } - Patient patient = searchInList(selectedPatient); + Patient patient = searchInPatientList(selectedPatient); if (patient != null) { try { - this.treatments.setAll(this.dao.readTreatmentsByPid(patient.getId())); + this.treatments.setAll(this.dao.readTreatmentsByPatient(patient.getId())); } catch (SQLException exception) { exception.printStackTrace(); } } } - private Patient searchInList(String surname) { + private Patient searchInPatientList(String surname) { for (Patient patient : this.patientList) { if (patient.getSurName().equals(surname)) { return patient; @@ -140,6 +163,15 @@ public class AllTreatmentController { return null; } + private Nurse searchInNurseList(String surname) { + for (Nurse nurse : this.nurseList) { + if (nurse.getSurName().equals(surname)) { + return nurse; + } + } + return null; + } + @FXML public void handleDelete() { int index = this.tableView.getSelectionModel().getSelectedIndex(); @@ -156,8 +188,12 @@ public class AllTreatmentController { public void handleNewTreatment() { try { String selectedPatient = this.comboBoxPatientSelection.getSelectionModel().getSelectedItem(); - Patient patient = searchInList(selectedPatient); - newTreatmentWindow(patient); + Patient patient = searchInPatientList(selectedPatient); + + String selectedNurse = this.comboBoxNurseSelection.getSelectionModel().getSelectedItem(); + Nurse nurse = searchInNurseList(selectedNurse); + + newTreatmentWindow(patient, nurse); } catch (NullPointerException exception) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Information"); @@ -174,12 +210,12 @@ public class AllTreatmentController { if (event.getClickCount() == 2 && (tableView.getSelectionModel().getSelectedItem() != null)) { int index = this.tableView.getSelectionModel().getSelectedIndex(); Treatment treatment = this.treatments.get(index); - treatmentWindow(treatment); + treatmentWindow(treatment, treatment.getNurse()); } }); } - public void newTreatmentWindow(Patient patient) { + public void newTreatmentWindow(Patient patient, Nurse nurse) { try { FXMLLoader loader = new FXMLLoader( Main.class.getResource("/de/hitec/nhplus/treatment/TreatmentModal.fxml") @@ -193,7 +229,8 @@ public class AllTreatmentController { this, stage, null, - patient + patient, + nurse ); stage.setScene(scene); @@ -206,7 +243,7 @@ public class AllTreatmentController { } } - public void treatmentWindow(Treatment treatment) { + public void treatmentWindow(Treatment treatment, Nurse nurse) { try { FXMLLoader loader = new FXMLLoader( Main.class.getResource("/de/hitec/nhplus/treatment/TreatmentModal.fxml") @@ -221,7 +258,8 @@ public class AllTreatmentController { this, stage, treatment, - pDao.read(treatment.getPatient().getId()) + pDao.read(treatment.getPatient().getId()), + nurse ); stage.setScene(scene); diff --git a/src/main/java/de/hitec/nhplus/treatment/TreatmentModalController.java b/src/main/java/de/hitec/nhplus/treatment/TreatmentModalController.java index af788f0..9948d5c 100644 --- a/src/main/java/de/hitec/nhplus/treatment/TreatmentModalController.java +++ b/src/main/java/de/hitec/nhplus/treatment/TreatmentModalController.java @@ -1,5 +1,6 @@ package de.hitec.nhplus.treatment; +import de.hitec.nhplus.nurse.Nurse; import de.hitec.nhplus.patient.Patient; import de.hitec.nhplus.utils.DateConverter; import javafx.beans.value.ChangeListener; @@ -14,6 +15,8 @@ import java.time.LocalTime; import static de.hitec.nhplus.utils.Validator.*; public class TreatmentModalController { + @FXML + private Label labelNurseName; @FXML private Label labelFirstName; @FXML @@ -33,18 +36,27 @@ public class TreatmentModalController { private AllTreatmentController controller; private Stage stage; private Patient patient; + private Nurse nurse; private Treatment treatment; private boolean isNewTreatment = false; - public void initialize(AllTreatmentController controller, Stage stage, Treatment treatment, Patient patient) { + public void initialize( + AllTreatmentController controller, + Stage stage, + Treatment treatment, + Patient patient, + Nurse nurse + ) { this.controller = controller; this.stage = stage; this.patient = patient; + this.nurse = nurse; if (treatment == null) { isNewTreatment = true; LocalTime currentTime = LocalTime.now(); this.treatment = new Treatment( patient, + nurse, LocalDate.now(), LocalTime.of(currentTime.getHour(), currentTime.getMinute()), LocalTime.of(currentTime.getHour(), currentTime.getMinute()), @@ -60,16 +72,16 @@ public class TreatmentModalController { ChangeListener inputNewTreatmentTextValidationListener = (observableValue, oldText, newText) -> { boolean isValid = isValidDate(this.datePicker.getValue()) - && isValidTimeRange(this.textFieldBegin.getText(), this.textFieldEnd.getText()) - && isValidDescription(this.textFieldDescription.getText()); + && 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()); + && isValidTimeRange(this.textFieldBegin.getText(), this.textFieldEnd.getText()) + && isValidDescription(this.textFieldDescription.getText()); this.buttonSave.setDisable(!isValid); }; @@ -98,6 +110,7 @@ public class TreatmentModalController { } private void showData() { + this.labelNurseName.setText(nurse.getSurName()); this.labelFirstName.setText(patient.getFirstName()); this.labelSurName.setText(patient.getSurName()); LocalDate date = DateConverter.convertStringToLocalDate(treatment.getDate()); diff --git a/src/main/resources/de/hitec/nhplus/treatment/AllTreatmentView.fxml b/src/main/resources/de/hitec/nhplus/treatment/AllTreatmentView.fxml index 0a6d5d0..99d5301 100644 --- a/src/main/resources/de/hitec/nhplus/treatment/AllTreatmentView.fxml +++ b/src/main/resources/de/hitec/nhplus/treatment/AllTreatmentView.fxml @@ -28,6 +28,11 @@ minWidth="80.0" text="Patient" /> + +