#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 e9aa98d63a
commit 6300509873
Signed by: SZUT-Dominik
GPG key ID: 67D15BB250B41E7C
5 changed files with 188 additions and 7 deletions

View file

@ -80,10 +80,16 @@ public class MainWindowController {
Permissions.MANAGEMENT | Permissions.OWNER Permissions.MANAGEMENT | Permissions.OWNER
) )
)); ));
tabManager.setupTab(mainTabPane, new TabStruct( tabManager.setupSubTabPane(mainTabPane, "Medikamente", Permissions.MANAGEMENT, List.of(
new TabStruct(
"Medikamente", "Medikamente",
"/de/hitec/nhplus/medication/AllMedicationView.fxml", "/de/hitec/nhplus/medication/AllMedicationView.fxml",
Permissions.MANAGEMENT Permissions.MANAGEMENT
), new TabStruct(
"Veraltete Medikamente",
"/de/hitec/nhplus/medication/DeprecatedMedicationView.fxml",
Permissions.MANAGEMENT
)
)); ));

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

@ -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>