Compare commits

..

No commits in common. "dba73c1994bc1eeb47c85a9b7339a228dcc14390" and "2b96bc967c1971aa009a3bdbff468db1eac2a94b" have entirely different histories.

6 changed files with 150 additions and 71 deletions

Binary file not shown.

View file

@ -20,7 +20,8 @@ import java.time.LocalDate;
import static de.hitec.nhplus.utils.Validator.*; import static de.hitec.nhplus.utils.Validator.*;
public class AllPatientController { public class AllPatientController
{
@FXML @FXML
private TableView<Patient> tableView; private TableView<Patient> tableView;
@ -37,6 +38,8 @@ public class AllPatientController {
@FXML @FXML
private TableColumn<Patient, String> columnRoomNumber; private TableColumn<Patient, String> columnRoomNumber;
@FXML @FXML
private TableColumn<Patient, String> columnAssets;
@FXML
private Button buttonDelete; private Button buttonDelete;
@FXML @FXML
private Button buttonAdd; private Button buttonAdd;
@ -50,11 +53,14 @@ public class AllPatientController {
private TextField textFieldCareLevel; private TextField textFieldCareLevel;
@FXML @FXML
private TextField textFieldRoomNumber; private TextField textFieldRoomNumber;
@FXML
private TextField textFieldAssets;
private final ObservableList<Patient> patients = FXCollections.observableArrayList(); private final ObservableList<Patient> patients = FXCollections.observableArrayList();
private PatientDao dao; private PatientDao dao;
public void initialize() { public void initialize()
{
this.readAllAndShowInTableView(); this.readAllAndShowInTableView();
this.columnId.setCellValueFactory(new PropertyValueFactory<>("pid")); this.columnId.setCellValueFactory(new PropertyValueFactory<>("pid"));
@ -74,6 +80,8 @@ public class AllPatientController {
this.columnRoomNumber.setCellValueFactory(new PropertyValueFactory<>("roomNumber")); this.columnRoomNumber.setCellValueFactory(new PropertyValueFactory<>("roomNumber"));
this.columnRoomNumber.setCellFactory(TextFieldTableCell.forTableColumn()); this.columnRoomNumber.setCellFactory(TextFieldTableCell.forTableColumn());
this.columnAssets.setCellValueFactory(new PropertyValueFactory<>("assets"));
this.columnAssets.setCellFactory(TextFieldTableCell.forTableColumn());
this.tableView.setItems(this.patients); this.tableView.setItems(this.patients);
@ -95,7 +103,8 @@ public class AllPatientController {
&& isValidSurName(this.textFieldSurname.getText()) && isValidSurName(this.textFieldSurname.getText())
&& isValidDate(this.textFieldDateOfBirth.getText()) && isValidDate(this.textFieldDateOfBirth.getText())
&& isValidCareLevel(this.textFieldCareLevel.getText()) && isValidCareLevel(this.textFieldCareLevel.getText())
&& isValidRoomNumber(textFieldRoomNumber.getText()); && isValidRoomNumber(textFieldRoomNumber.getText())
&& !this.textFieldAssets.getText().isBlank();
AllPatientController.this.buttonAdd.setDisable(!isValid); AllPatientController.this.buttonAdd.setDisable(!isValid);
}; };
@ -105,12 +114,15 @@ public class AllPatientController {
this.textFieldDateOfBirth.textProperty().addListener(inputNewPatientValidationListener); this.textFieldDateOfBirth.textProperty().addListener(inputNewPatientValidationListener);
this.textFieldCareLevel.textProperty().addListener(inputNewPatientValidationListener); this.textFieldCareLevel.textProperty().addListener(inputNewPatientValidationListener);
this.textFieldRoomNumber.textProperty().addListener(inputNewPatientValidationListener); this.textFieldRoomNumber.textProperty().addListener(inputNewPatientValidationListener);
this.textFieldAssets.textProperty().addListener(inputNewPatientValidationListener);
} }
@FXML @FXML
public void handleOnEditFirstname(TableColumn.CellEditEvent<Patient, String> event) { public void handleOnEditFirstname(TableColumn.CellEditEvent<Patient, String> event)
{
String newFirstName = event.getNewValue(); String newFirstName = event.getNewValue();
if (!isValidFirstName(newFirstName)) { if (!isValidFirstName(newFirstName))
{
showValidationError("First Name"); showValidationError("First Name");
event.getTableView().refresh(); event.getTableView().refresh();
return; return;
@ -120,9 +132,11 @@ public class AllPatientController {
} }
@FXML @FXML
public void handleOnEditSurname(TableColumn.CellEditEvent<Patient, String> event) { public void handleOnEditSurname(TableColumn.CellEditEvent<Patient, String> event)
{
String newSurName = event.getNewValue(); String newSurName = event.getNewValue();
if (!isValidSurName(newSurName)) { if (!isValidSurName(newSurName))
{
showValidationError("Sur Name"); showValidationError("Sur Name");
event.getTableView().refresh(); event.getTableView().refresh();
return; return;
@ -132,9 +146,11 @@ public class AllPatientController {
} }
@FXML @FXML
public void handleOnEditDateOfBirth(TableColumn.CellEditEvent<Patient, String> event) { public void handleOnEditDateOfBirth(TableColumn.CellEditEvent<Patient, String> event)
{
String newDateString = event.getNewValue(); String newDateString = event.getNewValue();
if (!isValidDate(newDateString)) { if (!isValidDate(newDateString))
{
showValidationError("Date"); showValidationError("Date");
event.getTableView().refresh(); event.getTableView().refresh();
return; return;
@ -144,9 +160,11 @@ public class AllPatientController {
} }
@FXML @FXML
public void handleOnEditCareLevel(TableColumn.CellEditEvent<Patient, String> event) { public void handleOnEditCareLevel(TableColumn.CellEditEvent<Patient, String> event)
{
String newCareLevel = event.getNewValue(); String newCareLevel = event.getNewValue();
if (!isValidCareLevel(newCareLevel)) { if (!isValidCareLevel(newCareLevel))
{
showValidationError("Care Level"); showValidationError("Care Level");
event.getTableView().refresh(); event.getTableView().refresh();
return; return;
@ -156,9 +174,11 @@ public class AllPatientController {
} }
@FXML @FXML
public void handleOnEditRoomNumber(TableColumn.CellEditEvent<Patient, String> event) { public void handleOnEditRoomNumber(TableColumn.CellEditEvent<Patient, String> event)
{
String newRoomNumber = event.getNewValue(); String newRoomNumber = event.getNewValue();
if (!isValidRoomNumber(newRoomNumber)) { if (!isValidRoomNumber(newRoomNumber))
{
showValidationError("Room Number"); showValidationError("Room Number");
event.getTableView().refresh(); event.getTableView().refresh();
return; return;
@ -167,60 +187,87 @@ public class AllPatientController {
this.doUpdate(event); this.doUpdate(event);
} }
@FXML
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);
}
private void doUpdate(TableColumn.CellEditEvent<Patient, String> event) { private void doUpdate(TableColumn.CellEditEvent<Patient, String> event)
try { {
try
{
this.dao.update(event.getRowValue()); this.dao.update(event.getRowValue());
} catch (SQLException exception) { } catch (SQLException exception)
{
exception.printStackTrace(); exception.printStackTrace();
} }
} }
private void readAllAndShowInTableView() { private void readAllAndShowInTableView()
{
this.patients.clear(); this.patients.clear();
this.dao = DaoFactory.getDaoFactory().createPatientDAO(); this.dao = DaoFactory.getDaoFactory().createPatientDAO();
try { try
{
this.patients.addAll(this.dao.readAll()); this.patients.addAll(this.dao.readAll());
} catch (SQLException exception) { } catch (SQLException exception)
{
exception.printStackTrace(); exception.printStackTrace();
} }
} }
@FXML @FXML
public void handleDelete() { public void handleDelete()
{
Patient selectedItem = this.tableView.getSelectionModel().getSelectedItem(); Patient selectedItem = this.tableView.getSelectionModel().getSelectedItem();
if (selectedItem != null) { if (selectedItem != null)
try { {
try
{
DaoFactory.getDaoFactory().createPatientDAO().deleteById(selectedItem.getPid()); DaoFactory.getDaoFactory().createPatientDAO().deleteById(selectedItem.getPid());
this.tableView.getItems().remove(selectedItem); this.tableView.getItems().remove(selectedItem);
} catch (SQLException exception) { } catch (SQLException exception)
{
exception.printStackTrace(); exception.printStackTrace();
} }
} }
} }
@FXML @FXML
public void handleAdd() { public void handleAdd()
{
String surname = this.textFieldSurname.getText(); String surname = this.textFieldSurname.getText();
String firstName = this.textFieldFirstName.getText(); String firstName = this.textFieldFirstName.getText();
String birthday = this.textFieldDateOfBirth.getText(); String birthday = this.textFieldDateOfBirth.getText();
LocalDate date = DateConverter.convertStringToLocalDate(birthday); LocalDate date = DateConverter.convertStringToLocalDate(birthday);
String careLevel = this.textFieldCareLevel.getText(); String careLevel = this.textFieldCareLevel.getText();
String roomNumber = this.textFieldRoomNumber.getText(); String roomNumber = this.textFieldRoomNumber.getText();
try { String assets = this.textFieldAssets.getText();
this.dao.create(new Patient(firstName, surname, date, careLevel, roomNumber)); try
} catch (SQLException exception) { {
this.dao.create(new Patient(firstName, surname, date, careLevel, roomNumber, assets));
} catch (SQLException exception)
{
exception.printStackTrace(); exception.printStackTrace();
} }
readAllAndShowInTableView(); readAllAndShowInTableView();
clearTextfields(); clearTextfields();
} }
private void clearTextfields() { private void clearTextfields()
{
this.textFieldFirstName.clear(); this.textFieldFirstName.clear();
this.textFieldSurname.clear(); this.textFieldSurname.clear();
this.textFieldDateOfBirth.clear(); this.textFieldDateOfBirth.clear();
this.textFieldCareLevel.clear(); this.textFieldCareLevel.clear();
this.textFieldRoomNumber.clear(); this.textFieldRoomNumber.clear();
this.textFieldAssets.clear();
} }
} }

View file

@ -32,14 +32,15 @@ public class PatientDao extends DaoImp<Patient> {
protected PreparedStatement getCreateStatement(Patient patient) { protected PreparedStatement getCreateStatement(Patient patient) {
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
try { try {
final String SQL = "INSERT INTO patient (firstname, surname, dateOfBirth, carelevel, roomnumber) " + final String SQL = "INSERT INTO patient (firstname, surname, dateOfBirth, carelevel, roomnumber, assets) " +
"VALUES (?, ?, ?, ?, ?)"; "VALUES (?, ?, ?, ?, ?, ?)";
preparedStatement = this.connection.prepareStatement(SQL); preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setString(1, patient.getFirstName()); preparedStatement.setString(1, patient.getFirstName());
preparedStatement.setString(2, patient.getSurname()); preparedStatement.setString(2, patient.getSurname());
preparedStatement.setString(3, patient.getDateOfBirth()); preparedStatement.setString(3, patient.getDateOfBirth());
preparedStatement.setString(4, patient.getCareLevel()); preparedStatement.setString(4, patient.getCareLevel());
preparedStatement.setString(5, patient.getRoomNumber()); preparedStatement.setString(5, patient.getRoomNumber());
preparedStatement.setString(6, patient.getAssets());
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
@ -79,7 +80,8 @@ public class PatientDao extends DaoImp<Patient> {
result.getString(3), result.getString(3),
DateConverter.convertStringToLocalDate(result.getString(4)), DateConverter.convertStringToLocalDate(result.getString(4)),
result.getString(5), result.getString(5),
result.getString(6)); result.getString(6),
result.getString(7));
} }
/** /**
@ -113,7 +115,7 @@ public class PatientDao extends DaoImp<Patient> {
LocalDate date = DateConverter.convertStringToLocalDate(result.getString(4)); LocalDate date = DateConverter.convertStringToLocalDate(result.getString(4));
Patient patient = new Patient(result.getInt(1), result.getString(2), Patient patient = new Patient(result.getInt(1), result.getString(2),
result.getString(3), date, result.getString(3), date,
result.getString(5), result.getString(6)); result.getString(5), result.getString(6), result.getString(7));
list.add(patient); list.add(patient);
} }
return list; return list;
@ -137,6 +139,7 @@ public class PatientDao extends DaoImp<Patient> {
"dateOfBirth = ?, " + "dateOfBirth = ?, " +
"carelevel = ?, " + "carelevel = ?, " +
"roomnumber = ?, " + "roomnumber = ?, " +
"assets = ? " +
"WHERE pid = ?"; "WHERE pid = ?";
preparedStatement = this.connection.prepareStatement(SQL); preparedStatement = this.connection.prepareStatement(SQL);
preparedStatement.setString(1, patient.getFirstName()); preparedStatement.setString(1, patient.getFirstName());
@ -144,7 +147,8 @@ public class PatientDao extends DaoImp<Patient> {
preparedStatement.setString(3, patient.getDateOfBirth()); preparedStatement.setString(3, patient.getDateOfBirth());
preparedStatement.setString(4, patient.getCareLevel()); preparedStatement.setString(4, patient.getCareLevel());
preparedStatement.setString(5, patient.getRoomNumber()); preparedStatement.setString(5, patient.getRoomNumber());
preparedStatement.setLong(6, patient.getPid()); preparedStatement.setString(6, patient.getAssets());
preparedStatement.setLong(7, patient.getPid());
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }

View file

@ -37,7 +37,8 @@ public class PatientFixture implements Fixture<Patient>
" surname TEXT NOT NULL, " + " surname TEXT NOT NULL, " +
" dateOfBirth TEXT NOT NULL, " + " dateOfBirth TEXT NOT NULL, " +
" carelevel TEXT NOT NULL, " + " carelevel TEXT NOT NULL, " +
" roomnumber TEXT NOT NULL" + " roomnumber TEXT NOT NULL, " +
" assets TEXt NOT NULL" +
");"; ");";
try (Statement statement = connection.createStatement()) try (Statement statement = connection.createStatement())
{ {
@ -58,42 +59,48 @@ public class PatientFixture implements Fixture<Patient>
"Herberger", "Herberger",
convertStringToLocalDate("1945-12-01"), convertStringToLocalDate("1945-12-01"),
"4", "4",
"202" "202",
"vermögend"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Martina", "Martina",
"Gerdsen", "Gerdsen",
convertStringToLocalDate("1954-08-12"), convertStringToLocalDate("1954-08-12"),
"5", "5",
"010" "010",
"arm"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Gertrud", "Gertrud",
"Franzen", "Franzen",
convertStringToLocalDate("1949-04-16"), convertStringToLocalDate("1949-04-16"),
"3", "3",
"002" "002",
"normal"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Ahmet", "Ahmet",
"Yilmaz", "Yilmaz",
convertStringToLocalDate("1941-02-22"), convertStringToLocalDate("1941-02-22"),
"3", "3",
"013" "013",
"normal"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Hans", "Hans",
"Neumann", "Neumann",
convertStringToLocalDate("1955-12-12"), convertStringToLocalDate("1955-12-12"),
"2", "2",
"001" "001",
"sehr vermögend"
)); ));
patients.add(new Patient( patients.add(new Patient(
"Elisabeth", "Elisabeth",
"Müller", "Müller",
convertStringToLocalDate("1958-03-07"), convertStringToLocalDate("1958-03-07"),
"5", "5",
"110" "110",
"arm"
)); ));
PatientDao dao = DaoFactory.getDaoFactory().createPatientDAO(); PatientDao dao = DaoFactory.getDaoFactory().createPatientDAO();

View file

@ -16,6 +16,7 @@ public class Patient extends Person {
private final SimpleStringProperty dateOfBirth; private final SimpleStringProperty dateOfBirth;
private final SimpleStringProperty careLevel; private final SimpleStringProperty careLevel;
private final SimpleStringProperty roomNumber; private final SimpleStringProperty roomNumber;
private final SimpleStringProperty assets;
private final List<Treatment> allTreatments = new ArrayList<>(); private final List<Treatment> allTreatments = new ArrayList<>();
/** /**
@ -27,18 +28,21 @@ public class Patient extends Person {
* @param dateOfBirth Date of birth of the patient. * @param dateOfBirth Date of birth of the patient.
* @param careLevel Care level of the patient. * @param careLevel Care level of the patient.
* @param roomNumber Room number of the patient. * @param roomNumber Room number of the patient.
* @param assets Assets of the patient.
*/ */
public Patient( public Patient(
String firstName, String firstName,
String surname, String surname,
LocalDate dateOfBirth, LocalDate dateOfBirth,
String careLevel, String careLevel,
String roomNumber String roomNumber,
String assets
) { ) {
super(firstName, surname); super(firstName, surname);
this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth)); this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth));
this.careLevel = new SimpleStringProperty(careLevel); this.careLevel = new SimpleStringProperty(careLevel);
this.roomNumber = new SimpleStringProperty(roomNumber); this.roomNumber = new SimpleStringProperty(roomNumber);
this.assets = new SimpleStringProperty(assets);
} }
/** /**
@ -51,6 +55,7 @@ public class Patient extends Person {
* @param dateOfBirth Date of birth of the patient. * @param dateOfBirth Date of birth of the patient.
* @param careLevel Care level of the patient. * @param careLevel Care level of the patient.
* @param roomNumber Room number of the patient. * @param roomNumber Room number of the patient.
* @param assets Assets of the patient.
*/ */
public Patient( public Patient(
long pid, long pid,
@ -58,13 +63,15 @@ public class Patient extends Person {
String surname, String surname,
LocalDate dateOfBirth, LocalDate dateOfBirth,
String careLevel, String careLevel,
String roomNumber String roomNumber,
String assets
) { ) {
super(firstName, surname); super(firstName, surname);
this.pid = new SimpleLongProperty(pid); this.pid = new SimpleLongProperty(pid);
this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth)); this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth));
this.careLevel = new SimpleStringProperty(careLevel); this.careLevel = new SimpleStringProperty(careLevel);
this.roomNumber = new SimpleStringProperty(roomNumber); this.roomNumber = new SimpleStringProperty(roomNumber);
this.assets = new SimpleStringProperty(assets);
} }
public long getPid() { public long getPid() {
@ -117,6 +124,17 @@ public class Patient extends Person {
this.roomNumber.set(roomNumber); this.roomNumber.set(roomNumber);
} }
public String getAssets() {
return assets.get();
}
public SimpleStringProperty assetsProperty() {
return assets;
}
public void setAssets(String assets) {
this.assets.set(assets);
}
/** /**
* Adds a treatment to the list of treatments, if the list does not already contain the treatment. * Adds a treatment to the list of treatments, if the list does not already contain the treatment.
@ -139,6 +157,7 @@ public class Patient extends Person {
"\nBirthday: " + this.dateOfBirth + "\nBirthday: " + this.dateOfBirth +
"\nCarelevel: " + this.careLevel + "\nCarelevel: " + this.careLevel +
"\nRoomnumber: " + this.roomNumber + "\nRoomnumber: " + this.roomNumber +
"\nAssets: " + this.assets +
"\n"; "\n";
} }
} }

View file

@ -23,6 +23,7 @@
<TableColumn fx:id="columnDateOfBirth" maxWidth="7500.0" onEditCommit="#handleOnEditDateOfBirth" prefWidth="75.0" text="Geburtstag" /> <TableColumn fx:id="columnDateOfBirth" maxWidth="7500.0" onEditCommit="#handleOnEditDateOfBirth" prefWidth="75.0" text="Geburtstag" />
<TableColumn fx:id="columnCareLevel" onEditCommit="#handleOnEditCareLevel" prefWidth="75.0" text="Pflegegrad" /> <TableColumn fx:id="columnCareLevel" onEditCommit="#handleOnEditCareLevel" prefWidth="75.0" text="Pflegegrad" />
<TableColumn fx:id="columnRoomNumber" onEditCommit="#handleOnEditRoomNumber" prefWidth="75.0" text="Raum" /> <TableColumn fx:id="columnRoomNumber" onEditCommit="#handleOnEditRoomNumber" prefWidth="75.0" text="Raum" />
<TableColumn fx:id="columnAssets" onEditCommit="#handleOnEditAssets" prefWidth="75.0" text="Vermögensstand" />
</columns> </columns>
<columnResizePolicy> <columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /> <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
@ -46,6 +47,7 @@
<TextField fx:id="textFieldDateOfBirth" minWidth="160.0" prefWidth="160.0" promptText="Geburtstag" GridPane.columnIndex="2" /> <TextField fx:id="textFieldDateOfBirth" minWidth="160.0" prefWidth="160.0" promptText="Geburtstag" GridPane.columnIndex="2" />
<TextField fx:id="textFieldCareLevel" prefHeight="26.0" prefWidth="200.0" promptText="Pflegegrad" GridPane.rowIndex="1" /> <TextField fx:id="textFieldCareLevel" prefHeight="26.0" prefWidth="200.0" promptText="Pflegegrad" GridPane.rowIndex="1" />
<TextField fx:id="textFieldRoomNumber" prefHeight="26.0" prefWidth="200.0" promptText="Raum" GridPane.columnIndex="1" GridPane.rowIndex="1" /> <TextField fx:id="textFieldRoomNumber" prefHeight="26.0" prefWidth="200.0" promptText="Raum" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField fx:id="textFieldAssets" minWidth="160.0" prefWidth="160.0" promptText="Vermögensstand" GridPane.columnIndex="2" GridPane.rowIndex="1" />
</children> </children>
<padding> <padding>
<Insets right="10.0" /> <Insets right="10.0" />