Compare commits

..

No commits in common. "6908e8129bdddb8a11f0bd651a54435cf7b679c0" and "192c14eb0dced7877c276cfdc7efdafe44b1272f" have entirely different histories.

11 changed files with 25 additions and 420 deletions

Binary file not shown.

View file

@ -46,14 +46,6 @@ public class NurseFixture implements Fixture<Nurse> {
"Armout",
"9876543210"
));
nurses.add(new Nurse(
"Björnd",
"Heideberger",
"69420",
true
));
NurseDao dao = DaoFactory.getInstance().createNurseDAO();
for (Nurse nurse : nurses) {
dao.create(nurse);

View file

@ -1,10 +1,8 @@
package de.hitec.nhplus.main;
import de.hitec.nhplus.Main;
import de.hitec.nhplus.nurse.Nurse;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.SelectionModel;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.AnchorPane;
@ -18,8 +16,6 @@ import java.util.Objects;
*
* @author Bernd Heidemann
* @author Dominik Säume
* @author Armin Ribic
* @author Dorian Nemec
*/
public class MainWindowController {
@FXML
@ -33,25 +29,14 @@ public class MainWindowController {
@FXML
private Tab treatmentTab;
@FXML
private AnchorPane nursePage;
@FXML
private Tab nurseTab;
@FXML
private TabPane nurseTabPane;
@FXML
private AnchorPane activeNursePage;
@FXML
private Tab activeNurseTab;
@FXML
private AnchorPane lockedNursePage;
@FXML
private Tab lockedNurseTab;
@FXML
private AnchorPane medicationPage;
@FXML
private Tab medicationTab;
/**
* Initialization method that is called after the binding of all the fields.
*/
@FXML
public void initialize() {
loadPatientPage();
@ -61,12 +46,6 @@ public class MainWindowController {
treatmentTab.setOnSelectionChanged(event -> loadTreatmentsPage());
nurseTab.setOnSelectionChanged(event -> loadNursePage());
medicationTab.setOnSelectionChanged(event -> loadMedicationPage());
nurseTabPane.getSelectionModel().select(activeNurseTab);
activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage());
lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage());
}
/**
@ -88,7 +67,7 @@ public class MainWindowController {
}
/**
* Loads the {@link } page into its tab.
* Loads the treatment page into its tab.
*/
private void loadTreatmentsPage() {
try {
@ -109,47 +88,15 @@ public class MainWindowController {
* Loads the nurse page into its tab.
*/
private void loadNursePage() {
SelectionModel<Tab> selectionModel = nurseTabPane.getSelectionModel();
Tab selectedTab = selectionModel.getSelectedItem();
if(selectedTab == activeNurseTab){
loadActiveNursePage();
}
if(selectedTab == lockedNurseTab){
loadLockedNursePage();
}
}
/**
* Loads the active {@link Nurse} page into its tab.
*/
private void loadActiveNursePage() {
try {
BorderPane activeNursePane = FXMLLoader.load(
BorderPane nursePane = FXMLLoader.load(
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/nurse/AllNurseView.fxml"))
);
activeNursePage.getChildren().setAll(activeNursePane);
AnchorPane.setTopAnchor(activeNursePane, 0d);
AnchorPane.setBottomAnchor(activeNursePane, 0d);
AnchorPane.setLeftAnchor(activeNursePane, 0d);
AnchorPane.setRightAnchor(activeNursePane, 0d);
} catch (IOException exception) {
exception.printStackTrace();
}
}
/**
* Loads the locked {@link Nurse} page into its tab.
*/
private void loadLockedNursePage() {
try {
BorderPane lockedNursePane = FXMLLoader.load(
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/nurse/LockedNurseView.fxml"))
);
lockedNursePage.getChildren().setAll(lockedNursePane);
AnchorPane.setTopAnchor(lockedNursePane, 0d);
AnchorPane.setBottomAnchor(lockedNursePane, 0d);
AnchorPane.setLeftAnchor(lockedNursePane, 0d);
AnchorPane.setRightAnchor(lockedNursePane, 0d);
nursePage.getChildren().setAll(nursePane);
AnchorPane.setTopAnchor(nursePane, 0d);
AnchorPane.setBottomAnchor(nursePane, 0d);
AnchorPane.setLeftAnchor(nursePane, 0d);
AnchorPane.setRightAnchor(nursePane, 0d);
} catch (IOException exception) {
exception.printStackTrace();
}

View file

@ -33,8 +33,6 @@ public class AllNurseController {
@FXML
public Button buttonAdd;
@FXML
public Button buttonLock;
@FXML
private TableView<Nurse> tableView;
@FXML
private TableColumn<Nurse, Long> columnId;
@ -91,7 +89,7 @@ public class AllNurseController {
this.nurses.clear();
this.dao = DaoFactory.getInstance().createNurseDAO();
try {
this.nurses.setAll(this.dao.readAllActive());
this.nurses.setAll(this.dao.readAll());
}catch (SQLException exception){
exception.printStackTrace();
}
@ -121,20 +119,5 @@ public class AllNurseController {
clearTextfields();
}
@FXML
public void handleLock(){
Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem();
if (selectedItem == null){
return;
}
try {
selectedItem.setLocked(true);
this.dao.update(selectedItem);
}catch (SQLException exception){
exception.printStackTrace();
}
readAllAndShowInTableView();
}
}

View file

@ -1,136 +0,0 @@
package de.hitec.nhplus.nurse;
import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.nurse.database.NurseDao;
import de.hitec.nhplus.treatment.Treatment;
import de.hitec.nhplus.treatment.database.TreatmentDao;
import de.hitec.nhplus.utils.DateConverter;
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;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Controller for all locked nurses.
* @author Armin Ribic
* @author Dorian Nemec
*/
public class LockedNurseController {
@FXML
public Button buttonDelete;
@FXML
private Button buttonUnlock;
@FXML
public TableView<Nurse> tableView;
@FXML
public TableColumn<Nurse, Long> columnId;
@FXML
public TableColumn<Nurse, String> columnFirstName;
@FXML
public TableColumn<Nurse, String> columnSurName;
@FXML
public TableColumn<Nurse, String> columnPhoneNumber;
@FXML
public TableColumn<Nurse, String> columnDeleteDate;
private final ObservableList<Nurse> nurses = FXCollections.observableArrayList();
private final Map<Nurse, List<Treatment>> treatmentsPerNurse = new HashMap<>();
private NurseDao dao;
private TreatmentDao treatmentDao;
/**
* This method allows initializing a {@link LockedNurseController} object
* that is called after the binding of all the fields.
*/
public void initialize() {
this.readAllAndShowInTableView();
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
this.columnSurName.setCellValueFactory(new PropertyValueFactory<>("surName"));
this.columnPhoneNumber.setCellValueFactory(new PropertyValueFactory<>("phoneNumber"));
this.columnDeleteDate.setCellValueFactory(cellData -> new SimpleStringProperty(
DateConverter.convertLocalDateToString(cellData.getValue().calculateDeleteDate()))
);
buttonDelete.setDisable(true);
this.tableView.setItems(this.nurses);
}
/**
* Reads all locked {@link Nurse} data and shows it in the table.
*/
private void readAllAndShowInTableView() {
this.nurses.clear();
this.treatmentsPerNurse.clear();
this.dao = DaoFactory.getInstance().createNurseDAO();
this.treatmentDao = DaoFactory.getInstance().createTreatmentDao();
try {
this.nurses.addAll(this.dao.readAllLocked());
this.nurses.forEach(
nurse -> {
try {
this.treatmentsPerNurse.put(nurse, this.treatmentDao.readTreatmentsByNurse(nurse.getId()));
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
);
} catch (SQLException exception) {
exception.printStackTrace();
}
}
@FXML
public void handleDelete() {
Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem();
if (selectedItem == null) {
return;
}
try {
this.dao.delete(selectedItem.getId());
} catch (SQLException exception) {
exception.printStackTrace();
}
readAllAndShowInTableView();
}
@FXML
public void handleMouseClick() {
Nurse nurse = tableView.getSelectionModel().getSelectedItem();
boolean canBeDeleted = nurse.calculateDeleteDate().isBefore(LocalDate.now());
buttonDelete.setDisable(!canBeDeleted);
}
@FXML
public void unlockNurse() {
Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem();
if (selectedItem == null) {
return;
}
try {
selectedItem.setLocked(false);
this.dao.update(selectedItem);
} catch (SQLException exception) {
exception.printStackTrace();
}
readAllAndShowInTableView();
}
}

View file

@ -1,36 +1,26 @@
package de.hitec.nhplus.nurse;
import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.main.Person;
import de.hitec.nhplus.treatment.Treatment;
import de.hitec.nhplus.utils.DateConverter;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.StringJoiner;
/**
* The model for a {@link Nurse}.
*
* @author Dominik Säume
* @author Armin Ribic
* @author Dorian Nemec
*/
public class Nurse extends Person {
private SimpleIntegerProperty id;
private final SimpleStringProperty phoneNumber;
private final SimpleBooleanProperty locked;
/**
* This constructor allows instantiating a {@link Nurse} object,
* before it is stored in the database, by omitting the {@link Nurse#id ID} value.
* It includes the locked Property.
* @implSpec This was added for usage in the {@link de.hitec.nhplus.fixtures.NurseFixture NurseFixture}.
*
* @implSpec Instances created with this constructor can be directly passed to
* {@link de.hitec.nhplus.nurse.database.NurseDao#create NurseDao.create}.
*/
public Nurse(
String firstName,
@ -39,22 +29,6 @@ public class Nurse extends Person {
) {
super(firstName, surName);
this.phoneNumber = new SimpleStringProperty(phoneNumber);
this.locked = new SimpleBooleanProperty(false);
}
/**
* This constructor allows instantiating a {@link Nurse} object with
* specifying if the nurse is locked or not.
*/
public Nurse(
String firstName,
String surName,
String phoneNumber,
Boolean isLocked
) {
super(firstName, surName);
this.phoneNumber = new SimpleStringProperty(phoneNumber);
this.locked = new SimpleBooleanProperty(isLocked);
}
/**
@ -64,38 +38,11 @@ public class Nurse extends Person {
int id,
String firstName,
String surName,
String phoneNumber,
Boolean isLocked
String phoneNumber
) {
super(firstName, surName);
this.id = new SimpleIntegerProperty(id);
this.phoneNumber = new SimpleStringProperty(phoneNumber);
this.locked = new SimpleBooleanProperty(isLocked);
}
/**
* Calculates the date when the {@link Nurse} can be deleted.
*/
public LocalDate calculateDeleteDate() {
List<Treatment> treatments;
try {
treatments = DaoFactory.getInstance().createTreatmentDao().readTreatmentsByNurse(this.getId());
}catch (SQLException exception){
treatments = null;
}
if(treatments == null){
return LocalDate.now().plusDays(1);
}
LocalDate newestDate = LocalDate.of(1980, 1, 1);
for (Treatment treatment : treatments) {
LocalDate date = DateConverter.convertStringToLocalDate(treatment.getDate());
if (date.isAfter(newestDate)) {
newestDate = date;
}
}
return newestDate.plusYears(10);
}
public void setPhoneNumber(String phoneNumber) {
@ -118,19 +65,6 @@ public class Nurse extends Person {
return phoneNumber;
}
public boolean isLocked() {
return locked.get();
}
public SimpleBooleanProperty lockedProperty() {
return locked;
}
public void setLocked(boolean locked) {
this.locked.set(locked);
}
@Override
public String toString() {
return new StringJoiner(System.lineSeparator())
@ -139,7 +73,6 @@ public class Nurse extends Person {
.add("FirstName: " + this.getFirstName())
.add("SurName: " + this.getSurName())
.add("PhoneNumber: " + this.getPhoneNumber())
.add("IsLocked: " + this.isLocked())
.toString();
}

View file

@ -17,7 +17,6 @@ import java.util.List;
* @author Dominik Säume
*/
public class NurseDao extends DaoImp<Nurse> {
public NurseDao(Connection connection) {
super(connection);
}
@ -26,14 +25,13 @@ public class NurseDao extends DaoImp<Nurse> {
protected PreparedStatement getCreateStatement(Nurse nurse) throws SQLException {
final String SQL = """
INSERT INTO nurse
(firstName, surName, phoneNumber, isLocked)
VALUES (?, ?, ?, ?)
(firstName, surName, phoneNumber)
VALUES (?, ?, ?)
""";
PreparedStatement statement = this.connection.prepareStatement(SQL);
statement.setString(1, nurse.getFirstName());
statement.setString(2, nurse.getSurName());
statement.setString(3, nurse.getPhoneNumber());
statement.setBoolean(4, nurse.isLocked());
return statement;
}
@ -51,8 +49,7 @@ public class NurseDao extends DaoImp<Nurse> {
result.getInt(1),
result.getString(2),
result.getString(3),
result.getString(4),
result.getBoolean(5)
result.getString(4)
);
}
@ -61,6 +58,7 @@ public class NurseDao extends DaoImp<Nurse> {
final String SQL = "SELECT * FROM nurse";
return this.connection.prepareStatement(SQL);
}
@Override
protected List<Nurse> getListFromResultSet(ResultSet result) throws SQLException {
ArrayList<Nurse> list = new ArrayList<>();
@ -70,38 +68,20 @@ public class NurseDao extends DaoImp<Nurse> {
return list;
}
/**
* Read all database entries of active {@link Nurse}s into a {@link List} of model instances.
*/
public List<Nurse> readAllActive() throws SQLException {
final String SQL = "SELECT * FROM nurse WHERE isLocked=false";
return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
}
/**
* Read all database entries of locked {@link Nurse}s into a {@link List} of model instances.
*/
public List<Nurse> readAllLocked() throws SQLException {
final String SQL = "SELECT * FROM nurse WHERE isLocked=true";
return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
}
@Override
@Override
protected PreparedStatement getUpdateStatement(Nurse nurse) throws SQLException {
final String SQL = """
UPDATE nurse SET
firstName = ?,
surName = ?,
phoneNumber = ?,
isLocked = ?
phoneNumber = ?
WHERE id = ?
""";
PreparedStatement statement = this.connection.prepareStatement(SQL);
statement.setString(1, nurse.getFirstName());
statement.setString(2, nurse.getSurName());
statement.setString(3, nurse.getPhoneNumber());
statement.setBoolean(4, nurse.isLocked());
statement.setInt(5, nurse.getId());
statement.setInt(4, nurse.getId());
return statement;
}
@ -112,6 +92,4 @@ public class NurseDao extends DaoImp<Nurse> {
statement.setInt(1, id);
return statement;
}
}

View file

@ -16,14 +16,7 @@
<AnchorPane fx:id="treatmentPage"/>
</Tab>
<Tab fx:id="nurseTab" text="Pfleger">
<TabPane fx:id="nurseTabPane" tabClosingPolicy="UNAVAILABLE">
<Tab fx:id="activeNurseTab" text="Pfleger">
<AnchorPane fx:id="activeNursePage"/>
</Tab>
<Tab fx:id="lockedNurseTab" text="Gesperrte Pfleger">
<AnchorPane fx:id="lockedNursePage"/>
</Tab>
</TabPane>
<AnchorPane fx:id="nursePage"/>
</Tab>
<Tab fx:id="medicationTab" text="Medikamente">
<AnchorPane fx:id="medicationPage"/>

View file

@ -77,11 +77,10 @@
text="Hinzufügen"
/>
<Button
fx:id="buttonLock"
fx:id="buttonDelete"
mnemonicParsing="false"
onAction="#handleLock"
prefWidth="90.0"
text="Sperren"
text="Löschen"
/>
</HBox>
</right>

View file

@ -1,83 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="de.hitec.nhplus.nurse.LockedNurseController"
>
<padding>
<Insets top="8" left="8" right="8" bottom="8"/>
</padding>
<center>
<TableView fx:id="tableView" layoutX="31.0" layoutY="40" onMouseClicked="#handleMouseClick" >
<columns>
<TableColumn
fx:id="columnId"
minWidth="40.0"
text="ID"
/>
<TableColumn
fx:id="columnSurName"
minWidth="140.0"
text="Nachname"
/>
<TableColumn
fx:id="columnFirstName"
minWidth="140.0"
text="Vorname"
/>
<TableColumn
fx:id="columnPhoneNumber"
minWidth="140.0"
text="Telefonnummer"
/>
<TableColumn
fx:id="columnDeleteDate"
minWidth="140.0"
text="Löschen ab"
/>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TableView>
</center>
<bottom>
<BorderPane>
<BorderPane.margin>
<Insets top="8.0"/>
</BorderPane.margin>
<center>
<HBox spacing="8.0">
<padding>
<Insets right="8.0"/>
</padding>
</HBox>
</center>
<right>
<HBox>
<spacing>8.0</spacing>
<Button
fx:id="buttonUnlock"
mnemonicParsing="false"
onAction="#unlockNurse"
prefWidth="90.0"
text="Entsperren"
/>
<Button
fx:id="buttonDelete"
mnemonicParsing="false"
onAction="#handleDelete"
prefWidth="90.0"
text="Löschen"
/>
</HBox>
</right>
</BorderPane>
</bottom>
</BorderPane>

View file

@ -3,6 +3,5 @@ CREATE TABLE nurse
id INTEGER PRIMARY KEY AUTOINCREMENT,
firstName TEXT NOT NULL,
surName TEXT NOT NULL,
phoneNumber TEXT NOT NULL,
isLocked BOOLEAN NOT NULL DEFAULT false
phoneNumber TEXT NOT NULL
)