Przeglądaj źródła

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

8 lat temu
rodzic
commit
0a50a47fa5

+ 4 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/DoctorAdminTeamDao.java

@ -14,7 +14,7 @@ import java.util.List;
/**
 * 行政团队DAO。
 * 
 *
 * @author Sand
 */
public interface DoctorAdminTeamDao extends
@ -92,4 +92,7 @@ public interface DoctorAdminTeamDao extends
    List<AdminTeam> findByOrgCode(String orgCode);
    //  查询当前医生是否为团队长
    @Query("SELECT count(1) from AdminTeam t WHERE t.available = true  AND t.leaderCode = ?1 ")
    int findLeader(String leaderCode);
}

+ 4 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java

@ -338,6 +338,7 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
    /**
     * 获取所有有效的签约信息(不包含-1 -2)
     *
     * @param patient
     * @return
     */
@ -360,4 +361,7 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
    @Query("select f from SignFamily f where f.patient = ?1 and f.adminTeamId = ?2 and f.status > 0 and f.type = ?3")
    SignFamily findByPatientAndAdminTeamId(String patient, Long teamCode, Integer type);
    //根据医生和居民判断是否存在签约关系(全科及健管)
    @Query("select count(1) from SignFamily f where f.status > 0 and f.patient = ?1 and ( f.doctor = ?2 or doctorHealth = ?2  )")
    int findByPatientAndDoctor(String patient, String doctor);
}

+ 240 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/label/SignPatientLabelInfoService.java

@ -1241,6 +1241,246 @@ public class SignPatientLabelInfoService extends BaseService {
        return result;
    }
