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.RecordsSummary;
007 import javax.servlet.http.HttpServletRequest;
008 import javax.servlet.http.HttpServletResponse;
009 import org.apache.log4j.Logger;
010 import org.apache.struts.action.ActionForm;
011 import org.apache.struts.action.ActionForward;
012 import org.apache.struts.action.ActionMapping;
013
014 /**
015 * <p>Retrieves all records for a patient. Records are returned
016 * in abbreviated form in order to display a summary of
017 * each record.</p>
018 *
019 * @author Copyright (c) 2006 by BEA Systems. All Rights Reserved.
020 */
021 public class PhysViewRecordsSummaryAction extends PhysBaseAction {
022
023 private static Logger logger =
024 MedRecLog4jFactory.getLogger(PhysViewRecordsSummaryAction.class.getName());
025
026 /**
027 * <p>Process the specified HTTP request, and create the corresponding HTTP
028 * response (or forward to another web component that will create it).
029 * Return an <code>ActionForward</code> instance describing where and how
030 * control should be forwarded.
031 * <br>
032 * Retrieves a patients entire medical record history.
033 * Information includes summarized views of records and prescriptions.
034 * </p>
035 *
036 * @param mapping The ActionMapping used to select this instance
037 * @param form The optional ActionForm bean for this request (if any)
038 * @param request The HTTP request we are processing
039 * @param response The HTTP response we are creating
040 */
041 public ActionForward executeAction(ActionMapping mapping,
042 ActionForm form,
043 HttpServletRequest request,
044 HttpServletResponse response)
045 throws ClientException, Exception {
046 // Minimal check for valid session.
047 //super.checkSession(request, mapping);
048
049 String nextPage = "view.records.summary";
050 String requestPatId = (String) request.getParameter("id");
051 PatientBean sessionPatient = (PatientBean) super.getSessionAttribute(request,
052 PATIENT_BEAN);
053 // Check for existing patient on session.
054 if (sessionPatient != null) {
055 // Check to see if request patient is the same as existing patient.
056 if (requestPatId != null && !sessionPatient.getId().equals(requestPatId)) {
057 // New patient selected from results page.
058 nextPage = "search.results";
059 } else {
060 logger.debug("Selected patient: "+sessionPatient.toString());
061 try {
062 // Get records summary for existing patient.
063 getMedicalRecords(request, sessionPatient.getId());
064 } catch (Exception e) {
065 throwClientException(e, mapping, "search.results");
066 }
067 }
068 } else if (requestPatId != null) {
069 // First time thru with selected patient from search results.
070 PatientBean[] patientBeans = (PatientBean[]) super.getSessionAttribute(
071 request, PATIENT_BEANS);
072 if (patientBeans == null) {
073 logger.info("Recreating results from previous search.");
074 nextPage = "search.results";
075 } else {
076 logger.info("Setting selected patient on session.");
077 PatientBean patient = findPatientInArray(requestPatId, patientBeans);
078 super.setSessionAttribute(request, PATIENT_BEAN, patient);
079 // This removed all search results from
080 // session after a resultant has been choosen.
081 super.removeSessionAttribute(request, PATIENT_BEANS);
082 getMedicalRecords(request, requestPatId);
083 }
084 }
085
086 logger.debug("Redirecting to "+nextPage);
087 return mapping.findForward(nextPage);
088 }
089
090 /**
091 * Retrieves medical record summary fro a given patient id.
092 */
093 private void getMedicalRecords(HttpServletRequest request, String patId)
094 throws Exception {
095 logger.info("Getting patient's medical record summary.");
096 logger.debug("Patient id = "+patId);
097 RecordsSummary recordsSummary =
098 getPhysicianSession().getRecordsSummary(Integer.valueOf(patId));
099 logger.debug("Found records: "+recordsSummary.toString());
100 logger.debug("Setting recordBeans on request");
101 request.setAttribute(RECORD_BEANS,
102 toBeanArray(recordsSummary.getRecords(),
103 com.bea.medrec.beans.RecordBean.class));
104 logger.debug("Setting prescriptionBeans on request");
105 request.setAttribute(PRESCRIPTION_BEANS,
106 toBeanArray(recordsSummary.getPrescriptions(),
107 com.bea.medrec.beans.PrescriptionBean.class));
108 }
109
110 /**
111 * User selects a patient from the search results collection. This
112 * method retrieves that patient from the collection.
113 */
114 private PatientBean findPatientInArray(String pPatientId,
115 PatientBean[] pPatientBeans) {
116 logger.info("Finding patient in session patient collection.");
117 logger.debug("PatId to find: "+pPatientId);
118 // declare local variables
119 PatientBean patientBean = null;
120
121 for (int i = 0; i < pPatientBeans.length; i++) {
122 patientBean = pPatientBeans[i];
123 logger.debug("Found PatId: "+patientBean.getId());
124 if (patientBean.getId().equals(pPatientId))
125 break;
126 }
127 return patientBean;
128 }
129
130 }
|