Advertisement
Guest User

Untitled

a guest
Dec 11th, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. * http://license.openmrs.org
  6. *
  7. * Software distributed under the License is distributed on an "AS IS"
  8. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9. * License for the specific language governing rights and limitations
  10. * under the License.
  11. *
  12. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  13. */
  14. package org.openmrs.module.appointment.web.controller;
  15.  
  16. import java.util.Date;
  17. import java.util.List;
  18. import java.util.Set;
  19.  
  20. import javax.servlet.http.HttpServletRequest;
  21. import javax.servlet.http.HttpSession;
  22.  
  23. import org.apache.commons.logging.Log;
  24. import org.apache.commons.logging.LogFactory;
  25. import org.openmrs.Location;
  26. import org.openmrs.Provider;
  27. import org.openmrs.api.context.Context;
  28. import org.openmrs.module.appointment.Appointment;
  29. import org.openmrs.module.appointment.AppointmentType;
  30. import org.openmrs.module.appointment.TimeSlot;
  31. import org.openmrs.module.appointment.api.AppointmentService;
  32. import org.openmrs.module.appointment.validator.AppointmentValidator;
  33. import org.openmrs.module.appointment.web.TimeSlotEditor;
  34. import org.openmrs.web.WebConstants;
  35. import org.springframework.stereotype.Controller;
  36. import org.springframework.validation.BindingResult;
  37. import org.springframework.web.bind.WebDataBinder;
  38. import org.springframework.web.bind.annotation.InitBinder;
  39. import org.springframework.web.bind.annotation.ModelAttribute;
  40. import org.springframework.web.bind.annotation.RequestMapping;
  41. import org.springframework.web.bind.annotation.RequestMethod;
  42. import org.springframework.web.bind.annotation.RequestParam;
  43.  
  44. /**
  45. * Controller for creating appointments.
  46. */
  47. @Controller
  48. public class AppointmentFormController {
  49.  
  50. /** Logger for this class and subclasses */
  51. protected final Log log = LogFactory.getLog(getClass());
  52.  
  53. @InitBinder
  54. public void initBinder(WebDataBinder binder) {
  55. binder.registerCustomEditor(TimeSlot.class, new TimeSlotEditor());
  56. }
  57.  
  58. @ModelAttribute("appointmentTypeList")
  59. public Set<AppointmentType> getAppointmentTypeList() {
  60. return Context.getService(AppointmentService.class).getAllAppointmentTypes();
  61. }
  62.  
  63. @ModelAttribute("providerList")
  64. public List<Provider> getProviderList() {
  65. return Context.getProviderService().getAllProviders();
  66. }
  67.  
  68. @ModelAttribute("availableTimes")
  69. public List<TimeSlot> getAvailableTimes(@RequestParam(value = "fromDate", required = false) Date fromDate,
  70. @RequestParam(value = "toDate", required = false) Date toDate,
  71. @RequestParam(value = "location", required = false) Location location) {
  72.  
  73. return Context.getService(AppointmentService.class).getAllTimeSlots();
  74. }
  75.  
  76. @ModelAttribute("appointment")
  77. public Appointment getAppointment(@RequestParam(value = "appointmentId", required = false) Integer appointmentId) {
  78. Appointment appointment = null;
  79.  
  80. if (Context.isAuthenticated()) {
  81. AppointmentService as = Context.getService(AppointmentService.class);
  82. if (appointmentId != null)
  83. appointment = as.getAppointment(appointmentId);
  84. }
  85.  
  86. if (appointment == null)
  87. appointment = new Appointment();
  88.  
  89. return appointment;
  90. }
  91.  
  92. @RequestMapping(value = "/module/appointment/appointmentForm", method = RequestMethod.GET)
  93. public void showForm() {
  94.  
  95. }
  96.  
  97. @RequestMapping(method = RequestMethod.POST)
  98. public String onSubmit(HttpServletRequest request, Appointment appointment, BindingResult result) throws Exception {
  99. HttpSession httpSession = request.getSession();
  100.  
  101. if (Context.isAuthenticated()) {
  102. AppointmentService appointmentService = Context.getService(AppointmentService.class);
  103.  
  104. if (request.getParameter("save") != null) {
  105. new AppointmentValidator().validate(appointment, result);
  106. }
  107. if (result.hasErrors())
  108. return null;
  109.  
  110. appointmentService.saveAppointment(appointment);
  111. httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "appointment.AppointmentType.saved");
  112. }
  113.  
  114. return null;
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement