#7 Cleanup
This commit is contained in:
parent
3c1445f430
commit
48720fa779
5 changed files with 104 additions and 107 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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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,62 +30,22 @@ public class TreatmentDao extends DaoImp<Treatment> {
|
|||
super(connection);
|
||||
}
|
||||
|
||||
@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;
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
@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;
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
@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
|
||||
|
@ -117,6 +77,63 @@ public class TreatmentDao extends DaoImp<Treatment> {
|
|||
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
|
||||
protected PreparedStatement getUpdateStatement(Treatment treatment) throws SQLException {
|
||||
final String SQL = """
|
||||
|
@ -135,7 +152,7 @@ public class TreatmentDao extends DaoImp<Treatment> {
|
|||
statement.setString(3, treatment.getEnd());
|
||||
statement.setString(4, treatment.getDescription());
|
||||
statement.setString(5, treatment.getRemarks());
|
||||
statement.setBoolean(6,treatment.isLocked());
|
||||
statement.setBoolean(6, treatment.isLocked());
|
||||
statement.setInt(7, treatment.getId());
|
||||
return statement;
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue