NOTICKET: Add Medication Module Javadoc
Some checks failed
Quality Check / Linting Check (push) Failing after 15s
Quality Check / Linting Check (pull_request) Failing after 20s
Quality Check / Javadoc Check (push) Successful in 34s
Quality Check / Javadoc Check (pull_request) Successful in 32s

This commit is contained in:
Dominik Säume 2024-05-15 00:27:45 +02:00
parent eeb3630229
commit a5925e3603
Signed by: SZUT-Dominik
GPG key ID: DACB4B96EB59ABA8
4 changed files with 55 additions and 10 deletions

View file

@ -13,6 +13,11 @@ import javafx.scene.control.cell.PropertyValueFactory;
import java.sql.SQLException;
import java.util.stream.Collectors;
/**
* The controller for viewing all {@link Medication}s.
*
* @author Dominik Säume
*/
public class AllMedicationController {
@FXML
private TableView<Medication> tableView;
@ -34,6 +39,10 @@ public class AllMedicationController {
private final ObservableList<Medication> medications = FXCollections.observableArrayList();
private MedicationDao dao;
/**
* Initialization method that is called after the binding of all the fields.
*/
@FXML
public void initialize() {
readAllAndShowInTableView();
@ -41,16 +50,14 @@ public class AllMedicationController {
this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
this.columnManufacturer.setCellValueFactory(new PropertyValueFactory<>("manufacturer"));
this.columnIngredient.setCellValueFactory(
cellData -> {
return new SimpleStringProperty(
cellData -> 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"));
@ -58,6 +65,9 @@ public class AllMedicationController {
this.tableView.setItems(this.medications);
}
/**
* Internal method to read all data and set it to the table view.
*/
public void readAllAndShowInTableView() {
this.dao = DaoFactory.getInstance().createMedicationDAO();
try {

View file

@ -2,6 +2,13 @@ package de.hitec.nhplus.medication;
import javafx.beans.property.SimpleStringProperty;
/**
* The simple model for an {@link Ingredient}.
*
* @author Dominik Säume
* @implSpec This isn't a conventional model, because it isn't directly stored in the database,
* but it can be changed to do that, in the case that its complexity rises in the future.
*/
public class Ingredient {
private final SimpleStringProperty name;

View file

@ -10,6 +10,11 @@ import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;
/**
* The model for a {@link Medication}.
*
* @author Dominik Säume
*/
public class Medication {
private SimpleIntegerProperty id;
private final SimpleStringProperty name;
@ -19,6 +24,13 @@ public class Medication {
private final SimpleStringProperty administrationMethod;
private final SimpleIntegerProperty currentStock;
/**
* This constructor allows instantiating a {@link Medication} object,
* before it is stored in the database, by omitting the {@link Medication#id ID} value.
*
* @implSpec Instances created with this constructor can be directly passed to
* {@link de.hitec.nhplus.medication.database.MedicationDao#create MedicationDao.create}.
*/
public Medication(
String name,
String manufacturer,
@ -35,6 +47,9 @@ public class Medication {
this.currentStock = new SimpleIntegerProperty(currentStock);
}
/**
* This constructor allows instantiating a {@link Medication} object with all existing fields.
*/
public Medication(
int id,
String name,

View file

@ -13,6 +13,12 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The {@link MedicationDao} is an implementation of the {@link de.hitec.nhplus.datastorage.Dao Dao} for the {@link Medication} model.
*
* @author Bernd Heidemann
* @author Dominik Säume
*/
public class MedicationDao implements Dao<Medication> {
protected final Connection connection;
@ -153,6 +159,13 @@ public class MedicationDao implements Dao<Medication> {
preparedStatement.executeUpdate();
}
/**
* Constructs a {@link Medication} object from the {@link ResultSet} obtained after executing a database query.
* This method is used internally to map the {@link ResultSet} data to a {@link Medication} object.
*
* @param result The {@link ResultSet} containing the data retrieved from the database.
* @return A {@link Medication} object constructed from the {@link ResultSet} data.
*/
private Medication getInstanceFromResultSet(ResultSet result) throws SQLException {
Medication medication = new Medication(
result.getInt(1),