From aaff15ede790a17b190ec565319e6cd3496bc7fc Mon Sep 17 00:00:00 2001 From: Jonas Hinterdorfer Date: Tue, 11 Mar 2025 15:04:11 +0100 Subject: [PATCH] added error messages --- .../controller/MedicalPracticeController.java | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/at/ionas999/health/controller/MedicalPracticeController.java b/src/main/java/at/ionas999/health/controller/MedicalPracticeController.java index 3c3e233..47cf348 100644 --- a/src/main/java/at/ionas999/health/controller/MedicalPracticeController.java +++ b/src/main/java/at/ionas999/health/controller/MedicalPracticeController.java @@ -43,13 +43,40 @@ public class MedicalPracticeController implements ChangeObserver { @FXML public void addPatient() { - waitingRoom.addPatient(name.getText(), - date.getValue().atTime(Integer.parseInt(time.getText().split(":")[0]), - Integer.parseInt(time.getText().split(":")[1])), - emergency.isSelected()); + + String name = this.name.getText(); + String time = this.time.getText(); + boolean emergency = this.emergency.isSelected(); + + + if(name.isEmpty() || !time.contains(":") || date.getValue() == null) + { + throwAlert("Please fill in all fields"); + return; + } + + int hour = Integer.parseInt(time.split(":")[0]); + int minute = Integer.parseInt(time.split(":")[1]); + + if(hour < 0 || hour > 23 || minute < 0 || minute > 59) + { + throwAlert("Invalid time"); + return; + } + + waitingRoom.addPatient(name, date.getValue().atTime(hour, minute), emergency); } public void nextPatient(ActionEvent actionEvent) { waitingRoom.treatNextPatient(); } + + private void throwAlert(String message) + { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Error"); + alert.setHeaderText("Error"); + alert.setContentText(message); + alert.showAndWait(); + } }