#7 Cleanup
Some checks failed
Quality Check / Linting Check (push) Successful in 16s
Quality Check / Linting Check (pull_request) Successful in 20s
Quality Check / Javadoc Check (push) Has been cancelled
Quality Check / Javadoc Check (pull_request) Successful in 41s

This commit is contained in:
Dominik Säume 2024-05-20 09:00:23 +02:00
parent 3c1445f430
commit 2fa002448b
Signed by: SZUT-Dominik
GPG key ID: DACB4B96EB59ABA8
8 changed files with 125 additions and 130 deletions

Binary file not shown.

View file

@ -58,7 +58,6 @@ public class TreatmentFixture implements Fixture<Treatment> {
Nurse armin = nursesByName.get("Armin"); Nurse armin = nursesByName.get("Armin");
treatments.add(new Treatment( treatments.add(new Treatment(
1,
seppl, seppl,
ole, ole,
convertStringToLocalDate("2023-06-03"), convertStringToLocalDate("2023-06-03"),
@ -67,11 +66,9 @@ public class TreatmentFixture implements Fixture<Treatment> {
"Gespräch", "Gespräch",
"Der Patient hat enorme Angstgefühle und glaubt, er sei überfallen worden." "Der Patient hat enorme Angstgefühle und glaubt, er sei überfallen worden."
+ "Ihm seien alle Wertsachen gestohlen worden." + "Ihm seien alle Wertsachen gestohlen worden."
+ "Patient beruhigt sich erst, als alle Wertsachen im Zimmer gefunden worden sind.", + "Patient beruhigt sich erst, als alle Wertsachen im Zimmer gefunden worden sind."
false
)); ));
treatments.add(new Treatment( treatments.add(new Treatment(
2,
seppl, seppl,
armin, armin,
convertStringToLocalDate("2023-06-05"), convertStringToLocalDate("2023-06-05"),
@ -80,102 +77,92 @@ public class TreatmentFixture implements Fixture<Treatment> {
"Gespräch", "Gespräch",
"Patient irrt auf der Suche nach gestohlenen Wertsachen durch die Etage " "Patient irrt auf der Suche nach gestohlenen Wertsachen durch die Etage "
+ "und bezichtigt andere Bewohner des Diebstahls." + "und bezichtigt andere Bewohner des Diebstahls."
+ "Patient wird in seinen Raum zurückbegleitet und erhält Beruhigungsmittel.", + "Patient wird in seinen Raum zurückbegleitet und erhält Beruhigungsmittel."
false
)); ));
treatments.add(new Treatment( treatments.add(new Treatment(
3,
martina, martina,
ole, ole,
convertStringToLocalDate("2023-06-04"), convertStringToLocalDate("2023-06-04"),
convertStringToLocalTime("07:30"), convertStringToLocalTime("07:30"),
convertStringToLocalTime("08:00"), convertStringToLocalTime("08:00"),
"Waschen", "Waschen",
"Patient mit Waschlappen gewaschen und frisch angezogen. Patient gewendet.", "Patient mit Waschlappen gewaschen und frisch angezogen. Patient gewendet."
false
)); ));
treatments.add(new Treatment( treatments.add(new Treatment(
4,
seppl, seppl,
armin, armin,
convertStringToLocalDate("2023-06-06"), convertStringToLocalDate("2023-06-06"),
convertStringToLocalTime("15:10"), convertStringToLocalTime("15:10"),
convertStringToLocalTime("16:00"), convertStringToLocalTime("16:00"),
"Spaziergang", "Spaziergang",
"Spaziergang im Park, Patient döst im Rollstuhl ein", "Spaziergang im Park, Patient döst im Rollstuhl ein"
false)
); ));
treatments.add(new Treatment( treatments.add(new Treatment(
8,
seppl, seppl,
ole, ole,
convertStringToLocalDate("2023-06-08"), convertStringToLocalDate("2023-06-08"),
convertStringToLocalTime("15:00"), convertStringToLocalTime("15:00"),
convertStringToLocalTime("16:00"), convertStringToLocalTime("16:00"),
"Spaziergang", "Spaziergang",
"Parkspaziergang; Patient ist heute lebhafter und hat klare Momente; erzählt von seiner Tochter", "Parkspaziergang; Patient ist heute lebhafter und hat klare Momente; erzählt von seiner Tochter"
false) ));
);
treatments.add(new Treatment( treatments.add(new Treatment(
9,
martina, martina,
armin, armin,
convertStringToLocalDate("2023-06-07"), convertStringToLocalDate("2023-06-07"),
convertStringToLocalTime("11:00"), convertStringToLocalTime("11:00"),
convertStringToLocalTime("11:30"), convertStringToLocalTime("11:30"),
"Waschen", "Waschen",
"Waschen per Dusche auf einem Stuhl; Patientin gewendet;", "Waschen per Dusche auf einem Stuhl; Patientin gewendet;"
false) ));
);
treatments.add(new Treatment( treatments.add(new Treatment(
12,
hans, hans,
armin, armin,
convertStringToLocalDate("2023-06-08"), convertStringToLocalDate("2023-06-08"),
convertStringToLocalTime("15:00"), convertStringToLocalTime("15:00"),
convertStringToLocalTime("15:30"), convertStringToLocalTime("15:30"),
"Physiotherapie", "Physiotherapie",
"Übungen zur Stabilisation und Mobilisierung der Rückenmuskulatur", "Übungen zur Stabilisation und Mobilisierung der Rückenmuskulatur"
false) ));
);
treatments.add(new Treatment( treatments.add(new Treatment(
14,
ahmet, ahmet,
ole, ole,
convertStringToLocalDate("2023-08-24"), convertStringToLocalDate("2023-08-24"),
convertStringToLocalTime("09:30"), convertStringToLocalTime("09:30"),
convertStringToLocalTime("10:15"), convertStringToLocalTime("10:15"),
"KG", "KG",
"Lympfdrainage", "Lympfdrainage"
false)); ));
treatments.add(new Treatment( treatments.add(new Treatment(
16,
elisabeth, elisabeth,
armin, armin,
convertStringToLocalDate("2023-08-31"), convertStringToLocalDate("2023-08-31"),
convertStringToLocalTime("13:30"), convertStringToLocalTime("13:30"),
convertStringToLocalTime("13:45"), convertStringToLocalTime("13:45"),
"Toilettengang", "Toilettengang",
"Hilfe beim Toilettengang; Patientin klagt über Schmerzen beim Stuhlgang. Gabe von Iberogast", "Hilfe beim Toilettengang; Patientin klagt über Schmerzen beim Stuhlgang. Gabe von Iberogast"
false) ));
); Treatment lockedTreatment = new Treatment(
treatments.add(new Treatment(
17,
elisabeth, elisabeth,
ole, ole,
convertStringToLocalDate("2023-09-01"), convertStringToLocalDate("2023-09-01"),
convertStringToLocalTime("16:00"), convertStringToLocalTime("16:00"),
convertStringToLocalTime("17:00"), convertStringToLocalTime("17:00"),
"KG", "KG",
"Massage der Extremitäten zur Verbesserung der Durchblutung", "Massage der Extremitäten zur Verbesserung der Durchblutung"
true)
); );
lockedTreatment.setLocked(true);
treatments.add(lockedTreatment);
TreatmentDao dao = DaoFactory.getInstance().createTreatmentDao(); TreatmentDao dao = DaoFactory.getInstance().createTreatmentDao();
Map<String, Treatment> treatmentsById = new HashMap<>(); Map<String, Treatment> treatmentsById = new HashMap<>();
for (Treatment treatment : treatments) { for (Treatment treatment : treatments) {
dao.create(treatment); dao.create(treatment);
}
for (Treatment treatment : dao.readAll()) {
treatmentsById.put(String.valueOf(treatment.getId()), treatment); treatmentsById.put(String.valueOf(treatment.getId()), treatment);
} }
return treatmentsById; return treatmentsById;
} }

View file

@ -74,7 +74,7 @@ public class NurseDao extends DaoImp<Nurse> {
* Read all database entries of active {@link Nurse}s into a {@link List} of model instances. * Read all database entries of active {@link Nurse}s into a {@link List} of model instances.
*/ */
public List<Nurse> readAllActive() throws SQLException { public List<Nurse> readAllActive() throws SQLException {
final String SQL = "SELECT * FROM nurse WHERE isLocked=false"; final String SQL = "SELECT * FROM nurse WHERE isLocked = false";
return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery()); return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
} }
@ -82,7 +82,7 @@ public class NurseDao extends DaoImp<Nurse> {
* Read all database entries of locked {@link Nurse}s into a {@link List} of model instances. * Read all database entries of locked {@link Nurse}s into a {@link List} of model instances.
*/ */
public List<Nurse> readAllLocked() throws SQLException { public List<Nurse> readAllLocked() throws SQLException {
final String SQL = "SELECT * FROM nurse WHERE isLocked=true"; final String SQL = "SELECT * FROM nurse WHERE isLocked = true";
return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery()); return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
} }

View file

@ -121,7 +121,7 @@ public class AllTreatmentController {
public void readAllAndShowInTableView() { public void readAllAndShowInTableView() {
this.dao = DaoFactory.getInstance().createTreatmentDao(); this.dao = DaoFactory.getInstance().createTreatmentDao();
try { try {
this.treatments.setAll(dao.readAll()); this.treatments.setAll(dao.readAllActive());
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }

View file

@ -70,7 +70,6 @@ public class LockedTreatmentController {
this.tableView.setItems(this.treatments); this.tableView.setItems(this.treatments);
handleDelete();
} }
/** /**
@ -82,11 +81,30 @@ public class LockedTreatmentController {
this.treatmentDao = DaoFactory.getInstance().createTreatmentDao(); this.treatmentDao = DaoFactory.getInstance().createTreatmentDao();
try { try {
this.treatments.addAll(this.treatmentDao.readAllLocked()); this.treatments.addAll(this.treatmentDao.readAllLocked());
deleteOldTreatments();
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
/**
* Deletes all {@link Treatment}s which are older than allowed.
*/
private void deleteOldTreatments() {
LocalDate today = LocalDate.now();
for (Treatment treatment : treatments) {
LocalDate deleteDate = treatment.calculateDeleteDate();
if (today.isEqual(deleteDate) || today.isAfter(deleteDate)) {
try {
treatmentDao.delete(treatment.getId());
} catch (SQLException exception) {
exception.printStackTrace();
}
}
}
}
@FXML @FXML
private void unlockTreatment() { private void unlockTreatment() {
Treatment selectedItem = this.tableView.getSelectionModel().getSelectedItem(); Treatment selectedItem = this.tableView.getSelectionModel().getSelectedItem();
@ -103,25 +121,6 @@ public class LockedTreatmentController {
readAllAndShowInTableView(); readAllAndShowInTableView();
} }
@FXML
public void handleDelete() {
Treatment selecteditem;
LocalDate today = LocalDate.now();
LocalDate deleteDate;
for (Treatment treatment : treatments) {
selecteditem = treatment;
deleteDate = selecteditem.calculateDeleteDate();
if (today.isEqual(deleteDate) || today.isAfter(deleteDate)) {
try {
treatmentDao.delete(selecteditem.getId());
} catch (SQLException exception) {
exception.printStackTrace();
}
}
}
readAllAndShowInTableView();
}
} }

View file

@ -1,6 +1,5 @@
package de.hitec.nhplus.treatment; package de.hitec.nhplus.treatment;
import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.nurse.Nurse; import de.hitec.nhplus.nurse.Nurse;
import de.hitec.nhplus.patient.Patient; import de.hitec.nhplus.patient.Patient;
import de.hitec.nhplus.utils.DateConverter; import de.hitec.nhplus.utils.DateConverter;
@ -11,7 +10,6 @@ import javafx.beans.property.SimpleStringProperty;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.List;
import java.util.StringJoiner; import java.util.StringJoiner;
/** /**
@ -32,7 +30,7 @@ public class Treatment {
private final SimpleStringProperty description; private final SimpleStringProperty description;
private final SimpleStringProperty remarks; private final SimpleStringProperty remarks;
private final SimpleBooleanProperty locked; private final SimpleBooleanProperty locked;
private final int sperrfrist = 10; private final static int BLOCKED_YEARS = 10;
/** /**
* This constructor allows instantiating a {@link Treatment} object, * This constructor allows instantiating a {@link Treatment} object,
@ -85,6 +83,13 @@ public class Treatment {
this.locked = new SimpleBooleanProperty(isLocked); this.locked = new SimpleBooleanProperty(isLocked);
} }
/**
* Calculates delete date of treatment.
*/
public LocalDate calculateDeleteDate() {
return DateConverter.convertStringToLocalDate(getDate()).plusYears(BLOCKED_YEARS);
}
public boolean isLocked() { public boolean isLocked() {
return locked.get(); return locked.get();
} }
@ -188,13 +193,8 @@ public class Treatment {
.add("End: " + this.getEnd()) .add("End: " + this.getEnd())
.add("Description: " + this.getDescription()) .add("Description: " + this.getDescription())
.add("Remarks: " + this.getRemarks()) .add("Remarks: " + this.getRemarks())
.add("isLocked: " + this.isLocked())
.toString(); .toString();
} }
/**
* Calculates delete date of treatment.
*/
public LocalDate calculateDeleteDate() {
return DateConverter.convertStringToLocalDate(getDate()).plusYears(sperrfrist);
}
} }

