Compare commits

...

3 commits

Author SHA1 Message Date
1827e8caf6
#32: Make Consistent Naming
All checks were successful
Quality Check / Qualty Check (push) Successful in 8s
Quality Check / Qualty Check (pull_request) Successful in 8s
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
2024-05-06 10:03:59 +02:00
afe306a364
#32: use Constants & Multiline Strings
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
2024-05-06 09:06:13 +02:00
77b38ef159
#32: Move Schemas to Resources
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
2024-05-06 08:52:31 +02:00
28 changed files with 391 additions and 320 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true"> <component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="nursingHome.db" uuid="5a5b8be1-080b-4129-b89d-42f1ea832b90"> <data-source source="LOCAL" name="Database" uuid="5a5b8be1-080b-4129-b89d-42f1ea832b90">
<driver-ref>sqlite.xerial</driver-ref> <driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize> <synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver> <jdbc-driver>org.sqlite.JDBC</jdbc-driver>

35
.idea/sqlDataSources.xml Normal file
View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DdlMappings">
<mapping uuid="6de31afe-6f51-4d57-ac29-b95200cc6a68" name="Database Mapping">
<data-sources db="5a5b8be1-080b-4129-b89d-42f1ea832b90" ddl="82842a6c-e549-4bc0-9743-9bdb8b472dfc" />
<scope>
<node negative="1">
<node kind="database" negative="1">
<node kind="schema" negative="1" />
</node>
<node kind="schema" qname="main" />
</node>
</scope>
</mapping>
</component>
<component name="SqlDataSourceStorage">
<option name="dataSources">
<list>
<State>
<option name="id" value="82842a6c-e549-4bc0-9743-9bdb8b472dfc" />
<option name="name" value="NHPlus DDL" />
<option name="dbmsName" value="SQLITE" />
<option name="urls">
<array>
<option value="file://$PROJECT_DIR$/src/main/resources/de/hitec/nhplus/patient/database/Patient.sql" />
<option value="file://$PROJECT_DIR$/src/main/resources/de/hitec/nhplus/treatment/database/Treatment.sql" />
<option value="file://$PROJECT_DIR$/src/main/resources/de/hitec/nhplus/nurse/database/Nurse.sql" />
</array>
</option>
<option name="outLayout" value="File per object by schema.groovy" />
</State>
</list>
</option>
</component>
</project>

View file

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="SqlDialectMappings"> <component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/src/main/java/de/hitec/nhplus/patient/PatientDao.java" dialect="GenericSQL" /> <file url="file://$PROJECT_DIR$/src/main/java/de/hitec/nhplus/patient/database/PatientDao.java" dialect="GenericSQL" />
<file url="file://$PROJECT_DIR$/src/main/java/de/hitec/nhplus/treatment/TreatmentDao.java" dialect="GenericSQL" /> <file url="file://$PROJECT_DIR$/src/main/java/de/hitec/nhplus/treatment/database/TreatmentDao.java" dialect="GenericSQL" />
<file url="file://$PROJECT_DIR$/src/main/java/de/hitec/nhplus/treatment/database/NurseDao.java" dialect="GenericSQL" />
<file url="PROJECT" dialect="SQLite" /> <file url="PROJECT" dialect="SQLite" />
</component> </component>
</project> </project>

Binary file not shown.

View file

