Ver código fonte

Merge branch 'dev' of wujunjie/patient-co-management into dev

yeshijie 7 anos atrás
pai
commit
e01dea9f2a

+ 82 - 94
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/physicalExamination/PhysicalExaminationRemindService.java

@ -65,21 +65,22 @@ public class PhysicalExaminationRemindService extends BaseService {
    /**
     * 单个提醒居民按钮
     *
     * @param patient
     * @param doctor
     */
    public Integer singleRemindPhyExam(String patient,String doctor){
        List<PatientRemindRecords> records = patientRemindRecordsDao.findByPatientAndType(patient,1);
        if(records!=null&&records.size()>0){
    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){
        try {
            sendSingleNotice(patient, d.getName());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("体检提醒失败"+e.getMessage());
            logger.error("体检提醒失败" + e.getMessage());
        }
        return 0;
@ -87,12 +88,13 @@ public class PhysicalExaminationRemindService extends BaseService {
    /**
     * 单个提醒居民按钮
     *
     * @param teamCode
     * @param doctor
     */
    public Integer remindPhyExams(Long teamCode,String doctor){
        List<PatientTeamRemindRecord> records = patientTeamRemindRecordDao.findByAdminTeamCodeAndType(teamCode,1);
        if(records!=null&&records.size()>0){
    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();
@ -103,11 +105,11 @@ public class PhysicalExaminationRemindService extends BaseService {
        patientTeamRemindRecordDao.save(record);
        Doctor d = doctorDao.findByCode(doctor);
        try{
            sendBatchNotice(teamCode,d.getName(),record.getId());
        }catch (Exception e){
        try {
            sendBatchNotice(teamCode, d.getName(), record.getId());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("批量体检提醒失败"+e.getMessage());
            logger.error("批量体检提醒失败" + e.getMessage());
        }
        return 0;
@ -115,10 +117,11 @@ public class PhysicalExaminationRemindService extends BaseService {
    /**
     * 健康体检 是否显示批量提醒按钮
     *
     * @param teamCode
     * @return
     */
    public Integer isShowRemindBtns(long teamCode){
    public Integer isShowRemindBtns(long teamCode) {
        Integer re = 0;
        List<Map<String, Object>> signList = new ArrayList<>();
        String sql = "";
@ -137,10 +140,10 @@ public class PhysicalExaminationRemindService extends BaseService {
                "           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>?)"+
                "                 and o.medical_time>?)" +
                " order by t1.openid desc,convert(t1.name using gbk) ";
        args = new Object[]{teamCode,teamCode,DateUtil.getLastYear()};
        args = new Object[]{teamCode, teamCode, DateUtil.getLastYear()};
        signList = jdbcTemplate.queryForList(sql, args);
        if (signList != null && signList.size() > 0) {
            for (Map<String, Object> sign : signList) {
@ -148,13 +151,13 @@ public class PhysicalExaminationRemindService extends BaseService {
                if (StringUtils.isEmpty(patient)) {
                    continue;
                }
                List<PatientRemindRecords> records = patientRemindRecordsDao.findByPatientAndType(patient,1);
                if(records==null||records.size()==0){
                List<PatientRemindRecords> records = patientRemindRecordsDao.findByPatientAndType(patient, 1);
                if (records == null || records.size() == 0) {
                    re = 1;
                    break;
                }
            }
        }else{
        } else {
            re = 1;
        }
        return re;
@ -162,6 +165,7 @@ public class PhysicalExaminationRemindService extends BaseService {
    /**
     * 获取65岁以上老年人1年内无体检记录列表
     *
     * @param teamCode
     * @param page
     * @param pagesize
@ -172,7 +176,7 @@ public class PhysicalExaminationRemindService extends BaseService {
        Map<String, JSONObject> result = new TreeMap<>();
        List<Map<String, Object>> signList = new ArrayList<>();
        Map<String,Object> patientDeviceTypeMap = new HashMap<>();//用于存储患者设备绑定情况
        Map<String, Object> patientDeviceTypeMap = new HashMap<>();//用于存储患者设备绑定情况
        int start = page * pagesize;
        String sql = "";
        Object[] args = null;
@ -191,23 +195,23 @@ public class PhysicalExaminationRemindService extends BaseService {
                "           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>?)"+
                "                 and o.medical_time>?)" +
                " order by t1.openid desc,convert(t1.name using gbk) ";
        args = new Object[]{teamCode,teamCode,DateUtil.getLastYear()};
        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);
        List<Map<String, Object>> patientCodeDeviceTypes = jdbcTemplate.queryForList(_pdsql);
        if(!patientCodeDeviceTypes.isEmpty()){
            for (Map<String,Object> patientCodeDeviceType : patientCodeDeviceTypes) {
        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);
                patientDeviceTypeMap.put(user, sum);
            }
        }
@ -273,17 +277,17 @@ public class PhysicalExaminationRemindService extends BaseService {
                }
                //病情类型:0健康,1高血压,2糖尿病,3高血压+糖尿病
                json.put("disease",p.getDisease());
                json.put("disease", p.getDisease());
                // 病情:0绿标,1黄标,2红标,
                json.put("diseaseCondition",p.getDiseaseCondition());
                json.put("diseaseCondition", p.getDiseaseCondition());
                //预警状态
                json.put("standardStatus",p.getStandardStatus());
                json.put("standardStatus", p.getStandardStatus());
                //设备状态:0未绑定,1血糖仪,2血压仪,3血糖仪+血压仪
                String deviceType = "";
                if(!patientDeviceTypeMap.isEmpty() && patientDeviceTypeMap.keySet().contains(p.getCode())){
                if (!patientDeviceTypeMap.isEmpty() && patientDeviceTypeMap.keySet().contains(p.getCode())) {
                    deviceType = (String) patientDeviceTypeMap.get(p.getCode());
                }
                json.put("deviceType",deviceType);
                json.put("deviceType", deviceType);
                boolean epTime = false;
@ -298,10 +302,10 @@ public class PhysicalExaminationRemindService extends BaseService {
                    json.put("wechatFocusRemind", 1);
                }
                // 7天提醒标志
                List<PatientRemindRecords> records = patientRemindRecordsDao.findByPatientAndType(p.getCode(),1);
                if(records!=null&&records.size()>0){
                List<PatientRemindRecords> records = patientRemindRecordsDao.findByPatientAndType(p.getCode(), 1);
                if (records != null && records.size() > 0) {
                    json.put("physicalExamRemind", 1);//7天内已提醒
                }else {
                } else {
                    json.put("physicalExamRemind", 0);
                }
@ -380,8 +384,8 @@ public class PhysicalExaminationRemindService extends BaseService {
            }
        }
//        微信发送失败发送短信
        if (flag&&StringUtils.isNotEmpty(mobile)){
            smsService.sendMsg(mobile,"您的家庭医生" + doctName + "提醒,您可以到签约社区进行免费的健康体检啦~");
        if (flag && StringUtils.isNotEmpty(mobile)) {
            smsService.sendMsg(mobile, "您的家庭医生" + doctName + "提醒,您可以到签约社区进行免费的健康体检啦~");
        }
        //保存发送提醒
@ -397,14 +401,15 @@ public class PhysicalExaminationRemindService extends BaseService {
    /**
     * 发送批量提醒
     *
     * @param teamId 团队ID
     * @param teamId   团队ID
     * @param doctName 医生姓名
     * @return
     */
    @Async
    public void sendBatchNotice(long teamId, String doctName,Long remindId) 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;
        // 推送消息给微信端
        JSONObject json = new org.json.JSONObject();
        json.put("first", "您的家庭医生" + doctName + "提醒,您可以到签约社区进行免费的健康体检啦~");
@ -413,63 +418,46 @@ public class PhysicalExaminationRemindService extends BaseService {
        json.put("url", "");
        json.put("remark", "为了您和您的家庭医生了解您近期的健康状况,请及时到您签约的社区体检哟~");
        String sql = "SELECT DISTINCT " +
                " t1.* " +
                " FROM" +
                " wlyy_sign_family t1 " +
                " WHERE " +
                " t1. STATUS > 0 " +
                " AND t1.admin_team_code = 485 " +
                " 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 =485 " +
                " AND s.`status` > 0 " +
                " AND s.idcard = o.id_card " +
                " AND o.medical_time >'2016-10-19 15:12:11' " +
                " )" +
                " ORDER BY " +
                " t1.openid DESC, " +
                " CONVERT (t1. NAME USING gbk)";
        List<Patient>patients = patientDao.findExaminationRemind(485,new Date());
        Patient patient = patientDao.findByCode("");
        if (StringUtils.isNotBlank(patient.getOpenid())) {
            pushMsgTask.putWxMsg(accessToken, 11, patient.getOpenid(), patient.getName(), json);
        }
        //发送代理人
        JSONArray jsonArray = openIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
        if (jsonArray != null && jsonArray.length() > 0) {
            for (int i = 0; i < jsonArray.length(); i++) {
                org.json.JSONObject j = jsonArray.getJSONObject(i);
                Patient member = (Patient) j.get("member");
                json.remove("toUser");
                json.put("toUser", member.getCode());
                json.remove("first");
                try {
                    json.put("first", openIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    pushMsgTask.putWxMsg(accessToken, 11, member.getOpenid(), patient.getName(), json);
        List<Patient> patients = patientDao.findExaminationRemind(teamId, new Date());
        for (Patient patient : patients) {
            String mobile = patient.getMobile();
            if (StringUtils.isNotBlank(patient.getOpenid())) {
                pushMsgTask.putWxMsg(accessToken, 11, patient.getOpenid(), patient.getName(), json);
                flag = false;
            }
            //发送代理人
            JSONArray jsonArray = openIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
            if (jsonArray != null && jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    org.json.JSONObject j = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    json.remove("toUser");
                    json.put("toUser", member.getCode());
                    json.remove("first");
                    try {
                        json.put("first", openIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (StringUtils.isNotBlank(member.getOpenid())) {
                        pushMsgTask.putWxMsg(accessToken, 11, member.getOpenid(), patient.getName(), json);
                        flag = false;
                    }
                }
            }
            //        微信发送失败发送短信
            if (flag && StringUtils.isNotEmpty(mobile)) {
                smsService.sendMsg(mobile, "您的家庭医生" + doctName + "提醒,您可以到签约社区进行免费的健康体检啦~");
            }
            flag = true;
            //保存发送提醒
            PatientRemindRecords patientRemindRecord = new PatientRemindRecords();
            patientRemindRecord.setCode(getCode());
            patientRemindRecord.setCreateTime(new Date());
            patientRemindRecord.setPatientCode(patient.getCode());
            patientRemindRecord.setRemindTime(new Date());
            patientRemindRecord.setType(1);
            patientRemindRecordsDao.save(patientRemindRecord);
        }
        //更新提醒状态