diff --git a/src/main/java/de/uniluebeck/mi/projmi6/controller/FallController.java b/src/main/java/de/uniluebeck/mi/projmi6/controller/FallController.java index de8ca95..a819c45 100644 --- a/src/main/java/de/uniluebeck/mi/projmi6/controller/FallController.java +++ b/src/main/java/de/uniluebeck/mi/projmi6/controller/FallController.java @@ -24,84 +24,119 @@ import java.sql.SQLException; public class FallController { - SimpleObjectProperty state = new SimpleObjectProperty<>(State.VIEW); - @FXML - Button btnFallSendHl7; private MainController mainController; @FXML private DateTimePicker dtTmAufnahme, dtTmEntlassung; @FXML - private Label fallPatID; + private Label fallId; @FXML private ComboBox fallFallart; @FXML private ComboBox fallKasse; @FXML - private TextField fallVersichertennummer; - @FXML - private TextField fallEinweisenderArzt; + private TextField fallVersichertennummer, fallEinweisenderArzt; @FXML private CheckBox fallSelbsteinweisung; @FXML private ComboBox fallHauptdiagnose; @FXML - private Label fallCreator; - @FXML - private Label fallEditor; - @FXML - private Label fallCreateTime; - @FXML - private Label fallEditTime; - @FXML - private Button btnFallSave; + private Label fallCreator, fallEditor, fallCreateTime, fallEditTime; @FXML - private Button btnFallAbort; - @FXML - private Button btnFallCancel; - @FXML - private Button btnFallEnableEdit; + private Button btnFallSave, btnFallAbort, btnFallCancel, btnFallEnableEdit, btnFallSendHl7; @FXML private GridPane fallFields; - private SimpleObjectProperty fallProperty = new SimpleObjectProperty<>(); + /** + * A property to the case which data this controller manages. + */ + private final SimpleObjectProperty fallProperty = new SimpleObjectProperty<>(); + + /** + * Controllers current state. + */ + private final SimpleObjectProperty state = new SimpleObjectProperty<>(State.VIEW); + + + /** + * Contstructor. + * @param mainController The main controller that creats this instance + */ public FallController(MainController mainController) { this.mainController = mainController; } + + /** + * Getter for the {@link #fallProperty()} + */ public Fall getFall() { return fallProperty.get(); } + /** + * Setter for the {@link #fallProperty()} + * @param fall + */ public void setFall(Fall fall) { this.fallProperty.set(fall); } - public SimpleObjectProperty fallPropertyProperty() { + /** + * The case that is shown in this controller. + */ + public SimpleObjectProperty fallProperty() { return fallProperty; } + /** + * State definitions. + */ + public enum State { + CREATE, EDIT, VIEW + } + + /** + * Getter for the {@link #stateProperty()}. + */ public State getState() { return state.get(); } + /** + * The controllers current state. + */ public ReadOnlyObjectProperty stateProperty() { return state; } + /** + * For showing the main diagnosis, the Controller also needs a pointer to the list of case diagnosis. + * @return + */ public ObjectProperty> diagnosenProperty() { return fallHauptdiagnose.itemsProperty(); } + /** + * Getter for the {@link #diagnosenProperty()} + */ public ObservableList getDiagnosen() { return fallHauptdiagnose.getItems(); } + /** + * Setter for the diagnosis in the main diagnosis combo box. + * @see #diagnosenProperty() + */ public void setDiagnosen(ObservableList list) { fallHauptdiagnose.setItems(list); } + /** + * FXMLLoaders initialize()-method. + */ @FXML - public void initialize() { + private void initialize() { fallEinweisenderArzt.disableProperty().bind(fallSelbsteinweisung.selectedProperty()); fallFallart.setItems(FXCollections.observableArrayList(FallArt.values())); fallKasse.setItems(mainController.getStammdaten().getKassen()); @@ -110,13 +145,13 @@ public class FallController { initButtons(); fallFields.disableProperty().bind(state.isEqualTo(State.VIEW)); - fallProperty.addListener(((observable, oldValue, newValue) -> { if (state.get() == State.VIEW) { copyFallDataIntoField(fallProperty.get()); } })); + fallHauptdiagnose.itemsProperty().addListener((observable1, oldValue1, newValue1) -> { copyHauptdiagnoseToComboBox(fallProperty.get()); }); @@ -160,6 +195,10 @@ public class FallController { btnFallSendHl7.visibleProperty().bind(btnFallSendHl7.managedProperty()); } + + /** + * EventHandler for the {@link #btnFallSendHl7} button. + */ @FXML private void clickedSendHl7() { /* Natascha */ @@ -175,17 +214,27 @@ public class FallController { } } + /** + * Toggle controller state to edit + */ public void editFall() { this.state.set(State.EDIT); } + /** + * EventHandler for {@link #btnFallEnableEdit} + */ @FXML - void clickedFallEnableEdit(ActionEvent event) { + private void clickedFallEnableEdit() { editFall(); } + + /** + * EventHandler for the {@link #btnFallCancel}. + */ @FXML - void clickedFallCancel(ActionEvent event) { + private void clickedFallCancel() { if (fallProperty.get() != null) { fallProperty.get().setStorniert(true); try { @@ -197,22 +246,34 @@ public class FallController { } } + /** + * EventHandler for the {@link #btnFallAbort} + */ @FXML - void clickedFallAbort(ActionEvent event) { + private void clickedFallAbort() { this.state.set(State.VIEW); copyFallDataIntoField(fallProperty.get()); } + + /** + * EventHandler for the {@link #btnFallSave} button. + */ @FXML - void clickedFallSave(ActionEvent event) { + private void clickedFallSave() { if (this.state.get() == State.CREATE) { Fall fall = new Fall(); copyFieldDataIntoFall(fall); try { int newfallid = DBHandler.setFall(fall, mainController.getCurrentMitarbeiter().getMitarbID()); fall.setFallID(newfallid); + + } catch (SQLException e) { + e.printStackTrace(); + } + try { HL7Sender.createMessageADT_A01(fall); - } catch (SQLException | HL7Exception | IOException e) { + }catch(IOException | HL7Exception | SQLException e){ e.printStackTrace(); } } else { @@ -229,6 +290,9 @@ public class FallController { mainController.refreshCasesFromDb(mainController.getPatientTablesController().getSelectedPatient()); } + /** + * Change the controllers state, init the fields for assistance. + */ public void createNewFall() { clearFields(); this.state.set(State.CREATE); @@ -245,6 +309,10 @@ public class FallController { fallVersichertennummer.setText(patient.getVersichertennummer()); } + + /** + * Clears the TextFields. + */ private void clearFields() { if (state.get() == State.CREATE) { dtTmAufnahme.setToCurrentDateTime(); @@ -254,7 +322,7 @@ public class FallController { dtTmEntlassung.setDateTime(null); } - fallPatID.setText(""); //TODO + fallId.setText(""); fallCreateTime.setText(""); fallCreator.setText(""); @@ -273,6 +341,10 @@ public class FallController { fallFallart.setValue(null); } + /** + * Copy the text entered in the views into a Fall object. + * @param fall The object for copying the data into. + */ private void copyFieldDataIntoFall(Fall fall) { fall.setPatient(mainController.getPatientTablesController().getSelectedPatient()); fall.setAufnahmeDatum(dtTmAufnahme.getDateTime()); @@ -293,12 +365,15 @@ public class FallController { } - //fall.setVorstellDatum(); //TODO + //fall.setVorstellDatum(); } + /** + * Set the field values in the view to the value of the {@link Fall} object. + * @param fall The object whose data will be copied. + */ private void copyFallDataIntoField(Fall fall) { if (fall == null) { - System.out.println("copyFallDataIntoFiled - Fall ist null"); clearFields(); return; } @@ -306,13 +381,15 @@ public class FallController { dtTmAufnahme.setDateTime(fall.getAufnahmeDatum()); dtTmEntlassung.setDateTime(fall.getEntlassungsDatum()); - fallPatID.setText(fallProperty.get().getPatient() + ""); //(fall.getPatient().getVorname()+" "+fall.getPatient().getNachname()); //TODO + fallId.setText(fall.getFallID() + ""); //(fall.getPatient().getVorname()+" "+fall.getPatient().getNachname()); //TODO fallCreateTime.setText(fall.getErstellDatumZeit() != null ? fall.getErstellDatumZeit().toString() : ""); fallCreator.setText(Integer.toString(fall.getErsteller())); fallEditTime.setText(fall.getBearbeitetDatumZeit() != null ? fall.getBearbeitetDatumZeit().toString() : ""); fallEditor.setText(Integer.toString(fall.getBearbeiter())); + + fallEinweisenderArzt.setText(fall.getEinweisenderArzt()); fallSelbsteinweisung.setSelected(fall.getSelbsteinweisung()); @@ -324,27 +401,27 @@ public class FallController { fallFallart.setValue(fall.getFallArt()); } + + /** + * This method sets the main diagnosis in the ComboBox + * @param fall The case whose main diagnosis will be picked + */ private void copyHauptdiagnoseToComboBox(Fall fall) { if (fallHauptdiagnose.getItems() == null || fall == null) { fallHauptdiagnose.setValue(null); return; } - System.out.println("Suche Diagnose..."); for (Diagnose diagnose : fallHauptdiagnose.getItems()) { System.out.println(diagnose.getDiagID() + "=" + fall.getHauptdiagnoseId()); if (diagnose.getDiagID() == fall.getHauptdiagnoseId()) { fallHauptdiagnose.getSelectionModel().select(diagnose); - System.out.println("Diagnose wiedergefunden!!"); return; } } } - public enum State { - CREATE, EDIT, VIEW - } } diff --git a/src/main/java/de/uniluebeck/mi/projmi6/controller/MainController.java b/src/main/java/de/uniluebeck/mi/projmi6/controller/MainController.java index f135a59..147456f 100644 --- a/src/main/java/de/uniluebeck/mi/projmi6/controller/MainController.java +++ b/src/main/java/de/uniluebeck/mi/projmi6/controller/MainController.java @@ -248,7 +248,7 @@ public class MainController { lvFall.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); - fallController.fallPropertyProperty().bind(lvFall.getSelectionModel().selectedItemProperty()); + fallController.fallProperty().bind(lvFall.getSelectionModel().selectedItemProperty()); lvFall.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> { diff --git a/src/main/resources/fall.fxml b/src/main/resources/fall.fxml index 953ccfa..52feeab 100644 --- a/src/main/resources/fall.fxml +++ b/src/main/resources/fall.fxml @@ -10,8 +10,8 @@ -