001 package com.bea.medrec.actions;
002
003 import com.bea.medrec.beans.PatientBean;
004 import com.bea.medrec.beans.RegistrationBean;
005 import com.bea.medrec.utils.ClientException;
006 import com.bea.medrec.utils.MedRecLog4jFactory;
007 import com.bea.medrec.utils.MedRecWebAppUtils;
008 import java.util.HashMap;
009 import java.util.Map;
010 import javax.servlet.http.HttpServletRequest;
011 import javax.servlet.http.HttpServletResponse;
012 import org.apache.log4j.Logger;
013 import org.apache.struts.action.ActionForm;
014 import org.apache.struts.action.ActionForward;
015 import org.apache.struts.action.ActionMapping;
016
017 /**
018 * <p>Handles all request during the registration process.</p<
019 *
020 * @author Copyright (c) 2005 by BEA Systems. All Rights Reserved.
021 */
022 public class RegisterAction extends PatientBaseLookupDispatchAction {
023
024 private static Logger logger =
025 MedRecLog4jFactory.getLogger(RegisterAction.class.getName());
026
027 /**
028 * <p>Mapping of action to method.</p>
029 *
030 * @return Map
031 */
032 protected Map getKeyMethodMap() {
033 Map<String,String> map = new HashMap<String,String>();
034 map.put("button.Cancel", "cancel");
035 map.put("button.Register", "register");
036 return map;
037 }
038
039 /**
040 * <p>Default behavior.</p>
041 *
042 * @return ActionForward
043 */
044 public ActionForward defaultMethod(ActionMapping mapping,
045 ActionForm form,
046 HttpServletRequest request,
047 HttpServletResponse response)
048 throws Exception {
049 // First time thru.
050 logger.debug("Default method executions.");
051 setupLocale(request);
052 return mapping.findForward("register.home");
053 }
054
055 /**
056 * <p>Cancel edit patient profile.</p>
057 *
058 * @return ActionForward
059 */
060 public ActionForward cancel(ActionMapping mapping,
061 ActionForm form,
062 HttpServletRequest request,
063 HttpServletResponse response)
064 throws Exception {
065 logger.info("Cancel registration.");
066 ActionForward forward = null;
067 try {
068 form.reset(mapping, request);
069 // Return to MedRec start page.
070 forward = new ActionForward("medrec.startpage", true);
071 } catch (Exception e) {
072 return handleException(e, request, mapping);
073 }
074 return forward;
075 }
076
077 /**
078 * <p>Register new patient user.</p>
079 *
080 * @return ActionForward
081 */
082 public ActionForward register(ActionMapping mapping,
083 ActionForm form,
084 HttpServletRequest request,
085 HttpServletResponse response)
086 throws ClientException, Exception {
087 logger.info("New user registration.");
088 RegistrationBean registrationBean = (RegistrationBean) form;
089 PatientBean patientBean = registrationBean.getPatientBean();
090
091 // The email address is the username.
092 patientBean.setEmail(registrationBean.getUserBean().getUsername());
093
094
095 try {
096 // Send registration to be processed.
097 getAdminSession().processRegistration(registrationBean.toRegistration());
098 } catch (Exception e) {
099 throwClientException(e, mapping, "validate.registration.failure");
100 }
101 return mapping.findForward("register.success");
102 }
103 }
|