@RequestMapping("/edit-appointment")
  public String editAppointment(
      int id,
      String dateMonth,
      String dateDay,
      String dateYear,
      String dateHour,
      String dateMinute,
      String purpose,
      String doctorName,
      String patientName,
      HttpSession session)
      throws Exception {

    if (session.getAttribute("username") == null) {
      throw new Exception("not logged in");
    }
    Appointment appointment = appointments.findOne(id);
    appointment.patientName = patientName;
    appointment.doctorName = doctorName;
    appointment.purpose = purpose;
    appointment.dateMonth = dateMonth;
    appointment.dateDay = dateDay;
    appointment.dateYear = dateYear;
    appointment.dateHour = dateHour;
    appointment.dateMinute = dateMinute;
    appointments.save(appointment);

    return "redirect:/";
  }
  @PostConstruct
  public void init() throws InvalidKeySpecException, NoSuchAlgorithmException {
    if (users.count() == 0) {
      User user = new User("admin", PasswordHash.createHash("admin"));
      users.save(user);
    }

    if (appointments.count() == 0) {
      User user = users.findOneByUsername("admin");
      appointments.save(
          new Appointment(user, "12", "14", "2015", "00", "00", "Headache", "House", "Holden"));
    }
  }
  @RequestMapping("/add-appointment")
  public String addAppointment(
      String dateMonth,
      String dateDay,
      String dateYear,
      String dateHour,
      String dateMinute,
      String purpose,
      String doctorName,
      String patientName,
      HttpSession session)
      throws Exception {

    if (session.getAttribute("username") == null) {
      throw new Exception("not logged in");
    }
    String username = (String) session.getAttribute("username");
    User user = users.findOneByUsername(username);
    Appointment appointment = new Appointment();
    appointment.patientName = patientName;
    appointment.doctorName = doctorName;
    appointment.purpose = purpose;
    appointment.dateMonth = dateMonth;
    appointment.dateDay = dateDay;
    appointment.dateYear = dateYear;
    appointment.dateHour = dateHour;
    appointment.dateMinute = dateMinute;
    if (purpose == null) {
      throw new Exception("Must submit purpose");
    } else if (doctorName == null) {
      throw new Exception("Must submit doctor name");
    } else if (patientName == null) {
      throw new Exception("Must submit patient name");
    } else {
      appointments.save(appointment);
    }
    return "redirect:/";
  }