Compare commits

..

No commits in common. "3f6625b270946a0acb7ae1cbe061600aefc9584f" and "1d419a622068e3df7b1d32877beaab5959350866" have entirely different histories.

3 changed files with 28 additions and 74 deletions

View file

@ -8,17 +8,12 @@ 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.medication.database.MedicationDao; import de.hitec.nhplus.medication.database.MedicationDao;
import de.hitec.nhplus.nurse.Nurse;
import de.hitec.nhplus.patient.Patient;
import de.hitec.nhplus.treatment.Treatment;
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.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.SelectionModel;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
@ -63,20 +58,20 @@ public class AllMedicationController {
this.columnName.setCellValueFactory(new PropertyValueFactory<>("name")); this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
this.columnManufacturer.setCellValueFactory(new PropertyValueFactory<>("manufacturer")); this.columnManufacturer.setCellValueFactory(new PropertyValueFactory<>("manufacturer"));
this.columnIngredient.setCellValueFactory( this.columnIngredient.setCellValueFactory(
cellData -> { cellData -> {
Medication medication = cellData.getValue(); Medication medication = cellData.getValue();
List<Ingredient> ingredients = medication.getIngredients(); List<Ingredient> ingredients = medication.getIngredients();
if (ingredients.isEmpty()) { if(ingredients.isEmpty()){
return new SimpleStringProperty(""); return new SimpleStringProperty("");
} }
return new SimpleStringProperty( return new SimpleStringProperty(
ingredients ingredients
.stream() .stream()
.map(ingredient -> ingredient.getName()) .map(ingredient -> ingredient.getName())
.collect(Collectors.joining("\n")) .collect(Collectors.joining("\n"))
); );
}); });
this.columnPossibleSideEffects.setCellValueFactory(new PropertyValueFactory<>("possibleSideEffects")); this.columnPossibleSideEffects.setCellValueFactory(new PropertyValueFactory<>("possibleSideEffects"));
this.columnAdministrationMethod.setCellValueFactory(new PropertyValueFactory<>("administrationMethod")); this.columnAdministrationMethod.setCellValueFactory(new PropertyValueFactory<>("administrationMethod"));
this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock")); this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock"));
@ -96,18 +91,6 @@ public class AllMedicationController {
} }
} }
/**
* Method to save the changes to a {@link Medication}.
*/
public void updateMedication(Medication medication) {
dao = DaoFactory.getInstance().createMedicationDAO();
try {
dao.update(medication);
} catch (SQLException exception) {
exception.printStackTrace();
}
}
/** /**
* Method to create a new {@link Medication}. * Method to create a new {@link Medication}.
*/ */
@ -120,26 +103,21 @@ public class AllMedicationController {
} }
} }
/** @FXML
* Internal method to create a {@link MedicationModalController MedicationModal}. public void handleNewMedication() {
*
* @param medication The {@link Medication} which should be edited. Set null to create a new one.
* @param title The Title of the created modal.
*/
public void medicationWindow(Medication medication, String title) {
try { try {
FXMLLoader loader = new FXMLLoader( FXMLLoader loader = new FXMLLoader(
Main.class.getResource("/de/hitec/nhplus/medication/MedicationModal.fxml") Main.class.getResource("/de/hitec/nhplus/medication/MedicationModal.fxml")
); );
BorderPane pane = loader.load(); BorderPane pane = loader.load();
Scene scene = new Scene(pane); Scene scene = new Scene(pane);
Stage stage = new Stage(); Stage stage = new Stage();
MedicationModalController controller = loader.getController(); MedicationModalController controller = loader.getController();
controller.initialize(stage, this, medication); controller.initialize(stage, this, null);
stage.setScene(scene); stage.setScene(scene);
stage.setTitle(title); stage.setTitle("NHPlus - Neues Medikament");
stage.setResizable(true); stage.setResizable(true);
stage.setAlwaysOnTop(true); stage.setAlwaysOnTop(true);
stage.showAndWait(); stage.showAndWait();
@ -147,21 +125,4 @@ public class AllMedicationController {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
@FXML
public void handleNewMedication() {
medicationWindow(null, "NHPlus - Neues Medikament");
}
@FXML
public void handleMouseClick() {
tableView.setOnMouseClicked(event -> {
SelectionModel<Medication> selectionModel = tableView.getSelectionModel();
if (event.getClickCount() == 2 && (selectionModel.getSelectedItem() != null)) {
int index = selectionModel.getSelectedIndex();
Medication medication = this.medications.get(index);
medicationWindow(medication, "NHPlus - Medikament");
}
});
}
} }

View file

@ -43,7 +43,6 @@ public class MedicationModalController {
private Medication medication; private Medication medication;
private final ObservableList<Ingredient> ingredients = FXCollections.observableArrayList(); private final ObservableList<Ingredient> ingredients = FXCollections.observableArrayList();
private AllMedicationController controller; private AllMedicationController controller;
private boolean isNewMedication = false;
/** /**
* Initialization method that is called after the binding of all the fields. * Initialization method that is called after the binding of all the fields.
@ -55,12 +54,11 @@ public class MedicationModalController {
Medication medication Medication medication
) { ) {
this.stage = stage; this.stage = stage;
this.controller = controller; this.controller=controller;
if (medication != null) { if( medication != null){
this.medication = medication; this.medication = medication;
} else { }else {
isNewMedication = true;
this.medication = new Medication( this.medication = new Medication(
"", "",
"", "",
@ -78,9 +76,9 @@ public class MedicationModalController {
ChangeListener<String> inputMedicationValidationListener = (observableValue, oldText, newText) -> { ChangeListener<String> inputMedicationValidationListener = (observableValue, oldText, newText) -> {
boolean isValid = isValidMedicationName(textFieldName.getText()) boolean isValid = isValidMedicationName(textFieldName.getText())
&& isValidMedicationManufacturer(textFieldManufacturer.getText()) && isValidMedicationManufacturer(textFieldManufacturer.getText())
&& isValidMedicationAdministrationMethod(textFieldAdministrationMethod.getText()) && isValidMedicationAdministrationMethod(textFieldAdministrationMethod.getText())
&& isValidStock(textFieldCurrentStock.getText()); && isValidStock(textFieldCurrentStock.getText());
this.buttonSave.setDisable(!isValid); this.buttonSave.setDisable(!isValid);
}; };
@ -94,7 +92,7 @@ public class MedicationModalController {
/** /**
* Internal method to show the data in the view. * Internal method to show the data in the view.
*/ */
private void showData() { private void showData(){
ingredients.setAll(medication.getIngredients()); ingredients.setAll(medication.getIngredients());
textFieldName.setText(medication.getName()); textFieldName.setText(medication.getName());
textFieldManufacturer.setText(medication.getManufacturer()); textFieldManufacturer.setText(medication.getManufacturer());
@ -119,12 +117,7 @@ public class MedicationModalController {
.toList() .toList()
); );
if (isNewMedication) { controller.createMedication(medication);
controller.createMedication(medication);
} else {
controller.updateMedication(medication);
}
controller.readAllAndShowInTableView(); controller.readAllAndShowInTableView();
stage.close(); stage.close();
} }

View file

@ -12,7 +12,7 @@
<Insets top="8" left="8" right="8" bottom="8"/> <Insets top="8" left="8" right="8" bottom="8"/>
</padding> </padding>
<center> <center>
<TableView fx:id="tableView" onMouseClicked="#handleMouseClick"> <TableView fx:id="tableView">
<columns> <columns>
<TableColumn <TableColumn
fx:id="columnId" fx:id="columnId"