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.

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