|
- package de.uniluebeck.mi.projmi6.controller;
-
-
- import de.uniluebeck.mi.projmi6.db.DBHandler;
- import de.uniluebeck.mi.projmi6.model.DiagArt;
- import de.uniluebeck.mi.projmi6.model.Diagnose;
- import de.uniluebeck.mi.projmi6.model.Icd10Code;
- import de.uniluebeck.mi.projmi6.model.Mitarbeiter;
- import de.uniluebeck.mi.projmi6.view.SelectKeyComboBoxListener;
- import javafx.beans.property.ReadOnlyObjectProperty;
- import javafx.beans.property.SimpleObjectProperty;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.collections.transformation.FilteredList;
- import javafx.fxml.FXML;
- import javafx.scene.control.*;
- import javafx.scene.layout.GridPane;
-
- /**
- * Controller that mantains the diagnosis assigned to a case in the UI.
- *
- * @author Johannes
- * Created by 631806 on 12.11.15.
- */
- public class DiagnoseController {
-
- private final SimpleObjectProperty<ObservableList<Diagnose>> diagnosen = new SimpleObjectProperty<>();
-
- /**
- * Controller state definitions
- */
- public enum State {
- CREATE, EDIT, VIEW
- }
-
- /**
- * Current controllers state
- */
- private final SimpleObjectProperty<State> state = new SimpleObjectProperty<>(State.VIEW);
-
- @FXML
- private Button btnDiagAbort, btnDiagEdit, btnDiagSave, btnDiagCreate, btnDiagCancel;
-
- @FXML
- private final MainController mainController;
-
- @FXML
- private ListView<Diagnose> diagnoseList;
- @FXML
- private GridPane fields;
- @FXML
- private ComboBox<Mitarbeiter> diagDiagnoseArzt;
- @FXML
- private Label diagCreator, diagCreateTime, diagChanger, diagChangeTime;
- @FXML
- private TextArea diagFreitext;
- @FXML
- private ComboBox<DiagArt> diagDiagnoseArt;
- @FXML
- private ComboBox<Icd10Code> diagDiagnose;
-
- /**
- * Contructor.
- *
- * @param mainController The main controller that creates this instance.
- */
- public DiagnoseController(MainController mainController) {
- this.mainController = mainController;
- }
-
- /**
- * Getter for the {@link #diagnosenProperty()}.
- *
- * @return The list of diagnosis shown in the GUI. Might be null.
- */
- public ObservableList<Diagnose> getDiagnosen() {
- return diagnosen.get();
- }
-
-
- /**
- * Setter for the {@link #diagnosenProperty()}.
- *
- * @param diagnosen A observable list of diagnosis to be set.
- */
- public void setDiagnosen(ObservableList<Diagnose> diagnosen) {
- this.diagnosen.set(diagnosen);
- }
-
- /**
- * The diagnosis in this controller.
- *
- * @return A simple object property.
- */
- public SimpleObjectProperty<ObservableList<Diagnose>> diagnosenProperty() {
- return diagnosen;
- }
-
- /**
- * Getter for the state of this controller
- *
- * @return State.VIEW, State.EDIT or State.CREATE
- */
- public State getState() {
- return state.get();
- }
-
- /**
- * A property for the controllers state.
- */
- public ReadOnlyObjectProperty<State> stateProperty() {
- return state;
- }
-
- /**
- * FXMLLoaders initialize()-method.
- * See <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/doc-files/introduction_to_fxml.html#controllers">Oracle FXML Introduction</a>
- */
- @FXML
- private void initialize() {
- initButtons();
-
- //Init diagnosis list view
- diagDiagnose.itemsProperty().bind(mainController.getStammdaten().icd10CodesProperty());
- new SelectKeyComboBoxListener(diagDiagnose);
-
- //init fields on the right
- diagDiagnoseArt.setItems(FXCollections.observableArrayList(DiagArt.values()));
-
- FilteredList<Mitarbeiter> mitarbeiterFilteredList = new FilteredList<Mitarbeiter>(mainController.getStammdaten().getMitarbeiter());
- mitarbeiterFilteredList.setPredicate(m -> !m.getNachname().equalsIgnoreCase("SYSTEM"));
- diagDiagnoseArzt.setItems(mitarbeiterFilteredList);
-
- diagnoseList.itemsProperty().bind(diagnosen);
- fields.disableProperty().bind(state.isEqualTo(State.VIEW));
-
- //Init the list view on the left.
- diagnoseList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
- diagnoseList.disableProperty().bind(state.isNotEqualTo(State.VIEW));
- diagnoseList.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
- if (newValue == null) {
- clearFields();
- } else {
- copyDiagnoseDataIntoFields(newValue);
- }
- });
-
- //React on state changes.
- state.addListener((observable, oldValue, newValue) -> {
- if (newValue == State.VIEW) {
- mainController.unlockFromEdit();
- Diagnose diagnose = diagnoseList.getSelectionModel().getSelectedItem();
- if (diagnose == null) {
- clearFields();
- } else {
- copyDiagnoseDataIntoFields(diagnose);
- }
- } else {
- mainController.lockForEdit(MainController.TabName.DIAGNOSE);
- if (newValue == State.CREATE) {
- clearFields();
- diagDiagnoseArzt.setValue(mainController.getCurrentMitarbeiter());
- }
- }
- });
-
-
- }
-
- /**
- * Bind button visibility to application state.
- */
- private void initButtons() {
- btnDiagCreate.disableProperty().bind(mainController.fallProperty().isNull());
-
- btnDiagEdit.disableProperty().bind(diagnoseList.getSelectionModel().selectedItemProperty().isNull());
-
- //btnDiagEdit.managedProperty().bind(state.isEqualTo(State.VIEW));
- //btnDiagEdit.visibleProperty().bind(btnDiagEdit.managedProperty());
- btnDiagEdit.setManaged(false);
- btnDiagEdit.setVisible(false);
-
- btnDiagSave.managedProperty().bind(state.isNotEqualTo(State.VIEW));
- btnDiagSave.visibleProperty().bind(btnDiagSave.managedProperty());
-
- btnDiagAbort.managedProperty().bind(btnDiagSave.managedProperty());
- btnDiagAbort.visibleProperty().bind(btnDiagSave.managedProperty());
-
- }
-
- /**
- * EventHandler for {@link #btnDiagEdit}.
- */
- @FXML
- private void clickedEdit() {
- state.set(State.EDIT);
- }
-
- /**
- * EventHandler for {@link #btnDiagAbort}.
- */
- @FXML
- private void clickedAbort() {
- state.set(State.VIEW);
- }
-
- /**
- * EventHandler for the {@link #btnDiagCreate}.
- */
- @FXML
- private void clickedDiagCreate() {
- this.state.set(State.CREATE);
- }
-
- /**
- * EventHandler for the {@link #btnDiagCancel}.
- */
- @FXML
- private void clickedDiagCancel() {
-
- }
-
- /**
- * EventHandler method for {@link #btnDiagSave}
- */
- @FXML
- void clickedDiagSave() {
- if (state.get() == State.CREATE) {
- //Create new diagnosis
- Diagnose diagnose = new Diagnose();
- copyFieldDataIntoDiagnose(diagnose);
- try {
- DBHandler.setDiagnose(diagnose);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- mainController.refreshCaseData();
- state.set(State.VIEW);
- }
-
- /**
- * Copy the object data into the fields.
- *
- * @param diagnose The object with the data.
- */
- private void copyDiagnoseDataIntoFields(Diagnose diagnose) {
- //Find the DiagnoseArzt by id.
- for (Mitarbeiter current : diagDiagnoseArzt.getItems()) {
- if (current.getMitarbID() == diagnose.getMitarbid()) {
- diagDiagnoseArzt.setValue(current);
- break;
- }
- }
-
- diagFreitext.setText(diagnose.getFreiText());
- diagDiagnoseArt.setValue(diagnose.getDiagArt());
- diagDiagnose.setValue(diagnose.getIcd10code());
-
- diagCreator.setText(Integer.toString(diagnose.getErsteller()));
- diagCreateTime.setText(diagnose.getErstellDatumZeit().toString());
- diagChanger.setText(Integer.toString(diagnose.getBearbeiter()));
- diagChangeTime.setText(diagnose.getBearbeitetDatumZeit().toString());
- }
-
- /**
- * Copy the data from the ComboBoxes into data model object
- *
- * @param diagnose The object to copy the data into
- */
- private void copyFieldDataIntoDiagnose(Diagnose diagnose) {
- diagnose.setIcd10code(diagDiagnose.getValue());
- diagnose.setArzt(diagDiagnoseArzt.getValue());
- diagnose.setFreiText(diagFreitext.getText());
- diagnose.setDiagArt(diagDiagnoseArt.getValue());
- diagnose.setFall(mainController.getFall());
-
- diagnose.setErsteller(mainController.getCurrentMitarbeiter().getMitarbID());
- diagnose.setBearbeiter(mainController.getCurrentMitarbeiter().getMitarbID());
- }
-
- /**
- * Clear the fields in case no diagnosis is selcted, or
- * creating a new one is started.
- */
- public void clearFields() {
- diagDiagnoseArzt.setValue(null);
- diagDiagnose.setValue(null);
- diagFreitext.setText("");
- diagDiagnoseArt.setValue(null);
-
- diagCreator.setText("");
- diagCreateTime.setText("");
- diagChanger.setText("");
- diagChangeTime.setText("");
- }
-
- }
|