|
@ -1692,82 +1692,122 @@ public class SignPatientLabelInfoService extends BaseService {
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONArray searchTeamsPatients(String filter, long teamCode, int page, int pagesize) throws Exception {
|
|
|
JSONArray reArray = new JSONArray();
|
|
|
Map<String, JSONArray> map = new HashMap<>();
|
|
|
Map<Long, AdminTeam> teamMap = new HashMap<>();
|
|
|
List<AdminTeam> teams = null;
|
|
|
int start = page * pagesize;
|
|
|
int size = pagesize;
|
|
|
teams = new ArrayList<>();
|
|
|
AdminTeam teamTemp = adminTeamService.getTeam(teamCode);
|
|
|
if (teamTemp == null) {
|
|
|
throw new Exception("adminTeam is not exist");
|
|
|
}
|
|
|
teams.add(teamTemp);
|
|
|
Map<String, JSONObject> result = new HashMap<>();
|
|
|
List<Map<String, Object>> signList = new ArrayList<>();
|
|
|
page = page * pagesize;
|
|
|
Object[] args = new Object[]{teamCode, "%" + filter + "%"};
|
|
|
|
|
|
String sql = "select distinct t.* from (" +
|
|
|
" select " +
|
|
|
" f.patient " +
|
|
|
" ,f.name " +
|
|
|
" ,f.openid " +
|
|
|
" ,f.admin_team_code " +
|
|
|
" ,p.sex " +
|
|
|
" ,p.idcard " +
|
|
|
" ,p.photo " +
|
|
|
" from " +
|
|
|
" wlyy_sign_family f,wlyy_patient p " +
|
|
|
" where " +
|
|
|
" f.patient = p.code and f.admin_team_code = ? and f.status > 0 and f.name like ? ) t "
|
|
|
+ (page < 0 ? "" : "limit " + start + "," + size);
|
|
|
String sqlTemp = "select " +
|
|
|
" DISTINCT t1.* " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family t1 " +
|
|
|
" WHERE " +
|
|
|
" t1.status > 0 " +
|
|
|
" AND t1.admin_team_code = ? " +
|
|
|
" AND t1.name like ? ";
|
|
|
|
|
|
if (teams != null) {
|
|
|
for (AdminTeam team : teams) {
|
|
|
teamMap.put(team.getId(), team);
|
|
|
List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{team.getId(),
|
|
|
"%" + filter + "%"});
|
|
|
String sql = sqlTemp + " limit " + page + "," + pagesize;
|
|
|
signList = jdbcTemplate.queryForList(sql, args);
|
|
|
|
|
|
if (result != null && result.size() > 0) {
|
|
|
for (Map<String, Object> p : result) {
|
|
|
JSONObject pJson = new JSONObject();
|
|
|
if (signList != null && signList.size() > 0) {
|
|
|
for (Map<String, Object> sign : signList) {
|
|
|
Patient p = patientDao.findByCode(sign.get("patient") == null ? "" : sign.get("patient").toString());
|
|
|
|
|
|
pJson.put("code", p.get("patient"));
|
|
|
pJson.put("name", p.get("name") != null ? p.get("name") : "");
|
|
|
pJson.put("openid", p.get("openid") != null ? p.get("openid") : "");
|
|
|
pJson.put("adminTeamCode", p.get("admin_team_code") != null ? p.get("admin_team_code") : "");
|
|
|
pJson.put("sex", p.get("sex") != null ? p.get("sex") : "");
|
|
|
pJson.put("age", p.get("idcard") != null ? IdCardUtil.getAgeForIdcard(String.valueOf(p.get("idcard"))) : "");
|
|
|
pJson.put("photo", p.get("photo") != null ? p.get("photo") : "");
|
|
|
if (p == null) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
List<SignPatientLabelInfo> labels = labelInfoDao.findByPatientAndStatus(String.valueOf(p.get("patient")), 1);
|
|
|
pJson.put("labels", labels == null ? "" : labels);
|
|
|
if (result.containsKey(p.getCode())) {
|
|
|
JSONObject jsonP = result.get(p.getCode());
|
|
|
|
|
|
if (map.containsKey(String.valueOf(p.get("admin_team_code")))) {
|
|
|
JSONArray array = map.get(String.valueOf(p.get("admin_team_code")));
|
|
|
array.put(pJson);
|
|
|
} else {
|
|
|
JSONArray array = new JSONArray();
|
|
|
array.put(pJson);
|
|
|
map.put(String.valueOf(p.get("admin_team_code")), array);
|
|
|
if (!String.valueOf(jsonP.get("signType")).equals(String.valueOf(sign.get("type")))) {
|
|
|
jsonP.put("signType", 3);
|
|
|
}
|
|
|
if (String.valueOf(sign.get("type")).equals("2")) {
|
|
|
jsonP.put("qyrq", sign.get("apply_date") != null ? DateUtil.dateToStr((Date) sign.get("apply_date"), DateUtil.YYYY_MM_DD) : "");
|
|
|
// 缴费情况
|
|
|
jsonP.put("expensesStatus", sign.get("expenses_status") != null ? String.valueOf(sign.get("expenses_status")) : "0");
|
|
|
// 缴费时间
|
|
|
jsonP.put("expensesTime", sign.get("expenses_time") != null ? DateUtil.dateToStr((Date) sign.get("expenses_time"), DateUtil.YYYY_MM_DD_HH_MM) : "");
|
|
|
// 缴费类型
|
|
|
jsonP.put("expensesType", sign.get("expenses_type") != null ? String.valueOf(sign.get("expenses_type")) : "");
|
|
|
if (StringUtils.isEmpty(String.valueOf(jsonP.get("expensesStatus"))) || String.valueOf(jsonP.get("expensesStatus")).equals("0")) {
|
|
|
String epTime = redisTemplate.opsForValue().get("expenses:remind:" + p.getCode());
|
|
|
|
|
|
if (StringUtils.isEmpty(epTime)) {
|
|
|
jsonP.put("expensesRemindStatus", 0);
|
|
|
} else {
|
|
|
jsonP.put("expensesRemindStatus", new SimpleDateFormat("yyyy-MM-dd").format(new Date()).equals(epTime) ? 1 : 0);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (map != null && map.size() > 0) {
|
|
|
for (String key : map.keySet()) {
|
|
|
AdminTeam team = teamMap.get(Long.valueOf(key));
|
|
|
JSONObject tJson = new JSONObject();
|
|
|
List<SignPatientLabelInfo> labels = labelInfoDao.findByPatientAndStatus(sign.get("patient").toString(), 1);
|
|
|
|
|
|
tJson.put("teamCode", team.getId());
|
|
|
tJson.put("teamName", team.getName());
|
|
|
tJson.put("patients", map.get(key));
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
|
|
reArray.put(tJson);
|
|
|
// 设置患者标识
|
|
|
json.put("code", p.getCode());
|
|
|
// 设置患者姓名
|
|
|
json.put("name", p.getName());
|
|
|
// 设置患者手机号
|
|
|
json.put("mobile", p.getMobile());
|
|
|
// 设置患者微信openid
|
|
|
json.put("openid", StringUtils.isNotEmpty(p.getOpenid()) ? p.getOpenid() : "");
|
|
|
// 设置患者联系电话
|
|
|
json.put("phone", p.getPhone());
|
|
|
// 设置患者紧急联系人
|
|
|
json.put("emerMobile", sign.get("emer_mobile") == null ? "" : String.valueOf(sign.get("emer_mobile")));
|
|
|
// 设置患者头像
|
|
|
json.put("photo", p.getPhoto());
|
|
|
// 设置患者年龄
|
|
|
json.put("age", DateUtil.getAgeByBirthday(p.getBirthday()));
|
|
|
// 设置患者性别
|
|
|
json.put("sex", p.getSex());
|
|
|
// 设置签约日期
|
|
|
json.put("qyrq", sign.get("apply_date") != null ? DateUtil.dateToStr((Date) sign.get("apply_date"), DateUtil.YYYY_MM_DD) : "");
|
|
|
// 设置签约类型
|
|
|
json.put("signType", sign.get("type") == null ? "" : sign.get("type"));
|
|
|
// 身份证号
|
|
|
json.put("idcard", p.getIdcard());
|
|
|
// 社保号
|
|
|
json.put("ssc", p.getSsc());
|
|
|
if (String.valueOf(sign.get("type")).equals("2")) {
|
|
|
// 缴费情况
|
|
|
json.put("expensesStatus", sign.get("expenses_status") != null ? String.valueOf(sign.get("expenses_status")) : "0");
|
|
|
// 缴费时间
|
|
|
json.put("expensesTime", sign.get("expenses_time") != null ? DateUtil.dateToStr((Date) sign.get("expenses_time"), DateUtil.YYYY_MM_DD_HH_MM) : "");
|
|
|
// 缴费类型
|
|
|
json.put("expensesType", sign.get("expenses_type") != null ? String.valueOf(sign.get("expenses_type")) : "");
|
|
|
|
|
|
if (StringUtils.isEmpty(String.valueOf(json.get("expensesStatus"))) || String.valueOf(json.get("expensesStatus")).equals("0")) {
|
|
|
String epTime = "";
|
|
|
try {
|
|
|
epTime = redisTemplate.opsForValue().get("expenses:remind:" + p.getCode());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
if (StringUtils.isEmpty(epTime)) {
|
|
|
json.put("expensesRemindStatus", 0);
|
|
|
} else {
|
|
|
json.put("expensesRemindStatus", new SimpleDateFormat("yyyy-MM-dd").format(new Date()).equals(epTime) ? 1 : 0);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
// 缴费情况
|
|
|
json.put("expensesStatus", "1");
|
|
|
}
|
|
|
// 患者标签
|
|
|
json.put("labels", labels == null ? "" : labels);
|
|
|
|
|
|
result.put(p.getCode(), json);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return reArray;
|
|
|
return result.size() > 0 ? new JSONArray(result.values()) : new JSONArray();
|
|
|
}
|
|
|
|
|
|
|