Im Rahmen der Veranstaltung "CS3330 - Projektpraktikum MedizinischeInformatik" an der Universität zu Lübeck entstandenes Krankenhausinformationssystem (KIS).
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

350 行
13 KiB

  1. package de.uniluebeck.mi.projmi6.controller;
  2. /**
  3. * Created by Johannes on 12.11.15.
  4. */
  5. import de.uniluebeck.mi.projmi6.db.DBHandler;
  6. import de.uniluebeck.mi.projmi6.model.Patient;
  7. import de.uniluebeck.mi.projmi6.model.Station;
  8. import de.uniluebeck.mi.projmi6.model.StationsUebersichtsItem;
  9. import de.uniluebeck.mi.projmi6.view.SelectKeyComboBoxListener;
  10. import javafx.beans.binding.Bindings;
  11. import javafx.beans.binding.ObjectBinding;
  12. import javafx.collections.FXCollections;
  13. import javafx.collections.ObservableList;
  14. import javafx.collections.transformation.FilteredList;
  15. import javafx.concurrent.Task;
  16. import javafx.fxml.FXML;
  17. import javafx.fxml.FXMLLoader;
  18. import javafx.scene.Parent;
  19. import javafx.scene.Scene;
  20. import javafx.scene.control.*;
  21. import javafx.scene.control.cell.PropertyValueFactory;
  22. import javafx.scene.image.Image;
  23. import javafx.stage.Modality;
  24. import javafx.stage.Stage;
  25. import java.io.IOException;
  26. import java.time.LocalDate;
  27. import java.util.List;
  28. /**
  29. * Controller class.
  30. */
  31. public class PatientTablesController {
  32. @FXML
  33. Button btnStatRefresh;
  34. private MainController mainController;
  35. @FXML
  36. private Label lblTablePatientEmpty;
  37. @FXML
  38. private Label lblTableStationEmpty;
  39. @FXML
  40. private Button btnPatCreate;
  41. @FXML
  42. private Button btnPatEdit;
  43. @FXML
  44. private TableView<Patient> tblPatientOverview;
  45. @FXML
  46. private TableColumn<Patient, String> colPatPatId;
  47. @FXML
  48. private TableColumn<Patient, String> colPatGeburtsname;
  49. @FXML
  50. private TableColumn<Patient, String> colPatNachname;
  51. @FXML
  52. private TableColumn<Patient, String> colPatVorname;
  53. @FXML
  54. private TableColumn<Patient, LocalDate> colPatGebDatum;
  55. @FXML
  56. private TableColumn<Patient, String> colPatStrasse;
  57. @FXML
  58. private TableColumn<Patient, String> colPatPlz;
  59. @FXML
  60. private TableColumn<Patient, String> colPatOrt;
  61. @FXML
  62. private TableColumn<Patient, String> colPatCave;
  63. @FXML
  64. private ToggleButton btnEntlassenePatientenZeigen;
  65. @FXML
  66. private ComboBox<Station> cmbStationenFilter;
  67. @FXML
  68. private TableView<StationsUebersichtsItem> tblStationOverview;
  69. @FXML
  70. private TableColumn<StationsUebersichtsItem, Integer> colStatPatId;
  71. @FXML
  72. private TableColumn<StationsUebersichtsItem, String> colStatFullName;
  73. @FXML
  74. private TableColumn<StationsUebersichtsItem, LocalDate> colStatGebDatum;
  75. @FXML
  76. private TableColumn<StationsUebersichtsItem, Integer> colStatAlter;
  77. @FXML
  78. private TableColumn<StationsUebersichtsItem, LocalDate> colStatAufnahmedatum;
  79. @FXML
  80. private TableColumn<StationsUebersichtsItem, LocalDate> colStatEntlassungsdatum;
  81. @FXML
  82. private Tab stationOverviewTab;
  83. @FXML
  84. private Tab patientOverviewTab;
  85. @FXML
  86. private TabPane patientOverviewTabPane;
  87. private ObservableList<StationsUebersichtsItem> stationsUebersicht = FXCollections.observableArrayList();
  88. private FilteredList<StationsUebersichtsItem> stationsUebersichtsItemFilteredList = new FilteredList<StationsUebersichtsItem>(stationsUebersicht,
  89. item -> item.getStationEntlassung() == null || !item.getStationEntlassung().isAfter(LocalDate.now()));
  90. private Task loadStationsHistorieTask = null;
  91. private Task loadPatientTask = null;
  92. @FXML
  93. private Button btnPatRefresh;
  94. private ObjectBinding<Patient> patientObjectBinding = null;
  95. public PatientTablesController(MainController mainController) {
  96. this.mainController = mainController;
  97. }
  98. public TabPane getPatientOverviewTabPane() {
  99. return patientOverviewTabPane;
  100. }
  101. @FXML
  102. public void initialize() {
  103. btnPatEdit.disableProperty().bind(tblPatientOverview.getSelectionModel().selectedItemProperty().isNull());
  104. tblPatientOverview.setRowFactory(tableView -> {
  105. TableRow<Patient> tableRow = new TableRow<>();
  106. tableRow.setOnMouseClicked(event -> {
  107. if (event.getClickCount() == 2 && (!tableRow.isEmpty())) {
  108. Patient patient = tableRow.getItem();
  109. showEditWindow(patient);
  110. }
  111. });
  112. return tableRow;
  113. });
  114. lblTablePatientEmpty.setText("Liste ist leer.");
  115. tblStationOverview.disableProperty().bind(cmbStationenFilter.valueProperty().isNull());
  116. cmbStationenFilter.itemsProperty().bind(mainController.getStammdaten().stationenProperty());
  117. new SelectKeyComboBoxListener(cmbStationenFilter);
  118. patientObjectBinding = Bindings.<Patient>createObjectBinding(() -> {
  119. if (patientOverviewTabPane.getSelectionModel().getSelectedItem().equals(patientOverviewTab)) {
  120. return tblPatientOverview.getSelectionModel().getSelectedItem();
  121. } else if (tblStationOverview.getSelectionModel().getSelectedItem() == null) {
  122. return null;
  123. } else {
  124. int selectedPatId = tblStationOverview.getSelectionModel().getSelectedItem().getPatId();
  125. Patient selectedPatient = tblPatientOverview.getItems().stream().filter(p -> p.getPatID() == selectedPatId).findFirst().orElse(null);
  126. return selectedPatient;
  127. }
  128. }, tblPatientOverview.getSelectionModel().selectedItemProperty(),
  129. tblStationOverview.getSelectionModel().selectedItemProperty(),
  130. patientOverviewTabPane.getSelectionModel().selectedItemProperty());
  131. initColumnsPatient();
  132. initColumnsStation();
  133. updatePatientsFromDb();
  134. }
  135. private void initColumnsPatient() {
  136. colPatPatId.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().patIDProperty().asString());
  137. colPatGeburtsname.setCellValueFactory(new PropertyValueFactory<>("geburtsname"));
  138. colPatNachname.setCellValueFactory(new PropertyValueFactory<>("nachname"));
  139. colPatVorname.setCellValueFactory(new PropertyValueFactory<>("vorname"));
  140. colPatGebDatum.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().geburtsdatumProperty());
  141. colPatStrasse.setCellValueFactory(cellDataFeatures -> {
  142. Patient patient = cellDataFeatures.getValue();
  143. return Bindings.concat(patient.strasseProperty(), " ", patient.hausnummerProperty());
  144. });
  145. colPatPlz.setCellValueFactory(new PropertyValueFactory<>("plz"));
  146. colPatOrt.setCellValueFactory(new PropertyValueFactory<>("ort"));
  147. colPatCave.setCellValueFactory(new PropertyValueFactory<>("cave"));
  148. }
  149. private void initColumnsStation() {
  150. colStatPatId.setCellValueFactory(new PropertyValueFactory<StationsUebersichtsItem, Integer>("patId"));
  151. colStatFullName.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().patNameProperty());
  152. colStatGebDatum.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().patBirthdateProperty());
  153. colStatAlter.setCellValueFactory(new PropertyValueFactory<StationsUebersichtsItem, Integer>("patAge"));
  154. colStatAufnahmedatum.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().stationAufnahmeProperty());
  155. colStatEntlassungsdatum.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().stationEntlassungProperty());
  156. cmbStationenFilter.valueProperty().addListener((observableValue, oldValue, newValue) -> {
  157. updateStationsHistorieFromDb();
  158. });
  159. tblStationOverview.itemsProperty().bind(Bindings.createObjectBinding(() -> {
  160. if (btnEntlassenePatientenZeigen.isSelected()) {
  161. return stationsUebersicht;
  162. } else {
  163. return stationsUebersichtsItemFilteredList;
  164. }
  165. }, btnEntlassenePatientenZeigen.selectedProperty()));
  166. }
  167. @FXML
  168. private void clickedCreatePatient() {
  169. showEditWindow(null);
  170. }
  171. @FXML
  172. private void clickedEditPatient() {
  173. showEditWindow(tblPatientOverview.getSelectionModel().getSelectedItem());
  174. }
  175. private void showEditWindow(Patient patient) {
  176. FXMLLoader fxmlLoader = new FXMLLoader();
  177. fxmlLoader.setLocation(getClass().getClassLoader().getResource("patient_edit.fxml"));
  178. PatientEditorController patientEditorController = new PatientEditorController(mainController);
  179. fxmlLoader.setControllerFactory(clazz -> patientEditorController);
  180. Parent root = null;
  181. try {
  182. root = fxmlLoader.load();
  183. } catch (IOException e) {
  184. e.printStackTrace();
  185. return;
  186. }
  187. Stage stage = new Stage();
  188. stage.setTitle(patient == null ? "Neuen Patienten erstellen" : "Patient bearbeiten");
  189. stage.setScene(new Scene(root, 600, 600));
  190. stage.getIcons().add(new Image("icon.png"));
  191. stage.initModality(Modality.WINDOW_MODAL);
  192. stage.initOwner(btnPatEdit.getScene().getWindow());
  193. patientEditorController.setPatient(patient);
  194. stage.show();
  195. }
  196. public void updatePatientsFromDb() {
  197. if (this.loadPatientTask != null && this.loadPatientTask.isRunning()) {
  198. System.out.println("Patienten werden bereits geladen.");
  199. return;
  200. }
  201. btnPatRefresh.setDisable(true);
  202. tblPatientOverview.setItems(null);
  203. mainController.increaseParallelTaskCount();
  204. lblTablePatientEmpty.setText("Liste wird geladen...");
  205. Task<List<Patient>> loadPatientsTask = new Task<List<Patient>>() {
  206. @Override
  207. protected List<Patient> call() throws Exception {
  208. return FXCollections.<Patient>observableArrayList(DBHandler.getAllPatients());
  209. }
  210. @Override
  211. protected void succeeded() {
  212. super.succeeded();
  213. btnPatRefresh.setDisable(false);
  214. lblTablePatientEmpty.setText("Liste ist leer.");
  215. tblPatientOverview.setItems(FXCollections.observableArrayList(this.getValue()));
  216. mainController.decreaseParallelTaskCount();
  217. }
  218. @Override
  219. protected void failed() {
  220. super.failed();
  221. btnPatRefresh.setDisable(false);
  222. lblTablePatientEmpty.setText("Laden fehlgeschlagen!");
  223. mainController.decreaseParallelTaskCount();
  224. tblPatientOverview.setItems(null);
  225. if (getException() != null) {
  226. getException().printStackTrace();
  227. }
  228. }
  229. };
  230. this.loadPatientTask = loadPatientsTask;
  231. Thread thread = new Thread(loadPatientsTask);
  232. thread.setDaemon(true);
  233. thread.start();
  234. }
  235. @FXML
  236. private void clickedRefreshStation() {
  237. updateStationsHistorieFromDb();
  238. }
  239. public void updateStationsHistorieFromDb() {
  240. if (this.loadStationsHistorieTask != null) {
  241. loadStationsHistorieTask.cancel();
  242. }
  243. lblTableStationEmpty.setText("Liste wird geladen...");
  244. btnStatRefresh.setDisable(true);
  245. stationsUebersicht.clear();
  246. mainController.increaseParallelTaskCount();
  247. Task<List<StationsUebersichtsItem>> loadStatHist = new Task<List<StationsUebersichtsItem>>() {
  248. @Override
  249. protected List<StationsUebersichtsItem> call() throws Exception {
  250. return FXCollections.<StationsUebersichtsItem>observableArrayList(
  251. DBHandler.getStationsUebersichtsItems(cmbStationenFilter.getValue().getStation()));
  252. }
  253. @Override
  254. protected void succeeded() {
  255. super.succeeded();
  256. if (!isCancelled()) {
  257. lblTableStationEmpty.setText("Liste ist leer.");
  258. stationsUebersicht.setAll(this.getValue());
  259. btnStatRefresh.setDisable(false);
  260. mainController.decreaseParallelTaskCount();
  261. }
  262. }
  263. @Override
  264. protected void cancelled() {
  265. super.cancelled();
  266. mainController.decreaseParallelTaskCount();
  267. }
  268. @Override
  269. protected void failed() {
  270. super.failed();
  271. if (!isCancelled()) {
  272. lblTableStationEmpty.setText("Laden fehlgeschlagen!");
  273. getException().printStackTrace();
  274. btnStatRefresh.setDisable(false);
  275. mainController.decreaseParallelTaskCount();
  276. }
  277. }
  278. };
  279. this.loadStationsHistorieTask = loadStatHist;
  280. Thread thread = new Thread(loadStationsHistorieTask);
  281. thread.setDaemon(true);
  282. thread.start();
  283. }
  284. @FXML
  285. private void clickedRefreshPatient() {
  286. updatePatientsFromDb();
  287. }
  288. public ObjectBinding<Patient> selectedPatientProperty() {
  289. return patientObjectBinding;
  290. }
  291. public Patient getSelectedPatient() {
  292. return selectedPatientProperty().get();
  293. }
  294. }