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.

329 lines
10 KiB

  1. package de.uniluebeck.mi.projmi6.controller;
  2. /**
  3. * Created by 631806 on 12.11.15.
  4. */
  5. import de.uniluebeck.mi.projmi6.db.DBHandler;
  6. import de.uniluebeck.mi.projmi6.model.*;
  7. import de.uniluebeck.mi.projmi6.view.DateTimePicker;
  8. import javafx.beans.property.ObjectProperty;
  9. import javafx.beans.property.ReadOnlyObjectProperty;
  10. import javafx.beans.property.SimpleObjectProperty;
  11. import javafx.collections.FXCollections;
  12. import javafx.collections.ObservableList;
  13. import javafx.event.ActionEvent;
  14. import javafx.fxml.FXML;
  15. import javafx.scene.control.*;
  16. import javafx.scene.layout.GridPane;
  17. import java.sql.SQLException;
  18. public class FallController {
  19. SimpleObjectProperty<State> state = new SimpleObjectProperty<>(State.VIEW);
  20. @FXML
  21. Button btnFallSendHl7;
  22. private MainController mainController;
  23. @FXML
  24. private DateTimePicker dtTmAufnahme, dtTmEntlassung;
  25. @FXML
  26. private Label fallPatID;
  27. @FXML
  28. private ComboBox<FallArt> fallFallart;
  29. @FXML
  30. private ComboBox<Kasse> fallKasse;
  31. @FXML
  32. private TextField fallVersichertennummer;
  33. @FXML
  34. private TextField fallEinweisenderArzt;
  35. @FXML
  36. private CheckBox fallSelbsteinweisung;
  37. @FXML
  38. private ComboBox<Diagnose> fallHauptdiagnose;
  39. @FXML
  40. private Label fallCreator;
  41. @FXML
  42. private Label fallEditor;
  43. @FXML
  44. private Label fallCreateTime;
  45. @FXML
  46. private Label fallEditTime;
  47. @FXML
  48. private Button btnFallSave;
  49. @FXML
  50. private Button btnFallAbort;
  51. @FXML
  52. private Button btnFallCancel;
  53. @FXML
  54. private Button btnFallEnableEdit;
  55. @FXML
  56. private GridPane fallFields;
  57. private SimpleObjectProperty<Fall> fallProperty = new SimpleObjectProperty<>();
  58. public FallController(MainController mainController) {
  59. this.mainController = mainController;
  60. }
  61. public Fall getFall() {
  62. return fallProperty.get();
  63. }
  64. public void setFall(Fall fall) {
  65. this.fallProperty.set(fall);
  66. }
  67. public SimpleObjectProperty<Fall> fallPropertyProperty() {
  68. return fallProperty;
  69. }
  70. public State getState() {
  71. return state.get();
  72. }
  73. public ReadOnlyObjectProperty<State> stateProperty() {
  74. return state;
  75. }
  76. public ObjectProperty<ObservableList<Diagnose>> diagnosenProperty(){
  77. return fallHauptdiagnose.itemsProperty();
  78. }
  79. public ObservableList<Diagnose> getDiagnosen() {
  80. return fallHauptdiagnose.getItems();
  81. }
  82. public void setDiagnosen(ObservableList<Diagnose> list){
  83. fallHauptdiagnose.setItems(list);
  84. }
  85. @FXML
  86. public void initialize(){
  87. fallEinweisenderArzt.disableProperty().bind(fallSelbsteinweisung.selectedProperty());
  88. fallFallart.setItems(FXCollections.observableArrayList(FallArt.values()));
  89. fallKasse.setItems(mainController.getStammdaten().getKassen());
  90. initButtons();
  91. fallFields.disableProperty().bind(state.isEqualTo(State.VIEW));
  92. fallProperty.addListener(((observable, oldValue, newValue) -> {
  93. if(state.get() == State.VIEW){
  94. copyFallDataIntoField(fallProperty.get());
  95. }
  96. }));
  97. state.addListener((observable, oldValue, newValue) -> {
  98. if(newValue==State.EDIT || newValue == State.CREATE){
  99. mainController.lockForEdit(MainController.TabName.OVERVIEW);
  100. }else{
  101. mainController.unlockFromEdit();
  102. }
  103. });
  104. }
  105. /**
  106. * Hide the buttons depending on controller state.
  107. */
  108. private void initButtons(){
  109. btnFallEnableEdit.managedProperty().bind(
  110. state.isEqualTo(State.VIEW).and(fallProperty.isNotNull())
  111. );
  112. btnFallEnableEdit.visibleProperty().bind(btnFallEnableEdit.managedProperty());
  113. btnFallAbort.managedProperty().bind(
  114. state.isNotEqualTo(State.VIEW)
  115. );
  116. btnFallAbort.visibleProperty().bind(btnFallAbort.managedProperty());
  117. btnFallSave.managedProperty().bind(
  118. state.isNotEqualTo(State.VIEW)
  119. );
  120. btnFallSave.visibleProperty().bind(btnFallSave.managedProperty());
  121. btnFallCancel.managedProperty().bind(
  122. state.isEqualTo(State.VIEW).and(fallProperty.isNotNull())
  123. );
  124. btnFallCancel.visibleProperty().bind(btnFallCancel.managedProperty());
  125. btnFallSendHl7.managedProperty().bind(
  126. state.isEqualTo(State.VIEW).and(fallProperty.isNotNull())
  127. );
  128. btnFallSendHl7.visibleProperty().bind(btnFallSendHl7.managedProperty());
  129. }
  130. @FXML
  131. private void clickedSendHl7(){
  132. /* Natascha */
  133. //TODO send funny message
  134. Fall fall = fallProperty.get();
  135. Patient patient = mainController.getPatientTablesController().getSelectedPatient();
  136. }
  137. public void editFall(){
  138. this.state.set(State.EDIT);
  139. }
  140. @FXML
  141. void clickedFallEnableEdit(ActionEvent event) {
  142. editFall();
  143. }
  144. @FXML
  145. void clickedFallCancel(ActionEvent event) {
  146. if (fallProperty.get() != null) {
  147. fallProperty.get().setStorniert(true);
  148. try {
  149. DBHandler.setFall(fallProperty.get(), mainController.getCurrentMitarbeiter().getMitarbID(), true);
  150. } catch (Exception e) {
  151. e.printStackTrace();
  152. }
  153. mainController.refreshCasesFromDb(mainController.getPatientTablesController().getSelectedPatient());
  154. }
  155. }
  156. @FXML
  157. void clickedFallAbort(ActionEvent event) {
  158. this.state.set(State.VIEW);
  159. copyFallDataIntoField(fallProperty.get());
  160. }
  161. @FXML
  162. void clickedFallSave(ActionEvent event) {
  163. if (this.state.get() == State.CREATE) {
  164. Fall fall = new Fall();
  165. copyFieldDataIntoFall(fall);
  166. try {
  167. DBHandler.setFall(fall, mainController.getCurrentMitarbeiter().getMitarbID());
  168. } catch (SQLException e) {
  169. e.printStackTrace();
  170. }
  171. } else {
  172. copyFieldDataIntoFall(fallProperty.get());
  173. try {
  174. DBHandler.setFall(fallProperty.get(), mainController.getCurrentMitarbeiter().getMitarbID(), true);
  175. } catch (SQLException e) {
  176. e.printStackTrace();
  177. }
  178. }
  179. this.state.set(State.VIEW);
  180. mainController.refreshCasesFromDb(mainController.getPatientTablesController().getSelectedPatient());
  181. }
  182. public void createNewFall() {
  183. clearFields();
  184. this.state.set(State.CREATE);
  185. Patient patient = mainController.getPatientTablesController().getSelectedPatient();
  186. // Kasse by Default auf die im Patienten hinterlegten Kasse setzen.
  187. for (Kasse kasse : fallKasse.getItems()) {
  188. if (kasse.getKassenID() == patient.getKassenID()) {
  189. fallKasse.getSelectionModel().select(kasse);
  190. break;
  191. }
  192. }
  193. fallVersichertennummer.setText(patient.getVersichertennummer());
  194. }
  195. private void clearFields(){
  196. if(state.get() == State.CREATE) {
  197. dtTmAufnahme.setToCurrentDateTime();
  198. dtTmEntlassung.setToCurrentDateTime();
  199. }else{
  200. dtTmAufnahme.setDateTime(null);
  201. dtTmEntlassung.setDateTime(null);
  202. }
  203. fallPatID.setText(""); //TODO
  204. fallCreateTime.setText("");
  205. fallCreator.setText("");
  206. fallEditTime.setText("");
  207. fallEditor.setText("");
  208. fallEinweisenderArzt.setText("");
  209. fallSelbsteinweisung.setSelected(false);
  210. fallVersichertennummer.setText("");
  211. fallKasse.setValue(null);
  212. fallHauptdiagnose.setValue(null);
  213. fallHauptdiagnose.setItems(null);
  214. fallFallart.setValue(null);
  215. }
  216. private void copyFieldDataIntoFall(Fall fall){
  217. fall.setPatient(mainController.getPatientTablesController().getSelectedPatient());
  218. fall.setAufnahmeDatum(dtTmAufnahme.getDateTime());
  219. fall.setEntlassungsDatum(dtTmEntlassung.getDateTime());
  220. if(fallSelbsteinweisung.isSelected()) {
  221. fall.setSelbsteinweisung(true);
  222. fall.setEinweisenderArzt(null);
  223. }else{
  224. fall.setEinweisenderArzt(fallEinweisenderArzt.getText());
  225. fall.setSelbsteinweisung(false);
  226. }
  227. fall.setVersichertenNummer(fallVersichertennummer.getText());
  228. fall.setKasse(fallKasse.getValue());
  229. fall.setFallArt(fallFallart.getValue());
  230. if (fallHauptdiagnose.getSelectionModel().getSelectedItem() != null) {
  231. fall.setHauptdiagnoseId(fallHauptdiagnose.getSelectionModel().getSelectedItem().getDiagID());
  232. }
  233. //fall.setVorstellDatum(); //TODO
  234. }
  235. private void copyFallDataIntoField(Fall fall){
  236. if(fall==null){
  237. System.out.println("copyFallDataIntoFiled - Fall ist null");
  238. clearFields();
  239. return;
  240. }
  241. dtTmAufnahme.setDateTime(fall.getAufnahmeDatum());
  242. dtTmEntlassung.setDateTime(fall.getEntlassungsDatum());
  243. fallPatID.setText(fallProperty.get().getPatient() + ""); //(fall.getPatient().getVorname()+" "+fall.getPatient().getNachname()); //TODO
  244. fallCreateTime.setText(fall.getErstellDatumZeit() !=null ? fall.getErstellDatumZeit().toString():"");
  245. fallCreator.setText(Integer.toString(fall.getErsteller()));
  246. fallEditTime.setText(fall.getBearbeitetDatumZeit()!=null? fall.getBearbeitetDatumZeit().toString():"");
  247. fallEditor.setText(Integer.toString(fall.getBearbeiter()));
  248. fallEinweisenderArzt.setText(fall.getEinweisenderArzt());
  249. fallSelbsteinweisung.setSelected(fall.getSelbsteinweisung());
  250. fallVersichertennummer.setText(fall.getVersichertenNummer());
  251. fallKasse.setValue(fall.getKasse());
  252. if (fallHauptdiagnose.getItems() != null) {
  253. for (Diagnose diagnose : fallHauptdiagnose.getItems()) {
  254. if (diagnose.getDiagID() == fall.getHauptdiagnoseId()) {
  255. fallHauptdiagnose.setValue(diagnose);
  256. return;
  257. }
  258. }
  259. }
  260. //fallHauptdiagnose.setValue(fall.getHauptDiagnose()); TODO
  261. // fallHauptdiagnose.setItems(fall.getD); TODO
  262. fallFallart.setValue(fall.getFallArt());
  263. }
  264. public enum State {
  265. CREATE, EDIT, VIEW
  266. }
  267. }