//    =========================================================================================================================================================
    /**
     * 根据姓名,地址,身份证号搜索团队内居民
     *
     * @param doctor
     * @param filter
     * @return
     * @throws Exception
     */
    public JSONArray getPatientByParams(String doctor, String filter,
                                                String labelCode, String labelType, long teamCode,
                                                String exLabelCode,
                                                String exLabelType,
                                                int page, int pagesize) throws Exception {
        Doctor doc = doctorDao.findByCode(doctor);
        System.out.print("-------------teamCode--------->" + teamCode);
        if (doc == null) {
            throw new Exception("doctor info can not find");
        }
        Map<String, JSONObject> result = new HashMap<>();
        List<Map<String, Object>> signList = new ArrayList<>();
        page = page * pagesize;
        Object[] args = null;
        String sql = "";
//        String reg = "(^\\d{15}$)|(^\\d{17}([0-9]|X)$)";
//        String reg = "^(\\d+)([0-9]|X|x)$";
        String reg = "^\\d+$";
        Pattern pattern = Pattern.compile(reg);
        Matcher matcher = pattern.matcher(filter);
       /* if (matcher.find()) {
//            按数字查询身份证号和地址
            sql = " select DISTINCT t.* " +
                    " from" +
                    "     wlyy_sign_family t join wlyy_patient p " +
                    "     on t.patient = p.code " +
                    (StringUtils.isNotEmpty(labelCode) ? (" join wlyy_sign_patient_label_info l " +
                            " on t.patient = l.patient ") : "") +
                    " where " +
                    "    (t.doctor = ? or t.doctor_health = ?) " +
                    (teamCode > 0 ? ("    and t.admin_team_code = " + teamCode) : "") +
                    (StringUtils.isNotEmpty(labelCode) ? " and l.label = ? and l.label_type = ? " : "") +
                    "     and ( p.idcard like ? OR p.address like ?  ) " +
//            "     and ( p.idcard like ?   ) ";
                    " ORDER BY  p.address DESC,p.idcard DESC ";
            if (StringUtils.isNotEmpty(labelCode)) {
                args = new Object[]{doctor, doctor, labelCode, labelType, "%" + filter + "%", "%" + filter + "%"};
            } else {
                args = new Object[]{doctor, doctor, "%" + filter + "%", "%" + filter + "%"};
            }
            System.out.println("=====================================>" + sql);
        } else {*/
//            非数字查询姓名和地址
        sql = "select " +
                "    DISTINCT t1.* " +
                " FROM " +
                "    (wlyy_sign_family t1,wlyy_patient p)  " +
//                    "    wlyy_sign_family t1   " +
                (StringUtils.isNotEmpty(labelCode) ?
                        " join " : " left join ") +
                "    wlyy_sign_patient_label_info t2 " +
                " ON t1.patient = t2.patient " +
                (teamCode > 0 ? " join (select * from wlyy_sign_patient_label where label_type != '4' or team_code = " + teamCode + " or (label_type = '4' and (label_code in (1,2)))) lb on t2.label = lb.label_code and t2.label_type = lb.label_type " : "") +
                " WHERE " +
                " p.code = t1.patient " +
//                    " p.code = t1.patient " +
                "   AND (t1.doctor = ? or t1.doctor_health = ?) " +
                "    AND t1.status > 0 " +
                "    AND (" + (StringUtils.isNotEmpty(labelCode) || StringUtils.isNotEmpty(labelType) ? "" : " t2.patient is null OR ") + " t2.status = 1) " +
                (StringUtils.isNotEmpty(labelCode) ? " AND t2.label = ? " : "") +
                (StringUtils.isNotEmpty(labelType) ? " AND t2.label_type = ? " : "") +
                (teamCode > 0 ? (" AND admin_team_code = " + teamCode) : "") +
                "  AND (t1.name like ? or p.address like ? or p.idcard like ? ) " +
//                    "  AND (t1.name like ? or t2.label_name like ?  ) " ;
                " ORDER BY  p.name DESC,p.address DESC, p.idcard DESC ";
        System.out.println("=====================================>" + sql);
        if (StringUtils.isNotEmpty(labelCode)) {
            args = new Object[]{doctor, doctor, labelCode, labelType, "%" + filter + "%", "%" + filter + "%", "%" + filter + "%"};
        } else if (StringUtils.isEmpty(labelCode) && StringUtils.isNotEmpty(labelType)) {
            args = new Object[]{doctor, doctor, labelType, "%" + filter + "%", "%" + filter + "%", "%" + filter + "%"};
        } else {
            args = new Object[]{doctor, doctor, "%" + filter + "%", "%" + filter + "%", "%" + filter + "%"};
        }
//        }
        sql += " limit " + page + "," + pagesize;
        signList = jdbcTemplate.queryForList(sql, args);
        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;
                }
                if (result.containsKey(p.getCode())) {
                    JSONObject jsonP = result.get(p.getCode());
//                  返回的签约类型
                    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")) {
                            boolean epTime = false;
                            try {
                                epTime = redisTemplate.opsForSet().isMember("expenses:remind:set", p.getCode());
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            if (!epTime) {
                                jsonP.put("expensesRemindStatus", 0);
                            } else {
                                jsonP.put("expensesRemindStatus", 1);
                            }
                        }
                        boolean epTime = false;
                        try {
                            epTime = redisTemplate.opsForSet().isMember("wechat:focus:remind:set", p.getCode());
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        if (!epTime) {
                            jsonP.put("wechatFocusRemind", 0);
                        } else {
                            jsonP.put("wechatFocusRemind", 1);
                        }
                    }
                    continue;
                }
                if (StringUtils.isNotEmpty(exLabelCode)) {
                    SignPatientLabelInfo labelInfoEx = labelInfoDao.findByPatientAndLabelAndLabelTypeAndStatus(p.getCode(), exLabelCode, exLabelType, 1);
                    if (labelInfoEx != null) {
                        continue;
                    }
                } else if (StringUtils.isNotEmpty(exLabelType)) {
                    List<SignPatientLabelInfo> labelExs = labelInfoDao.findByPatientAndLabelTypeAndStatus(p.getCode(), exLabelType, 1);
                    if (labelExs != null && labelExs.size() > 0) {
                        continue;
                    }
                }
                List<SignPatientLabelInfo> labels = null;
                if (teamCode > 0) {
                    labels = labelInfoDao.findByPatientAndStatusByTeam(sign.get("patient").toString(), 1, teamCode);
                } else {
                    labels = labelInfoDao.findByPatientAndStatus(sign.get("patient").toString(), 1);
                }
                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());
                // 地址(追加)
                json.put("address", p.getAddress() == null ? "" : p.getAddress());
                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("2".equals(String.valueOf(sign.get("type"))) && "1".equals(String.valueOf(sign.get("expenses_status")))){
//                    json.put("qyrq", sign.get("expenses_time") != null ? DateUtil.dateToStr((Date) sign.get("expenses_time"), DateUtil.YYYY_MM_DD) : "");
//                }
                    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");
                }
                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);
                }
                // 患者标签
                json.put("labels", labels == null ? "" : labels);
                result.put(p.getCode(), json);
            }
        }
        return result.size() > 0 ? new JSONArray(result.values()) : new JSONArray();
    }
