Compare commits
No commits in common. "dba73c1994bc1eeb47c85a9b7339a228dcc14390" and "2b96bc967c1971aa009a3bdbff468db1eac2a94b" have entirely different histories.
dba73c1994
...
2b96bc967c
6 changed files with 150 additions and 71 deletions
Binary file not shown.
|
@ -20,7 +20,8 @@ import java.time.LocalDate;
|
|||
|
||||
import static de.hitec.nhplus.utils.Validator.*;
|
||||
|
||||
public class AllPatientController {
|
||||
public class AllPatientController
|
||||
{
|
||||
|
||||
@FXML
|
||||
private TableView<Patient> tableView;
|
||||
|
@ -37,6 +38,8 @@ public class AllPatientController {
|
|||
@FXML
|
||||
private TableColumn<Patient, String> columnRoomNumber;
|
||||
@FXML
|
||||
private TableColumn<Patient, String> columnAssets;
|
||||
@FXML
|
||||
private Button buttonDelete;
|
||||
@FXML
|
||||
private Button buttonAdd;
|
||||
|
@ -50,11 +53,14 @@ public class AllPatientController {
|
|||
private TextField textFieldCareLevel;
|
||||
@FXML
|
||||
private TextField textFieldRoomNumber;
|
||||
@FXML
|
||||
private TextField textFieldAssets;
|
||||
|
||||
private final ObservableList<Patient> patients = FXCollections.observableArrayList();
|
||||
private PatientDao dao;
|
||||
|
||||
public void initialize() {
|
||||
public void initialize()
|
||||
{
|
||||
this.readAllAndShowInTableView();
|
||||
|
||||
this.columnId.setCellValueFactory(new PropertyValueFactory<>("pid"));
|
||||
|
@ -74,6 +80,8 @@ public class AllPatientController {
|
|||
this.columnRoomNumber.setCellValueFactory(new PropertyValueFactory<>("roomNumber"));
|
||||
this.columnRoomNumber.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
|
||||
this.columnAssets.setCellValueFactory(new PropertyValueFactory<>("assets"));
|
||||
this.columnAssets.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
|
||||
this.tableView.setItems(this.patients);
|
||||
|
||||
|
@ -95,7 +103,8 @@ public class AllPatientController {
|
|||
&& isValidSurName(this.textFieldSurname.getText())
|
||||
&& isValidDate(this.textFieldDateOfBirth.getText())
|
||||
&& isValidCareLevel(this.textFieldCareLevel.getText())
|
||||
&& isValidRoomNumber(textFieldRoomNumber.getText());
|
||||
&& isValidRoomNumber(textFieldRoomNumber.getText())
|
||||
&& !this.textFieldAssets.getText().isBlank();
|
||||
|
||||
AllPatientController.this.buttonAdd.setDisable(!isValid);
|
||||
};
|
||||
|
@ -105,12 +114,15 @@ public class AllPatientController {
|
|||
this.textFieldDateOfBirth.textProperty().addListener(inputNewPatientValidationListener);
|
||||
this.textFieldCareLevel.textProperty().addListener(inputNewPatientValidationListener);
|
||||
this.textFieldRoomNumber.textProperty().addListener(inputNewPatientValidationListener);
|
||||
this.textFieldAssets.textProperty().addListener(inputNewPatientValidationListener);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleOnEditFirstname(TableColumn.CellEditEvent<Patient, String> event) {
|
||||
public void handleOnEditFirstname(TableColumn.CellEditEvent<Patient, String> event)
|
||||
{
|
||||
String newFirstName = event.getNewValue();
|
||||
if (!isValidFirstName(newFirstName)) {
|
||||
if (!isValidFirstName(newFirstName))
|
||||
{
|
||||
showValidationError("First Name");
|
||||
event.getTableView().refresh();
|
||||
return;
|
||||
|
@ -120,9 +132,11 @@ public class AllPatientController {
|
|||
}
|
||||
|
||||
@FXML
|
||||
public void handleOnEditSurname(TableColumn.CellEditEvent<Patient, String> event) {
|
||||
public void handleOnEditSurname(TableColumn.CellEditEvent<Patient, String> event)
|
||||
{
|
||||
String newSurName = event.getNewValue();
|
||||
if (!isValidSurName(newSurName)) {
|
||||
if (!isValidSurName(newSurName))
|
||||
{
|
||||
showValidationError("Sur Name");
|
||||
event.getTableView().refresh();
|
||||
return;
|
||||
|
@ -132,9 +146,11 @@ public class AllPatientController {
|
|||
}
|
||||
|
||||
@FXML
|
||||
public void handleOnEditDateOfBirth(TableColumn.CellEditEvent<Patient, String> event) {
|
||||
public void handleOnEditDateOfBirth(TableColumn.CellEditEvent<Patient, String> event)
|
||||
{
|
||||
String newDateString = event.getNewValue();
|
||||
if (!isValidDate(newDateString)) {
|
||||
if (!isValidDate(newDateString))
|
||||
{
|
||||
showValidationError("Date");
|
||||
event.getTableView().refresh();
|
||||
return;
|
||||
|
@ -144,9 +160,11 @@ public class AllPatientController {
|
|||
}
|
||||
|
||||
@FXML
|
||||
public void handleOnEditCareLevel(TableColumn.CellEditEvent<Patient, String> event) {
|
||||
public void handleOnEditCareLevel(TableColumn.CellEditEvent<Patient, String> event)
|
||||
{
|
||||
String newCareLevel = event.getNewValue();
|
||||
if (!isValidCareLevel(newCareLevel)) {
|
||||
if (!isValidCareLevel(newCareLevel))
|
||||
{
|
||||
showValidationError("Care Level");
|
||||
event.getTableView().refresh();
|
||||
return;
|
||||
|
@ -156,9 +174,11 @@ public class AllPatientController {
|
|||
}
|
||||
|
||||
@FXML
|
||||
public void handleOnEditRoomNumber(TableColumn.CellEditEvent<Patient, String> event) {
|
||||
public void handleOnEditRoomNumber(TableColumn.CellEditEvent<Patient, String> event)
|
||||
{
|
||||
String newRoomNumber = event.getNewValue();
|
||||
if (!isValidRoomNumber(newRoomNumber)) {
|
||||
if (!isValidRoomNumber(newRoomNumber))
|
||||
{
|
||||
showValidationError("Room Number");
|
||||
event.getTableView().refresh();
|
||||
return;
|
||||
|
@ -167,60 +187,87 @@ public class AllPatientController {
|
|||
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) {
|
||||
try {
|
||||
private void doUpdate(TableColumn.CellEditEvent<Patient, String> event)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.dao.update(event.getRowValue());
|
||||
} catch (SQLException exception) {
|
||||
} catch (SQLException exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleAdd() {
|
||||
public void handleAdd()
|
||||
{
|
||||
String surname = this.textFieldSurname.getText();
|
||||
String firstName = this.textFieldFirstName.getText();
|
||||
String birthday = this.textFieldDateOfBirth.getText();
|
||||
LocalDate date = DateConverter.convertStringToLocalDate(birthday);
|
||||
String careLevel = this.textFieldCareLevel.getText();
|
||||
String roomNumber = this.textFieldRoomNumber.getText();
|
||||
try {
|
||||
this.dao.create(new Patient(firstName, surname, date, careLevel, roomNumber));
|
||||
} catch (SQLException exception) {
|
||||
String assets = this.textFieldAssets.getText();
|
||||
try
|
||||
{
|
||||
this.dao.create(new Patient(firstName, surname, date, careLevel, roomNumber, assets));
|
||||
} catch (SQLException exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
readAllAndShowInTableView();
|
||||
clearTextfields();
|
||||
}
|
||||
|
||||
private void clearTextfields() {
|
||||
private void clearTextfields()
|
||||
{
|
||||
this.textFieldFirstName.clear();
|
||||
this.textFieldSurname.clear();
|
||||
this.textFieldDateOfBirth.clear();
|
||||
this.textFieldCareLevel.clear();
|
||||
this.textFieldRoomNumber.clear();
|
||||
this.textFieldAssets.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,14 +32,15 @@ public class PatientDao extends DaoImp<Patient> {
|
|||
protected PreparedStatement getCreateStatement(Patient patient) {
|
||||
PreparedStatement preparedStatement = null;
|
||||
try {
|
||||
final String SQL = "INSERT INTO patient (firstname, surname, dateOfBirth, carelevel, roomnumber) " +
|
||||
"VALUES (?, ?, ?, ?, ?)";
|
||||
final String SQL = "INSERT INTO patient (firstname, surname, dateOfBirth, carelevel, roomnumber, assets) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?)";
|
||||
preparedStatement = this.connection.prepareStatement(SQL);
|
||||
preparedStatement.setString(1, patient.getFirstName());
|
||||
preparedStatement.setString(2, patient.getSurname());
|
||||
preparedStatement.setString(3, patient.getDateOfBirth());
|
||||
preparedStatement.setString(4, patient.getCareLevel());
|
||||
preparedStatement.setString(5, patient.getRoomNumber());
|
||||
preparedStatement.setString(6, patient.getAssets());
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
@ -79,7 +80,8 @@ public class PatientDao extends DaoImp<Patient> {
|
|||
result.getString(3),
|
||||
DateConverter.convertStringToLocalDate(result.getString(4)),
|
||||
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));
|
||||
Patient patient = new Patient(result.getInt(1), result.getString(2),
|
||||
result.getString(3), date,
|
||||
result.getString(5), result.getString(6));
|
||||
result.getString(5), result.getString(6), result.getString(7));
|
||||
list.add(patient);
|
||||
}
|
||||
return list;
|
||||
|
@ -137,6 +139,7 @@ public class PatientDao extends DaoImp<Patient> {
|
|||
"dateOfBirth = ?, " +
|
||||
"carelevel = ?, " +
|
||||
"roomnumber = ?, " +
|
||||
"assets = ? " +
|
||||
"WHERE pid = ?";
|
||||
preparedStatement = this.connection.prepareStatement(SQL);
|
||||
preparedStatement.setString(1, patient.getFirstName());
|
||||
|
@ -144,7 +147,8 @@ public class PatientDao extends DaoImp<Patient> {
|
|||
preparedStatement.setString(3, patient.getDateOfBirth());
|
||||
preparedStatement.setString(4, patient.getCareLevel());
|
||||
preparedStatement.setString(5, patient.getRoomNumber());
|
||||
preparedStatement.setLong(6, patient.getPid());
|
||||
preparedStatement.setString(6, patient.getAssets());
|
||||
preparedStatement.setLong(7, patient.getPid());
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@ public class PatientFixture implements Fixture<Patient>
|
|||
" surname TEXT NOT NULL, " +
|
||||
" dateOfBirth TEXT NOT NULL, " +
|
||||
" carelevel TEXT NOT NULL, " +
|
||||
" roomnumber TEXT NOT NULL" +
|
||||
" roomnumber TEXT NOT NULL, " +
|
||||
" assets TEXt NOT NULL" +
|
||||
");";
|
||||
try (Statement statement = connection.createStatement())
|
||||
{
|
||||
|
@ -58,42 +59,48 @@ public class PatientFixture implements Fixture<Patient>
|
|||
"Herberger",
|
||||
convertStringToLocalDate("1945-12-01"),
|
||||
"4",
|
||||
"202"
|
||||
"202",
|
||||
"vermögend"
|
||||
));
|
||||
patients.add(new Patient(
|
||||
"Martina",
|
||||
"Gerdsen",
|
||||
convertStringToLocalDate("1954-08-12"),
|
||||
"5",
|
||||
"010"
|
||||
"010",
|
||||
"arm"
|
||||
));
|
||||
patients.add(new Patient(
|
||||
"Gertrud",
|
||||
"Franzen",
|
||||
convertStringToLocalDate("1949-04-16"),
|
||||
"3",
|
||||
"002"
|
||||
"002",
|
||||
"normal"
|
||||
));
|
||||
patients.add(new Patient(
|
||||
"Ahmet",
|
||||
"Yilmaz",
|
||||
convertStringToLocalDate("1941-02-22"),
|
||||
"3",
|
||||
"013"
|
||||
"013",
|
||||
"normal"
|
||||
));
|
||||
patients.add(new Patient(
|
||||
"Hans",
|
||||
"Neumann",
|
||||
convertStringToLocalDate("1955-12-12"),
|
||||
"2",
|
||||
"001"
|
||||
"001",
|
||||
"sehr vermögend"
|
||||
));
|
||||
patients.add(new Patient(
|
||||
"Elisabeth",
|
||||
"Müller",
|
||||
convertStringToLocalDate("1958-03-07"),
|
||||
"5",
|
||||
"110"
|
||||
"110",
|
||||
"arm"
|
||||
));
|
||||
|
||||
PatientDao dao = DaoFactory.getDaoFactory().createPatientDAO();
|
||||
|
|
|
@ -16,6 +16,7 @@ public class Patient extends Person {
|
|||
private final SimpleStringProperty dateOfBirth;
|
||||
private final SimpleStringProperty careLevel;
|
||||
private final SimpleStringProperty roomNumber;
|
||||
private final SimpleStringProperty assets;
|
||||
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 careLevel Care level of the patient.
|
||||
* @param roomNumber Room number of the patient.
|
||||
* @param assets Assets of the patient.
|
||||
*/
|
||||
public Patient(
|
||||
String firstName,
|
||||
String surname,
|
||||
LocalDate dateOfBirth,
|
||||
String careLevel,
|
||||
String roomNumber
|
||||
String roomNumber,
|
||||
String assets
|
||||
) {
|
||||
super(firstName, surname);
|
||||
this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth));
|
||||
this.careLevel = new SimpleStringProperty(careLevel);
|
||||
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 careLevel Care level of the patient.
|
||||
* @param roomNumber Room number of the patient.
|
||||
* @param assets Assets of the patient.
|
||||
*/
|
||||
public Patient(
|
||||
long pid,
|
||||
|
@ -58,13 +63,15 @@ public class Patient extends Person {
|
|||
String surname,
|
||||
LocalDate dateOfBirth,
|
||||
String careLevel,
|
||||
String roomNumber
|
||||
String roomNumber,
|
||||
String assets
|
||||
) {
|
||||
super(firstName, surname);
|
||||
this.pid = new SimpleLongProperty(pid);
|
||||
this.dateOfBirth = new SimpleStringProperty(DateConverter.convertLocalDateToString(dateOfBirth));
|
||||
this.careLevel = new SimpleStringProperty(careLevel);
|
||||
this.roomNumber = new SimpleStringProperty(roomNumber);
|
||||
this.assets = new SimpleStringProperty(assets);
|
||||
}
|
||||
|
||||
public long getPid() {
|
||||
|
@ -117,6 +124,17 @@ public class Patient extends Person {
|
|||
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.
|
||||
|
@ -139,6 +157,7 @@ public class Patient extends Person {
|
|||
"\nBirthday: " + this.dateOfBirth +
|
||||
"\nCarelevel: " + this.careLevel +
|
||||
"\nRoomnumber: " + this.roomNumber +
|
||||
"\nAssets: " + this.assets +
|
||||
"\n";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
<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="columnRoomNumber" onEditCommit="#handleOnEditRoomNumber" prefWidth="75.0" text="Raum" />
|
||||
<TableColumn fx:id="columnAssets" onEditCommit="#handleOnEditAssets" prefWidth="75.0" text="Vermögensstand" />
|
||||
</columns>
|
||||
<columnResizePolicy>
|
||||
<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="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="textFieldAssets" minWidth="160.0" prefWidth="160.0" promptText="Vermögensstand" GridPane.columnIndex="2" GridPane.rowIndex="1" />
|
||||
</children>
|
||||
<padding>
|
||||
<Insets right="10.0" />
|
||||
|
|
Loading…
Reference in a new issue