-Zustandsverwaltung in FallController überarbeitet -Bug mit dem StationÜbersichts-asynchron-laden gefixttestBranch
| @@ -7,6 +7,7 @@ package de.uniluebeck.mi.projmi6.controller; | |||
| import de.uniluebeck.mi.projmi6.db.DBHandler; | |||
| import de.uniluebeck.mi.projmi6.model.*; | |||
| import de.uniluebeck.mi.projmi6.view.DateTimePicker; | |||
| import javafx.beans.property.ReadOnlyObjectProperty; | |||
| import javafx.beans.property.SimpleObjectProperty; | |||
| import javafx.collections.FXCollections; | |||
| import javafx.event.ActionEvent; | |||
| @@ -93,6 +94,16 @@ public class FallController { | |||
| CREATE, EDIT, VIEW | |||
| } | |||
| public State getState() { | |||
| return state.get(); | |||
| } | |||
| public ReadOnlyObjectProperty<State> stateProperty() { | |||
| return state; | |||
| } | |||
| SimpleObjectProperty<State> state = new SimpleObjectProperty<>(State.VIEW); | |||
| @@ -123,6 +134,15 @@ public class FallController { | |||
| copyFallDataIntoField(fallProperty.get()); | |||
| } | |||
| })); | |||
| state.addListener((observable, oldValue, newValue) -> { | |||
| if(newValue==State.EDIT || newValue == State.CREATE){ | |||
| mainController.lockForEdit(MainController.TabName.OVERVIEW); | |||
| }else{ | |||
| mainController.unlockFromEdit(); | |||
| } | |||
| }); | |||
| } | |||
| @@ -147,7 +167,6 @@ public class FallController { | |||
| void clickedFallAbort(ActionEvent event) { | |||
| this.state.set(State.VIEW); | |||
| copyFallDataIntoField(fallProperty.get()); | |||
| mainController.fallCreationComplete(); | |||
| } | |||
| @FXML | |||
| @@ -157,21 +176,20 @@ public class FallController { | |||
| copyFieldDataIntoFall(fall); | |||
| try { | |||
| DBHandler.setFall(fall, mainController.getCurrentMitarbeiter().getMitarbID()); | |||
| //TODO Reload Faelle for Patient im MainController | |||
| } catch (SQLException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } else { | |||
| try { | |||
| DBHandler.setFall(fallProperty.get(), mainController.getCurrentMitarbeiter().getMitarbID(), true); | |||
| } catch (SQLException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| mainController.fallCreationComplete(); | |||
| this.state.set(State.VIEW); | |||
| //TODO Update/create in db | |||
| mainController.refreshCasesFromDb(mainController.getPatientTablesController().getSelectedPatient()); | |||
| } | |||
| public void createNewFall() { | |||
| @@ -188,10 +206,6 @@ public class FallController { | |||
| } | |||
| } | |||
| fallVersichertennummer.setText(patient.getVersichertennummer()); | |||
| // TODO: Jojo: Kannst Du das wieder heile machen? :D | |||
| // fallProperty.unbind(); | |||
| // fallProperty.set(new Fall()); | |||
| } | |||
| @@ -208,10 +222,10 @@ public class FallController { | |||
| fallPatID.setText(""); //TODO | |||
| fallCreateTime.setText("<auto>"); | |||
| fallCreator.setText("<auto>"); | |||
| fallEditTime.setText("<auto>"); | |||
| fallEditor.setText("<auto>"); | |||
| fallCreateTime.setText(""); | |||
| fallCreator.setText(""); | |||
| fallEditTime.setText(""); | |||
| fallEditor.setText(""); | |||
| fallEinweisenderArzt.setText(""); | |||
| fallSelbsteinweisung.setSelected(false); | |||
| @@ -234,7 +248,7 @@ public class FallController { | |||
| fall.setSelbsteinweisung(true); | |||
| fall.setEinweisenderArzt(null); | |||
| }else{ | |||
| // fall.setEinweisenderArzt(fallEinweisenderArzt.getText()); TODO | |||
| //fall.setEinweisenderArzt(fallEinweisenderArzt.getText()); TODO | |||
| fall.setSelbsteinweisung(false); | |||
| } | |||
| fall.setVersichertenNummer(fallVersichertennummer.getText()); | |||
| @@ -29,9 +29,6 @@ public class MainController { | |||
| private UntersuchungenController untersuchungenController; | |||
| private int parallelTaskCount = 0; | |||
| @FXML | |||
| @@ -53,35 +50,35 @@ public class MainController { | |||
| private TabPane tabPaneFall; | |||
| @FXML | |||
| private Tab tabFallOverview, tabFallUntersuchungen, tabFallDiagnose, tabFallStationsHistorie ; | |||
| private Tab tabFallOverview, tabFallUntersuchungen, tabFallDiagnose, tabFallStationsHistorie; | |||
| private Stammdaten stammdaten = new Stammdaten(); | |||
| private Callback<Class<?>, Object> controllerFactory = clazz -> { | |||
| if(clazz.equals(MainController.class)) { | |||
| if (clazz.equals(MainController.class)) { | |||
| return this; | |||
| }else if(clazz.equals(FallController.class)){ | |||
| } else if (clazz.equals(FallController.class)) { | |||
| return fallController; | |||
| }else if(clazz.equals(DiagnoseController.class)){ | |||
| } else if (clazz.equals(DiagnoseController.class)) { | |||
| return diagnoseController; | |||
| }else if(clazz.equals(PatientTablesController.class)){ | |||
| } else if (clazz.equals(PatientTablesController.class)) { | |||
| return patientTablesController; | |||
| }else if(clazz.equals(SettingsController.class)){ | |||
| return settingsController; | |||
| } else if(clazz.equals(UntersuchungenController.class)) { | |||
| } else if (clazz.equals(SettingsController.class)) { | |||
| return settingsController; | |||
| } else if (clazz.equals(UntersuchungenController.class)) { | |||
| return untersuchungenController; | |||
| }else if(clazz.equals(StationsHistorieController.class)){ | |||
| } else if (clazz.equals(StationsHistorieController.class)) { | |||
| return stationsHistorieController; | |||
| }else { | |||
| System.err.println("Keine Controller-Klasse des Typs "+clazz+" gefunden!!!"); | |||
| } else { | |||
| System.err.println("Keine Controller-Klasse des Typs " + clazz + " gefunden!!!"); | |||
| return null; | |||
| } | |||
| }; | |||
| public MainController(){ | |||
| public MainController() { | |||
| fallController = new FallController(this); | |||
| diagnoseController = new DiagnoseController(this); | |||
| patientTablesController = new PatientTablesController(this); | |||
| @@ -91,47 +88,45 @@ public class MainController { | |||
| } | |||
| public Stammdaten getStammdaten(){ | |||
| return stammdaten; | |||
| public Stammdaten getStammdaten() { | |||
| return stammdaten; | |||
| } | |||
| public Callback<Class<?>, Object> getControllerFactory(){ | |||
| public Callback<Class<?>, Object> getControllerFactory() { | |||
| return controllerFactory; | |||
| } | |||
| public FallController getFallController(){ | |||
| public FallController getFallController() { | |||
| return fallController; | |||
| } | |||
| public DiagnoseController getDiagnoseController(){ | |||
| public DiagnoseController getDiagnoseController() { | |||
| return diagnoseController; | |||
| } | |||
| public PatientTablesController getPatientTablesController(){ | |||
| return patientTablesController; | |||
| public PatientTablesController getPatientTablesController() { | |||
| return patientTablesController; | |||
| } | |||
| public SettingsController getSettingsController(){ | |||
| public SettingsController getSettingsController() { | |||
| return settingsController; | |||
| } | |||
| public UntersuchungenController getUntersuchungenController(){ | |||
| return untersuchungenController; | |||
| public UntersuchungenController getUntersuchungenController() { | |||
| return untersuchungenController; | |||
| } | |||
| public void increaseParallelTaskCount(){ | |||
| public void increaseParallelTaskCount() { | |||
| parallelTaskCount++; | |||
| if(parallelTaskCount>0 && progressIndicator!=null){ | |||
| if (parallelTaskCount > 0 && progressIndicator != null) { | |||
| progressIndicator.setVisible(true); | |||
| } | |||
| } | |||
| public void decreaseParallelTaskCount(){ | |||
| public void decreaseParallelTaskCount() { | |||
| parallelTaskCount--; | |||
| if(parallelTaskCount<=0 && progressIndicator!=null){ | |||
| if (parallelTaskCount <= 0 && progressIndicator != null) { | |||
| parallelTaskCount = 0; | |||
| progressIndicator.setVisible(false); | |||
| } | |||
| @@ -142,36 +137,32 @@ public class MainController { | |||
| private Label lvFallPlaceholder; | |||
| private Task<List<Fall>> loadFallTask = null; | |||
| private ChangeListener<Patient> onPatientChanged = (observableValue,oldValue,newValue)-> { | |||
| public void refreshCasesFromDb(Patient patient) { | |||
| lvFall.setItems(null); //clear list | |||
| if(newValue==null){ // If no patient is selected | |||
| if (patient == null) { // If no patient is selected | |||
| lvFallPlaceholder.setText("Kein Patient ausgew\u00e4hlt!"); | |||
| return; | |||
| } | |||
| if(loadFallTask!=null && loadFallTask.isRunning()){ | |||
| if (loadFallTask != null && loadFallTask.isRunning()) { | |||
| loadFallTask.cancel(); | |||
| } | |||
| loadFallTask = new Task<List<Fall>>() { | |||
| @Override | |||
| protected List<Fall> call() throws Exception { | |||
| return DBHandler.getFaelleByPatID(newValue.getPatID()); | |||
| return DBHandler.getFaelleByPatID(patient.getPatID()); | |||
| } | |||
| @Override | |||
| protected void succeeded() { | |||
| super.succeeded(); | |||
| if(isCancelled()){ | |||
| System.out.println("Task wurde gecancelt"); | |||
| if (isCancelled()) { | |||
| return; | |||
| } | |||
| lvFallPlaceholder.setText("Keine F\u00e4lle vorhanden!"); | |||
| @@ -199,20 +190,24 @@ public class MainController { | |||
| Thread thread = new Thread(loadFallTask); | |||
| thread.setDaemon(true); | |||
| thread.start(); | |||
| }; | |||
| } | |||
| @FXML | |||
| private void initialize(){ | |||
| private void initialize() { | |||
| //Init user data. | |||
| cmbUserChoose.itemsProperty().bind(this.getStammdaten().mitarbeiterProperty()); | |||
| cmbUserChoose.getSelectionModel().select(0); // TODO: Bessere Loesung finden. | |||
| //Disable the right side if no case is selected. | |||
| fallOverview.disableProperty().bind(patientTablesController.selectedPatientProperty().isNull()); | |||
| fallOverview.disableProperty().bind(patientTablesController.selectedPatientProperty().isNull() | |||
| .and(fallController.stateProperty().isNotEqualTo(FallController.State.CREATE))); | |||
| //Load the cases async if patient changes | |||
| patientTablesController.selectedPatientProperty().addListener(onPatientChanged); | |||
| patientTablesController.selectedPatientProperty().addListener((observableValue, oldValue, newValue) -> { | |||
| refreshCasesFromDb(newValue); | |||
| }); | |||
| lvFall.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); | |||
| @@ -220,19 +215,16 @@ public class MainController { | |||
| fallController.fallPropertyProperty().bind(lvFall.getSelectionModel().selectedItemProperty()); | |||
| lvFall.getSelectionModel().selectedItemProperty().addListener(onCaseChanged); | |||
| } | |||
| private Task<Void> loadCaseData = null; | |||
| private ChangeListener<Fall> onCaseChanged = (observable, oldValue, newValue) -> { | |||
| if(loadCaseData!=null && loadCaseData.isRunning()){ | |||
| if (loadCaseData != null && loadCaseData.isRunning()) { | |||
| loadCaseData.cancel(); | |||
| } | |||
| @@ -241,25 +233,24 @@ public class MainController { | |||
| tabFallStationsHistorie.setDisable(true); | |||
| tabFallUntersuchungen.setDisable(true); | |||
| if(newValue==null) { | |||
| if (newValue == null) { | |||
| tabPaneFall.setDisable(true); | |||
| System.out.println("TODO: Clear tables cuz fall = null!"); | |||
| //fallController.c | |||
| return; | |||
| } | |||
| if(newValue==null){ // If no patient is selected | |||
| if (newValue == null) { // If no patient is selected | |||
| //lvFallPlaceholder.setText("Kein Patient ausgew\u00e4hlt!"); | |||
| return; | |||
| } | |||
| loadCaseData = new Task<Void>() { | |||
| List<Untersuchung> untersuchungList; | |||
| List<Diagnose> diagnoseList; | |||
| List<StationsHistorie> stationsHistorieList; | |||
| @Override | |||
| protected Void call() throws Exception { | |||
| untersuchungList = DBHandler.getUntersuchungByFall(newValue); | |||
| @@ -271,7 +262,7 @@ public class MainController { | |||
| @Override | |||
| protected void succeeded() { | |||
| super.succeeded(); | |||
| if(isCancelled()){ | |||
| if (isCancelled()) { | |||
| System.out.println("Task wurde gecancelt"); | |||
| return; | |||
| } | |||
| @@ -310,29 +301,67 @@ public class MainController { | |||
| @FXML | |||
| private void clickedCreateFall(){ | |||
| private void clickedCreateFall() { | |||
| // tabFallDiagnose.setDisable(true); | |||
| // tabFallUntersuchungen.setDisable(true); | |||
| // tabFallStationsHistorie.setDisable(true); | |||
| // tabPaneFall.getSelectionModel().select(tabFallOverview); | |||
| // patientTablesController.getPatientOverviewTabPane().setDisable(true); | |||
| // | |||
| // | |||
| fallController.createNewFall(); | |||
| lockForEdit(TabName.OVERVIEW); | |||
| } | |||
| public enum TabName { | |||
| OVERVIEW, DIAGNOSE, UNTERSUCHUNG, STATIONSHISTORIE; | |||
| } | |||
| public void lockForEdit(TabName exclude) { | |||
| tabFallDiagnose.setDisable(true); | |||
| tabFallUntersuchungen.setDisable(true); | |||
| tabFallStationsHistorie.setDisable(true); | |||
| tabPaneFall.getSelectionModel().select(tabFallOverview); | |||
| tabFallOverview.setDisable(true); | |||
| lvFall.setDisable(true); | |||
| btnFallCreate.setDisable(true); | |||
| patientTablesController.getPatientOverviewTabPane().setDisable(true); | |||
| switch (exclude) { | |||
| case OVERVIEW: | |||
| tabFallOverview.setDisable(false); | |||
| break; | |||
| case DIAGNOSE: | |||
| tabFallDiagnose.setDisable(false); | |||
| break; | |||
| case UNTERSUCHUNG: | |||
| tabFallUntersuchungen.setDisable(false); | |||
| break; | |||
| case STATIONSHISTORIE: | |||
| tabFallStationsHistorie.setDisable(false); | |||
| default: | |||
| break; | |||
| } | |||
| fallController.createNewFall(); | |||
| } | |||
| public void fallCreationComplete(){ | |||
| public void unlockFromEdit() { | |||
| tabFallDiagnose.setDisable(false); | |||
| tabFallUntersuchungen.setDisable(false); | |||
| tabFallStationsHistorie.setDisable(false); | |||
| patientTablesController.getPatientOverviewTabPane().setDisable(false); | |||
| lvFall.setDisable(false); | |||
| btnFallCreate.setDisable(false); | |||
| } | |||
| public Mitarbeiter getCurrentMitarbeiter(){ | |||
| public Mitarbeiter getCurrentMitarbeiter() { | |||
| return cmbUserChoose.getValue(); | |||
| } | |||
| public ReadOnlyObjectProperty<Mitarbeiter> currentMitarbeiterProperty(){ | |||
| public ReadOnlyObjectProperty<Mitarbeiter> currentMitarbeiterProperty() { | |||
| return cmbUserChoose.valueProperty(); | |||
| } | |||
| @@ -146,15 +146,21 @@ public class PatientTablesController { | |||
| return tableRow; | |||
| }); | |||
| lblTablePatientEmpty.setText("Liste ist leer."); | |||
| lblTableStationEmpty.setText(""); | |||
| tblStationOverview.disableProperty().bind(cmbStationenFilter.valueProperty().isNull()); | |||
| cmbStationenFilter.itemsProperty().bind(mainController.getStammdaten().stationenProperty()); | |||
| patientObjectBinding = Bindings.<Patient>createObjectBinding(() -> { | |||
| return patientOverviewTabPane.getSelectionModel().getSelectedItem().equals(patientOverviewTab) | |||
| ? tblPatientOverview.getSelectionModel().getSelectedItem() | |||
| : null; //(Patient)tblStationOverview.getSelectionModel().getSelectedItem(); //TODO | |||
| if(patientOverviewTabPane.getSelectionModel().getSelectedItem().equals(patientOverviewTab)) { | |||
| return tblPatientOverview.getSelectionModel().getSelectedItem(); | |||
| }else if(tblStationOverview.getSelectionModel().getSelectedItem()==null){ | |||
| return null; | |||
| }else{ | |||
| int selectedPatId = tblStationOverview.getSelectionModel().getSelectedItem().getPatId(); | |||
| Patient selectedPatient = tblPatientOverview.getItems().stream().filter(p -> p.getPatID()==selectedPatId).findFirst().orElse(null); | |||
| return selectedPatient; | |||
| } | |||
| }, tblPatientOverview.getSelectionModel().selectedItemProperty(), | |||
| tblStationOverview.getSelectionModel().selectedItemProperty(), | |||
| patientOverviewTabPane.getSelectionModel().selectedItemProperty()); | |||
| @@ -309,10 +315,10 @@ public class PatientTablesController { | |||
| private Task loadStationsHistorieTask = null; | |||
| public void updateStationsHistorieFromDb() { | |||
| if (this.loadStationsHistorieTask != null && this.loadStationsHistorieTask.isRunning()) { | |||
| if (this.loadStationsHistorieTask !=null) { | |||
| loadStationsHistorieTask.cancel(); | |||
| return; | |||
| } | |||
| lblTableStationEmpty.setText("Liste wird geladen..."); | |||
| btnStatRefresh.setDisable(true); | |||
| @@ -320,7 +326,6 @@ public class PatientTablesController { | |||
| mainController.increaseParallelTaskCount(); | |||
| lblTableStationEmpty.setText("Liste wird geladen..."); | |||
| Task<List<StationsUebersichtsItem>> loadStatHist = new Task<List<StationsUebersichtsItem>>() { | |||
| @@ -344,20 +349,18 @@ public class PatientTablesController { | |||
| @Override | |||
| protected void cancelled() { | |||
| super.cancelled(); | |||
| btnStatRefresh.setDisable(false); | |||
| mainController.decreaseParallelTaskCount(); | |||
| System.out.println("Cancelled"); | |||
| } | |||
| @Override | |||
| protected void failed() { | |||
| super.failed(); | |||
| if(!isCancelled()){ | |||
| lblTablePatientEmpty.setText("Laden fehlgeschlagen!"); | |||
| lblTableStationEmpty.setText("Laden fehlgeschlagen!"); | |||
| getException().printStackTrace(); | |||
| btnStatRefresh.setDisable(false); | |||
| mainController.decreaseParallelTaskCount(); | |||
| } | |||
| mainController.decreaseParallelTaskCount(); | |||
| btnStatRefresh.setDisable(false); | |||
| } | |||
| }; | |||
| this.loadStationsHistorieTask = loadStatHist; | |||
| @@ -389,4 +392,6 @@ public class PatientTablesController { | |||
| return selectedPatientProperty().get(); | |||
| } | |||
| } | |||
| @@ -71,30 +71,41 @@ public class StationsHistorieController { | |||
| private void initialize() { | |||
| initColumns(); | |||
| initStationsFilter(); | |||
| tblStationsHistorie.itemsProperty().bind(stationsHistorie); | |||
| tblStationsHistorie.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> { | |||
| setStationsHistorieSelected(newValue); | |||
| }); | |||
| } | |||
| private void initStationsFilter(){ | |||
| final String any = "beliebig"; | |||
| List<String> abteilungen = mainController.getStammdaten().getStationen().stream() | |||
| .map(stat->stat.getAbteilung()).distinct().collect(Collectors.toList()); | |||
| .map(stat->stat.getAbteilung()).distinct().collect(Collectors.toList()); | |||
| cmbAbteilung.setItems(FXCollections.observableArrayList(abteilungen)); | |||
| cmbAbteilung.getItems().add(0, any); | |||
| cmbAbteilung.getSelectionModel().select(0); | |||
| FilteredList<Station> stationenFiltered = new FilteredList<Station>(mainController.getStammdaten().getStationen()); | |||
| stationenFiltered.predicateProperty().bind(Bindings.createObjectBinding(() -> { | |||
| if(cmbAbteilung.getValue()==null || cmbAbteilung.getValue().equals(any)){ | |||
| return p->true; | |||
| } | |||
| return p -> p.getAbteilung().equals(cmbAbteilung.getValue()); | |||
| },cmbAbteilung.valueProperty())); | |||
| cmbStation.setItems(mainController.getStammdaten().getStationen()); | |||
| tblStationsHistorie.itemsProperty().bind(stationsHistorie); | |||
| tblStationsHistorie.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> { | |||
| setStationsHistorieSelected(newValue); | |||
| }); | |||
| cmbStation.setItems(stationenFiltered); | |||
| } | |||
| @FXML | |||
| private void clickedCancel(){ | |||
| @@ -58,8 +58,7 @@ | |||
| <children> | |||
| <ToolBar prefHeight="40.0" prefWidth="200.0"> | |||
| <items> | |||
| <Label text="Station:" /> | |||
| <ComboBox fx:id="cmbStationenFilter" prefWidth="150.0" promptText="Stationen" /> | |||
| <ComboBox fx:id="cmbStationenFilter" prefWidth="250.0" promptText="Station auswählen..." /> | |||
| <ToggleButton fx:id="btnEntlassenePatientenZeigen" mnemonicParsing="false" text="Entlassene Patienten zeigen" /> | |||
| <Pane HBox.hgrow="ALWAYS" /> | |||
| <Button fx:id="btnStatRefresh" text="Liste aktualisieren" onAction="#clickedRefreshStation"/> | |||
| @@ -19,12 +19,15 @@ | |||
| <Button mnemonicParsing="false" text="Neuen Aufenthalt erstellen" onAction="#clickedCreateAufenthalt"/> | |||
| </items> | |||
| </ToolBar> | |||
| <TableView prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" fx:id="tblStationsHistorie"> | |||
| <TableView prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" fx:id="tblStationsHistorie" > | |||
| <columns> | |||
| <TableColumn prefWidth="75.0" text="Station" fx:id="colStatHistStation"/> | |||
| <TableColumn prefWidth="75.0" text="Aufnahme" fx:id="colStatHistAufnahmeDatum"/> | |||
| <TableColumn prefWidth="75.0" text="Entlassung" fx:id="colStatHistEntlassungsDatum"/> | |||
| </columns> | |||
| <columnResizePolicy> | |||
| <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /> | |||
| </columnResizePolicy> | |||
| </TableView> | |||
| </children> | |||
| </VBox> | |||
| @@ -43,7 +46,7 @@ | |||
| </rowConstraints> | |||
| <children> | |||
| <Label text="Abteilung:"/> | |||
| <ComboBox disable="true" prefWidth="150.0" GridPane.columnIndex="1" fx:id="cmbAbteilung"/> | |||
| <ComboBox prefWidth="150.0" GridPane.columnIndex="1" fx:id="cmbAbteilung"/> | |||
| <Label text="Station:" GridPane.rowIndex="1"/> | |||
| <ComboBox prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="1" fx:id="cmbStation"/> | |||