//    =========================================================================================================================================================
    /**
     * 根据患者姓名或标签名称查询
     *

+ 29 - 78
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java

@ -289,22 +289,22 @@ public class ManagerQuestionnaireService extends BaseService {
                String openId = p.getOpenid();
                json.put("keyword2", sdf.format(new Date()));
                json.put("toUser", c);
                json.put("survey_id",surveyCode );
                json.put("survey_id", surveyCode);
                json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                //判断是否判定openId,有没有发则查找家人发送
                if(StringUtils.isNotBlank(p.getOpenid())){
                if (StringUtils.isNotBlank(p.getOpenid())) {
                    // 添加到发送队列
                    PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
                }else{
                    JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getOpenid());
                } else {
                    JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getOpenid());
                    Patient member = (Patient) j.get("member");
                    if(StringUtils.isNotBlank(member.getOpenid())){
                    if (StringUtils.isNotBlank(member.getOpenid())) {
                        String first = (String) json.get("first");
                        json.remove("first");
                        try{
                            json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName())+first);
                        }catch (Exception e){
                        try {
                            json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()) + first);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        PushMsgTask.getInstance().putWxMsg(accessToken, 11, member.getOpenid(), member.getName(), json);
@ -337,6 +337,7 @@ public class ManagerQuestionnaireService extends BaseService {
            int sort = Integer.parseInt(tempQestion.get("sort").toString());
            int del = 1;
            String qstNextQuestion = null;
//            前提一定要有nextQuestion字段传入,没有为""
            if (!StringUtils.isEmpty(tempQestion.get("nextQuestion").toString())) {
//                            optionNextQuestion = tempOption.get("nextQuestion").toString();
                qstNextQuestion = surveyTemplateQuestionsDao.findBySort(templateCode, tempQestion.get("nextQuestion"));
@ -445,6 +446,7 @@ public class ManagerQuestionnaireService extends BaseService {
                        if (!StringUtils.isEmpty(tempOption.get("nextQuestion").toString())) {
//                            optionNextQuestion = tempOption.get("nextQuestion").toString();
                            optionNextQuestion = surveyTemplateQuestionsDao.findBySort(templateCode, tempOption.get("nextQuestion"));
                            optionNextQuestion = (optionNextQuestion == null ? "0" : optionNextQuestion);
                        }
//                        自主创建,插入表
@ -1187,6 +1189,8 @@ public class ManagerQuestionnaireService extends BaseService {
            }
            question.put("title", title);
//            增加返回模板问题编码
            question.put("qstCode", qstcode);
            question.put("isRequired", isRequired);
            question.put("comment", comment);
            question.put("type", type);
@ -1215,9 +1219,17 @@ public class ManagerQuestionnaireService extends BaseService {
        return jsonObject;
    }
    /**
     * 保存为新模板
     *
     * @param code        问卷编码
     * @param modifyTitle 标题重复后修改后的标题(第一次为null)
     * @return
     * @throws Exception
     */
    public int savaSurveyAsTemplate(String code, String modifyTitle) throws Exception {
        Survey survey = surveyDao.findById(code);
        String tempCode = getCode();
        Survey survey = surveyDao.findById(code);
        String title = survey.getTitle();
        String templateComment = survey.getSurveyComment();
        String creater = survey.getCreater();
@ -1281,6 +1293,7 @@ public class ManagerQuestionnaireService extends BaseService {
        return 0;
    }
    //根据模板创建的问卷再次保存为问卷时是修改模板
    public int modifyTemplate(String code, String templateCode, String modifyTitle) throws Exception {
        Survey survey = surveyDao.findById(code);
        String title = survey.getTitle();
@ -1312,9 +1325,10 @@ public class ManagerQuestionnaireService extends BaseService {
//            surveyLabelInfoDao.save(surveyLabelInfo1);
            surveyLabelInfoDao.modifyLabel(templateCode, surveyLabelInfo.getLabel());
        }
        List<SurveyQuestionnaire> surveyQuestionnaires = surveyQuestionnaireDao.findById(survey.getCode());
        List<SurveyQuestionnaire> surveyQuestionnaires = surveyQuestionnaireDao.findById(code);
        for (SurveyQuestionnaire question : surveyQuestionnaires) {
            String qstCode = getCode();
//            String qstCode = getCode();
            String qstCode = question.getCode();
            String qstTitle = question.getTitle();
            String qstComment = question.getQuestionComment();
            Integer qstType = question.getQuestionType();
@ -1329,6 +1343,7 @@ public class ManagerQuestionnaireService extends BaseService {
//            SurveyTemplateQuestions surveyTemplateQuestions = new SurveyTemplateQuestions(qstCode, qstTitle, qstComment, qstType, templateCode, isRequired, minNum, maxNum, sort, next, null, de, createTiem, updateTiem);
            //            更改问题到模板问题表
//            surveyTemplateQuestionsDao.save(surveyTemplateQuestions);
            System.out.println(templateCode+","+qstCode+qstTitle+","+qstComment+","+qstType+","+isRequired+","+minNum+","+maxNum+","+sort+","+next);
            surveyTemplateQuestionsDao.modifyQuestion(templateCode, qstCode, qstTitle, qstComment, qstType, isRequired, minNum, maxNum, sort, next);
            if (qstType != 2) {
                List<SurveyQuestionnaireOptions> surveyQuestionnaireOptions = surveyQuestionnaireOptionsDao.findByIdAndQstCode(code, question.getCode());
@ -1339,6 +1354,7 @@ public class ManagerQuestionnaireService extends BaseService {
//                    surveyTemplateOptionsDao.save(surveyTemplateOptions);
                    surveyTemplateOptionsDao.modifyOption(templateCode, qstCode, option.getCode(),
                            option.getHaveComment(), option.getContent(), option.getQuestionCodeNext(), option.getIsRequired(), option.getSort());
                    System.out.println("=============>");
                }
            }
        }
@ -1395,9 +1411,9 @@ public class ManagerQuestionnaireService extends BaseService {
//        1.服务 2.健康 3疾病
        JSONObject jsonObject = new JSONObject(json);
        String sex = jsonObject.get("sex").toString();
        String str = "SELECT s.patient  FROM ( " +
        String str = "SELECT DISTINCT s.patient  FROM ( " +
                "SELECT t.patient,GROUP_CONCAT(t.label_name) label_name FROM wlyy_sign_patient_label_info t  " +
                "WHERE t.patient IN (SELECT a.patient FROM wlyy_sign_family a WHERE a.status IN(1,2,3)) AND t.patient IN (SELECT b.`code` FROM wlyy_patient b WHERE b.`openid` IS NOT NULL AND b.`openid`!='' ";
                "WHERE t.patient IN (SELECT a.patient FROM wlyy_sign_family a WHERE a.status IN(1,2,3)) and t.status = 1 AND t.patient IN (SELECT b.`code` FROM wlyy_patient b WHERE b.`openid` IS NOT NULL AND b.`openid`!='' ";
        if (!"0".equals(sex)) {
            str += " AND b.sex= " + sex + " ) GROUP BY t.patient ) s WHERE 1=1 ";
        } else {
@ -1475,75 +1491,10 @@ public class ManagerQuestionnaireService extends BaseService {
        if (!StringUtils.isEmpty(dis)) {
            str += " AND ( " + dis.substring(0, dis.lastIndexOf("OR")) + " ) ";
        }
      /*  if (Integer.parseInt(sex) != 0) {
            str += "and t.sex = " + sex;
        }
        JSONArray service = jsonObject.getJSONArray("service");
        String ser = "";
        String servi = "";
        for (Object serv : service) {
            if ("0".equals(serv.toString())) {
                ser += ",";
                break;
            } else {
                ser += serv.toString() + ",";
            }
        }
        ser = ser.substring(0, ser.length() - 1);
        if (ser.length() != 0) {
            servi = "(t.`label_type`=1 AND t.`label`IN(" + ser + "))";
        }
        JSONArray healthCondition = jsonObject.getJSONArray("healthCondition");
        String heal = "";
        String healt = "";
        for (Object health : healthCondition) {
            if ("0".equals(health.toString())) {
                heal += ",";
                break;
            } else {
                heal += health.toString() + ",";
            }
        }
        heal = heal.substring(0, heal.length() - 1);
        if (heal.length() != 0) {
            healt = "(t.`label_type`=2 AND t.`label`IN(" + heal + "))";
        }
        JSONArray disease = jsonObject.getJSONArray("disease");
        String dise = "";
        String diseas = "";
        for (Object disea : disease) {
            if ("0".equals(disea.toString())) {
                dise += ",";
                break;
            } else {
                dise += disea.toString() + ",";
            }
        }
        dise = dise.substring(0, dise.length() - 1);
        if (dise.length() != 0) {
            diseas = "(t.`label_type`=3 AND t.`label`IN(" + dise + "))";
        }
        if (servi.length() != 0 & healt.length() != 0 & diseas.length() != 0) {
            str += "AND ( " + servi + "OR" + healt + "OR" + diseas + " )";
        } else if (servi.length() != 0 & healt.length() != 0 & diseas.length() == 0) {
            str += "AND ( " + servi + "OR" + healt + " )";
        } else if (servi.length() != 0 & healt.length() == 0 & diseas.length() != 0) {
            str += "AND ( " + servi + "OR" + diseas + " )";
        } else if (servi.length() == 0 & healt.length() != 0 & diseas.length() != 0) {
            str += "AND ( " + healt + "OR" + diseas + " )";
        } else if (servi.length() != 0 & healt.length() == 0 & diseas.length() == 0) {
            str += "AND " + servi;
        } else if (servi.length() == 0 & healt.length() != 0 & diseas.length() == 0) {
            str += "AND " + healt;
        } else if (servi.length() == 0 & healt.length() == 0 & diseas.length() != 0) {
            str += "AND " + diseas;
        }*/
//        Map<String, Object> patients = jdbcTemplate.queryForMap(str);
        System.out.println("=====query sql =======>>>>" + str);
        List<String> patients = jdbcTemplate.queryForList(str, String.class);
        return patients;
    }
}

+ 55 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ImUtill.java

@ -7,6 +7,61 @@ import org.json.JSONObject;
 * Created by 卓 on 2017/1/13.
 */
public class ImUtill {
    //    ===============================
    private static String host = "http://192.168.131.107:3000";
    /**
     * 获取医生统计数据
     * status reply 为空值是是该医生总咨询量
     *
     * @param user   团队就把团队的医生合并起来用,隔开(医生编码)
     * @param status
     * @param reply
     * @return
     */
    public static String getConsultData(String user, Integer status, Integer reply) {
//        String imAddr = SystemConf.getInstance().getImListGet() + "/api/v2/sessions/topics/count/reply";
        String imAddr = host + "/api/v2/sessions/topics/count/reply";
        JSONObject params = new JSONObject();
        params.put("user", user);
        if (status!=null) {
            params.put("status", status);
        }
        if (reply!=null) {
            params.put("reply", reply);
        }
        String response = HttpClientUtil.postBody(imAddr, params);
        return response;
    }
    /**
     * 列表接口
     * 获取团队内医生的健康咨询状况
     * status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
     *
     * @param user     团队就把团队的医生合并起来用,隔开(医生编码)
     * @param page
     * @param pagesize
     * @param status
     * @param reply
     * @return
     */
    public static String getConsultByStatus(String user, Integer status, Integer reply, int page, int pagesize) {
        String imAddr = host + "/api/v2/sessions/topics";
        JSONObject params = new JSONObject();
        params.put("user", user);
        params.put("page", page);
        params.put("pagesize", pagesize);
        if (status!=null) {
            params.put("status", status);
        }
        if (reply!=null) {
            params.put("reply", reply);
        }
        String response = HttpClientUtil.postBody(imAddr, params);
        return response;
    }
//    ===============================
    /**
     * 发送消息给IM
     *

+ 166 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/im/imController.java

@ -1,20 +1,183 @@
package com.yihu.wlyy.web.common.im;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.util.ImUtill;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;
import com.yihu.wlyy.util.HttpUtil;
import com.yihu.wlyy.web.BaseController;
import java.util.*;
@RestController
@RequestMapping(value = "im_new", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "IM-即时消息")
public class imController extends BaseController {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private SignFamilyDao signFamilyDao;
    /**
     * 获取列表
     * status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
     * 第一次列表为当前医生(很可能团队长)待回复列表 传参:doctor有后台获取 status=0,reply=0未回复
     * 后 取团队内单各医生的咨询情况 doctor、status、reply均有前端传入
     *
     * @return
     */
    @RequestMapping(value = "/consult/getList", method = RequestMethod.GET)
    @ResponseBody
    public String getTeamData(
            @RequestParam(required = false) String doctor,
            @RequestParam Integer status,
            @RequestParam(required = false) Integer reply,
            @RequestParam int page,
            @RequestParam int pagesize) {
        try {
//            后端校验
            if (StringUtils.isEmpty(doctor)) {
                doctor = getUID();
            }
            String consult = ImUtill.getConsultByStatus(doctor, status, reply, page, pagesize);
            JSONArray jsonArray = new JSONArray(consult);
            Iterator<Object> it = jsonArray.iterator();
            List list = new ArrayList();
            while (it.hasNext()) {
                Map map = new HashMap();
                JSONObject ob = (JSONObject) it.next();
                String session_id = ob.get("session_id").toString();
                String name = ob.get("name").toString();
                map.put("name", name);
                map.put("session_id", session_id);
                list.add(map);
            }
            return write(200, "查询成功", "data", list);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
    /**
     * 获取团队统计数据
     * status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
     *
     * @return
     */
    @RequestMapping(value = "/consult/getTeamData", method = RequestMethod.GET)
    @ResponseBody
    public String getTeamData() {
        try {
            String uid = getUID();
            List<Map<String, Object>> doctors = getMemberByDoctor(uid);
            JSONObject json = new JSONObject();
            List list = new ArrayList();
            int countUnReply = 0;
            int countReply = 0;
            int countConsult = 0;
//        团队下的医生统计数量
            for (Map<String, Object> doc : doctors) {
                Map map = new HashMap();
                String doctor = doc.get("code").toString();
                map.put("photo", doc.get("photo").toString());
                map.put("name", doc.get("name").toString());
                map.put("sex", doc.get("sex").toString());
                map.put("doctor", doctor);
//                map.put("code", "ec6714314d6d48a6bfcf1e9119187e02");
                String totalUnReply = ImUtill.getConsultData(doctor, 0, 0);
                int unReply = Integer.parseInt(totalUnReply);
                map.put("totalUnReply", unReply);
                String totalReply = ImUtill.getConsultData(doctor, 0, 1);
                int reply = Integer.parseInt(totalReply);
                map.put("totalReply", reply);
                String totalConsult = ImUtill.getConsultData(doctor, null, null);
                int consult = Integer.parseInt(totalConsult);
                map.put("totalConsult", consult);
                countUnReply += unReply;
                countReply += reply;
                countConsult += consult;
                list.add(map);
            }
            json.put("totalUnReply", countUnReply);
            json.put("totalReply", countReply);
            json.put("totalConsult", countConsult);
            json.put("doctors", list);
            return write(200, "查询成功");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
    /**
     * 获取团队内医生的健康咨询状况
     *
     * @param code
     * @param type 0待回复 1进行中 2已完成
     * @return
     *//*
    @RequestMapping(value = "/getTeamDoctor", method = RequestMethod.GET)
    @ResponseBody
    public String getTeamDoctor(@RequestParam String code,
                                @RequestParam int type,
                                @RequestParam int pageNo,
                                @RequestParam int pageSize) {
        try {
//			List list = consultTeamService.getTeamDoctor(code, type);
//			return write(200, "查询成功", "data", list);
            return write(200, "查询成功");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
/**/
    /**
     * 获取团队医生下居民的咨询
     *
     * @param patient
     * @return
     */
    @RequestMapping(value = "/getConsultByPatient", method = RequestMethod.GET)
    @ResponseBody
    public String getConsultByPatient(@RequestParam String patient) {
        try {
//            1.调im接口
//            2.判断团队长和当前咨询居民是否存在签约关系
            String doctor = getUID();
//			Boolean flag = consultTeamService.getConsultByPatient(patient,doctor);
            int count = signFamilyDao.findByPatientAndDoctor(patient,doctor);
            boolean flag = (count ==0)? false : true;
			return write(200, "查询成功", "data", flag);
//            return write(200, "查询成功");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
    public List getMemberByDoctor(String doctor) {
//        List<Doctor> doctors = doctorDao.findMemberByLeader(doctor);
        String sql = "SELECT d.photo,d.`name`,d.sex,d.`code` " +
                " from wlyy_admin_team t,wlyy_admin_team_member m,wlyy_doctor d " +
                " where t.id = m.team_id and m.doctor_code = d.`code` and t.available = 1 and m.available=1 " +
                " and t.leader_code = ? ";
        List<Map<String, Object>> doctors = jdbcTemplate.queryForList(sql, doctor);
        return doctors;
    }
}

+ 6 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/account/DoctorController.java

@ -11,6 +11,7 @@ import com.yihu.wlyy.entity.doctor.profile.DoctorComment;
import com.yihu.wlyy.entity.organization.HospitalDept;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.doctor.DoctorAdminTeamDao;
import com.yihu.wlyy.service.app.account.PatientInfoService;
import com.yihu.wlyy.service.app.consult.ConsultTeamService;
import com.yihu.wlyy.service.app.hospital.HospitalDeptService;
@ -80,6 +81,8 @@ public class DoctorController extends BaseController {
    StringRedisTemplate redisTemplate;
    @Autowired
    private RoleService roleService;
    @Autowired
    private DoctorAdminTeamDao doctorAdminTeamDao;
    /**
     * 社区医院下医生列表查询接口 没分页
@ -549,6 +552,7 @@ public class DoctorController extends BaseController {
                code = getUID();
            }
            Doctor temp = doctorInfoService.findDoctorByCode(code);
            int leader = doctorAdminTeamDao.findLeader(code);
            if (temp != null) {
                JSONObject json = new JSONObject();
                // 设置医生手机号码
@ -600,6 +604,8 @@ public class DoctorController extends BaseController {
                //获取医生角色和区域权限
                List<Map<String, String>> roleMap = roleService.getUserRoleAndArea(temp.getCode());
                json.put("userRole", roleMap);
//                是否团队长
                json.put("isLeader", leader==0?"0":"1");
                return write(200, "医生信息查询成功!", "data", json);
            } else {
                return error(-1, "医生信息查询失败!");

+ 47 - 20
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/SignPatientLabelInfoController.java

@ -26,15 +26,42 @@ public class SignPatientLabelInfoController extends BaseController {
    @Autowired
    SignPatientLabelInfoService labelInfoService;
    @RequestMapping(value="getPatientByNameOrIdcard",method = RequestMethod.GET)
    /**
     * 根据姓名,地址,身份证号搜索团队内居民
     *
     * @param str
     * @return
     */
    @RequestMapping(value = "getPatientByParams", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("由姓名|地址|身份证号搜索签约居民")
    public String getPatientByParams(@RequestParam String str,
                                     @RequestParam String teamCode) {
        try {
            if (StringUtils.isEmpty(str)) {
                return error(-1, "搜索条件不能为空!");
            }
            if (StringUtils.isEmpty(teamCode)) {
                return error(-1, "团队不能为空!");
            }
            JSONObject temp = labelInfoService.search(str, getUID());
            return write(200, "查询成功!", "data", temp);
        } catch (Exception e) {
            error(e);
//            return error(-1, "查询失败!");
            return invalidUserException(e,-1, "查询失败!");
        }
    }
    @RequestMapping(value = "getPatientByNameOrIdcard", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("医生端搜索签约居民")
    public String search(@RequestParam(required = true) String str){
    public String search(@RequestParam(required = true) String str) {
        try {
            if (StringUtils.isEmpty(str)) {
                return error(-1, "居民不能为空!");
            }
            JSONObject temp = labelInfoService.search(str,getUID());
            JSONObject temp = labelInfoService.search(str, getUID());
            return write(200, "查询成功!", "data", temp);
        } catch (Exception e) {
            e.printStackTrace();
@ -133,10 +160,10 @@ public class SignPatientLabelInfoController extends BaseController {
     * @return
     */
    @RequestMapping(value = "/team_patient")
    public String getTeamPatient(@RequestParam(required = true)Long teamCode,
                                       @RequestParam(required = false) String labelCode,
                                       @RequestParam(required = false) String labelType,
                                 @RequestParam(required = true)int page, @RequestParam(required = true)int pagesize) {
    public String getTeamPatient(@RequestParam(required = true) Long teamCode,
                                 @RequestParam(required = false) String labelCode,
                                 @RequestParam(required = false) String labelType,
                                 @RequestParam(required = true) int page, @RequestParam(required = true) int pagesize) {
        try {
            if (teamCode == null || teamCode < 1) {
                return error(-1, "团队cdoe不能为空");
@ -189,17 +216,17 @@ public class SignPatientLabelInfoController extends BaseController {
     * @return
     */
    @RequestMapping(value = "/label_team_amount")
    public String getPatientAmountByTeam(@RequestParam(required = false)String labelType, @RequestParam(required = true) Long teamCode) {
    public String getPatientAmountByTeam(@RequestParam(required = false) String labelType, @RequestParam(required = true) Long teamCode) {
        try {
            if (StringUtils.isEmpty(labelType)) {
                labelType="0";
                labelType = "0";
            }
            if (teamCode == null) {
                teamCode = 0L;
            }
            JSONArray result = labelInfoService.getPatientAmountByTeamGroupLable(teamCode,labelType);
            JSONArray result = labelInfoService.getPatientAmountByTeamGroupLable(teamCode, labelType);
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            return error(-1, "查询失败");
@ -209,17 +236,17 @@ public class SignPatientLabelInfoController extends BaseController {
    /**
     * 查询某个团队的患者数/汇总
     *
     * @param teamCode  团队code
     * @param teamCode 团队code
     * @return
     */
    @RequestMapping(value = "/team_amount")
    public String getAmountByTeam(@RequestParam(required = true) Long teamCode) {
        try {
            int result = labelInfoService.getPatientAmountByTeam(teamCode);
            int resultFocus =labelInfoService.getPatientFocusAmountByTeam(teamCode);
            int resultFocus = labelInfoService.getPatientFocusAmountByTeam(teamCode);
            JSONObject re = new JSONObject();
            re.put("amount",result);
            re.put("focusAmount",resultFocus);
            re.put("amount", result);
            re.put("focusAmount", resultFocus);
            return write(200, "查询成功", "data", re);
        } catch (Exception e) {
@ -246,7 +273,7 @@ public class SignPatientLabelInfoController extends BaseController {
                return error(-1, "健康情况标签不能为空");
            }
            int result = labelInfoService.setPatientLabels(patient, "", "", health, disease, custom ,getUID(), getUID());
            int result = labelInfoService.setPatientLabels(patient, "", "", health, disease, custom, getUID(), getUID());
            if (result == 0) {
                return error(-1, "查不到患者信息");
@ -289,7 +316,7 @@ public class SignPatientLabelInfoController extends BaseController {
                return error(-1, "患者不能为空");
            }
            JSONArray labels = labelInfoService.getPatientLabelByLabelTypeAndTeamCode(patient, labelType,teamCode,getUID());
            JSONArray labels = labelInfoService.getPatientLabelByLabelTypeAndTeamCode(patient, labelType, teamCode, getUID());
            return write(200, "查询成功", "data", labels);
        } catch (Exception e) {
@ -403,15 +430,15 @@ public class SignPatientLabelInfoController extends BaseController {
    @RequestMapping(value = "/patient_search_all_exitdoc", method = RequestMethod.GET)
    @ApiOperation("根据姓名搜索所有团队下居民(根据团队)")
    public String searchPatientsExitDoc(@RequestParam(required = true) String filter,
                                 @RequestParam(required = true, defaultValue = "0") long teamCode,
                                 @RequestParam(required = false, defaultValue = "0") int page,
                                 @RequestParam(required = false, defaultValue = "15") int pagesize) {
                                        @RequestParam(required = true, defaultValue = "0") long teamCode,
                                        @RequestParam(required = false, defaultValue = "0") int page,
                                        @RequestParam(required = false, defaultValue = "15") int pagesize) {
        try {
            if (StringUtils.isEmpty(filter)) {
                return error(-1, "查询参数不能为空");
            }
            page = page > 0 ? page - 1 : 0;
            JSONArray result = labelInfoService.searchTeamsPatients(filter,teamCode, page, pagesize);
            JSONArray result = labelInfoService.searchTeamsPatients(filter, teamCode, page, pagesize);
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            e.printStackTrace();

+ 16 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/survey/ManagerQuestionnaireController.java

@ -108,6 +108,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
            @RequestParam String id) {
        try {
            JSONObject jsonObject = managerQuestionnaireService.getQuestionnaireDetail(id);
            System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+jsonObject);
            return write(200, "查询成功", "data", jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
@ -205,6 +206,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
        try {
//        解析整套问卷json字符串并保存
            JSONObject jsonStr = new JSONObject(jsonData.toString());
            System.out.println("==============================>"+jsonStr);
//            获取医生信息(仅限市级管理员)
            String doctor = getUID();
            String accessToken = getAccessToken();
@ -394,9 +396,21 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
        try {
            int num = 0;
            if (StringUtils.isEmpty(templateCode)) {
                num = managerQuestionnaireService.savaSurveyAsTemplate(code, title);
//                保存为新模板(重复之后才会有title传进来)
                if (StringUtils.isEmpty(title)){
                    num = managerQuestionnaireService.savaSurveyAsTemplate(code, null);
                }else {
                    num = managerQuestionnaireService.savaSurveyAsTemplate(code, title);
                }
            } else {
                num = managerQuestionnaireService.modifyTemplate(code, templateCode, title);
//                修改原模板(重复之后才会有title传进来)
                if (StringUtils.isEmpty(title)){
                    num = managerQuestionnaireService.modifyTemplate(code, templateCode, null);
                }else {
                    num = managerQuestionnaireService.modifyTemplate(code, templateCode, title);
                }
            }
            if (num == 0) {
                return write(200, "保存成功!");