Compare commits
3 commits
4b6765858e
...
864fbd37a8
Author | SHA1 | Date | |
---|---|---|---|
|
864fbd37a8 | ||
|
0aea0911b4 | ||
|
6e33101494 |
15 changed files with 153 additions and 31 deletions
Binary file not shown.
|
@ -117,7 +117,7 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
"Unterhautinjektion",
|
||||
120
|
||||
));
|
||||
medications.add(new Medication(
|
||||
Medication deprecatedMedication = new Medication(
|
||||
"Levothyroxin",
|
||||
"Sandoz",
|
||||
List.of(
|
||||
|
@ -129,7 +129,9 @@ public class MedicationFixture implements Fixture<Medication> {
|
|||
"Herzrasen, Gewichtsverlust",
|
||||
"Oral",
|
||||
90
|
||||
));
|
||||
);
|
||||
deprecatedMedication.setIsDeprecated(true);
|
||||
medications.add(deprecatedMedication);
|
||||
medications.add(new Medication(
|
||||
"Warfarin",
|
||||
"Apotex Inc.",
|
||||
|
|
|
@ -2,6 +2,9 @@ package de.hitec.nhplus.main;
|
|||
|
||||
import de.hitec.nhplus.Main;
|
||||
import de.hitec.nhplus.nurse.Nurse;
|
||||
import de.hitec.nhplus.patient.Patient;
|
||||
import de.hitec.nhplus.treatment.Treatment;
|
||||
import de.hitec.nhplus.medication.Medication;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.control.SelectionModel;
|
||||
|
@ -49,6 +52,8 @@ public class MainWindowController {
|
|||
@FXML
|
||||
private Tab medicationTab;
|
||||
@FXML
|
||||
private Tab availableMedicationTab;
|
||||
@FXML
|
||||
private TabPane medicationTabPane;
|
||||
@FXML
|
||||
private AnchorPane deprecatedMedicationPage;
|
||||
|
@ -71,7 +76,7 @@ public class MainWindowController {
|
|||
|
||||
activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage());
|
||||
lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage());
|
||||
medicationTab.setOnSelectionChanged(event -> loadMedicationPage());
|
||||
availableMedicationTab.setOnSelectionChanged(event -> loadAvailableMedicationPage());
|
||||
deprecatedMedicationTab.setOnSelectionChanged(event -> loadDeprecatedMedicationPage());
|
||||
|
||||
nurseTabPane.getSelectionModel().select(activeNurseTab);
|
||||
|
@ -79,7 +84,7 @@ public class MainWindowController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads the patient page into its tab.
|
||||
* Loads the {@link Patient} page into its tab.
|
||||
*/
|
||||
private void loadPatientPage() {
|
||||
try {
|
||||
|
@ -97,7 +102,7 @@ public class MainWindowController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads the {@link } page into its tab.
|
||||
* Loads the {@link Treatment} page into its tab.
|
||||
*/
|
||||
private void loadTreatmentsPage() {
|
||||
try {
|
||||
|
@ -115,7 +120,7 @@ public class MainWindowController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads the nurse page into its tab.
|
||||
* Loads the {@link Nurse} page into its tab.
|
||||
*/
|
||||
private void loadNursePage() {
|
||||
SelectionModel<Tab> selectionModel = nurseTabPane.getSelectionModel();
|
||||
|
@ -165,9 +170,24 @@ public class MainWindowController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads the medication page into its tab.
|
||||
* Loads the {@link Medication} page into its tab.
|
||||
*/
|
||||
private void loadMedicationPage() {
|
||||
private void loadMedicationPage()
|
||||
{
|
||||
SelectionModel<Tab> selectionModel = medicationTabPane.getSelectionModel();
|
||||
Tab selectedTab = selectionModel.getSelectedItem();
|
||||
if(selectedTab == availableMedicationTab){
|
||||
loadAvailableMedicationPage();
|
||||
}
|
||||
if(selectedTab == deprecatedMedicationTab){
|
||||
loadDeprecatedMedicationPage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the {@link Medication} page into its tab.
|
||||
*/
|
||||
private void loadAvailableMedicationPage() {
|
||||
try {
|
||||
BorderPane medicationPane = FXMLLoader.load(
|
||||
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/medication/AllMedicationView.fxml"))
|
||||
|
@ -182,10 +202,14 @@ public class MainWindowController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the deprecated {@link Medication} page into its tab.
|
||||
*/
|
||||
private void loadDeprecatedMedicationPage(){
|
||||
try {
|
||||
BorderPane deprecatedMedicationPane = FXMLLoader.load(
|
||||
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/medication/DeprecatedMedicationView.fxml"))
|
||||
Objects.requireNonNull(Main.class.getResource(
|
||||
"/de/hitec/nhplus/medication/DeprecatedMedicationView.fxml"))
|
||||
);
|
||||
deprecatedMedicationPage.getChildren().setAll(deprecatedMedicationPane);
|
||||
AnchorPane.setTopAnchor(deprecatedMedicationPane, 0d);
|
||||
|
|
|
@ -18,6 +18,7 @@ import javafx.collections.ObservableList;
|
|||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.SelectionModel;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
|
@ -48,6 +49,8 @@ public class AllMedicationController {
|
|||
private TableColumn<Medication, String> columnAdministrationMethod;
|
||||
@FXML
|
||||
private TableColumn<Medication, Integer> columnCurrentStock;
|
||||
@FXML
|
||||
public Button buttonChangeAvailable;
|
||||
|
||||
private final ObservableList<Medication> medications = FXCollections.observableArrayList();
|
||||
private MedicationDao dao;
|
||||
|
@ -57,7 +60,7 @@ public class AllMedicationController {
|
|||
*/
|
||||
@FXML
|
||||
public void initialize() {
|
||||
readAllAndShowInTableView();
|
||||
this.readAllAndShowInTableView();
|
||||
|
||||
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
|
||||
this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
|
||||
|
@ -82,6 +85,7 @@ public class AllMedicationController {
|
|||
this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock"));
|
||||
|
||||
this.tableView.setItems(this.medications);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,7 +94,7 @@ public class AllMedicationController {
|
|||
public void readAllAndShowInTableView() {
|
||||
this.dao = DaoFactory.getInstance().createMedicationDAO();
|
||||
try {
|
||||
this.medications.setAll(dao.readAll());
|
||||
this.medications.setAll(dao.readAllAvailable());
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
@ -120,6 +124,22 @@ public class AllMedicationController {
|
|||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleChangeAvailable() {
|
||||
Medication selectedItem = this.tableView.getSelectionModel().getSelectedItem();
|
||||
if (selectedItem == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
selectedItem.setIsDeprecated(true);
|
||||
this.dao.update(selectedItem);
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
this.readAllAndShowInTableView();
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to create a {@link MedicationModalController MedicationModal}.
|
||||
*
|
||||
|
|
|
@ -6,6 +6,7 @@ import javafx.beans.property.SimpleStringProperty;
|
|||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
|
@ -31,13 +32,17 @@ public class DeprecatedMedicationController {
|
|||
private TableColumn<Medication, String> columnAdministrationMethod;
|
||||
@FXML
|
||||
private TableColumn<Medication, Integer> columnCurrentStock;
|
||||
@FXML
|
||||
public Button buttonChangeAvailable;
|
||||
|
||||
private final ObservableList<Medication> medications = FXCollections.observableArrayList();
|
||||
private MedicationDao dao;
|
||||
|
||||
@FXML
|
||||
/**
|
||||
* Initialization method that is called after the binding of all the fields.
|
||||
*/
|
||||
public void initialize() {
|
||||
readAllAndShowInTableView();
|
||||
this.readAllAndShowInTableView();
|
||||
|
||||
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
|
||||
this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
|
||||
|
@ -62,18 +67,35 @@ public class DeprecatedMedicationController {
|
|||
this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock"));
|
||||
|
||||
this.tableView.setItems(this.medications);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to read all data and set it to the table view.
|
||||
*/
|
||||
public void readAllAndShowInTableView() {
|
||||
this.medications.clear();
|
||||
this.dao = DaoFactory.getInstance().createMedicationDAO();
|
||||
try {
|
||||
this.medications.setAll(dao.readAllDeprecated());
|
||||
this.medications.setAll(this.dao.readAllDeprecated());
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
@FXML
|
||||
public void handleChangeAvailable(){
|
||||
Medication selectedItem = tableView.getSelectionModel().getSelectedItem();
|
||||
if (selectedItem == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
selectedItem.setIsDeprecated(false);
|
||||
this.dao.update(selectedItem);
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
this.readAllAndShowInTableView();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class Medication {
|
|||
String possibleSideEffects,
|
||||
String administrationMethod,
|
||||
int currentStock,
|
||||
boolean isDepreacted
|
||||
boolean isDeprecated
|
||||
) {
|
||||
this.id = new SimpleIntegerProperty(id);
|
||||
this.name = new SimpleStringProperty(name);
|
||||
|
@ -70,7 +70,7 @@ public class Medication {
|
|||
this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects);
|
||||
this.administrationMethod = new SimpleStringProperty(administrationMethod);
|
||||
this.currentStock = new SimpleIntegerProperty(currentStock);
|
||||
this.isDeprecated = new SimpleBooleanProperty(isDepreacted);
|
||||
this.isDeprecated = new SimpleBooleanProperty(isDeprecated);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
|
|
@ -39,6 +39,7 @@ public class MedicationModalController {
|
|||
@FXML
|
||||
public Button buttonSave;
|
||||
|
||||
|
||||
private Stage stage;
|
||||
private Medication medication;
|
||||
private final ObservableList<Ingredient> ingredients = FXCollections.observableArrayList();
|
||||
|
|
|
@ -86,7 +86,6 @@ public class MedicationDao implements Dao<Medication> {
|
|||
SELECT medication.*, medication_ingredient.name
|
||||
FROM medication LEFT JOIN
|
||||
medication_ingredient ON medication.id = medication_ingredient.id
|
||||
WHERE isDeprecated = false
|
||||
""";
|
||||
ResultSet result = connection.prepareStatement(SQL).executeQuery();
|
||||
|
||||
|
@ -133,8 +132,58 @@ public class MedicationDao implements Dao<Medication> {
|
|||
final String SQL = """
|
||||
SELECT medication.*, medication_ingredient.name
|
||||
FROM medication LEFT JOIN
|
||||
medication_ingredient ON medication.id = medication_ingredient.id
|
||||
WHERE isDeprecated = true
|
||||
medication_ingredient
|
||||
ON medication.id = medication_ingredient.id
|
||||
WHERE medication.isDeprecated = true
|
||||
""";
|
||||
ResultSet result = connection.prepareStatement(SQL).executeQuery();
|
||||
|
||||
List<Medication> medications = new ArrayList<>();
|
||||
Map<Integer, List<Ingredient>> ingredientMap = new HashMap<>();
|
||||
|
||||
int currentMedicationId;
|
||||
int lastMedicationId = -1;
|
||||
while (result.next()) {
|
||||
currentMedicationId = result.getInt(1);
|
||||
if (currentMedicationId != lastMedicationId) {
|
||||
Medication medication = new Medication(
|
||||
result.getInt(1),
|
||||
result.getString(2),
|
||||
result.getString(3),
|
||||
new ArrayList<>(),
|
||||
result.getString(4),
|
||||
result.getString(5),
|
||||
result.getInt(6),
|
||||
result.getBoolean(7)
|
||||
);
|
||||
medications.add(medication);
|
||||
}
|
||||
List<Ingredient> ingredients = ingredientMap.computeIfAbsent(currentMedicationId, k -> new ArrayList<>());
|
||||
String ingredientName = result.getString(8);
|
||||
if(ingredientName == null){
|
||||
continue;
|
||||
}
|
||||
ingredients.add(new Ingredient(ingredientName));
|
||||
lastMedicationId = currentMedicationId;
|
||||
}
|
||||
for (Medication medication : medications) {
|
||||
List<Ingredient> ingredients = ingredientMap.get(medication.getId());
|
||||
if(ingredients.isEmpty()){
|
||||
continue;
|
||||
}
|
||||
medication.setIngredients(ingredientMap.get(medication.getId()));
|
||||
}
|
||||
|
||||
return medications;
|
||||
}
|
||||
|
||||
public List<Medication> readAllAvailable() throws SQLException {
|
||||
final String SQL = """
|
||||
SELECT medication.*, medication_ingredient.name
|
||||
FROM medication LEFT JOIN
|
||||
medication_ingredient
|
||||
ON medication.id = medication_ingredient.id
|
||||
WHERE medication.isDeprecated = false
|
||||
""";
|
||||
ResultSet result = connection.prepareStatement(SQL).executeQuery();
|
||||
|
||||
|
@ -195,8 +244,8 @@ public class MedicationDao implements Dao<Medication> {
|
|||
preparedStatement.setString(3, medication.getPossibleSideEffects());
|
||||
preparedStatement.setString(4, medication.getAdministrationMethod());
|
||||
preparedStatement.setInt(5, medication.getCurrentStock());
|
||||
preparedStatement.setInt(6, medication.getId());
|
||||
preparedStatement.setBoolean(6, medication.isDeprecated());
|
||||
preparedStatement.setInt(7, medication.getId());
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
final String ingredientDeleteSQL = """
|
||||
|
|
|
@ -112,6 +112,4 @@ public class NurseDao extends DaoImp<Nurse> {
|
|||
statement.setInt(1, id);
|
||||
return statement;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ public class AllTreatmentController {
|
|||
*/
|
||||
@FXML
|
||||
public void initialize() {
|
||||
readAllAndShowInTableView();
|
||||
|
||||
comboBoxPatientSelection.setItems(patientSelection);
|
||||
comboBoxPatientSelection.getSelectionModel().select("alle");
|
||||
|
||||
|
@ -109,6 +109,7 @@ public class AllTreatmentController {
|
|||
);
|
||||
|
||||
this.createComboBoxData();
|
||||
readAllAndShowInTableView();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
</Tab>
|
||||
<Tab fx:id="medicationTab" text="Medikamente">
|
||||
<TabPane fx:id="medicationTabPane" tabClosingPolicy="UNAVAILABLE">
|
||||
<Tab fx:id="allMedicationTab" text="Medikamente">
|
||||
<Tab fx:id="availableMedicationTab" text="Medikamente">
|
||||
<AnchorPane fx:id="medicationPage"/>
|
||||
</Tab>
|
||||
<Tab fx:id="deprecatedMedicationTab" text="Veraltete Medikamente">
|
||||
|
|
|
@ -75,6 +75,13 @@
|
|||
prefWidth="90.0"
|
||||
text="Löschen"
|
||||
/>
|
||||
<Button
|
||||
fx:id="buttonChangeAvailable"
|
||||
mnemonicParsing="false"
|
||||
onAction="#handleChangeAvailable"
|
||||
prefWidth="155.0"
|
||||
text="Veraltet-Status ändern"
|
||||
/>
|
||||
</HBox>
|
||||
</right>
|
||||
</BorderPane>
|
||||
|
|
|
@ -62,14 +62,13 @@
|
|||
</BorderPane.margin>
|
||||
<right>
|
||||
<HBox spacing="8.0">
|
||||
<!--
|
||||
<Button
|
||||
fx:id="buttonDelete"
|
||||
fx:id="buttonChangeAvailable"
|
||||
mnemonicParsing="false"
|
||||
prefWidth="90.0"
|
||||
text="Löschen"
|
||||
prefWidth="155.0"
|
||||
onAction="#handleChangeAvailable"
|
||||
text="Veraltet-Status ändern"
|
||||
/>
|
||||
-->
|
||||
</HBox>
|
||||
</right>
|
||||
</BorderPane>
|
||||
|
|
|
@ -6,5 +6,5 @@ CREATE TABLE medication
|
|||
possibleSideEffects TEXT NOT NULL,
|
||||
administrationMethod TEXT NOT NULL,
|
||||
currentStock INTEGER NOT NULL,
|
||||
isDeprecated BOOLEAN NOT NULL DEFAULT FALSE
|
||||
isDeprecated BOOLEAN NOT NULL DEFAULT false
|
||||
)
|
|
@ -74,7 +74,6 @@
|
|||
onAction="#handleDelete"
|
||||
prefWidth="90.0"
|
||||
text="Löschen"
|
||||
|
||||
/>
|
||||
</HBox>
|
||||
</right>
|
||||
|
|
Loading…
Reference in a new issue