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.

420 lines
13 KiB

  1. package de.uniluebeck.mi.projmi6.controller;
  2. /**
  3. * Created by 631806 on 12.11.15.
  4. */
  5. import ca.uhn.hl7v2.HL7Exception;
  6. import de.uniluebeck.mi.projmi6.db.DBHandler;
  7. import de.uniluebeck.mi.projmi6.hapi.HL7Sender;
  8. import de.uniluebeck.mi.projmi6.model.*;
  9. import de.uniluebeck.mi.projmi6.view.DateTimePicker;
  10. import javafx.beans.property.ObjectProperty;
  11. import javafx.beans.property.ReadOnlyObjectProperty;
  12. import javafx.beans.property.SimpleObjectProperty;
  13. import javafx.collections.FXCollections;
  14. import javafx.collections.ObservableList;
  15. import javafx.fxml.FXML;
  16. import javafx.scene.control.*;
  17. import javafx.scene.layout.GridPane;
  18. import java.io.IOException;
  19. import java.sql.SQLException;
  20. public class FallController {
  21. /**
  22. * A property to the case which data this controller manages.
  23. */
  24. private final SimpleObjectProperty<Fall> fallProperty = new SimpleObjectProperty<>();
  25. /**
  26. * Controllers current state.
  27. */
  28. private final SimpleObjectProperty<State> state = new SimpleObjectProperty<>(State.VIEW);
  29. private MainController mainController;
  30. @FXML
  31. private DateTimePicker dtTmAufnahme, dtTmEntlassung;
  32. @FXML
  33. private Label fallId;
  34. @FXML
  35. private ComboBox<FallArt> fallFallart;
  36. @FXML
  37. private ComboBox<Kasse> fallKasse;
  38. @FXML
  39. private TextField fallVersichertennummer, fallEinweisenderArzt;
  40. @FXML
  41. private CheckBox fallSelbsteinweisung;
  42. @FXML
  43. private ComboBox<Diagnose> fallHauptdiagnose;
  44. @FXML
  45. private Label fallCreator, fallEditor, fallCreateTime, fallEditTime;
  46. @FXML
  47. private Button btnFallSave, btnFallAbort, btnFallCancel, btnFallEnableEdit, btnFallSendHl7;
  48. @FXML
  49. private GridPane fallFields;
  50. /**
  51. * Contstructor.
  52. * @param mainController The main controller that creats this instance
  53. */
  54. public FallController(MainController mainController) {
  55. this.mainController = mainController;
  56. }
  57. /**
  58. * Getter for the {@link #fallProperty()}
  59. */
  60. public Fall getFall() {
  61. return fallProperty.get();
  62. }
  63. /**
  64. * Setter for the {@link #fallProperty()}
  65. * @param fall
  66. */
  67. public void setFall(Fall fall) {
  68. this.fallProperty.set(fall);
  69. }
  70. /**
  71. * The case that is shown in this controller.
  72. */
  73. public SimpleObjectProperty<Fall> fallProperty() {
  74. return fallProperty;
  75. }
  76. /**
  77. * Getter for the {@link #stateProperty()}.
  78. */
  79. public State getState() {
  80. return state.get();
  81. }
  82. /**
  83. * The controllers current state.
  84. */
  85. public ReadOnlyObjectProperty<State> stateProperty() {
  86. return state;
  87. }
  88. /**
  89. * For showing the main diagnosis, the Controller also needs a pointer to the list of case diagnosis.
  90. * @return
  91. */
  92. public ObjectProperty<ObservableList<Diagnose>> diagnosenProperty() {
  93. return fallHauptdiagnose.itemsProperty();
  94. }
  95. /**
  96. * Getter for the {@link #diagnosenProperty()}
  97. */
  98. public ObservableList<Diagnose> getDiagnosen() {
  99. return fallHauptdiagnose.getItems();
  100. }
  101. /**
  102. * Setter for the diagnosis in the main diagnosis combo box.
  103. * @see #diagnosenProperty()
  104. */
  105. public void setDiagnosen(ObservableList<Diagnose> list) {
  106. fallHauptdiagnose.setItems(list);
  107. }
  108. /**
  109. * FXMLLoaders initialize()-method.
  110. */
  111. @FXML
  112. private void initialize() {
  113. fallEinweisenderArzt.disableProperty().bind(fallSelbsteinweisung.selectedProperty());
  114. fallFallart.setItems(FXCollections.observableArrayList(FallArt.values()));
  115. fallKasse.setItems(mainController.getStammdaten().getKassen());
  116. initButtons();
  117. fallFields.disableProperty().bind(state.isEqualTo(State.VIEW));
  118. fallProperty.addListener(((observable, oldValue, newValue) -> {
  119. if (state.get() == State.VIEW) {
  120. copyFallDataIntoField(fallProperty.get());
  121. }
  122. }));
  123. fallHauptdiagnose.itemsProperty().addListener((observable1, oldValue1, newValue1) -> {
  124. copyHauptdiagnoseToComboBox(fallProperty.get());
  125. });
  126. state.addListener((observable, oldValue, newValue) -> {
  127. if (newValue == State.EDIT || newValue == State.CREATE) {
  128. mainController.lockForEdit(MainController.TabName.OVERVIEW);
  129. } else {
  130. mainController.unlockFromEdit();
  131. }
  132. });
  133. }
  134. /**
  135. * Hide the buttons depending on controller state.
  136. */
  137. private void initButtons() {
  138. btnFallEnableEdit.managedProperty().bind(
  139. state.isEqualTo(State.VIEW).and(fallProperty.isNotNull())
  140. );
  141. btnFallEnableEdit.visibleProperty().bind(btnFallEnableEdit.managedProperty());
  142. btnFallAbort.managedProperty().bind(
  143. state.isNotEqualTo(State.VIEW)
  144. );
  145. btnFallAbort.visibleProperty().bind(btnFallAbort.managedProperty());
  146. btnFallSave.managedProperty().bind(
  147. state.isNotEqualTo(State.VIEW)
  148. );
  149. btnFallSave.visibleProperty().bind(btnFallSave.managedProperty());
  150. btnFallCancel.managedProperty().bind(
  151. state.isEqualTo(State.VIEW).and(fallProperty.isNotNull())
  152. );
  153. btnFallCancel.visibleProperty().bind(btnFallCancel.managedProperty());
  154. btnFallSendHl7.managedProperty().bind(
  155. state.isEqualTo(State.VIEW).and(fallProperty.isNotNull())
  156. );
  157. btnFallSendHl7.visibleProperty().bind(btnFallSendHl7.managedProperty());
  158. }
  159. /**
  160. * EventHandler for the {@link #btnFallSendHl7} button.
  161. */
  162. @FXML
  163. private void clickedSendHl7() {
  164. /* Natascha */
  165. //TODO send funny message
  166. Patient patient = mainController.getPatientTablesController().getSelectedPatient();
  167. Fall fall = fallProperty.get();
  168. fall.setPatient(patient);
  169. try {
  170. HL7Sender.createMessageADT_A01(fall);
  171. } catch (HL7Exception | IOException | SQLException e) {
  172. e.printStackTrace();
  173. }
  174. }
  175. /**
  176. * Toggle controller state to edit
  177. */
  178. public void editFall() {
  179. this.state.set(State.EDIT);
  180. }
  181. /**
  182. * EventHandler for {@link #btnFallEnableEdit}
  183. */
  184. @FXML
  185. private void clickedFallEnableEdit() {
  186. editFall();
  187. }
  188. /**
  189. * EventHandler for the {@link #btnFallCancel}.
  190. */
  191. @FXML
  192. private void clickedFallCancel() {
  193. if (fallProperty.get() != null) {
  194. fallProperty.get().setStorniert(true);
  195. try {
  196. DBHandler.setFall(fallProperty.get(), mainController.getCurrentMitarbeiter().getMitarbID(), true);
  197. } catch (Exception e) {
  198. e.printStackTrace();
  199. }
  200. mainController.refreshCasesFromDb(mainController.getPatientTablesController().getSelectedPatient());
  201. }
  202. }
  203. /**
  204. * EventHandler for the {@link #btnFallAbort}
  205. */
  206. @FXML
  207. private void clickedFallAbort() {
  208. this.state.set(State.VIEW);
  209. copyFallDataIntoField(fallProperty.get());
  210. }
  211. /**
  212. * EventHandler for the {@link #btnFallSave} button.
  213. */
  214. @FXML
  215. private void clickedFallSave() {
  216. if (this.state.get() == State.CREATE) {
  217. Fall fall = new Fall();
  218. copyFieldDataIntoFall(fall);
  219. try {
  220. int newfallid = DBHandler.setFall(fall, mainController.getCurrentMitarbeiter().getMitarbID());
  221. fall.setFallID(newfallid);
  222. } catch (SQLException e) {
  223. e.printStackTrace();
  224. }
  225. try {
  226. HL7Sender.createMessageADT_A01(fall);
  227. } catch (IOException | HL7Exception | SQLException e) {
  228. e.printStackTrace();
  229. }
  230. } else {
  231. copyFieldDataIntoFall(fallProperty.get());
  232. try {
  233. DBHandler.setFall(fallProperty.get(), mainController.getCurrentMitarbeiter().getMitarbID(), true);
  234. } catch (SQLException e) {
  235. e.printStackTrace();
  236. }
  237. }
  238. this.state.set(State.VIEW);
  239. mainController.refreshCasesFromDb(mainController.getPatientTablesController().getSelectedPatient());
  240. }
  241. /**
  242. * Change the controllers state, init the fields for assistance.
  243. */
  244. public void createNewFall() {
  245. clearFields();
  246. this.state.set(State.CREATE);
  247. Patient patient = mainController.getPatientTablesController().getSelectedPatient();
  248. // Kasse by Default auf die im Patienten hinterlegten Kasse setzen.
  249. for (Kasse kasse : fallKasse.getItems()) {
  250. if (kasse.getKassenID() == patient.getKassenID()) {
  251. fallKasse.getSelectionModel().select(kasse);
  252. break;
  253. }
  254. }
  255. fallVersichertennummer.setText(patient.getVersichertennummer());
  256. }
  257. /**
  258. * Clears the TextFields.
  259. */
  260. private void clearFields() {
  261. if (state.get() == State.CREATE) {
  262. dtTmAufnahme.setToCurrentDateTime();
  263. dtTmEntlassung.setToCurrentDateTime();
  264. } else {
  265. dtTmAufnahme.setDateTime(null);
  266. dtTmEntlassung.setDateTime(null);
  267. }
  268. fallId.setText("");
  269. fallCreateTime.setText("");
  270. fallCreator.setText("");
  271. fallEditTime.setText("");
  272. fallEditor.setText("");
  273. fallEinweisenderArzt.setText("");
  274. fallSelbsteinweisung.setSelected(false);
  275. fallVersichertennummer.setText("");
  276. fallKasse.setValue(null);
  277. fallHauptdiagnose.setValue(null);
  278. fallHauptdiagnose.setItems(null);
  279. fallFallart.setValue(null);
  280. }
  281. /**
  282. * Copy the text entered in the views into a Fall object.
  283. * @param fall The object for copying the data into.
  284. */
  285. private void copyFieldDataIntoFall(Fall fall) {
  286. fall.setPatient(mainController.getPatientTablesController().getSelectedPatient());
  287. fall.setAufnahmeDatum(dtTmAufnahme.getDateTime());
  288. fall.setEntlassungsDatum(dtTmEntlassung.getDateTime());
  289. if (fallSelbsteinweisung.isSelected()) {
  290. fall.setSelbsteinweisung(true);
  291. fall.setEinweisenderArzt(null);
  292. } else {
  293. fall.setEinweisenderArzt(fallEinweisenderArzt.getText());
  294. fall.setSelbsteinweisung(false);
  295. }
  296. fall.setVersichertenNummer(fallVersichertennummer.getText());
  297. fall.setKasse(fallKasse.getValue());
  298. fall.setFallArt(fallFallart.getValue());
  299. if (fallHauptdiagnose.getSelectionModel().getSelectedItem() != null) {
  300. fall.setHauptdiagnoseId(fallHauptdiagnose.getSelectionModel().getSelectedItem().getDiagID());
  301. }
  302. //fall.setVorstellDatum();
  303. }
  304. /**
  305. * Set the field values in the view to the value of the {@link Fall} object.
  306. * @param fall The object whose data will be copied.
  307. */
  308. private void copyFallDataIntoField(Fall fall) {
  309. if (fall == null) {
  310. clearFields();
  311. return;
  312. }
  313. dtTmAufnahme.setDateTime(fall.getAufnahmeDatum());
  314. dtTmEntlassung.setDateTime(fall.getEntlassungsDatum());
  315. fallId.setText(fall.getFallID() + ""); //(fall.getPatient().getVorname()+" "+fall.getPatient().getNachname()); //TODO
  316. fallCreateTime.setText(fall.getErstellDatumZeit() != null ? fall.getErstellDatumZeit().toString() : "");
  317. fallCreator.setText(Integer.toString(fall.getErsteller()));
  318. fallEditTime.setText(fall.getBearbeitetDatumZeit() != null ? fall.getBearbeitetDatumZeit().toString() : "");
  319. fallEditor.setText(Integer.toString(fall.getBearbeiter()));
  320. fallEinweisenderArzt.setText(fall.getEinweisenderArzt());
  321. fallSelbsteinweisung.setSelected(fall.getSelbsteinweisung());
  322. fallVersichertennummer.setText(fall.getVersichertenNummer());
  323. fallKasse.setValue(fall.getKasse());
  324. copyHauptdiagnoseToComboBox(fall);
  325. fallFallart.setValue(fall.getFallArt());
  326. }
  327. /**
  328. * This method sets the main diagnosis in the ComboBox
  329. * @param fall The case whose main diagnosis will be picked
  330. */
  331. private void copyHauptdiagnoseToComboBox(Fall fall) {
  332. if (fallHauptdiagnose.getItems() == null
  333. || fall == null) {
  334. fallHauptdiagnose.setValue(null);
  335. return;
  336. }
  337. for (Diagnose diagnose : fallHauptdiagnose.getItems()) {
  338. System.out.println(diagnose.getDiagID() + "=" + fall.getHauptdiagnoseId());
  339. if (diagnose.getDiagID().equalsIgnoreCase(fall.getHauptdiagnoseId())) {
  340. fallHauptdiagnose.getSelectionModel().select(diagnose);
  341. return;
  342. }
  343. }
  344. }
  345. /**
  346. * State definitions.
  347. */
  348. public enum State {
  349. CREATE, EDIT, VIEW
  350. }
  351. }