From 85a5461386609e9904f2cfb55dda4521c38de863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Wed, 22 May 2024 11:56:53 +0200 Subject: [PATCH] #27: WIP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dominik Säume --- .idea/dataSources.xml | 2 +- db/nursingHome.db | Bin 57344 -> 61440 bytes .../nhplus/fixtures/MedicationFixture.java | 169 ++++++++++-------- .../hitec/nhplus/medication/Medication.java | 22 ++- .../medication/MedicationModalController.java | 8 +- .../medication/database/MedicationDao.java | 22 ++- .../database/Medication_Alternative.sql | 7 + 7 files changed, 144 insertions(+), 86 deletions(-) create mode 100644 src/main/resources/de/hitec/nhplus/medication/database/Medication_Alternative.sql diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index 98f48a2..fed79a7 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -1,7 +1,7 @@ - + sqlite.xerial true org.sqlite.JDBC diff --git a/db/nursingHome.db b/db/nursingHome.db index b89b1465940bb9f8aa1e08321a549d20da8681fd..58ed37080c1a49ca429a988e2e252f32ff14484e 100644 GIT binary patch delta 1174 zcmZoTz})bFd4iM>>plhs27Vxh0!I0XI!0PRQN5ytyc`Y;d@KtY_*V1%<=w-*lq-a@ zj>CgJjzgSHj$N8%A?tJ24Vw)GBw3i7cz8FT;N)RsGUcEAn$?7v-;@tXYfScL<7IBF z;+}ki>ld3N51V+X{^a+pa+BNGKNjx z5aQ_M$b@O|suZ+x%IV_X+^NKODOxEVVI(ao; zkX#c3GrPF7G-Go(*iQvOKcwcBKq;ol%&bo*8Hj9FR1o5ytY&|YkClHv1OI3K7yLK* zPx9{vihJ?b^G0%Wr!h-2LN&4R_c4ew=9Lx|r?T*KrZdCXY|Lz2c_nOlzyRZ4%pkys z2n3KgP;dtW7bjR7h?fTyJPQ`&U}Y9%1jP#r9}BZ0vQ}PZQ)YR_lA_eal3bv}xj32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7+X@ONnfeM@3E`u;c zFeoE{fAlzoLw_g&0V${3UXHF~B00~SVB@;Ogd!=m&?_NHy=d{Biy`Vp*#*u`f zTj)GGfFx8SkE{fZdrk#0U5t(l6w6=c;7fRy*_6UrERvM*_C7q{;KS<{sXZ}y)UojS z3tPW?{wLRa?e1e;bo||)U+sL7va-*}T{RN59!p8n#oXSBGY+o*<@3$P!8Yr+8B5FF zIZ``Rd~!$O-I@K)3B`4#Ei1`}JMmYB1%PL*YB5e9nz23YZo->AUpbTzi_8;3t9h4` zcXjOCcmJxdxus|KoheOUyq=Kcv9;DNIe~;d32Uy|)2eoS8c`mKYo?AJ8W>PsEj@ja zyPVkHnxFXEN7}~p?TyVJh?g4Yrdba?vL4+QNjbNKzQ|AmWlx=I!D zXUpZvY%aSk@BEVU8^1YMvf!GXcq8Kg;c=H;pnL27o*Fi*Yfj(b#~FQ{9vGJY`{M3n z_fE7vYOjwVHn${u7nS~aVNz@)+i5*hUD&?B`{&{6lTX;e$o{n-PPA?<+PSWIS@q>;CN6+JR?rM%Pz#-YG4 fTnR}0Xftkr0h@>N3x6Q#VIMuBhXa}z;S~P^tN*Hb diff --git a/src/main/java/de/hitec/nhplus/fixtures/MedicationFixture.java b/src/main/java/de/hitec/nhplus/fixtures/MedicationFixture.java index 8dc9f96..72c5ad3 100644 --- a/src/main/java/de/hitec/nhplus/fixtures/MedicationFixture.java +++ b/src/main/java/de/hitec/nhplus/fixtures/MedicationFixture.java @@ -1,17 +1,17 @@ package de.hitec.nhplus.fixtures; -import de.hitec.nhplus.Main; -import de.hitec.nhplus.datastorage.DaoFactory; -import de.hitec.nhplus.medication.Ingredient; -import de.hitec.nhplus.medication.Medication; -import de.hitec.nhplus.medication.database.MedicationDao; - import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.SQLException; import java.util.*; +import de.hitec.nhplus.Main; +import de.hitec.nhplus.datastorage.DaoFactory; +import de.hitec.nhplus.medication.Ingredient; +import de.hitec.nhplus.medication.Medication; +import de.hitec.nhplus.medication.database.MedicationDao; + /** * {@link Fixture} for {@link Medication}. * @@ -20,11 +20,13 @@ import java.util.*; public class MedicationFixture implements Fixture { private static final String SCHEMA = "/de/hitec/nhplus/medication/database/Medication.sql"; private static final String INGREDIENT_SCHEMA = "/de/hitec/nhplus/medication/database/Medication_Ingredient.sql"; + private static final String ALTERNATIVE_SCHEMA = "/de/hitec/nhplus/medication/database/Medication_Alternative.sql"; @Override public void dropTable(Connection connection) throws SQLException { connection.createStatement().execute("DROP TABLE IF EXISTS medication"); - connection.createStatement().execute("DROP TABLE IF EXISTS medication_ingredient"); + connection.createStatement().execute("DROP TABLE IF EXISTS medication_ingredient"); + connection.createStatement().execute("DROP TABLE IF EXISTS medication_alternative"); } @Override @@ -32,16 +34,25 @@ public class MedicationFixture implements Fixture { final InputStream schema = Main.class.getResourceAsStream(SCHEMA); final InputStream ingredientSchema = Main.class.getResourceAsStream(INGREDIENT_SCHEMA); + final InputStream alternativeSchema = Main.class.getResourceAsStream(ALTERNATIVE_SCHEMA); + assert schema != null; assert ingredientSchema != null; + assert alternativeSchema != null; + String SQL = new Scanner(schema, StandardCharsets.UTF_8) - .useDelimiter("\\A") - .next(); + .useDelimiter("\\A") + .next(); String ingredientSQL = ";" + new Scanner(ingredientSchema, StandardCharsets.UTF_8) - .useDelimiter("\\A") - .next(); + .useDelimiter("\\A") + .next(); + String alternativeSQL = ";" + new Scanner(alternativeSchema, StandardCharsets.UTF_8) + .useDelimiter("\\A") + .next(); + connection.createStatement().execute(SQL); connection.createStatement().execute(ingredientSQL); + connection.createStatement().execute(alternativeSQL); } @@ -67,81 +78,87 @@ public class MedicationFixture implements Fixture { Ingredient warfarinnatrium = new Ingredient("Warfarinnatrium"); medications.add(new Medication( - "Metformin", - "AstraZeneca", - List.of( - metforminhydrochlorid, - cellulose, - povidon, - magnesiumstearat - ), - "Übelkeit, Durchfall, Laktatazidose (selten)", - "Oral", - 100 + "Metformin", + "AstraZeneca", + List.of( + metforminhydrochlorid, + cellulose, + povidon, + magnesiumstearat + ), + "Übelkeit, Durchfall, Laktatazidose (selten)", + "Oral", + 100, + new ArrayList<>() )); medications.add(new Medication( - "Lisinopril", - "Teva Pharmaceuticals", - List.of( - lisinoprilDihydrat, - mannitol, - calciumphosphat, - magnesiumstearat - ), - "Schwindel, trockener Husten", - "Oral", - 150 + "Lisinopril", + "Teva Pharmaceuticals", + List.of( + lisinoprilDihydrat, + mannitol, + calciumphosphat, + magnesiumstearat + ), + "Schwindel, trockener Husten", + "Oral", + 150, + new ArrayList<>() )); medications.add(new Medication( - "Simvastatin", - "Mylan", - List.of( - simvastatin, - laktose, - cellulose, - magnesiumstearat - ), - "Muskelschmerzen, Leberprobleme(selten)", - "Oral", - 80 + "Simvastatin", + "Mylan", + List.of( + simvastatin, + laktose, + cellulose, + magnesiumstearat + ), + "Muskelschmerzen, Leberprobleme(selten)", + "Oral", + 80, + new ArrayList<>() )); medications.add(new Medication( - "Enoxaparin", - "Sanofi", - List.of( - enoxaparinNatrium, - benzylalkohol, - wasser - ), - "Blutungen, Reaktionen an der Injektionsstelle", - "Unterhautinjektion", - 120 + "Enoxaparin", + "Sanofi", + List.of( + enoxaparinNatrium, + benzylalkohol, + wasser + ), + "Blutungen, Reaktionen an der Injektionsstelle", + "Unterhautinjektion", + 120, + new ArrayList<>() )); medications.add(new Medication( - "Levothyroxin", - "Sandoz", - List.of( - levothyroxinnatrium, - laktose, - staerke, - akaziengummi - ), - "Herzrasen, Gewichtsverlust", - "Oral", - 90 + "Levothyroxin", + "Sandoz", + List.of( + levothyroxinnatrium, + laktose, + staerke, + akaziengummi + ), + "Herzrasen, Gewichtsverlust", + "Oral", + 90, + new ArrayList<>() )); medications.add(new Medication( - "Warfarin", - "Apotex Inc.", - List.of( - warfarinnatrium, - laktose, - staerke, - magnesiumstearat - ), - "Blutungen, Blutergüsse", - "Oral", - 110 + "Warfarin", + "Apotex Inc.", + List.of( + warfarinnatrium, + laktose, + staerke, + magnesiumstearat + ), + "Blutungen, Blutergüsse", + "Oral", + 110, + new ArrayList<>() )); MedicationDao dao = DaoFactory.getInstance().createMedicationDAO(); Map medicationsByName = new HashMap<>(); diff --git a/src/main/java/de/hitec/nhplus/medication/Medication.java b/src/main/java/de/hitec/nhplus/medication/Medication.java index 7fdce57..02971eb 100644 --- a/src/main/java/de/hitec/nhplus/medication/Medication.java +++ b/src/main/java/de/hitec/nhplus/medication/Medication.java @@ -23,6 +23,7 @@ public class Medication { private final SimpleStringProperty possibleSideEffects; private final SimpleStringProperty administrationMethod; private final SimpleIntegerProperty currentStock; + private final SimpleListProperty alternativeMedication; /** * This constructor allows instantiating a {@link Medication} object, @@ -37,7 +38,8 @@ public class Medication { List ingredients, String possibleSideEffects, String administrationMethod, - int currentStock + int currentStock, + List alternativeMedication ) { this.name = new SimpleStringProperty(name); this.manufacturer = new SimpleStringProperty(manufacturer); @@ -45,6 +47,7 @@ public class Medication { this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects); this.administrationMethod = new SimpleStringProperty(administrationMethod); this.currentStock = new SimpleIntegerProperty(currentStock); + this.alternativeMedication = new SimpleListProperty<>(FXCollections.observableArrayList(alternativeMedication)); } /** @@ -57,7 +60,8 @@ public class Medication { List ingredients, String possibleSideEffects, String administrationMethod, - int currentStock + int currentStock, + List alternativeMedication ) { this.id = new SimpleIntegerProperty(id); this.name = new SimpleStringProperty(name); @@ -66,6 +70,7 @@ public class Medication { this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects); this.administrationMethod = new SimpleStringProperty(administrationMethod); this.currentStock = new SimpleIntegerProperty(currentStock); + this.alternativeMedication = new SimpleListProperty<>(FXCollections.observableArrayList(alternativeMedication)); } public int getId() { @@ -124,6 +129,18 @@ public class Medication { this.possibleSideEffects.set(possibleSideEffects); } + public ObservableList getAlternativeMedication() { + return alternativeMedication.get(); + } + + public SimpleListProperty alternativeMedicationProperty() { + return alternativeMedication; + } + + public void setAlternativeMedication(ObservableList alternativeMedication) { + this.alternativeMedication.set(alternativeMedication); + } + public String getAdministrationMethod() { return administrationMethod.get(); } @@ -162,6 +179,7 @@ public class Medication { .add("Possible Side Effects: " + this.getPossibleSideEffects()) .add("Administration Method: " + this.getAdministrationMethod()) .add("Current Stock: " + this.getCurrentStock()) + .add("Alternative Medication" + this.getAlternativeMedication()) .toString(); } diff --git a/src/main/java/de/hitec/nhplus/medication/MedicationModalController.java b/src/main/java/de/hitec/nhplus/medication/MedicationModalController.java index fa89b39..d30c609 100644 --- a/src/main/java/de/hitec/nhplus/medication/MedicationModalController.java +++ b/src/main/java/de/hitec/nhplus/medication/MedicationModalController.java @@ -70,7 +70,8 @@ public class MedicationModalController { new ArrayList<>(), "", "", - 0 + 0, + new ArrayList<>() ); this.buttonSave.setDisable(true); } @@ -161,10 +162,11 @@ public class MedicationModalController { alternativeMediaction.add(new Medication( null, null, - List.of(), + new ArrayList<>(), null, null, - -1 + -1, + new ArrayList<>() )); } } 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 e226770..97d5fe6 100644 --- a/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java +++ b/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java @@ -63,6 +63,18 @@ public class MedicationDao implements Dao { ingredientStatement.setString(2, ingredient.getName()); ingredientStatement.execute(); } + + final String alternativeMedicationSQL = """ + INSERT INTO medication_alternative + (id, alternativeId) + VALUES (?, ?); + """; + for (Medication alternative : medication.getAlternativeMedication()) { + PreparedStatement alternativeStatement = this.connection.prepareStatement(alternativeMedicationSQL); + alternativeStatement.setInt(1, newId); + alternativeStatement.setInt(2, alternative.getId()); + alternativeStatement.execute(); + } } @Override @@ -82,7 +94,7 @@ public class MedicationDao implements Dao { @Override public List readAll() throws SQLException { final String SQL = """ - SELECT medication.*, medication_ingredient.name + SELECT medication.*, medication_ingredient.name, medication_alternative.alternativeId FROM medication LEFT JOIN medication_ingredient ON medication.id = medication_ingredient.id """; @@ -103,7 +115,8 @@ public class MedicationDao implements Dao { new ArrayList<>(), result.getString(4), result.getString(5), - result.getInt(6) + result.getInt(6), + new ArrayList<>() ); medications.add(medication); } @@ -188,10 +201,11 @@ public class MedicationDao implements Dao { result.getInt(1), result.getString(2), result.getString(3), - List.of(), + new ArrayList<>(), result.getString(4), result.getString(5), - result.getInt(6) + result.getInt(6), + new ArrayList<>() ); List ingredients = new ArrayList<>(); diff --git a/src/main/resources/de/hitec/nhplus/medication/database/Medication_Alternative.sql b/src/main/resources/de/hitec/nhplus/medication/database/Medication_Alternative.sql new file mode 100644 index 0000000..76e3364 --- /dev/null +++ b/src/main/resources/de/hitec/nhplus/medication/database/Medication_Alternative.sql @@ -0,0 +1,7 @@ +CREATE TABLE medication_alternative +( + id INTEGER NOT NULL , + alternativeId INTEGER NOT NULL , + FOREIGN KEY (id) REFERENCES medication (id) ON DELETE CASCADE, + FOREIGN KEY (alternativeId) REFERENCES medication (id) ON DELETE CASCADE +) \ No newline at end of file