From 0aea0911b476b8fb971a9cb0ad87714e34ee5680 Mon Sep 17 00:00:00 2001 From: Dorian Nemec Date: Mon, 20 May 2024 16:34:06 +0200 Subject: [PATCH] #24: Implement Deprecated and Available medications --- db/nursingHome.db | Bin 28672 -> 28672 bytes .../nhplus/fixtures/MedicationFixture.java | 6 +- .../nhplus/main/MainWindowController.java | 18 +++++- .../medication/AllMedicationController.java | 9 +-- .../DeprecatedMedicationController.java | 9 +-- .../hitec/nhplus/medication/Medication.java | 4 +- .../medication/database/MedicationDao.java | 57 ++++++++++++++++-- .../hitec/nhplus/nurse/database/NurseDao.java | 2 - .../treatment/AllTreatmentController.java | 3 +- .../de/hitec/nhplus/main/MainWindowView.fxml | 2 +- .../nhplus/medication/database/Medication.sql | 2 +- .../hitec/nhplus/nurse/LockedNurseView.fxml | 1 - 12 files changed, 89 insertions(+), 24 deletions(-) diff --git a/db/nursingHome.db b/db/nursingHome.db index 28051a7f03cff2f8887d0c9d23bdec0402a3af5a..ccbada552254d42fbc0d69be87ef43280cc1778e 100644 GIT binary patch delta 767 zcmZvZ&ubGw6vy{v(yhB`W>OnWwMeQWBDR#apophhD+sMr`Xk!b)-jo6m+a2O*-2=6 zX{9GGqU=czA}U@y=^hlk2-TbZ0UpHO1Qic@5Ii|)B3gA|VBUAW@4e5PS=)rQO}MdV zr}@e-jCQ?$t#3E`hGOQc$CqLj1YzDf3TAlQx&tyiZudfaG-oe?U8G*X?8EEqO0<#q z03f1ANi7HFR+Xz>B}$VoDZF6B$;b)vk(?t%G7@$64w6-zL;JvI1vgKXE4XRRpbYS; z3>YGH!v-Z8RmoYDZJvC_mCd!2TsKmG<~7CphHY&nH!R$2iqHNhzG;f#i-Ba8yx;Cf zS(-c1qDV|fp9i{ohccKNT*DN<#jkOM zAL;>LCc__oX|;2a*wvDWo>59vEsp|W#eG$R# zc#Z}Ele-oW493T}Sf-T*SpV53S?4^0L-CW0uhc#2m4zcbGKb&*nsWUb4V3;Vp1z=g z(LccFb$8V2p3EW0qEY7cc~wsj&@qc(Z)}2c?keG>XLJD_ZJ#(Z9o`k0#jYv+V6jo^ z<@IA!91&C;s_fIq>X{TZw;*`;7_yE{FjW-Ncezt9NRf9uA>BgPDP;BkUAAKsSy@fe V1bH&Kh{1}M7UuzWgwL18egf2(=gc{whOyUX9}&fK(v4{YP2D0f_kH1^-_!pM6kxdq#fExcW0X2DFPnA zXgJd}UOaHocrh_CdyvGFLH_~oMs6l*Ja{qjz;6lDSWL?9PQL@+*O#MGUezLcWu)WRtuIM<(V;YwOgx_$11L@)=bg6Urt#5ey!y z@G@0g;wdz85VhZoWwV-STcYU)x|K^|CM+wD(y*UF&P4cgEHfM$izN)*;exmiV71@N z!gyTIr7?|=ZL&ok5k_XoEpm;F5*z=)Kk#S#3Gd)nxP_nMhnSMz+s85yCk6_50QM)hwI&)5Rf+DRe8L(su!3A@U`b*U3LQv)F zsYDXNnOMF~*Ekc^rsr{|PtU{-0ll5z0FX`~xDqR}WvObb{<>T_qSyq%fH6mdfcd=` z!C7OHiM3Uix^-ETZhsuXC8HqZ3Tw(grAyVC%5k1aGc4@ECDe9KB$3{&CjT%)wCW4c?RS2%6n~rHW(IOAH zkPV-^xf{H;TG20P4w`fWRR6T GlKv0P3d}hG diff --git a/src/main/java/de/hitec/nhplus/fixtures/MedicationFixture.java b/src/main/java/de/hitec/nhplus/fixtures/MedicationFixture.java index 8dc9f96..025c222 100644 --- a/src/main/java/de/hitec/nhplus/fixtures/MedicationFixture.java +++ b/src/main/java/de/hitec/nhplus/fixtures/MedicationFixture.java @@ -117,7 +117,7 @@ public class MedicationFixture implements Fixture { "Unterhautinjektion", 120 )); - medications.add(new Medication( + Medication deprecatedMedication = new Medication( "Levothyroxin", "Sandoz", List.of( @@ -129,7 +129,9 @@ public class MedicationFixture implements Fixture { "Herzrasen, Gewichtsverlust", "Oral", 90 - )); + ); + deprecatedMedication.setIsDeprecated(true); + medications.add(deprecatedMedication); medications.add(new Medication( "Warfarin", "Apotex Inc.", diff --git a/src/main/java/de/hitec/nhplus/main/MainWindowController.java b/src/main/java/de/hitec/nhplus/main/MainWindowController.java index 2e5910d..27daa89 100644 --- a/src/main/java/de/hitec/nhplus/main/MainWindowController.java +++ b/src/main/java/de/hitec/nhplus/main/MainWindowController.java @@ -49,6 +49,8 @@ public class MainWindowController { @FXML private Tab medicationTab; @FXML + private Tab availableMedicationTab; + @FXML private TabPane medicationTabPane; @FXML private AnchorPane deprecatedMedicationPage; @@ -71,7 +73,7 @@ public class MainWindowController { activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage()); lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage()); - medicationTab.setOnSelectionChanged(event -> loadMedicationPage()); + availableMedicationTab.setOnSelectionChanged(event -> loadAvailableMedicationPage()); deprecatedMedicationTab.setOnSelectionChanged(event -> loadDeprecatedMedicationPage()); nurseTabPane.getSelectionModel().select(activeNurseTab); @@ -164,10 +166,22 @@ public class MainWindowController { } } + private void loadMedicationPage() + { + SelectionModel selectionModel = medicationTabPane.getSelectionModel(); + Tab selectedTab = selectionModel.getSelectedItem(); + if(selectedTab == availableMedicationTab){ + loadAvailableMedicationPage(); + } + if(selectedTab == deprecatedMedicationTab){ + loadDeprecatedMedicationPage(); + } + } + /** * Loads the medication page into its tab. */ - private void loadMedicationPage() { + private void loadAvailableMedicationPage() { try { BorderPane medicationPane = FXMLLoader.load( Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/medication/AllMedicationView.fxml")) diff --git a/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java b/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java index 8c2ca83..5e57089 100644 --- a/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java +++ b/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java @@ -60,7 +60,7 @@ public class AllMedicationController { */ @FXML public void initialize() { - readAllAndShowInTableView(); + this.readAllAndShowInTableView(); this.columnId.setCellValueFactory(new PropertyValueFactory<>("id")); this.columnName.setCellValueFactory(new PropertyValueFactory<>("name")); @@ -85,6 +85,7 @@ public class AllMedicationController { this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock")); this.tableView.setItems(this.medications); + } /** @@ -93,7 +94,7 @@ public class AllMedicationController { public void readAllAndShowInTableView() { this.dao = DaoFactory.getInstance().createMedicationDAO(); try { - this.medications.setAll(dao.readAll()); + this.medications.setAll(dao.readAllAvailable()); } catch (SQLException exception) { exception.printStackTrace(); } @@ -125,7 +126,7 @@ public class AllMedicationController { @FXML public void handleChangeAvailable() { - Medication selectedItem = tableView.getSelectionModel().getSelectedItem(); + Medication selectedItem = this.tableView.getSelectionModel().getSelectedItem(); if (selectedItem == null) { return; } @@ -136,7 +137,7 @@ public class AllMedicationController { } catch (SQLException exception) { exception.printStackTrace(); } - readAllAndShowInTableView(); + this.readAllAndShowInTableView(); } /** diff --git a/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java b/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java index d992fe9..8d36f59 100644 --- a/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java +++ b/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java @@ -38,9 +38,8 @@ public class DeprecatedMedicationController { private final ObservableList medications = FXCollections.observableArrayList(); private MedicationDao dao; - @FXML public void initialize() { - readAllAndShowInTableView(); + this.readAllAndShowInTableView(); this.columnId.setCellValueFactory(new PropertyValueFactory<>("id")); this.columnName.setCellValueFactory(new PropertyValueFactory<>("name")); @@ -65,15 +64,17 @@ public class DeprecatedMedicationController { this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock")); this.tableView.setItems(this.medications); + } /** * Internal method to read all data and set it to the table view. */ public void readAllAndShowInTableView() { + this.medications.clear(); this.dao = DaoFactory.getInstance().createMedicationDAO(); try { - this.medications.setAll(dao.readAllDeprecated()); + this.medications.setAll(this.dao.readAllDeprecated()); } catch (SQLException exception) { exception.printStackTrace(); } @@ -91,7 +92,7 @@ public class DeprecatedMedicationController { } catch (SQLException exception) { exception.printStackTrace(); } - readAllAndShowInTableView(); + this.readAllAndShowInTableView(); } } diff --git a/src/main/java/de/hitec/nhplus/medication/Medication.java b/src/main/java/de/hitec/nhplus/medication/Medication.java index a73c8b3..f33a98e 100644 --- a/src/main/java/de/hitec/nhplus/medication/Medication.java +++ b/src/main/java/de/hitec/nhplus/medication/Medication.java @@ -61,7 +61,7 @@ public class Medication { String possibleSideEffects, String administrationMethod, int currentStock, - boolean isDepreacted + boolean isDeprecated ) { this.id = new SimpleIntegerProperty(id); this.name = new SimpleStringProperty(name); @@ -70,7 +70,7 @@ public class Medication { this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects); this.administrationMethod = new SimpleStringProperty(administrationMethod); this.currentStock = new SimpleIntegerProperty(currentStock); - this.isDeprecated = new SimpleBooleanProperty(isDepreacted); + this.isDeprecated = new SimpleBooleanProperty(isDeprecated); } public int getId() { diff --git a/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java b/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java index f4f4655..5e31e43 100644 --- a/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java +++ b/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java @@ -86,7 +86,6 @@ public class MedicationDao implements Dao { SELECT medication.*, medication_ingredient.name FROM medication LEFT JOIN medication_ingredient ON medication.id = medication_ingredient.id - WHERE medication.isDeprecated = false """; ResultSet result = connection.prepareStatement(SQL).executeQuery(); @@ -133,7 +132,8 @@ public class MedicationDao implements Dao { final String SQL = """ SELECT medication.*, medication_ingredient.name FROM medication LEFT JOIN - medication_ingredient ON medication.id = medication_ingredient.id + medication_ingredient + ON medication.id = medication_ingredient.id WHERE medication.isDeprecated = true """; ResultSet result = connection.prepareStatement(SQL).executeQuery(); @@ -177,6 +177,55 @@ public class MedicationDao implements Dao { return medications; } + public List readAllAvailable() throws SQLException { + final String SQL = """ + SELECT medication.*, medication_ingredient.name + FROM medication LEFT JOIN + medication_ingredient + ON medication.id = medication_ingredient.id + WHERE medication.isDeprecated = false + """; + ResultSet result = connection.prepareStatement(SQL).executeQuery(); + + List medications = new ArrayList<>(); + Map> ingredientMap = new HashMap<>(); + + int currentMedicationId; + int lastMedicationId = -1; + while (result.next()) { + currentMedicationId = result.getInt(1); + if (currentMedicationId != lastMedicationId) { + Medication medication = new Medication( + result.getInt(1), + result.getString(2), + result.getString(3), + new ArrayList<>(), + result.getString(4), + result.getString(5), + result.getInt(6), + result.getBoolean(7) + ); + medications.add(medication); + } + List ingredients = ingredientMap.computeIfAbsent(currentMedicationId, k -> new ArrayList<>()); + String ingredientName = result.getString(8); + if(ingredientName == null){ + continue; + } + ingredients.add(new Ingredient(ingredientName)); + lastMedicationId = currentMedicationId; + } + for (Medication medication : medications) { + List ingredients = ingredientMap.get(medication.getId()); + if(ingredients.isEmpty()){ + continue; + } + medication.setIngredients(ingredientMap.get(medication.getId())); + } + + return medications; + } + @Override public void update(Medication medication) throws SQLException { final String SQL = """ @@ -195,8 +244,8 @@ public class MedicationDao implements Dao { preparedStatement.setString(3, medication.getPossibleSideEffects()); preparedStatement.setString(4, medication.getAdministrationMethod()); preparedStatement.setInt(5, medication.getCurrentStock()); - preparedStatement.setInt(6, medication.getId()); - preparedStatement.setBoolean(7, medication.isDeprecated()); + preparedStatement.setBoolean(6, medication.isDeprecated()); + preparedStatement.setInt(7, medication.getId()); preparedStatement.executeUpdate(); final String ingredientDeleteSQL = """ diff --git a/src/main/java/de/hitec/nhplus/nurse/database/NurseDao.java b/src/main/java/de/hitec/nhplus/nurse/database/NurseDao.java index f4b0b3c..b2d8f4a 100644 --- a/src/main/java/de/hitec/nhplus/nurse/database/NurseDao.java +++ b/src/main/java/de/hitec/nhplus/nurse/database/NurseDao.java @@ -112,6 +112,4 @@ public class NurseDao extends DaoImp { statement.setInt(1, id); return statement; } - - } diff --git a/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java b/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java index 3384c3f..04018bc 100644 --- a/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java +++ b/src/main/java/de/hitec/nhplus/treatment/AllTreatmentController.java @@ -75,7 +75,7 @@ public class AllTreatmentController { */ @FXML public void initialize() { - readAllAndShowInTableView(); + comboBoxPatientSelection.setItems(patientSelection); comboBoxPatientSelection.getSelectionModel().select("alle"); @@ -109,6 +109,7 @@ public class AllTreatmentController { ); this.createComboBoxData(); + readAllAndShowInTableView(); } /** diff --git a/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml b/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml index d4db00c..c22810a 100644 --- a/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml +++ b/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml @@ -27,7 +27,7 @@ - + diff --git a/src/main/resources/de/hitec/nhplus/medication/database/Medication.sql b/src/main/resources/de/hitec/nhplus/medication/database/Medication.sql index 6d68c0e..4d4dc45 100644 --- a/src/main/resources/de/hitec/nhplus/medication/database/Medication.sql +++ b/src/main/resources/de/hitec/nhplus/medication/database/Medication.sql @@ -6,5 +6,5 @@ CREATE TABLE medication possibleSideEffects TEXT NOT NULL, administrationMethod TEXT NOT NULL, currentStock INTEGER NOT NULL, - isDeprecated BOOLEAN NOT NULL DEFAULT FALSE + isDeprecated BOOLEAN NOT NULL DEFAULT false ) \ No newline at end of file diff --git a/src/main/resources/de/hitec/nhplus/nurse/LockedNurseView.fxml b/src/main/resources/de/hitec/nhplus/nurse/LockedNurseView.fxml index 23f2c6d..7500c1d 100644 --- a/src/main/resources/de/hitec/nhplus/nurse/LockedNurseView.fxml +++ b/src/main/resources/de/hitec/nhplus/nurse/LockedNurseView.fxml @@ -74,7 +74,6 @@ onAction="#handleDelete" prefWidth="90.0" text="Löschen" - />