Compare commits

...

3 commits

7 changed files with 531 additions and 375 deletions

View file

@ -2,8 +2,9 @@ package de.hitec.nhplus.controller;
import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.datastorage.PatientDao;
import de.hitec.nhplus.model.Patient;
import de.hitec.nhplus.utils.DateConverter;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
@ -13,82 +14,58 @@ import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import de.hitec.nhplus.model.Patient;
import de.hitec.nhplus.utils.DateConverter;
import java.sql.SQLException;
import java.time.LocalDate;
import static de.hitec.nhplus.utils.Validator.*;
/**
* The <code>AllPatientController</code> contains the entire logic of the patient view. It determines which data is displayed and how to react to events.
*/
public class AllPatientController {
public class AllPatientController
{
@FXML
private TableView<Patient> tableView;
@FXML
private TableColumn<Patient, Integer> columnId;
@FXML
private TableColumn<Patient, String> columnFirstName;
@FXML
private TableColumn<Patient, String> columnSurname;
@FXML
private TableColumn<Patient, String> columnDateOfBirth;
@FXML
private TableColumn<Patient, String> columnCareLevel;
@FXML
private TableColumn<Patient, String> columnRoomNumber;
@FXML
private TableColumn<Patient, String> columnAssets;
@FXML
private Button buttonDelete;
@FXML
private Button buttonAdd;
@FXML
private TextField textFieldSurname;
@FXML
private TextField textFieldFirstName;
@FXML
private TextField textFieldDateOfBirth;
@FXML
private TextField textFieldCareLevel;
@FXML
private TextField textFieldRoomNumber;
@FXML
private TextField textFieldAssets;
private final ObservableList<Patient> patients = FXCollections.observableArrayList();
private PatientDao dao;
/**
* When <code>initialize()</code> gets called, all fields are already initialized. For example from the FXMLLoader
* after loading an FXML-File. At this point of the lifecycle of the Controller, the fields can be accessed and
* configured.
*/
public void initialize() {
public void initialize()
{
this.readAllAndShowInTableView();
this.columnId.setCellValueFactory(new PropertyValueFactory<>("pid"));
// CellValueFactory to show property values in TableView
this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
// CellFactory to write property values from with in the TableView
this.columnFirstName.setCellFactory(TextFieldTableCell.forTableColumn());
this.columnSurname.setCellValueFactory(new PropertyValueFactory<>("surname"));
@ -106,146 +83,166 @@ public class AllPatientController {
this.columnAssets.setCellValueFactory(new PropertyValueFactory<>("assets"));
this.columnAssets.setCellFactory(TextFieldTableCell.forTableColumn());
//Anzeigen der Daten
this.tableView.setItems(this.patients);
this.buttonDelete.setDisable(true);
this.tableView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Patient>() {
@Override
public void changed(ObservableValue<? extends Patient> observableValue, Patient oldPatient, Patient newPatient) {;
this.tableView
.getSelectionModel()
.selectedItemProperty()
.addListener((observableValue, oldPatient, newPatient) ->
{
AllPatientController.this.buttonDelete.setDisable(newPatient == null);
}
});
);
this.buttonAdd.setDisable(true);
ChangeListener<String> inputNewPatientListener = (observableValue, oldText, newText) ->
AllPatientController.this.buttonAdd.setDisable(!AllPatientController.this.areInputDataValid());
this.textFieldSurname.textProperty().addListener(inputNewPatientListener);
this.textFieldFirstName.textProperty().addListener(inputNewPatientListener);
this.textFieldDateOfBirth.textProperty().addListener(inputNewPatientListener);
this.textFieldCareLevel.textProperty().addListener(inputNewPatientListener);
this.textFieldRoomNumber.textProperty().addListener(inputNewPatientListener);
this.textFieldAssets.textProperty().addListener(inputNewPatientListener);
ChangeListener<String> inputNewPatientValidationListener = (observableValue, oldText, newText) ->
{
boolean isValid = isValidDate(this.textFieldDateOfBirth.getText())
&& isValidFirstName(this.textFieldFirstName.getText())
&& isValidSurName(this.textFieldSurname.getText())
&& isValidDate(this.textFieldDateOfBirth.getText())
&& isValidCareLevel(this.textFieldCareLevel.getText())
&& isValidRoomNumber(textFieldRoomNumber.getText())
&& !this.textFieldAssets.getText().isBlank();
AllPatientController.this.buttonAdd.setDisable(!isValid);
};
this.textFieldSurname.textProperty().addListener(inputNewPatientValidationListener);
this.textFieldFirstName.textProperty().addListener(inputNewPatientValidationListener);
this.textFieldDateOfBirth.textProperty().addListener(inputNewPatientValidationListener);
this.textFieldCareLevel.textProperty().addListener(inputNewPatientValidationListener);
this.textFieldRoomNumber.textProperty().addListener(inputNewPatientValidationListener);
this.textFieldAssets.textProperty().addListener(inputNewPatientValidationListener);
}
/**
* When a cell of the column with first names was changed, this method will be called, to persist the change.
*
* @param event Event including the changed object and the change.
*/
@FXML
public void handleOnEditFirstname(TableColumn.CellEditEvent<Patient, String> event) {
event.getRowValue().setFirstName(event.getNewValue());
public void handleOnEditFirstname(TableColumn.CellEditEvent<Patient, String> event)
{
String newFirstName = event.getNewValue();
if (!isValidFirstName(newFirstName))
{
showValidationError("First Name");
event.getTableView().refresh();
return;
}
event.getRowValue().setFirstName(newFirstName);
this.doUpdate(event);
}
/**
* When a cell of the column with surnames was changed, this method will be called, to persist the change.
*
* @param event Event including the changed object and the change.
*/
@FXML
public void handleOnEditSurname(TableColumn.CellEditEvent<Patient, String> event) {
event.getRowValue().setSurname(event.getNewValue());
public void handleOnEditSurname(TableColumn.CellEditEvent<Patient, String> event)
{
String newSurName = event.getNewValue();
if (!isValidSurName(newSurName))
{
showValidationError("Sur Name");
event.getTableView().refresh();
return;
}
event.getRowValue().setSurname(newSurName);
this.doUpdate(event);
}
/**
* When a cell of the column with dates of birth was changed, this method will be called, to persist the change.
*
* @param event Event including the changed object and the change.
*/
@FXML
public void handleOnEditDateOfBirth(TableColumn.CellEditEvent<Patient, String> event) {
event.getRowValue().setDateOfBirth(event.getNewValue());
public void handleOnEditDateOfBirth(TableColumn.CellEditEvent<Patient, String> event)
{
String newDateString = event.getNewValue();
if (!isValidDate(newDateString))
{
showValidationError("Date");
event.getTableView().refresh();
return;
}
event.getRowValue().setDateOfBirth(newDateString);
this.doUpdate(event);
}
/**
* When a cell of the column with care levels was changed, this method will be called, to persist the change.
*
* @param event Event including the changed object and the change.
*/
@FXML
public void handleOnEditCareLevel(TableColumn.CellEditEvent<Patient, String> event) {
event.getRowValue().setCareLevel(event.getNewValue());
public void handleOnEditCareLevel(TableColumn.CellEditEvent<Patient, String> event)
{
String newCareLevel = event.getNewValue();
if (!isValidCareLevel(newCareLevel))
{
showValidationError("Care Level");
event.getTableView().refresh();
return;
}
event.getRowValue().setCareLevel(newCareLevel);
this.doUpdate(event);
}
/**
* When a cell of the column with room numbers was changed, this method will be called, to persist the change.
*
* @param event Event including the changed object and the change.
*/
@FXML
public void handleOnEditRoomNumber(TableColumn.CellEditEvent<Patient, String> event){
event.getRowValue().setRoomNumber(event.getNewValue());
public void handleOnEditRoomNumber(TableColumn.CellEditEvent<Patient, String> event)
{
String newRoomNumber = event.getNewValue();
if (!isValidRoomNumber(newRoomNumber))
{
showValidationError("Room Number");
event.getTableView().refresh();
return;
}
event.getRowValue().setRoomNumber(newRoomNumber);
this.doUpdate(event);
}
/**
* When a cell of the column with assets was changed, this method will be called, to persist the change.
*
* @param event Event including the changed object and the change.
*/
@FXML
public void handleOnEditAssets(TableColumn.CellEditEvent<Patient, String> event){
event.getRowValue().setAssets(event.getNewValue());
public void handleOnEditAssets(TableColumn.CellEditEvent<Patient, String> event)
{
String newAssets = event.getNewValue();
if(newAssets.isBlank()){
event.getTableView().refresh();
return;
}
event.getRowValue().setAssets(newAssets);
this.doUpdate(event);
}
/**
* Updates a patient by calling the method <code>update()</code> of {@link PatientDao}.
*
* @param event Event including the changed object and the change.
*/
private void doUpdate(TableColumn.CellEditEvent<Patient, String> event) {
try {
private void doUpdate(TableColumn.CellEditEvent<Patient, String> event)
{
try
{
this.dao.update(event.getRowValue());
} catch (SQLException exception) {
} catch (SQLException exception)
{
exception.printStackTrace();
}
}
/**
* Reloads all patients to the table by clearing the list of all patients and filling it again by all persisted
* patients, delivered by {@link PatientDao}.
*/
private void readAllAndShowInTableView() {
private void readAllAndShowInTableView()
{
this.patients.clear();
this.dao = DaoFactory.getDaoFactory().createPatientDAO();
try {
try
{
this.patients.addAll(this.dao.readAll());
} catch (SQLException exception) {
} catch (SQLException exception)
{
exception.printStackTrace();
}
}
/**
* This method handles events fired by the button to delete patients. It calls {@link PatientDao} to delete the
* patient from the database and removes the object from the list, which is the data source of the
* <code>TableView</code>.
*/
@FXML
public void handleDelete() {
public void handleDelete()
{
Patient selectedItem = this.tableView.getSelectionModel().getSelectedItem();
if (selectedItem != null) {
try {
if (selectedItem != null)
{
try
{
DaoFactory.getDaoFactory().createPatientDAO().deleteById(selectedItem.getPid());
this.tableView.getItems().remove(selectedItem);
} catch (SQLException exception) {
} catch (SQLException exception)
{
exception.printStackTrace();
}
}
}
/**
* This method handles the events fired by the button to add a patient. It collects the data from the
* <code>TextField</code>s, creates an object of class <code>Patient</code> of it and passes the object to
* {@link PatientDao} to persist the data.
*/
@FXML
public void handleAdd() {
public void handleAdd()
{
String surname = this.textFieldSurname.getText();
String firstName = this.textFieldFirstName.getText();
String birthday = this.textFieldDateOfBirth.getText();
@ -253,19 +250,19 @@ public class AllPatientController {
String careLevel = this.textFieldCareLevel.getText();
String roomNumber = this.textFieldRoomNumber.getText();
String assets = this.textFieldAssets.getText();
try {
try
{
this.dao.create(new Patient(firstName, surname, date, careLevel, roomNumber, assets));
} catch (SQLException exception) {
} catch (SQLException exception)
{
exception.printStackTrace();
}
readAllAndShowInTableView();
clearTextfields();
}
/**
* Clears all contents from all <code>TextField</code>s.
*/
private void clearTextfields() {
private void clearTextfields()
{
this.textFieldFirstName.clear();
this.textFieldSurname.clear();
this.textFieldDateOfBirth.clear();
@ -273,18 +270,4 @@ public class AllPatientController {
this.textFieldRoomNumber.clear();
this.textFieldAssets.clear();
}
private boolean areInputDataValid() {
if (!this.textFieldDateOfBirth.getText().isBlank()) {
try {
DateConverter.convertStringToLocalDate(this.textFieldDateOfBirth.getText());
} catch (Exception exception) {
return false;
}
}
return !this.textFieldFirstName.getText().isBlank() && !this.textFieldSurname.getText().isBlank() &&
!this.textFieldDateOfBirth.getText().isBlank() && !this.textFieldCareLevel.getText().isBlank() &&
!this.textFieldRoomNumber.getText().isBlank() && !this.textFieldAssets.getText().isBlank();
}
}

View file

@ -4,6 +4,8 @@ import de.hitec.nhplus.Main;
import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.datastorage.PatientDao;
import de.hitec.nhplus.datastorage.TreatmentDao;
import de.hitec.nhplus.model.Patient;
import de.hitec.nhplus.model.Treatment;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
@ -13,14 +15,13 @@ import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import de.hitec.nhplus.model.Patient;
import de.hitec.nhplus.model.Treatment;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
public class AllTreatmentController {
public class AllTreatmentController
{
@FXML
private TableView<Treatment> tableView;
@ -54,7 +55,8 @@ public class AllTreatmentController {
private final ObservableList<String> patientSelection = FXCollections.observableArrayList();
private ArrayList<Patient> patientList;
public void initialize() {
public void initialize()
{
readAllAndShowInTableView();
comboBoxPatientSelection.setItems(patientSelection);
comboBoxPatientSelection.getSelectionModel().select(0);
@ -67,67 +69,88 @@ public class AllTreatmentController {
this.columnDescription.setCellValueFactory(new PropertyValueFactory<>("description"));
this.tableView.setItems(this.treatments);
// Disabling the button to delete treatments as long, as no treatment was selected.
this.buttonDelete.setDisable(true);
this.tableView.getSelectionModel().selectedItemProperty().addListener(
(observableValue, oldTreatment, newTreatment) ->
AllTreatmentController.this.buttonDelete.setDisable(newTreatment == null));
this.tableView
.getSelectionModel()
.selectedItemProperty()
.addListener((observableValue, oldTreatment, newTreatment) ->
{
AllTreatmentController.this.buttonDelete.setDisable(newTreatment == null);
}
);
this.createComboBoxData();
}
public void readAllAndShowInTableView() {
public void readAllAndShowInTableView()
{
this.treatments.clear();
comboBoxPatientSelection.getSelectionModel().select(0);
this.dao = DaoFactory.getDaoFactory().createTreatmentDao();
try {
try
{
this.treatments.addAll(dao.readAll());
} catch (SQLException exception) {
} catch (SQLException exception)
{
exception.printStackTrace();
}
}
private void createComboBoxData() {
private void createComboBoxData()
{
PatientDao dao = DaoFactory.getDaoFactory().createPatientDAO();
try {
try
{
patientList = (ArrayList<Patient>) dao.readAll();
this.patientSelection.add("alle");
for (Patient patient: patientList) {
for (Patient patient : patientList)
{
this.patientSelection.add(patient.getSurname());
}
} catch (SQLException exception) {
} catch (SQLException exception)
{
exception.printStackTrace();
}
}
@FXML
public void handleComboBox() {
public void handleComboBox()
{
String selectedPatient = this.comboBoxPatientSelection.getSelectionModel().getSelectedItem();
this.treatments.clear();
this.dao = DaoFactory.getDaoFactory().createTreatmentDao();
if (selectedPatient.equals("alle")) {
try {
if (selectedPatient.equals("alle"))
{
try
{
this.treatments.addAll(this.dao.readAll());
} catch (SQLException exception) {
} catch (SQLException exception)
{
exception.printStackTrace();
}
}
Patient patient = searchInList(selectedPatient);
if (patient !=null) {
try {
if (patient != null)
{
try
{
this.treatments.addAll(this.dao.readTreatmentsByPid(patient.getPid()));
} catch (SQLException exception) {
} catch (SQLException exception)
{
exception.printStackTrace();
}
}
}
private Patient searchInList(String surname) {
for (Patient patient : this.patientList) {
if (patient.getSurname().equals(surname)) {
private Patient searchInList(String surname)
{
for (Patient patient : this.patientList)
{
if (patient.getSurname().equals(surname))
{
return patient;
}
}
@ -135,24 +158,30 @@ public class AllTreatmentController {
}
@FXML
public void handleDelete() {
public void handleDelete()
{
int index = this.tableView.getSelectionModel().getSelectedIndex();
Treatment t = this.treatments.remove(index);
TreatmentDao dao = DaoFactory.getDaoFactory().createTreatmentDao();
try {
try
{
dao.deleteById(t.getTid());
} catch (SQLException exception) {
} catch (SQLException exception)
{
exception.printStackTrace();
}
}
@FXML
public void handleNewTreatment() {
try{
public void handleNewTreatment()
{
try
{
String selectedPatient = this.comboBoxPatientSelection.getSelectionModel().getSelectedItem();
Patient patient = searchInList(selectedPatient);
newTreatmentWindow(patient);
} catch (NullPointerException exception){
} catch (NullPointerException exception)
{
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Information");
alert.setHeaderText("Patient für die Behandlung fehlt!");
@ -162,9 +191,12 @@ public class AllTreatmentController {
}
@FXML
public void handleMouseClick() {
tableView.setOnMouseClicked(event -> {
if (event.getClickCount() == 2 && (tableView.getSelectionModel().getSelectedItem() != null)) {
public void handleMouseClick()
{
tableView.setOnMouseClicked(event ->
{
if (event.getClickCount() == 2 && (tableView.getSelectionModel().getSelectedItem() != null))
{
int index = this.tableView.getSelectionModel().getSelectedIndex();
Treatment treatment = this.treatments.get(index);
treatmentWindow(treatment);
@ -172,8 +204,10 @@ public class AllTreatmentController {
});
}
public void newTreatmentWindow(Patient patient) {
try {
public void newTreatmentWindow(Patient patient)
{
try
{
FXMLLoader loader = new FXMLLoader(Main.class.getResource("/de/hitec/nhplus/NewTreatmentView.fxml"));
AnchorPane pane = loader.load();
Scene scene = new Scene(pane);
@ -187,13 +221,16 @@ public class AllTreatmentController {
stage.setScene(scene);
stage.setResizable(false);
stage.showAndWait();
} catch (IOException exception) {
} catch (IOException exception)
{
exception.printStackTrace();
}
}
public void treatmentWindow(Treatment treatment){
try {
public void treatmentWindow(Treatment treatment)
{
try
{
FXMLLoader loader = new FXMLLoader(Main.class.getResource("/de/hitec/nhplus/TreatmentView.fxml"));
AnchorPane pane = loader.load();
Scene scene = new Scene(pane);
@ -206,7 +243,8 @@ public class AllTreatmentController {
stage.setScene(scene);
stage.setResizable(false);
stage.showAndWait();
} catch (IOException exception) {
} catch (IOException exception)
{
exception.printStackTrace();
}
}

View file

@ -2,20 +2,23 @@ package de.hitec.nhplus.controller;
import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.datastorage.TreatmentDao;
import de.hitec.nhplus.model.Patient;
import de.hitec.nhplus.model.Treatment;
import de.hitec.nhplus.utils.DateConverter;
import javafx.beans.value.ChangeListener;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.stage.Stage;
import de.hitec.nhplus.model.Patient;
import de.hitec.nhplus.model.Treatment;
import de.hitec.nhplus.utils.DateConverter;
import javafx.util.StringConverter;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.LocalTime;
public class NewTreatmentController {
import static de.hitec.nhplus.utils.Validator.*;
public class NewTreatmentController
{
@FXML
private Label labelFirstName;
@ -45,40 +48,66 @@ public class NewTreatmentController {
private Patient patient;
private Stage stage;
public void initialize(AllTreatmentController controller, Stage stage, Patient patient) {
public void initialize(AllTreatmentController controller, Stage stage, Patient patient)
{
this.controller = controller;
this.patient = patient;
this.stage = stage;
this.buttonAdd.setDisable(true);
ChangeListener<String> inputNewPatientListener = (observableValue, oldText, newText) ->
NewTreatmentController.this.buttonAdd.setDisable(NewTreatmentController.this.areInputDataInvalid());
this.textFieldBegin.textProperty().addListener(inputNewPatientListener);
this.textFieldEnd.textProperty().addListener(inputNewPatientListener);
this.textFieldDescription.textProperty().addListener(inputNewPatientListener);
this.textAreaRemarks.textProperty().addListener(inputNewPatientListener);
this.datePicker.valueProperty().addListener((observableValue, localDate, t1) -> NewTreatmentController.this.buttonAdd.setDisable(NewTreatmentController.this.areInputDataInvalid()));
this.datePicker.setConverter(new StringConverter<>() {
ChangeListener<String> inputNewTreatmentTextValidationListener = (observableValue, oldText, newText) ->
{
boolean isValid = isValidDate(this.datePicker.getValue())
&& isValidTimeRange(this.textFieldBegin.getText(), this.textFieldEnd.getText())
&& isValidDescription(this.textFieldDescription.getText());
NewTreatmentController.this.buttonAdd.setDisable(!isValid);
};
ChangeListener<LocalDate> inputNewTreatmentDateValidationListener = (observableValue, localDate, t1) ->
{
boolean isValid = isValidDate(this.datePicker.getValue())
&& isValidTimeRange(this.textFieldBegin.getText(), this.textFieldEnd.getText())
&& isValidDescription(this.textFieldDescription.getText());
NewTreatmentController.this.buttonAdd.setDisable(!isValid);
};
this.textFieldBegin.textProperty().addListener(inputNewTreatmentTextValidationListener);
this.textFieldEnd.textProperty().addListener(inputNewTreatmentTextValidationListener);
this.textFieldDescription.textProperty().addListener(inputNewTreatmentTextValidationListener);
this.textAreaRemarks.textProperty().addListener(inputNewTreatmentTextValidationListener);
this.datePicker.valueProperty().addListener(inputNewTreatmentDateValidationListener);
this.datePicker.setConverter(new StringConverter<>()
{
@Override
public String toString(LocalDate localDate) {
public String toString(LocalDate localDate)
{
return (localDate == null) ? "" : DateConverter.convertLocalDateToString(localDate);
}
@Override
public LocalDate fromString(String localDate) {
public LocalDate fromString(String localDate)
{
if (!isValidDate(localDate))
{
return null;
}
return DateConverter.convertStringToLocalDate(localDate);
}
});
this.showPatientData();
}
private void showPatientData(){
private void showPatientData()
{
this.labelFirstName.setText(patient.getFirstName());
this.labelSurname.setText(patient.getSurname());
}
@FXML
public void handleAdd(){
public void handleAdd()
{
LocalDate date = this.datePicker.getValue();
LocalTime begin = DateConverter.convertStringToLocalTime(textFieldBegin.getText());
LocalTime end = DateConverter.convertStringToLocalTime(textFieldEnd.getText());
@ -90,33 +119,22 @@ public class NewTreatmentController {
stage.close();
}
private void createTreatment(Treatment treatment) {
private void createTreatment(Treatment treatment)
{
TreatmentDao dao = DaoFactory.getDaoFactory().createTreatmentDao();
try {
try
{
dao.create(treatment);
} catch (SQLException exception) {
} catch (SQLException exception)
{
exception.printStackTrace();
}
}
@FXML
public void handleCancel(){
public void handleCancel()
{
stage.close();
}
private boolean areInputDataInvalid() {
if (this.textFieldBegin.getText() == null || this.textFieldEnd.getText() == null) {
return true;
}
try {
LocalTime begin = DateConverter.convertStringToLocalTime(this.textFieldBegin.getText());
LocalTime end = DateConverter.convertStringToLocalTime(this.textFieldEnd.getText());
if (!end.isAfter(begin)) {
return true;
}
} catch (Exception exception) {
return true;
}
return this.textFieldDescription.getText().isBlank() || this.datePicker.getValue() == null;
}
}

View file

@ -13,6 +13,8 @@ import de.hitec.nhplus.utils.DateConverter;
import java.sql.SQLException;
import java.time.LocalDate;
import static de.hitec.nhplus.utils.Validator.*;
public class TreatmentController {
@FXML
@ -44,6 +46,7 @@ public class TreatmentController {
public void initializeController(AllTreatmentController controller, Stage stage, Treatment treatment) {
this.stage = stage;
this.controller= controller;
PatientDao pDao = DaoFactory.getDaoFactory().createPatientDAO();
try {
this.patient = pDao.read((int) treatment.getPid());
@ -67,11 +70,37 @@ public class TreatmentController {
@FXML
public void handleChange(){
this.treatment.setDate(this.datePicker.getValue().toString());
this.treatment.setBegin(textFieldBegin.getText());
this.treatment.setEnd(textFieldEnd.getText());
this.treatment.setDescription(textFieldDescription.getText());
this.treatment.setRemarks(textAreaRemarks.getText());
LocalDate newDate = this.datePicker.getValue();
if(!isValidDate(newDate)){
showValidationError("Date");
return;
}
String newDescription = textFieldDescription.getText();
if(!isValidDescription(newDescription)){
showValidationError("Description");
return;
}
String newBegin = textFieldBegin.getText();
String newEnd = textFieldEnd.getText();
if(!isValidTimeRange(newBegin, newEnd)){
showValidationError("Time Range");
return;
}
String newRemarks = textAreaRemarks.getText();
if(!isValidDescription(newRemarks)){
showValidationError("Remarks");
return;
}
this.treatment.setDate(newDate.toString());
this.treatment.setDescription(newDescription);
this.treatment.setBegin(newBegin);
this.treatment.setEnd(newEnd);
this.treatment.setRemarks(newRemarks);
doUpdate();
controller.readAllAndShowInTableView();
stage.close();

View file

@ -0,0 +1,79 @@
package de.hitec.nhplus.utils;
import javafx.scene.control.Alert;
import java.time.LocalDate;
import java.time.LocalTime;
public class Validator
{
public static void showValidationError(String type){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText(null);
alert.setContentText("Invalid " + type + " !");
alert.showAndWait();
}
public static boolean isValidDate(String text) {
if(text.isBlank()){
return false;
}
try {
DateConverter.convertStringToLocalDate(text);
} catch (Exception exception) {
return false;
}
return true;
}
public static boolean isValidDate(LocalDate date) {
if(date == null){
return false;
}
try {
DateConverter.convertStringToLocalDate(date.toString());
} catch (Exception exception) {
return false;
}
return true;
}
public static boolean isValidTime(String text){
if(text.isBlank()){
return false;
}
try {
DateConverter.convertStringToLocalTime(text);
}catch (Exception exception){
return false;
}
return true;
}
public static boolean isValidTimeRange(String start, String end){
if(
!isValidTime(start) || !isValidTime(end)
){
return false;
}
LocalTime startTime = DateConverter.convertStringToLocalTime(start);
LocalTime endTime = DateConverter.convertStringToLocalTime(end);
return startTime.isBefore(endTime);
}
public static boolean isValidDescription(String text) {
return !text.isBlank();
}
public static boolean isValidFirstName(String text){
return !text.isBlank();
}
public static boolean isValidSurName(String text){
return !text.isBlank();
}
public static boolean isValidCareLevel(String text){
return !text.isBlank();
}
public static boolean isValidRoomNumber(String text){
return !text.isBlank();
}
}

View file

@ -3,19 +3,22 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="450.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hitec.nhplus.controller.NewTreatmentController">
<AnchorPane prefHeight="450.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/17.0.2-ea"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hitec.nhplus.controller.NewTreatmentController">
<children>
<HBox alignment="TOP_CENTER" prefWidth="200.0" spacing="25.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="5.0">
<HBox alignment="TOP_CENTER" prefWidth="200.0" spacing="25.0" AnchorPane.leftAnchor="5.0"
AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="5.0">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" minWidth="400.0" text="Neue Behandlung" textAlignment="CENTER">
<Label alignment="CENTER" contentDisplay="CENTER" minWidth="400.0" text="Neue Behandlung"
textAlignment="CENTER">
<font>
<Font size="36.0"/>
</font>
</Label>
</children>
</HBox>
<GridPane hgap="10.0" layoutX="14.0" layoutY="14.0" AnchorPane.leftAnchor="50.0" AnchorPane.rightAnchor="50.0" AnchorPane.topAnchor="100.0">
<GridPane hgap="10.0" layoutX="14.0" layoutY="14.0" AnchorPane.leftAnchor="50.0" AnchorPane.rightAnchor="50.0"
AnchorPane.topAnchor="100.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="200.0"/>
@ -45,35 +48,40 @@
<Font name="System Bold" size="13.0"/>
</font>
</Label>
<Label text="Beginn:" GridPane.columnIndex="2" GridPane.rowIndex="3">
<Label text="Beschreibung:" GridPane.columnIndex="2" GridPane.rowIndex="3">
<font>
<Font name="System Bold" size="13.0"/>
</font>
</Label>
<Label text="Ende" GridPane.rowIndex="4">
<Label text="Beginn:" GridPane.rowIndex="4">
<font>
<Font name="System Bold" size="13.0"/>
</font>
</Label>
<Label text="Beschreibung:" GridPane.columnIndex="2" GridPane.rowIndex="4">
<Label text="Ende" GridPane.columnIndex="2" GridPane.rowIndex="4">
<font>
<Font name="System Bold" size="13.0"/>
</font>
</Label>
<TextField fx:id="textFieldBegin" promptText="hh:mm" GridPane.columnIndex="3" GridPane.rowIndex="3" />
<TextField fx:id="textFieldEnd" maxWidth="192.0" prefWidth="150.0" promptText="hh:mm" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<TextField fx:id="textFieldDescription" GridPane.columnIndex="3" GridPane.rowIndex="4" />
<DatePicker fx:id="datePicker" prefWidth="192.0" promptText="yyyy-mm-dd" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<TextField fx:id="textFieldDescription" GridPane.columnIndex="3" GridPane.rowIndex="3"/>
<TextField fx:id="textFieldBegin" promptText="hh:mm" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
<TextField fx:id="textFieldEnd" maxWidth="192.0" prefWidth="150.0" promptText="hh:mm"
GridPane.columnIndex="3" GridPane.rowIndex="4"/>
<DatePicker fx:id="datePicker" prefWidth="192.0" promptText="yyyy-mm-dd" GridPane.columnIndex="1"
GridPane.rowIndex="3"/>
<Label fx:id="labelFirstName" text="Vorname" GridPane.columnIndex="1"/>
<Label fx:id="labelSurname" text="Nachname" GridPane.columnIndex="3"/>
</children>
</GridPane>
<HBox layoutX="298.0" layoutY="237.0" spacing="20.0" AnchorPane.bottomAnchor="20.0" AnchorPane.rightAnchor="50.0">
<HBox layoutX="298.0" layoutY="237.0" spacing="20.0" AnchorPane.bottomAnchor="20.0"
AnchorPane.rightAnchor="50.0">
<children>
<Button fx:id="buttonAdd" mnemonicParsing="false" onAction="#handleAdd" text="Anlegen"/>
<Button fx:id="buttonCancel" layoutX="298.0" layoutY="237.0" mnemonicParsing="false" onAction="#handleCancel" text="Abbruch" />
<Button fx:id="buttonCancel" layoutX="298.0" layoutY="237.0" mnemonicParsing="false"
onAction="#handleCancel" text="Abbruch"/>
</children>
</HBox>
<TextArea fx:id="textAreaRemarks" layoutX="50.0" layoutY="252.0" prefHeight="134.0" prefWidth="700.0" AnchorPane.topAnchor="265.0" />
<TextArea fx:id="textAreaRemarks" layoutX="50.0" layoutY="252.0" prefHeight="134.0" prefWidth="700.0"
AnchorPane.topAnchor="265.0"/>
</children>
</AnchorPane>

View file

@ -1,29 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="450.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hitec.nhplus.controller.TreatmentController">
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="450.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hitec.nhplus.controller.TreatmentController">
<children>
<HBox alignment="TOP_CENTER" prefWidth="200.0" spacing="25.0" AnchorPane.leftAnchor="15.0" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="5.0">
<HBox alignment="TOP_CENTER" prefWidth="200.0" spacing="25.0" AnchorPane.leftAnchor="15.0"
AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="5.0">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" minWidth="400.0" text="Behandlung" textAlignment="CENTER">
<Label alignment="CENTER" contentDisplay="CENTER" minWidth="400.0" text="Behandlung"
textAlignment="CENTER">
<font>
<Font size="36.0"/>
</font>
</Label>
</children>
</HBox>
<GridPane hgap="10.0" layoutX="14.0" layoutY="14.0" AnchorPane.leftAnchor="50.0" AnchorPane.rightAnchor="50.0" AnchorPane.topAnchor="100.0">
<GridPane hgap="10.0" layoutX="14.0" layoutY="14.0" AnchorPane.leftAnchor="50.0" AnchorPane.rightAnchor="50.0"
AnchorPane.topAnchor="100.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="200.0"/>
@ -53,35 +48,41 @@
<Font name="System Bold" size="13.0"/>
</font>
</Label>
<Label text="Beginn:" GridPane.columnIndex="2" GridPane.rowIndex="3">
<Label text="Beschreibung:" GridPane.columnIndex="2" GridPane.rowIndex="3">
<font>
<Font name="System Bold" size="13.0"/>
</font>
</Label>
<Label text="Ende" GridPane.rowIndex="4">
<Label text="Beginn:" GridPane.rowIndex="4">
<font>
<Font name="System Bold" size="13.0"/>
</font>
</Label>
<Label text="Beschreibung:" GridPane.columnIndex="2" GridPane.rowIndex="4">
<Label text="Ende" GridPane.columnIndex="2" GridPane.rowIndex="4">
<font>
<Font name="System Bold" size="13.0"/>
</font>
</Label>
<TextField fx:id="textFieldBegin" GridPane.columnIndex="3" GridPane.rowIndex="3" />
<TextField fx:id="textFieldEnd" maxWidth="192.0" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<TextField fx:id="textFieldDescription" GridPane.columnIndex="3" GridPane.rowIndex="4" />
<TextField fx:id="textFieldDescription" GridPane.columnIndex="3" GridPane.rowIndex="3"/>
<TextField fx:id="textFieldBegin" promptText="hh:mm" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
<TextField fx:id="textFieldEnd" promptText="hh:mm" maxWidth="192.0" prefWidth="150.0"
GridPane.columnIndex="3"
GridPane.rowIndex="4"/>
<DatePicker fx:id="datePicker" prefWidth="192.0" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<Label fx:id="labelPatientName" text="Name" GridPane.columnIndex="1"/>
<Label fx:id="labelCareLevel" text="Pflegestufe" GridPane.columnIndex="3"/>
</children>
</GridPane>
<HBox layoutX="298.0" layoutY="237.0" spacing="20.0" AnchorPane.bottomAnchor="20.0" AnchorPane.rightAnchor="50.0">
<HBox layoutX="298.0" layoutY="237.0" spacing="20.0" AnchorPane.bottomAnchor="20.0"
AnchorPane.rightAnchor="50.0">
<children>
<Button fx:id="btnChange" mnemonicParsing="false" onAction="#handleChange" text="Ändern"/>
<Button fx:id="btnCancel" layoutX="298.0" layoutY="237.0" mnemonicParsing="false" onAction="#handleCancel" text="Abbruch" />
<Button fx:id="btnCancel" layoutX="298.0" layoutY="237.0" mnemonicParsing="false"
onAction="#handleCancel" text="Abbruch"/>
</children>
</HBox>
<TextArea fx:id="textAreaRemarks" layoutX="50.0" layoutY="252.0" prefHeight="134.0" prefWidth="700.0" AnchorPane.topAnchor="265.0" />
<TextArea fx:id="textAreaRemarks" layoutX="50.0" layoutY="252.0" prefHeight="134.0" prefWidth="700.0"
AnchorPane.topAnchor="265.0"/>
</children>
</AnchorPane>