Compare commits

..

2 commits

Author SHA1 Message Date
942577a86a
NOTICKET: Fix MedicationDao
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 36s
Quality Check / Javadoc Check (pull_request) Successful in 34s
2024-05-17 08:43:46 +02:00
60c47098c6 #18: WIP
All checks were successful
Quality Check / Linting Check (push) Successful in 12s
Quality Check / Javadoc Check (push) Successful in 20s
2024-05-17 08:41:35 +02:00
3 changed files with 69 additions and 16 deletions

View file

@ -1,12 +1,15 @@
package de.hitec.nhplus.medication;
import java.io.IOException;
import java.sql.SQLException;
import java.util.stream.Collectors;
import de.hitec.nhplus.Main;
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.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
@ -16,10 +19,6 @@ import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import java.io.IOException;
import java.sql.SQLException;
import java.util.stream.Collectors;
/**
* The controller for viewing all {@link Medication}s.
*
@ -84,6 +83,15 @@ public class AllMedicationController {
}
}
public void createMedication(Medication medication) {
dao = DaoFactory.getInstance().createMedicationDAO();
try {
dao.create(medication);
} catch (SQLException exception) {
exception.printStackTrace();
}
}
@FXML
public void handleNewMedication() {
try {
@ -95,7 +103,7 @@ public class AllMedicationController {
Stage stage = new Stage();
MedicationModalController controller = loader.getController();
controller.initialize(null);
controller.initialize(stage, this, null);
stage.setScene(scene);
stage.setTitle("NHPlus - Neues Medikament");

View file

@ -1,9 +1,14 @@
package de.hitec.nhplus.medication;
import de.hitec.nhplus.treatment.AllTreatmentController;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import java.util.ArrayList;
public class MedicationModalController {
@ -11,13 +16,27 @@ public class MedicationModalController {
@FXML
public ListView<Ingredient> listViewIngredients;
@FXML
public TextField textFieldName;
@FXML
public TextField textFieldManufacturer;
@FXML
public TextField textFieldAdministrationMethod;
@FXML
public TextField textFieldCurrentStock;
@FXML
public TextArea textAreaPossibleSideEffects;
private Stage stage;
private Medication medication;
private final ObservableList<Ingredient> ingredients = FXCollections.observableArrayList();
private AllMedicationController controller;
@FXML
public void initialize(Medication medication) {
public void initialize(Stage stage, AllMedicationController controller, Medication medication) {
this.stage = stage;
this.controller=controller;
this.medication = medication != null ? medication : new Medication(
"",
"",
@ -35,10 +54,25 @@ public class MedicationModalController {
private void showData(){
ingredients.setAll(medication.getIngredients());
textFieldName.setText(medication.getName());
textFieldManufacturer.setText(medication.getManufacturer());
textFieldAdministrationMethod.setText(medication.getAdministrationMethod());
textFieldCurrentStock.setText(String.valueOf(medication.getCurrentStock()));
textAreaPossibleSideEffects.setText(medication.getPossibleSideEffects());
}
@FXML
public void handleSave() {
this.medication.setName(textFieldName.getText());
this.medication.setManufacturer(textFieldManufacturer.getText());
this.medication.setAdministrationMethod(textFieldAdministrationMethod.getText());
this.medication.setCurrentStock(Integer.parseInt(textFieldCurrentStock.getText()));
this.medication.setPossibleSideEffects(textAreaPossibleSideEffects.getText());
this.medication.setIngredients(ingredients);
controller.createMedication(medication);
controller.readAllAndShowInTableView();
stage.close();
}
@FXML

View file

@ -32,6 +32,7 @@
text="Name:"
/>
<TextField
fx:id="textFieldName"
GridPane.rowIndex="0"
GridPane.columnIndex="1"
/>
@ -41,6 +42,7 @@
text="Hersteller:"
/>
<TextField
fx:id="textFieldManufacturer"
GridPane.rowIndex="0"
GridPane.columnIndex="4"
/>
@ -51,6 +53,7 @@
text="Verabreichungsmethode:"
/>
<TextField
fx:id="textFieldAdministrationMethod"
GridPane.rowIndex="1"
GridPane.columnIndex="1"
/>
@ -60,6 +63,7 @@
text="Lagerbestand:"
/>
<TextField
fx:id="textFieldCurrentStock"
GridPane.rowIndex="1"
GridPane.columnIndex="4"
/>
@ -102,7 +106,14 @@
</BorderPane>
</left>
<center>
<TextArea/>
<BorderPane>
<top>
<Label text="Nebenwirkungen"/>
</top>
<center>
<TextArea fx:id="textAreaPossibleSideEffects"/>
</center>
</BorderPane>
</center>
</BorderPane>
</center>