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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package edu.ncsu.csc.itrust.action;
import java.io.Serializable;
import java.util.*;
import edu.ncsu.csc.itrust.beans.DiagnosisBean;
import edu.ncsu.csc.itrust.beans.HCPDiagnosisBean;
import edu.ncsu.csc.itrust.beans.OfficeVisitBean;
import edu.ncsu.csc.itrust.beans.PrescriptionBean;
import edu.ncsu.csc.itrust.beans.MedicationBean;
import edu.ncsu.csc.itrust.beans.SurveyBean;
import edu.ncsu.csc.itrust.beans.LabProcedureBean;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.PatientDAO;
import edu.ncsu.csc.itrust.dao.mysql.PrescriptionsDAO;
import edu.ncsu.csc.itrust.dao.mysql.OfficeVisitDAO;
import edu.ncsu.csc.itrust.dao.mysql.SurveyDAO;
import edu.ncsu.csc.itrust.dao.mysql.PersonnelDAO;
import edu.ncsu.csc.itrust.dao.mysql.LabProcedureDAO;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.ITrustException;
/**
* Edits the privacy levels of diagnoses, used by myDiagnoses.jsp
*
*
*/
public class MyDiagnosisAction {
private OfficeVisitDAO officeVisitDAO;
private PatientDAO patientDAO;
private PersonnelDAO personnelDAO;
private SurveyDAO surveyDAO;
private LabProcedureDAO labprocDAO;
private PrescriptionsDAO prescriptionsDAO;
private long loggedInMID;
/**
* Set up for defaults
*
* @param factory The DAOFactory used to create the DAOs used in this action.
* @param loggedInMID The MID of the user who is looking at their diagnoses.
* @throws ITrustException
*/
public MyDiagnosisAction(DAOFactory factory, long loggedInMID) throws ITrustException {
this.loggedInMID = loggedInMID;
this.patientDAO = factory.getPatientDAO();
this.officeVisitDAO = factory.getOfficeVisitDAO();
this.personnelDAO = factory.getPersonnelDAO();
this.surveyDAO = factory.getSurveyDAO();
this.labprocDAO = factory.getLabProcedureDAO();
this.prescriptionsDAO = factory.getPrescriptionsDAO();
}
/**
* Returns a list of DiagnosisBeans for the patient
*
* @return the list of DiagnosisBeans
* @throws DBException
*/
public List<DiagnosisBean> getDiagnoses() throws DBException {
return patientDAO.getDiagnoses(loggedInMID);
}
/**
* Returns a list of all the HCPs who have a particular diagnosis
*
* @param icdcode the diagnosis of interest
* @return the list of HCPs
* @throws DBException
*/
public List<HCPDiagnosisBean> getHCPByDiagnosis(String icdcode) throws DBException {
int medMatch = 0;
HashMap<Long, HCPDiagnosisBean> hcpHash = new HashMap<Long, HCPDiagnosisBean>();
HashMap<Long, Long> patientHash = new HashMap<Long, Long>();
HCPDiagnosisBean diag = null;
List<OfficeVisitBean> beans = officeVisitDAO.getAllOfficeVisitsForDiagnosis(icdcode);
for (OfficeVisitBean bean: beans) {
// check for HCP-Patient locality based on first 3 digits in ZIP
if (!patientDAO.getPatient(loggedInMID).getZip().substring(0, 2).equals(personnelDAO.getPersonnel(bean.getHcpID()).getZip().substring(0, 2)))
continue;
// Check to see if we already have a bean for the HCP associated with this visit
if (hcpHash.containsKey(bean.getHcpID())) {
diag = hcpHash.get(bean.getHcpID());
// get all prescriptions associated with an office visit
List<PrescriptionBean> prescriptions = prescriptionsDAO.getList(bean.getID());
for (PrescriptionBean p: prescriptions) {
List<MedicationBean> mlist = diag.getMedList();
for (MedicationBean b: mlist) {
if (p.getMedication().getDescription().equals(b.getDescription()))
medMatch++;
}
if (medMatch == 0) {
mlist.add(p.getMedication());
diag.setMedList(mlist);
}
else {
medMatch = 0;
}
}
// Get Lab Procedures
List<LabProcedureBean> labprocs = diag.getLabList();
List<LabProcedureBean> lpbeans = labprocDAO.getAllLabProceduresForDocOV(bean.getVisitID());
for (LabProcedureBean p: lpbeans) {
labprocs.add(p);
}
diag.setLabList(labprocs);
if (surveyDAO.isSurveyCompleted(bean.getVisitID())) {
SurveyBean survey = surveyDAO.getSurveyData(bean.getVisitID());
diag.setVisitSat(survey.getVisitSatisfaction());
diag.setTreatmentSat(survey.getTreatmentSatisfaction());
}
// Check if this patient has been seen multiple times for this diagnosis
if (!patientHash.containsKey(bean.getPatientID())) {
patientHash.put(bean.getPatientID(), bean.getHcpID());
diag.incNumPatients();
}
}
else {
diag = new HCPDiagnosisBean();
List<MedicationBean> mlist = new ArrayList<MedicationBean>();
diag.setHCP(bean.getHcpID());
try {
diag.setHCPName(personnelDAO.getName(bean.getHcpID()));
} catch (ITrustException e) {
diag.setHCPName("null");
}
diag.incNumPatients();
List<PrescriptionBean> prescriptions = prescriptionsDAO.getList(bean.getID());
for (PrescriptionBean p: prescriptions) {
mlist.add(p.getMedication());
}
diag.setMedList(mlist);
diag.setLabList(labprocDAO.getAllLabProceduresForDocOV(bean.getVisitID()));
if (surveyDAO.isSurveyCompleted(bean.getVisitID())) {
SurveyBean survey = surveyDAO.getSurveyData(bean.getVisitID());
diag.setVisitSat(survey.getVisitSatisfaction());
diag.setTreatmentSat(survey.getTreatmentSatisfaction());
}
patientHash.put(bean.getPatientID(), bean.getHcpID());
hcpHash.put(bean.getHcpID(), diag);
}
}
List<HCPDiagnosisBean> list = new ArrayList<HCPDiagnosisBean>(hcpHash.values());
Collections.sort(list, new HCPDiagnosisBeanComparator() );
return list;
}
/**
* Looks up all the prescriptions given by a certain HCP with the same ICD code.
* @param hcpid The MID of the HCP
* @param icdcode The ICD code of the prescription we are looking up.
* @return A java.util.List of PrescriptionBeans made by this HCP of this ICD code.
* @throws DBException
*/
public List<PrescriptionBean> getPrescriptionsByHCPAndICD(long hcpid, String icdcode) throws DBException {
List<PrescriptionBean> list = new ArrayList<PrescriptionBean>();
List<OfficeVisitBean> ovs = officeVisitDAO.getAllOfficeVisitsForDiagnosis(icdcode);
for (int i = 0; i < ovs.size(); i++) {
if (ovs.get(i).getHcpID() == hcpid) {
long ovid = ovs.get(i).getID();
List<PrescriptionBean> prescriptions = prescriptionsDAO.getList(ovid);
list.addAll(prescriptions);
}
}
return list;
}
/**
* Checks to see what HCP has had the most experience with a diagnosis
*
*/
public static class HCPDiagnosisBeanComparator implements Comparator<HCPDiagnosisBean>, Serializable {
private static final long serialVersionUID = -6328390386684022934L;
/**
* Compares one HCP with another
*
* @param a the first HCP
* @param b the second HCP
* @return -1 if a has had more patients, 1 if b has had more patients; otherwise 0
*/
public int compare(HCPDiagnosisBean a, HCPDiagnosisBean b) {
int ret = 0;
if (a.getNumPatients() > b.getNumPatients())
ret = -1;
else if (a.getNumPatients() < b.getNumPatients())
ret = 1;
return ret;
}
}
}