#16 story/pfleger-modul-grundimplementierung #20

Merged
SZUT-Dominik merged 2 commits from story/pfleger-modul-grundimplementierung into main 2024-04-29 11:48:20 +00:00
11 changed files with 388 additions and 64 deletions

Binary file not shown.

View file

@ -0,0 +1,59 @@
package de.hitec.nhplus.controller;
import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.datastorage.NurseDao;
import de.hitec.nhplus.model.Nurse;
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 javafx.scene.control.cell.TextFieldTableCell;
import java.sql.SQLException;
public class AllNurseController {
@FXML
private TableView<Nurse> tableView;
@FXML
private TableColumn<Nurse, Long> columnId;
@FXML
private TableColumn<Nurse, String> columnFirstName;
@FXML
private TableColumn<Nurse, String> columnSurname;
@FXML
private TableColumn<Nurse, String> columnPhoneNumber;
private final ObservableList<Nurse> nurses = FXCollections.observableArrayList();
private NurseDao dao;
public void initialize() {
this.readAllAndSHowInTableView();
this.columnId.setCellValueFactory(new PropertyValueFactory<>("nid"));
this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
this.columnFirstName.setCellFactory(TextFieldTableCell.forTableColumn());
this.columnSurname.setCellValueFactory(new PropertyValueFactory<>("surname"));
this.columnSurname.setCellFactory(TextFieldTableCell.forTableColumn());
this.columnPhoneNumber.setCellValueFactory(new PropertyValueFactory<>("phoneNumber"));
this.columnPhoneNumber.setCellFactory(TextFieldTableCell.forTableColumn());
this.tableView.setItems(this.nurses);
}
private void readAllAndSHowInTableView(){
this.nurses.clear();
this.dao = DaoFactory.getDaoFactory().createNurseDAO();
try {
this.nurses.addAll(this.dao.readAll());
}catch (SQLException exception){
exception.printStackTrace();
}
}
}

View file

@ -36,4 +36,14 @@ public class MainWindowController {
exception.printStackTrace();
}
}
@FXML
private void handleShowAllNurses(ActionEvent event){
FXMLLoader loader = new FXMLLoader(Main.class.getResource("/de/hitec/nhplus/AllNurseView.fxml"));
try {
mainBorderPane.setCenter(loader.load());
}catch (IOException exception){
exception.printStackTrace();
}
}
}

View file

@ -21,4 +21,8 @@ public class DaoFactory {
public PatientDao createPatientDAO() {
return new PatientDao(ConnectionBuilder.getConnection());
}
public NurseDao createNurseDAO() {
return new NurseDao(ConnectionBuilder.getConnection());
}
}

View file

