#26: Implementing Editing of Medications
This commit is contained in:
parent
1d419a6220
commit
ad3bd8ba0a
3 changed files with 44 additions and 7 deletions
|
@ -8,12 +8,17 @@ 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;
|
||||||
|
@ -91,6 +96,15 @@ public class AllMedicationController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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}.
|
||||||
*/
|
*/
|
||||||
|
@ -103,8 +117,7 @@ public class AllMedicationController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
public void medicationWindow(Medication medication, String title) {
|
||||||
public void handleNewMedication() {
|
|
||||||
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")
|
||||||
|
@ -114,10 +127,10 @@ public class AllMedicationController {
|
||||||
Stage stage = new Stage();
|
Stage stage = new Stage();
|
||||||
|
|
||||||
MedicationModalController controller = loader.getController();
|
MedicationModalController controller = loader.getController();
|
||||||
controller.initialize(stage, this, null);
|
controller.initialize(stage, this, medication);
|
||||||
|
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
stage.setTitle("NHPlus - Neues Medikament");
|
stage.setTitle(title);
|
||||||
stage.setResizable(true);
|
stage.setResizable(true);
|
||||||
stage.setAlwaysOnTop(true);
|
stage.setAlwaysOnTop(true);
|
||||||
stage.showAndWait();
|
stage.showAndWait();
|
||||||
|
@ -125,4 +138,21 @@ 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");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ 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.
|
||||||
|
@ -59,6 +60,7 @@ public class MedicationModalController {
|
||||||
if( medication != null){
|
if( medication != null){
|
||||||
this.medication = medication;
|
this.medication = medication;
|
||||||
}else {
|
}else {
|
||||||
|
isNewMedication = true;
|
||||||
this.medication = new Medication(
|
this.medication = new Medication(
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
|
@ -117,7 +119,12 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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">
|
<TableView fx:id="tableView" onMouseClicked="#handleMouseClick">
|
||||||
<columns>
|
<columns>
|
||||||
<TableColumn
|
<TableColumn
|
||||||
fx:id="columnId"
|
fx:id="columnId"
|
||||||
|
|
Loading…
Reference in a new issue