|
@ -1,11 +1,19 @@
|
|
|
package com.yihu.wlyy.service.app.physicalExamination;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.entity.patient.PatientRemindRecords;
|
|
|
import com.yihu.wlyy.entity.patient.PatientTeamRemindRecord;
|
|
|
import com.yihu.wlyy.repository.doctor.DoctorDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientRemindRecordsDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientTeamRemindRecordDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.service.common.SMSService;
|
|
|
import com.yihu.wlyy.task.PushMsgTask;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
import com.yihu.wlyy.util.IdCardUtil;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@ -15,11 +23,14 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Created by Reece on 2017/10/19/019.
|
|
@ -41,6 +52,289 @@ public class PhysicalExaminationRemindService extends BaseService {
|
|
|
private WeiXinAccessTokenUtils accessTokenUtils;
|
|
|
@Autowired
|
|
|
private WeiXinOpenIdUtils openIdUtils;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private PatientRemindRecordsDao patientRemindRecordsDao;
|
|
|
@Autowired
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
@Autowired
|
|
|
private DoctorDao doctorDao;
|
|
|
@Autowired
|
|
|
private PatientTeamRemindRecordDao patientTeamRemindRecordDao;
|
|
|
|
|
|
/**
|
|
|
* 单个提醒居民按钮
|
|
|
* @param patient
|
|
|
* @param doctor
|
|
|
*/
|
|
|
public Integer singleRemindPhyExam(String patient,String doctor){
|
|
|
List<PatientRemindRecords> records = patientRemindRecordsDao.findByPatientAndType(patient,1);
|
|
|
if(records!=null&&records.size()>0){
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
Doctor d = doctorDao.findByCode(doctor);
|
|
|
try{
|
|
|
sendSingleNotice(patient,d.getName());
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
logger.error("体检提醒失败"+e.getMessage());
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 单个提醒居民按钮
|
|
|
* @param teamCode
|
|
|
* @param doctor
|
|
|
*/
|
|
|
public Integer remindPhyExams(Long teamCode,String doctor){
|
|
|
List<PatientTeamRemindRecord> records = patientTeamRemindRecordDao.findByAdminTeamCodeAndType(teamCode,1);
|
|
|
if(records!=null&&records.size()>0){
|
|
|
return -1;
|
|
|
}
|
|
|
PatientTeamRemindRecord record = new PatientTeamRemindRecord();
|
|
|
record.setType(1);
|
|
|
record.setCreateTime(new Date());
|
|
|
record.setStatus(0);
|
|
|
record.setAdminTeamCode(teamCode);
|
|
|
patientTeamRemindRecordDao.save(record);
|
|
|
|
|
|
Doctor d = doctorDao.findByCode(doctor);
|
|
|
try{
|
|
|
sendBatchNotice(teamCode,d.getName(),record.getId());
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
logger.error("批量体检提醒失败"+e.getMessage());
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 健康体检 是否显示批量提醒按钮
|
|
|
* @param teamCode
|
|
|
* @return
|
|
|
*/
|
|
|
public Integer isShowRemindBtns(long teamCode){
|
|
|
Integer re = 0;
|
|
|
List<Map<String, Object>> signList = new ArrayList<>();
|
|
|
String sql = "";
|
|
|
Object[] args = null;
|
|
|
|
|
|
sql = "SELECT " +
|
|
|
" DISTINCT t1.* " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family t1 " +
|
|
|
" WHERE " +
|
|
|
" t1.status > 0 " +
|
|
|
" AND t1.admin_team_code = ? " +
|
|
|
" AND (YEAR(curdate()) -IF(length(idcard) = 18,substring(idcard, 7, 4),IF(length(idcard) = 15,concat('19', substring(idcard, 7, 2)),NULL)))>65 " +
|
|
|
" AND t1.idcard not in " +
|
|
|
" (SELECT DISTINCT s.idcard " +
|
|
|
" from wlyy_sign_family s," +
|
|
|
" wlyy_old_people_physical_examination o" +
|
|
|
" WHERE s.admin_team_code=? and s.`status`>0 and s.idcard = o.id_card " +
|
|
|
" and o.medical_time>?)"+
|
|
|
" order by t1.openid desc,convert(t1.name using gbk) ";
|
|
|
|
|
|
args = new Object[]{teamCode,teamCode,DateUtil.getLastYear()};
|
|
|
signList = jdbcTemplate.queryForList(sql, args);
|
|
|
if (signList != null && signList.size() > 0) {
|
|
|
for (Map<String, Object> sign : signList) {
|
|
|
String patient = sign.get("patient") == null ? "" : sign.get("patient").toString();
|
|
|
if (StringUtils.isEmpty(patient)) {
|
|
|
continue;
|
|
|
}
|
|
|
List<PatientRemindRecords> records = patientRemindRecordsDao.findByPatientAndType(patient,1);
|
|
|
if(records==null||records.size()==0){
|
|
|
re = 1;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}else{
|
|
|
re = 1;
|
|
|
}
|
|
|
return re;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取65岁以上老年人1年内无体检记录列表
|
|
|
* @param teamCode
|
|
|
* @param page
|
|
|
* @param pagesize
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public JSONArray getOldPatientByTeamCode(long teamCode, int page, int pagesize) throws Exception {
|
|
|
|
|
|
Map<String, JSONObject> result = new TreeMap<>();
|
|
|
List<Map<String, Object>> signList = new ArrayList<>();
|
|
|
Map<String,Object> patientDeviceTypeMap = new HashMap<>();//用于存储患者设备绑定情况
|
|
|
int start = page * pagesize;
|
|
|
String sql = "";
|
|
|
Object[] args = null;
|
|
|
|
|
|
//标签类别为空的时候
|
|
|
sql = "SELECT " +
|
|
|
" DISTINCT t1.* " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family t1 " +
|
|
|
" WHERE " +
|
|
|
" t1.status > 0 " +
|
|
|
" AND t1.admin_team_code = ? " +
|
|
|
" AND (YEAR(curdate()) -IF(length(idcard) = 18,substring(idcard, 7, 4),IF(length(idcard) = 15,concat('19', substring(idcard, 7, 2)),NULL)))>65 " +
|
|
|
" AND t1.idcard not in " +
|
|
|
" (SELECT DISTINCT s.idcard " +
|
|
|
" from wlyy_sign_family s," +
|
|
|
" wlyy_old_people_physical_examination o" +
|
|
|
" WHERE s.admin_team_code=? and s.`status`>0 and s.idcard = o.id_card " +
|
|
|
" and o.medical_time>?)"+
|
|
|
" order by t1.openid desc,convert(t1.name using gbk) ";
|
|
|
|
|
|
args = new Object[]{teamCode,teamCode,DateUtil.getLastYear()};
|
|
|
|
|
|
sql = sql + " limit " + start + "," + pagesize;
|
|
|
signList = jdbcTemplate.queryForList(sql, args);
|
|
|
|
|
|
//查询患者设备绑定情况
|
|
|
String _pdsql = "select user,sum(category_code) deviceType FROM wlyy_patient_device GROUP BY user";
|
|
|
List<Map<String,Object>> patientCodeDeviceTypes = jdbcTemplate.queryForList(_pdsql);
|
|
|
|
|
|
if(!patientCodeDeviceTypes.isEmpty()){
|
|
|
for (Map<String,Object> patientCodeDeviceType : patientCodeDeviceTypes) {
|
|
|
String user = String.valueOf(patientCodeDeviceType.get("user"));
|
|
|
String sum = String.valueOf(patientCodeDeviceType.get("deviceType"));
|
|
|
patientDeviceTypeMap.put(user,sum);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (signList != null && signList.size() > 0) {
|
|
|
for (Map<String, Object> sign : signList) {
|
|
|
Patient p = patientDao.findByCode(sign.get("patient") == null ? "" : sign.get("patient").toString());
|
|
|
if (p == null) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
|
|
// 设置患者标识
|
|
|
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", IdCardUtil.getAgeForIdcard(p.getIdcard()));
|
|
|
// 设置患者性别
|
|
|
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")) {
|
|
|
boolean epTime = false;
|
|
|
try {
|
|
|
epTime = redisTemplate.opsForSet().isMember("expenses:remind:set", p.getCode());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
if (!epTime) {
|
|
|
json.put("expensesRemindStatus", 0);
|
|
|
} else {
|
|
|
json.put("expensesRemindStatus", 1);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
// 缴费情况
|
|
|
json.put("expensesStatus", "1");
|
|
|
}
|
|
|
|
|
|
//病情类型:0健康,1高血压,2糖尿病,3高血压+糖尿病
|
|
|
json.put("disease",p.getDisease());
|
|
|
// 病情:0绿标,1黄标,2红标,
|
|
|
json.put("diseaseCondition",p.getDiseaseCondition());
|
|
|
//预警状态
|
|
|
json.put("standardStatus",p.getStandardStatus());
|
|
|
//设备状态:0未绑定,1血糖仪,2血压仪,3血糖仪+血压仪
|
|
|
String deviceType = "";
|
|
|
if(!patientDeviceTypeMap.isEmpty() && patientDeviceTypeMap.keySet().contains(p.getCode())){
|
|
|
deviceType = (String) patientDeviceTypeMap.get(p.getCode());
|
|
|
}
|
|
|
json.put("deviceType",deviceType);
|
|
|
|
|
|
|
|
|
boolean epTime = false;
|
|
|
try {
|
|
|
epTime = redisTemplate.opsForSet().isMember("wechat:focus:remind:set", p.getCode());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
if (!epTime) {
|
|
|
json.put("wechatFocusRemind", 0);
|
|
|
} else {
|
|
|
json.put("wechatFocusRemind", 1);
|
|
|
}
|
|
|
// 7天提醒标志
|
|
|
List<PatientRemindRecords> records = patientRemindRecordsDao.findByPatientAndType(p.getCode(),1);
|
|
|
if(records!=null&&records.size()>0){
|
|
|
json.put("physicalExamRemind", 1);//7天内已提醒
|
|
|
}else {
|
|
|
json.put("physicalExamRemind", 0);
|
|
|
}
|
|
|
|
|
|
result.put(p.getCode(), json);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (result.size() > 0) {
|
|
|
List<JSONObject> list = Lists.newArrayList(result.values());
|
|
|
|
|
|
Collections.sort(list, new Comparator<JSONObject>() {
|
|
|
@Override
|
|
|
public int compare(JSONObject o1, JSONObject o2) {
|
|
|
//微信綁定情況
|
|
|
String openid1 = o1.has("openid") ? o1.getString("openid") : "";
|
|
|
String openid2 = o2.has("openid") ? o2.getString("openid") : "";
|
|
|
int re = openid1.compareTo(openid2);
|
|
|
|
|
|
if (re > 0) {
|
|
|
return -1;
|
|
|
} else if (re < 0) {
|
|
|
return 1;
|
|
|
} else {
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return new JSONArray(list);
|
|
|
} else {
|
|
|
return new JSONArray();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 发送单条提醒
|
|
@ -89,6 +383,15 @@ public class PhysicalExaminationRemindService extends BaseService {
|
|
|
if (flag&&StringUtils.isNotEmpty(mobile)){
|
|
|
smsService.sendMsg(mobile,"您的家庭医生" + doctName + "提醒,您可以到签约社区进行免费的健康体检啦~");
|
|
|
}
|
|
|
|
|
|
//保存发送提醒
|
|
|
PatientRemindRecords patientRemindRecord = new PatientRemindRecords();
|
|
|
patientRemindRecord.setCode(getCode());
|
|
|
patientRemindRecord.setCreateTime(new Date());
|
|
|
patientRemindRecord.setPatientCode(userCode);
|
|
|
patientRemindRecord.setRemindTime(new Date());
|
|
|
patientRemindRecord.setType(1);
|
|
|
patientRemindRecordsDao.save(patientRemindRecord);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@ -99,7 +402,7 @@ public class PhysicalExaminationRemindService extends BaseService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Async
|
|
|
public void sendBatchNotice(long teamId, String doctName) throws Exception {
|
|
|
public void sendBatchNotice(long teamId, String doctName,Long remindId) throws Exception {
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
|
|
String accessToken = accessTokenUtils.getAccessToken();
|
|
|
Boolean flag = true;
|
|
@ -145,5 +448,10 @@ public class PhysicalExaminationRemindService extends BaseService {
|
|
|
flag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
//更新提醒状态
|
|
|
PatientTeamRemindRecord record = patientTeamRemindRecordDao.findOne(remindId);
|
|
|
record.setStatus(1);
|
|
|
patientTeamRemindRecordDao.save(record);
|
|
|
}
|
|
|
}
|