Compare commits
2 commits
942577a86a
...
930eba22e1
Author | SHA1 | Date | |
---|---|---|---|
930eba22e1 | |||
d89c0f49e4 |
8 changed files with 273 additions and 18 deletions
|
@ -67,7 +67,6 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
Ingredient warfarinnatrium = new Ingredient("Warfarinnatrium");
|
||||
|
||||
medications.add(new Medication(
|
||||
1,
|
||||
"Metformin",
|
||||
"AstraZeneca",
|
||||
List.of(
|
||||
|
@ -81,7 +80,6 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
100
|
||||
));
|
||||
medications.add(new Medication(
|
||||
2,
|
||||
"Lisinopril",
|
||||
"Teva Pharmaceuticals",
|
||||
List.of(
|
||||
|
@ -95,7 +93,6 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
150
|
||||
));
|
||||
medications.add(new Medication(
|
||||
3,
|
||||
"Simvastatin",
|
||||
"Mylan",
|
||||
List.of(
|
||||
|
@ -109,7 +106,6 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
80
|
||||
));
|
||||
medications.add(new Medication(
|
||||
4,
|
||||
"Enoxaparin",
|
||||
"Sanofi",
|
||||
List.of(
|
||||
|
@ -122,7 +118,6 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
120
|
||||
));
|
||||
medications.add(new Medication(
|
||||
5,
|
||||
"Levothyroxin",
|
||||
"Sandoz",
|
||||
List.of(
|
||||
|
@ -136,7 +131,6 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
90
|
||||
));
|
||||
medications.add(new Medication(
|
||||
6,
|
||||
"Warfarin",
|
||||
"Apotex Inc.",
|
||||
List.of(
|
||||
|
|
|
@ -95,7 +95,7 @@ public class AllMedicationController {
|
|||
Stage stage = new Stage();
|
||||
|
||||
MedicationModalController controller = loader.getController();
|
||||
controller.initialize();
|
||||
controller.initialize(null);
|
||||
|
||||
stage.setScene(scene);
|
||||
stage.setTitle("NHPlus - Neues Medikament");
|
||||
|
|
|
@ -17,7 +17,7 @@ public class Ingredient {
|
|||
}
|
||||
|
||||
public String getName() {
|
||||
return name.get();
|
||||
return name.getValue();
|
||||
}
|
||||
|
||||
public SimpleStringProperty nameProperty() {
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
package de.hitec.nhplus.medication;
|
||||
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.text.Text;
|
||||
|
||||
public class IngredientListCell extends ListCell<Ingredient> {
|
||||
private final TextField textField;
|
||||
private final Button deleteButton;
|
||||
|
||||
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;
|
||||
|
||||
public IngredientListCell() {
|
||||
this.setPadding(new Insets(CELL_PADDING));
|
||||
|
||||
textField = new TextField();
|
||||
textField.setPromptText("Inhaltsstoff");
|
||||
textField.textProperty().addListener(this::onTextFieldUpdate);
|
||||
|
||||
deleteButton = new Button("-");
|
||||
deleteButton.setPadding(new Insets(
|
||||
BUTTON_PADDING_Y,
|
||||
BUTTON_PADDING_X,
|
||||
BUTTON_PADDING_Y,
|
||||
BUTTON_PADDING_X
|
||||
));
|
||||
deleteButton.setOnAction(event -> getListView().getItems().remove(this));
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateItem(Ingredient item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (empty || item == null) {
|
||||
setGraphic(null);
|
||||
} else {
|
||||
String oldText = textField.getText();
|
||||
String newText = oldText != null && !oldText.isEmpty() ? oldText : item.getName();
|
||||
textField.setText(newText);
|
||||
|
||||
BorderPane cellPane = new BorderPane();
|
||||
cellPane.setCenter(textField);
|
||||
cellPane.setRight(deleteButton);
|
||||
BorderPane.setMargin(deleteButton, new Insets(0, 0, 0, CELL_SPACING));
|
||||
setGraphic(cellPane);
|
||||
}
|
||||
}
|
||||
|
||||
private void onTextFieldUpdate(ObservableValue<? extends String> observable, String oldValue, String newValue) {
|
||||
commitEdit(new Ingredient(textField.getText()));
|
||||
|
||||
textField.setMinWidth(getTextFieldRequiredWidth(textField));
|
||||
|
||||
ListView<Ingredient> listView = getListView();
|
||||
double max = listView.lookupAll("*")
|
||||
.stream()
|
||||
.filter(node -> node instanceof IngredientListCell)
|
||||
.mapToDouble(node -> getTextFieldRequiredWidth(((IngredientListCell) node).textField))
|
||||
.max()
|
||||
.orElse(0);
|
||||
|
||||
getListView().setMinWidth(max + totalSpacing);
|
||||
}
|
||||
|
||||
private double getTextFieldRequiredWidth(TextField textField) {
|
||||
Text textNode = new Text(textField.getText());
|
||||
textNode.setFont(textField.getFont());
|
||||
return textNode.getLayoutBounds().getWidth()
|
||||
+ textField.getPadding().getLeft()
|
||||
+ textField.getPadding().getRight()
|
||||
+ BUILTIN_BORDER_WIDTH * 2;
|
||||
}
|
||||
}
|
|
@ -1,8 +1,52 @@
|
|||
package de.hitec.nhplus.medication;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ListView;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MedicationModalController {
|
||||
|
||||
public void initialize(){
|
||||
|
||||
@FXML
|
||||
public ListView<Ingredient> listViewIngredients;
|
||||
|
||||
private Medication medication;
|
||||
private final ObservableList<Ingredient> ingredients = FXCollections.observableArrayList();
|
||||
private AllMedicationController controller;
|
||||
|
||||
@FXML
|
||||
public void initialize(Medication medication) {
|
||||
this.medication = medication != null ? medication : new Medication(
|
||||
"",
|
||||
"",
|
||||
new ArrayList<>(),
|
||||
"",
|
||||
"",
|
||||
0
|
||||
);
|
||||
|
||||
listViewIngredients.setCellFactory(cellData -> new IngredientListCell());
|
||||
listViewIngredients.setItems(ingredients);
|
||||
|
||||
showData();
|
||||
}
|
||||
|
||||
private void showData(){
|
||||
ingredients.setAll(medication.getIngredients());
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleSave() {
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleCancel() {
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleAddIngredient() {
|
||||
ingredients.add(new Ingredient(null));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ public class MedicationDao implements Dao<Medication> {
|
|||
|
||||
@Override
|
||||
public void create(Medication medication) throws SQLException {
|
||||
connection.setAutoCommit(false); //Switch to Manual Commit, to do an SQL Transaction
|
||||
final String medicationSQL = """
|
||||
INSERT INTO medication
|
||||
(name, manufacturer, possibleSideEffects, administrationMethod, currentStock)
|
||||
|
@ -42,6 +43,15 @@ public class MedicationDao implements Dao<Medication> {
|
|||
medicationStatement.setInt(5, medication.getCurrentStock());
|
||||
medicationStatement.execute();
|
||||
|
||||
ResultSet generatedKeys = connection.createStatement().executeQuery("SELECT last_insert_rowid()");
|
||||
connection.commit(); //Finish SQL Transaction
|
||||
connection.setAutoCommit(true); //Switch back Mode
|
||||
|
||||
if (!generatedKeys.next()) {
|
||||
return;
|
||||
}
|
||||
int newId = generatedKeys.getInt(1);
|
||||
|
||||
final String ingredientSQL = """
|
||||
INSERT INTO medication_ingredient
|
||||
(id, name)
|
||||
|
@ -49,7 +59,7 @@ public class MedicationDao implements Dao<Medication> {
|
|||
""";
|
||||
for (Ingredient ingredient : medication.getIngredients()) {
|
||||
PreparedStatement ingredientStatement = this.connection.prepareStatement(ingredientSQL);
|
||||
ingredientStatement.setInt(1, medication.getId());
|
||||
ingredientStatement.setInt(1, newId);
|
||||
ingredientStatement.setString(2, ingredient.getName());
|
||||
ingredientStatement.execute();
|
||||
}
|
||||
|
@ -104,6 +114,9 @@ public class MedicationDao implements Dao<Medication> {
|
|||
lastMedicationId = currentMedicationId;
|
||||
}
|
||||
for (Medication medication : medications) {
|
||||
if(!ingredientMap.containsKey(medication.getId())){
|
||||
continue;
|
||||
}
|
||||
medication.setIngredients(ingredientMap.get(medication.getId()));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<BorderPane
|
||||
xmlns="http://javafx.com/javafx/17.0.2-ea"
|
||||
xmlns:fx="http://javafx.com/fxml/1"
|
||||
|
@ -12,7 +11,120 @@
|
|||
<padding>
|
||||
<Insets top="8" left="8" bottom="8" right="8"/>
|
||||
</padding>
|
||||
<top>
|
||||
<GridPane hgap="8.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="NEVER"/>
|
||||
<ColumnConstraints hgrow="ALWAYS"/>
|
||||
<ColumnConstraints hgrow="NEVER"/>
|
||||
<ColumnConstraints hgrow="NEVER"/>
|
||||
<ColumnConstraints hgrow="ALWAYS"/>
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER"/>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER"/>
|
||||
</rowConstraints>
|
||||
|
||||
<!-- Row 0-->
|
||||
<Label
|
||||
GridPane.rowIndex="0"
|
||||
GridPane.columnIndex="0"
|
||||
text="Name:"
|
||||
/>
|
||||
<TextField
|
||||
GridPane.rowIndex="0"
|
||||
GridPane.columnIndex="1"
|
||||
/>
|
||||
<Label
|
||||
GridPane.rowIndex="0"
|
||||
GridPane.columnIndex="3"
|
||||
text="Hersteller:"
|
||||
/>
|
||||
<TextField
|
||||
GridPane.rowIndex="0"
|
||||
GridPane.columnIndex="4"
|
||||
/>
|
||||
<!-- Row 1 -->
|
||||
<Label
|
||||
GridPane.rowIndex="1"
|
||||
GridPane.columnIndex="0"
|
||||
text="Verabreichungsmethode:"
|
||||
/>
|
||||
<TextField
|
||||
GridPane.rowIndex="1"
|
||||
GridPane.columnIndex="1"
|
||||
/>
|
||||
<Label
|
||||
GridPane.rowIndex="1"
|
||||
GridPane.columnIndex="3"
|
||||
text="Lagerbestand:"
|
||||
/>
|
||||
<TextField
|
||||
GridPane.rowIndex="1"
|
||||
GridPane.columnIndex="4"
|
||||
/>
|
||||
|
||||
</GridPane>
|
||||
</top>
|
||||
<center>
|
||||
<Label text="Test"/>
|
||||
<BorderPane>
|
||||
<padding>
|
||||
<Insets top="8" bottom="8"/>
|
||||
</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="8"/>
|
||||
</BorderPane.margin>
|
||||
</ListView>
|
||||
</center>
|
||||
<bottom>
|
||||
<AnchorPane>
|
||||
<BorderPane.margin>
|
||||
<Insets top="8"/>
|
||||
</BorderPane.margin>
|
||||
<Button
|
||||
onAction="#handleAddIngredient"
|
||||
text="+"
|
||||
AnchorPane.leftAnchor="0"
|
||||
AnchorPane.rightAnchor="0"
|
||||
/>
|
||||
</AnchorPane>
|
||||
</bottom>
|
||||
</BorderPane>
|
||||
</left>
|
||||
<center>
|
||||
<TextArea/>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</center>
|
||||
<bottom>
|
||||
<BorderPane>
|
||||
<right>
|
||||
<HBox spacing="8.0">
|
||||
<Button
|
||||
fx:id="buttonSave"
|
||||
prefWidth="90"
|
||||
mnemonicParsing="false"
|
||||
onAction="#handleSave"
|
||||
text="Speichern"
|
||||
/>
|
||||
<Button
|
||||
prefWidth="90"
|
||||
mnemonicParsing="false"
|
||||
onAction="#handleCancel"
|
||||
text="Abbrechen"
|
||||
/>
|
||||
</HBox>
|
||||
</right>
|
||||
</BorderPane>
|
||||
</bottom>
|
||||
</BorderPane>
|
||||
|
|
|
@ -119,7 +119,7 @@
|
|||
fx:id="textAreaRemarks"
|
||||
HBox.hgrow="ALWAYS"
|
||||
/>
|
||||
<VBox>
|
||||
<VBox spacing="8.0">
|
||||
<Button
|
||||
fx:id="buttonSave"
|
||||
prefWidth="90"
|
||||
|
|
Loading…
Reference in a new issue