#7 Cleanup
This commit is contained in:
parent
f77072ab70
commit
970f167bc3
8 changed files with 125 additions and 132 deletions
Binary file not shown.
|
@ -58,7 +58,6 @@ public class TreatmentFixture implements Fixture<Treatment> {
|
|||
Nurse armin = nursesByName.get("Armin");
|
||||
|
||||
treatments.add(new Treatment(
|
||||
1,
|
||||
seppl,
|
||||
ole,
|
||||
convertStringToLocalDate("2023-06-03"),
|
||||
|
@ -67,11 +66,9 @@ public class TreatmentFixture implements Fixture<Treatment> {
|
|||
"Gespräch",
|
||||
"Der Patient hat enorme Angstgefühle und glaubt, er sei überfallen worden."
|
||||
+ "Ihm seien alle Wertsachen gestohlen worden."
|
||||
+ "Patient beruhigt sich erst, als alle Wertsachen im Zimmer gefunden worden sind.",
|
||||
false
|
||||
+ "Patient beruhigt sich erst, als alle Wertsachen im Zimmer gefunden worden sind."
|
||||
));
|
||||
treatments.add(new Treatment(
|
||||
2,
|
||||
seppl,
|
||||
armin,
|
||||
convertStringToLocalDate("2023-06-05"),
|
||||
|
@ -80,102 +77,92 @@ public class TreatmentFixture implements Fixture<Treatment> {
|
|||
"Gespräch",
|
||||
"Patient irrt auf der Suche nach gestohlenen Wertsachen durch die Etage "
|
||||
+ "und bezichtigt andere Bewohner des Diebstahls."
|
||||
+ "Patient wird in seinen Raum zurückbegleitet und erhält Beruhigungsmittel.",
|
||||
false
|
||||
+ "Patient wird in seinen Raum zurückbegleitet und erhält Beruhigungsmittel."
|
||||
));
|
||||
treatments.add(new Treatment(
|
||||
3,
|
||||
martina,
|
||||
ole,
|
||||
convertStringToLocalDate("2023-06-04"),
|
||||
convertStringToLocalTime("07:30"),
|
||||
convertStringToLocalTime("08:00"),
|
||||
"Waschen",
|
||||
"Patient mit Waschlappen gewaschen und frisch angezogen. Patient gewendet.",
|
||||
false
|
||||
"Patient mit Waschlappen gewaschen und frisch angezogen. Patient gewendet."
|
||||
));
|
||||
treatments.add(new Treatment(
|
||||
4,
|
||||
seppl,
|
||||
armin,
|
||||
convertStringToLocalDate("2023-06-06"),
|
||||
convertStringToLocalTime("15:10"),
|
||||
convertStringToLocalTime("16:00"),
|
||||
"Spaziergang",
|
||||
"Spaziergang im Park, Patient döst im Rollstuhl ein",
|
||||
false)
|
||||
);
|
||||
"Spaziergang im Park, Patient döst im Rollstuhl ein"
|
||||
|
||||
));
|
||||
treatments.add(new Treatment(
|
||||
8,
|
||||
seppl,
|
||||
ole,
|
||||
convertStringToLocalDate("2023-06-08"),
|
||||
convertStringToLocalTime("15:00"),
|
||||
convertStringToLocalTime("16:00"),
|
||||
"Spaziergang",
|
||||
"Parkspaziergang; Patient ist heute lebhafter und hat klare Momente; erzählt von seiner Tochter",
|
||||
false)
|
||||
);
|
||||
"Parkspaziergang; Patient ist heute lebhafter und hat klare Momente; erzählt von seiner Tochter"
|
||||
));
|
||||
treatments.add(new Treatment(
|
||||
9,
|
||||
martina,
|
||||
armin,
|
||||
convertStringToLocalDate("2023-06-07"),
|
||||
convertStringToLocalTime("11:00"),
|
||||
convertStringToLocalTime("11:30"),
|
||||
"Waschen",
|
||||
"Waschen per Dusche auf einem Stuhl; Patientin gewendet;",
|
||||
false)
|
||||
);
|
||||
"Waschen per Dusche auf einem Stuhl; Patientin gewendet;"
|
||||
));
|
||||
treatments.add(new Treatment(
|
||||
12,
|
||||
hans,
|
||||
armin,
|
||||
convertStringToLocalDate("2023-06-08"),
|
||||
convertStringToLocalTime("15:00"),
|
||||
convertStringToLocalTime("15:30"),
|
||||
"Physiotherapie",
|
||||
"Übungen zur Stabilisation und Mobilisierung der Rückenmuskulatur",
|
||||
false)
|
||||
);
|
||||
"Übungen zur Stabilisation und Mobilisierung der Rückenmuskulatur"
|
||||
));
|
||||
treatments.add(new Treatment(
|
||||
14,
|
||||
ahmet,
|
||||
ole,
|
||||
convertStringToLocalDate("2023-08-24"),
|
||||
convertStringToLocalTime("09:30"),
|
||||
convertStringToLocalTime("10:15"),
|
||||
"KG",
|
||||
"Lympfdrainage",
|
||||
false));
|
||||
"Lympfdrainage"
|
||||
));
|
||||
treatments.add(new Treatment(
|
||||
16,
|
||||
elisabeth,
|
||||
armin,
|
||||
convertStringToLocalDate("2023-08-31"),
|
||||
convertStringToLocalTime("13:30"),
|
||||
convertStringToLocalTime("13:45"),
|
||||
"Toilettengang",
|
||||
"Hilfe beim Toilettengang; Patientin klagt über Schmerzen beim Stuhlgang. Gabe von Iberogast",
|
||||
false)
|
||||
);
|
||||
treatments.add(new Treatment(
|
||||
17,
|
||||
"Hilfe beim Toilettengang; Patientin klagt über Schmerzen beim Stuhlgang. Gabe von Iberogast"
|
||||
));
|
||||
Treatment lockedTreatment = new Treatment(
|
||||
elisabeth,
|
||||
ole,
|
||||
convertStringToLocalDate("2023-09-01"),
|
||||
convertStringToLocalTime("16:00"),
|
||||
convertStringToLocalTime("17:00"),
|
||||
"KG",
|
||||
"Massage der Extremitäten zur Verbesserung der Durchblutung",
|
||||
true)
|
||||
"Massage der Extremitäten zur Verbesserung der Durchblutung"
|
||||
);
|
||||
lockedTreatment.setLocked(true);
|
||||
treatments.add(lockedTreatment);
|
||||
|
||||
TreatmentDao dao = DaoFactory.getInstance().createTreatmentDao();
|
||||
Map<String, Treatment> treatmentsById = new HashMap<>();
|
||||
for (Treatment treatment : treatments) {
|
||||
dao.create(treatment);
|
||||
}
|
||||
for (Treatment treatment : dao.readAll()) {
|
||||
treatmentsById.put(String.valueOf(treatment.getId()), treatment);
|
||||
|
||||
}
|
||||
return treatmentsById;
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ public class AllTreatmentController {
|
|||
public void readAllAndShowInTableView() {
|
||||
this.dao = DaoFactory.getInstance().createTreatmentDao();
|
||||
try {
|
||||
this.treatments.setAll(dao.readAll());
|
||||
this.treatments.setAll(dao.readAllActive());
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -70,7 +70,6 @@ public class LockedTreatmentController {
|
|||
|
||||
|
||||
this.tableView.setItems(this.treatments);
|
||||
handleDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,11 +81,30 @@ public class LockedTreatmentController {
|
|||
this.treatmentDao = DaoFactory.getInstance().createTreatmentDao();
|
||||
try {
|
||||
this.treatments.addAll(this.treatmentDao.readAllLocked());
|
||||
deleteOldTreatments();
|
||||
} catch (SQLException exception) {
|
||||
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
|
||||
private void unlockTreatment() {
|
||||
Treatment selectedItem = this.tableView.getSelectionModel().getSelectedItem();
|
||||
|
@ -103,25 +121,4 @@ public class LockedTreatmentController {
|
|||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package de.hitec.nhplus.treatment;
|
||||
|
||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||
import de.hitec.nhplus.nurse.Nurse;
|
||||
import de.hitec.nhplus.patient.Patient;
|
||||
import de.hitec.nhplus.utils.DateConverter;
|
||||
|
@ -11,7 +10,6 @@ import javafx.beans.property.SimpleStringProperty;
|
|||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +30,7 @@ public class Treatment {
|
|||
private final SimpleStringProperty description;
|
||||
private final SimpleStringProperty remarks;
|
||||
private final SimpleBooleanProperty locked;
|
||||
private final int sperrfrist = 10;
|
||||
private final static int BLOCKED_YEARS = 10;
|
||||
|
||||
/**
|
||||
* This constructor allows instantiating a {@link Treatment} object,
|
||||
|
@ -85,6 +83,13 @@ public class Treatment {
|
|||
this.locked = new SimpleBooleanProperty(isLocked);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates delete date of treatment.
|
||||
*/
|
||||
public LocalDate calculateDeleteDate() {
|
||||
return DateConverter.convertStringToLocalDate(getDate()).plusYears(BLOCKED_YEARS);
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked.get();
|
||||
}
|
||||
|
@ -188,13 +193,8 @@ public class Treatment {
|
|||
.add("End: " + this.getEnd())
|
||||
.add("Description: " + this.getDescription())
|
||||
.add("Remarks: " + this.getRemarks())
|
||||
.add("isLocked: " + this.isLocked())
|
||||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates delete date of treatment.
|
||||
*/
|
||||
public LocalDate calculateDeleteDate() {
|
||||
return DateConverter.convertStringToLocalDate(getDate()).plusYears(sperrfrist);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,53 @@ public class TreatmentDao extends DaoImp<Treatment> {
|
|||
super(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all database entries of active {@link Treatment}s into a {@link List} of model instances.
|
||||
*/
|
||||
public List<Treatment> readAllActive() throws SQLException {
|
||||
final String SQL = "SELECT * FROM treatment WHERE isLocked = false";
|
||||
return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all database entries of locked {@link Treatment}s into a {@link Treatment} of model instances.
|
||||
*/
|
||||
public List<Treatment> readAllLocked() throws SQLException {
|
||||
final String SQL = "SELECT * FROM treatment WHERE isLocked = true";
|
||||
return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves a list of {@link Treatment}s associated with a specific
|
||||
* {@link Patient#id patient ID} from the database.
|
||||
*
|
||||
* @param patientId The {@link Patient#id ID} of the {@link Patient} whose {@link Treatment}s are to be retrieved.
|
||||
* @return A {@link List} of {@link Treatment} objects associated with the specified {@link Patient} ID.
|
||||
*/
|
||||
public List<Treatment> readTreatmentsByPatient(int patientId) throws SQLException {
|
||||
final String SQL = "SELECT * FROM treatment WHERE patientId = ?";
|
||||
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
||||
statement.setInt(1, patientId);
|
||||
ResultSet result = statement.executeQuery();
|
||||
return getListFromResultSet(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of {@link Treatment}s associated with a specific
|
||||
* {@link Nurse#id patient ID} from the database.
|
||||
*
|
||||
* @param nurseId The {@link Nurse#id ID} of the {@link Nurse} whose {@link Treatment}s are to be retrieved.
|
||||
* @return A {@link List} of {@link Treatment} objects associated with the specified {@link Nurse} ID.
|
||||
*/
|
||||
public List<Treatment> readTreatmentsByNurse(int nurseId) throws SQLException {
|
||||
final String SQL = "SELECT * FROM treatment WHERE nurseId = ?";
|
||||
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
||||
statement.setInt(1, nurseId);
|
||||
ResultSet result = statement.executeQuery();
|
||||
return getListFromResultSet(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getCreateStatement(Treatment treatment) throws SQLException {
|
||||
final String SQL = """
|
||||
|
@ -68,13 +115,13 @@ public class TreatmentDao extends DaoImp<Treatment> {
|
|||
DateConverter.convertStringToLocalTime(result.getString(6)),
|
||||
result.getString(7),
|
||||
result.getString(8),
|
||||
false
|
||||
result.getBoolean(9)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getReadAllStatement() throws SQLException {
|
||||
final String SQL = "SELECT * FROM treatment where isLocked = false";
|
||||
final String SQL = "SELECT * FROM treatment";
|
||||
return this.connection.prepareStatement(SQL);
|
||||
}
|
||||
|
||||
|
@ -87,36 +134,6 @@ public class TreatmentDao extends DaoImp<Treatment> {
|
|||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of {@link Treatment}s associated with a specific
|
||||
* {@link Patient#id patient ID} from the database.
|
||||
*
|
||||
* @param patientId The {@link Patient#id ID} of the {@link Patient} whose {@link Treatment}s are to be retrieved.
|
||||
* @return A {@link List} of {@link Treatment} objects associated with the specified {@link Patient} ID.
|
||||
*/
|
||||
public List<Treatment> readTreatmentsByPatient(int patientId) throws SQLException {
|
||||
final String SQL = "SELECT * FROM treatment WHERE patientId = ?";
|
||||
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
||||
statement.setInt(1, patientId);
|
||||
ResultSet result = statement.executeQuery();
|
||||
return getListFromResultSet(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of {@link Treatment}s associated with a specific
|
||||
* {@link Nurse#id patient ID} from the database.
|
||||
*
|
||||
* @param nurseId The {@link Nurse#id ID} of the {@link Nurse} whose {@link Treatment}s are to be retrieved.
|
||||
* @return A {@link List} of {@link Treatment} objects associated with the specified {@link Nurse} ID.
|
||||
*/
|
||||
public List<Treatment> readTreatmentsByNurse(int nurseId) throws SQLException {
|
||||
final String SQL = "SELECT * FROM treatment WHERE nurseId = ?";
|
||||
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
||||
statement.setInt(1, nurseId);
|
||||
ResultSet result = statement.executeQuery();
|
||||
return getListFromResultSet(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getUpdateStatement(Treatment treatment) throws SQLException {
|
||||
final String SQL = """
|
||||
|
@ -149,11 +166,4 @@ public class TreatmentDao extends DaoImp<Treatment> {
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,9 +40,8 @@
|
|||
fx:id="columnDeleteDate"
|
||||
minWidth="40.0"
|
||||
prefWidth="102.0"
|
||||
text="Geloescht am"
|
||||
text="Löschung am"
|
||||
/>
|
||||
|
||||
</columns>
|
||||
<columnResizePolicy>
|
||||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
|
||||
|
|
Loading…
Reference in a new issue