#24: UI Veraltete Medikamenten addiert

This commit is contained in:
Dorian Nemec 2024-05-20 07:50:54 +02:00 committed by Dominik Säume
parent 700aba10b7
commit 3a330f0b69
Signed by: SZUT-Dominik
GPG key ID: 67D15BB250B41E7C
6 changed files with 213 additions and 7 deletions

View file

@ -48,6 +48,13 @@ public class MainWindowController {
private AnchorPane medicationPage; private AnchorPane medicationPage;
@FXML @FXML
private Tab medicationTab; private Tab medicationTab;
@FXML
private TabPane medicationTabPane;
@FXML
private AnchorPane deprecatedMedicationPage;
@FXML
private Tab deprecatedMedicationTab;
/** /**
* Initialization method that is called after the binding of all the fields. * Initialization method that is called after the binding of all the fields.
@ -62,11 +69,13 @@ public class MainWindowController {
nurseTab.setOnSelectionChanged(event -> loadNursePage()); nurseTab.setOnSelectionChanged(event -> loadNursePage());
medicationTab.setOnSelectionChanged(event -> loadMedicationPage()); medicationTab.setOnSelectionChanged(event -> loadMedicationPage());
nurseTabPane.getSelectionModel().select(activeNurseTab);
activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage()); activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage());
lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage()); lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage());
medicationTab.setOnSelectionChanged(event -> loadMedicationPage());
deprecatedMedicationTab.setOnSelectionChanged(event -> loadDeprecatedMedicationPage());
nurseTabPane.getSelectionModel().select(activeNurseTab);
medicationTabPane.getSelectionModel().select(medicationTab);
} }
/** /**
@ -172,4 +181,19 @@ public class MainWindowController {
exception.printStackTrace(); 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();
}
}
} }

View file

@ -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<Medication> tableView;
@FXML
private TableColumn<Medication, Integer> columnId;
@FXML
private TableColumn<Medication, String> columnName;
@FXML
private TableColumn<Medication, String> columnManufacturer;
@FXML
private TableColumn<Medication, String> columnIngredient;
@FXML
private TableColumn<Medication, String> columnPossibleSideEffects;
@FXML
private TableColumn<Medication, String> columnAdministrationMethod;
@FXML
private TableColumn<Medication, Integer> columnCurrentStock;
private final ObservableList<Medication> 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<Ingredient> 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();
}
}
}

View file

@ -1,5 +1,6 @@
package de.hitec.nhplus.medication; package de.hitec.nhplus.medication;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleListProperty; import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
@ -23,6 +24,7 @@ public class Medication {
private final SimpleStringProperty possibleSideEffects; private final SimpleStringProperty possibleSideEffects;
private final SimpleStringProperty administrationMethod; private final SimpleStringProperty administrationMethod;
private final SimpleIntegerProperty currentStock; private final SimpleIntegerProperty currentStock;
private final SimpleBooleanProperty isDeprecated;
/** /**
* This constructor allows instantiating a {@link Medication} object, * This constructor allows instantiating a {@link Medication} object,
@ -45,6 +47,7 @@ public class Medication {
this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects); this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects);
this.administrationMethod = new SimpleStringProperty(administrationMethod); this.administrationMethod = new SimpleStringProperty(administrationMethod);
this.currentStock = new SimpleIntegerProperty(currentStock); this.currentStock = new SimpleIntegerProperty(currentStock);
this.isDeprecated = new SimpleBooleanProperty(false);
} }
/** /**
@ -57,7 +60,8 @@ public class Medication {
List<Ingredient> ingredients, List<Ingredient> ingredients,
String possibleSideEffects, String possibleSideEffects,
String administrationMethod, String administrationMethod,
int currentStock int currentStock,
boolean isDepreacted
) { ) {
this.id = new SimpleIntegerProperty(id); this.id = new SimpleIntegerProperty(id);
this.name = new SimpleStringProperty(name); this.name = new SimpleStringProperty(name);
@ -66,6 +70,7 @@ public class Medication {
this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects); this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects);
this.administrationMethod = new SimpleStringProperty(administrationMethod); this.administrationMethod = new SimpleStringProperty(administrationMethod);
this.currentStock = new SimpleIntegerProperty(currentStock); this.currentStock = new SimpleIntegerProperty(currentStock);
this.isDeprecated = new SimpleBooleanProperty(isDepreacted);
} }
public int getId() { public int getId() {
@ -84,6 +89,18 @@ public class Medication {
return name; 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) { public void setName(String name) {
this.name.set(name); this.name.set(name);
} }

View file

@ -103,7 +103,8 @@ public class MedicationDao implements Dao<Medication> {
new ArrayList<>(), new ArrayList<>(),
result.getString(4), result.getString(4),
result.getString(5), result.getString(5),
result.getInt(6) result.getInt(6),
result.getBoolean(7)
); );
medications.add(medication); medications.add(medication);
} }
@ -191,7 +192,8 @@ public class MedicationDao implements Dao<Medication> {
List.of(), List.of(),
result.getString(4), result.getString(4),
result.getString(5), result.getString(5),
result.getInt(6) result.getInt(6),
result.getBoolean(7)
); );
List<Ingredient> ingredients = new ArrayList<>(); List<Ingredient> ingredients = new ArrayList<>();

View file

@ -26,6 +26,13 @@
</TabPane> </TabPane>
</Tab> </Tab>
<Tab fx:id="medicationTab" text="Medikamente"> <Tab fx:id="medicationTab" text="Medikamente">
<AnchorPane fx:id="medicationPage"/> <TabPane fx:id="medicationTabPane" tabClosingPolicy="UNAVAILABLE">
<Tab fx:id="allMedicationTab" text="Medikamente">
<AnchorPane fx:id="medicationPage"/>
</Tab>
<Tab fx:id="deprecatedMedicationTab" text="Veraltete Medikamente">
<AnchorPane fx:id="deprecatedMedicationPage"/>
</Tab>
</TabPane>
</Tab> </Tab>
</TabPane> </TabPane>

View file

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<BorderPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="de.hitec.nhplus.medication.DeprecatedMedicationController"
>
<padding>
<Insets top="8" left="8" right="8" bottom="8"/>
</padding>
<center>
<TableView fx:id="tableView">
<columns>
<TableColumn
fx:id="columnId"
minWidth="40.0"
text="ID"
/>
<TableColumn
fx:id="columnName"
minWidth="140.0"
text="Name"
/>
<TableColumn
fx:id="columnManufacturer"
minWidth="140.0"
text="Hersteller"
/>
<TableColumn
fx:id="columnIngredient"
minWidth="140.0"
text="Inhaltsstoffe"
/>
<TableColumn
fx:id="columnPossibleSideEffects"
minWidth="200.0"
text="Mögliche Nebenwirkungen"
/>
<TableColumn
fx:id="columnAdministrationMethod"
minWidth="180.0"
text="Verabreichungsmethode"
/>
<TableColumn
fx:id="columnCurrentStock"
minWidth="100.0"
text="Lagerbestand"
/>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TableView>
</center>
<bottom>
<BorderPane>
<BorderPane.margin>
<Insets top="8.0"/>
</BorderPane.margin>
<right>
<HBox spacing="8.0">
<!--
<Button
fx:id="buttonDelete"
mnemonicParsing="false"
prefWidth="90.0"
text="Löschen"
/>
-->
</HBox>
</right>
</BorderPane>
</bottom>
</BorderPane>