Im Rahmen der Veranstaltung "CS3330 - Projektpraktikum MedizinischeInformatik" an der Universität zu Lübeck entstandenes Krankenhausinformationssystem (KIS).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

299 line
9.1 KiB

  1. package de.uniluebeck.mi.projmi6.controller;
  2. import de.uniluebeck.mi.projmi6.db.DBHandler;
  3. import de.uniluebeck.mi.projmi6.model.DiagArt;
  4. import de.uniluebeck.mi.projmi6.model.Diagnose;
  5. import de.uniluebeck.mi.projmi6.model.Icd10Code;
  6. import de.uniluebeck.mi.projmi6.model.Mitarbeiter;
  7. import de.uniluebeck.mi.projmi6.view.SelectKeyComboBoxListener;
  8. import javafx.beans.property.ReadOnlyObjectProperty;
  9. import javafx.beans.property.SimpleObjectProperty;
  10. import javafx.collections.FXCollections;
  11. import javafx.collections.ObservableList;
  12. import javafx.collections.transformation.FilteredList;
  13. import javafx.fxml.FXML;
  14. import javafx.scene.control.*;
  15. import javafx.scene.layout.GridPane;
  16. /**
  17. * Controller that mantains the diagnosis assigned to a case in the UI.
  18. *
  19. * @author Johannes
  20. * Created by 631806 on 12.11.15.
  21. */
  22. public class DiagnoseController {
  23. private final SimpleObjectProperty<ObservableList<Diagnose>> diagnosen = new SimpleObjectProperty<>();
  24. /**
  25. * Controller state definitions
  26. */
  27. public enum State {
  28. CREATE, EDIT, VIEW
  29. }
  30. /**
  31. * Current controllers state
  32. */
  33. private final SimpleObjectProperty<State> state = new SimpleObjectProperty<>(State.VIEW);
  34. @FXML
  35. private Button btnDiagAbort, btnDiagEdit, btnDiagSave, btnDiagCreate, btnDiagCancel;
  36. @FXML
  37. private final MainController mainController;
  38. @FXML
  39. private ListView<Diagnose> diagnoseList;
  40. @FXML
  41. private GridPane fields;
  42. @FXML
  43. private ComboBox<Mitarbeiter> diagDiagnoseArzt;
  44. @FXML
  45. private Label diagCreator, diagCreateTime, diagChanger, diagChangeTime;
  46. @FXML
  47. private TextArea diagFreitext;
  48. @FXML
  49. private ComboBox<DiagArt> diagDiagnoseArt;
  50. @FXML
  51. private ComboBox<Icd10Code> diagDiagnose;
  52. /**
  53. * Contructor.
  54. *
  55. * @param mainController The main controller that creates this instance.
  56. */
  57. public DiagnoseController(MainController mainController) {
  58. this.mainController = mainController;
  59. }
  60. /**
  61. * Getter for the {@link #diagnosenProperty()}.
  62. *
  63. * @return The list of diagnosis shown in the GUI. Might be null.
  64. */
  65. public ObservableList<Diagnose> getDiagnosen() {
  66. return diagnosen.get();
  67. }
  68. /**
  69. * Setter for the {@link #diagnosenProperty()}.
  70. *
  71. * @param diagnosen A observable list of diagnosis to be set.
  72. */
  73. public void setDiagnosen(ObservableList<Diagnose> diagnosen) {
  74. this.diagnosen.set(diagnosen);
  75. }
  76. /**
  77. * The diagnosis in this controller.
  78. *
  79. * @return A simple object property.
  80. */
  81. public SimpleObjectProperty<ObservableList<Diagnose>> diagnosenProperty() {
  82. return diagnosen;
  83. }
  84. /**
  85. * Getter for the state of this controller
  86. *
  87. * @return State.VIEW, State.EDIT or State.CREATE
  88. */
  89. public State getState() {
  90. return state.get();
  91. }
  92. /**
  93. * A property for the controllers state.
  94. */
  95. public ReadOnlyObjectProperty<State> stateProperty() {
  96. return state;
  97. }
  98. /**
  99. * FXMLLoaders initialize()-method.
  100. * See <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/doc-files/introduction_to_fxml.html#controllers">Oracle FXML Introduction</a>
  101. */
  102. @FXML
  103. private void initialize() {
  104. initButtons();
  105. //Init diagnosis list view
  106. diagDiagnose.itemsProperty().bind(mainController.getStammdaten().icd10CodesProperty());
  107. new SelectKeyComboBoxListener(diagDiagnose);
  108. //init fields on the right
  109. diagDiagnoseArt.setItems(FXCollections.observableArrayList(DiagArt.values()));
  110. FilteredList<Mitarbeiter> mitarbeiterFilteredList = new FilteredList<Mitarbeiter>(mainController.getStammdaten().getMitarbeiter());
  111. mitarbeiterFilteredList.setPredicate(m -> !m.getNachname().equalsIgnoreCase("SYSTEM"));
  112. diagDiagnoseArzt.setItems(mitarbeiterFilteredList);
  113. diagnoseList.itemsProperty().bind(diagnosen);
  114. fields.disableProperty().bind(state.isEqualTo(State.VIEW));
  115. //Init the list view on the left.
  116. diagnoseList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
  117. diagnoseList.disableProperty().bind(state.isNotEqualTo(State.VIEW));
  118. diagnoseList.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
  119. if (newValue == null) {
  120. clearFields();
  121. } else {
  122. copyDiagnoseDataIntoFields(newValue);
  123. }
  124. });
  125. //React on state changes.
  126. state.addListener((observable, oldValue, newValue) -> {
  127. if (newValue == State.VIEW) {
  128. mainController.unlockFromEdit();
  129. Diagnose diagnose = diagnoseList.getSelectionModel().getSelectedItem();
  130. if (diagnose == null) {
  131. clearFields();
  132. } else {
  133. copyDiagnoseDataIntoFields(diagnose);
  134. }
  135. } else {
  136. mainController.lockForEdit(MainController.TabName.DIAGNOSE);
  137. if (newValue == State.CREATE) {
  138. clearFields();
  139. diagDiagnoseArzt.setValue(mainController.getCurrentMitarbeiter());
  140. }
  141. }
  142. });
  143. }
  144. /**
  145. * Bind button visibility to application state.
  146. */
  147. private void initButtons() {
  148. btnDiagCreate.disableProperty().bind(mainController.fallProperty().isNull());
  149. btnDiagEdit.disableProperty().bind(diagnoseList.getSelectionModel().selectedItemProperty().isNull());
  150. //btnDiagEdit.managedProperty().bind(state.isEqualTo(State.VIEW));
  151. //btnDiagEdit.visibleProperty().bind(btnDiagEdit.managedProperty());
  152. btnDiagEdit.setManaged(false);
  153. btnDiagEdit.setVisible(false);
  154. btnDiagSave.managedProperty().bind(state.isNotEqualTo(State.VIEW));
  155. btnDiagSave.visibleProperty().bind(btnDiagSave.managedProperty());
  156. btnDiagAbort.managedProperty().bind(btnDiagSave.managedProperty());
  157. btnDiagAbort.visibleProperty().bind(btnDiagSave.managedProperty());
  158. }
  159. /**
  160. * EventHandler for {@link #btnDiagEdit}.
  161. */
  162. @FXML
  163. private void clickedEdit() {
  164. state.set(State.EDIT);
  165. }
  166. /**
  167. * EventHandler for {@link #btnDiagAbort}.
  168. */
  169. @FXML
  170. private void clickedAbort() {
  171. state.set(State.VIEW);
  172. }
  173. /**
  174. * EventHandler for the {@link #btnDiagCreate}.
  175. */
  176. @FXML
  177. private void clickedDiagCreate() {
  178. this.state.set(State.CREATE);
  179. }
  180. /**
  181. * EventHandler for the {@link #btnDiagCancel}.
  182. */
  183. @FXML
  184. private void clickedDiagCancel() {
  185. }
  186. /**
  187. * EventHandler method for {@link #btnDiagSave}
  188. */
  189. @FXML
  190. void clickedDiagSave() {
  191. if (state.get() == State.CREATE) {
  192. //Create new diagnosis
  193. Diagnose diagnose = new Diagnose();
  194. copyFieldDataIntoDiagnose(diagnose);
  195. try {
  196. DBHandler.setDiagnose(diagnose);
  197. } catch (Exception e) {
  198. e.printStackTrace();
  199. }
  200. }
  201. mainController.refreshCaseData();
  202. state.set(State.VIEW);
  203. }
  204. /**
  205. * Copy the object data into the fields.
  206. *
  207. * @param diagnose The object with the data.
  208. */
  209. private void copyDiagnoseDataIntoFields(Diagnose diagnose) {
  210. //Find the DiagnoseArzt by id.
  211. for (Mitarbeiter current : diagDiagnoseArzt.getItems()) {
  212. if (current.getMitarbID() == diagnose.getMitarbid()) {
  213. diagDiagnoseArzt.setValue(current);
  214. break;
  215. }
  216. }
  217. diagFreitext.setText(diagnose.getFreiText());
  218. diagDiagnoseArt.setValue(diagnose.getDiagArt());
  219. diagDiagnose.setValue(diagnose.getIcd10code());
  220. diagCreator.setText(Integer.toString(diagnose.getErsteller()));
  221. diagCreateTime.setText(diagnose.getErstellDatumZeit().toString());
  222. diagChanger.setText(Integer.toString(diagnose.getBearbeiter()));
  223. diagChangeTime.setText(diagnose.getBearbeitetDatumZeit().toString());
  224. }
  225. /**
  226. * Copy the data from the ComboBoxes into data model object
  227. *
  228. * @param diagnose The object to copy the data into
  229. */
  230. private void copyFieldDataIntoDiagnose(Diagnose diagnose) {
  231. diagnose.setIcd10code(diagDiagnose.getValue());
  232. diagnose.setArzt(diagDiagnoseArzt.getValue());
  233. diagnose.setFreiText(diagFreitext.getText());
  234. diagnose.setDiagArt(diagDiagnoseArt.getValue());
  235. diagnose.setFall(mainController.getFall());
  236. diagnose.setErsteller(mainController.getCurrentMitarbeiter().getMitarbID());
  237. diagnose.setBearbeiter(mainController.getCurrentMitarbeiter().getMitarbID());
  238. }
  239. /**
  240. * Clear the fields in case no diagnosis is selcted, or
  241. * creating a new one is started.
  242. */
  243. public void clearFields() {
  244. diagDiagnoseArzt.setValue(null);
  245. diagDiagnose.setValue(null);
  246. diagFreitext.setText("");
  247. diagDiagnoseArt.setValue(null);
  248. diagCreator.setText("");
  249. diagCreateTime.setText("");
  250. diagChanger.setText("");
  251. diagChangeTime.setText("");
  252. }
  253. }