diff --git a/src/main/java/de/hitec/nhplus/main/MainWindowController.java b/src/main/java/de/hitec/nhplus/main/MainWindowController.java index c402020..cc6ba17 100644 --- a/src/main/java/de/hitec/nhplus/main/MainWindowController.java +++ b/src/main/java/de/hitec/nhplus/main/MainWindowController.java @@ -80,10 +80,16 @@ public class MainWindowController { Permissions.MANAGEMENT | Permissions.OWNER ) )); - tabManager.setupTab(mainTabPane, new TabStruct( - "Medikamente", - "/de/hitec/nhplus/medication/AllMedicationView.fxml", - Permissions.MANAGEMENT + tabManager.setupSubTabPane(mainTabPane, "Medikamente", Permissions.MANAGEMENT, List.of( + new TabStruct( + "Medikamente", + "/de/hitec/nhplus/medication/AllMedicationView.fxml", + Permissions.MANAGEMENT + ), new TabStruct( + "Veraltete Medikamente", + "/de/hitec/nhplus/medication/DeprecatedMedicationView.fxml", + Permissions.MANAGEMENT + ) )); diff --git a/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java b/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java new file mode 100644 index 0000000..6938407 --- /dev/null +++ b/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java @@ -0,0 +1,79 @@ +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.List; +import java.util.stream.Collectors; + +public class DeprecatedMedicationController { + @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; + + @FXML + 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 -> { + Medication medication = cellData.getValue(); + List ingredients = medication.getIngredients(); + if (ingredients.isEmpty()) { + return new SimpleStringProperty(""); + } + + return new SimpleStringProperty( + ingredients + .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); + } + + /** + * Internal method to read all data and set it to the table view. + */ + 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/Medication.java b/src/main/java/de/hitec/nhplus/medication/Medication.java index 6320e58..a73c8b3 100644 --- a/src/main/java/de/hitec/nhplus/medication/Medication.java +++ b/src/main/java/de/hitec/nhplus/medication/Medication.java @@ -1,5 +1,6 @@ package de.hitec.nhplus.medication; +import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleListProperty; import javafx.beans.property.SimpleStringProperty; @@ -23,6 +24,7 @@ public class Medication { private final SimpleStringProperty possibleSideEffects; private final SimpleStringProperty administrationMethod; private final SimpleIntegerProperty currentStock; + private final SimpleBooleanProperty isDeprecated; /** * This constructor allows instantiating a {@link Medication} object, @@ -45,6 +47,7 @@ public class Medication { this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects); this.administrationMethod = new SimpleStringProperty(administrationMethod); this.currentStock = new SimpleIntegerProperty(currentStock); + this.isDeprecated = new SimpleBooleanProperty(false); } /** @@ -57,7 +60,8 @@ public class Medication { List ingredients, String possibleSideEffects, String administrationMethod, - int currentStock + int currentStock, + boolean isDepreacted ) { 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.isDeprecated = new SimpleBooleanProperty(isDepreacted); } public int getId() { @@ -84,6 +89,18 @@ public class Medication { return name; } + public boolean isDeprecated() { + return isDeprecated.get(); + } + + public SimpleBooleanProperty isDeprecatedProperty() { + return isDeprecated; + } + + public void setIsDeprecated(boolean isDeprecated) { + this.isDeprecated.set(isDeprecated); + } + public void setName(String name) { this.name.set(name); } 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..36a0e5e 100644 --- a/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java +++ b/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java @@ -103,7 +103,8 @@ public class MedicationDao implements Dao { new ArrayList<>(), result.getString(4), result.getString(5), - result.getInt(6) + result.getInt(6), + result.getBoolean(7) ); medications.add(medication); } @@ -191,7 +192,8 @@ public class MedicationDao implements Dao { List.of(), result.getString(4), result.getString(5), - result.getInt(6) + result.getInt(6), + result.getBoolean(7) ); List ingredients = new ArrayList<>(); diff --git a/src/main/resources/de/hitec/nhplus/medication/DeprecatedMedicationView.fxml b/src/main/resources/de/hitec/nhplus/medication/DeprecatedMedicationView.fxml new file mode 100644 index 0000000..f140ac2 --- /dev/null +++ b/src/main/resources/de/hitec/nhplus/medication/DeprecatedMedicationView.fxml @@ -0,0 +1,77 @@ + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
\ No newline at end of file