task/#17 Treatement -> Nurse Relation #36
6 changed files with 72 additions and 38 deletions
Binary file not shown.
|
@ -1,6 +1,7 @@
|
|||
package de.hitec.nhplus.fixtures;
|
||||
|
||||
import de.hitec.nhplus.datastorage.ConnectionBuilder;
|
||||
import de.hitec.nhplus.nurse.Nurse;
|
||||
import de.hitec.nhplus.patient.Patient;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
@ -28,15 +29,17 @@ public class Fixtures {
|
|||
patientFixture.setupTable(connection);
|
||||
Map<String, Patient> patientsByName = patientFixture.load();
|
||||
|
||||
TreatmentFixture treatmentFixture = new TreatmentFixture(patientsByName);
|
||||
NurseFixture nurseFixture = new NurseFixture();
|
||||
nurseFixture.dropTable(connection);
|
||||
nurseFixture.setupTable(connection);
|
||||
Map<String, Nurse> nursesByName = nurseFixture.load();
|
||||
|
||||
|
||||
TreatmentFixture treatmentFixture = new TreatmentFixture(patientsByName, nursesByName);
|
||||
treatmentFixture.dropTable(connection);
|
||||
treatmentFixture.setupTable(connection);
|
||||
treatmentFixture.load();
|
||||
|
||||
NurseFixture nurseFixture = new NurseFixture();
|
||||
nurseFixture.dropTable(connection);
|
||||
nurseFixture.setupTable(connection);
|
||||
nurseFixture.load();
|
||||
|
||||
MedicationFixture medicationFixture = new MedicationFixture();
|
||||
medicationFixture.dropTable(connection);
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.hitec.nhplus.fixtures;
|
|||
|
||||
import de.hitec.nhplus.Main;
|
||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||
import de.hitec.nhplus.nurse.Nurse;
|
||||
import de.hitec.nhplus.patient.Patient;
|
||||
import de.hitec.nhplus.treatment.Treatment;
|
||||
import de.hitec.nhplus.treatment.database.TreatmentDao;
|
||||
|
@ -17,9 +18,11 @@ import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalTime;
|
|||
|
||||
public class TreatmentFixture implements Fixture<Treatment> {
|
||||
private final Map<String, Patient> patientsByName;
|
||||
private final Map<String, Nurse> nursesByName;
|
||||
|
||||
public TreatmentFixture(Map<String, Patient> patientsByName) {
|
||||
public TreatmentFixture(Map<String, Patient> patientsByName, Map<String, Nurse> nursesByName) {
|
||||
this.patientsByName = patientsByName;
|
||||
this.nursesByName = nursesByName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,9 +48,13 @@ public class TreatmentFixture implements Fixture<Treatment> {
|
|||
Patient ahmet = patientsByName.get("Ahmet");
|
||||
Patient elisabeth = patientsByName.get("Elisabeth");
|
||||
|
||||
Nurse ole = nursesByName.get("Ole");
|
||||
Nurse armin = nursesByName.get("Armin");
|
||||
|
||||
treatments.add(new Treatment(
|
||||
1,
|
||||
seppl,
|
||||
ole,
|
||||
convertStringToLocalDate("2023-06-03"),
|
||||
convertStringToLocalTime("11:00"),
|
||||
convertStringToLocalTime("15:00"),
|
||||
|
@ -59,6 +66,7 @@ public class TreatmentFixture implements Fixture<Treatment> {
|
|||
treatments.add(new Treatment(
|
||||
2,
|
||||
seppl,
|
||||
armin,
|
||||
convertStringToLocalDate("2023-06-05"),
|
||||
convertStringToLocalTime("11:00"),
|
||||
convertStringToLocalTime("12:30"),
|
||||
|
@ -70,6 +78,7 @@ public class TreatmentFixture implements Fixture<Treatment> {
|
|||
treatments.add(new Treatment(
|
||||
3,
|
||||
martina,
|
||||
ole,
|
||||
convertStringToLocalDate("2023-06-04"),
|
||||
convertStringToLocalTime("07:30"),
|
||||
convertStringToLocalTime("08:00"),
|
||||
|
@ -79,6 +88,7 @@ public class TreatmentFixture implements Fixture<Treatment> {
|
|||
treatments.add(new Treatment(
|
||||
4,
|
||||
seppl,
|
||||
armin,
|
||||
convertStringToLocalDate("2023-06-06"),
|
||||
convertStringToLocalTime("15:10"),
|
||||
convertStringToLocalTime("16:00"),
|
||||
|
@ -88,6 +98,7 @@ public class TreatmentFixture implements Fixture<Treatment> {
|
|||
treatments.add(new Treatment(
|
||||
8,
|
||||
seppl,
|
||||
ole,
|
||||
convertStringToLocalDate("2023-06-08"),
|
||||
convertStringToLocalTime("15:00"),
|
||||
convertStringToLocalTime("16:00"),
|
||||
|
@ -97,6 +108,7 @@ public class TreatmentFixture implements Fixture<Treatment> {
|
|||
treatments.add(new Treatment(
|
||||
9,
|
||||
martina,
|
||||
armin,
|
||||
convertStringToLocalDate("2023-06-07"),
|
||||
convertStringToLocalTime("11:00"),
|
||||
convertStringToLocalTime("11:30"),
|
||||
|
@ -106,6 +118,7 @@ public class TreatmentFixture implements Fixture<Treatment> {
|
|||
treatments.add(new Treatment(
|
||||
12,
|
||||
hans,
|
||||
armin,
|
||||
convertStringToLocalDate("2023-06-08"),
|
||||
convertStringToLocalTime("15:00"),
|
||||
convertStringToLocalTime("15:30"),
|
||||
|
@ -115,6 +128,7 @@ public class TreatmentFixture implements Fixture<Treatment> {
|
|||
treatments.add(new Treatment(
|
||||
14,
|
||||
ahmet,
|
||||
ole,
|
||||
convertStringToLocalDate("2023-08-24"),
|
||||
convertStringToLocalTime("09:30"),
|
||||
convertStringToLocalTime("10:15"),
|
||||
|
@ -123,6 +137,7 @@ public class TreatmentFixture implements Fixture<Treatment> {
|
|||
treatments.add(new Treatment(
|
||||
16,
|
||||
elisabeth,
|
||||
armin,
|
||||
convertStringToLocalDate("2023-08-31"),
|
||||
convertStringToLocalTime("13:30"),
|
||||
convertStringToLocalTime("13:45"),
|
||||
|
@ -132,6 +147,7 @@ public class TreatmentFixture implements Fixture<Treatment> {
|
|||
treatments.add(new Treatment(
|
||||
17,
|
||||
elisabeth,
|
||||
ole,
|
||||
convertStringToLocalDate("2023-09-01"),
|
||||
convertStringToLocalTime("16:00"),
|
||||
convertStringToLocalTime("17:00"),
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.hitec.nhplus.treatment;
|
||||
|
||||
import de.hitec.nhplus.nurse.Nurse;
|
||||
import de.hitec.nhplus.patient.Patient;
|
||||
import de.hitec.nhplus.utils.DateConverter;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
|
@ -13,16 +14,17 @@ import java.util.StringJoiner;
|
|||
public class Treatment {
|
||||
private SimpleIntegerProperty id;
|
||||
private final SimpleObjectProperty<Patient> patient;
|
||||
private final SimpleObjectProperty<Nurse> nurse;
|
||||
private final SimpleObjectProperty<LocalDate> date;
|
||||
private final SimpleObjectProperty<LocalTime> begin;
|
||||
private final SimpleObjectProperty<LocalTime> end;
|
||||
private final SimpleStringProperty description;
|
||||
private final SimpleStringProperty remarks;
|
||||
//TODO: Add Nurse
|
||||
|
||||
public Treatment(Patient patient, LocalDate date, LocalTime begin,
|
||||
public Treatment(Patient patient, Nurse nurse, LocalDate date, LocalTime begin,
|
||||
LocalTime end, String description, String remarks) {
|
||||
this.patient = new SimpleObjectProperty<>(patient);
|
||||
this.nurse = new SimpleObjectProperty<>(nurse);
|
||||
this.date = new SimpleObjectProperty<>(date);
|
||||
this.begin = new SimpleObjectProperty<>(begin);
|
||||
this.end = new SimpleObjectProperty<>(end);
|
||||
|
@ -30,10 +32,11 @@ public class Treatment {
|
|||
this.remarks = new SimpleStringProperty(remarks);
|
||||
}
|
||||
|
||||
public Treatment(int id, Patient patient, LocalDate date, LocalTime begin,
|
||||
public Treatment(int id, Patient patient, Nurse nurse, LocalDate date, LocalTime begin,
|
||||
LocalTime end, String description, String remarks) {
|
||||
this.id = new SimpleIntegerProperty(id);
|
||||
this.patient = new SimpleObjectProperty<>(patient);
|
||||
this.nurse = new SimpleObjectProperty<>(nurse);
|
||||
this.date = new SimpleObjectProperty<>(date);
|
||||
this.begin = new SimpleObjectProperty<>(begin);
|
||||
this.end = new SimpleObjectProperty<>(end);
|
||||
|
@ -49,6 +52,10 @@ public class Treatment {
|
|||
return patient.getValue();
|
||||
}
|
||||
|
||||
public Nurse getNurse() {
|
||||
return nurse.getValue();
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date.getValue().toString();
|
||||
}
|
||||
|
@ -89,6 +96,10 @@ public class Treatment {
|
|||
return patient;
|
||||
}
|
||||
|
||||
public SimpleObjectProperty<Nurse> nurseProperty() {
|
||||
return nurse;
|
||||
}
|
||||
|
||||
public SimpleObjectProperty<LocalDate> dateProperty() {
|
||||
return date;
|
||||
}
|
||||
|
@ -118,6 +129,7 @@ public class Treatment {
|
|||
.add("TREATMENT")
|
||||
.add("ID: " + this.getId())
|
||||
.add("Patient: " + this.getPatient().getSurName() + ", " + this.getPatient().getFirstName())
|
||||
.add("Nurse: " + this.getNurse().getSurName() + ", " + this.getNurse().getFirstName())
|
||||
.add("Date: " + this.getDate())
|
||||
.add("Begin: " + this.getBegin())
|
||||
.add("End: " + this.getEnd())
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.hitec.nhplus.treatment.database;
|
|||
|
||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||
import de.hitec.nhplus.datastorage.DaoImp;
|
||||
import de.hitec.nhplus.nurse.Nurse;
|
||||
import de.hitec.nhplus.treatment.Treatment;
|
||||
import de.hitec.nhplus.utils.DateConverter;
|
||||
|
||||
|
@ -12,7 +13,6 @@ import java.sql.SQLException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
//TODO: Update Methods to use a new Nurse Field (cascade this to any class using this DAO)
|
||||
public class TreatmentDao extends DaoImp<Treatment> {
|
||||
|
||||
public TreatmentDao(Connection connection) {
|
||||
|
@ -23,16 +23,17 @@ public class TreatmentDao extends DaoImp<Treatment> {
|
|||
protected PreparedStatement getCreateStatement(Treatment treatment) throws SQLException {
|
||||
final String SQL = """
|
||||
INSERT INTO treatment
|
||||
(patientId, date, begin, end, description, remark)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
(patientId, nurseId, date, begin, end, description, remark)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
""";
|
||||
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
||||
statement.setInt(1, treatment.getPatient().getId());
|
||||
statement.setString(2, treatment.getDate());
|
||||
statement.setString(3, treatment.getBegin());
|
||||
statement.setString(4, treatment.getEnd());
|
||||
statement.setString(5, treatment.getDescription());
|
||||
statement.setString(6, treatment.getRemarks());
|
||||
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());
|
||||
return statement;
|
||||
}
|
||||
|
||||
|
@ -49,11 +50,12 @@ public class TreatmentDao extends DaoImp<Treatment> {
|
|||
return new Treatment(
|
||||
result.getInt(1),
|
||||
DaoFactory.getInstance().createPatientDAO().read(result.getInt(2)),
|
||||
DateConverter.convertStringToLocalDate(result.getString(3)),
|
||||
DateConverter.convertStringToLocalTime(result.getString(4)),
|
||||
DaoFactory.getInstance().createNurseDAO().read(result.getInt(3)),
|
||||
DateConverter.convertStringToLocalDate(result.getString(4)),
|
||||
DateConverter.convertStringToLocalTime(result.getString(5)),
|
||||
result.getString(6),
|
||||
result.getString(7)
|
||||
DateConverter.convertStringToLocalTime(result.getString(6)),
|
||||
result.getString(7),
|
||||
result.getString(8)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -72,25 +74,26 @@ public class TreatmentDao extends DaoImp<Treatment> {
|
|||
return list;
|
||||
}
|
||||
|
||||
private PreparedStatement getReadAllTreatmentsOfOnePatientByPid(int patientId) throws SQLException {
|
||||
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);
|
||||
return statement;
|
||||
}
|
||||
|
||||
public List<Treatment> readTreatmentsByPid(int patientId) throws SQLException {
|
||||
ResultSet result = getReadAllTreatmentsOfOnePatientByPid(patientId).executeQuery();
|
||||
ResultSet result = statement.executeQuery();
|
||||
return getListFromResultSet(result);
|
||||
}
|
||||
|
||||
//TODO: readTreatmentsByNurse
|
||||
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 = """
|
||||
UPDATE treatment SET
|
||||
patientId = ?,
|
||||
date = ?,
|
||||
begin = ?,
|
||||
end = ?,
|
||||
|
@ -99,13 +102,12 @@ public class TreatmentDao extends DaoImp<Treatment> {
|
|||
WHERE id = ?
|
||||
""";
|
||||
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
||||
statement.setInt(1, treatment.getPatient().getId());
|
||||
statement.setString(2, treatment.getDate());
|
||||
statement.setString(3, treatment.getBegin());
|
||||
statement.setString(4, treatment.getEnd());
|
||||
statement.setString(5, treatment.getDescription());
|
||||
statement.setString(6, treatment.getRemarks());
|
||||
statement.setInt(7, treatment.getId());
|
||||
statement.setString(1, treatment.getDate());
|
||||
statement.setString(2, treatment.getBegin());
|
||||
statement.setString(3, treatment.getEnd());
|
||||
statement.setString(4, treatment.getDescription());
|
||||
statement.setString(5, treatment.getRemarks());
|
||||
statement.setInt(6, treatment.getId());
|
||||
return statement;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,11 +2,12 @@ CREATE TABLE treatment
|
|||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
patientId INTEGER NOT NULL,
|
||||
nurseId 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
|
||||
-- TODO: Add Nurse
|
||||
FOREIGN KEY (patientId) REFERENCES patient (id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (nurseId) REFERENCES nurse (id) ON DELETE SET NULL
|
||||
)
|
Loading…
Reference in a new issue