Compare commits

...

5 commits

Author SHA1 Message Date
Dorian Nemec
cc5af63b0e
#24: Javado & Cleanup
All checks were successful
Quality Check / Linting Check (push) Successful in 17s
Quality Check / Linting Check (pull_request) Successful in 21s
Quality Check / Javadoc Check (push) Successful in 38s
Quality Check / Javadoc Check (pull_request) Successful in 36s
2024-05-22 17:39:35 +02:00
Dorian Nemec
812bc30bf2
#24: Implement Deprecated and Available medications 2024-05-22 17:39:35 +02:00
arminribic
2cb83aa604
#24: Logik implementiert und UI fertig gestellt 2024-05-22 17:39:35 +02:00
Dorian Nemec
09637e6028
#24: Implemented isDeprecated in Dao 2024-05-22 17:39:11 +02:00
Dorian Nemec
3a330f0b69
#24: UI Veraltete Medikamenten addiert 2024-05-22 17:39:05 +02:00
15 changed files with 407 additions and 26 deletions

Binary file not shown.

View file

@ -117,7 +117,7 @@ public class MedicationFixture implements Fixture<Medication> {
"Unterhautinjektion",
120
));
medications.add(new Medication(
Medication deprecatedMedication = new Medication(
"Levothyroxin",
"Sandoz",
List.of(
@ -129,7 +129,9 @@ public class MedicationFixture implements Fixture<Medication> {
"Herzrasen, Gewichtsverlust",
"Oral",
90
));
);
deprecatedMedication.setIsDeprecated(true);
medications.add(deprecatedMedication);
medications.add(new Medication(
"Warfarin",
"Apotex Inc.",

View file

@ -2,6 +2,9 @@ package de.hitec.nhplus.main;
import de.hitec.nhplus.Main;
import de.hitec.nhplus.nurse.Nurse;
import de.hitec.nhplus.patient.Patient;
import de.hitec.nhplus.treatment.Treatment;
import de.hitec.nhplus.medication.Medication;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.SelectionModel;
@ -48,6 +51,15 @@ public class MainWindowController {
private AnchorPane medicationPage;
@FXML
private Tab medicationTab;
@FXML
private Tab availableMedicationTab;
@FXML
private TabPane medicationTabPane;
@FXML
private AnchorPane deprecatedMedicationPage;
@FXML
private Tab deprecatedMedicationTab;
/**
* Initialization method that is called after the binding of all the fields.
@ -62,15 +74,17 @@ public class MainWindowController {
nurseTab.setOnSelectionChanged(event -> loadNursePage());
medicationTab.setOnSelectionChanged(event -> loadMedicationPage());
nurseTabPane.getSelectionModel().select(activeNurseTab);
activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage());
lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage());
availableMedicationTab.setOnSelectionChanged(event -> loadAvailableMedicationPage());
deprecatedMedicationTab.setOnSelectionChanged(event -> loadDeprecatedMedicationPage());
nurseTabPane.getSelectionModel().select(activeNurseTab);
medicationTabPane.getSelectionModel().select(medicationTab);
}
/**
* Loads the patient page into its tab.
* Loads the {@link Patient} page into its tab.
*/
private void loadPatientPage() {
try {
@ -88,7 +102,7 @@ public class MainWindowController {
}
/**
* Loads the {@link } page into its tab.
* Loads the {@link Treatment} page into its tab.
*/
private void loadTreatmentsPage() {
try {
@ -106,7 +120,7 @@ public class MainWindowController {
}
/**
* Loads the nurse page into its tab.
* Loads the {@link Nurse} page into its tab.
*/
private void loadNursePage() {
SelectionModel<Tab> selectionModel = nurseTabPane.getSelectionModel();
@ -156,9 +170,24 @@ public class MainWindowController {
}
/**
* Loads the medication page into its tab.
* Loads the {@link Medication} page into its tab.
*/
private void loadMedicationPage() {
private void loadMedicationPage()
{
SelectionModel<Tab> selectionModel = medicationTabPane.getSelectionModel();
Tab selectedTab = selectionModel.getSelectedItem();
if(selectedTab == availableMedicationTab){
loadAvailableMedicationPage();
}
if(selectedTab == deprecatedMedicationTab){
loadDeprecatedMedicationPage();
}
}
/**
* Loads the {@link Medication} page into its tab.
*/
private void loadAvailableMedicationPage() {
try {
BorderPane medicationPane = FXMLLoader.load(
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/medication/AllMedicationView.fxml"))
@ -172,4 +201,23 @@ public class MainWindowController {
exception.printStackTrace();
}
}
/**
* Loads the deprecated {@link Medication} page into its tab.
*/
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

@ -18,6 +18,7 @@ import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.SelectionModel;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
@ -48,6 +49,8 @@ public class AllMedicationController {
private TableColumn<Medication, String> columnAdministrationMethod;
@FXML
private TableColumn<Medication, Integer> columnCurrentStock;
@FXML
public Button buttonChangeAvailable;
private final ObservableList<Medication> medications = FXCollections.observableArrayList();
private MedicationDao dao;
@ -57,7 +60,7 @@ public class AllMedicationController {
*/
@FXML
public void initialize() {
readAllAndShowInTableView();
this.readAllAndShowInTableView();
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
@ -82,6 +85,7 @@ public class AllMedicationController {
this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock"));
this.tableView.setItems(this.medications);
}
/**
@ -90,7 +94,7 @@ public class AllMedicationController {
public void readAllAndShowInTableView() {
this.dao = DaoFactory.getInstance().createMedicationDAO();
try {
this.medications.setAll(dao.readAll());
this.medications.setAll(dao.readAllAvailable());
} catch (SQLException exception) {
exception.printStackTrace();
}
@ -120,6 +124,22 @@ public class AllMedicationController {
}
}
@FXML
public void handleChangeAvailable() {
Medication selectedItem = this.tableView.getSelectionModel().getSelectedItem();
if (selectedItem == null) {
return;
}
try {
selectedItem.setIsDeprecated(true);
this.dao.update(selectedItem);
} catch (SQLException exception) {
exception.printStackTrace();
}
this.readAllAndShowInTableView();
}
/**
* Internal method to create a {@link MedicationModalController MedicationModal}.
*

View file

@ -0,0 +1,101 @@
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.Button;
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;
@FXML
public Button buttonChangeAvailable;
private final ObservableList<Medication> medications = FXCollections.observableArrayList();
private MedicationDao dao;
/**
* Initialization method that is called after the binding of all the fields.
*/
public void initialize() {
this.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.medications.clear();
this.dao = DaoFactory.getInstance().createMedicationDAO();
try {
this.medications.setAll(this.dao.readAllDeprecated());
} catch (SQLException exception) {
exception.printStackTrace();
}
}
@FXML
public void handleChangeAvailable(){
Medication selectedItem = tableView.getSelectionModel().getSelectedItem();
if (selectedItem == null) {
return;
}
try {
selectedItem.setIsDeprecated(false);
this.dao.update(selectedItem);
} catch (SQLException exception) {
exception.printStackTrace();
}
this.readAllAndShowInTableView();
}
}

View file

@ -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<Ingredient> ingredients,
String possibleSideEffects,
String administrationMethod,
int currentStock
int currentStock,
boolean isDeprecated
) {
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(isDeprecated);
}
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);
}

View file

@ -39,6 +39,7 @@ public class MedicationModalController {
@FXML
public Button buttonSave;
private Stage stage;
private Medication medication;
private final ObservableList<Ingredient> ingredients = FXCollections.observableArrayList();

View file

@ -32,8 +32,8 @@ public class MedicationDao implements Dao<Medication> {
connection.setAutoCommit(false); //Switch to Manual Commit, to do an SQL Transaction
final String medicationSQL = """
INSERT INTO medication
(name, manufacturer, possibleSideEffects, administrationMethod, currentStock)
VALUES (?, ?, ?, ?, ?);
(name, manufacturer, possibleSideEffects, administrationMethod, currentStock, isDeprecated)
VALUES (?, ?, ?, ?, ?, ?);
""";
PreparedStatement medicationStatement = this.connection.prepareStatement(medicationSQL);
medicationStatement.setString(1, medication.getName());
@ -41,6 +41,7 @@ public class MedicationDao implements Dao<Medication> {
medicationStatement.setString(3, medication.getPossibleSideEffects());
medicationStatement.setString(4, medication.getAdministrationMethod());
medicationStatement.setInt(5, medication.getCurrentStock());
medicationStatement.setBoolean(6, medication.isDeprecated());
medicationStatement.execute();
ResultSet generatedKeys = connection.createStatement().executeQuery("SELECT last_insert_rowid()");
@ -103,12 +104,111 @@ public class MedicationDao implements Dao<Medication> {
new ArrayList<>(),
result.getString(4),
result.getString(5),
result.getInt(6)
result.getInt(6),
result.getBoolean(7)
);
medications.add(medication);
}
List<Ingredient> ingredients = ingredientMap.computeIfAbsent(currentMedicationId, k -> new ArrayList<>());
String ingredientName = result.getString(7);
String ingredientName = result.getString(8);
if(ingredientName == null){
continue;
}
ingredients.add(new Ingredient(ingredientName));
lastMedicationId = currentMedicationId;
}
for (Medication medication : medications) {
List<Ingredient> ingredients = ingredientMap.get(medication.getId());
if(ingredients.isEmpty()){
continue;
}
medication.setIngredients(ingredientMap.get(medication.getId()));
}
return medications;
}
public List<Medication> readAllDeprecated() throws SQLException {
final String SQL = """
SELECT medication.*, medication_ingredient.name
FROM medication LEFT JOIN
medication_ingredient
ON medication.id = medication_ingredient.id
WHERE medication.isDeprecated = true
""";
ResultSet result = connection.prepareStatement(SQL).executeQuery();
List<Medication> medications = new ArrayList<>();
Map<Integer, List<Ingredient>> 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),
new ArrayList<>(),
result.getString(4),
result.getString(5),
result.getInt(6),
result.getBoolean(7)
);
medications.add(medication);
}
List<Ingredient> ingredients = ingredientMap.computeIfAbsent(currentMedicationId, k -> new ArrayList<>());
String ingredientName = result.getString(8);
if(ingredientName == null){
continue;
}
ingredients.add(new Ingredient(ingredientName));
lastMedicationId = currentMedicationId;
}
for (Medication medication : medications) {
List<Ingredient> ingredients = ingredientMap.get(medication.getId());
if(ingredients.isEmpty()){
continue;
}
medication.setIngredients(ingredientMap.get(medication.getId()));
}
return medications;
}
public List<Medication> readAllAvailable() throws SQLException {
final String SQL = """
SELECT medication.*, medication_ingredient.name
FROM medication LEFT JOIN
medication_ingredient
ON medication.id = medication_ingredient.id
WHERE medication.isDeprecated = false
""";
ResultSet result = connection.prepareStatement(SQL).executeQuery();
List<Medication> medications = new ArrayList<>();
Map<Integer, List<Ingredient>> 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),
new ArrayList<>(),
result.getString(4),
result.getString(5),
result.getInt(6),
result.getBoolean(7)
);
medications.add(medication);
}
List<Ingredient> ingredients = ingredientMap.computeIfAbsent(currentMedicationId, k -> new ArrayList<>());
String ingredientName = result.getString(8);
if(ingredientName == null){
continue;
}
@ -134,7 +234,8 @@ public class MedicationDao implements Dao<Medication> {
manufacturer = ?,
possibleSideEffects = ?,
administrationMethod = ?,
currentStock = ?
currentStock = ?,
isDeprecated = ?
WHERE id = ?
""";
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
@ -143,7 +244,8 @@ public class MedicationDao implements Dao<Medication> {
preparedStatement.setString(3, medication.getPossibleSideEffects());
preparedStatement.setString(4, medication.getAdministrationMethod());
preparedStatement.setInt(5, medication.getCurrentStock());
preparedStatement.setInt(6, medication.getId());
preparedStatement.setBoolean(6, medication.isDeprecated());
preparedStatement.setInt(7, medication.getId());
preparedStatement.executeUpdate();
final String ingredientDeleteSQL = """
@ -191,7 +293,8 @@ public class MedicationDao implements Dao<Medication> {
List.of(),
result.getString(4),
result.getString(5),
result.getInt(6)
result.getInt(6),
result.getBoolean(7)
);
List<Ingredient> ingredients = new ArrayList<>();

View file

@ -112,6 +112,4 @@ public class NurseDao extends DaoImp<Nurse> {
statement.setInt(1, id);
return statement;
}
}

View file

@ -75,7 +75,7 @@ public class AllTreatmentController {
*/
@FXML
public void initialize() {
readAllAndShowInTableView();
comboBoxPatientSelection.setItems(patientSelection);
comboBoxPatientSelection.getSelectionModel().select("alle");
@ -109,6 +109,7 @@ public class AllTreatmentController {
);
this.createComboBoxData();
readAllAndShowInTableView();
}
/**

View file

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

View file

@ -75,6 +75,13 @@
prefWidth="90.0"
text="Löschen"
/>
<Button
fx:id="buttonChangeAvailable"
mnemonicParsing="false"
onAction="#handleChangeAvailable"
prefWidth="155.0"
text="Veraltet-Status ändern"
/>
</HBox>
</right>
</BorderPane>

View file

@ -0,0 +1,76 @@
<?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="buttonChangeAvailable"
mnemonicParsing="false"
prefWidth="155.0"
onAction="#handleChangeAvailable"
text="Veraltet-Status ändern"
/>
</HBox>
</right>
</BorderPane>
</bottom>
</BorderPane>

View file

@ -5,5 +5,6 @@ CREATE TABLE medication
manufacturer TEXT NOT NULL,
possibleSideEffects TEXT NOT NULL,
administrationMethod TEXT NOT NULL,
currentStock INTEGER NOT NULL
currentStock INTEGER NOT NULL,
isDeprecated BOOLEAN NOT NULL DEFAULT false
)

View file

@ -74,7 +74,6 @@
onAction="#handleDelete"
prefWidth="90.0"
text="Löschen"
/>
</HBox>
</right>