Compare commits
No commits in common. "ff9867f274f4b17b2e59c5498052bf66cdc1cc05" and "97373930ec8abed2996dab29497e695e0875ab22" have entirely different histories.
ff9867f274
...
97373930ec
14 changed files with 199 additions and 556 deletions
|
@ -30,7 +30,6 @@
|
|||
<option value="file://$PROJECT_DIR$/src/main/resources/de/hitec/nhplus/login/database/User.sql" />
|
||||
<option value="file://$PROJECT_DIR$/src/main/resources/de/hitec/nhplus/login/database/UserPermission.sql" />
|
||||
<option value="file://$PROJECT_DIR$/src/main/resources/de/hitec/nhplus/login/database/UserToNurse.sql" />
|
||||
<option value="file://$PROJECT_DIR$/src/main/resources/de/hitec/nhplus/medication/database/Medication_Alternative.sql" />
|
||||
</array>
|
||||
</option>
|
||||
<option name="outLayout" value="File per object.groovy" />
|
||||
|
|
Binary file not shown.
|
@ -12,12 +12,6 @@ import java.sql.Connection;
|
|||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import de.hitec.nhplus.Main;
|
||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||
import de.hitec.nhplus.medication.Ingredient;
|
||||
import de.hitec.nhplus.medication.Medication;
|
||||
import de.hitec.nhplus.medication.database.MedicationDao;
|
||||
|
||||
/**
|
||||
* {@link Fixture} for {@link Medication}.
|
||||
*
|
||||
|
@ -26,13 +20,11 @@ import de.hitec.nhplus.medication.database.MedicationDao;
|
|||
public class MedicationFixture implements Fixture<Medication> {
|
||||
private static final String SCHEMA = "/de/hitec/nhplus/medication/database/Medication.sql";
|
||||
private static final String INGREDIENT_SCHEMA = "/de/hitec/nhplus/medication/database/Medication_Ingredient.sql";
|
||||
private static final String ALTERNATIVE_SCHEMA = "/de/hitec/nhplus/medication/database/Medication_Alternative.sql";
|
||||
|
||||
@Override
|
||||
public void dropTable(Connection connection) throws SQLException {
|
||||
connection.createStatement().execute("DROP TABLE IF EXISTS medication");
|
||||
connection.createStatement().execute("DROP TABLE IF EXISTS medication_ingredient");
|
||||
connection.createStatement().execute("DROP TABLE IF EXISTS medication_alternative");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,25 +32,16 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
|
||||
final InputStream schema = Main.class.getResourceAsStream(SCHEMA);
|
||||
final InputStream ingredientSchema = Main.class.getResourceAsStream(INGREDIENT_SCHEMA);
|
||||
final InputStream alternativeSchema = Main.class.getResourceAsStream(ALTERNATIVE_SCHEMA);
|
||||
|
||||
assert schema != null;
|
||||
assert ingredientSchema != null;
|
||||
assert alternativeSchema != null;
|
||||
|
||||
String SQL = new Scanner(schema, StandardCharsets.UTF_8)
|
||||
.useDelimiter("\\A")
|
||||
.next();
|
||||
String ingredientSQL = ";" + new Scanner(ingredientSchema, StandardCharsets.UTF_8)
|
||||
.useDelimiter("\\A")
|
||||
.next();
|
||||
String alternativeSQL = ";" + new Scanner(alternativeSchema, StandardCharsets.UTF_8)
|
||||
.useDelimiter("\\A")
|
||||
.next();
|
||||
|
||||
connection.createStatement().execute(SQL);
|
||||
connection.createStatement().execute(ingredientSQL);
|
||||
connection.createStatement().execute(alternativeSQL);
|
||||
|
||||
}
|
||||
|
||||
|
@ -94,8 +77,7 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
),
|
||||
"Übelkeit, Durchfall, Laktatazidose (selten)",
|
||||
"Oral",
|
||||
100,
|
||||
new ArrayList<>()
|
||||
100
|
||||
));
|
||||
medications.add(new Medication(
|
||||
"Lisinopril",
|
||||
|
@ -108,8 +90,7 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
),
|
||||
"Schwindel, trockener Husten",
|
||||
"Oral",
|
||||
150,
|
||||
new ArrayList<>()
|
||||
150
|
||||
));
|
||||
medications.add(new Medication(
|
||||
"Simvastatin",
|
||||
|
@ -122,8 +103,7 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
),
|
||||
"Muskelschmerzen, Leberprobleme(selten)",
|
||||
"Oral",
|
||||
80,
|
||||
new ArrayList<>()
|
||||
80
|
||||
));
|
||||
medications.add(new Medication(
|
||||
"Enoxaparin",
|
||||
|
@ -135,8 +115,7 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
),
|
||||
"Blutungen, Reaktionen an der Injektionsstelle",
|
||||
"Unterhautinjektion",
|
||||
120,
|
||||
new ArrayList<>()
|
||||
120
|
||||
));
|
||||
Medication deprecatedMedication = new Medication(
|
||||
"Levothyroxin",
|
||||
|
@ -149,8 +128,7 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
),
|
||||
"Herzrasen, Gewichtsverlust",
|
||||
"Oral",
|
||||
90,
|
||||
new ArrayList<>()
|
||||
90
|
||||
);
|
||||
deprecatedMedication.setIsDeprecated(true);
|
||||
medications.add(deprecatedMedication);
|
||||
|
@ -165,27 +143,12 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
),
|
||||
"Blutungen, Blutergüsse",
|
||||
"Oral",
|
||||
110,
|
||||
new ArrayList<>()
|
||||
110
|
||||
));
|
||||
MedicationDao dao = DaoFactory.getInstance().createMedicationDAO();
|
||||
Map<String, Medication> medicationsByName = new HashMap<>();
|
||||
for (Medication medication : medications) {
|
||||
dao.create(medication);
|
||||
}
|
||||
List<Medication> createdMedications = dao.readAll();
|
||||
Map<String, Medication> medicationsByName = new HashMap<>();
|
||||
for (Medication medication : createdMedications){
|
||||
switch (medication.getName()){
|
||||
case "Warfarin":
|
||||
medication.setAlternativeMedication(List.of(
|
||||
createdMedications.get(0),
|
||||
createdMedications.get(3)
|
||||
));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
dao.update(medication);
|
||||
medicationsByName.put(medication.getName(), medication);
|
||||
}
|
||||
return medicationsByName;
|
||||
|
|
|
@ -53,8 +53,6 @@ public class AllMedicationController {
|
|||
@FXML
|
||||
private TableColumn<Medication, Integer> columnCurrentStock;
|
||||
@FXML
|
||||
public TableColumn<Medication, String> columnAlternativeMedication;
|
||||
@FXML
|
||||
public Button buttonChangeAvailable;
|
||||
@FXML
|
||||
public Button buttonAdd;
|
||||
|
@ -65,10 +63,6 @@ public class AllMedicationController {
|
|||
private MedicationDao dao;
|
||||
private boolean hasEditPermissions;
|
||||
|
||||
public MedicationDao getDao() {
|
||||
return dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization method that is called after the binding of all the fields.
|
||||
*/
|
||||
|
@ -93,29 +87,13 @@ public class AllMedicationController {
|
|||
return new SimpleStringProperty(
|
||||
ingredients
|
||||
.stream()
|
||||
.map(Ingredient::getName)
|
||||
.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.columnAlternativeMedication.setCellValueFactory(
|
||||
cellData -> {
|
||||
Medication medication = cellData.getValue();
|
||||
List<Medication> alternatives = medication.getAlternativeMedication();
|
||||
if (alternatives.isEmpty()) {
|
||||
return new SimpleStringProperty("");
|
||||
}
|
||||
|
||||
return new SimpleStringProperty(
|
||||
alternatives
|
||||
.stream()
|
||||
.map(med -> med.getName() + ", " + med.getManufacturer())
|
||||
.collect(Collectors.joining("\n"))
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
this.tableView.setItems(this.medications);
|
||||
|
||||
|
@ -239,4 +217,5 @@ public class AllMedicationController {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,8 +39,6 @@ public class DeprecatedMedicationController {
|
|||
@FXML
|
||||
private TableColumn<Medication, Integer> columnCurrentStock;
|
||||
@FXML
|
||||
public TableColumn<Medication, String> columnAlternativeMedication;
|
||||
@FXML
|
||||
public Button buttonChangeAvailable;
|
||||
|
||||
private final ObservableList<Medication> medications = FXCollections.observableArrayList();
|
||||
|
@ -73,22 +71,6 @@ public class DeprecatedMedicationController {
|
|||
this.columnPossibleSideEffects.setCellValueFactory(new PropertyValueFactory<>("possibleSideEffects"));
|
||||
this.columnAdministrationMethod.setCellValueFactory(new PropertyValueFactory<>("administrationMethod"));
|
||||
this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock"));
|
||||
this.columnAlternativeMedication.setCellValueFactory(
|
||||
cellData -> {
|
||||
Medication medication = cellData.getValue();
|
||||
List<Medication> alternatives = medication.getAlternativeMedication();
|
||||
if (alternatives.isEmpty()) {
|
||||
return new SimpleStringProperty("");
|
||||
}
|
||||
|
||||
return new SimpleStringProperty(
|
||||
alternatives
|
||||
.stream()
|
||||
.map(med -> med.getName() + ", " + med.getManufacturer())
|
||||
.collect(Collectors.joining("\n"))
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
this.tableView.setItems(this.medications);
|
||||
|
||||
|
|
|
@ -18,14 +18,13 @@ import java.util.stream.Collectors;
|
|||
*/
|
||||
public class Medication {
|
||||
private SimpleIntegerProperty id;
|
||||
private SimpleStringProperty name;
|
||||
private SimpleStringProperty manufacturer;
|
||||
private SimpleListProperty<Ingredient> ingredients;
|
||||
private SimpleStringProperty possibleSideEffects;
|
||||
private SimpleStringProperty administrationMethod;
|
||||
private SimpleIntegerProperty currentStock;
|
||||
private SimpleListProperty<Medication> alternativeMedication;
|
||||
private SimpleBooleanProperty isDeprecated;
|
||||
private final SimpleStringProperty name;
|
||||
private final SimpleStringProperty manufacturer;
|
||||
private final SimpleListProperty<Ingredient> ingredients;
|
||||
private final SimpleStringProperty possibleSideEffects;
|
||||
private final SimpleStringProperty administrationMethod;
|
||||
private final SimpleIntegerProperty currentStock;
|
||||
private final SimpleBooleanProperty isDeprecated;
|
||||
|
||||
/**
|
||||
* This constructor allows instantiating a {@link Medication} object,
|
||||
|
@ -40,8 +39,7 @@ public class Medication {
|
|||
List<Ingredient> ingredients,
|
||||
String possibleSideEffects,
|
||||
String administrationMethod,
|
||||
int currentStock,
|
||||
List<Medication> alternativeMedication
|
||||
int currentStock
|
||||
) {
|
||||
this.name = new SimpleStringProperty(name);
|
||||
this.manufacturer = new SimpleStringProperty(manufacturer);
|
||||
|
@ -49,7 +47,6 @@ public class Medication {
|
|||
this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects);
|
||||
this.administrationMethod = new SimpleStringProperty(administrationMethod);
|
||||
this.currentStock = new SimpleIntegerProperty(currentStock);
|
||||
this.alternativeMedication = new SimpleListProperty<>(FXCollections.observableArrayList(alternativeMedication));
|
||||
this.isDeprecated = new SimpleBooleanProperty(false);
|
||||
}
|
||||
|
||||
|
@ -64,7 +61,6 @@ public class Medication {
|
|||
String possibleSideEffects,
|
||||
String administrationMethod,
|
||||
int currentStock,
|
||||
List<Medication> alternativeMedication,
|
||||
boolean isDeprecated
|
||||
) {
|
||||
this.id = new SimpleIntegerProperty(id);
|
||||
|
@ -74,25 +70,9 @@ public class Medication {
|
|||
this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects);
|
||||
this.administrationMethod = new SimpleStringProperty(administrationMethod);
|
||||
this.currentStock = new SimpleIntegerProperty(currentStock);
|
||||
this.alternativeMedication = new SimpleListProperty<>(FXCollections.observableArrayList(alternativeMedication));
|
||||
this.isDeprecated = new SimpleBooleanProperty(isDeprecated);
|
||||
}
|
||||
|
||||
public void replace(Medication medication){
|
||||
if(medication == null){
|
||||
return;
|
||||
}
|
||||
this.id = medication.idProperty();
|
||||
this.name = medication.nameProperty();
|
||||
this.manufacturer = medication.manufacturerProperty();
|
||||
this.ingredients = medication.ingredientsProperty();
|
||||
this.possibleSideEffects = medication.possibleSideEffectsProperty();
|
||||
this.administrationMethod = medication.administrationMethodProperty();
|
||||
this.currentStock = medication.currentStockProperty();
|
||||
this.alternativeMedication = medication.alternativeMedicationProperty();
|
||||
this.isDeprecated = medication.isDeprecatedProperty();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id.get();
|
||||
}
|
||||
|
@ -161,18 +141,6 @@ public class Medication {
|
|||
this.possibleSideEffects.set(possibleSideEffects);
|
||||
}
|
||||
|
||||
public ObservableList<Medication> getAlternativeMedication() {
|
||||
return alternativeMedication.get();
|
||||
}
|
||||
|
||||
public SimpleListProperty<Medication> alternativeMedicationProperty() {
|
||||
return alternativeMedication;
|
||||
}
|
||||
|
||||
public void setAlternativeMedication(List<Medication> alternativeMedication) {
|
||||
this.alternativeMedication.set(FXCollections.observableArrayList(alternativeMedication));
|
||||
}
|
||||
|
||||
public String getAdministrationMethod() {
|
||||
return administrationMethod.get();
|
||||
}
|
||||
|
@ -211,14 +179,6 @@ public class Medication {
|
|||
.add("Possible Side Effects: " + this.getPossibleSideEffects())
|
||||
.add("Administration Method: " + this.getAdministrationMethod())
|
||||
.add("Current Stock: " + this.getCurrentStock())
|
||||
.add("Alternative Medication" + this.getAlternativeMedication())
|
||||
.toString();
|
||||
}
|
||||
|
||||
public String getComboBoxString() {
|
||||
return new StringJoiner(System.lineSeparator())
|
||||
.add("Name: " + this.getName())
|
||||
.add("Hersteller: " + this.getManufacturer())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,146 +0,0 @@
|
|||
package de.hitec.nhplus.medication;
|
||||
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.text.Text;
|
||||
import org.controlsfx.control.SearchableComboBox;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A custom implementation of the {@link ListCell} for {@link Ingredient}s.
|
||||
* This implementation contains an automatic resizing of the parent {@link ListView}.
|
||||
*
|
||||
* @author Dominik Säume
|
||||
*/
|
||||
public class MedicationListCell extends ListCell<Medication> {
|
||||
private final Button deleteButton;
|
||||
private final SearchableComboBox<Medication> comboBox;
|
||||
private static final double BUILTIN_BORDER_WIDTH = 1;
|
||||
private static final double CELL_SPACING = 4;
|
||||
private static final double CELL_PADDING = 4;
|
||||
private static final double BUTTON_PADDING_X = 8;
|
||||
private static final double BUTTON_PADDING_Y = 4;
|
||||
private final double totalSpacing;
|
||||
private boolean firstUpdate = true;
|
||||
|
||||
public MedicationListCell(List<Medication> allOtherMedications) {
|
||||
this.setPadding(new Insets(CELL_PADDING));
|
||||
|
||||
comboBox = new SearchableComboBox<>();
|
||||
ObservableList<Medication> list = FXCollections.observableArrayList();
|
||||
list.setAll(allOtherMedications);
|
||||
comboBox.setItems(list);
|
||||
comboBox.setPromptText("Alternatve Auswählen");
|
||||
comboBox.setCellFactory(this::comboBoxFactory);
|
||||
comboBox.setButtonCell(comboBoxButtonFactory());
|
||||
comboBox.valueProperty().addListener(this::onComboBoxChange);
|
||||
|
||||
deleteButton = new Button("-");
|
||||
deleteButton.setPadding(new Insets(
|
||||
BUTTON_PADDING_Y,
|
||||
BUTTON_PADDING_X,
|
||||
BUTTON_PADDING_Y,
|
||||
BUTTON_PADDING_X
|
||||
));
|
||||
deleteButton.setOnAction(this::handleDeleteButton);
|
||||
|
||||
// Calculate Delete Button Width
|
||||
Text textNode = new Text(deleteButton.getText());
|
||||
textNode.setFont(deleteButton.getFont());
|
||||
double calculatedDeleteButtonWidth = textNode.getLayoutBounds().getWidth() + BUTTON_PADDING_X * 2;
|
||||
|
||||
totalSpacing = BUILTIN_BORDER_WIDTH * 2 // List View
|
||||
+ CELL_PADDING * 2
|
||||
+ CELL_SPACING
|
||||
+ calculatedDeleteButtonWidth;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A Callback for use as a Listener for the {@link MedicationListCell#comboBox}.
|
||||
*/
|
||||
private void onComboBoxChange(
|
||||
ObservableValue<? extends Medication> observableValue,
|
||||
Medication oldValue,
|
||||
Medication newValue
|
||||
) {
|
||||
getItem().replace(comboBox.getValue());
|
||||
|
||||
ListView<Medication> listView = getListView();
|
||||
double max = listView.lookupAll("*")
|
||||
.stream()
|
||||
.filter(node -> node instanceof MedicationListCell)
|
||||
.mapToDouble(node -> comboBox.getWidth())
|
||||
.max()
|
||||
.orElse(0);
|
||||
|
||||
listView.setMinWidth(max + totalSpacing);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateItem(Medication item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (empty || item == null) {
|
||||
setGraphic(null);
|
||||
} else {
|
||||
if (
|
||||
firstUpdate
|
||||
&& comboBox.getSelectionModel().getSelectedItem() == null
|
||||
&& item.getName() != null
|
||||
&& comboBox.getItems().contains(item)
|
||||
) {
|
||||
comboBox.getSelectionModel().select(item);
|
||||
}
|
||||
firstUpdate = false;
|
||||
|
||||
BorderPane cellPane = new BorderPane();
|
||||
cellPane.setCenter(comboBox);
|
||||
cellPane.setRight(deleteButton);
|
||||
BorderPane.setMargin(deleteButton, new Insets(0, 0, 0, CELL_SPACING));
|
||||
setGraphic(cellPane);
|
||||
}
|
||||
}
|
||||
|
||||
private ListCell comboBoxFactory(Object param) {
|
||||
return new ListCell<Medication>() {
|
||||
|
||||
@Override
|
||||
protected void updateItem(Medication med, boolean empty) {
|
||||
super.updateItem(med, empty);
|
||||
setText(
|
||||
empty || med == null
|
||||
? null
|
||||
: med.getComboBoxString()
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private ListCell comboBoxButtonFactory() {
|
||||
return new ListCell<Medication>() {
|
||||
@Override
|
||||
protected void updateItem(Medication med, boolean empty) {
|
||||
super.updateItem(med, empty);
|
||||
setText(
|
||||
empty || med == null
|
||||
? comboBox.getPromptText()
|
||||
: med.getComboBoxString()
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void handleDeleteButton(ActionEvent event) {
|
||||
if (getItem() == null) {
|
||||
getListView().getItems().remove(getItem());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package de.hitec.nhplus.medication;
|
||||
|
||||
import de.hitec.nhplus.treatment.Treatment;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
@ -12,10 +13,7 @@ import javafx.stage.Stage;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static de.hitec.nhplus.utils.Validator.*;
|
||||
|
||||
|
@ -40,17 +38,13 @@ public class MedicationModalController {
|
|||
public TextArea textAreaPossibleSideEffects;
|
||||
@FXML
|
||||
public Button buttonSave;
|
||||
@FXML
|
||||
public ListView<Medication> listViewAlternativeMedication;
|
||||
|
||||
|
||||
private Stage stage;
|
||||
private Medication medication;
|
||||
private final ObservableList<Ingredient> ingredients = FXCollections.observableArrayList();
|
||||
private final ObservableList<Medication> alternativeMediaction = FXCollections.observableArrayList();
|
||||
private AllMedicationController controller;
|
||||
private boolean isNewMedication = false;
|
||||
private List<Medication> allOtherMedications;
|
||||
|
||||
/**
|
||||
* Initialization method that is called after the binding of all the fields.
|
||||
|
@ -74,20 +68,15 @@ public class MedicationModalController {
|
|||
new ArrayList<>(),
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
new ArrayList<>()
|
||||
0
|
||||
);
|
||||
this.buttonSave.setDisable(true);
|
||||
}
|
||||
|
||||
listViewIngredients.setCellFactory(cellData -> new IngredientListCell());
|
||||
listViewIngredients.setItems(ingredients);
|
||||
|
||||
showData();
|
||||
|
||||
listViewAlternativeMedication.setCellFactory(cellData -> new MedicationListCell(allOtherMedications));
|
||||
listViewAlternativeMedication.setItems(alternativeMediaction);
|
||||
|
||||
ChangeListener<String> inputMedicationValidationListener = (observableValue, oldText, newText) -> {
|
||||
boolean isValid = isValidMedicationName(textFieldName.getText())
|
||||
&& isValidMedicationManufacturer(textFieldManufacturer.getText())
|
||||
|
@ -108,22 +97,6 @@ public class MedicationModalController {
|
|||
*/
|
||||
private void showData() {
|
||||
ingredients.setAll(medication.getIngredients());
|
||||
alternativeMediaction.setAll(medication.getAlternativeMedication());
|
||||
Map<Integer, Medication> currentAlternatives = alternativeMediaction
|
||||
.stream()
|
||||
.collect(Collectors.toMap(Medication::getId, med -> med));
|
||||
try {
|
||||
allOtherMedications = controller.getDao().readAll();
|
||||
if (!isNewMedication) {
|
||||
allOtherMedications = allOtherMedications
|
||||
.stream()
|
||||
.filter(med -> med.getId() != medication.getId())
|
||||
.map(med -> currentAlternatives.getOrDefault(med.getId(), med))
|
||||
.toList();
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
textFieldName.setText(medication.getName());
|
||||
textFieldManufacturer.setText(medication.getManufacturer());
|
||||
textFieldAdministrationMethod.setText(medication.getAdministrationMethod());
|
||||
|
@ -147,15 +120,6 @@ public class MedicationModalController {
|
|||
.toList()
|
||||
);
|
||||
|
||||
this.medication.setAlternativeMedication(
|
||||
alternativeMediaction
|
||||
.stream()
|
||||
.distinct()
|
||||
.filter(Predicate.not(Objects::isNull))
|
||||
.filter(Predicate.not(med -> med.idProperty() == null))
|
||||
.toList()
|
||||
);
|
||||
|
||||
if (isNewMedication) {
|
||||
controller.createMedication(medication);
|
||||
} else {
|
||||
|
@ -175,16 +139,4 @@ public class MedicationModalController {
|
|||
public void handleAddIngredient() {
|
||||
ingredients.add(new Ingredient(""));
|
||||
}
|
||||
|
||||
public void handleAddAlternativeMedication() {
|
||||
alternativeMediaction.add(new Medication(
|
||||
null,
|
||||
null,
|
||||
new ArrayList<>(),
|
||||
null,
|
||||
null,
|
||||
-1,
|
||||
new ArrayList<>()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,10 @@ import java.sql.Connection;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The {@link MedicationDao} is an implementation of the{@link de.hitec.nhplus.datastorage.Dao Dao}
|
||||
|
@ -61,45 +64,36 @@ public class MedicationDao implements Dao<Medication> {
|
|||
ingredientStatement.setString(2, ingredient.getName());
|
||||
ingredientStatement.execute();
|
||||
}
|
||||
|
||||
final String alternativeMedicationSQL = """
|
||||
INSERT INTO medication_alternative
|
||||
(id, alternativeId)
|
||||
VALUES (?, ?);
|
||||
""";
|
||||
for (Medication alternative : medication.getAlternativeMedication()) {
|
||||
PreparedStatement alternativeStatement = this.connection.prepareStatement(alternativeMedicationSQL);
|
||||
alternativeStatement.setInt(1, newId);
|
||||
alternativeStatement.setInt(2, alternative.getId());
|
||||
alternativeStatement.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Medication read(int id) throws SQLException {
|
||||
ResultSet result = getReadStatement(id).executeQuery();
|
||||
final String SQL = """
|
||||
SELECT medication.*, medication_ingredient.id
|
||||
FROM medication
|
||||
LEFT JOIN medication_ingredient ON medication.id = medication_ingredient.id
|
||||
WHERE medication.id = ?
|
||||
""";
|
||||
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
||||
statement.setInt(1, id);
|
||||
ResultSet result = statement.executeQuery();
|
||||
return getInstanceFromResultSet(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Medication> readAll() throws SQLException {
|
||||
final String SQL = """
|
||||
SELECT medication.*, medication_ingredient.name, medication_alternative.alternativeId
|
||||
FROM medication
|
||||
LEFT JOIN
|
||||
SELECT medication.*, medication_ingredient.name
|
||||
FROM medication LEFT JOIN
|
||||
medication_ingredient ON medication.id = medication_ingredient.id
|
||||
LEFT JOIN
|
||||
medication_alternative ON medication.id = medication_alternative.id
|
||||
""";
|
||||
ResultSet result = connection.prepareStatement(SQL).executeQuery();
|
||||
|
||||
Map<Integer, Medication> medications = new HashMap<>();
|
||||
List<Medication> medications = new ArrayList<>();
|
||||
Map<Integer, List<Ingredient>> ingredientMap = new HashMap<>();
|
||||
Map<Integer, Set<Integer>> alternativesMap = new HashMap<>();
|
||||
|
||||
int currentMedicationId;
|
||||
int lastMedicationId = -1;
|
||||
String latIngredient = "";
|
||||
while (result.next()) {
|
||||
currentMedicationId = result.getInt(1);
|
||||
if (currentMedicationId != lastMedicationId) {
|
||||
|
@ -111,56 +105,125 @@ public class MedicationDao implements Dao<Medication> {
|
|||
result.getString(4),
|
||||
result.getString(5),
|
||||
result.getInt(6),
|
||||
new ArrayList<>(),
|
||||
result.getBoolean(7)
|
||||
);
|
||||
medications.put(currentMedicationId, medication);
|
||||
medications.add(medication);
|
||||
}
|
||||
|
||||
List<Ingredient> ingredients = ingredientMap.computeIfAbsent(currentMedicationId, k -> new ArrayList<>());
|
||||
String ingredientName = result.getString(8);
|
||||
if (ingredientName != null && !latIngredient.equals(ingredientName)) {
|
||||
if(ingredientName == null){
|
||||
continue;
|
||||
}
|
||||
ingredients.add(new Ingredient(ingredientName));
|
||||
latIngredient = ingredientName;
|
||||
}
|
||||
|
||||
Set<Integer> alternatives = alternativesMap.computeIfAbsent(currentMedicationId, k -> new HashSet<>());
|
||||
int alternativeId = result.getInt(9);
|
||||
if (alternativeId != 0) {
|
||||
alternatives.add(alternativeId);
|
||||
}
|
||||
|
||||
lastMedicationId = currentMedicationId;
|
||||
}
|
||||
for (Medication medication : medications.values()) {
|
||||
for (Medication medication : medications) {
|
||||
List<Ingredient> ingredients = ingredientMap.get(medication.getId());
|
||||
if (ingredients.isEmpty()) {
|
||||
if(ingredients.isEmpty()){
|
||||
continue;
|
||||
}
|
||||
medication.setIngredients(ingredientMap.get(medication.getId()));
|
||||
Set<Integer> alternativeIds = alternativesMap.get(medication.getId());
|
||||
List<Medication> alternatives = new ArrayList<>();
|
||||
for (Integer alternativeId : alternativeIds) {
|
||||
alternatives.add(medications.get(alternativeId));
|
||||
}
|
||||
medication.setAlternativeMedication(alternatives);
|
||||
}
|
||||
|
||||
return medications.values().stream().toList();
|
||||
}
|
||||
|
||||
public List<Medication> readAllAvailable() throws SQLException {
|
||||
return readAll()
|
||||
.stream()
|
||||
.filter(med -> !med.isDeprecated())
|
||||
.toList();
|
||||
return medications;
|
||||
}
|
||||
|
||||
public List<Medication> readAllDeprecated() throws SQLException {
|
||||
return readAll()
|
||||
.stream()
|
||||
.filter(Medication::isDeprecated)
|
||||
.toList();
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -203,25 +266,6 @@ public class MedicationDao implements Dao<Medication> {
|
|||
statement.setString(2, ingredient.getName());
|
||||
statement.execute();
|
||||
}
|
||||
|
||||
final String alternativeDeleteSQL = """
|
||||
DELETE FROM medication_alternative WHERE id = ?
|
||||
""";
|
||||
PreparedStatement alternativeStatement = this.connection.prepareStatement(alternativeDeleteSQL);
|
||||
alternativeStatement.setInt(1, medication.getId());
|
||||
alternativeStatement.executeUpdate();
|
||||
|
||||
final String alternativeCreateSQL = """
|
||||
INSERT INTO medication_alternative
|
||||
(id, alternativeId)
|
||||
VALUES (?, ?);
|
||||
""";
|
||||
for (Medication alternative : medication.getAlternativeMedication()) {
|
||||
PreparedStatement statement = this.connection.prepareStatement(alternativeCreateSQL);
|
||||
statement.setInt(1, medication.getId());
|
||||
statement.setInt(2, alternative.getId());
|
||||
statement.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -234,23 +278,6 @@ public class MedicationDao implements Dao<Medication> {
|
|||
preparedStatement.executeUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id The ID of the database entry to read.
|
||||
* @return A {@link PreparedStatement} to read a specific entry by its ID.
|
||||
*/
|
||||
public PreparedStatement getReadStatement(int id) throws SQLException {
|
||||
final String SQL = """
|
||||
SELECT medication.*, medication_ingredient.name, medication_alternative.alternativeId
|
||||
FROM medication
|
||||
LEFT JOIN medication_ingredient ON medication.id = medication_ingredient.id
|
||||
LEFT JOIN medication_alternative ON medication.id = medication_alternative.id
|
||||
WHERE medication.id = ?
|
||||
""";
|
||||
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
||||
statement.setInt(1, id);
|
||||
return statement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@link Medication} object from the {@link ResultSet} obtained after executing a database query.
|
||||
* This method is used internally to map the {@link ResultSet} data to a {@link Medication} object.
|
||||
|
@ -263,41 +290,19 @@ public class MedicationDao implements Dao<Medication> {
|
|||
result.getInt(1),
|
||||
result.getString(2),
|
||||
result.getString(3),
|
||||
new ArrayList<>(),
|
||||
List.of(),
|
||||
result.getString(4),
|
||||
result.getString(5),
|
||||
result.getInt(6),
|
||||
new ArrayList<>(),
|
||||
result.getBoolean(7)
|
||||
);
|
||||
|
||||
List<Ingredient> ingredients = new ArrayList<>();
|
||||
List<Medication> alternatives = new ArrayList<>();
|
||||
while (result.next()) {
|
||||
String ingredientName = result.getString(8);
|
||||
if (ingredientName != null) {
|
||||
ingredients.add(new Ingredient(ingredientName));
|
||||
}
|
||||
int alternativeId = result.getInt(9);
|
||||
if (alternativeId != 0) {
|
||||
ResultSet alternativeResult = getReadStatement(alternativeId).executeQuery();
|
||||
Medication alternativeMedication = new Medication(
|
||||
alternativeResult.getInt(1),
|
||||
alternativeResult.getString(2),
|
||||
alternativeResult.getString(3),
|
||||
new ArrayList<>(),
|
||||
alternativeResult.getString(4),
|
||||
alternativeResult.getString(5),
|
||||
alternativeResult.getInt(6),
|
||||
new ArrayList<>(),
|
||||
alternativeResult.getBoolean(7)
|
||||
);
|
||||
alternatives.add(alternativeMedication);
|
||||
}
|
||||
}
|
||||
medication.setIngredients(ingredients);
|
||||
medication.setAlternativeMedication(alternatives);
|
||||
return medication;
|
||||
ingredients.add(new Ingredient(result.getString(2)));
|
||||
|
||||
}
|
||||
medication.setIngredients(ingredients);
|
||||
return medication;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ module de.hitec.nhplus {
|
|||
requires javafx.fxml;
|
||||
requires java.sql;
|
||||
requires org.xerial.sqlitejdbc;
|
||||
requires org.controlsfx.controls;
|
||||
|
||||
exports de.hitec.nhplus;
|
||||
opens de.hitec.nhplus to javafx.fxml;
|
||||
|
|
|
@ -49,11 +49,6 @@
|
|||
minWidth="100.0"
|
||||
text="Lagerbestand"
|
||||
/>
|
||||
<TableColumn
|
||||
fx:id="columnAlternativeMedication"
|
||||
minWidth="100.0"
|
||||
text="Alternative Medikamente"
|
||||
/>
|
||||
</columns>
|
||||
<columnResizePolicy>
|
||||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
|
||||
|
|
|
@ -49,11 +49,6 @@
|
|||
minWidth="100.0"
|
||||
text="Lagerbestand"
|
||||
/>
|
||||
<TableColumn
|
||||
fx:id="columnAlternativeMedication"
|
||||
minWidth="100.0"
|
||||
text="Alternative Medikamente"
|
||||
/>
|
||||
</columns>
|
||||
<columnResizePolicy>
|
||||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import org.controlsfx.control.SearchableComboBox?>
|
||||
<BorderPane
|
||||
xmlns="http://javafx.com/javafx/17.0.2-ea"
|
||||
xmlns:fx="http://javafx.com/fxml/1"
|
||||
|
@ -78,13 +77,16 @@
|
|||
</padding>
|
||||
<left>
|
||||
<BorderPane>
|
||||
<BorderPane.margin>
|
||||
<Insets right="8"/>
|
||||
</BorderPane.margin>
|
||||
<top>
|
||||
<Label text="Inhaltsstoffe:"/>
|
||||
</top>
|
||||
<center>
|
||||
<ListView fx:id="listViewIngredients" minWidth="200">
|
||||
<BorderPane.margin>
|
||||
<Insets top="4"/>
|
||||
<Insets top="8"/>
|
||||
</BorderPane.margin>
|
||||
</ListView>
|
||||
</center>
|
||||
|
@ -103,45 +105,10 @@
|
|||
</bottom>
|
||||
</BorderPane>
|
||||
</left>
|
||||
<right>
|
||||
<BorderPane>
|
||||
<top>
|
||||
<Label text="Alternative Medikamente:"/>
|
||||
</top>
|
||||
<center>
|
||||
<ListView fx:id="listViewAlternativeMedication" minWidth="200">
|
||||
<BorderPane.margin>
|
||||
<Insets top="4"/>
|
||||
</BorderPane.margin>
|
||||
</ListView>
|
||||
</center>
|
||||
<bottom>
|
||||
<AnchorPane>
|
||||
<BorderPane.margin>
|
||||
<Insets top="8"/>
|
||||
</BorderPane.margin>
|
||||
<Button
|
||||
onAction="#handleAddAlternativeMedication"
|
||||
text="+"
|
||||
AnchorPane.leftAnchor="0"
|
||||
AnchorPane.rightAnchor="0"
|
||||
/>
|
||||
</AnchorPane>
|
||||
</bottom>
|
||||
</BorderPane>
|
||||
</right>
|
||||
<center>
|
||||
<BorderPane>
|
||||
<BorderPane.margin>
|
||||
<Insets left="8" right="8"/>
|
||||
</BorderPane.margin>
|
||||
<top>
|
||||
<Label text="Nebenwirkungen">
|
||||
<BorderPane.margin>
|
||||
<Insets bottom="4"/>
|
||||
</BorderPane.margin>
|
||||
|
||||
</Label>
|
||||
<Label text="Nebenwirkungen"/>
|
||||
</top>
|
||||
<center>
|
||||
<TextArea fx:id="textAreaPossibleSideEffects"/>
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
CREATE TABLE medication_alternative
|
||||
(
|
||||
id INTEGER NOT NULL ,
|
||||
alternativeId INTEGER NOT NULL ,
|
||||
FOREIGN KEY (id) REFERENCES medication (id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (alternativeId) REFERENCES medication (id) ON DELETE CASCADE
|
||||
)
|
Loading…
Reference in a new issue