Compare commits

...

8 commits

Author SHA1 Message Date
arminribic
4b6765858e #24 Linter
All checks were successful
Quality Check / Linting Check (push) Successful in 12s
Quality Check / Javadoc Check (push) Successful in 21s
Quality Check / Linting Check (pull_request) Successful in 13s
Quality Check / Javadoc Check (pull_request) Successful in 22s
2024-05-21 08:42:27 +02:00
Dorian Nemec
e2462b9f7c #24 Javadoc ergänzt
Some checks failed
Quality Check / Linting Check (push) Failing after 13s
Quality Check / Javadoc Check (push) Successful in 22s
2024-05-21 08:39:58 +02:00
Dorian Nemec
48a221848a #24 Fixed UI not being correctly updated
Some checks failed
Quality Check / Linting Check (push) Failing after 13s
Quality Check / Javadoc Check (push) Successful in 21s
2024-05-21 08:24:27 +02:00
Dorian Nemec
1a542a0d71 #24 Deprecated and available medication properly implemented
Some checks failed
Quality Check / Linting Check (push) Failing after 12s
Quality Check / Javadoc Check (push) Successful in 21s
2024-05-20 16:49:57 +02:00
Dorian Nemec
67b1093661 #24 WIP Medication
Some checks failed
Quality Check / Linting Check (push) Failing after 12s
Quality Check / Javadoc Check (push) Successful in 21s
2024-05-20 16:34:06 +02:00
arminribic
6ea6c4d0e6 #24 Logik implementiert und UI fertig gestellt
Some checks failed
Quality Check / Linting Check (push) Failing after 13s
Quality Check / Javadoc Check (push) Successful in 22s
2024-05-20 10:32:58 +02:00
arminribic
b206e2975b #24 Logik implementiert und UI fertig gestellt 2024-05-20 10:32:08 +02:00
arminribic
75b275198a #24 Logik implementiert und UI fertig gestellt
Some checks failed
Quality Check / Linting Check (push) Failing after 12s
Quality Check / Javadoc Check (push) Successful in 21s
2024-05-20 10:28:17 +02:00
15 changed files with 153 additions and 31 deletions

Binary file not shown.

View file

@ -117,7 +117,7 @@ public class MedicationFixture implements Fixture<Medication> {
"Unterhautinjektion", "Unterhautinjektion",
120 120
)); ));
medications.add(new Medication( Medication deprecatedMedication = new Medication(
"Levothyroxin", "Levothyroxin",
"Sandoz", "Sandoz",
List.of( List.of(
@ -129,7 +129,9 @@ public class MedicationFixture implements Fixture<Medication> {
"Herzrasen, Gewichtsverlust", "Herzrasen, Gewichtsverlust",
"Oral", "Oral",
90 90
)); );
deprecatedMedication.setIsDeprecated(true);
medications.add(deprecatedMedication);
medications.add(new Medication( medications.add(new Medication(
"Warfarin", "Warfarin",
"Apotex Inc.", "Apotex Inc.",

View file

@ -2,6 +2,9 @@ package de.hitec.nhplus.main;
import de.hitec.nhplus.Main; import de.hitec.nhplus.Main;
import de.hitec.nhplus.nurse.Nurse; 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.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.control.SelectionModel; import javafx.scene.control.SelectionModel;
@ -49,6 +52,8 @@ public class MainWindowController {
@FXML @FXML
private Tab medicationTab; private Tab medicationTab;
@FXML @FXML
private Tab availableMedicationTab;
@FXML
private TabPane medicationTabPane; private TabPane medicationTabPane;
@FXML @FXML
private AnchorPane deprecatedMedicationPage; private AnchorPane deprecatedMedicationPage;
@ -71,7 +76,7 @@ public class MainWindowController {
activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage()); activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage());
lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage()); lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage());
medicationTab.setOnSelectionChanged(event -> loadMedicationPage()); availableMedicationTab.setOnSelectionChanged(event -> loadAvailableMedicationPage());
deprecatedMedicationTab.setOnSelectionChanged(event -> loadDeprecatedMedicationPage()); deprecatedMedicationTab.setOnSelectionChanged(event -> loadDeprecatedMedicationPage());
nurseTabPane.getSelectionModel().select(activeNurseTab); 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() { private void loadPatientPage() {
try { 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() { private void loadTreatmentsPage() {
try { 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() { private void loadNursePage() {
SelectionModel<Tab> selectionModel = nurseTabPane.getSelectionModel(); 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 { try {
BorderPane medicationPane = FXMLLoader.load( BorderPane medicationPane = FXMLLoader.load(
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/medication/AllMedicationView.fxml")) 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(){ private void loadDeprecatedMedicationPage(){
try { try {
BorderPane deprecatedMedicationPane = FXMLLoader.load( 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); deprecatedMedicationPage.getChildren().setAll(deprecatedMedicationPane);
AnchorPane.setTopAnchor(deprecatedMedicationPane, 0d); AnchorPane.setTopAnchor(deprecatedMedicationPane, 0d);

View file

@ -18,6 +18,7 @@ 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.Button;
import javafx.scene.control.SelectionModel; 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;
@ -48,6 +49,8 @@ public class AllMedicationController {
private TableColumn<Medication, String> columnAdministrationMethod; private TableColumn<Medication, String> columnAdministrationMethod;
@FXML @FXML
private TableColumn<Medication, Integer> columnCurrentStock; private TableColumn<Medication, Integer> columnCurrentStock;
@FXML
public Button buttonChangeAvailable;
private final ObservableList<Medication> medications = FXCollections.observableArrayList(); private final ObservableList<Medication> medications = FXCollections.observableArrayList();
private MedicationDao dao; private MedicationDao dao;
@ -57,7 +60,7 @@ public class AllMedicationController {
*/ */
@FXML @FXML
public void initialize() { public void initialize() {
readAllAndShowInTableView(); this.readAllAndShowInTableView();
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id")); this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
this.columnName.setCellValueFactory(new PropertyValueFactory<>("name")); this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
@ -82,6 +85,7 @@ public class AllMedicationController {
this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock")); this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock"));
this.tableView.setItems(this.medications); this.tableView.setItems(this.medications);
} }
/** /**
@ -90,7 +94,7 @@ public class AllMedicationController {
public void readAllAndShowInTableView() { public void readAllAndShowInTableView() {
this.dao = DaoFactory.getInstance().createMedicationDAO(); this.dao = DaoFactory.getInstance().createMedicationDAO();
try { try {
this.medications.setAll(dao.readAll()); this.medications.setAll(dao.readAllAvailable());
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); 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}. * Internal method to create a {@link MedicationModalController MedicationModal}.
* *

View file

@ -6,6 +6,7 @@ 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.scene.control.Button;
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;
@ -31,13 +32,17 @@ public class DeprecatedMedicationController {
private TableColumn<Medication, String> columnAdministrationMethod; private TableColumn<Medication, String> columnAdministrationMethod;
@FXML @FXML
private TableColumn<Medication, Integer> columnCurrentStock; private TableColumn<Medication, Integer> columnCurrentStock;
@FXML
public Button buttonChangeAvailable;
private final ObservableList<Medication> medications = FXCollections.observableArrayList(); private final ObservableList<Medication> medications = FXCollections.observableArrayList();
private MedicationDao dao; private MedicationDao dao;
@FXML /**
* Initialization method that is called after the binding of all the fields.
*/
public void initialize() { public void initialize() {
readAllAndShowInTableView(); this.readAllAndShowInTableView();
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id")); this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
this.columnName.setCellValueFactory(new PropertyValueFactory<>("name")); this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
@ -62,18 +67,35 @@ public class DeprecatedMedicationController {
this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock")); this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock"));
this.tableView.setItems(this.medications); this.tableView.setItems(this.medications);
} }
/** /**
* Internal method to read all data and set it to the table view. * Internal method to read all data and set it to the table view.
*/ */
public void readAllAndShowInTableView() { public void readAllAndShowInTableView() {
this.medications.clear();
this.dao = DaoFactory.getInstance().createMedicationDAO(); this.dao = DaoFactory.getInstance().createMedicationDAO();
try { try {
this.medications.setAll(dao.readAllDeprecated()); this.medications.setAll(this.dao.readAllDeprecated());
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); 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();
}
} }

View file

@ -61,7 +61,7 @@ public class Medication {
String possibleSideEffects, String possibleSideEffects,
String administrationMethod, String administrationMethod,
int currentStock, int currentStock,
boolean isDepreacted boolean isDeprecated
) { ) {
this.id = new SimpleIntegerProperty(id); this.id = new SimpleIntegerProperty(id);
this.name = new SimpleStringProperty(name); this.name = new SimpleStringProperty(name);
@ -70,7 +70,7 @@ public class Medication {
this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects); this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects);
this.administrationMethod = new SimpleStringProperty(administrationMethod); this.administrationMethod = new SimpleStringProperty(administrationMethod);
this.currentStock = new SimpleIntegerProperty(currentStock); this.currentStock = new SimpleIntegerProperty(currentStock);
this.isDeprecated = new SimpleBooleanProperty(isDepreacted); this.isDeprecated = new SimpleBooleanProperty(isDeprecated);
} }
public int getId() { public int getId() {

View file

@ -39,6 +39,7 @@ public class MedicationModalController {
@FXML @FXML
public Button buttonSave; public Button buttonSave;
private Stage stage; private Stage stage;
private Medication medication; private Medication medication;
private final ObservableList<Ingredient> ingredients = FXCollections.observableArrayList(); private final ObservableList<Ingredient> ingredients = FXCollections.observableArrayList();

View file

@ -86,7 +86,6 @@ public class MedicationDao implements Dao<Medication> {
SELECT medication.*, medication_ingredient.name SELECT medication.*, medication_ingredient.name
FROM medication LEFT JOIN FROM medication LEFT JOIN
medication_ingredient ON medication.id = medication_ingredient.id medication_ingredient ON medication.id = medication_ingredient.id
WHERE isDeprecated = false
"""; """;
ResultSet result = connection.prepareStatement(SQL).executeQuery(); ResultSet result = connection.prepareStatement(SQL).executeQuery();
@ -133,8 +132,58 @@ public class MedicationDao implements Dao<Medication> {
final String SQL = """ final String SQL = """
SELECT medication.*, medication_ingredient.name SELECT medication.*, medication_ingredient.name
FROM medication LEFT JOIN FROM medication LEFT JOIN
medication_ingredient ON medication.id = medication_ingredient.id medication_ingredient
WHERE isDeprecated = true 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(); ResultSet result = connection.prepareStatement(SQL).executeQuery();
@ -195,8 +244,8 @@ public class MedicationDao implements Dao<Medication> {
preparedStatement.setString(3, medication.getPossibleSideEffects()); preparedStatement.setString(3, medication.getPossibleSideEffects());
preparedStatement.setString(4, medication.getAdministrationMethod()); preparedStatement.setString(4, medication.getAdministrationMethod());
preparedStatement.setInt(5, medication.getCurrentStock()); preparedStatement.setInt(5, medication.getCurrentStock());
preparedStatement.setInt(6, medication.getId());
preparedStatement.setBoolean(6, medication.isDeprecated()); preparedStatement.setBoolean(6, medication.isDeprecated());
preparedStatement.setInt(7, medication.getId());
preparedStatement.executeUpdate(); preparedStatement.executeUpdate();
final String ingredientDeleteSQL = """ final String ingredientDeleteSQL = """

View file

@ -112,6 +112,4 @@ public class NurseDao extends DaoImp<Nurse> {
statement.setInt(1, id); statement.setInt(1, id);
return statement; return statement;
} }
} }

View file

@ -75,7 +75,7 @@ public class AllTreatmentController {
*/ */
@FXML @FXML
public void initialize() { public void initialize() {
readAllAndShowInTableView();
comboBoxPatientSelection.setItems(patientSelection); comboBoxPatientSelection.setItems(patientSelection);
comboBoxPatientSelection.getSelectionModel().select("alle"); comboBoxPatientSelection.getSelectionModel().select("alle");
@ -109,6 +109,7 @@ public class AllTreatmentController {
); );
this.createComboBoxData(); this.createComboBoxData();
readAllAndShowInTableView();
} }
/** /**

View file

@ -27,7 +27,7 @@
</Tab> </Tab>
<Tab fx:id="medicationTab" text="Medikamente"> <Tab fx:id="medicationTab" text="Medikamente">
<TabPane fx:id="medicationTabPane" tabClosingPolicy="UNAVAILABLE"> <TabPane fx:id="medicationTabPane" tabClosingPolicy="UNAVAILABLE">
<Tab fx:id="allMedicationTab" text="Medikamente"> <Tab fx:id="availableMedicationTab" text="Medikamente">
<AnchorPane fx:id="medicationPage"/> <AnchorPane fx:id="medicationPage"/>
</Tab> </Tab>
<Tab fx:id="deprecatedMedicationTab" text="Veraltete Medikamente"> <Tab fx:id="deprecatedMedicationTab" text="Veraltete Medikamente">

View file

@ -75,6 +75,13 @@
prefWidth="90.0" prefWidth="90.0"
text="Löschen" text="Löschen"
/> />
<Button
fx:id="buttonChangeAvailable"
mnemonicParsing="false"
onAction="#handleChangeAvailable"
prefWidth="155.0"
text="Veraltet-Status ändern"
/>
</HBox> </HBox>
</right> </right>
</BorderPane> </BorderPane>

View file

@ -62,14 +62,13 @@
</BorderPane.margin> </BorderPane.margin>
<right> <right>
<HBox spacing="8.0"> <HBox spacing="8.0">
<!--
<Button <Button
fx:id="buttonDelete" fx:id="buttonChangeAvailable"
mnemonicParsing="false" mnemonicParsing="false"
prefWidth="90.0" prefWidth="155.0"
text="Löschen" onAction="#handleChangeAvailable"
text="Veraltet-Status ändern"
/> />
-->
</HBox> </HBox>
</right> </right>
</BorderPane> </BorderPane>

View file

@ -6,5 +6,5 @@ CREATE TABLE medication
possibleSideEffects TEXT NOT NULL, possibleSideEffects TEXT NOT NULL,
administrationMethod TEXT NOT NULL, administrationMethod TEXT NOT NULL,
currentStock INTEGER NOT NULL, currentStock INTEGER NOT NULL,
isDeprecated BOOLEAN NOT NULL DEFAULT FALSE isDeprecated BOOLEAN NOT NULL DEFAULT false
) )

View file

@ -74,7 +74,6 @@
onAction="#handleDelete" onAction="#handleDelete"
prefWidth="90.0" prefWidth="90.0"
text="Löschen" text="Löschen"
/> />
</HBox> </HBox>
</right> </right>