package de.uniluebeck.mi.projmi6.controller; /** * Created by Johannes on 12.11.15. */ import de.uniluebeck.mi.projmi6.db.DBHandler; import de.uniluebeck.mi.projmi6.model.Patient; import de.uniluebeck.mi.projmi6.model.Station; import de.uniluebeck.mi.projmi6.model.StationsUebersichtsItem; import javafx.beans.binding.Bindings; import javafx.beans.binding.ObjectBinding; 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.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.image.Image; import javafx.stage.Modality; import javafx.stage.Stage; import java.io.IOException; import java.rmi.server.ExportException; import java.sql.SQLException; import java.time.LocalDate; /** * Controller class. */ public class PatientTablesController{ private MainController mainController; @FXML private Label lblTablePatientEmpty; @FXML private Label lblTableStationEmpty; @FXML private Button btnPatCreate; @FXML private Button btnPatEdit; @FXML private TableView tblPatientOverview; @FXML private TableColumn colPatPatId; @FXML private TableColumn colPatGeburtsname; @FXML private TableColumn colPatNachname; @FXML private TableColumn colPatVorname; @FXML private TableColumn colPatGebDatum; @FXML private TableColumn colPatStrasse; @FXML private TableColumn colPatPlz; @FXML private TableColumn colPatOrt; @FXML private TableColumn colPatCave; @FXML private ToggleButton btnEntlassenePatientenZeigen; @FXML private ComboBox cmbStationenFilter; @FXML private TableView tblStationOverview; @FXML private TableColumn colStatPatId; @FXML private TableColumn colStatFullName; @FXML private TableColumn colStatGebDatum; @FXML private TableColumn colStatAlter; @FXML private TableColumn colStatAufnahmedatum; @FXML private TableColumn colStatEntlassungsdatum; @FXML private Tab stationOverviewTab, patientOverviewTab; @FXML private TabPane patientOverviewTabPane; public PatientTablesController(MainController mainController){ this.mainController = mainController; } @FXML public void initialize() { btnPatEdit.disableProperty().bind(tblPatientOverview.getSelectionModel().selectedItemProperty().isNull()); tblPatientOverview.setRowFactory(tableView -> { TableRow tableRow = new TableRow<>(); tableRow.setOnMouseClicked(event -> { if(event.getClickCount()==2 && (!tableRow.isEmpty())){ Patient patient = tableRow.getItem(); showEditWindow(patient); } }); return tableRow; }); lblTablePatientEmpty.setText("Liste ist leer."); lblTableStationEmpty.setText("Daten werden geladen..."); cmbStationenFilter.itemsProperty().bind(mainController.stationenProperty()); ObservableList patientList = null; try { patientList = FXCollections.observableArrayList(DBHandler.getAllPatients()); } catch (SQLException e) { e.printStackTrace(); } tblPatientOverview.setItems(patientList); initColumnsPatient(); initColumnsStation(); } private void initColumnsPatient(){ colPatPatId.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().patIDProperty().asString()); colPatGeburtsname.setCellValueFactory(new PropertyValueFactory<>("geburtsname")); colPatNachname.setCellValueFactory(new PropertyValueFactory<>("nachname")); colPatVorname.setCellValueFactory(new PropertyValueFactory<>("vorname")); colPatGebDatum.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().geburtsdatumProperty()); colPatStrasse.setCellValueFactory(cellDataFeatures -> { Patient patient = cellDataFeatures.getValue(); return Bindings.concat(patient.strasseProperty(), " ", patient.hausnummerProperty()); }); colPatPlz.setCellValueFactory(new PropertyValueFactory<>("plz")); colPatOrt.setCellValueFactory(new PropertyValueFactory<>("ort")); colPatCave.setCellValueFactory(new PropertyValueFactory<>("cave")); } private void initColumnsStation(){ colStatPatId.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().patIdProperty().asString()); colStatFullName.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().patNameProperty()); colStatGebDatum.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().patBirthdateProperty().asString()); colStatAlter.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().patAgeProperty().asString()); colStatAufnahmedatum.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().stationAufnahmeProperty().asString()); colStatEntlassungsdatum.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().stationEntlassungProperty().asString()); } @FXML private void clickedCreatePatient (){ showEditWindow(null); } @FXML private void clickedEditPatient(){ showEditWindow(tblPatientOverview.getSelectionModel().getSelectedItem()); } private void showEditWindow(Patient patient){ FXMLLoader fxmlLoader = new FXMLLoader(); fxmlLoader.setLocation(getClass().getClassLoader().getResource("patient_edit.fxml")); PatientEditorController patientEditorController = new PatientEditorController(mainController); fxmlLoader.setControllerFactory(clazz -> patientEditorController); Parent root = null; try{ root = fxmlLoader.load(); }catch (IOException e){ e.printStackTrace(); return; } Stage stage = new Stage(); stage.setTitle(patient==null ? "Neuen Patienten erstellen": "Patient bearbeiten"); stage.setScene(new Scene(root, 600, 600)); stage.getIcons().add(new Image("icon.png")); stage.initModality(Modality.WINDOW_MODAL); stage.initOwner(btnPatEdit.getScene().getWindow()); patientEditorController.setPatient(patient); stage.show(); } public ObjectBinding selectedPatientProperty(){ return Bindings.createObjectBinding(() ->{ return patientOverviewTabPane.getSelectionModel().getSelectedItem().equals(patientOverviewTab) ? tblPatientOverview.getSelectionModel().getSelectedItem() : null; //(Patient)tblStationOverview.getSelectionModel().getSelectedItem(); //TODO }, tblPatientOverview.getSelectionModel().selectedItemProperty(), tblStationOverview.getSelectionModel().selectedItemProperty(), patientOverviewTabPane.getSelectionModel().selectedItemProperty()); } public Patient getSelectedPatient(){ return selectedPatientProperty().get(); } }