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
package edu.ncsu.csc.itrust.action;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import edu.ncsu.csc.itrust.beans.CustomComparator;
import edu.ncsu.csc.itrust.beans.HospitalBean;
import edu.ncsu.csc.itrust.beans.PersonnelBean;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.HospitalsDAO;
import edu.ncsu.csc.itrust.dao.mysql.PersonnelDAO;
import edu.ncsu.csc.itrust.exception.DBException;
/**
* Action class to find experts based on the distance from the user and type of expert.
*
*/
public class FindExpertAction {
/**
* HospitalDAO to grab hospitals from
*/
HospitalsDAO hospitalsDAO;
/**
* PersonnelDAO to find experts from
*/
PersonnelDAO personnelDAO;
/**
* Constructor simply is used to initialize the DAOs
* @param factory used to initialize DAOs
*/
public FindExpertAction(DAOFactory factory){
hospitalsDAO = new HospitalsDAO(factory);
personnelDAO = new PersonnelDAO(factory);
}
/**
*
* Main method used to find the hospitals and all specified personnel within range
*
* @param distance The maximum distance that a hospital must be within range in order for it to return
* @param specialty The specialty that the user is interested in
* @param patientZip Zipcode entered by the patient
* @param zipRange The range to search hospitals for. The amount of zipcode digits to match, starting with the first digit.
* @return A relationship between hospitals within the defined proximity and the specified experts at the hospital.
*/
public HashMap<HospitalBean, List<PersonnelBean>> findHospitalsBySpecialty(String specialty, String patientZip, int zipRange){
HashMap<HospitalBean, List<PersonnelBean>> experts = null;
try {
//Grab all hospitals and filter them based on distance
List<HospitalBean> hospitals = filterHospitals(hospitalsDAO.getAllHospitals(), patientZip, zipRange);
//Find experts in hospitals
experts = findExperts(hospitals, specialty);
} catch (DBException e) {
//
}
return experts;
}
/**
* Method used to find experts of specified specialty from hospitals that are in range
* @param hospitals The hospitals within the proximity of the user
* @param specialty The expertise specified
* @return A relationship between the hospitals within proximity and the personnel with the specified expertise within them.
*/
public HashMap<HospitalBean, List<PersonnelBean>> findExperts(List<HospitalBean> hospitals, String specialty){
HashMap<HospitalBean, List<PersonnelBean>> experts = new HashMap<HospitalBean, List<PersonnelBean>>();
try{
//Go through all nearby hospitals
for(HospitalBean hospital : hospitals){
//Put the specified experts into a hashmap with the hospital
experts.put(hospital, personnelDAO.getPersonnelFromHospital(hospital.getHospitalID(), specialty));
}
} catch (DBException e){
//
}
return experts;
}
/**
* Method used to find experts of specified specialty from hospitals that are in range
* @param hospitals The hospitals within the proximity of the user
* @param specialty The expertise specified
* @return A relationship between the hospitals within proximity and the personnel with the specified expertise within them.
*/
public List<PersonnelBean> findExpertsForLocalHospitals(List<HospitalBean> hospitals, String specialty){
List<PersonnelBean> beans = new ArrayList<PersonnelBean>();
boolean searchForAll;
searchForAll = specialty.equalsIgnoreCase("all");
if (searchForAll) {
}
try{
//Go through all nearby hospitals
for(HospitalBean hospital : hospitals){
//Put the specified experts into a hashmap with the hospital
//experts.put(hospital, personnelDAO.getPersonnelFromHospital(hospital.getHospitalID(), specialty));
List<PersonnelBean> personnelBeans = personnelDAO.getPersonnelFromHospital(hospital.getHospitalID(), specialty);
for (PersonnelBean personnelBean : personnelBeans) {
beans.add(personnelBean);
}
}
} catch (DBException e){
e.printStackTrace();
}
Collections.sort(beans, new CustomComparator());
return beans;
}
public List<HospitalBean> findHospitalsAssignedToHCP(long pid) throws SQLException
{
return hospitalsDAO.getHospitalsAssignedToPhysician(pid);
}
/**
* Filters hospitals down to just the hospitals in the specified range of the user
* @param hospitals Hospitals to filter
* @param patientZip Zipcode entered by the patient
* @param zipRange The range to search hospitals for. The amount of zipcode digits to match, starting with the first digit.
* @return All hospitals within the specified range of the user
*/
public List<HospitalBean> filterHospitals(List<HospitalBean> hospitals, String patientZip, int zipRange){
List<HospitalBean> inRange = new ArrayList<HospitalBean>();
for (int i = 0; i < hospitals.size(); i++) {
try {
//A hospital is in range if its zipcode matches the user entered one from the first number to the zipRangeth number
if (hospitals.get(i).getHospitalZip().substring(0, zipRange).equals(patientZip.substring(0, zipRange)))
inRange.add(hospitals.get(i));
} catch (NullPointerException e1) {
//Examine next hospital if current has null zipcode entry
} catch (IndexOutOfBoundsException e2) {
//If the hospital's zip code is not at least 5 digits long, examine next hospital
}
}
return inRange;
}
}