diff --git a/.idea/sqlDataSources.xml b/.idea/sqlDataSources.xml
index e75a467..f73128a 100644
--- a/.idea/sqlDataSources.xml
+++ b/.idea/sqlDataSources.xml
@@ -25,6 +25,8 @@
+
+
diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml
index aecddda..b2ef682 100644
--- a/.idea/sqldialects.xml
+++ b/.idea/sqldialects.xml
@@ -3,7 +3,6 @@
-
\ No newline at end of file
diff --git a/db/nursingHome.db b/db/nursingHome.db
index 2f42a9d..c3e0182 100644
Binary files a/db/nursingHome.db and b/db/nursingHome.db differ
diff --git a/src/main/java/de/hitec/nhplus/datastorage/ConnectionBuilder.java b/src/main/java/de/hitec/nhplus/datastorage/ConnectionBuilder.java
index 82cea08..3b1bcf2 100644
--- a/src/main/java/de/hitec/nhplus/datastorage/ConnectionBuilder.java
+++ b/src/main/java/de/hitec/nhplus/datastorage/ConnectionBuilder.java
@@ -21,7 +21,6 @@ public class ConnectionBuilder {
/**
* @return a Thread-safe {@link Connection} to the Database.
- * @author Bernd Heidemann
*/
synchronized public static Connection getConnection() {
try {
@@ -39,8 +38,6 @@ public class ConnectionBuilder {
/**
* Closes the Connection to the Database.
- *
- * @author Bernd Heidemann
*/
synchronized public static void closeConnection() {
try {
diff --git a/src/main/java/de/hitec/nhplus/datastorage/Dao.java b/src/main/java/de/hitec/nhplus/datastorage/Dao.java
index 0a38d48..477faf5 100644
--- a/src/main/java/de/hitec/nhplus/datastorage/Dao.java
+++ b/src/main/java/de/hitec/nhplus/datastorage/Dao.java
@@ -17,7 +17,6 @@ public interface Dao {
* Create a Database Entry from a Model object.
*
* @param t the Model instance
- * @author Bernd Heidemann
*/
void create(T t) throws SQLException;
@@ -25,14 +24,11 @@ public interface Dao {
* Read a Database Entry to a Model object.
*
* @param id of the Element in the Database
- * @author Bernd Heidemann
*/
T read(int id) throws SQLException;
/**
* Read all Database Entries to a {@link List} of Model objects.
- *
- * @author Bernd Heidemann
*/
List readAll() throws SQLException;
@@ -40,7 +36,6 @@ public interface Dao {
* Update the Database according to the Values of the Model object.
*
* @param t the Model instance.
- * @author Bernd Heidemann
*/
void update(T t) throws SQLException;
@@ -48,7 +43,6 @@ public interface Dao {
* Delete a Database Entry.
*
* @param id of the Element in the Database.
- * @author Bernd Heidemann
*/
void delete(int id) throws SQLException;
}
diff --git a/src/main/java/de/hitec/nhplus/datastorage/DaoFactory.java b/src/main/java/de/hitec/nhplus/datastorage/DaoFactory.java
index f4fc8dc..5fcebc7 100644
--- a/src/main/java/de/hitec/nhplus/datastorage/DaoFactory.java
+++ b/src/main/java/de/hitec/nhplus/datastorage/DaoFactory.java
@@ -1,5 +1,6 @@
package de.hitec.nhplus.datastorage;
+import de.hitec.nhplus.medication.database.MedicationDao;
import de.hitec.nhplus.nurse.database.NurseDao;
import de.hitec.nhplus.patient.database.PatientDao;
import de.hitec.nhplus.treatment.database.TreatmentDao;
@@ -16,15 +17,12 @@ public class DaoFactory {
/**
* A Private Constructor according to the Singleton Pattern.
- *
- * @author Bernd Heidemann
*/
private DaoFactory() {
}
/**
* @return {@link DaoFactory}, the Singleton Instance
- * @author Bernd Heidemann
*/
public static DaoFactory getInstance() {
if (DaoFactory.instance == null) {
@@ -35,7 +33,6 @@ public class DaoFactory {
/**
* @return a {@link TreatmentDao}
- * @author Bernd Heidemann
*/
public TreatmentDao createTreatmentDao() {
return new TreatmentDao(ConnectionBuilder.getConnection());
@@ -43,7 +40,6 @@ public class DaoFactory {
/**
* @return a {@link PatientDao}
- * @author Bernd Heidemann
*/
public PatientDao createPatientDAO() {
return new PatientDao(ConnectionBuilder.getConnection());
@@ -51,9 +47,15 @@ public class DaoFactory {
/**
* @return a {@link NurseDao}
- * @author Dominik Säume
*/
public NurseDao createNurseDAO() {
return new NurseDao(ConnectionBuilder.getConnection());
}
+
+ /**
+ * @return a {@link MedicationDao}
+ */
+ public MedicationDao createMedicationDAO() {
+ return new MedicationDao(ConnectionBuilder.getConnection());
+ }
}
diff --git a/src/main/java/de/hitec/nhplus/datastorage/DaoImp.java b/src/main/java/de/hitec/nhplus/datastorage/DaoImp.java
index 417c285..a9c7ff6 100644
--- a/src/main/java/de/hitec/nhplus/datastorage/DaoImp.java
+++ b/src/main/java/de/hitec/nhplus/datastorage/DaoImp.java
@@ -20,7 +20,6 @@ public abstract class DaoImp implements Dao {
/**
* @param connection a Database Connection, which should be gotten from {@link ConnectionBuilder}
- * @author Bernd Heidemann
*/
public DaoImp(Connection connection) {
this.connection = connection;
@@ -30,7 +29,6 @@ public abstract class DaoImp implements Dao {
* Creates a new Database Entry from a Model object.
*
* @param t the Model instance
- * @author Bernd Heidemann
*/
@Override
public void create(T t) throws SQLException {
@@ -41,7 +39,6 @@ public abstract class DaoImp implements Dao {
* Read a Database Entry to a Model object.
*
* @param id of the Element in the Database
- * @author Bernd Heidemann
*/
@Override
public T read(int id) throws SQLException {
@@ -55,8 +52,6 @@ public abstract class DaoImp implements Dao {
/**
* Read all Database Entries to a {@link List} of Model objects.
- *
- * @author Bernd Heidemann
*/
@Override
public List readAll() throws SQLException {
@@ -67,7 +62,6 @@ public abstract class DaoImp implements Dao {
* Update the Database according to the Values of the Model object.
*
* @param t the Model instance.
- * @author Bernd Heidemann
*/
@Override
public void update(T t) throws SQLException {
@@ -78,7 +72,6 @@ public abstract class DaoImp implements Dao {
* Delete a Database Entry.
*
* @param id of the Element in the Database.
- * @author Bernd Heidemann
*/
@Override
public void delete(int id) throws SQLException {
diff --git a/src/main/java/de/hitec/nhplus/fixtures/Fixtures.java b/src/main/java/de/hitec/nhplus/fixtures/Fixtures.java
index 5c98676..9497632 100644
--- a/src/main/java/de/hitec/nhplus/fixtures/Fixtures.java
+++ b/src/main/java/de/hitec/nhplus/fixtures/Fixtures.java
@@ -29,6 +29,11 @@ public class Fixtures
nurseFixture.setupTable(connection);
nurseFixture.load();
+ MedicationFixture medicationFixture = new MedicationFixture();
+ medicationFixture.dropTable(connection);
+ medicationFixture.setupTable(connection);
+ medicationFixture.load();
+
} catch (Exception exception){
System.out.println(exception.getMessage());
}
diff --git a/src/main/java/de/hitec/nhplus/fixtures/MedicationFixture.java b/src/main/java/de/hitec/nhplus/fixtures/MedicationFixture.java
new file mode 100644
index 0000000..719e53c
--- /dev/null
+++ b/src/main/java/de/hitec/nhplus/fixtures/MedicationFixture.java
@@ -0,0 +1,157 @@
+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.*;
+
+
+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";
+
+ @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");
+ }
+
+ @Override
+ public void setupTable(Connection connection) throws SQLException {
+
+ final InputStream schema = Main.class.getResourceAsStream(SCHEMA);
+ final InputStream ingredientSchema = Main.class.getResourceAsStream(INGREDIENT_SCHEMA);
+ assert schema != null;
+ assert ingredientSchema != null;
+ String SQL = new Scanner(schema, StandardCharsets.UTF_8)
+ .useDelimiter("\\A")
+ .next();
+ String ingredientSQL = ";" + new Scanner(ingredientSchema, StandardCharsets.UTF_8)
+ .useDelimiter("\\A")
+ .next();
+ connection.createStatement().execute(SQL);
+ connection.createStatement().execute(ingredientSQL);
+
+ }
+
+ @Override
+ public Map load() throws SQLException {
+ List medications = new ArrayList<>();
+
+ Ingredient metforminhydrochlorid = new Ingredient("Metforminhydrochlorid");
+ Ingredient cellulose = new Ingredient("Cellulose");
+ Ingredient povidon = new Ingredient("Povidon");
+ Ingredient magnesiumstearat = new Ingredient("Magnesiumstearat");
+ Ingredient lisinoprilDihydrat = new Ingredient("Lisinopril-Dihydrat");
+ Ingredient mannitol = new Ingredient("Mannitol");
+ Ingredient calciumphosphat = new Ingredient("Calciumphosphat");
+ Ingredient simvastatin = new Ingredient("Simvastatin");
+ Ingredient laktose = new Ingredient("Laktose");
+ Ingredient enoxaparinNatrium = new Ingredient("Enoxaparin-Natrium");
+ Ingredient benzylalkohol = new Ingredient("Benzylalkohol");
+ Ingredient wasser = new Ingredient("Wasser");
+ Ingredient levothyroxinnatrium = new Ingredient("Levothyroxinnatrium");
+ Ingredient staerke = new Ingredient("Stärke");
+ Ingredient akaziengummi = new Ingredient("Akaziengummi");
+ Ingredient warfarinnatrium = new Ingredient("Warfarinnatrium");
+
+ medications.add(new Medication(
+ 1,
+ "Metformin",
+ "AstraZeneca",
+ List.of(
+ metforminhydrochlorid,
+ cellulose,
+ povidon,
+ magnesiumstearat
+ ),
+ "Übelkeit, Durchfall, Laktatazidose (selten)",
+ "Oral",
+ 100
+ ));
+ medications.add(new Medication(
+ 2,
+ "Lisinopril",
+ "Teva Pharmaceuticals",
+ List.of(
+ lisinoprilDihydrat,
+ mannitol,
+ calciumphosphat,
+ magnesiumstearat
+ ),
+ "Schwindel, trockener Husten",
+ "Oral",
+ 150
+ ));
+ medications.add(new Medication(
+ 3,
+ "Simvastatin",
+ "Mylan",
+ List.of(
+ simvastatin,
+ laktose,
+ cellulose,
+ magnesiumstearat
+ ),
+ "Muskelschmerzen, Leberprobleme(selten)",
+ "Oral",
+ 80
+ ));
+ medications.add(new Medication(
+ 4,
+ "Enoxaparin",
+ "Sanofi",
+ List.of(
+ enoxaparinNatrium,
+ benzylalkohol,
+ wasser
+ ),
+ "Blutungen, Reaktionen an der Injektionsstelle",
+ "Unterhautinjektion",
+ 120
+ ));
+ medications.add(new Medication(
+ 5,
+ "Levothyroxin",
+ "Sandoz",
+ List.of(
+ levothyroxinnatrium,
+ laktose,
+ staerke,
+ akaziengummi
+ ),
+ "Herzrasen, Gewichtsverlust",
+ "Oral",
+ 90
+ ));
+ medications.add(new Medication(
+ 6,
+ "Warfarin",
+ "Apotex Inc.",
+ List.of(
+ warfarinnatrium,
+ laktose,
+ staerke,
+ magnesiumstearat
+ ),
+ "Blutungen, Blutergüsse",
+ "Oral",
+ 110
+ ));
+ MedicationDao dao = DaoFactory.getInstance().createMedicationDAO();
+ Map medicationsByName = new HashMap<>();
+ for (Medication medication : medications) {
+ dao.create(medication);
+ medicationsByName.put(medication.getName(), medication);
+ }
+ return medicationsByName;
+
+ }
+}
diff --git a/src/main/java/de/hitec/nhplus/fixtures/NurseFixture.java b/src/main/java/de/hitec/nhplus/fixtures/NurseFixture.java
index c31bb4d..7c2d98a 100644
--- a/src/main/java/de/hitec/nhplus/fixtures/NurseFixture.java
+++ b/src/main/java/de/hitec/nhplus/fixtures/NurseFixture.java
@@ -14,7 +14,7 @@ import java.util.*;
public class NurseFixture implements Fixture {
@Override
public void dropTable(Connection connection) throws SQLException {
- connection.createStatement().execute("DROP TABLE nurse");
+ connection.createStatement().execute("DROP TABLE IF EXISTS nurse");
}
@Override
diff --git a/src/main/java/de/hitec/nhplus/fixtures/PatientFixture.java b/src/main/java/de/hitec/nhplus/fixtures/PatientFixture.java
index dc040bf..372a832 100644
--- a/src/main/java/de/hitec/nhplus/fixtures/PatientFixture.java
+++ b/src/main/java/de/hitec/nhplus/fixtures/PatientFixture.java
@@ -16,7 +16,7 @@ import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalDate;
public class PatientFixture implements Fixture {
@Override
public void dropTable(Connection connection) throws SQLException {
- connection.createStatement().execute("DROP TABLE patient");
+ connection.createStatement().execute("DROP TABLE IF EXISTS patient");
}
@Override
diff --git a/src/main/java/de/hitec/nhplus/fixtures/TreatmentFixture.java b/src/main/java/de/hitec/nhplus/fixtures/TreatmentFixture.java
index 3925d3a..cd2b7dc 100644
--- a/src/main/java/de/hitec/nhplus/fixtures/TreatmentFixture.java
+++ b/src/main/java/de/hitec/nhplus/fixtures/TreatmentFixture.java
@@ -24,7 +24,7 @@ public class TreatmentFixture implements Fixture {
@Override
public void dropTable(Connection connection) throws SQLException {
- connection.createStatement().execute("DROP TABLE treatment");
+ connection.createStatement().execute("DROP TABLE IF EXISTS treatment");
}
@Override
diff --git a/src/main/java/de/hitec/nhplus/main/MainWindowController.java b/src/main/java/de/hitec/nhplus/main/MainWindowController.java
index 6f0ee03..5c70576 100644
--- a/src/main/java/de/hitec/nhplus/main/MainWindowController.java
+++ b/src/main/java/de/hitec/nhplus/main/MainWindowController.java
@@ -26,6 +26,10 @@ public class MainWindowController {
private AnchorPane nursePage;
@FXML
private Tab nurseTab;
+ @FXML
+ private AnchorPane medicationPage;
+ @FXML
+ private Tab medicationTab;
@FXML
public void initialize() {
@@ -35,7 +39,7 @@ public class MainWindowController {
patientTab.setOnSelectionChanged(event -> loadPatientPage());
treatmentTab.setOnSelectionChanged(event -> loadTreatmentsPage());
nurseTab.setOnSelectionChanged(event -> loadNursePage());
-
+ medicationTab.setOnSelectionChanged(event -> loadMedicationPage());
}
private void loadPatientPage() {
@@ -82,4 +86,19 @@ public class MainWindowController {
exception.printStackTrace();
}
}
+
+ private void loadMedicationPage() {
+ try {
+ BorderPane medicationPane = FXMLLoader.load(
+ Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/medication/AllMedicationView.fxml"))
+ );
+ medicationPage.getChildren().setAll(medicationPane);
+ AnchorPane.setTopAnchor(medicationPane, 0d);
+ AnchorPane.setBottomAnchor(medicationPane, 0d);
+ AnchorPane.setLeftAnchor(medicationPane, 0d);
+ AnchorPane.setRightAnchor(medicationPane, 0d);
+ } catch (IOException exception) {
+ exception.printStackTrace();
+ }
+ }
}
diff --git a/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java b/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java
new file mode 100644
index 0000000..8f3bb55
--- /dev/null
+++ b/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java
@@ -0,0 +1,69 @@
+package de.hitec.nhplus.medication;
+
+import de.hitec.nhplus.datastorage.DaoFactory;
+import de.hitec.nhplus.medication.database.MedicationDao;
+import javafx.beans.property.SimpleStringProperty;
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javafx.fxml.FXML;
+import javafx.scene.control.TableColumn;
+import javafx.scene.control.TableView;
+import javafx.scene.control.cell.PropertyValueFactory;
+
+import java.sql.SQLException;
+import java.util.stream.Collectors;
+
+public class AllMedicationController {
+ @FXML
+ private TableView tableView;
+ @FXML
+ private TableColumn columnId;
+ @FXML
+ private TableColumn columnName;
+ @FXML
+ private TableColumn columnManufacturer;
+ @FXML
+ private TableColumn columnIngredient;
+ @FXML
+ private TableColumn columnPossibleSideEffects;
+ @FXML
+ private TableColumn columnAdministrationMethod;
+ @FXML
+ private TableColumn columnCurrentStock;
+
+ private final ObservableList medications = FXCollections.observableArrayList();
+ private MedicationDao dao;
+
+ public void initialize() {
+ readAllAndShowInTableView();
+
+ this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
+ this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
+ this.columnManufacturer.setCellValueFactory(new PropertyValueFactory<>("manufacturer"));
+ this.columnIngredient.setCellValueFactory(
+ cellData -> {
+ return new SimpleStringProperty(
+ cellData
+ .getValue()
+ .getIngredients()
+ .stream()
+ .map(ingredient -> ingredient.getName())
+ .collect(Collectors.joining("\n"))
+ );
+ });
+ this.columnPossibleSideEffects.setCellValueFactory(new PropertyValueFactory<>("possibleSideEffects"));
+ this.columnAdministrationMethod.setCellValueFactory(new PropertyValueFactory<>("administrationMethod"));
+ this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock"));
+
+ this.tableView.setItems(this.medications);
+ }
+
+ public void readAllAndShowInTableView() {
+ this.dao = DaoFactory.getInstance().createMedicationDAO();
+ try {
+ this.medications.setAll(dao.readAll());
+ } catch (SQLException exception) {
+ exception.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/de/hitec/nhplus/medication/Ingredient.java b/src/main/java/de/hitec/nhplus/medication/Ingredient.java
new file mode 100644
index 0000000..626e3c0
--- /dev/null
+++ b/src/main/java/de/hitec/nhplus/medication/Ingredient.java
@@ -0,0 +1,25 @@
+package de.hitec.nhplus.medication;
+
+import javafx.beans.property.SimpleStringProperty;
+
+public class Ingredient {
+ private final SimpleStringProperty name;
+
+ public Ingredient(String name) {
+ this.name = new SimpleStringProperty(name);
+ }
+
+ public String getName() {
+ return name.get();
+ }
+
+ public SimpleStringProperty nameProperty() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name.set(name);
+ }
+
+
+}
diff --git a/src/main/java/de/hitec/nhplus/medication/Medication.java b/src/main/java/de/hitec/nhplus/medication/Medication.java
new file mode 100644
index 0000000..f27a312
--- /dev/null
+++ b/src/main/java/de/hitec/nhplus/medication/Medication.java
@@ -0,0 +1,152 @@
+package de.hitec.nhplus.medication;
+
+import javafx.beans.property.SimpleIntegerProperty;
+import javafx.beans.property.SimpleListProperty;
+import javafx.beans.property.SimpleStringProperty;
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+
+import java.util.List;
+import java.util.StringJoiner;
+import java.util.stream.Collectors;
+
+public class Medication {
+ private SimpleIntegerProperty id;
+ private final SimpleStringProperty name;
+ private final SimpleStringProperty manufacturer;
+ private final SimpleListProperty ingredients;
+ private final SimpleStringProperty possibleSideEffects;
+ private final SimpleStringProperty administrationMethod;
+ private final SimpleIntegerProperty currentStock;
+
+ public Medication(
+ String name,
+ String manufacturer,
+ List ingredients,
+ String possibleSideEffects,
+ String administrationMethod,
+ int currentStock
+ ) {
+ this.name = new SimpleStringProperty(name);
+ this.manufacturer = new SimpleStringProperty(manufacturer);
+ this.ingredients = new SimpleListProperty<>(FXCollections.observableArrayList(ingredients));
+ this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects);
+ this.administrationMethod = new SimpleStringProperty(administrationMethod);
+ this.currentStock = new SimpleIntegerProperty(currentStock);
+ }
+
+ public Medication(
+ int id,
+ String name,
+ String manufacturer,
+ List ingredients,
+ String possibleSideEffects,
+ String administrationMethod,
+ int currentStock
+ ) {
+ this.id = new SimpleIntegerProperty(id);
+ this.name = new SimpleStringProperty(name);
+ this.manufacturer = new SimpleStringProperty(manufacturer);
+ this.ingredients = new SimpleListProperty<>(FXCollections.observableArrayList(ingredients));
+ this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects);
+ this.administrationMethod = new SimpleStringProperty(administrationMethod);
+ this.currentStock = new SimpleIntegerProperty(currentStock);
+ }
+
+ public int getId() {
+ return id.get();
+ }
+
+ public SimpleIntegerProperty idProperty() {
+ return id;
+ }
+
+ public String getName() {
+ return name.get();
+ }
+
+ public SimpleStringProperty nameProperty() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name.set(name);
+ }
+
+ public String getManufacturer() {
+ return manufacturer.get();
+ }
+
+ public SimpleStringProperty manufacturerProperty() {
+ return manufacturer;
+ }
+
+ public void setManufacturer(String manufacturer) {
+ this.manufacturer.set(manufacturer);
+ }
+
+ public ObservableList getIngredients() {
+ return ingredients.get();
+ }
+
+ public SimpleListProperty ingredientsProperty() {
+ return ingredients;
+ }
+
+ public void setIngredients(List ingredients) {
+ this.ingredients.set(FXCollections.observableArrayList(ingredients));
+ }
+
+ public String getPossibleSideEffects() {
+ return possibleSideEffects.get();
+ }
+
+ public SimpleStringProperty possibleSideEffectsProperty() {
+ return possibleSideEffects;
+ }
+
+ public void setPossibleSideEffects(String possibleSideEffects) {
+ this.possibleSideEffects.set(possibleSideEffects);
+ }
+
+ public String getAdministrationMethod() {
+ return administrationMethod.get();
+ }
+
+ public SimpleStringProperty administrationMethodProperty() {
+ return administrationMethod;
+ }
+
+ public void setAdministrationMethod(String administrationMethod) {
+ this.administrationMethod.set(administrationMethod);
+ }
+
+ public int getCurrentStock() {
+ return currentStock.get();
+ }
+
+ public SimpleIntegerProperty currentStockProperty() {
+ return currentStock;
+ }
+
+ public void setCurrentStock(int currentStock) {
+ this.currentStock.set(currentStock);
+ }
+
+ @Override
+ public String toString() {
+ return new StringJoiner(System.lineSeparator())
+ .add("MEDICATION")
+ .add("ID: " + this.getId())
+ .add("Name: " + this.getName())
+ .add("Manufacturer: " + this.getManufacturer())
+ .add("Ingredients: " + this.getIngredients()
+ .stream()
+ .map(Ingredient::getName)
+ .collect(Collectors.joining(", ", "[", "]")))
+ .add("Possible Side Effects: " + this.getPossibleSideEffects())
+ .add("Administration Method: " + this.getAdministrationMethod())
+ .add("Current Stock: " + this.getCurrentStock())
+ .toString();
+ }
+}
diff --git a/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java b/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java
new file mode 100644
index 0000000..4170582
--- /dev/null
+++ b/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java
@@ -0,0 +1,175 @@
+package de.hitec.nhplus.medication.database;
+
+import de.hitec.nhplus.datastorage.Dao;
+import de.hitec.nhplus.medication.Ingredient;
+import de.hitec.nhplus.medication.Medication;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class MedicationDao implements Dao {
+ protected final Connection connection;
+
+ public MedicationDao(Connection connection) {
+ this.connection = connection;
+ }
+
+ @Override
+ public void create(Medication medication) throws SQLException {
+ final String medicationSQL = """
+ INSERT INTO medication
+ (name, manufacturer, possibleSideEffects, administrationMethod, currentStock)
+ VALUES (?, ?, ?, ?, ?);
+ """;
+ PreparedStatement medicationStatement = this.connection.prepareStatement(medicationSQL);
+ medicationStatement.setString(1, medication.getName());
+ medicationStatement.setString(2, medication.getManufacturer());
+ medicationStatement.setString(3, medication.getPossibleSideEffects());
+ medicationStatement.setString(4, medication.getAdministrationMethod());
+ medicationStatement.setInt(5, medication.getCurrentStock());
+ medicationStatement.execute();
+
+ final String ingredientSQL = """
+ INSERT INTO medication_ingredient
+ (id, name)
+ VALUES (?, ?);
+ """;
+ for (Ingredient ingredient : medication.getIngredients()) {
+ PreparedStatement ingredientStatement = this.connection.prepareStatement(ingredientSQL);
+ ingredientStatement.setInt(1, medication.getId());
+ ingredientStatement.setString(2, ingredient.getName());
+ ingredientStatement.execute();
+ }
+ }
+
+ @Override
+ public Medication read(int id) throws SQLException {
+ final String SQL = """
+ SELECT medication.*, medication_ingredient.id
+ FROM medication
+ LEFT JOIN medication_ingredient ON medication.id = medication_ingredient.id
+ WHERE medication.id = ?
+ """;
+ PreparedStatement statement = this.connection.prepareStatement(SQL);
+ statement.setInt(1, id);
+ ResultSet result = statement.executeQuery();
+ return getInstanceFromResultSet(result);
+ }
+
+ @Override
+ public List readAll() throws SQLException {
+ final String SQL = """
+ SELECT medication.*, medication_ingredient.name
+ FROM medication LEFT JOIN
+ medication_ingredient ON medication.id = medication_ingredient.id
+ """;
+ 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),
+ List.of(),
+ result.getString(4),
+ result.getString(5),
+ result.getInt(6)
+ );
+ medications.add(medication);
+ lastMedicationId = currentMedicationId;
+ continue;
+ }
+ List ingredients = ingredientMap.computeIfAbsent(currentMedicationId, k -> new ArrayList<>());
+ ingredients.add(new Ingredient(result.getString(7)));
+ lastMedicationId = currentMedicationId;
+ }
+ for (Medication medication : medications) {
+ medication.setIngredients(ingredientMap.get(medication.getId()));
+ }
+
+ return medications;
+ }
+
+ @Override
+ public void update(Medication medication) throws SQLException {
+ final String SQL = """
+ UPDATE medication SET
+ name = ?,
+ manufacturer = ?,
+ possibleSideEffects = ?,
+ administrationMethod = ?,
+ currentStock = ?
+ WHERE id = ?
+ """;
+ PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
+ preparedStatement.setString(1, medication.getName());
+ preparedStatement.setString(2, medication.getManufacturer());
+ preparedStatement.setString(3, medication.getPossibleSideEffects());
+ preparedStatement.setString(4, medication.getAdministrationMethod());
+ preparedStatement.setInt(5, medication.getCurrentStock());
+ preparedStatement.setInt(6, medication.getId());
+ preparedStatement.executeUpdate();
+
+ final String ingredientDeleteSQL = """
+ DELETE FROM medication_ingredient WHERE id = ?
+ """;
+ PreparedStatement ingredientStatement = this.connection.prepareStatement(ingredientDeleteSQL);
+ ingredientStatement.setInt(1, medication.getId());
+ ingredientStatement.executeUpdate();
+
+ final String ingredientCreateSQL = """
+ INSERT INTO medication_ingredient
+ (id, name)
+ VALUES (?, ?);
+ """;
+ for (Ingredient ingredient : medication.getIngredients()) {
+ PreparedStatement statement = this.connection.prepareStatement(ingredientCreateSQL);
+ statement.setInt(1, medication.getId());
+ statement.setString(2, ingredient.getName());
+ statement.execute();
+ }
+ }
+
+ @Override
+ public void delete(int id) throws SQLException {
+ final String SQL = """
+ DELETE FROM medication WHERE medication.id = ?;
+ """;
+ PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
+ preparedStatement.setInt(1, id);
+ preparedStatement.executeUpdate();
+ }
+
+ private Medication getInstanceFromResultSet(ResultSet result) throws SQLException {
+ Medication medication = new Medication(
+ result.getInt(1),
+ result.getString(2),
+ result.getString(3),
+ List.of(),
+ result.getString(4),
+ result.getString(5),
+ result.getInt(6)
+ );
+
+ List ingredients = new ArrayList<>();
+ while (result.next()) {
+ ingredients.add(new Ingredient(result.getString(2)));
+
+ }
+ medication.setIngredients(ingredients);
+ return medication;
+ }
+}
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index 84a02fd..06e67a7 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -24,4 +24,9 @@ module de.hitec.nhplus {
exports de.hitec.nhplus.nurse.database;
opens de.hitec.nhplus.nurse to javafx.base, javafx.fxml;
opens de.hitec.nhplus.nurse.database to javafx.base, javafx.fxml;
+
+ exports de.hitec.nhplus.medication;
+ exports de.hitec.nhplus.medication.database;
+ opens de.hitec.nhplus.medication to javafx.base, javafx.fxml;
+ opens de.hitec.nhplus.medication.database to javafx.base, javafx.fxml;
}
diff --git a/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml b/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml
index 7d1697d..2c63236 100644
--- a/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml
+++ b/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml
@@ -1,7 +1,6 @@
-
-
+
-
-
-
+
+
+
+
+
+
diff --git a/src/main/resources/de/hitec/nhplus/medication/AllMedicationView.fxml b/src/main/resources/de/hitec/nhplus/medication/AllMedicationView.fxml
new file mode 100644
index 0000000..f5ee43b
--- /dev/null
+++ b/src/main/resources/de/hitec/nhplus/medication/AllMedicationView.fxml
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/de/hitec/nhplus/medication/database/Medication.sql b/src/main/resources/de/hitec/nhplus/medication/database/Medication.sql
new file mode 100644
index 0000000..fc7c049
--- /dev/null
+++ b/src/main/resources/de/hitec/nhplus/medication/database/Medication.sql
@@ -0,0 +1,9 @@
+CREATE TABLE medication
+(
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ manufacturer TEXT NOT NULL,
+ possibleSideEffects TEXT NOT NULL,
+ administrationMethod TEXT NOT NULL,
+ currentStock INTEGER NOT NULL
+)
\ No newline at end of file
diff --git a/src/main/resources/de/hitec/nhplus/medication/database/Medication_Ingredient.sql b/src/main/resources/de/hitec/nhplus/medication/database/Medication_Ingredient.sql
new file mode 100644
index 0000000..dce00b2
--- /dev/null
+++ b/src/main/resources/de/hitec/nhplus/medication/database/Medication_Ingredient.sql
@@ -0,0 +1,6 @@
+CREATE TABLE medication_ingredient
+(
+ id INTEGER NOT NULL ,
+ name TEXT NOT NULL,
+ FOREIGN KEY (id) REFERENCES medication (id) ON DELETE CASCADE
+)
\ No newline at end of file
diff --git a/src/main/resources/de/hitec/nhplus/nurse/AllNurseView.fxml b/src/main/resources/de/hitec/nhplus/nurse/AllNurseView.fxml
index eec0384..2597997 100644
--- a/src/main/resources/de/hitec/nhplus/nurse/AllNurseView.fxml
+++ b/src/main/resources/de/hitec/nhplus/nurse/AllNurseView.fxml
@@ -12,7 +12,7 @@