@ -0,0 +1,115 @@
package de.hitec.nhplus.datastorage;
import de.hitec.nhplus.model.Nurse;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class NurseDao extends DaoImp<Nurse> {
public NurseDao(Connection connection) {
super(connection);
}
@Override
protected PreparedStatement getCreateStatement(Nurse nurse) {
PreparedStatement preparedStatement = null;
try {
final String SQL = "INSERT INTO nurse (firstname, surname, phoneNumber)" +
"VALUES (?, ?, ?)";
preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setString(1, nurse.getFirstName());
preparedStatement.setString(2, nurse.getSurname());
preparedStatement.setString(3, nurse.getPhoneNumber());
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement;
}
@Override
protected PreparedStatement getReadByIDStatement(long nid) {
PreparedStatement preparedStatement = null;
try {
final String SQL = "SELECT * FROM nurse WHERE nid = ?";
preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setLong(1, nid);
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement;
}
@Override
protected Nurse getInstanceFromResultSet(ResultSet result) throws SQLException {
return new Nurse(
result.getLong(1),
result.getString(2),
result.getString(3),
result.getString(4)
);
}
@Override
protected PreparedStatement getReadAllStatement() {
PreparedStatement statement = null;
try {
final String SQL = "SELECT * FROM nurse";
statement = this.connection.prepareStatement(SQL);
} catch (SQLException exception) {
exception.printStackTrace();
}
return statement;
}
@Override
protected ArrayList<Nurse> getListFromResultSet(ResultSet result) throws SQLException {
ArrayList<Nurse> list = new ArrayList<>();
while (result.next()) {
list.add(new Nurse(
result.getLong(1),
result.getString(2),
result.getString(3),
result.getString(4)
));
}
return list;
}
@Override
protected PreparedStatement getUpdateStatement(Nurse nurse) {
PreparedStatement preparedStatement = null;
try {
final String SQL =
"UPDATE nurse SET " +
"firstname = ?, " +
"surname = ?, " +
"phoneNumber = ?, " +
"WHERE nid = ?";
preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setString(1, nurse.getFirstName());
preparedStatement.setString(2, nurse.getSurname());
preparedStatement.setString(3, nurse.getPhoneNumber());
preparedStatement.setLong(4, nurse.getNid());
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement;
}
@Override
protected PreparedStatement getDeleteStatement(long nid) {
PreparedStatement preparedStatement = null;
try {
final String SQL = "DELETE FROM nurse WHERE nid = ?";
preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setLong(1, nid);
} catch (SQLException exception) {
exception.printStackTrace();
}
return preparedStatement;
}
}

View file

@ -23,6 +23,12 @@ public class Fixtures
treatmentFixture.dropTable(connection);
treatmentFixture.setupTable(connection);
treatmentFixture.load();
NurseFixture nurseFixture = new NurseFixture();
nurseFixture.dropTable(connection);
nurseFixture.setupTable(connection);
nurseFixture.load();
} catch (Exception exception){
System.out.println(exception.getMessage());
}

View file

@ -0,0 +1,65 @@
package de.hitec.nhplus.fixtures;
import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.datastorage.NurseDao;
import de.hitec.nhplus.model.Nurse;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class NurseFixture implements Fixture<Nurse> {
@Override
public void dropTable(Connection connection) {
try (Statement statement = connection.createStatement()) {
statement.execute("DROP TABLE nurse");
} catch (SQLException exception) {
System.out.println(exception.getMessage());
}
}
@Override
public void setupTable(Connection connection) {
final String SQL = "CREATE TABLE IF NOT EXISTS nurse (" +
"tid INTEGER PRIMARY KEY AUTOINCREMENT, " +
"firstname TEXT NOT NULL, " +
"surname TEXT NOT NULL, " +
"phoneNumber TEXT NOT NULL" +
");";
try (Statement statement = connection.createStatement()) {
statement.execute(SQL);
} catch (SQLException exception) {
System.out.println(exception.getMessage());
}
}
@Override
public Map<String, Nurse> load() throws SQLException {
List<Nurse> nurses = new ArrayList<>();
nurses.add(new Nurse(
"Ole",
"Kück",
"0123456789"
));
nurses.add(new Nurse(
"Armin",
"Armout",
"9876543210"
));
NurseDao dao = DaoFactory.getDaoFactory().createNurseDAO();
for(Nurse nurse : nurses){
dao.create(nurse);
}
Map<String, Nurse> nursesByName = new HashMap<>();
for (Nurse nurse : dao.readAll()){
nursesByName.put(nurse.getFirstName(), nurse);
}
return nursesByName;
}
}

View file

@ -0,0 +1,49 @@
package de.hitec.nhplus.model;
import javafx.beans.property.SimpleLongProperty;
import javafx.beans.property.SimpleStringProperty;
public class Nurse extends Person {
private SimpleLongProperty nid;
private final SimpleStringProperty phoneNumber;
public Nurse(
String firstName,
String surname,
String phoneNumber
) {
super(firstName, surname);
this.phoneNumber = new SimpleStringProperty(phoneNumber);
}
public Nurse(
long nid,
String firstName,
String surname,
String phoneNumber
) {
super(firstName, surname);
this.nid = new SimpleLongProperty(nid);
this.phoneNumber = new SimpleStringProperty(phoneNumber);
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber.set(phoneNumber);
}
public long getNid() {
return nid.get();
}
public SimpleLongProperty nidProperty() {
return nid;
}
public String getPhoneNumber() {
return phoneNumber.get();
}
public SimpleStringProperty phoneNumberProperty() {
return phoneNumber;
}
}

View file

@ -1,43 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="500.0" prefWidth="855.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TableView fx:id="tableView" editable="true" layoutX="31.0" layoutY="40.0" AnchorPane.bottomAnchor="70.0" AnchorPane.leftAnchor="15.0" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="80.0">
<columns>
<TableColumn fx:id="colID" maxWidth="1200.0" minWidth="5.0" prefWidth="5.0" text="ID" />
<TableColumn fx:id="colSurname" maxWidth="7500.0" minWidth="20.0" prefWidth="100.0" text="Nachname" />
<TableColumn fx:id="colFirstName" maxWidth="7500.0" prefWidth="75.0" text="Vorname" />
<TableColumn fx:id="colTelephone" maxWidth="7500.0" prefWidth="75.0" text="Telefon" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
<HBox layoutX="420.0" layoutY="450.0" spacing="10.0" AnchorPane.bottomAnchor="15.0" AnchorPane.leftAnchor="15.0" AnchorPane.rightAnchor="15.0">
<children>
<TextField fx:id="txfSurname" prefHeight="26.0" prefWidth="220.0" promptText="Nachname" />
<TextField fx:id="txfFirstname" prefHeight="26.0" prefWidth="220.0" promptText="Vorname" />
<TextField fx:id="txfTelephone" prefWidth="160.0" promptText="Telefonnummer" />
<Button fx:id="btnAdd" mnemonicParsing="false" prefWidth="90.0" text="Hinzufügen" />
<Button fx:id="btnDelete" mnemonicParsing="false" prefWidth="90.0" text="Löschen" />
</children>
</HBox>
<HBox alignment="TOP_CENTER" layoutX="10.0" layoutY="10.0" prefWidth="200.0" spacing="25.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="5.0">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" minWidth="400.0" text="Pfleger/innen" textAlignment="CENTER">
<font>
<Font size="36.0" />
</font>
</Label>
</children>
</HBox>
</children>
<padding>
<Insets top="10.0" />
</padding>
</AnchorPane>

View file

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="500.0" prefWidth="855.0" xmlns="http://javafx.com/javafx/10.0.2-internal"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hitec.nhplus.controller.AllNurseController">
<children>
<TableView fx:id="tableView" editable="true" layoutX="31.0" layoutY="40.0" AnchorPane.bottomAnchor="70.0"
AnchorPane.leftAnchor="15.0" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="80.0">
<columns>
<TableColumn fx:id="columnId" maxWidth="1200.0" minWidth="5.0" prefWidth="5.0" text="ID"/>
<TableColumn fx:id="columnSurname" maxWidth="7500.0" minWidth="20.0" prefWidth="100.0" text="Nachname"/>
<TableColumn fx:id="columnFirstName" maxWidth="7500.0" prefWidth="75.0" text="Vorname"/>
<TableColumn fx:id="columnPhoneNumber" maxWidth="7500.0" prefWidth="75.0" text="Telefonnummer"/>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TableView>
<HBox layoutX="420.0" layoutY="450.0" spacing="10.0" AnchorPane.bottomAnchor="15.0" AnchorPane.leftAnchor="15.0"
AnchorPane.rightAnchor="15.0">
<children>
<TextField fx:id="txfSurname" prefHeight="26.0" prefWidth="220.0" promptText="Nachname"/>
<TextField fx:id="txfFirstname" prefHeight="26.0" prefWidth="220.0" promptText="Vorname"/>
<TextField fx:id="txfPhoneNumber" prefWidth="160.0" promptText="Telefonnummer"/>
<Button fx:id="btnAdd" mnemonicParsing="false" prefWidth="90.0" text="Hinzufügen"/>
<Button fx:id="btnDelete" mnemonicParsing="false" prefWidth="90.0" text="Löschen"/>
</children>
</HBox>
<HBox alignment="TOP_CENTER" layoutX="10.0" layoutY="10.0" prefWidth="200.0" spacing="25.0"
AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="5.0">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" minWidth="400.0" text="Pfleger/innen"
textAlignment="CENTER">
<font>
<Font size="36.0"/>
</font>
</Label>
</children>
</HBox>
</children>
<padding>
<Insets top="10.0"/>
</padding>
</AnchorPane>

View file

@ -1,24 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.*?>
<BorderPane fx:id="mainBorderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="688.0" prefWidth="926.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hitec.nhplus.controller.MainWindowController">
<BorderPane fx:id="mainBorderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
prefHeight="688.0" prefWidth="926.0" xmlns="http://javafx.com/javafx/10.0.2-internal"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hitec.nhplus.controller.MainWindowController">
<left>
<VBox id="vBox" alignment="CENTER" spacing="50.0" styleClass="vBox" stylesheets="@Application.css" BorderPane.alignment="CENTER">
<VBox id="vBox" alignment="CENTER" spacing="50.0" styleClass="vBox" stylesheets="@Application.css"
BorderPane.alignment="CENTER">
<children>
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" onAction="#handleShowAllPatient" prefWidth="105.0" text="Patienten/innen">
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false"
onAction="#handleShowAllPatient" prefWidth="105.0" text="Patienten/innen">
<VBox.margin>
<Insets bottom="50.0" left="10.0" right="10.0" top="50.0" />
<Insets bottom="50.0" left="10.0" right="10.0" top="50.0"/>
</VBox.margin>
<opaqueInsets>
<Insets />
</opaqueInsets></Button>
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" onAction="#handleShowAllTreatments" prefWidth="105.0" text="Behandlungen">
<Insets/>
</opaqueInsets>
</Button>
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false"
onAction="#handleShowAllTreatments" prefWidth="105.0" text="Behandlungen">
<VBox.margin>
<Insets bottom="50.0" left="10.0" right="10.0" top="50.0" />
</VBox.margin></Button>
<Insets bottom="50.0" left="10.0" right="10.0" top="50.0"/>
</VBox.margin>
</Button>
<Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false"
onAction="#handleShowAllNurses" prefWidth="105.0" text="Pfleger/innen">
<VBox.margin>
<Insets bottom="50.0" left="10.0" right="10.0" top="50.0"/>
</VBox.margin>
</Button>
</children>
</VBox>
</left>