From a4e61157efa646f408635c123ea839691840634c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Wed, 15 May 2024 00:39:27 +0200 Subject: [PATCH 1/4] #10: Add TODOs for implementation --- src/main/java/de/hitec/nhplus/treatment/Treatment.java | 1 + .../java/de/hitec/nhplus/treatment/database/TreatmentDao.java | 3 +++ .../resources/de/hitec/nhplus/treatment/database/Treatment.sql | 1 + 3 files changed, 5 insertions(+) diff --git a/src/main/java/de/hitec/nhplus/treatment/Treatment.java b/src/main/java/de/hitec/nhplus/treatment/Treatment.java index 4551560..c6742a2 100644 --- a/src/main/java/de/hitec/nhplus/treatment/Treatment.java +++ b/src/main/java/de/hitec/nhplus/treatment/Treatment.java @@ -18,6 +18,7 @@ public class Treatment { private final SimpleObjectProperty end; private final SimpleStringProperty description; private final SimpleStringProperty remarks; + //TODO: Add Nurse public Treatment(Patient patient, LocalDate date, LocalTime begin, LocalTime end, String description, String remarks) { diff --git a/src/main/java/de/hitec/nhplus/treatment/database/TreatmentDao.java b/src/main/java/de/hitec/nhplus/treatment/database/TreatmentDao.java index 51ccde3..9293845 100644 --- a/src/main/java/de/hitec/nhplus/treatment/database/TreatmentDao.java +++ b/src/main/java/de/hitec/nhplus/treatment/database/TreatmentDao.java @@ -12,6 +12,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +//TODO: Update Methods to use a new Nurse Field (cascade this to any class using this DAO) public class TreatmentDao extends DaoImp { public TreatmentDao(Connection connection) { @@ -83,6 +84,8 @@ public class TreatmentDao extends DaoImp { return getListFromResultSet(result); } + //TODO: readTreatmentsByNurse + @Override protected PreparedStatement getUpdateStatement(Treatment treatment) throws SQLException { final String SQL = """ diff --git a/src/main/resources/de/hitec/nhplus/treatment/database/Treatment.sql b/src/main/resources/de/hitec/nhplus/treatment/database/Treatment.sql index 0fdee0d..00b18d8 100644 --- a/src/main/resources/de/hitec/nhplus/treatment/database/Treatment.sql +++ b/src/main/resources/de/hitec/nhplus/treatment/database/Treatment.sql @@ -8,4 +8,5 @@ CREATE TABLE treatment description TEXT NOT NULL, remark TEXT NOT NULL, FOREIGN KEY (patientId) REFERENCES patient (id) ON DELETE CASCADE + -- TODO: Add Nurse ) \ No newline at end of file -- 2.45.2 From c6c3e6528a7e4658245bdd7f64260ea374a09f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Wed, 15 May 2024 08:43:25 +0200 Subject: [PATCH 2/4] #17: Update Treatment Model, Dao and Fixtures for Relation to a Nurse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dominik Säume --- db/nursingHome.db | Bin 28672 -> 28672 bytes .../de/hitec/nhplus/fixtures/Fixtures.java | 13 ++-- .../nhplus/fixtures/TreatmentFixture.java | 18 +++++- .../de/hitec/nhplus/treatment/Treatment.java | 18 +++++- .../treatment/database/TreatmentDao.java | 56 +++++++++--------- .../nhplus/treatment/database/Treatment.sql | 5 +- 6 files changed, 72 insertions(+), 38 deletions(-) diff --git a/db/nursingHome.db b/db/nursingHome.db index c3e0182522f652437dd0616564451101e63df8bd..e05cb45f7f42374a9e0679c17dac84b9d5231516 100644 GIT binary patch delta 541 zcmZp8z}WDBae}m983O|YI}k$wBmYDlW63fGy`qJ@T!$FgIBqfUt>#_9^OEBh_jG>E zjg8ycxtdd}*u~}L8QUc%7jbtf=9Lx|r+TI+fPkl8h^xD6kb<9oNONjEk}7tns>y-e zqKpcYzj1%`(%}N>aPtpx^>p`B@OF(<(10q^R0wi)a}9F!b9N0@0E;PTWTt2;`1>ii zxcaz;xGDs@hA8-j`uK2Z^8IDFI$4k3l#zXM3jZWtwnj!auveP=8W}cAarrSaH`>%q ze#5hmsg`{*Bft9Q%e=abj5ILReVW^z z>)~cafume(FjGU9dN=5QpKLL9%zGHTeqIp|YBd zf~-uF1!YorV%dPQAPv&hOq1(nLRdLixfnPnUzcg+iDltr-~>r2moiOGlMQCeX9nA| zPd0})g9)e#Bq!g@%QV?k?jCCnBS@dP{A<2D3@rRhMfuP3AK~B1zjU*pLqGrI`TA_` ze2L78jJc^PnaPPInfZBaya~+mj3q^>i6yzIc_mz&@yz0k;GksUj$@W)EC8wkii5(6 NpA$*j<~RBx4ggvYiIV^T delta 382 zcmZp8z}WDBae}lU3j+fKI}pRb?}<9bk}M2*MGJZP{xYy}i8Ju6=3T*^!Sj+!oL_6R zqQHDk<|e patientsByName = patientFixture.load(); - TreatmentFixture treatmentFixture = new TreatmentFixture(patientsByName); + NurseFixture nurseFixture = new NurseFixture(); + nurseFixture.dropTable(connection); + nurseFixture.setupTable(connection); + Map nursesByName = nurseFixture.load(); + + + TreatmentFixture treatmentFixture = new TreatmentFixture(patientsByName, nursesByName); treatmentFixture.dropTable(connection); treatmentFixture.setupTable(connection); treatmentFixture.load(); - NurseFixture nurseFixture = new NurseFixture(); - nurseFixture.dropTable(connection); - nurseFixture.setupTable(connection); - nurseFixture.load(); MedicationFixture medicationFixture = new MedicationFixture(); medicationFixture.dropTable(connection); diff --git a/src/main/java/de/hitec/nhplus/fixtures/TreatmentFixture.java b/src/main/java/de/hitec/nhplus/fixtures/TreatmentFixture.java index cd2b7dc..26edb8a 100644 --- a/src/main/java/de/hitec/nhplus/fixtures/TreatmentFixture.java +++ b/src/main/java/de/hitec/nhplus/fixtures/TreatmentFixture.java @@ -2,6 +2,7 @@ package de.hitec.nhplus.fixtures; import de.hitec.nhplus.Main; import de.hitec.nhplus.datastorage.DaoFactory; +import de.hitec.nhplus.nurse.Nurse; import de.hitec.nhplus.patient.Patient; import de.hitec.nhplus.treatment.Treatment; import de.hitec.nhplus.treatment.database.TreatmentDao; @@ -17,9 +18,11 @@ import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalTime; public class TreatmentFixture implements Fixture { private final Map patientsByName; + private final Map nursesByName; - public TreatmentFixture(Map patientsByName) { + public TreatmentFixture(Map patientsByName, Map nursesByName) { this.patientsByName = patientsByName; + this.nursesByName = nursesByName; } @Override @@ -45,9 +48,13 @@ public class TreatmentFixture implements Fixture { Patient ahmet = patientsByName.get("Ahmet"); Patient elisabeth = patientsByName.get("Elisabeth"); + Nurse ole = nursesByName.get("Ole"); + Nurse armin = nursesByName.get("Armin"); + treatments.add(new Treatment( 1, seppl, + ole, convertStringToLocalDate("2023-06-03"), convertStringToLocalTime("11:00"), convertStringToLocalTime("15:00"), @@ -59,6 +66,7 @@ public class TreatmentFixture implements Fixture { treatments.add(new Treatment( 2, seppl, + armin, convertStringToLocalDate("2023-06-05"), convertStringToLocalTime("11:00"), convertStringToLocalTime("12:30"), @@ -70,6 +78,7 @@ public class TreatmentFixture implements Fixture { treatments.add(new Treatment( 3, martina, + ole, convertStringToLocalDate("2023-06-04"), convertStringToLocalTime("07:30"), convertStringToLocalTime("08:00"), @@ -79,6 +88,7 @@ public class TreatmentFixture implements Fixture { treatments.add(new Treatment( 4, seppl, + armin, convertStringToLocalDate("2023-06-06"), convertStringToLocalTime("15:10"), convertStringToLocalTime("16:00"), @@ -88,6 +98,7 @@ public class TreatmentFixture implements Fixture { treatments.add(new Treatment( 8, seppl, + ole, convertStringToLocalDate("2023-06-08"), convertStringToLocalTime("15:00"), convertStringToLocalTime("16:00"), @@ -97,6 +108,7 @@ public class TreatmentFixture implements Fixture { treatments.add(new Treatment( 9, martina, + armin, convertStringToLocalDate("2023-06-07"), convertStringToLocalTime("11:00"), convertStringToLocalTime("11:30"), @@ -106,6 +118,7 @@ public class TreatmentFixture implements Fixture { treatments.add(new Treatment( 12, hans, + armin, convertStringToLocalDate("2023-06-08"), convertStringToLocalTime("15:00"), convertStringToLocalTime("15:30"), @@ -115,6 +128,7 @@ public class TreatmentFixture implements Fixture { treatments.add(new Treatment( 14, ahmet, + ole, convertStringToLocalDate("2023-08-24"), convertStringToLocalTime("09:30"), convertStringToLocalTime("10:15"), @@ -123,6 +137,7 @@ public class TreatmentFixture implements Fixture { treatments.add(new Treatment( 16, elisabeth, + armin, convertStringToLocalDate("2023-08-31"), convertStringToLocalTime("13:30"), convertStringToLocalTime("13:45"), @@ -132,6 +147,7 @@ public class TreatmentFixture implements Fixture { treatments.add(new Treatment( 17, elisabeth, + ole, convertStringToLocalDate("2023-09-01"), convertStringToLocalTime("16:00"), convertStringToLocalTime("17:00"), diff --git a/src/main/java/de/hitec/nhplus/treatment/Treatment.java b/src/main/java/de/hitec/nhplus/treatment/Treatment.java index c6742a2..e369119 100644 --- a/src/main/java/de/hitec/nhplus/treatment/Treatment.java +++ b/src/main/java/de/hitec/nhplus/treatment/Treatment.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.property.SimpleIntegerProperty; @@ -13,16 +14,17 @@ import java.util.StringJoiner; public class Treatment { private SimpleIntegerProperty id; private final SimpleObjectProperty patient; + private final SimpleObjectProperty nurse; private final SimpleObjectProperty date; private final SimpleObjectProperty begin; private final SimpleObjectProperty end; private final SimpleStringProperty description; private final SimpleStringProperty remarks; - //TODO: Add Nurse - public Treatment(Patient patient, LocalDate date, LocalTime begin, + public Treatment(Patient patient, Nurse nurse, LocalDate date, LocalTime begin, LocalTime end, String description, String remarks) { this.patient = new SimpleObjectProperty<>(patient); + this.nurse = new SimpleObjectProperty<>(nurse); this.date = new SimpleObjectProperty<>(date); this.begin = new SimpleObjectProperty<>(begin); this.end = new SimpleObjectProperty<>(end); @@ -30,10 +32,11 @@ public class Treatment { this.remarks = new SimpleStringProperty(remarks); } - public Treatment(int id, Patient patient, LocalDate date, LocalTime begin, + public Treatment(int id, Patient patient, Nurse nurse, LocalDate date, LocalTime begin, LocalTime end, String description, String remarks) { this.id = new SimpleIntegerProperty(id); this.patient = new SimpleObjectProperty<>(patient); + this.nurse = new SimpleObjectProperty<>(nurse); this.date = new SimpleObjectProperty<>(date); this.begin = new SimpleObjectProperty<>(begin); this.end = new SimpleObjectProperty<>(end); @@ -49,6 +52,10 @@ public class Treatment { return patient.getValue(); } + public Nurse getNurse() { + return nurse.getValue(); + } + public String getDate() { return date.getValue().toString(); } @@ -89,6 +96,10 @@ public class Treatment { return patient; } + public SimpleObjectProperty nurseProperty() { + return nurse; + } + public SimpleObjectProperty dateProperty() { return date; } @@ -118,6 +129,7 @@ public class Treatment { .add("TREATMENT") .add("ID: " + this.getId()) .add("Patient: " + this.getPatient().getSurName() + ", " + this.getPatient().getFirstName()) + .add("Nurse: " + this.getNurse().getSurName() + ", " + this.getNurse().getFirstName()) .add("Date: " + this.getDate()) .add("Begin: " + this.getBegin()) .add("End: " + this.getEnd()) diff --git a/src/main/java/de/hitec/nhplus/treatment/database/TreatmentDao.java b/src/main/java/de/hitec/nhplus/treatment/database/TreatmentDao.java index 9293845..1a67596 100644 --- a/src/main/java/de/hitec/nhplus/treatment/database/TreatmentDao.java +++ b/src/main/java/de/hitec/nhplus/treatment/database/TreatmentDao.java @@ -2,6 +2,7 @@ package de.hitec.nhplus.treatment.database; import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.datastorage.DaoImp; +import de.hitec.nhplus.nurse.Nurse; import de.hitec.nhplus.treatment.Treatment; import de.hitec.nhplus.utils.DateConverter; @@ -12,7 +13,6 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -//TODO: Update Methods to use a new Nurse Field (cascade this to any class using this DAO) public class TreatmentDao extends DaoImp { public TreatmentDao(Connection connection) { @@ -23,16 +23,17 @@ public class TreatmentDao extends DaoImp { protected PreparedStatement getCreateStatement(Treatment treatment) throws SQLException { final String SQL = """ INSERT INTO treatment - (patientId, date, begin, end, description, remark) - VALUES (?, ?, ?, ?, ?, ?) + (patientId, nurseId, date, begin, end, description, remark) + VALUES (?, ?, ?, ?, ?, ?, ?) """; PreparedStatement statement = this.connection.prepareStatement(SQL); statement.setInt(1, treatment.getPatient().getId()); - statement.setString(2, treatment.getDate()); - statement.setString(3, treatment.getBegin()); - statement.setString(4, treatment.getEnd()); - statement.setString(5, treatment.getDescription()); - statement.setString(6, treatment.getRemarks()); + statement.setInt(2, treatment.getNurse().getId()); + statement.setString(3, treatment.getDate()); + statement.setString(4, treatment.getBegin()); + statement.setString(5, treatment.getEnd()); + statement.setString(6, treatment.getDescription()); + statement.setString(7, treatment.getRemarks()); return statement; } @@ -49,11 +50,12 @@ public class TreatmentDao extends DaoImp { return new Treatment( result.getInt(1), DaoFactory.getInstance().createPatientDAO().read(result.getInt(2)), - DateConverter.convertStringToLocalDate(result.getString(3)), - DateConverter.convertStringToLocalTime(result.getString(4)), + DaoFactory.getInstance().createNurseDAO().read(result.getInt(3)), + DateConverter.convertStringToLocalDate(result.getString(4)), DateConverter.convertStringToLocalTime(result.getString(5)), - result.getString(6), - result.getString(7) + DateConverter.convertStringToLocalTime(result.getString(6)), + result.getString(7), + result.getString(8) ); } @@ -72,25 +74,26 @@ public class TreatmentDao extends DaoImp { return list; } - private PreparedStatement getReadAllTreatmentsOfOnePatientByPid(int patientId) throws SQLException { + public List readTreatmentsByPatient(int patientId) throws SQLException { final String SQL = "SELECT * FROM treatment WHERE patientId = ?"; PreparedStatement statement = this.connection.prepareStatement(SQL); statement.setInt(1, patientId); - return statement; - } - - public List readTreatmentsByPid(int patientId) throws SQLException { - ResultSet result = getReadAllTreatmentsOfOnePatientByPid(patientId).executeQuery(); + ResultSet result = statement.executeQuery(); return getListFromResultSet(result); } - //TODO: readTreatmentsByNurse + public List readTreatmentsByNurse(int nurseId) throws SQLException { + final String SQL = "SELECT * FROM treatment WHERE nurseId = ?"; + PreparedStatement statement = this.connection.prepareStatement(SQL); + statement.setInt(1, nurseId); + ResultSet result = statement.executeQuery(); + return getListFromResultSet(result); + } @Override protected PreparedStatement getUpdateStatement(Treatment treatment) throws SQLException { final String SQL = """ UPDATE treatment SET - patientId = ?, date = ?, begin = ?, end = ?, @@ -99,13 +102,12 @@ public class TreatmentDao extends DaoImp { WHERE id = ? """; PreparedStatement statement = this.connection.prepareStatement(SQL); - statement.setInt(1, treatment.getPatient().getId()); - statement.setString(2, treatment.getDate()); - statement.setString(3, treatment.getBegin()); - statement.setString(4, treatment.getEnd()); - statement.setString(5, treatment.getDescription()); - statement.setString(6, treatment.getRemarks()); - statement.setInt(7, treatment.getId()); + statement.setString(1, treatment.getDate()); + statement.setString(2, treatment.getBegin()); + statement.setString(3, treatment.getEnd()); + statement.setString(4, treatment.getDescription()); + statement.setString(5, treatment.getRemarks()); + statement.setInt(6, treatment.getId()); return statement; } diff --git a/src/main/resources/de/hitec/nhplus/treatment/database/Treatment.sql b/src/main/resources/de/hitec/nhplus/treatment/database/Treatment.sql index 00b18d8..75b7af1 100644 --- a/src/main/resources/de/hitec/nhplus/treatment/database/Treatment.sql +++ b/src/main/resources/de/hitec/nhplus/treatment/database/Treatment.sql @@ -2,11 +2,12 @@ CREATE TABLE treatment ( id INTEGER PRIMARY KEY AUTOINCREMENT, patientId INTEGER NOT NULL, + nurseId INTEGER NOT NULL , date TEXT NOT NULL, begin TEXT NOT NULL, end TEXT NOT NULL, description TEXT NOT NULL, remark TEXT NOT NULL, - FOREIGN KEY (patientId) REFERENCES patient (id) ON DELETE CASCADE - -- TODO: Add Nurse + FOREIGN KEY (patientId) REFERENCES patient (id) ON DELETE CASCADE, + FOREIGN KEY (nurseId) REFERENCES nurse (id) ON DELETE SET NULL ) \ No newline at end of file -- 2.45.2 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 3/4] #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" /> + +