@ -1,8 +1,8 @@
package de.hitec.nhplus.datastorage; package de.hitec.nhplus.datastorage;
import de.hitec.nhplus.nurse.NurseDao; import de.hitec.nhplus.nurse.database.NurseDao;
import de.hitec.nhplus.patient.PatientDao; import de.hitec.nhplus.patient.database.PatientDao;
import de.hitec.nhplus.treatment.TreatmentDao; import de.hitec.nhplus.treatment.database.TreatmentDao;
public class DaoFactory { public class DaoFactory {

View file

@ -6,7 +6,7 @@ import java.util.Map;
public interface Fixture<T> public interface Fixture<T>
{ {
void dropTable(Connection connection); void dropTable(Connection connection) throws SQLException;
void setupTable(Connection connection); void setupTable(Connection connection) throws SQLException;
Map<String, T> load() throws SQLException; Map<String, T> load() throws SQLException;
} }

View file

@ -1,40 +1,28 @@
package de.hitec.nhplus.fixtures; package de.hitec.nhplus.fixtures;
import de.hitec.nhplus.Main;
import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.nurse.NurseDao;
import de.hitec.nhplus.nurse.Nurse; import de.hitec.nhplus.nurse.Nurse;
import de.hitec.nhplus.nurse.database.NurseDao;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class NurseFixture implements Fixture<Nurse> { public class NurseFixture implements Fixture<Nurse> {
@Override @Override
public void dropTable(Connection connection) { public void dropTable(Connection connection) throws SQLException {
try (Statement statement = connection.createStatement()) { connection.createStatement().execute("DROP TABLE nurse");
statement.execute("DROP TABLE nurse");
} catch (SQLException exception) {
System.out.println(exception.getMessage());
}
} }
@Override @Override
public void setupTable(Connection connection) { public void setupTable(Connection connection) throws SQLException {
final String SQL = "CREATE TABLE IF NOT EXISTS nurse (" + final InputStream schema = Main.class.getResourceAsStream("/de/hitec/nhplus/nurse/database/Nurse.sql");
"id INTEGER PRIMARY KEY AUTOINCREMENT, " + assert schema != null;
"firstname TEXT NOT NULL, " + final String SQL = new Scanner(schema, StandardCharsets.UTF_8).useDelimiter("\\A").next();
"surname TEXT NOT NULL, " + connection.createStatement().execute(SQL);
"phoneNumber TEXT NOT NULL" +
");";
try (Statement statement = connection.createStatement()) {
statement.execute(SQL);
} catch (SQLException exception) {
System.out.println(exception.getMessage());
}
} }
@Override @Override
@ -53,11 +41,11 @@ public class NurseFixture implements Fixture<Nurse> {
"9876543210" "9876543210"
)); ));
NurseDao dao = DaoFactory.getInstance().createNurseDAO(); NurseDao dao = DaoFactory.getInstance().createNurseDAO();
for(Nurse nurse : nurses){ for (Nurse nurse : nurses) {
dao.create(nurse); dao.create(nurse);
} }
Map<String, Nurse> nursesByName = new HashMap<>(); Map<String, Nurse> nursesByName = new HashMap<>();
for (Nurse nurse : dao.readAll()){ for (Nurse nurse : dao.readAll()) {
nursesByName.put(nurse.getFirstName(), nurse); nursesByName.put(nurse.getFirstName(), nurse);
} }
return nursesByName; return nursesByName;

View file

@ -1,107 +1,86 @@
package de.hitec.nhplus.fixtures; package de.hitec.nhplus.fixtures;
import de.hitec.nhplus.Main;
import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.patient.PatientDao;
import de.hitec.nhplus.patient.Patient; import de.hitec.nhplus.patient.Patient;
import de.hitec.nhplus.patient.database.PatientDao;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalDate; import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalDate;
public class PatientFixture implements Fixture<Patient> public class PatientFixture implements Fixture<Patient> {
{
@Override @Override
public void dropTable(Connection connection) public void dropTable(Connection connection) throws SQLException {
{ connection.createStatement().execute("DROP TABLE patient");
try (Statement statement = connection.createStatement())
{
statement.execute("DROP TABLE patient");
} catch (SQLException exception)
{
System.out.println(exception.getMessage());
}
} }
@Override @Override
public void setupTable(Connection connection) public void setupTable(Connection connection) throws SQLException {
{ // @SuppressWarnings("checkstyle:LineLength")
final String SQL = "CREATE TABLE IF NOT EXISTS patient (" + final InputStream schema = Main.class.getResourceAsStream("/de/hitec/nhplus/patient/database/Patient.sql");
" id INTEGER PRIMARY KEY AUTOINCREMENT, " + assert schema != null;
" firstname TEXT NOT NULL, " + final String SQL = new Scanner(schema, StandardCharsets.UTF_8).useDelimiter("\\A").next();
" surname TEXT NOT NULL, " + connection.createStatement().execute(SQL);
" dateOfBirth TEXT NOT NULL, " +
" carelevel TEXT NOT NULL, " +
" roomnumber TEXT NOT NULL" +
");";
try (Statement statement = connection.createStatement())
{
statement.execute(SQL);
} catch (SQLException exception)
{
System.out.println(exception.getMessage());
}
} }
@Override @Override
public Map<String, Patient> load() throws SQLException public Map<String, Patient> load() throws SQLException {
{
List<Patient> patients = new ArrayList<>(); List<Patient> patients = new ArrayList<>();
patients.add(new Patient( patients.add(new Patient(
"Seppl", "Seppl",
"Herberger", "Herberger",
convertStringToLocalDate("1945-12-01"), convertStringToLocalDate("1945-12-01"),
"4", "4",
"202" "202"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Martina", "Martina",
"Gerdsen", "Gerdsen",
convertStringToLocalDate("1954-08-12"), convertStringToLocalDate("1954-08-12"),
"5", "5",
"010" "010"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Gertrud", "Gertrud",
"Franzen", "Franzen",
convertStringToLocalDate("1949-04-16"), convertStringToLocalDate("1949-04-16"),
"3", "3",
"002" "002"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Ahmet", "Ahmet",
"Yilmaz", "Yilmaz",
convertStringToLocalDate("1941-02-22"), convertStringToLocalDate("1941-02-22"),
"3", "3",
"013" "013"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Hans", "Hans",
"Neumann", "Neumann",
convertStringToLocalDate("1955-12-12"), convertStringToLocalDate("1955-12-12"),
"2", "2",
"001" "001"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Elisabeth", "Elisabeth",
"Müller", "Müller",
convertStringToLocalDate("1958-03-07"), convertStringToLocalDate("1958-03-07"),
"5", "5",
"110" "110"
)); ));
PatientDao dao = DaoFactory.getInstance().createPatientDAO(); PatientDao dao = DaoFactory.getInstance().createPatientDAO();
for (Patient patient : patients){ for (Patient patient : patients) {
dao.create(patient); dao.create(patient);
} }
Map<String, Patient> patientsByName = new HashMap<>(); Map<String, Patient> patientsByName = new HashMap<>();
for (Patient patient : dao.readAll()){ for (Patient patient : dao.readAll()) {
patientsByName.put(patient.getFirstName(), patient); patientsByName.put(patient.getFirstName(), patient);
} }

View file

@ -1,17 +1,16 @@
package de.hitec.nhplus.fixtures; package de.hitec.nhplus.fixtures;
import de.hitec.nhplus.Main;
import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.patient.Patient; import de.hitec.nhplus.patient.Patient;
import de.hitec.nhplus.treatment.Treatment; import de.hitec.nhplus.treatment.Treatment;
import de.hitec.nhplus.treatment.TreatmentDao; import de.hitec.nhplus.treatment.database.TreatmentDao;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalDate; import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalDate;
import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalTime; import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalTime;
@ -24,32 +23,16 @@ public class TreatmentFixture implements Fixture<Treatment> {
} }
@Override @Override
public void dropTable(Connection connection) { public void dropTable(Connection connection) throws SQLException {
try (Statement statement = connection.createStatement()) { connection.createStatement().execute("DROP TABLE treatment");
statement.execute("DROP TABLE treatment");
} catch (SQLException exception) {
System.out.println(exception.getMessage());
}
} }
@Override @Override
public void setupTable(Connection connection) { public void setupTable(Connection connection) throws SQLException {
final String SQL = "CREATE TABLE IF NOT EXISTS treatment (" + final InputStream schema = Main.class.getResourceAsStream("/de/hitec/nhplus/treatment/database/Treatment.sql");
" id INTEGER PRIMARY KEY AUTOINCREMENT, " + assert schema != null;
" patientId INTEGER NOT NULL, " + final String SQL = new Scanner(schema, StandardCharsets.UTF_8).useDelimiter("\\A").next();
" treatment_date TEXT NOT NULL, " + connection.createStatement().execute(SQL);
" begin TEXT NOT NULL, " +
" end TEXT NOT NULL, " +
" description TEXT NOT NULL, " +
" remark TEXT NOT NULL," +
" FOREIGN KEY (patientId) REFERENCES patient (id) ON DELETE CASCADE " +
");";
try (Statement statement = connection.createStatement()) {
statement.execute(SQL);
} catch (SQLException exception) {
System.out.println(exception.getMessage());
}
} }
@Override @Override

View file

@ -9,6 +9,7 @@ import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
public class MainWindowController { public class MainWindowController {
@FXML @FXML
@ -40,7 +41,7 @@ public class MainWindowController {
private void loadPatientPage() { private void loadPatientPage() {
try { try {
BorderPane patientsPane = FXMLLoader.load( BorderPane patientsPane = FXMLLoader.load(
Main.class.getResource("/de/hitec/nhplus/patient/AllPatientView.fxml") Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/patient/AllPatientView.fxml"))
); );
patientPage.getChildren().setAll(patientsPane); patientPage.getChildren().setAll(patientsPane);
AnchorPane.setTopAnchor(patientsPane, 0d); AnchorPane.setTopAnchor(patientsPane, 0d);
@ -55,7 +56,7 @@ public class MainWindowController {
private void loadTreatmentsPage() { private void loadTreatmentsPage() {
try { try {
BorderPane treatmentsPane = FXMLLoader.load( BorderPane treatmentsPane = FXMLLoader.load(
Main.class.getResource("/de/hitec/nhplus/treatment/AllTreatmentView.fxml") Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/treatment/AllTreatmentView.fxml"))
); );
treatmentPage.getChildren().setAll(treatmentsPane); treatmentPage.getChildren().setAll(treatmentsPane);
AnchorPane.setTopAnchor(treatmentsPane, 0d); AnchorPane.setTopAnchor(treatmentsPane, 0d);
@ -70,7 +71,7 @@ public class MainWindowController {
private void loadNursePage() { private void loadNursePage() {
try { try {
BorderPane nursePane = FXMLLoader.load( BorderPane nursePane = FXMLLoader.load(
Main.class.getResource("/de/hitec/nhplus/nurse/AllNurseView.fxml") Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/nurse/AllNurseView.fxml"))
); );
nursePage.getChildren().setAll(nursePane); nursePage.getChildren().setAll(nursePane);
AnchorPane.setTopAnchor(nursePane, 0d); AnchorPane.setTopAnchor(nursePane, 0d);

View file

@ -4,11 +4,11 @@ import javafx.beans.property.SimpleStringProperty;
public abstract class Person { public abstract class Person {
private final SimpleStringProperty firstName; private final SimpleStringProperty firstName;
private final SimpleStringProperty surname; private final SimpleStringProperty surName;
public Person(String firstName, String surname) { public Person(String firstName, String surName) {
this.firstName = new SimpleStringProperty(firstName); this.firstName = new SimpleStringProperty(firstName);
this.surname = new SimpleStringProperty(surname); this.surName = new SimpleStringProperty(surName);
} }
public String getFirstName() { public String getFirstName() {
@ -23,15 +23,15 @@ public abstract class Person {
this.firstName.set(firstName); this.firstName.set(firstName);
} }
public String getSurname() { public String getSurName() {
return surname.get(); return surName.get();
} }
public SimpleStringProperty surnameProperty() { public SimpleStringProperty surNameProperty() {
return surname; return surName;
} }
public void setSurname(String surname) { public void setSurName(String surName) {
this.surname.set(surname); this.surName.set(surName);
} }
} }

View file

@ -3,6 +3,7 @@ package de.hitec.nhplus.nurse;
import static de.hitec.nhplus.utils.Validator.*; import static de.hitec.nhplus.utils.Validator.*;
import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.nurse.database.NurseDao;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
@ -18,9 +19,9 @@ import java.sql.SQLException;
public class AllNurseController { public class AllNurseController {
@FXML @FXML
public TextField textFieldSurname; public TextField textFieldSurName;
@FXML @FXML
public TextField textFieldFirstname; public TextField textFieldFirstName;
@FXML @FXML
public TextField textFieldPhoneNumber; public TextField textFieldPhoneNumber;
@FXML @FXML
@ -32,7 +33,7 @@ public class AllNurseController {
@FXML @FXML
private TableColumn<Nurse, String> columnFirstName; private TableColumn<Nurse, String> columnFirstName;
@FXML @FXML
private TableColumn<Nurse, String> columnSurname; private TableColumn<Nurse, String> columnSurName;
@FXML @FXML
private TableColumn<Nurse, String> columnPhoneNumber; private TableColumn<Nurse, String> columnPhoneNumber;
@ -47,8 +48,8 @@ public class AllNurseController {
this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName")); this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
this.columnFirstName.setCellFactory(TextFieldTableCell.forTableColumn()); this.columnFirstName.setCellFactory(TextFieldTableCell.forTableColumn());
this.columnSurname.setCellValueFactory(new PropertyValueFactory<>("surname")); this.columnSurName.setCellValueFactory(new PropertyValueFactory<>("surName"));
this.columnSurname.setCellFactory(TextFieldTableCell.forTableColumn()); this.columnSurName.setCellFactory(TextFieldTableCell.forTableColumn());
this.columnPhoneNumber.setCellValueFactory(new PropertyValueFactory<>("phoneNumber")); this.columnPhoneNumber.setCellValueFactory(new PropertyValueFactory<>("phoneNumber"));
@ -59,15 +60,15 @@ public class AllNurseController {
this.buttonAdd.setDisable(true); this.buttonAdd.setDisable(true);
ChangeListener<String> inputNewNurseValidationListener = (observableValue, oldText, newText)-> ChangeListener<String> inputNewNurseValidationListener = (observableValue, oldText, newText)->
{ {
boolean isValid = isValidFirstName(this.textFieldFirstname.getText()) boolean isValid = isValidFirstName(this.textFieldFirstName.getText())
&& isValidSurName(this.textFieldSurname.getText()) && isValidSurName(this.textFieldSurName.getText())
&& isValidPhoneNumber(this.textFieldPhoneNumber.getText()); && isValidPhoneNumber(this.textFieldPhoneNumber.getText());
AllNurseController.this.buttonAdd.setDisable(!isValid); AllNurseController.this.buttonAdd.setDisable(!isValid);
}; };
this.textFieldFirstname.textProperty().addListener(inputNewNurseValidationListener); this.textFieldFirstName.textProperty().addListener(inputNewNurseValidationListener);
this.textFieldSurname.textProperty().addListener(inputNewNurseValidationListener); this.textFieldSurName.textProperty().addListener(inputNewNurseValidationListener);
this.textFieldPhoneNumber.textProperty().addListener(inputNewNurseValidationListener); this.textFieldPhoneNumber.textProperty().addListener(inputNewNurseValidationListener);
} }
@ -82,8 +83,8 @@ public class AllNurseController {
} }
@FXML @FXML
public void handleAdd(){ public void handleAdd(){
String surname=this.textFieldSurname.getText(); String surname=this.textFieldSurName.getText();
String firstName=this.textFieldFirstname.getText(); String firstName=this.textFieldFirstName.getText();
String phoneNumber=this.textFieldPhoneNumber.getText(); String phoneNumber=this.textFieldPhoneNumber.getText();
try { try {
this.dao.create(new Nurse(firstName, surname, phoneNumber)); this.dao.create(new Nurse(firstName, surname, phoneNumber));
@ -96,8 +97,8 @@ public class AllNurseController {
} }
private void clearTextfields() { private void clearTextfields() {
this.textFieldFirstname.clear(); this.textFieldFirstName.clear();
this.textFieldSurname.clear(); this.textFieldSurName.clear();
this.textFieldPhoneNumber.clear(); this.textFieldPhoneNumber.clear();
} }

View file

@ -12,20 +12,20 @@ public class Nurse extends Person {
public Nurse( public Nurse(
String firstName, String firstName,
String surname, String surName,
String phoneNumber String phoneNumber
) { ) {
super(firstName, surname); super(firstName, surName);
this.phoneNumber = new SimpleStringProperty(phoneNumber); this.phoneNumber = new SimpleStringProperty(phoneNumber);
} }
public Nurse( public Nurse(
int id, int id,
String firstName, String firstName,
String surname, String surName,
String phoneNumber String phoneNumber
) { ) {
super(firstName, surname); super(firstName, surName);
this.id = new SimpleIntegerProperty(id); this.id = new SimpleIntegerProperty(id);
this.phoneNumber = new SimpleStringProperty(phoneNumber); this.phoneNumber = new SimpleStringProperty(phoneNumber);
} }
@ -55,8 +55,8 @@ public class Nurse extends Person {
return new StringJoiner(System.lineSeparator()) return new StringJoiner(System.lineSeparator())
.add("NURSE") .add("NURSE")
.add("ID: " + this.getId()) .add("ID: " + this.getId())
.add("Firstname: " + this.getFirstName()) .add("FirstName: " + this.getFirstName())
.add("Surname: " + this.getSurname()) .add("SurName: " + this.getSurName())
.add("PhoneNumber: " + this.getPhoneNumber()) .add("PhoneNumber: " + this.getPhoneNumber())
.toString(); .toString();

View file

@ -1,6 +1,7 @@
package de.hitec.nhplus.nurse; package de.hitec.nhplus.nurse.database;
import de.hitec.nhplus.datastorage.DaoImp; import de.hitec.nhplus.datastorage.DaoImp;
import de.hitec.nhplus.nurse.Nurse;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -16,21 +17,24 @@ public class NurseDao extends DaoImp<Nurse> {
@Override @Override
protected PreparedStatement getCreateStatement(Nurse nurse) throws SQLException { protected PreparedStatement getCreateStatement(Nurse nurse) throws SQLException {
final String SQL = "INSERT INTO nurse (firstname, surname, phoneNumber)" + final String SQL = """
"VALUES (?, ?, ?)"; INSERT INTO nurse
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL); (firstName, surName, phoneNumber)
preparedStatement.setString(1, nurse.getFirstName()); VALUES (?, ?, ?)
preparedStatement.setString(2, nurse.getSurname()); """;
preparedStatement.setString(3, nurse.getPhoneNumber()); PreparedStatement statement = this.connection.prepareStatement(SQL);
return preparedStatement; statement.setString(1, nurse.getFirstName());
statement.setString(2, nurse.getSurName());
statement.setString(3, nurse.getPhoneNumber());
return statement;
} }
@Override @Override
protected PreparedStatement getReadByIDStatement(int id) throws SQLException { protected PreparedStatement getReadByIDStatement(int id) throws SQLException {
final String SQL = "SELECT * FROM nurse WHERE id = ?"; final String SQL = "SELECT * FROM nurse WHERE id = ?";
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL); PreparedStatement statement = this.connection.prepareStatement(SQL);
preparedStatement.setInt(1, id); statement.setInt(1, id);
return preparedStatement; return statement;
} }
@Override @Override
@ -58,28 +62,28 @@ public class NurseDao extends DaoImp<Nurse> {
return list; return list;
} }
@Override @Override
protected PreparedStatement getUpdateStatement(Nurse nurse) throws SQLException { protected PreparedStatement getUpdateStatement(Nurse nurse) throws SQLException {
final String SQL = final String SQL = """
"UPDATE nurse SET " + UPDATE nurse SET
"firstname = ?, " + firstName = ?,
"surname = ?, " + surName = ?,
"phoneNumber = ? " + phoneNumber = ?
"WHERE id = ?"; WHERE id = ?
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL); """;
preparedStatement.setString(1, nurse.getFirstName()); PreparedStatement statement = this.connection.prepareStatement(SQL);
preparedStatement.setString(2, nurse.getSurname()); statement.setString(1, nurse.getFirstName());
preparedStatement.setString(3, nurse.getPhoneNumber()); statement.setString(2, nurse.getSurName());
preparedStatement.setInt(4, nurse.getId()); statement.setString(3, nurse.getPhoneNumber());
return preparedStatement; statement.setInt(4, nurse.getId());
return statement;
} }
@Override @Override
protected PreparedStatement getDeleteStatement(int id) throws SQLException { protected PreparedStatement getDeleteStatement(int id) throws SQLException {
final String SQL = "DELETE FROM nurse WHERE id = ?"; final String SQL = "DELETE FROM nurse WHERE id = ?";
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL); PreparedStatement statement = this.connection.prepareStatement(SQL);
preparedStatement.setInt(1, id); statement.setInt(1, id);
return preparedStatement; return statement;
} }
} }

View file

@ -1,6 +1,7 @@
package de.hitec.nhplus.patient; package de.hitec.nhplus.patient;
import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.patient.database.PatientDao;
import de.hitec.nhplus.utils.DateConverter; import de.hitec.nhplus.utils.DateConverter;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
@ -27,7 +28,7 @@ public class AllPatientController {
@FXML @FXML
private TableColumn<Patient, String> columnFirstName; private TableColumn<Patient, String> columnFirstName;
@FXML @FXML
private TableColumn<Patient, String> columnSurname; private TableColumn<Patient, String> columnSurName;
@FXML @FXML
private TableColumn<Patient, String> columnDateOfBirth; private TableColumn<Patient, String> columnDateOfBirth;
@FXML @FXML
@ -39,7 +40,7 @@ public class AllPatientController {
@FXML @FXML
private Button buttonAdd; private Button buttonAdd;
@FXML @FXML
private TextField textFieldSurname; private TextField textFieldSurName;
@FXML @FXML
private TextField textFieldFirstName; private TextField textFieldFirstName;
@FXML @FXML
@ -60,8 +61,8 @@ public class AllPatientController {
this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName")); this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
this.columnFirstName.setCellFactory(TextFieldTableCell.forTableColumn()); this.columnFirstName.setCellFactory(TextFieldTableCell.forTableColumn());
this.columnSurname.setCellValueFactory(new PropertyValueFactory<>("surname")); this.columnSurName.setCellValueFactory(new PropertyValueFactory<>("surName"));
this.columnSurname.setCellFactory(TextFieldTableCell.forTableColumn()); this.columnSurName.setCellFactory(TextFieldTableCell.forTableColumn());
this.columnDateOfBirth.setCellValueFactory(new PropertyValueFactory<>("dateOfBirth")); this.columnDateOfBirth.setCellValueFactory(new PropertyValueFactory<>("dateOfBirth"));
this.columnDateOfBirth.setCellFactory(TextFieldTableCell.forTableColumn()); this.columnDateOfBirth.setCellFactory(TextFieldTableCell.forTableColumn());
@ -88,7 +89,7 @@ public class AllPatientController {
{ {
boolean isValid = isValidDate(this.textFieldDateOfBirth.getText()) boolean isValid = isValidDate(this.textFieldDateOfBirth.getText())
&& isValidFirstName(this.textFieldFirstName.getText()) && isValidFirstName(this.textFieldFirstName.getText())
&& isValidSurName(this.textFieldSurname.getText()) && isValidSurName(this.textFieldSurName.getText())
&& isValidDate(this.textFieldDateOfBirth.getText()) && isValidDate(this.textFieldDateOfBirth.getText())
&& isValidCareLevel(this.textFieldCareLevel.getText()) && isValidCareLevel(this.textFieldCareLevel.getText())
&& isValidRoomNumber(textFieldRoomNumber.getText()); && isValidRoomNumber(textFieldRoomNumber.getText());
@ -96,7 +97,7 @@ public class AllPatientController {
AllPatientController.this.buttonAdd.setDisable(!isValid); AllPatientController.this.buttonAdd.setDisable(!isValid);
}; };
this.textFieldSurname.textProperty().addListener(inputNewPatientValidationListener); this.textFieldSurName.textProperty().addListener(inputNewPatientValidationListener);
this.textFieldFirstName.textProperty().addListener(inputNewPatientValidationListener); this.textFieldFirstName.textProperty().addListener(inputNewPatientValidationListener);
this.textFieldDateOfBirth.textProperty().addListener(inputNewPatientValidationListener); this.textFieldDateOfBirth.textProperty().addListener(inputNewPatientValidationListener);
this.textFieldCareLevel.textProperty().addListener(inputNewPatientValidationListener); this.textFieldCareLevel.textProperty().addListener(inputNewPatientValidationListener);
@ -123,7 +124,7 @@ public class AllPatientController {
event.getTableView().refresh(); event.getTableView().refresh();
return; return;
} }
event.getRowValue().setSurname(newSurName); event.getRowValue().setSurName(newSurName);
this.doUpdate(event); this.doUpdate(event);
} }
@ -197,7 +198,7 @@ public class AllPatientController {
@FXML @FXML
public void handleAdd() { public void handleAdd() {
String surname = this.textFieldSurname.getText(); String surname = this.textFieldSurName.getText();
String firstName = this.textFieldFirstName.getText(); String firstName = this.textFieldFirstName.getText();
String birthday = this.textFieldDateOfBirth.getText(); String birthday = this.textFieldDateOfBirth.getText();
LocalDate date = DateConverter.convertStringToLocalDate(birthday); LocalDate date = DateConverter.convertStringToLocalDate(birthday);
@ -214,7 +215,7 @@ public class AllPatientController {
private void clearTextfields() { private void clearTextfields() {
this.textFieldFirstName.clear(); this.textFieldFirstName.clear();
this.textFieldSurname.clear(); this.textFieldSurName.clear();
this.textFieldDateOfBirth.clear(); this.textFieldDateOfBirth.clear();
this.textFieldCareLevel.clear(); this.textFieldCareLevel.clear();
this.textFieldRoomNumber.clear(); this.textFieldRoomNumber.clear();

View file

@ -20,12 +20,12 @@ public class Patient extends Person {
public Patient( public Patient(
String firstName, String firstName,
String surname, String surName,
LocalDate dateOfBirth, LocalDate dateOfBirth,
String careLevel, String careLevel,
String roomNumber String roomNumber
) { ) {
super(firstName, surname); super(firstName, surName);
this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth)); this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth));
this.careLevel = new SimpleStringProperty(careLevel); this.careLevel = new SimpleStringProperty(careLevel);
this.roomNumber = new SimpleStringProperty(roomNumber); this.roomNumber = new SimpleStringProperty(roomNumber);
@ -34,12 +34,12 @@ public class Patient extends Person {
public Patient( public Patient(
int id, int id,
String firstName, String firstName,
String surname, String surName,
LocalDate dateOfBirth, LocalDate dateOfBirth,
String careLevel, String careLevel,
String roomNumber String roomNumber
) { ) {
super(firstName, surname); super(firstName, surName);
this.id = new SimpleIntegerProperty(id); this.id = new SimpleIntegerProperty(id);
this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth)); this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth));
this.careLevel = new SimpleStringProperty(careLevel); this.careLevel = new SimpleStringProperty(careLevel);
@ -103,8 +103,8 @@ public class Patient extends Person {
return new StringJoiner(System.lineSeparator()) return new StringJoiner(System.lineSeparator())
.add("PATIENT") .add("PATIENT")
.add("ID: " + this.getId()) .add("ID: " + this.getId())
.add("Firstname: " + this.getFirstName()) .add("FirstName: " + this.getFirstName())
.add("Surname: " + this.getSurname()) .add("SurName: " + this.getSurName())
.add("Birthday: " + this.getDateOfBirth()) .add("Birthday: " + this.getDateOfBirth())
.add("Carelevel: " + this.getCareLevel()) .add("Carelevel: " + this.getCareLevel())
.add("RoomNumber: " + this.getRoomNumber()) .add("RoomNumber: " + this.getRoomNumber())

View file

@ -1,6 +1,7 @@
package de.hitec.nhplus.patient; package de.hitec.nhplus.patient.database;
import de.hitec.nhplus.datastorage.DaoImp; import de.hitec.nhplus.datastorage.DaoImp;
import de.hitec.nhplus.patient.Patient;
import de.hitec.nhplus.utils.DateConverter; import de.hitec.nhplus.utils.DateConverter;
import java.sql.Connection; import java.sql.Connection;
@ -18,23 +19,26 @@ public class PatientDao extends DaoImp<Patient> {
@Override @Override
protected PreparedStatement getCreateStatement(Patient patient) throws SQLException { protected PreparedStatement getCreateStatement(Patient patient) throws SQLException {
final String SQL = "INSERT INTO patient (firstname, surname, dateOfBirth, carelevel, roomnumber) " + final String SQL = """
"VALUES (?, ?, ?, ?, ?)"; INSERT INTO patient
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL); (firstName, surName, dateOfBirth, careLevel, roomNumber)
preparedStatement.setString(1, patient.getFirstName()); VALUES (?, ?, ?, ?, ?)
preparedStatement.setString(2, patient.getSurname()); """;
preparedStatement.setString(3, patient.getDateOfBirth()); PreparedStatement statement = this.connection.prepareStatement(SQL);
preparedStatement.setString(4, patient.getCareLevel()); statement.setString(1, patient.getFirstName());
preparedStatement.setString(5, patient.getRoomNumber()); statement.setString(2, patient.getSurName());
return preparedStatement; statement.setString(3, patient.getDateOfBirth());
statement.setString(4, patient.getCareLevel());
statement.setString(5, patient.getRoomNumber());
return statement;
} }
@Override @Override
protected PreparedStatement getReadByIDStatement(int id) throws SQLException { protected PreparedStatement getReadByIDStatement(int id) throws SQLException {
final String SQL = "SELECT * FROM patient WHERE id = ?"; final String SQL = "SELECT * FROM patient WHERE id = ?";
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL); PreparedStatement statement = this.connection.prepareStatement(SQL);
preparedStatement.setInt(1, id); statement.setInt(1, id);
return preparedStatement; return statement;
} }
@Override @Override
@ -65,29 +69,30 @@ public class PatientDao extends DaoImp<Patient> {
@Override @Override
protected PreparedStatement getUpdateStatement(Patient patient) throws SQLException { protected PreparedStatement getUpdateStatement(Patient patient) throws SQLException {
final String SQL = final String SQL = """
"UPDATE patient SET " + UPDATE patient SET
"firstname = ?, " + firstName = ?,
"surname = ?, " + surName = ?,
"dateOfBirth = ?, " + dateOfBirth = ?,
"carelevel = ?, " + careLevel = ?,
"roomnumber = ?, " + roomNumber = ?,
"WHERE id = ?"; WHERE id = ?
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL); """;
preparedStatement.setString(1, patient.getFirstName()); PreparedStatement statement = this.connection.prepareStatement(SQL);
preparedStatement.setString(2, patient.getSurname()); statement.setString(1, patient.getFirstName());
preparedStatement.setString(3, patient.getDateOfBirth()); statement.setString(2, patient.getSurName());
preparedStatement.setString(4, patient.getCareLevel()); statement.setString(3, patient.getDateOfBirth());
preparedStatement.setString(5, patient.getRoomNumber()); statement.setString(4, patient.getCareLevel());
preparedStatement.setInt(6, patient.getId()); statement.setString(5, patient.getRoomNumber());
return preparedStatement; statement.setInt(6, patient.getId());
return statement;
} }
@Override @Override
protected PreparedStatement getDeleteStatement(int id) throws SQLException { protected PreparedStatement getDeleteStatement(int id) throws SQLException {
final String SQL = "DELETE FROM patient WHERE id = ?"; final String SQL = "DELETE FROM patient WHERE id = ?";
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL); PreparedStatement statement = this.connection.prepareStatement(SQL);
preparedStatement.setInt(1, id); statement.setInt(1, id);
return preparedStatement; return statement;
} }
} }

View file

@ -3,7 +3,10 @@ package de.hitec.nhplus.treatment;
import de.hitec.nhplus.Main; import de.hitec.nhplus.Main;
import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.patient.Patient; import de.hitec.nhplus.patient.Patient;
import de.hitec.nhplus.patient.PatientDao; import de.hitec.nhplus.patient.database.PatientDao;
import de.hitec.nhplus.treatment.database.TreatmentDao;
import javafx.beans.property.SimpleIntegerProperty;
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;
@ -27,7 +30,7 @@ public class AllTreatmentController {
private TableColumn<Treatment, Integer> columnId; private TableColumn<Treatment, Integer> columnId;
@FXML @FXML
private TableColumn<Treatment, Integer> columnPatientId; private TableColumn<Treatment, String> columnPatientName;
@FXML @FXML
private TableColumn<Treatment, String> columnDate; private TableColumn<Treatment, String> columnDate;
@ -58,7 +61,12 @@ public class AllTreatmentController {
comboBoxPatientSelection.getSelectionModel().select(0); comboBoxPatientSelection.getSelectionModel().select(0);
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id")); this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
this.columnPatientId.setCellValueFactory(new PropertyValueFactory<>("patientId")); this.columnPatientName.setCellValueFactory(
cellData -> {
Patient patient = cellData.getValue().getPatient();
return new SimpleStringProperty(patient.getSurName() + ", " + patient.getFirstName());
}
);
this.columnDate.setCellValueFactory(new PropertyValueFactory<>("date")); this.columnDate.setCellValueFactory(new PropertyValueFactory<>("date"));
this.columnBegin.setCellValueFactory(new PropertyValueFactory<>("begin")); this.columnBegin.setCellValueFactory(new PropertyValueFactory<>("begin"));
this.columnEnd.setCellValueFactory(new PropertyValueFactory<>("end")); this.columnEnd.setCellValueFactory(new PropertyValueFactory<>("end"));
@ -92,7 +100,7 @@ public class AllTreatmentController {
patientList = (ArrayList<Patient>) dao.readAll(); patientList = (ArrayList<Patient>) dao.readAll();
this.patientSelection.add("alle"); this.patientSelection.add("alle");
for (Patient patient : patientList) { for (Patient patient : patientList) {
this.patientSelection.add(patient.getSurname()); this.patientSelection.add(patient.getSurName());
} }
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
@ -126,7 +134,7 @@ public class AllTreatmentController {
private Patient searchInList(String surname) { private Patient searchInList(String surname) {
for (Patient patient : this.patientList) { for (Patient patient : this.patientList) {
if (patient.getSurname().equals(surname)) { if (patient.getSurName().equals(surname)) {
return patient; return patient;
} }
} }

View file

@ -2,94 +2,121 @@ package de.hitec.nhplus.treatment;
import de.hitec.nhplus.patient.Patient; import de.hitec.nhplus.patient.Patient;
import de.hitec.nhplus.utils.DateConverter; import de.hitec.nhplus.utils.DateConverter;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.StringJoiner; import java.util.StringJoiner;
public class Treatment { public class Treatment {
private int id; private SimpleIntegerProperty id;
private final Patient patient; private final SimpleObjectProperty<Patient> patient;
private LocalDate date; private final SimpleObjectProperty<LocalDate> date;
private LocalTime begin; private final SimpleObjectProperty<LocalTime> begin;
private LocalTime end; private final SimpleObjectProperty<LocalTime> end;
private String description; private final SimpleStringProperty description;
private String remarks; private final SimpleStringProperty remarks;
public Treatment(Patient patient, LocalDate date, LocalTime begin, public Treatment(Patient patient, LocalDate date, LocalTime begin,
LocalTime end, String description, String remarks) { LocalTime end, String description, String remarks) {
this.patient = patient; this.patient = new SimpleObjectProperty<>(patient);
this.date = date; this.date = new SimpleObjectProperty<>(date);
this.begin = begin; this.begin = new SimpleObjectProperty<>(begin);
this.end = end; this.end = new SimpleObjectProperty<>(end);
this.description = description; this.description = new SimpleStringProperty(description);
this.remarks = remarks; this.remarks = new SimpleStringProperty(remarks);
} }
public Treatment(int id, Patient patient, LocalDate date, LocalTime begin, public Treatment(int id, Patient patient, LocalDate date, LocalTime begin,
LocalTime end, String description, String remarks) { LocalTime end, String description, String remarks) {
this.id = id; this.id = new SimpleIntegerProperty(id);
this.patient = patient; this.patient = new SimpleObjectProperty<>(patient);
this.date = date; this.date = new SimpleObjectProperty<>(date);
this.begin = begin; this.begin = new SimpleObjectProperty<>(begin);
this.end = end; this.end = new SimpleObjectProperty<>(end);
this.description = description; this.description = new SimpleStringProperty(description);
this.remarks = remarks; this.remarks = new SimpleStringProperty(remarks);
} }
public int getId() { public int getId() {
return id; return id.getValue();
} }
public Patient getPatient() { public Patient getPatient() {
return this.patient; return patient.getValue();
} }
public String getDate() { public String getDate() {
return date.toString(); return date.getValue().toString();
} }
public String getBegin() { public String getBegin() {
return begin.toString(); return begin.getValue().toString();
} }
public String getEnd() { public String getEnd() {
return end.toString(); return end.getValue().toString();
} }
public void setDate(String date) { public void setDate(String date) {
this.date = DateConverter.convertStringToLocalDate(date); this.date.set(DateConverter.convertStringToLocalDate(date));
} }
public void setBegin(LocalTime begin) { public void setBegin(LocalTime begin) {
this.begin = begin; this.begin.set(begin);
} }
public void setEnd(LocalTime end) { public void setEnd(LocalTime end) {
this.end = end; this.end.set(end);
} }
public String getDescription() { public String getDescription() {
return description; return description.getValue();
} }
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description.set(description);
} }
public String getRemarks() { public String getRemarks() {
return remarks.getValue();
}
public SimpleObjectProperty<Patient> patientProperty() {
return patient;
}
public SimpleObjectProperty<LocalDate> dateProperty() {
return date;
}
public SimpleObjectProperty<LocalTime> beginProperty() {
return begin;
}
public SimpleObjectProperty<LocalTime> endProperty() {
return end;
}
public SimpleStringProperty descriptionProperty() {
return description;
}
public SimpleStringProperty remarksProperty() {
return remarks; return remarks;
} }
public void setRemarks(String remarks) { public void setRemarks(String remarks) {
this.remarks = remarks; this.remarks.set(remarks);
} }
public String toString() { public String toString() {
return new StringJoiner(System.lineSeparator()) return new StringJoiner(System.lineSeparator())
.add("TREATMENT") .add("TREATMENT")
.add("ID: " + this.getId()) .add("ID: " + this.getId())
.add("Patient: " + this.getPatient().getSurname() + " " + this.getPatient().getFirstName()) .add("Patient: " + this.getPatient().getSurName() + " " + this.getPatient().getFirstName())
.add("Date: " + this.getDate()) .add("Date: " + this.getDate())
.add("Begin: " + this.getBegin()) .add("Begin: " + this.getBegin())
.add("End: " + this.getEnd()) .add("End: " + this.getEnd())

View file

@ -99,7 +99,7 @@ public class TreatmentModalController {
private void showData() { private void showData() {
this.labelFirstName.setText(patient.getFirstName()); this.labelFirstName.setText(patient.getFirstName());
this.labelSurname.setText(patient.getSurname()); this.labelSurname.setText(patient.getSurName());
LocalDate date = DateConverter.convertStringToLocalDate(treatment.getDate()); LocalDate date = DateConverter.convertStringToLocalDate(treatment.getDate());
this.datePicker.setValue(date); this.datePicker.setValue(date);
this.textFieldBegin.setText(this.treatment.getBegin()); this.textFieldBegin.setText(this.treatment.getBegin());

View file

@ -1,7 +1,8 @@
package de.hitec.nhplus.treatment; package de.hitec.nhplus.treatment.database;
import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.datastorage.DaoImp; import de.hitec.nhplus.datastorage.DaoImp;
import de.hitec.nhplus.treatment.Treatment;
import de.hitec.nhplus.utils.DateConverter; import de.hitec.nhplus.utils.DateConverter;
import java.sql.Connection; import java.sql.Connection;
@ -19,24 +20,27 @@ public class TreatmentDao extends DaoImp<Treatment> {
@Override @Override
protected PreparedStatement getCreateStatement(Treatment treatment) throws SQLException { protected PreparedStatement getCreateStatement(Treatment treatment) throws SQLException {
final String SQL = "INSERT INTO treatment (patientId, treatment_date, begin, end, description, remark) " + final String SQL = """
"VALUES (?, ?, ?, ?, ?, ?)"; INSERT INTO treatment
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL); (patientId, date, begin, end, description, remark)
preparedStatement.setInt(1, treatment.getPatient().getId()); VALUES (?, ?, ?, ?, ?, ?)
preparedStatement.setString(2, treatment.getDate()); """;
preparedStatement.setString(3, treatment.getBegin()); PreparedStatement statement = this.connection.prepareStatement(SQL);
preparedStatement.setString(4, treatment.getEnd()); statement.setInt(1, treatment.getPatient().getId());
preparedStatement.setString(5, treatment.getDescription()); statement.setString(2, treatment.getDate());
preparedStatement.setString(6, treatment.getRemarks()); statement.setString(3, treatment.getBegin());
return preparedStatement; statement.setString(4, treatment.getEnd());
statement.setString(5, treatment.getDescription());
statement.setString(6, treatment.getRemarks());
return statement;
} }
@Override @Override
protected PreparedStatement getReadByIDStatement(int id) throws SQLException { protected PreparedStatement getReadByIDStatement(int id) throws SQLException {
final String SQL = "SELECT * FROM treatment WHERE id = ?"; final String SQL = "SELECT * FROM treatment WHERE id = ?";
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL); PreparedStatement statement = this.connection.prepareStatement(SQL);
preparedStatement.setInt(1, id); statement.setInt(1, id);
return preparedStatement; return statement;
} }
@Override @Override
@ -69,9 +73,9 @@ public class TreatmentDao extends DaoImp<Treatment> {
private PreparedStatement getReadAllTreatmentsOfOnePatientByPid(int patientId) throws SQLException { private PreparedStatement getReadAllTreatmentsOfOnePatientByPid(int patientId) throws SQLException {
final String SQL = "SELECT * FROM treatment WHERE patientId = ?"; final String SQL = "SELECT * FROM treatment WHERE patientId = ?";
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL); PreparedStatement statement = this.connection.prepareStatement(SQL);
preparedStatement.setInt(1, patientId); statement.setInt(1, patientId);
return preparedStatement; return statement;
} }
public List<Treatment> readTreatmentsByPid(int patientId) throws SQLException { public List<Treatment> readTreatmentsByPid(int patientId) throws SQLException {
@ -81,32 +85,33 @@ public class TreatmentDao extends DaoImp<Treatment> {
@Override @Override
protected PreparedStatement getUpdateStatement(Treatment treatment) throws SQLException { protected PreparedStatement getUpdateStatement(Treatment treatment) throws SQLException {
final String SQL = final String SQL = """
"UPDATE treatment SET " + UPDATE treatment SET
"patientId = ?, " + patientId = ?,
"treatment_date = ?, " + date = ?,
"begin = ?, " + begin = ?,
"end = ?, " + end = ?,
"description = ?, " + description = ?,
"remark = ? " + remark = ?
"WHERE id = ?"; WHERE id = ?
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL); """;
preparedStatement.setInt(1, treatment.getPatient().getId()); PreparedStatement statement = this.connection.prepareStatement(SQL);
preparedStatement.setString(2, treatment.getDate()); statement.setInt(1, treatment.getPatient().getId());
preparedStatement.setString(3, treatment.getBegin()); statement.setString(2, treatment.getDate());
preparedStatement.setString(4, treatment.getEnd()); statement.setString(3, treatment.getBegin());
preparedStatement.setString(5, treatment.getDescription()); statement.setString(4, treatment.getEnd());
preparedStatement.setString(6, treatment.getRemarks()); statement.setString(5, treatment.getDescription());
preparedStatement.setInt(7, treatment.getId()); statement.setString(6, treatment.getRemarks());
return preparedStatement; statement.setInt(7, treatment.getId());
return statement;
} }
@Override @Override
protected PreparedStatement getDeleteStatement(int id) throws SQLException { protected PreparedStatement getDeleteStatement(int id) throws SQLException {
final String SQL = final String SQL =
"DELETE FROM treatment WHERE id = ?"; "DELETE FROM treatment WHERE id = ?";
PreparedStatement preparedStatement = this.connection.prepareStatement(SQL); PreparedStatement statement = this.connection.prepareStatement(SQL);
preparedStatement.setInt(1, id); statement.setInt(1, id);
return preparedStatement; return statement;
} }
} }

View file

@ -11,11 +11,17 @@ module de.hitec.nhplus {
opens de.hitec.nhplus.main to javafx.base, javafx.fxml; opens de.hitec.nhplus.main to javafx.base, javafx.fxml;
exports de.hitec.nhplus.patient; exports de.hitec.nhplus.patient;
exports de.hitec.nhplus.patient.database;
opens de.hitec.nhplus.patient.database to javafx.base, javafx.fxml;
opens de.hitec.nhplus.patient to javafx.base, javafx.fxml; opens de.hitec.nhplus.patient to javafx.base, javafx.fxml;
exports de.hitec.nhplus.treatment; exports de.hitec.nhplus.treatment;
exports de.hitec.nhplus.treatment.database;
opens de.hitec.nhplus.treatment to javafx.base, javafx.fxml; opens de.hitec.nhplus.treatment to javafx.base, javafx.fxml;
opens de.hitec.nhplus.treatment.database to javafx.base, javafx.fxml;
exports de.hitec.nhplus.nurse; exports de.hitec.nhplus.nurse;
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;
} }

View file

@ -20,7 +20,7 @@
text="ID" text="ID"
/> />
<TableColumn <TableColumn
fx:id="columnSurname" fx:id="columnSurName"
minWidth="140.0" minWidth="140.0"
text="Nachname" text="Nachname"
/> />
@ -51,12 +51,12 @@
<Insets right="8.0"/> <Insets right="8.0"/>
</padding> </padding>
<TextField <TextField
fx:id="textFieldSurname" fx:id="textFieldSurName"
prefWidth="200.0" prefWidth="200.0"
promptText="Nachname" promptText="Nachname"
/> />
<TextField <TextField
fx:id="textFieldFirstname" fx:id="textFieldFirstName"
prefWidth="200.0" prefWidth="200.0"
promptText="Vorname" promptText="Vorname"
/> />

View file

@ -0,0 +1,7 @@
CREATE TABLE nurse
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
firstName TEXT NOT NULL,
surName TEXT NOT NULL,
phoneNumber TEXT NOT NULL
)

View file

@ -23,7 +23,7 @@
text="ID" text="ID"
/> />
<TableColumn <TableColumn
fx:id="columnSurname" fx:id="columnSurName"
minWidth="140.0" minWidth="140.0"
onEditCommit="#handleOnEditSurname" onEditCommit="#handleOnEditSurname"
text="Nachname" text="Nachname"
@ -90,7 +90,7 @@
GridPane.rowIndex="0" GridPane.rowIndex="0"
GridPane.columnIndex="1" GridPane.columnIndex="1"
prefWidth="200.0" prefWidth="200.0"
fx:id="textFieldSurname" fx:id="textFieldSurName"
promptText="Nachname" promptText="Nachname"
/> />
<TextField <TextField

View file

@ -0,0 +1,9 @@
CREATE TABLE patient
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
firstName TEXT NOT NULL,
surName TEXT NOT NULL,
dateOfBirth TEXT NOT NULL,
careLevel TEXT NOT NULL,
roomNumber TEXT NOT NULL
);

View file

@ -24,9 +24,9 @@
text="ID" text="ID"
/> />
<TableColumn <TableColumn
fx:id="columnPatientId" fx:id="columnPatientName"
minWidth="40.0" minWidth="80.0"
text="PatientID" text="Patient"
/> />
<TableColumn <TableColumn
fx:id="columnDate" fx:id="columnDate"

View file

@ -0,0 +1,11 @@
CREATE TABLE treatment
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
patientId INTEGER NOT NULL,
date TEXT NOT NULL,
begin TEXT NOT NULL,
end TEXT NOT NULL,
description TEXT NOT NULL,
remark TEXT NOT NULL,
FOREIGN KEY (patientId) REFERENCES patient (id) ON DELETE CASCADE
)