Compare commits

..

No commits in common. "efea16e5b100e81d569f038c77bbeb4aafa05eaa" and "e9aa98d63ab5696fa148873dd947222c9e9f6493" have entirely different histories.

14 changed files with 22 additions and 395 deletions

Binary file not shown.

View file

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

View file

@ -80,16 +80,10 @@ public class MainWindowController {
Permissions.MANAGEMENT | Permissions.OWNER Permissions.MANAGEMENT | Permissions.OWNER
) )
)); ));
tabManager.setupSubTabPane(mainTabPane, "Medikamente", Permissions.MANAGEMENT, List.of( tabManager.setupTab(mainTabPane, new TabStruct(
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

@ -7,8 +7,6 @@ import java.util.stream.Collectors;
import de.hitec.nhplus.Main; import de.hitec.nhplus.Main;
import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.login.Permissions;
import de.hitec.nhplus.main.MainWindowController;
import de.hitec.nhplus.medication.database.MedicationDao; import de.hitec.nhplus.medication.database.MedicationDao;
import de.hitec.nhplus.nurse.Nurse; import de.hitec.nhplus.nurse.Nurse;
import de.hitec.nhplus.patient.Patient; import de.hitec.nhplus.patient.Patient;
@ -17,11 +15,9 @@ import de.hitec.nhplus.treatment.TreatmentModalController;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.SelectionModel; import javafx.scene.control.SelectionModel;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
@ -52,26 +48,16 @@ public class AllMedicationController {
private TableColumn<Medication, String> columnAdministrationMethod; private TableColumn<Medication, String> columnAdministrationMethod;
@FXML @FXML
private TableColumn<Medication, Integer> columnCurrentStock; private TableColumn<Medication, Integer> columnCurrentStock;
@FXML
public Button buttonChangeAvailable;
@FXML
public Button buttonAdd;
@FXML
public Button buttonDelete;
private final ObservableList<Medication> medications = FXCollections.observableArrayList(); private final ObservableList<Medication> medications = FXCollections.observableArrayList();
private MedicationDao dao; private MedicationDao dao;
private boolean hasEditPermissions;
/** /**
* Initialization method that is called after the binding of all the fields. * Initialization method that is called after the binding of all the fields.
*/ */
@FXML @FXML
public void initialize() { public void initialize() {
int editPermissions = Permissions.MANAGEMENT | Permissions.OWNER; readAllAndShowInTableView();
int userPermissions = MainWindowController.getInstance().getUser().getPermissions();
hasEditPermissions = (userPermissions & editPermissions) != 0;
this.readAllAndShowInTableView();
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id")); this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
this.columnName.setCellValueFactory(new PropertyValueFactory<>("name")); this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
@ -96,13 +82,6 @@ public class AllMedicationController {
this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock")); this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock"));
this.tableView.setItems(this.medications); this.tableView.setItems(this.medications);
if (!hasEditPermissions) {
this.buttonAdd.setDisable(true);
this.buttonDelete.setDisable(true);
this.buttonChangeAvailable.setDisable(true);
}
} }
/** /**
@ -111,7 +90,7 @@ public class AllMedicationController {
public void readAllAndShowInTableView() { public void readAllAndShowInTableView() {
this.dao = DaoFactory.getInstance().createMedicationDAO(); this.dao = DaoFactory.getInstance().createMedicationDAO();
try { try {
this.medications.setAll(dao.readAllAvailable()); this.medications.setAll(dao.readAll());
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
@ -141,38 +120,6 @@ 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();
}
@FXML
public void handleDelete() {
Medication selectedItem = this.tableView.getSelectionModel().getSelectedItem();
if (selectedItem == null) {
return;
}
try {
this.dao.delete(selectedItem.getId());
} catch (SQLException exception) {
exception.printStackTrace();
}
this.readAllAndShowInTableView();
}
/** /**
* Internal method to create a {@link MedicationModalController MedicationModal}. * Internal method to create a {@link MedicationModalController MedicationModal}.
* *
@ -217,5 +164,4 @@ public class AllMedicationController {
} }
}); });
} }
} }

View file

@ -1,108 +0,0 @@
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;
/**
* The controller for viewing all deprecated {@link Medication}s.
*
* @author Armin Ribic
* @author Dorian Nemec
*/
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,6 +1,5 @@
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;
@ -24,7 +23,6 @@ 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,
@ -47,7 +45,6 @@ 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);
} }
/** /**
@ -60,8 +57,7 @@ public class Medication {
List<Ingredient> ingredients, List<Ingredient> ingredients,
String possibleSideEffects, String possibleSideEffects,
String administrationMethod, String administrationMethod,
int currentStock, int currentStock
boolean isDeprecated
) { ) {
this.id = new SimpleIntegerProperty(id); this.id = new SimpleIntegerProperty(id);
this.name = new SimpleStringProperty(name); this.name = new SimpleStringProperty(name);
@ -70,7 +66,6 @@ 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(isDeprecated);
} }
public int getId() { public int getId() {
@ -89,18 +84,6 @@ 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

@ -39,7 +39,6 @@ public class MedicationModalController {
@FXML @FXML
public Button buttonSave; public Button buttonSave;
private Stage stage; private Stage stage;
private Medication medication; private Medication medication;
private final ObservableList<Ingredient> ingredients = FXCollections.observableArrayList(); 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 connection.setAutoCommit(false); //Switch to Manual Commit, to do an SQL Transaction
final String medicationSQL = """ final String medicationSQL = """
INSERT INTO medication INSERT INTO medication
(name, manufacturer, possibleSideEffects, administrationMethod, currentStock, isDeprecated) (name, manufacturer, possibleSideEffects, administrationMethod, currentStock)
VALUES (?, ?, ?, ?, ?, ?); VALUES (?, ?, ?, ?, ?);
"""; """;
PreparedStatement medicationStatement = this.connection.prepareStatement(medicationSQL); PreparedStatement medicationStatement = this.connection.prepareStatement(medicationSQL);
medicationStatement.setString(1, medication.getName()); medicationStatement.setString(1, medication.getName());
@ -41,7 +41,6 @@ public class MedicationDao implements Dao<Medication> {
medicationStatement.setString(3, medication.getPossibleSideEffects()); medicationStatement.setString(3, medication.getPossibleSideEffects());
medicationStatement.setString(4, medication.getAdministrationMethod()); medicationStatement.setString(4, medication.getAdministrationMethod());
medicationStatement.setInt(5, medication.getCurrentStock()); medicationStatement.setInt(5, medication.getCurrentStock());
medicationStatement.setBoolean(6, medication.isDeprecated());
medicationStatement.execute(); medicationStatement.execute();
ResultSet generatedKeys = connection.createStatement().executeQuery("SELECT last_insert_rowid()"); ResultSet generatedKeys = connection.createStatement().executeQuery("SELECT last_insert_rowid()");
@ -104,111 +103,12 @@ 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);
} }
List<Ingredient> ingredients = ingredientMap.computeIfAbsent(currentMedicationId, k -> new ArrayList<>()); List<Ingredient> ingredients = ingredientMap.computeIfAbsent(currentMedicationId, k -> new ArrayList<>());
String ingredientName = result.getString(8); String ingredientName = result.getString(7);
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){ if(ingredientName == null){
continue; continue;
} }
@ -234,8 +134,7 @@ public class MedicationDao implements Dao<Medication> {
manufacturer = ?, manufacturer = ?,
possibleSideEffects = ?, possibleSideEffects = ?,
administrationMethod = ?, administrationMethod = ?,
currentStock = ?, currentStock = ?
isDeprecated = ?
WHERE id = ? WHERE id = ?
"""; """;
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL); PreparedStatement preparedStatement = this.connection.prepareStatement(SQL);
@ -244,8 +143,7 @@ public class MedicationDao implements Dao<Medication> {
preparedStatement.setString(3, medication.getPossibleSideEffects()); preparedStatement.setString(3, medication.getPossibleSideEffects());
preparedStatement.setString(4, medication.getAdministrationMethod()); preparedStatement.setString(4, medication.getAdministrationMethod());
preparedStatement.setInt(5, medication.getCurrentStock()); preparedStatement.setInt(5, medication.getCurrentStock());
preparedStatement.setBoolean(6, medication.isDeprecated()); preparedStatement.setInt(6, medication.getId());
preparedStatement.setInt(7, medication.getId());
preparedStatement.executeUpdate(); preparedStatement.executeUpdate();
final String ingredientDeleteSQL = """ final String ingredientDeleteSQL = """
@ -293,8 +191,7 @@ 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

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

View file

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

View file

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

View file

@ -1,76 +0,0 @@
<?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,6 +5,5 @@ CREATE TABLE medication
manufacturer TEXT NOT NULL, manufacturer TEXT NOT NULL,
possibleSideEffects TEXT NOT NULL, possibleSideEffects TEXT NOT NULL,
administrationMethod TEXT NOT NULL, administrationMethod TEXT NOT NULL,
currentStock INTEGER NOT NULL, currentStock INTEGER NOT NULL
isDeprecated BOOLEAN NOT NULL DEFAULT false
) )

View file

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