added error messages

This commit is contained in:
Jonas Hinterdorfer 2025-03-11 15:04:11 +01:00
parent 4af661e44d
commit aaff15ede7

View File

@ -43,13 +43,40 @@ public class MedicalPracticeController implements ChangeObserver<WaitingRoom> {
@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();
}
}