NOTICKET: Add Treatment Module Javadoc
This commit is contained in:
parent
87cf330dce
commit
797dd69f63
4 changed files with 161 additions and 98 deletions
|
@ -20,6 +20,12 @@ import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The controller for viewing all {@link Treatment}s.
|
||||||
|
*
|
||||||
|
* @author Bernd Heideman
|
||||||
|
* @author Dominik Säume
|
||||||
|
*/
|
||||||
public class AllTreatmentController {
|
public class AllTreatmentController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -54,6 +60,10 @@ public class AllTreatmentController {
|
||||||
private final ObservableList<String> patientSelection = FXCollections.observableArrayList();
|
private final ObservableList<String> patientSelection = FXCollections.observableArrayList();
|
||||||
private ArrayList<Patient> patientList;
|
private ArrayList<Patient> patientList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialization method that is called after the binding of all the fields.
|
||||||
|
*/
|
||||||
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
readAllAndShowInTableView();
|
readAllAndShowInTableView();
|
||||||
comboBoxPatientSelection.setItems(patientSelection);
|
comboBoxPatientSelection.setItems(patientSelection);
|
||||||
|
@ -83,6 +93,9 @@ public class AllTreatmentController {
|
||||||
this.createComboBoxData();
|
this.createComboBoxData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal method to read all data and set it to the table view.
|
||||||
|
*/
|
||||||
public void readAllAndShowInTableView() {
|
public void readAllAndShowInTableView() {
|
||||||
comboBoxPatientSelection.getSelectionModel().select(0);
|
comboBoxPatientSelection.getSelectionModel().select(0);
|
||||||
this.dao = DaoFactory.getInstance().createTreatmentDao();
|
this.dao = DaoFactory.getInstance().createTreatmentDao();
|
||||||
|
@ -93,6 +106,9 @@ public class AllTreatmentController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal method to create the data set for the combobox that is used for creating a new {@link Treatment}.
|
||||||
|
*/
|
||||||
private void createComboBoxData() {
|
private void createComboBoxData() {
|
||||||
PatientDao dao = DaoFactory.getInstance().createPatientDAO();
|
PatientDao dao = DaoFactory.getInstance().createPatientDAO();
|
||||||
try {
|
try {
|
||||||
|
@ -106,6 +122,78 @@ public class AllTreatmentController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal method to get the {@link Patient} object by its surname.
|
||||||
|
*
|
||||||
|
* @see AllTreatmentController#handleComboBox
|
||||||
|
* @see AllTreatmentController#handleNewTreatment
|
||||||
|
*/
|
||||||
|
private Patient searchInList(String surname) {
|
||||||
|
for (Patient patient : this.patientList) {
|
||||||
|
if (patient.getSurName().equals(surname)) {
|
||||||
|
return patient;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal method to create a {@link TreatmentModalController TreatmentModal}.
|
||||||
|
*
|
||||||
|
* @param treatment The {@link Treatment} which should be edited. Set null to create a new one.
|
||||||
|
* @param title The Title of the created modal.
|
||||||
|
* @param patient The {@link Patient} whose {@link Treatment} this is.
|
||||||
|
*/
|
||||||
|
public void treatmentWindow(Treatment treatment, String title, Patient patient) {
|
||||||
|
try {
|
||||||
|
FXMLLoader loader = new FXMLLoader(
|
||||||
|
Main.class.getResource("/de/hitec/nhplus/treatment/TreatmentModal.fxml")
|
||||||
|
);
|
||||||
|
BorderPane pane = loader.load();
|
||||||
|
Scene scene = new Scene(pane);
|
||||||
|
Stage stage = new Stage();
|
||||||
|
|
||||||
|
TreatmentModalController controller = loader.getController();
|
||||||
|
controller.initialize(
|
||||||
|
this,
|
||||||
|
stage,
|
||||||
|
treatment,
|
||||||
|
patient
|
||||||
|
);
|
||||||
|
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.setTitle(title);
|
||||||
|
stage.setResizable(true);
|
||||||
|
stage.setAlwaysOnTop(true);
|
||||||
|
stage.showAndWait();
|
||||||
|
} catch (IOException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to create a new {@link Treatment}.
|
||||||
|
*/
|
||||||
|
protected void createTreatment(Treatment treatment) {
|
||||||
|
TreatmentDao dao = DaoFactory.getInstance().createTreatmentDao();
|
||||||
|
try {
|
||||||
|
dao.create(treatment);
|
||||||
|
} catch (SQLException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to save the changes to a {@link Treatment}.
|
||||||
|
*/
|
||||||
|
protected void updateTreatment(Treatment treatment) {
|
||||||
|
TreatmentDao dao = DaoFactory.getInstance().createTreatmentDao();
|
||||||
|
try {
|
||||||
|
dao.update(treatment);
|
||||||
|
} catch (SQLException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void handleComboBox() {
|
public void handleComboBox() {
|
||||||
|
@ -131,14 +219,6 @@ public class AllTreatmentController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Patient searchInList(String surname) {
|
|
||||||
for (Patient patient : this.patientList) {
|
|
||||||
if (patient.getSurName().equals(surname)) {
|
|
||||||
return patient;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void handleDelete() {
|
public void handleDelete() {
|
||||||
|
@ -157,7 +237,7 @@ public class AllTreatmentController {
|
||||||
try {
|
try {
|
||||||
String selectedPatient = this.comboBoxPatientSelection.getSelectionModel().getSelectedItem();
|
String selectedPatient = this.comboBoxPatientSelection.getSelectionModel().getSelectedItem();
|
||||||
Patient patient = searchInList(selectedPatient);
|
Patient patient = searchInList(selectedPatient);
|
||||||
newTreatmentWindow(patient);
|
treatmentWindow(null, "NHPlus - Neue Behandlung", patient);
|
||||||
} catch (NullPointerException exception) {
|
} catch (NullPointerException exception) {
|
||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||||
alert.setTitle("Information");
|
alert.setTitle("Information");
|
||||||
|
@ -174,81 +254,18 @@ public class AllTreatmentController {
|
||||||
if (event.getClickCount() == 2 && (tableView.getSelectionModel().getSelectedItem() != null)) {
|
if (event.getClickCount() == 2 && (tableView.getSelectionModel().getSelectedItem() != null)) {
|
||||||
int index = this.tableView.getSelectionModel().getSelectedIndex();
|
int index = this.tableView.getSelectionModel().getSelectedIndex();
|
||||||
Treatment treatment = this.treatments.get(index);
|
Treatment treatment = this.treatments.get(index);
|
||||||
treatmentWindow(treatment);
|
try {
|
||||||
|
treatmentWindow(
|
||||||
|
treatment,
|
||||||
|
"NHPlus - Behandlung",
|
||||||
|
DaoFactory.getInstance().createPatientDAO().read(
|
||||||
|
treatment.getPatient().getId()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void newTreatmentWindow(Patient patient) {
|
|
||||||
try {
|
|
||||||
FXMLLoader loader = new FXMLLoader(
|
|
||||||
Main.class.getResource("/de/hitec/nhplus/treatment/TreatmentModal.fxml")
|
|
||||||
);
|
|
||||||
BorderPane pane = loader.load();
|
|
||||||
Scene scene = new Scene(pane);
|
|
||||||
Stage stage = new Stage();
|
|
||||||
|
|
||||||
TreatmentModalController controller = loader.getController();
|
|
||||||
controller.initialize(
|
|
||||||
this,
|
|
||||||
stage,
|
|
||||||
null,
|
|
||||||
patient
|
|
||||||
);
|
|
||||||
|
|
||||||
stage.setScene(scene);
|
|
||||||
stage.setTitle("NHPlus - Neue Behandlung");
|
|
||||||
stage.setResizable(true);
|
|
||||||
stage.setAlwaysOnTop(true);
|
|
||||||
stage.showAndWait();
|
|
||||||
} catch (IOException exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void treatmentWindow(Treatment treatment) {
|
|
||||||
try {
|
|
||||||
FXMLLoader loader = new FXMLLoader(
|
|
||||||
Main.class.getResource("/de/hitec/nhplus/treatment/TreatmentModal.fxml")
|
|
||||||
);
|
|
||||||
BorderPane pane = loader.load();
|
|
||||||
Scene scene = new Scene(pane);
|
|
||||||
Stage stage = new Stage();
|
|
||||||
|
|
||||||
TreatmentModalController controller = loader.getController();
|
|
||||||
PatientDao pDao = DaoFactory.getInstance().createPatientDAO();
|
|
||||||
controller.initialize(
|
|
||||||
this,
|
|
||||||
stage,
|
|
||||||
treatment,
|
|
||||||
pDao.read(treatment.getPatient().getId())
|
|
||||||
);
|
|
||||||
|
|
||||||
stage.setScene(scene);
|
|
||||||
stage.setTitle("NHPlus - Behandlung");
|
|
||||||
stage.setResizable(true);
|
|
||||||
stage.setAlwaysOnTop(true);
|
|
||||||
stage.showAndWait();
|
|
||||||
} catch (IOException | SQLException exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createTreatment(Treatment treatment) {
|
|
||||||
TreatmentDao dao = DaoFactory.getInstance().createTreatmentDao();
|
|
||||||
try {
|
|
||||||
dao.create(treatment);
|
|
||||||
} catch (SQLException exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateTreatment(Treatment treatment) {
|
|
||||||
TreatmentDao dao = DaoFactory.getInstance().createTreatmentDao();
|
|
||||||
try {
|
|
||||||
dao.update(treatment);
|
|
||||||
} catch (SQLException exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,12 @@ import java.time.LocalDate;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The model for a {@link Treatment}.
|
||||||
|
*
|
||||||
|
* @author Bernd Heideman
|
||||||
|
* @author Dominik Säume
|
||||||
|
*/
|
||||||
public class Treatment {
|
public class Treatment {
|
||||||
private SimpleIntegerProperty id;
|
private SimpleIntegerProperty id;
|
||||||
private final SimpleObjectProperty<Patient> patient;
|
private final SimpleObjectProperty<Patient> patient;
|
||||||
|
@ -19,8 +25,21 @@ public class Treatment {
|
||||||
private final SimpleStringProperty description;
|
private final SimpleStringProperty description;
|
||||||
private final SimpleStringProperty remarks;
|
private final SimpleStringProperty remarks;
|
||||||
|
|
||||||
public Treatment(Patient patient, LocalDate date, LocalTime begin,
|
/**
|
||||||
LocalTime end, String description, String remarks) {
|
* This constructor allows instantiating a {@link Treatment} object,
|
||||||
|
* before it is stored in the database, by omitting the {@link Treatment#id ID} value.
|
||||||
|
*
|
||||||
|
* @implSpec Instances created with this constructor can be directly passed to
|
||||||
|
* {@link de.hitec.nhplus.treatment.database.TreatmentDao#create TreatmentDao.create}.
|
||||||
|
*/
|
||||||
|
public Treatment(
|
||||||
|
Patient patient,
|
||||||
|
LocalDate date,
|
||||||
|
LocalTime begin,
|
||||||
|
LocalTime end,
|
||||||
|
String description,
|
||||||
|
String remarks
|
||||||
|
) {
|
||||||
this.patient = new SimpleObjectProperty<>(patient);
|
this.patient = new SimpleObjectProperty<>(patient);
|
||||||
this.date = new SimpleObjectProperty<>(date);
|
this.date = new SimpleObjectProperty<>(date);
|
||||||
this.begin = new SimpleObjectProperty<>(begin);
|
this.begin = new SimpleObjectProperty<>(begin);
|
||||||
|
@ -29,8 +48,18 @@ public class Treatment {
|
||||||
this.remarks = new SimpleStringProperty(remarks);
|
this.remarks = new SimpleStringProperty(remarks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Treatment(int id, Patient patient, LocalDate date, LocalTime begin,
|
/**
|
||||||
LocalTime end, String description, String remarks) {
|
* This constructor allows instantiating a {@link Treatment} object with all existing fields.
|
||||||
|
*/
|
||||||
|
public Treatment(
|
||||||
|
int id,
|
||||||
|
Patient patient,
|
||||||
|
LocalDate date,
|
||||||
|
LocalTime begin,
|
||||||
|
LocalTime end,
|
||||||
|
String description,
|
||||||
|
String remarks
|
||||||
|
) {
|
||||||
this.id = new SimpleIntegerProperty(id);
|
this.id = new SimpleIntegerProperty(id);
|
||||||
this.patient = new SimpleObjectProperty<>(patient);
|
this.patient = new SimpleObjectProperty<>(patient);
|
||||||
this.date = new SimpleObjectProperty<>(date);
|
this.date = new SimpleObjectProperty<>(date);
|
||||||
|
|
|
@ -13,6 +13,11 @@ import java.time.LocalTime;
|
||||||
|
|
||||||
import static de.hitec.nhplus.utils.Validator.*;
|
import static de.hitec.nhplus.utils.Validator.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The controller for creating and editing a specific {@link Treatment}.
|
||||||
|
*
|
||||||
|
* @author Dominik Säume
|
||||||
|
*/
|
||||||
public class TreatmentModalController {
|
public class TreatmentModalController {
|
||||||
@FXML
|
@FXML
|
||||||
private Label labelFirstName;
|
private Label labelFirstName;
|
||||||
|
@ -36,6 +41,10 @@ public class TreatmentModalController {
|
||||||
private Treatment treatment;
|
private Treatment treatment;
|
||||||
private boolean isNewTreatment = false;
|
private boolean isNewTreatment = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialization method that is called after the binding of all the fields.
|
||||||
|
*/
|
||||||
|
@FXML
|
||||||
public void initialize(AllTreatmentController controller, Stage stage, Treatment treatment, Patient patient) {
|
public void initialize(AllTreatmentController controller, Stage stage, Treatment treatment, Patient patient) {
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
this.stage = stage;
|
this.stage = stage;
|
||||||
|
@ -96,7 +105,9 @@ public class TreatmentModalController {
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Internal method to show the data in the view.
|
||||||
|
*/
|
||||||
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());
|
||||||
|
@ -136,8 +147,4 @@ public class TreatmentModalController {
|
||||||
public void handleCancel() {
|
public void handleCancel() {
|
||||||
stage.close();
|
stage.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Treatment getTreatment() {
|
|
||||||
return treatment;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ 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.patient.Patient;
|
||||||
import de.hitec.nhplus.treatment.Treatment;
|
import de.hitec.nhplus.treatment.Treatment;
|
||||||
import de.hitec.nhplus.utils.DateConverter;
|
import de.hitec.nhplus.utils.DateConverter;
|
||||||
|
|
||||||
|
@ -12,6 +13,12 @@ import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link TreatmentDao} is an implementation of the {@link de.hitec.nhplus.datastorage.Dao Dao} for the {@link Treatment} model.
|
||||||
|
*
|
||||||
|
* @author Bernd Heidemann
|
||||||
|
* @author Dominik Säume
|
||||||
|
*/
|
||||||
public class TreatmentDao extends DaoImp<Treatment> {
|
public class TreatmentDao extends DaoImp<Treatment> {
|
||||||
|
|
||||||
public TreatmentDao(Connection connection) {
|
public TreatmentDao(Connection connection) {
|
||||||
|
@ -71,15 +78,18 @@ public class TreatmentDao extends DaoImp<Treatment> {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PreparedStatement getReadAllTreatmentsOfOnePatientByPid(int patientId) throws SQLException {
|
/**
|
||||||
|
* 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> readTreatmentsByPid(int patientId) throws SQLException {
|
||||||
final String SQL = "SELECT * FROM treatment WHERE patientId = ?";
|
final String SQL = "SELECT * FROM treatment WHERE patientId = ?";
|
||||||
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
||||||
statement.setInt(1, patientId);
|
statement.setInt(1, patientId);
|
||||||
return statement;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Treatment> readTreatmentsByPid(int patientId) throws SQLException {
|
ResultSet result = statement.executeQuery();
|
||||||
ResultSet result = getReadAllTreatmentsOfOnePatientByPid(patientId).executeQuery();
|
|
||||||
return getListFromResultSet(result);
|
return getListFromResultSet(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue