|
|
|
@@ -26,29 +26,19 @@ import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* The controller class for the hospital ward history. |
|
|
|
* <p> |
|
|
|
* @author Johannes |
|
|
|
* Created by Johannes on 12.11.15. |
|
|
|
*/ |
|
|
|
public class StationsHistorieController { |
|
|
|
|
|
|
|
private final SimpleObjectProperty<State> state = new SimpleObjectProperty<>(State.VIEW); |
|
|
|
@FXML |
|
|
|
private Button btnStatHistAbort; |
|
|
|
private MainController mainController; |
|
|
|
|
|
|
|
@FXML |
|
|
|
private GridPane fields; |
|
|
|
@FXML |
|
|
|
private Button btnStatHistEdit; |
|
|
|
@FXML |
|
|
|
private Button btnStatHistDelete; |
|
|
|
/** |
|
|
|
* The station history that is shown in the edit window, or null if a new station history should be created. |
|
|
|
*/ |
|
|
|
private StationsHistorie stationsHistorieSelected = null; |
|
|
|
private MainController mainController; |
|
|
|
@FXML |
|
|
|
private TableView<StationsHistorie> tblStationsHistorie; |
|
|
|
@FXML |
|
|
|
private Button btnStatHistCancel, btnStatHistSave; |
|
|
|
private Button btnStatHistSave, btnStatHistCreate, btnStatHistEdit, btnStatHistDelete, btnStatHistAbort; |
|
|
|
@FXML |
|
|
|
private Label statHistCreator, statHistCreateTime, statHistEditor, statHistEditTime; |
|
|
|
@FXML |
|
|
|
@@ -63,26 +53,56 @@ public class StationsHistorieController { |
|
|
|
private ComboBox<String> cmbAbteilung; |
|
|
|
private SimpleObjectProperty<ObservableList<StationsHistorie>> stationsHistorie = |
|
|
|
new SimpleObjectProperty<>(); |
|
|
|
@FXML |
|
|
|
private Button btnStatHistCreate; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Definition of the controllers states. |
|
|
|
*/ |
|
|
|
public enum State { |
|
|
|
CREATE, EDIT, VIEW; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* The current state of the controller. |
|
|
|
*/ |
|
|
|
private final SimpleObjectProperty<State> state = new SimpleObjectProperty<>(State.VIEW); |
|
|
|
|
|
|
|
/** |
|
|
|
* Constructor |
|
|
|
* @param mainController |
|
|
|
*/ |
|
|
|
public StationsHistorieController(MainController mainController) { |
|
|
|
this.mainController = mainController; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* EventHandler for the {@link #btnStatHistEdit} |
|
|
|
*/ |
|
|
|
@FXML |
|
|
|
private void clickedEdit() { |
|
|
|
this.state.set(State.EDIT); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Getter for the {@link #stateProperty()} |
|
|
|
* @return The stateProperty's value. |
|
|
|
*/ |
|
|
|
public State getState() { |
|
|
|
return state.get(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @return Property of the controllers state |
|
|
|
*/ |
|
|
|
public ReadOnlyObjectProperty<State> stateProperty() { |
|
|
|
return state; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* initialize()-method of the controller. |
|
|
|
*/ |
|
|
|
@FXML |
|
|
|
private void initialize() { |
|
|
|
initColumns(); |
|
|
|
@@ -106,12 +126,16 @@ public class StationsHistorieController { |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
tblStationsHistorie.disableProperty().bind(state.isNotEqualTo(State.VIEW)); |
|
|
|
tblStationsHistorie.itemsProperty().bind(stationsHistorie); |
|
|
|
tblStationsHistorie.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> { |
|
|
|
setStationsHistorieSelected(newValue); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Show/hide/disable buttons depending on the controller state |
|
|
|
*/ |
|
|
|
private void initButtons() { |
|
|
|
// btnStatHistCancel.visibleProperty().bind(state.isEqualTo(State.VIEW).and(tblStationsHistorie.getSelectionModel().selectedItemProperty().isNotNull())); |
|
|
|
// btnStatHistCancel.managedProperty().bind(btnStatHistCancel.visibleProperty()); |
|
|
|
@@ -130,22 +154,25 @@ public class StationsHistorieController { |
|
|
|
btnStatHistDelete.managedProperty().bind(btnStatHistDelete.visibleProperty()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Init the comboboxes for the wards |
|
|
|
*/ |
|
|
|
private void initStationsFilter() { |
|
|
|
final String any = "beliebig"; |
|
|
|
|
|
|
|
//Finde die Abteilungen und setzte in die ComboBox |
|
|
|
List<String> abteilungen = mainController.getStammdaten().getStationen().stream() |
|
|
|
.map(stat -> stat.getAbteilung()).distinct().collect(Collectors.toList()); |
|
|
|
Collections.sort(abteilungen); |
|
|
|
.map(stat -> stat.getAbteilung()).distinct().sorted().collect(Collectors.toList()); |
|
|
|
|
|
|
|
cmbAbteilung.setItems(FXCollections.observableArrayList(abteilungen)); |
|
|
|
cmbAbteilung.getItems().add(0, any); |
|
|
|
cmbAbteilung.getSelectionModel().select(0); |
|
|
|
|
|
|
|
new SelectKeyComboBoxListener(cmbAbteilung); |
|
|
|
|
|
|
|
tblStationsHistorie.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { |
|
|
|
setStationsHistorieSelected(newValue); |
|
|
|
}); |
|
|
|
|
|
|
|
//Filtere die Stationscombobox nach ausgewaehlter Abteilung |
|
|
|
FilteredList<Station> stationenFiltered = new FilteredList<Station>(mainController.getStammdaten().getStationen()); |
|
|
|
|
|
|
|
stationenFiltered.predicateProperty().bind(Bindings.createObjectBinding(() -> { |
|
|
|
@@ -155,20 +182,16 @@ public class StationsHistorieController { |
|
|
|
return p -> p.getAbteilung().equals(cmbAbteilung.getValue()); |
|
|
|
}, cmbAbteilung.valueProperty())); |
|
|
|
|
|
|
|
|
|
|
|
cmbStation.setItems(stationenFiltered); |
|
|
|
new SelectKeyComboBoxListener(cmbStation); |
|
|
|
} |
|
|
|
|
|
|
|
@FXML |
|
|
|
private void clickedCancel() { |
|
|
|
// this.state.set(State.VIEW); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* EventHandler for {@link #btnStatHistSave}. |
|
|
|
*/ |
|
|
|
@FXML |
|
|
|
private void clickedSave() { |
|
|
|
|
|
|
|
|
|
|
|
if (getState() == State.CREATE) { |
|
|
|
StationsHistorie stationsHistorie = new StationsHistorie(); |
|
|
|
copyFieldDataIntoStationsHistorie(stationsHistorie); |
|
|
|
@@ -182,6 +205,7 @@ public class StationsHistorieController { |
|
|
|
} |
|
|
|
mainController.refreshCaseData(); |
|
|
|
} else { |
|
|
|
StationsHistorie stationsHistorieSelected = tblStationsHistorie.getSelectionModel().getSelectedItem(); |
|
|
|
copyFieldDataIntoStationsHistorie(stationsHistorieSelected); |
|
|
|
if (!validateData(stationsHistorieSelected)) { |
|
|
|
return; |
|
|
|
@@ -196,18 +220,31 @@ public class StationsHistorieController { |
|
|
|
state.set(State.VIEW); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* EventHandler for {@link #btnStatHistAbort}. |
|
|
|
*/ |
|
|
|
@FXML |
|
|
|
private void clickedAbort() { |
|
|
|
state.set(State.VIEW); |
|
|
|
copyStationsHistorieDataIntoFields(); |
|
|
|
StationsHistorie stationsHistorieSelected = tblStationsHistorie.getSelectionModel().getSelectedItem(); |
|
|
|
copyStationsHistorieDataIntoFields(stationsHistorieSelected); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* EventHandler for {@link #btnStatHistCreate}. |
|
|
|
*/ |
|
|
|
@FXML |
|
|
|
private void clickedCreateAufenthalt() { |
|
|
|
this.state.set(State.CREATE); |
|
|
|
setStationsHistorieSelected(null); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* EventHandler for the {@link #btnStatHistDelete} button. |
|
|
|
*/ |
|
|
|
@FXML |
|
|
|
private void clickedDelete() { |
|
|
|
StationsHistorie selectedItem = tblStationsHistorie.getSelectionModel().getSelectedItem(); |
|
|
|
@@ -217,7 +254,7 @@ public class StationsHistorieController { |
|
|
|
alert.setTitle("Stationsaufenthalt kann nicht entfernt werden!"); |
|
|
|
alert.setHeaderText(null); |
|
|
|
alert.setContentText("Der Aufenthalt muss in der Zukunft liegen, um gel\u00f6scht werden zu k\u00f6nnen!"); |
|
|
|
alert.initOwner(btnStatHistCancel.getScene().getWindow()); |
|
|
|
alert.initOwner(btnStatHistDelete.getScene().getWindow()); |
|
|
|
alert.initModality(Modality.APPLICATION_MODAL); |
|
|
|
alert.showAndWait(); |
|
|
|
return; |
|
|
|
@@ -230,30 +267,39 @@ public class StationsHistorieController { |
|
|
|
} |
|
|
|
|
|
|
|
mainController.refreshCaseData(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* A getter for {@link #stationsHistorieProperty()} |
|
|
|
* @return The value of that property. |
|
|
|
*/ |
|
|
|
public ObservableList<StationsHistorie> getStationsHistorie() { |
|
|
|
return stationsHistorie.get(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Setter for the {@link #stationsHistorieProperty()} |
|
|
|
* @param stationsHistorie The value to be set. |
|
|
|
*/ |
|
|
|
public void setStationsHistorie(ObservableList<StationsHistorie> stationsHistorie) { |
|
|
|
this.stationsHistorie.set(stationsHistorie); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* The list that will be shown in the TableView. |
|
|
|
* @return A property to that list. |
|
|
|
*/ |
|
|
|
public SimpleObjectProperty<ObservableList<StationsHistorie>> stationsHistorieProperty() { |
|
|
|
return stationsHistorie; |
|
|
|
} |
|
|
|
|
|
|
|
public void setStationsHistorieSelected(StationsHistorie stationsHistorie) { |
|
|
|
this.stationsHistorieSelected = stationsHistorie; |
|
|
|
if (stationsHistorie == null) { |
|
|
|
clearFields(); |
|
|
|
} else { |
|
|
|
copyStationsHistorieDataIntoFields(); |
|
|
|
copyStationsHistorieDataIntoFields(stationsHistorie); |
|
|
|
} |
|
|
|
|
|
|
|
tblStationsHistorie.getSelectionModel().select(stationsHistorie); |
|
|
|
} |
|
|
|
|
|
|
|
private void initColumns() { |
|
|
|
@@ -262,16 +308,19 @@ public class StationsHistorieController { |
|
|
|
colStatHistEntlassungsDatum.setCellValueFactory(new PropertyValueFactory<StationsHistorie, LocalDate>("entlassungsDatum")); |
|
|
|
} |
|
|
|
|
|
|
|
private void copyStationsHistorieDataIntoFields() { |
|
|
|
|
|
|
|
if (stationsHistorieSelected == null) { |
|
|
|
/** |
|
|
|
* Copies the data from the given StationsHistorie into the fields in the GUI. |
|
|
|
*/ |
|
|
|
private void copyStationsHistorieDataIntoFields(StationsHistorie stationsHistorie) { |
|
|
|
if (stationsHistorie == null) { |
|
|
|
clearFields(); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
//Setze Station im Dropdownfeld |
|
|
|
for (Station station : cmbStation.getItems()) { |
|
|
|
if (station.getStation().equals(stationsHistorieSelected.getStationKey())) { |
|
|
|
if (station.getStation().equals(stationsHistorie.getStationKey())) { |
|
|
|
cmbStation.getSelectionModel().select(station); |
|
|
|
cmbAbteilung.getSelectionModel().select(station.getAbteilung()); |
|
|
|
break; |
|
|
|
@@ -279,19 +328,23 @@ public class StationsHistorieController { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dtTmAufnahme.setDateTime(stationsHistorieSelected.getAufnahmeDatum()); |
|
|
|
dtTmEntlassung.setDateTime(stationsHistorieSelected.getEntlassungsDatum()); |
|
|
|
dtTmAufnahme.setDateTime(stationsHistorie.getAufnahmeDatum()); |
|
|
|
dtTmEntlassung.setDateTime(stationsHistorie.getEntlassungsDatum()); |
|
|
|
|
|
|
|
statHistCreator.setText(Integer.toString(stationsHistorieSelected.getErsteller())); |
|
|
|
if (stationsHistorieSelected.getErstellDatumZeit() != null) { |
|
|
|
statHistCreateTime.setText(stationsHistorieSelected.getErstellDatumZeit().toString()); |
|
|
|
statHistCreator.setText(Integer.toString(stationsHistorie.getErsteller())); |
|
|
|
if (stationsHistorie.getErstellDatumZeit() != null) { |
|
|
|
statHistCreateTime.setText(stationsHistorie.getErstellDatumZeit().toString()); |
|
|
|
} |
|
|
|
statHistEditor.setText(Integer.toString(stationsHistorieSelected.getBearbeiter())); |
|
|
|
if (stationsHistorieSelected.getBearbeitetDatumZeit() != null) { |
|
|
|
statHistEditTime.setText(stationsHistorieSelected.getBearbeitetDatumZeit().toString()); |
|
|
|
statHistEditor.setText(Integer.toString(stationsHistorie.getBearbeiter())); |
|
|
|
if (stationsHistorie.getBearbeitetDatumZeit() != null) { |
|
|
|
statHistEditTime.setText(stationsHistorie.getBearbeitetDatumZeit().toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Copies the data entered in the fields into {@link de.uniluebeck.mi.projmi6.model.StationsHistorie} objects. |
|
|
|
* @param stationsHistorie The object in which the data will be copied |
|
|
|
*/ |
|
|
|
private void copyFieldDataIntoStationsHistorie(StationsHistorie stationsHistorie) { |
|
|
|
stationsHistorie.setAufnahmeDatum(dtTmAufnahme.getDateTime()); |
|
|
|
stationsHistorie.setEntlassungsDatum(dtTmEntlassung.getDateTime()); |
|
|
|
@@ -306,7 +359,11 @@ public class StationsHistorieController { |
|
|
|
stationsHistorie.setBearbeiter(mainController.getCurrentMitarbeiter().getMitarbID()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Helper method for {@link #validateData(StationsHistorie)}. Opens a error window. |
|
|
|
* @param title The Alerts header text |
|
|
|
* @param message The Alerts contents text |
|
|
|
*/ |
|
|
|
private void showMessage(String title, String message) { |
|
|
|
Alert alert = new Alert(Alert.AlertType.INFORMATION); |
|
|
|
alert.setTitle("Ung\u00fcltige Daten!"); |
|
|
|
@@ -317,6 +374,11 @@ public class StationsHistorieController { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Checks the StationsHistorie and makes error alerts if necessary. |
|
|
|
* @param stationsHistorie The StationsHistorie that should be validated, |
|
|
|
* @return true if data is valid, false otherwise. |
|
|
|
*/ |
|
|
|
private boolean validateData(StationsHistorie stationsHistorie) { |
|
|
|
if (stationsHistorie.getStationKey() == null) { |
|
|
|
showMessage("Keine Station ausgew\00e4hlt!", "Bitte Station und nicht nur Abteilung ausw\00e4hlen!"); |
|
|
|
@@ -336,8 +398,10 @@ public class StationsHistorieController { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Clears TextFields in the view |
|
|
|
*/ |
|
|
|
private void clearFields() { |
|
|
|
|
|
|
|
statHistCreateTime.setText(""); |
|
|
|
statHistCreator.setText(""); |
|
|
|
statHistEditTime.setText(""); |
|
|
|
@@ -351,7 +415,4 @@ public class StationsHistorieController { |
|
|
|
dtTmEntlassung.setDateTime(null); |
|
|
|
} |
|
|
|
|
|
|
|
public enum State { |
|
|
|
CREATE, EDIT, VIEW |
|
|
|
} |
|
|
|
} |