#22 story/medikamente-modul-grundimplementierung #34
7 changed files with 213 additions and 43 deletions
|
@ -26,6 +26,10 @@ public class MainWindowController {
|
||||||
private AnchorPane nursePage;
|
private AnchorPane nursePage;
|
||||||
@FXML
|
@FXML
|
||||||
private Tab nurseTab;
|
private Tab nurseTab;
|
||||||
|
@FXML
|
||||||
|
private AnchorPane medicationPage;
|
||||||
|
@FXML
|
||||||
|
private Tab medicationTab;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
@ -35,7 +39,7 @@ public class MainWindowController {
|
||||||
patientTab.setOnSelectionChanged(event -> loadPatientPage());
|
patientTab.setOnSelectionChanged(event -> loadPatientPage());
|
||||||
treatmentTab.setOnSelectionChanged(event -> loadTreatmentsPage());
|
treatmentTab.setOnSelectionChanged(event -> loadTreatmentsPage());
|
||||||
nurseTab.setOnSelectionChanged(event -> loadNursePage());
|
nurseTab.setOnSelectionChanged(event -> loadNursePage());
|
||||||
|
medicationTab.setOnSelectionChanged(event -> loadMedicationPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadPatientPage() {
|
private void loadPatientPage() {
|
||||||
|
@ -82,4 +86,19 @@ public class MainWindowController {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadMedicationPage() {
|
||||||
|
try {
|
||||||
|
BorderPane medicationPane = FXMLLoader.load(
|
||||||
|
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/medication/AllMedicationView.fxml"))
|
||||||
|
);
|
||||||
|
medicationPage.getChildren().setAll(medicationPane);
|
||||||
|
AnchorPane.setTopAnchor(medicationPane, 0d);
|
||||||
|
AnchorPane.setBottomAnchor(medicationPane, 0d);
|
||||||
|
AnchorPane.setLeftAnchor(medicationPane, 0d);
|
||||||
|
AnchorPane.setRightAnchor(medicationPane, 0d);
|
||||||
|
} catch (IOException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
package de.hitec.nhplus.medication;
|
||||||
|
|
||||||
|
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.fxml.FXML;
|
||||||
|
import javafx.scene.control.TableColumn;
|
||||||
|
import javafx.scene.control.TableView;
|
||||||
|
import javafx.scene.control.cell.PropertyValueFactory;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class AllMedicationController {
|
||||||
|
@FXML
|
||||||
|
private TableView<Medication> tableView;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<Medication, Integer> columnId;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<Medication, String> columnName;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<Medication, String> columnManufacturer;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<Medication, String> columnIngredient;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<Medication, String> columnPossibleSideEffects;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<Medication, String> columnAdministrationMethod;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<Medication, Integer> columnCurrentStock;
|
||||||
|
|
||||||
|
private final ObservableList<Medication> medications = FXCollections.observableArrayList();
|
||||||
|
private MedicationDao dao;
|
||||||
|
|
||||||
|
public void initialize() {
|
||||||
|
readAllAndShowInTableView();
|
||||||
|
|
||||||
|
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
|
||||||
|
this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
|
||||||
|
this.columnManufacturer.setCellValueFactory(new PropertyValueFactory<>("manufacturer"));
|
||||||
|
this.columnIngredient.setCellValueFactory(
|
||||||
|
cellData -> {
|
||||||
|
return 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"));
|
||||||
|
|
||||||
|
this.tableView.setItems(this.medications);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readAllAndShowInTableView() {
|
||||||
|
this.dao = DaoFactory.getInstance().createMedicationDAO();
|
||||||
|
try {
|
||||||
|
this.medications.setAll(dao.readAll());
|
||||||
|
} catch (SQLException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -64,24 +64,42 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
@Override
|
@Override
|
||||||
public List<Medication> readAll() throws SQLException {
|
public List<Medication> readAll() throws SQLException {
|
||||||
final String SQL = """
|
final String SQL = """
|
||||||
SELECT medication.*, medication_ingredient.id
|
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
|
||||||
""";
|
""";
|
||||||
ResultSet result = connection.prepareStatement(SQL).executeQuery();
|
ResultSet result = connection.prepareStatement(SQL).executeQuery();
|
||||||
Map<Integer, List<ResultSet>> resultSetMap = new HashMap<>();
|
|
||||||
|
|
||||||
while (result.next()) {
|
|
||||||
List<ResultSet> resultSetList = resultSetMap.computeIfAbsent(result.getInt(0), k -> new ArrayList<>());
|
|
||||||
resultSetList.add(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Medication> medications = new ArrayList<>();
|
List<Medication> medications = new ArrayList<>();
|
||||||
for (Map.Entry<Integer, List<ResultSet>> entry : resultSetMap.entrySet()) {
|
Map<Integer, List<Ingredient>> ingredientMap = new HashMap<>();
|
||||||
medications.add(getInstanceFromResultSet(this.mergeResultSets(entry.getValue())));
|
|
||||||
}
|
|
||||||
return medications;
|
|
||||||
|
|
||||||
|
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),
|
||||||
|
List.of(),
|
||||||
|
result.getString(4),
|
||||||
|
result.getString(5),
|
||||||
|
result.getInt(6)
|
||||||
|
);
|
||||||
|
medications.add(medication);
|
||||||
|
lastMedicationId = currentMedicationId;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
List<Ingredient> ingredients = ingredientMap.computeIfAbsent(currentMedicationId, k -> new ArrayList<>());
|
||||||
|
ingredients.add(new Ingredient(result.getString(7)));
|
||||||
|
lastMedicationId = currentMedicationId;
|
||||||
|
}
|
||||||
|
for (Medication medication : medications) {
|
||||||
|
medication.setIngredients(ingredientMap.get(medication.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return medications;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -120,7 +138,7 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
result.getInt(1),
|
result.getInt(1),
|
||||||
result.getString(2),
|
result.getString(2),
|
||||||
result.getString(3),
|
result.getString(3),
|
||||||
null,
|
List.of(),
|
||||||
result.getString(4),
|
result.getString(4),
|
||||||
result.getString(5),
|
result.getString(5),
|
||||||
result.getInt(6)
|
result.getInt(6)
|
||||||
|
@ -134,28 +152,4 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
medication.setIngredients(ingredients);
|
medication.setIngredients(ingredients);
|
||||||
return medication;
|
return medication;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Merges a List of ResultSets to one for further use.
|
|
||||||
*
|
|
||||||
* @param resultSetList the {@link List} of {@link ResultSet} to merge
|
|
||||||
* @return merged {@link ResultSet}
|
|
||||||
*/
|
|
||||||
private ResultSet mergeResultSets(List<ResultSet> resultSetList) throws SQLException {
|
|
||||||
ResultSetMetaData metaData = resultSetList.get(0).getMetaData();
|
|
||||||
CachedRowSet cachedRowSet = RowSetProvider.newFactory().createCachedRowSet();
|
|
||||||
cachedRowSet.populate(resultSetList.get(0));
|
|
||||||
for (int i = 1; i < resultSetList.size(); i++) {
|
|
||||||
ResultSet resultSet = resultSetList.get(i);
|
|
||||||
while (resultSet.next()) {
|
|
||||||
cachedRowSet.moveToInsertRow();
|
|
||||||
for (int j = 1; j <= metaData.getColumnCount(); j++) {
|
|
||||||
cachedRowSet.updateObject(j, resultSet.getObject(j));
|
|
||||||
}
|
|
||||||
cachedRowSet.insertRow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cachedRowSet.moveToCurrentRow();
|
|
||||||
return cachedRowSet;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,4 +24,9 @@ module de.hitec.nhplus {
|
||||||
exports de.hitec.nhplus.nurse.database;
|
exports de.hitec.nhplus.nurse.database;
|
||||||
opens de.hitec.nhplus.nurse to javafx.base, javafx.fxml;
|
opens de.hitec.nhplus.nurse to javafx.base, javafx.fxml;
|
||||||
opens de.hitec.nhplus.nurse.database to javafx.base, javafx.fxml;
|
opens de.hitec.nhplus.nurse.database to javafx.base, javafx.fxml;
|
||||||
|
|
||||||
|
exports de.hitec.nhplus.medication;
|
||||||
|
exports de.hitec.nhplus.medication.database;
|
||||||
|
opens de.hitec.nhplus.medication to javafx.base, javafx.fxml;
|
||||||
|
opens de.hitec.nhplus.medication.database to javafx.base, javafx.fxml;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.scene.control.Tab?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.control.TabPane?>
|
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
<TabPane
|
<TabPane
|
||||||
fx:id="mainTabPane"
|
fx:id="mainTabPane"
|
||||||
|
@ -19,4 +18,7 @@
|
||||||
<Tab fx:id="nurseTab" text="Pfleger">
|
<Tab fx:id="nurseTab" text="Pfleger">
|
||||||
<AnchorPane fx:id="nursePage"/>
|
<AnchorPane fx:id="nursePage"/>
|
||||||
</Tab>
|
</Tab>
|
||||||
|
<Tab fx:id="medicationTab" text="Medikamente">
|
||||||
|
<AnchorPane fx:id="medicationPage"/>
|
||||||
|
</Tab>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.BorderPane?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
<BorderPane xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
fx:controller="de.hitec.nhplus.medication.AllMedicationController"
|
||||||
|
>
|
||||||
|
<padding>
|
||||||
|
<Insets top="8" left="8" right="8" bottom="8"/>
|
||||||
|
</padding>
|
||||||
|
<center>
|
||||||
|
<TableView fx:id="tableView">
|
||||||
|
<columns>
|
||||||
|
<TableColumn
|
||||||
|
fx:id="columnId"
|
||||||
|
minWidth="40.0"
|
||||||
|
text="ID"
|
||||||
|
/>
|
||||||
|
<TableColumn
|
||||||
|
fx:id="columnName"
|
||||||
|
minWidth="140.0"
|
||||||
|
text="Name"
|
||||||
|
/>
|
||||||
|
<TableColumn
|
||||||
|
fx:id="columnManufacturer"
|
||||||
|
minWidth="140.0"
|
||||||
|
text="Hersteller"
|
||||||
|
/>
|
||||||
|
<TableColumn
|
||||||
|
fx:id="columnIngredient"
|
||||||
|
minWidth="140.0"
|
||||||
|
text="Inhaltsstoffe"
|
||||||
|
/>
|
||||||
|
<TableColumn
|
||||||
|
fx:id="columnPossibleSideEffects"
|
||||||
|
minWidth="200.0"
|
||||||
|
text="Mögliche Nebenwirkungen"
|
||||||
|
/>
|
||||||
|
<TableColumn
|
||||||
|
fx:id="columnAdministrationMethod"
|
||||||
|
minWidth="180.0"
|
||||||
|
text="Verabreichungsmethode"
|
||||||
|
/>
|
||||||
|
<TableColumn
|
||||||
|
fx:id="columnCurrentStock"
|
||||||
|
minWidth="100.0"
|
||||||
|
text="Lagerbestand"
|
||||||
|
/>
|
||||||
|
</columns>
|
||||||
|
<columnResizePolicy>
|
||||||
|
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
|
||||||
|
</columnResizePolicy>
|
||||||
|
</TableView>
|
||||||
|
</center>
|
||||||
|
<bottom>
|
||||||
|
<BorderPane>
|
||||||
|
<BorderPane.margin>
|
||||||
|
<Insets top="8.0"/>
|
||||||
|
</BorderPane.margin>
|
||||||
|
<right>
|
||||||
|
<HBox spacing="8.0">
|
||||||
|
<Button
|
||||||
|
fx:id="buttonAdd"
|
||||||
|
mnemonicParsing="false"
|
||||||
|
prefWidth="90.0"
|
||||||
|
text="Hinzufügen"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
fx:id="buttonDelete"
|
||||||
|
mnemonicParsing="false"
|
||||||
|
prefWidth="90.0"
|
||||||
|
text="Löschen"
|
||||||
|
/>
|
||||||
|
</HBox>
|
||||||
|
</right>
|
||||||
|
</BorderPane>
|
||||||
|
</bottom>
|
||||||
|
</BorderPane>
|
|
@ -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" editable="true" layoutX="31.0" layoutY="40.0">
|
<TableView fx:id="tableView" editable="true">
|
||||||
<columns>
|
<columns>
|
||||||
<TableColumn
|
<TableColumn
|
||||||
fx:id="columnId"
|
fx:id="columnId"
|
||||||
|
|
Loading…
Reference in a new issue