Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package edu.ncsu.csc.itrust.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import edu.ncsu.csc.itrust.ParameterUtil;
import edu.ncsu.csc.itrust.action.base.PatientBaseAction;
import edu.ncsu.csc.itrust.beans.OfficeVisitBean;
import edu.ncsu.csc.itrust.beans.PatientBean;
import edu.ncsu.csc.itrust.beans.PrescriptionReportBean;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.OfficeVisitDAO;
import edu.ncsu.csc.itrust.dao.mysql.PatientDAO;
import edu.ncsu.csc.itrust.dao.mysql.PrescriptionReportDAO;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.exception.NoHealthRecordsException;
import edu.ncsu.csc.itrust.exception.ITrustException;
/**
* Handles Prescription Reports for the given pid Used by hcp-uap/getPrescriptionReport.jsp,
* hcp-uap/viewPrescriptionRecord.jsp, patient/getMyPrescriptionReport.jsp, &
* patient/viewMyPrescriptionRecord.jsp
*
*
*/
public class PrescriptionReportAction extends PatientBaseAction {
private boolean isRepresenting = false;
private OfficeVisitDAO ovDAO;
private PrescriptionReportDAO prDAO;
private PatientDAO patientDAO;
private long loggedInMID;
/**
* Super class validates pidString
*
* @param factory The DAOFactory used to create the DAOs used in this action.
* @param loggedInMID The MID of the user who is making a prescription report.
* @param pidString The MID of the patient in question.
* @throws ITrustException
* @throws DBException
* @throws NoHealthRecordsException
*/
public PrescriptionReportAction(DAOFactory factory, long loggedInMID, String pidString)
throws ITrustException, DBException, NoHealthRecordsException {
super(factory, pidString);
this.ovDAO = factory.getOfficeVisitDAO();
this.patientDAO = factory.getPatientDAO();
this.prDAO = factory.getPrescriptionReportDAO();
this.loggedInMID = loggedInMID;
}
/**
* Takes the patient's representee as a param and returns it as a long if the patient represents the input
* param
*
* @param input
* the patient's representee mid
* @return representee's mid as a long
* @throws ITrustException
*/
public long representPatient(String input) throws ITrustException {
try {
long reppeeMID = Long.valueOf(input);
if (patientDAO.represents(loggedInMID, reppeeMID)) {
loggedInMID = reppeeMID;
pid = reppeeMID;
isRepresenting = true;
return reppeeMID;
} else
throw new ITrustException("You do not represent patient " + reppeeMID);
} catch (NumberFormatException e) {
throw new ITrustException("MID is not a number");
}
}
/**
* Returns a list of all office visits for the pid
*
* @return list of OfficeVisitBeans for the pid
* @throws DBException
*/
public List<OfficeVisitBean> getAllOfficeVisits() throws DBException {
return ovDAO.getAllOfficeVisits(pid);
}
/**
* Used by the JSP, passes a Map from the html form and a list of OfficeVisitBeans Returns a list of
* PrescriptionReportBeans
*
* @param params A java.util.HashMap containing the parameter map.
* @param officeVisits A java.util.List of OfficeVisitBeans for the visits.
* @return list of PrescriptionReportBeans
* @throws DBException
*/
public List<PrescriptionReportBean> getPrescriptionReports(Map<String, String> params, List<OfficeVisitBean> officeVisits)
throws DBException {
HashMap<String, String> myParams = ParameterUtil.convertMap(params);
List<Long> ovIDs = new ArrayList<Long>();
for (int i = 0; i < officeVisits.size(); i++) {
try {
if (params.get("ovOff" + i) != null) {
int offset = Integer.valueOf(myParams.get("ovOff" + i));
ovIDs.add(officeVisits.get(offset).getVisitID());
}
} catch (NumberFormatException e) {
// just skip it
}
}
if (ovIDs.size() == 0)
return new ArrayList<PrescriptionReportBean>();
return prDAO.byOfficeVisitAndPatient(ovIDs, pid);
}
/**
* Returns a PatientBean for the pid
*
* @return PatientBean
* @throws DBException
*/
public PatientBean getPatient() throws DBException {
return patientDAO.getPatient(pid);
}
/**
* Used by the JSP, which passes the param map from the html form and a list of OfficeVisitBeans Returns a
* string that will be used to create a new url. The JSP will pull params from this url to create the
* prescription report.
*
* @param paramMap A java.util.HashMap of the parameters.
* @param officeVisits A java.util.List of OfficeVisitBeans.
* @return the string that will be used in the new url
* @throws FormValidationException
* @throws DBException
*/
@SuppressWarnings("rawtypes")
public String getQueryString(Map paramMap, List<OfficeVisitBean> officeVisits)
throws FormValidationException, DBException {
HashMap<String, String> myParams = ParameterUtil.convertMap(paramMap);
List<Integer> ovOffsets = checkOfficeVisits(myParams, officeVisits);
String queryString = buildQueryString(ovOffsets);
if (isRepresenting)
queryString += "&rep=" + pid;
return queryString;
}
/**
* Checks office visits
*
* @param myParams list of parameters
* @param officeVisits list of office visits
* @return Returns a java.util.ArrayList of Integers for the given office visits.
*/
private ArrayList<Integer> checkOfficeVisits(HashMap<String, String> myParams,
List<OfficeVisitBean> officeVisits) {
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < officeVisits.size(); i++) {
if ("on".equals(myParams.get("ov" + i)))
list.add(i);
}
return list;
}
/**
* Builds a query string for office visits
*
* @param ovOffsets offsets for the office visits
* @return A SQL query in a Java String.
*/
private String buildQueryString(List<Integer> ovOffsets) {
int n = ovOffsets.size();
if (n == 0)
return "";
String str = "&n=" + n;
StringBuffer buf = new StringBuffer();
for (int i = 0; i < ovOffsets.size(); i++) {
buf.append("&ovOff" + i + "=" + ovOffsets.get(i));
}
str += buf.toString();
return str;
}
}