001 package com.bea.medrec.actions;
002
003 import com.bea.medrec.beans.PatientBean;
004 import com.bea.medrec.utils.ClientException;
005 import com.bea.medrec.utils.MedRecLog4jFactory;
006 import com.bea.medrec.value.Mail;
007 import java.util.HashMap;
008 import java.util.Map;
009 import javax.servlet.http.HttpServletRequest;
010 import javax.servlet.http.HttpServletResponse;
011 import org.apache.log4j.Logger;
012 import org.apache.struts.action.ActionForm;
013 import org.apache.struts.action.ActionForward;
014 import org.apache.struts.action.ActionMapping;
015
016 /**
017 * <p>Patient registration approval controller.
018 * Handles requests to approve a patient registration.</p>
019 *
020 * @author Copyright (c) 2006 by BEA Systems. All Rights Reserved.
021 */
022 public class ApprovePatientRequestAction extends AdminBaseLookupDispatchAction {
023 private static Logger logger =
024 MedRecLog4jFactory.getLogger(ApprovePatientRequestAction.class.getName());
025
026 /**
027 * <p>Determines method calling based on select submit button.</p>
028 */
029 protected Map getKeyMethodMap() {
030 Map<String,String> map = new HashMap<String,String>();
031 map.put("button.Approve", "approve");
032 map.put("button.Deny", "deny");
033 map.put("button.Cancel", "cancel");
034 return map;
035 }
036
037 /**
038 * <p>Default action method.</p>
039 *
040 * @return ActionForward
041 */
042 public ActionForward defaultMethod(ActionMapping mapping,
043 ActionForm form,
044 HttpServletRequest request,
045 HttpServletResponse response)
046 throws Exception
047 {
048 return mapping.findForward("patient.approval.success");
049 }
050
051 /**
052 * <p>User selected patient approve button.</p>
053 *
054 * @return ActionForward
055 */
056 public ActionForward approve(ActionMapping mapping,
057 ActionForm form,
058 HttpServletRequest request,
059 HttpServletResponse response)
060 throws ClientException, Exception
061 {
062 // Declare and initialize local variables.
063 Mail mail = null;
064 PatientBean patient =
065 (PatientBean)getSessionAttribute(request, "patientBean");
066 try {
067 mail = composeMail(patient.getEmail(), "account.approved.subject",
068 "account.approved.message", request);
069 getAdminSession().activateAccountStatus(patient.getEmail(), mail);
070 } catch (Exception e) {
071 throwClientException(e, mapping, "patient.approval.failure");
072 }
073 return mapping.findForward("patient.approval.success");
074 }
075
076 /**
077 * <p>User selected cancel button.</p>
078 *
079 * @return ActionForward
080 */
081 public ActionForward cancel(ActionMapping mapping,
082 ActionForm form,
083 HttpServletRequest request,
084 HttpServletResponse response)
085 throws Exception
086 {
087 logger.info("Cancel approve patient registration.");
088 ActionForward forward = null;
089 try {
090 forward = (mapping.findForward("patient.approval.success"));
091 }
092 catch(Exception e) {
093 return handleException(e, request, mapping);
094 }
095 return forward;
096 }
097
098 /**
099 * <p>User selected patient deny button.</p>
100 *
101 * @return ActionForward
102 */
103 public ActionForward deny(ActionMapping mapping,
104 ActionForm form,
105 HttpServletRequest request,
106 HttpServletResponse response)
107 throws ClientException, Exception
108 {
109 Mail mail = null;
110 PatientBean patient =
111 (PatientBean)getSessionAttribute(request, "patientBean");
112 try {
113 mail = composeMail(patient.getEmail(), "account.denied.subject",
114 "account.denied.message", request);
115 getAdminSession().denyAccountStatus(patient.getEmail(), mail);
116 } catch(Exception e) {
117 throwClientException(e, mapping, "patient.approval.failure");
118 }
119 return mapping.findForward("patient.approval.success");
120 }
121
122 /**
123 * <p>Composes localized mail message with given mail attributes.</p>
124 */
125 private Mail composeMail(String email,
126 String subject,
127 String msg,
128 HttpServletRequest request)
129 throws Exception
130 {
131 Mail mail = null;
132
133 // Compose mail message.
134 mail = new Mail();
135 mail.setTo(email);
136 mail.setSubject(getMessage(request, subject));
137 mail.setMessage(getMessage(request, msg));
138 return mail;
139 }
140 }
|