diff --git a/src/main/java/de/hitec/nhplus/main/MainWindowController.java b/src/main/java/de/hitec/nhplus/main/MainWindowController.java index 51a7450..2e5910d 100644 --- a/src/main/java/de/hitec/nhplus/main/MainWindowController.java +++ b/src/main/java/de/hitec/nhplus/main/MainWindowController.java @@ -48,6 +48,12 @@ public class MainWindowController { private AnchorPane medicationPage; @FXML private Tab medicationTab; + @FXML + private TabPane medicationTabPane; + @FXML + private AnchorPane deprecatedMedicationPage; + @FXML + private Tab deprecatedMedicationTab; /** @@ -63,11 +69,13 @@ public class MainWindowController { nurseTab.setOnSelectionChanged(event -> loadNursePage()); medicationTab.setOnSelectionChanged(event -> loadMedicationPage()); - - nurseTabPane.getSelectionModel().select(activeNurseTab); - activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage()); lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage()); + medicationTab.setOnSelectionChanged(event -> loadMedicationPage()); + deprecatedMedicationTab.setOnSelectionChanged(event -> loadDeprecatedMedicationPage()); + + nurseTabPane.getSelectionModel().select(activeNurseTab); + medicationTabPane.getSelectionModel().select(medicationTab); } /** @@ -173,4 +181,19 @@ public class MainWindowController { exception.printStackTrace(); } } + + private void loadDeprecatedMedicationPage(){ + try { + BorderPane deprecatedMedicationPane = FXMLLoader.load( + Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/medication/DeprecatedMedicationView.fxml")) + ); + deprecatedMedicationPage.getChildren().setAll(deprecatedMedicationPane); + AnchorPane.setTopAnchor(deprecatedMedicationPane, 0d); + AnchorPane.setBottomAnchor(deprecatedMedicationPane, 0d); + AnchorPane.setLeftAnchor(deprecatedMedicationPane, 0d); + AnchorPane.setRightAnchor(deprecatedMedicationPane, 0d); + } catch (IOException exception) { + exception.printStackTrace(); + } + } } 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/main/MainWindowView.fxml b/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml index c5316ea..d4db00c 100644 --- a/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml +++ b/src/main/resources/de/hitec/nhplus/main/MainWindowView.fxml @@ -26,6 +26,13 @@ - + + + + + + + + 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