#7 Implement Logic
This commit is contained in:
parent
efe10a72a3
commit
f77072ab70
4 changed files with 216 additions and 28 deletions
|
@ -9,6 +9,9 @@ import javafx.scene.control.Tab;
|
|||
import javafx.scene.control.TabPane;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import de.hitec.nhplus.treatment.Treatment;
|
||||
import de.hitec.nhplus.medication.Medication;
|
||||
import de.hitec.nhplus.patient.Patient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
@ -29,10 +32,18 @@ public class MainWindowController {
|
|||
@FXML
|
||||
private Tab patientTab;
|
||||
@FXML
|
||||
private AnchorPane treatmentPage;
|
||||
private AnchorPane activeTreatmentPage;
|
||||
@FXML
|
||||
private Tab treatmentTab;
|
||||
@FXML
|
||||
private TabPane treatmentTabPane;
|
||||
@FXML
|
||||
private Tab activeTreatmentTab;
|
||||
@FXML
|
||||
private AnchorPane lockedTreatmentPage;
|
||||
@FXML
|
||||
private Tab lockedTreatmentTab;
|
||||
@FXML
|
||||
private Tab nurseTab;
|
||||
@FXML
|
||||
private TabPane nurseTabPane;
|
||||
|
@ -58,19 +69,25 @@ public class MainWindowController {
|
|||
mainTabPane.getSelectionModel().select(patientTab);
|
||||
|
||||
patientTab.setOnSelectionChanged(event -> loadPatientPage());
|
||||
treatmentTab.setOnSelectionChanged(event -> loadTreatmentsPage());
|
||||
nurseTab.setOnSelectionChanged(event -> loadNursePage());
|
||||
medicationTab.setOnSelectionChanged(event -> loadMedicationPage());
|
||||
|
||||
|
||||
nurseTab.setOnSelectionChanged(event -> loadNursePage());
|
||||
nurseTabPane.getSelectionModel().select(activeNurseTab);
|
||||
|
||||
activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage());
|
||||
lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage());
|
||||
|
||||
treatmentTab.setOnSelectionChanged(event -> loadTreatmentPage());
|
||||
treatmentTabPane.getSelectionModel().select(activeTreatmentTab);
|
||||
|
||||
activeTreatmentTab.setOnSelectionChanged(event -> loadActiveTreatmentPage());
|
||||
lockedTreatmentTab.setOnSelectionChanged(event -> loadLockedTreatmentPage());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the patient page into its tab.
|
||||
* Loads the {@link Patient} page into its tab.
|
||||
*/
|
||||
private void loadPatientPage() {
|
||||
try {
|
||||
|
@ -88,14 +105,46 @@ public class MainWindowController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads the {@link } page into its tab.
|
||||
* Loads the {@link Treatment } tab.
|
||||
*/
|
||||
private void loadTreatmentsPage() {
|
||||
private void loadTreatmentPage() {
|
||||
SelectionModel<Tab> selectionModel = treatmentTabPane.getSelectionModel();
|
||||
Tab selectedTab = selectionModel.getSelectedItem();
|
||||
if (selectedTab == activeTreatmentTab) {
|
||||
loadActiveTreatmentPage();
|
||||
}
|
||||
if (selectedTab == lockedTreatmentTab) {
|
||||
loadLockedTreatmentPage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the active {@link Treatment} page into its tab.
|
||||
*/
|
||||
private void loadActiveTreatmentPage() {
|
||||
try {
|
||||
BorderPane treatmentsPane = FXMLLoader.load(
|
||||
BorderPane activeTreatmentPane = FXMLLoader.load(
|
||||
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/treatment/AllTreatmentView.fxml"))
|
||||
);
|
||||
treatmentPage.getChildren().setAll(treatmentsPane);
|
||||
activeTreatmentPage.getChildren().setAll(activeTreatmentPane);
|
||||
AnchorPane.setTopAnchor(activeTreatmentPane, 0d);
|
||||
AnchorPane.setBottomAnchor(activeTreatmentPane, 0d);
|
||||
AnchorPane.setLeftAnchor(activeTreatmentPane, 0d);
|
||||
AnchorPane.setRightAnchor(activeTreatmentPane, 0d);
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the locked {@link Treatment} page into its tab.
|
||||
*/
|
||||
private void loadLockedTreatmentPage() {
|
||||
try {
|
||||
BorderPane treatmentsPane = FXMLLoader.load(
|
||||
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/treatment/LockedTreatmentView.fxml"))
|
||||
);
|
||||
lockedTreatmentPage.getChildren().setAll(treatmentsPane);
|
||||
AnchorPane.setTopAnchor(treatmentsPane, 0d);
|
||||
AnchorPane.setBottomAnchor(treatmentsPane, 0d);
|
||||
AnchorPane.setLeftAnchor(treatmentsPane, 0d);
|
||||
|
@ -106,7 +155,7 @@ public class MainWindowController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads the nurse page into its tab.
|
||||
* Loads the {@link Nurse} page into its tab.
|
||||
*/
|
||||
private void loadNursePage() {
|
||||
SelectionModel<Tab> selectionModel = nurseTabPane.getSelectionModel();
|
||||
|
@ -156,7 +205,7 @@ public class MainWindowController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads the medication page into its tab.
|
||||
* Loads the {@link Medication} page into its tab.
|
||||
*/
|
||||
private void loadMedicationPage() {
|
||||
try {
|
||||
|
|
|
@ -22,6 +22,8 @@ import java.sql.SQLException;
|
|||
*
|
||||
* @author Dominik Säume
|
||||
* @author Ole Kück
|
||||
* @author Armin Ribic
|
||||
* @author Dorian Nemec
|
||||
*/
|
||||
public class AllNurseController {
|
||||
@FXML
|
||||
|
|
|
@ -20,6 +20,7 @@ import javafx.stage.Stage;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
|
@ -27,6 +28,8 @@ import java.util.ArrayList;
|
|||
*
|
||||
* @author Bernd Heidemann
|
||||
* @author Dominik Säume
|
||||
* @author Armin Ribic
|
||||
* @author Dorian Nemec
|
||||
*/
|
||||
public class AllTreatmentController {
|
||||
|
||||
|
@ -61,7 +64,7 @@ public class AllTreatmentController {
|
|||
public ComboBox<String> comboBoxNurseSelection;
|
||||
|
||||
@FXML
|
||||
private Button buttonDelete;
|
||||
private Button buttonLock;
|
||||
|
||||
private final ObservableList<Treatment> treatments = FXCollections.observableArrayList();
|
||||
private TreatmentDao dao;
|
||||
|
@ -100,15 +103,16 @@ public class AllTreatmentController {
|
|||
this.columnDescription.setCellValueFactory(new PropertyValueFactory<>("description"));
|
||||
this.tableView.setItems(this.treatments);
|
||||
|
||||
this.buttonDelete.setDisable(true);
|
||||
this.buttonLock.setDisable(true);
|
||||
this.tableView
|
||||
.getSelectionModel()
|
||||
.selectedItemProperty()
|
||||
.addListener((observableValue, oldTreatment, newTreatment) ->
|
||||
AllTreatmentController.this.buttonDelete.setDisable(newTreatment == null)
|
||||
AllTreatmentController.this.buttonLock.setDisable(newTreatment == null)
|
||||
);
|
||||
|
||||
this.createComboBoxData();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -136,7 +140,7 @@ public class AllTreatmentController {
|
|||
this.patientSelection.add(patient.getSurName());
|
||||
}
|
||||
|
||||
nurseList = (ArrayList<Nurse>) nurseDao.readAll();
|
||||
nurseList = (ArrayList<Nurse>) nurseDao.readAllActive();
|
||||
for (Nurse nurse : nurseList) {
|
||||
this.nurseSelection.add(nurse.getSurName());
|
||||
}
|
||||
|
@ -258,18 +262,6 @@ public class AllTreatmentController {
|
|||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleDelete() {
|
||||
int index = this.tableView.getSelectionModel().getSelectedIndex();
|
||||
Treatment t = this.treatments.remove(index);
|
||||
TreatmentDao dao = DaoFactory.getInstance().createTreatmentDao();
|
||||
try {
|
||||
dao.delete(t.getId());
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleNewTreatment() {
|
||||
String selectedPatient = this.comboBoxPatientSelection.getSelectionModel().getSelectedItem();
|
||||
|
@ -316,4 +308,22 @@ public class AllTreatmentController {
|
|||
});
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleLock(){
|
||||
Treatment selectedItem = this.tableView.getSelectionModel().getSelectedItem();
|
||||
if (selectedItem == null){
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
selectedItem.setLocked(true);
|
||||
this.dao.update(selectedItem);
|
||||
}catch (SQLException exception){
|
||||
exception.printStackTrace();
|
||||
}
|
||||
readAllAndShowInTableView();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
package de.hitec.nhplus.treatment;
|
||||
|
||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||
import de.hitec.nhplus.nurse.Nurse;
|
||||
import de.hitec.nhplus.patient.Patient;
|
||||
import de.hitec.nhplus.treatment.database.TreatmentDao;
|
||||
import de.hitec.nhplus.utils.DateConverter;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Controller for all locked treatments.
|
||||
*
|
||||
* @author Armin Ribic
|
||||
* @author Dorian Nemec
|
||||
*/
|
||||
public class LockedTreatmentController {
|
||||
|
||||
@FXML
|
||||
public Button buttonUnlock;
|
||||
@FXML
|
||||
public TableView<Treatment> tableView;
|
||||
@FXML
|
||||
public TableColumn<Treatment, Long> columnId;
|
||||
@FXML
|
||||
private TableColumn<Treatment, String> columnPatient;
|
||||
@FXML
|
||||
private TableColumn<Treatment, String> columnNurse;
|
||||
@FXML
|
||||
private TableColumn<Treatment, String> columnDeleteDate;
|
||||
|
||||
private final ObservableList<Treatment> treatments = FXCollections.observableArrayList();
|
||||
private TreatmentDao treatmentDao;
|
||||
|
||||
/**
|
||||
* This method allows initializing a {@link LockedTreatmentController} object
|
||||
* that is called after the binding of all the fields.
|
||||
*/
|
||||
public void initialize() {
|
||||
this.readAllAndShowInTableView();
|
||||
|
||||
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
|
||||
|
||||
this.columnPatient.setCellValueFactory(
|
||||
cellData -> {
|
||||
Patient patient = cellData.getValue().getPatient();
|
||||
return new SimpleStringProperty(patient.getSurName() + ", " + patient.getFirstName());
|
||||
}
|
||||
);
|
||||
|
||||
this.columnNurse.setCellValueFactory(
|
||||
cellData -> {
|
||||
Nurse nurse = cellData.getValue().getNurse();
|
||||
return new SimpleStringProperty(nurse.getSurName() + ", " + nurse.getFirstName());
|
||||
}
|
||||
);
|
||||
this.columnDeleteDate.setCellValueFactory(cellData -> new SimpleStringProperty(
|
||||
DateConverter.convertLocalDateToString(cellData.getValue().calculateDeleteDate())));
|
||||
|
||||
|
||||
this.tableView.setItems(this.treatments);
|
||||
handleDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all locked {@link Treatment} data and shows it in the table.
|
||||
*/
|
||||
private void readAllAndShowInTableView() {
|
||||
this.treatments.clear();
|
||||
|
||||
this.treatmentDao = DaoFactory.getInstance().createTreatmentDao();
|
||||
try {
|
||||
this.treatments.addAll(this.treatmentDao.readAllLocked());
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void unlockTreatment() {
|
||||
Treatment selectedItem = this.tableView.getSelectionModel().getSelectedItem();
|
||||
if (selectedItem == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
selectedItem.setLocked(false);
|
||||
this.treatmentDao.update(selectedItem);
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
readAllAndShowInTableView();
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleDelete() {
|
||||
Treatment selecteditem;
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate deleteDate;
|
||||
|
||||
for (Treatment treatment : treatments) {
|
||||
selecteditem = treatment;
|
||||
deleteDate = selecteditem.calculateDeleteDate();
|
||||
if (today.isEqual(deleteDate) || today.isAfter(deleteDate)) {
|
||||
try {
|
||||
treatmentDao.delete(selecteditem.getId());
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
readAllAndShowInTableView();
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue