package de.uniluebeck.mi.projmi6.controller; /** * Created by 631806 on 12.11.15. */ import de.uniluebeck.mi.projmi6.db.DBHandler; import de.uniluebeck.mi.projmi6.model.*; import de.uniluebeck.mi.projmi6.view.DateTimePicker; import javafx.beans.property.ObjectProperty; import javafx.beans.property.ReadOnlyObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import java.sql.SQLException; public class FallController { private MainController mainController; public FallController (MainController mainController){ this.mainController = mainController; } @FXML private DateTimePicker dtTmAufnahme, dtTmEntlassung; @FXML private Label fallPatID; @FXML private ComboBox fallFallart; @FXML private ComboBox fallKasse; @FXML private TextField fallVersichertennummer; @FXML private TextField fallEinweisenderArzt; @FXML private CheckBox fallSelbsteinweisung; @FXML private ComboBox fallHauptdiagnose; @FXML private Label fallCreator; @FXML private Label fallEditor; @FXML private Label fallCreateTime; @FXML private Label fallEditTime; @FXML private Button btnFallSave; @FXML private Button btnFallAbort; @FXML private Button btnFallCancel; @FXML private Button btnFallEnableEdit; @FXML private GridPane fallFields; private SimpleObjectProperty fallProperty = new SimpleObjectProperty<>(); public Fall getFall() { return fallProperty.get(); } public SimpleObjectProperty fallPropertyProperty() { return fallProperty; } public void setFall(Fall fall) { this.fallProperty.set(fall); } public enum State { CREATE, EDIT, VIEW } public State getState() { return state.get(); } public ReadOnlyObjectProperty stateProperty() { return state; } SimpleObjectProperty state = new SimpleObjectProperty<>(State.VIEW); public ObjectProperty> diagnosenProperty(){ return fallHauptdiagnose.itemsProperty(); } public void setDiagnosen(ObservableList list){ fallHauptdiagnose.setItems(list); } public ObservableList getDiagnosen(){ return fallHauptdiagnose.getItems(); } @FXML public void initialize(){ fallEinweisenderArzt.disableProperty().bind(fallSelbsteinweisung.selectedProperty()); fallFallart.setItems(FXCollections.observableArrayList(FallArt.values())); fallKasse.setItems(mainController.getStammdaten().getKassen()); initButtons(); fallFields.disableProperty().bind(state.isEqualTo(State.VIEW)); fallProperty.addListener(((observable, oldValue, newValue) -> { if(state.get() == State.VIEW){ copyFallDataIntoField(fallProperty.get()); } })); state.addListener((observable, oldValue, newValue) -> { if(newValue==State.EDIT || newValue == State.CREATE){ mainController.lockForEdit(MainController.TabName.OVERVIEW); }else{ mainController.unlockFromEdit(); } }); } /** * Hide the buttons depending on controller state. */ private void initButtons(){ btnFallEnableEdit.managedProperty().bind( state.isEqualTo(State.VIEW).and(fallProperty.isNotNull()) ); btnFallEnableEdit.visibleProperty().bind(btnFallEnableEdit.managedProperty()); btnFallAbort.managedProperty().bind( state.isNotEqualTo(State.VIEW) ); btnFallAbort.visibleProperty().bind(btnFallAbort.managedProperty()); btnFallSave.managedProperty().bind( state.isNotEqualTo(State.VIEW) ); btnFallSave.visibleProperty().bind(btnFallSave.managedProperty()); btnFallCancel.managedProperty().bind( state.isEqualTo(State.VIEW).and(fallProperty.isNotNull()) ); btnFallCancel.visibleProperty().bind(btnFallCancel.managedProperty()); btnFallSendHl7.managedProperty().bind( state.isEqualTo(State.VIEW).and(fallProperty.isNotNull()) ); btnFallSendHl7.visibleProperty().bind(btnFallSendHl7.managedProperty()); } @FXML Button btnFallSendHl7; @FXML private void clickedSendHl7(){ /* Natascha */ //TODO send funny message Fall fall = fallProperty.get(); Patient patient = mainController.getPatientTablesController().getSelectedPatient(); } public void editFall(){ this.state.set(State.EDIT); } @FXML void clickedFallEnableEdit(ActionEvent event) { editFall(); } @FXML void clickedFallCancel(ActionEvent event) { if(fallProperty.get()!=null){ fallProperty.get().setStorniert(true); try { DBHandler.setFall(fallProperty.get(), mainController.getCurrentMitarbeiter().getMitarbID(), true); }catch (Exception e){ e.printStackTrace(); } mainController.refreshCasesFromDb(mainController.getPatientTablesController().getSelectedPatient()); } } @FXML void clickedFallAbort(ActionEvent event) { this.state.set(State.VIEW); copyFallDataIntoField(fallProperty.get()); } @FXML void clickedFallSave(ActionEvent event) { if (this.state.get() == State.CREATE) { Fall fall = new Fall(); copyFieldDataIntoFall(fall); try { DBHandler.setFall(fall, mainController.getCurrentMitarbeiter().getMitarbID()); } catch (SQLException e) { e.printStackTrace(); } } else { copyFieldDataIntoFall(fallProperty.get()); try { DBHandler.setFall(fallProperty.get(), mainController.getCurrentMitarbeiter().getMitarbID(), true); } catch (SQLException e) { e.printStackTrace(); } } this.state.set(State.VIEW); mainController.refreshCasesFromDb(mainController.getPatientTablesController().getSelectedPatient()); } public void createNewFall() { clearFields(); this.state.set(State.CREATE); Patient patient = mainController.getPatientTablesController().getSelectedPatient(); // Kasse by Default auf die im Patienten hinterlegten Kasse setzen. for (Kasse kasse : fallKasse.getItems()) { if (kasse.getKassenID() == patient.getKassenID()) { fallKasse.getSelectionModel().select(kasse); break; } } fallVersichertennummer.setText(patient.getVersichertennummer()); } private void clearFields(){ if(state.get() == State.CREATE) { dtTmAufnahme.setToCurrentDateTime(); dtTmEntlassung.setToCurrentDateTime(); }else{ dtTmAufnahme.setDateTime(null); dtTmEntlassung.setDateTime(null); } fallPatID.setText(""); //TODO fallCreateTime.setText(""); fallCreator.setText(""); fallEditTime.setText(""); fallEditor.setText(""); fallEinweisenderArzt.setText(""); fallSelbsteinweisung.setSelected(false); fallVersichertennummer.setText(""); fallKasse.setValue(null); fallHauptdiagnose.setValue(null); fallHauptdiagnose.setItems(null); fallFallart.setValue(null); } private void copyFieldDataIntoFall(Fall fall){ fall.setPatient(mainController.getPatientTablesController().getSelectedPatient()); fall.setAufnahmeDatum(dtTmAufnahme.getDateTime()); fall.setEntlassungsDatum(dtTmEntlassung.getDateTime()); if(fallSelbsteinweisung.isSelected()) { fall.setSelbsteinweisung(true); fall.setEinweisenderArzt(null); }else{ fall.setEinweisenderArzt(fallEinweisenderArzt.getText()); fall.setSelbsteinweisung(false); } fall.setVersichertenNummer(fallVersichertennummer.getText()); fall.setKasse(fallKasse.getValue()); fall.setFallArt(fallFallart.getValue()); //fall.setVorstellDatum(); //TODO } private void copyFallDataIntoField(Fall fall){ if(fall==null){ System.out.println("copyFallDataIntoFiled - Fall ist null"); clearFields(); return; } dtTmAufnahme.setDateTime(fall.getAufnahmeDatum()); dtTmEntlassung.setDateTime(fall.getEntlassungsDatum()); fallPatID.setText(fallProperty.get().getPatient() + ""); //(fall.getPatient().getVorname()+" "+fall.getPatient().getNachname()); //TODO fallCreateTime.setText(fall.getErstellDatumZeit() !=null ? fall.getErstellDatumZeit().toString():""); fallCreator.setText(Integer.toString(fall.getErsteller())); fallEditTime.setText(fall.getBearbeitetDatumZeit()!=null? fall.getBearbeitetDatumZeit().toString():""); fallEditor.setText(Integer.toString(fall.getBearbeiter())); fallEinweisenderArzt.setText(fall.getEinweisenderArzt()); fallSelbsteinweisung.setSelected(fall.getSelbsteinweisung()); fallVersichertennummer.setText(fall.getVersichertenNummer()); fallKasse.setValue(fall.getKasse()); //fallHauptdiagnose.setValue(fall.getHauptDiagnose()); TODO // fallHauptdiagnose.setItems(fall.getD); TODO fallFallart.setValue(fall.getFallArt()); } }