Compare commits

..

2 commits

Author SHA1 Message Date
930eba22e1
NOTICKET: Fix MedicationDao
All checks were successful
Quality Check / Linting Check (push) Successful in 11s
Quality Check / Javadoc Check (push) Successful in 20s
Quality Check / Linting Check (pull_request) Successful in 12s
Quality Check / Javadoc Check (pull_request) Successful in 21s
2024-05-16 18:32:10 +02:00
d89c0f49e4
#18: WIP
All checks were successful
Quality Check / Linting Check (push) Successful in 12s
Quality Check / Javadoc Check (push) Successful in 20s
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
2024-05-15 20:56:50 +02:00
3 changed files with 16 additions and 69 deletions

View file

@ -1,15 +1,12 @@
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;
@ -19,6 +16,10 @@ 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.
*
@ -56,14 +57,14 @@ public class AllMedicationController {
this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
this.columnManufacturer.setCellValueFactory(new PropertyValueFactory<>("manufacturer"));
this.columnIngredient.setCellValueFactory(
cellData -> new SimpleStringProperty(
cellData
.getValue()
.getIngredients()
.stream()
.map(ingredient -> ingredient.getName())
.collect(Collectors.joining("\n"))
));
cellData -> new SimpleStringProperty(
cellData
.getValue()
.getIngredients()
.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"));
@ -83,15 +84,6 @@ 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 {
@ -103,7 +95,7 @@ public class AllMedicationController {
Stage stage = new Stage();
MedicationModalController controller = loader.getController();
controller.initialize(stage, this, null);
controller.initialize(null);
stage.setScene(scene);
stage.setTitle("NHPlus - Neues Medikament");

View file

@ -1,14 +1,9 @@
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 {
@ -16,27 +11,13 @@ 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(Stage stage, AllMedicationController controller, Medication medication) {
this.stage = stage;
this.controller=controller;
public void initialize(Medication medication) {
this.medication = medication != null ? medication : new Medication(
"",
"",
@ -54,25 +35,10 @@ 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,7 +32,6 @@
text="Name:"
/>
<TextField
fx:id="textFieldName"
GridPane.rowIndex="0"
GridPane.columnIndex="1"
/>
@ -42,7 +41,6 @@
text="Hersteller:"
/>
<TextField
fx:id="textFieldManufacturer"
GridPane.rowIndex="0"
GridPane.columnIndex="4"
/>
@ -53,7 +51,6 @@
text="Verabreichungsmethode:"
/>
<TextField
fx:id="textFieldAdministrationMethod"
GridPane.rowIndex="1"
GridPane.columnIndex="1"
/>
@ -63,7 +60,6 @@
text="Lagerbestand:"
/>
<TextField
fx:id="textFieldCurrentStock"
GridPane.rowIndex="1"
GridPane.columnIndex="4"
/>
@ -106,14 +102,7 @@
</BorderPane>
</left>
<center>
<BorderPane>
<top>
<Label text="Nebenwirkungen"/>
</top>
<center>
<TextArea fx:id="textAreaPossibleSideEffects"/>
</center>
</BorderPane>
<TextArea/>
</center>
</BorderPane>
</center>