View file

@ -30,62 +30,22 @@ public class TreatmentDao extends DaoImp<Treatment> {
super(connection); super(connection);
} }
@Override /**
protected PreparedStatement getCreateStatement(Treatment treatment) throws SQLException { * Read all database entries of active {@link Treatment}s into a {@link List} of model instances.
final String SQL = """ */
INSERT INTO treatment public List<Treatment> readAllActive() throws SQLException {
(patientId, nurseId, date, begin, end, description, remark, isLocked) final String SQL = "SELECT * FROM treatment WHERE isLocked = false";
VALUES (?, ?, ?, ?, ?, ?, ?, ?) return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
""";
PreparedStatement statement = this.connection.prepareStatement(SQL);
statement.setInt(1, treatment.getPatient().getId());
statement.setInt(2, treatment.getNurse().getId());
statement.setString(3, treatment.getDate());
statement.setString(4, treatment.getBegin());
statement.setString(5, treatment.getEnd());
statement.setString(6, treatment.getDescription());
statement.setString(7, treatment.getRemarks());
statement.setBoolean(8,treatment.isLocked());
return statement;
} }
@Override /**
protected PreparedStatement getReadByIDStatement(int id) throws SQLException { * Read all database entries of locked {@link Treatment}s into a {@link Treatment} of model instances.
final String SQL = "SELECT * FROM treatment WHERE id = ?"; */
PreparedStatement statement = this.connection.prepareStatement(SQL); public List<Treatment> readAllLocked() throws SQLException {
statement.setInt(1, id); final String SQL = "SELECT * FROM treatment WHERE isLocked = true";
return statement; return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
} }
@Override
protected Treatment getInstanceFromResultSet(ResultSet result) throws SQLException {
return new Treatment(
result.getInt(1),
DaoFactory.getInstance().createPatientDAO().read(result.getInt(2)),
DaoFactory.getInstance().createNurseDAO().read(result.getInt(3)),
DateConverter.convertStringToLocalDate(result.getString(4)),
DateConverter.convertStringToLocalTime(result.getString(5)),
DateConverter.convertStringToLocalTime(result.getString(6)),
result.getString(7),
result.getString(8),
false
);
}
@Override
protected PreparedStatement getReadAllStatement() throws SQLException {
final String SQL = "SELECT * FROM treatment where isLocked = false";
return this.connection.prepareStatement(SQL);
}
@Override
protected List<Treatment> getListFromResultSet(ResultSet result) throws SQLException {
ArrayList<Treatment> list = new ArrayList<>();
while (result.next()) {
list.add(getInstanceFromResultSet(result));
}
return list;
}
/** /**
* Retrieves a list of {@link Treatment}s associated with a specific * Retrieves a list of {@link Treatment}s associated with a specific
@ -117,6 +77,63 @@ public class TreatmentDao extends DaoImp<Treatment> {
return getListFromResultSet(result); return getListFromResultSet(result);
} }
@Override
protected PreparedStatement getCreateStatement(Treatment treatment) throws SQLException {
final String SQL = """
INSERT INTO treatment
(patientId, nurseId, date, begin, end, description, remark, isLocked)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""";
PreparedStatement statement = this.connection.prepareStatement(SQL);
statement.setInt(1, treatment.getPatient().getId());
statement.setInt(2, treatment.getNurse().getId());
statement.setString(3, treatment.getDate());
statement.setString(4, treatment.getBegin());
statement.setString(5, treatment.getEnd());
statement.setString(6, treatment.getDescription());
statement.setString(7, treatment.getRemarks());
statement.setBoolean(8, treatment.isLocked());
return statement;
}
@Override
protected PreparedStatement getReadByIDStatement(int id) throws SQLException {
final String SQL = "SELECT * FROM treatment WHERE id = ?";
PreparedStatement statement = this.connection.prepareStatement(SQL);
statement.setInt(1, id);
return statement;
}
@Override
protected Treatment getInstanceFromResultSet(ResultSet result) throws SQLException {
return new Treatment(
result.getInt(1),
DaoFactory.getInstance().createPatientDAO().read(result.getInt(2)),
DaoFactory.getInstance().createNurseDAO().read(result.getInt(3)),
DateConverter.convertStringToLocalDate(result.getString(4)),
DateConverter.convertStringToLocalTime(result.getString(5)),
DateConverter.convertStringToLocalTime(result.getString(6)),
result.getString(7),
result.getString(8),
result.getBoolean(9)
);
}
@Override
protected PreparedStatement getReadAllStatement() throws SQLException {
final String SQL = "SELECT * FROM treatment";
return this.connection.prepareStatement(SQL);
}
@Override
protected List<Treatment> getListFromResultSet(ResultSet result) throws SQLException {
ArrayList<Treatment> list = new ArrayList<>();
while (result.next()) {
list.add(getInstanceFromResultSet(result));
}
return list;
}
@Override @Override
protected PreparedStatement getUpdateStatement(Treatment treatment) throws SQLException { protected PreparedStatement getUpdateStatement(Treatment treatment) throws SQLException {
final String SQL = """ final String SQL = """
@ -135,7 +152,7 @@ public class TreatmentDao extends DaoImp<Treatment> {
statement.setString(3, treatment.getEnd()); statement.setString(3, treatment.getEnd());
statement.setString(4, treatment.getDescription()); statement.setString(4, treatment.getDescription());
statement.setString(5, treatment.getRemarks()); statement.setString(5, treatment.getRemarks());
statement.setBoolean(6,treatment.isLocked()); statement.setBoolean(6, treatment.isLocked());
statement.setInt(7, treatment.getId()); statement.setInt(7, treatment.getId());
return statement; return statement;
} }
@ -149,11 +166,4 @@ public class TreatmentDao extends DaoImp<Treatment> {
return statement; return statement;
} }
/**
* Returns all locked treatments.
*/
public List<Treatment> readAllLocked() throws SQLException {
final String SQL = "SELECT * FROM treatment WHERE isLocked = true";
return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
}
} }

View file

@ -40,9 +40,8 @@
fx:id="columnDeleteDate" fx:id="columnDeleteDate"
minWidth="40.0" minWidth="40.0"
prefWidth="102.0" prefWidth="102.0"
text="Geloescht am" text="Löschung am"
/> />
</columns> </columns>
<columnResizePolicy> <columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/> <TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>