Просмотр исходного кода

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

trick9191 8 лет назад
Родитель
Сommit
03949b9f5d
21 измененных файлов с 887 добавлено и 600 удалено
  1. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateOptionsDao.java
  2. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyTemplateQuestionsDao.java
  3. 1 3
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/archives/PatientRecordService.java
  4. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/family/FamilyMemberService.java
  5. 69 51
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/label/SignPatientLabelInfoService.java
  6. 164 89
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java
  7. 14 4
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java
  8. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/team/AdminTeamService.java
  9. 81 98
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java
  10. 4 64
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/PatientQuestionnaireService.java
  11. 98 121
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/jw/JwSmjkService.java
  12. 18 12
      patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java
  13. 13 19
      patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ImUtill.java
  14. 51 39
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/im/imController.java
  15. 75 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/account/DoctorController.java
  16. 20 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultController.java
  17. 48 13
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/SignPatientLabelInfoController.java
  18. 146 10
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorFamilyContractController.java
  19. 61 58
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/survey/ManagerQuestionnaireController.java
  20. 19 13
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java
  21. 1 1
      patient-co-wlyy/src/main/resources/system.properties

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

@ -17,5 +17,5 @@ public interface SurveyTemplateOptionsDao extends PagingAndSortingRepository<Sur
    @Modifying
    @Query("update SurveyTemplateOptions t set t.haveComment=?4,t.content=?5," +
            "t.questionCodeNext=?6,t.isRequired=?7,t.sort=?8 where  t.templateQuestionCode = ?1 and t.templateCode = ?2 and t.code=?3")
    void modifyOption(String tempCode, String qstcode, String optcode, Integer haveCommment, String content, String nextCode, Integer isRequired, Integer sort);
    int modifyOption(String tempCode, String qstcode, String optcode, Integer haveCommment, String content, String nextCode, Integer isRequired, Integer sort);
}

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

@ -23,6 +23,6 @@ public interface SurveyTemplateQuestionsDao extends PagingAndSortingRepository<S
    @Modifying
    @Query("update SurveyTemplateQuestions t set t.title=?3,t.questionComment=?4,t.questionType=?5," +
            "t.isRequired=?6,t.minNum=?7,t.maxNum=?8,t.sort=?9,t.questionCodeNext=?10  where t.templateCode = ?1 and t.code = ?2 ")
    void modifyQuestion(String tempCode, String qstCode, String qstTitle, String qstComment, Integer qstType,
    int modifyQuestion(String tempCode, String qstCode, String qstTitle, String qstComment, Integer qstType,
                        Integer isRequired, Integer minNum, Integer maxNum, Integer sort, String next);
}

+ 1 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/archives/PatientRecordService.java

@ -347,9 +347,7 @@ public class PatientRecordService {
        //获取患者
        Patient patient = patientDao.findByCode(patientCode);
        String response = jwSmjkService.getDrugsListPage(patient.getSsc(), page, pageSize);
        if ("[{}]".equals(response)) {
            response = "[]";
        }
        return response;
    }

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/family/FamilyMemberService.java

@ -526,7 +526,7 @@ public class FamilyMemberService extends BaseService {
        //2.判断手机过滤
        //判断是否绑定了手机
        if (StringUtils.isNotBlank(p.getMobile())) {
        if (StringUtils.isNoneBlank(p.getMobile())) {
            //如果用户绑定了微信,将状态更改为4
            if (result == 1) {
                result = 3;

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

@ -12,6 +12,7 @@ import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.logs.BusinessLogs;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.doctor.DoctorPatientGroupInfoDao;
import com.yihu.wlyy.repository.doctor.SignPatientLabelDao;
import com.yihu.wlyy.repository.doctor.SignPatientLabelInfoDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientDiseaseDao;
@ -26,6 +27,8 @@ import org.apache.commons.lang3.StringUtils;
import org.hibernate.type.descriptor.sql.JdbcTypeFamilyInformation;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
@ -69,6 +72,10 @@ public class SignPatientLabelInfoService extends BaseService {
    StringRedisTemplate redisTemplate;
    @Autowired
    AdminTeamService adminTeamService;
    @Autowired
    SignPatientLabelDao labelDao;
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    /**
     * 查询单个居民信息
@ -412,7 +419,7 @@ public class SignPatientLabelInfoService extends BaseService {
            }
        }
        if(result.size() > 0) {
        if (result.size() > 0) {
            List<JSONObject> list = Lists.newArrayList(result.values());
            Collections.sort(list, new Comparator<JSONObject>() {
@ -1241,7 +1248,54 @@ public class SignPatientLabelInfoService extends BaseService {
        return result;
    }
//    =========================================================================================================================================================
    //    =========================================================================================================================================================
    /**
     * 获取没有健康管理师的患者列表
     *
     * @param teamCode
     * @return
     * @throws Exception
     */
    public List findNoHealthSignFamilyHealth(String filter, Long teamCode,int page,int pagesize) throws Exception {
        List list = new ArrayList();
        String sql = "SELECT  DISTINCT " +
                "  p.photo photo, " +
                "  p.name name, " +
                "  p.code code, " +
                "  p.sex sex," +
                "  p.address address," +
                "  p.idcard idcard " +
                " FROM " +
                " wlyy_sign_family sf " +
                " JOIN wlyy_patient p ON sf.patient = p.CODE " +
                " left JOIN wlyy_sign_patient_label_info sp ON sf.patient = sp.patient AND sp.`status` = 1 " +
                " WHERE " +
                " sf.type = 2 " +
                " AND sf. STATUS > 0 " +
                " and sf.admin_team_code = ? " +
                " AND ( sf.doctor_health is null or sf.doctor_health ='' ) " +
                "  AND (p.name like ? or p.address like ? or p.idcard like ? ) " +
                " ORDER BY  p.name DESC,p.address DESC, p.idcard DESC " +
                " limit "+(page-1)+","+pagesize;
        List<Map<String, Object>> datas = jdbcTemplate.queryForList(sql, teamCode, "%" + filter + "%", "%" + filter + "%", "%" + filter + "%");
        if (datas != null && datas.size() > 0) {
            for (Map<String, Object> map : datas) {
                Map ma = new HashMap();
                ma.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard")==null?"":map.get("idcard").toString()));
                ma.put("photo",map.get("photo")==null?"":map.get("photo").toString());
                ma.put("name",map.get("name")==null?"":map.get("name").toString());
                ma.put("code",map.get("code")==null?"":map.get("code").toString());
                ma.put("sex",map.get("sex")==null?"":map.get("sex").toString());
                ma.put("address",map.get("address")==null?"":map.get("address").toString());
                ma.put("idcard",map.get("idcard")==null?"":map.get("idcard").toString());
                list.add(ma);
            }
        }
        return list;
    }
    /**
     * 根据姓名,地址,身份证号搜索团队内居民
     *
@ -1251,55 +1305,23 @@ public class SignPatientLabelInfoService extends BaseService {
     * @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 {
                                        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;
        page = (page - 1) * 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 " +
        String 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 " +
@ -1307,7 +1329,6 @@ public class SignPatientLabelInfoService extends BaseService {
                (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) " +
@ -1315,9 +1336,7 @@ public class SignPatientLabelInfoService extends BaseService {
                (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)) {
@ -1325,7 +1344,6 @@ public class SignPatientLabelInfoService extends BaseService {
        } else {
            args = new Object[]{doctor, doctor, "%" + filter + "%", "%" + filter + "%", "%" + filter + "%"};
        }
//        }
        sql += " limit " + page + "," + pagesize;
        signList = jdbcTemplate.queryForList(sql, args);
@ -1832,7 +1850,7 @@ public class SignPatientLabelInfoService extends BaseService {
                    "   f.admin_team_code," +
                    "   f. STATUS," +
                    "   t.id teamCode," +
                    "   t.name teamName"+
                    "   t.name teamName" +
                    "  FROM" +
                    "   wlyy_patient p" +
                    "  LEFT JOIN (" +
@ -1854,7 +1872,7 @@ public class SignPatientLabelInfoService extends BaseService {
                    "  LEFT JOIN wlyy_admin_team t ON t.id = f.admin_team_code" +
                    "  WHERE" +
                    "   p. idcard = ?";
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, filter,filter);
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, filter, filter);
            for (Map<String, Object> p : list) {
                JSONObject pJson = new JSONObject();
@ -1866,7 +1884,7 @@ public class SignPatientLabelInfoService extends BaseService {
                pJson.put("photo", p.get("photo") != null ? p.get("photo") : "");
                pJson.put("id", p.get("id") != null ? p.get("id") : "");
                pJson.put("doctor", p.get("doctor") != null ? p.get("doctor") : "");
                pJson.put("isSign",p.get("status")!=null?(Integer.parseInt(p.get("status").toString())>=1?"1":"0"):"0");
                pJson.put("isSign", p.get("status") != null ? (Integer.parseInt(p.get("status").toString()) >= 1 ? "1" : "0") : "0");
                pJson.put("doctorHealth", p.get("doctor_health") != null ? p.get("doctor_health") : "");
                if (p.get("id") != null && (doctorCode.equals(pJson.get("doctor")) || doctorCode.equals(pJson.get("doctorHealth")))) {
                    if (p.get("teamCode") != null && StringUtils.isNotEmpty(p.get("teamCode").toString())) {
@ -1901,7 +1919,7 @@ public class SignPatientLabelInfoService extends BaseService {
                    "   f.admin_team_code," +
                    "   f. STATUS," +
                    "   t.id teamCode," +
                    "   t.name teamName"+
                    "   t.name teamName" +
                    "  FROM" +
                    "   wlyy_patient p" +
                    "  LEFT JOIN (" +
@ -1923,7 +1941,7 @@ public class SignPatientLabelInfoService extends BaseService {
                    "  LEFT JOIN wlyy_admin_team t ON t.id = f.admin_team_code" +
                    "  WHERE" +
                    "   p. name  = ?";
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, filter,filter);
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, filter, filter);
            for (Map<String, Object> p : list) {
                JSONObject pJson = new JSONObject();
@ -1935,7 +1953,7 @@ public class SignPatientLabelInfoService extends BaseService {
                pJson.put("photo", p.get("photo") != null ? p.get("photo") : "");
                pJson.put("id", p.get("id") != null ? p.get("id") : "");
                pJson.put("doctor", p.get("doctor") != null ? p.get("doctor") : "");
                pJson.put("isSign",p.get("status")!=null?(Integer.parseInt(p.get("status").toString())>=1?"1":"0"):"0");
                pJson.put("isSign", p.get("status") != null ? (Integer.parseInt(p.get("status").toString()) >= 1 ? "1" : "0") : "0");
                pJson.put("doctorHealth", p.get("doctor_health") != null ? p.get("doctor_health") : "");
                if (p.get("id") != null && (doctorCode.equals(pJson.get("doctor")) || doctorCode.equals(pJson.get("doctorHealth")))) {
                    if (p.get("teamCode") != null && StringUtils.isNotEmpty(p.get("teamCode").toString())) {
@ -2703,7 +2721,7 @@ public class SignPatientLabelInfoService extends BaseService {
            }
        }
        if(result.size() > 0) {
        if (result.size() > 0) {
            List<JSONObject> list = Lists.newArrayList(result.values());
            Collections.sort(list, new Comparator<JSONObject>() {

+ 164 - 89
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -241,11 +241,12 @@ public class FamilyContractService extends BaseService {
    /**
     * 根据医生和患者获取患者的签约状态
     *
     * @param patient
     * @param doctor
     * @return
     */
    public List<SignFamily> getSign(String patient,String doctor){
    public List<SignFamily> getSign(String patient, String doctor) {
        List<SignFamily> sfList = signFamilyDao.findSSandFamilyByDoctorPatient(patient, doctor);
        return sfList;
    }
@ -528,8 +529,8 @@ public class FamilyContractService extends BaseService {
    /**
     * 申请签约
     *
     * @param doctor     签约医生
     * @param patient    居民code
     * @param doctor  签约医生
     * @param patient 居民code
     * @return
     */
    public int sign(String doctor, String patient) throws Exception {
@ -996,38 +997,38 @@ public class FamilyContractService extends BaseService {
            json.put("date", DateUtil.dateToStrShort(sf.getBegin()));
            json.put("content", content);
            json.put("remark", ""); //您好,您成功签约家庭医生
            if(StringUtils.isNotBlank(sf.getOpenid())){
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                PushMsgTask.getInstance().putWxMsg(access_token, 1, sf.getOpenid(), sf.getName(), json);
            }else{
            } else {
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient.getCode());
                if(j!=null){
                    Patient member = (Patient)j.get("member");
                    if(StringUtils.isNotBlank(member.getOpenid())){
                        String first = (String)json.get("first");
                if (j != null) {
                    Patient member = (Patient) j.get("member");
                    if (StringUtils.isNotBlank(member.getOpenid())) {
                        String first = (String) json.get("first");
                        json.remove("first");
                        json.put("first",weiXinOpenIdUtils.getTitleMes(patient,j.getInt("relation"),member.getName()));
                        json.put("first", weiXinOpenIdUtils.getTitleMes(patient, j.getInt("relation"), member.getName()));
                        PushMsgTask.getInstance().putWxMsg(access_token, 1, member.getOpenid(), member.getName(), json);
                    }
                }
            }
            new Thread(new SignUploadTask(sf.getCode())).start();
            JSONObject participants = new JSONObject();
            participants.put(sf.getPatient(),0);
            if(StringUtils.equals(sf.getDoctor(),sf.getDoctorHealth())){//全科和建管同一个人
                participants.put(sf.getDoctor(),0);
            }else{//全科和建管不同一个人
                participants.put(sf.getDoctorHealth(),0);
                participants.put(sf.getDoctor(),1);
            participants.put(sf.getPatient(), 0);
            if (StringUtils.equals(sf.getDoctor(), sf.getDoctorHealth())) {//全科和建管同一个人
                participants.put(sf.getDoctor(), 0);
            } else {//全科和建管不同一个人
                participants.put(sf.getDoctorHealth(), 0);
                participants.put(sf.getDoctor(), 1);
            }
            //创建医生会话讨论组
            JSONObject sessionObj  =  ImUtill.createSession(participants,ImUtill.SESSION_TYPE_MUC,patient.getName(),patient.getCode()+"_"+sf.getTeamCode()+"_"+2);
            if(sessionObj.getInt("status")==-1){
                throw  new RuntimeException(sessionObj.getString("message"));
            JSONObject sessionObj = ImUtill.createSession(participants, ImUtill.SESSION_TYPE_MUC, patient.getName(), patient.getCode() + "_" + sf.getTeamCode() + "_" + 2);
            if (sessionObj.getInt("status") == -1) {
                throw new RuntimeException(sessionObj.getString("message"));
            }
            ImUtill.updateSessionStatus(patient.getCode()+"_"+sf.getTeamCode()+"_"+2,ImUtill.SESSION_STATUS_END);
            ImUtill.updateSessionStatus(patient.getCode() + "_" + sf.getTeamCode() + "_" + 2, ImUtill.SESSION_STATUS_END);
            ImUtill.sendImMsg(doc.getCode(),doc.getName(),patient.getCode()+"_"+sf.getTeamCode()+"_"+2,"0","家庭医生代理签约成功!","1");
            ImUtill.sendImMsg(doc.getCode(), doc.getName(), patient.getCode() + "_" + sf.getTeamCode() + "_" + 2, "0", "家庭医生代理签约成功!", "1");
        }
        BusinessLogs.info(BusinessLogs.BusinessType.sign, signDoctorCode, sf.getPatient(), new JSONObject(sf));
        return temp;
@ -1077,7 +1078,7 @@ public class FamilyContractService extends BaseService {
            result.put("status", 0);
            return result;
        }
        String doctorTeamCode  =null;//服务团队的CODE;
        String doctorTeamCode = null;//服务团队的CODE;
        if (type == 1) {
            //判断是否有三师签约 并且判断全科医生一致
            SignFamily sssignFamily = signFamilyDao.findSSByIdcard(p.getIdcard());
@ -1234,17 +1235,17 @@ public class FamilyContractService extends BaseService {
            json.put("content", sf.getName() + ",您好!您与 " + (StringUtils.isEmpty(sf.getDoctor()) ? sf.getDoctorHealthName() : sf.getDoctorName()) + " 医生建立家庭医生签约关系失败,请查看!");
            json.put("remark", "您好,签约家庭医生失败通知");
            if(StringUtils.isNotBlank(sf.getOpenid())){
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                PushMsgTask.getInstance().putWxMsg(access_token, 2, sf.getOpenid(), sf.getName(), json);
            }else{
            } else {
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                Patient member = (Patient)j.get("member");
                if(StringUtils.isNotBlank(member.getOpenid())){
                   String first = (String)json.get("first");
                   json.remove("first");
                   json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                   PushMsgTask.getInstance().putWxMsg(access_token, 2, member.getOpenid(), member.getName(), json);
                Patient member = (Patient) j.get("member");
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    String first = (String) json.get("first");
                    json.remove("first");
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
                    PushMsgTask.getInstance().putWxMsg(access_token, 2, member.getOpenid(), member.getName(), json);
                }
            }
@ -1277,15 +1278,15 @@ public class FamilyContractService extends BaseService {
            json.put("content", content);
            json.put("remark", ""); //您好,您成功签约家庭医生
            // 添加到发送队列
            if(StringUtils.isNotBlank(sf.getOpenid())){
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                PushMsgTask.getInstance().putWxMsg(access_token, 1, sf.getOpenid(), sf.getName(), json);
            }else{
                JSONObject j =  weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                Patient member = (Patient)j.get("member");
                if(StringUtils.isNotBlank(member.getOpenid())){
                    String first = (String)json.get("first");
            } else {
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                Patient member = (Patient) j.get("member");
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    String first = (String) json.get("first");
                    json.remove("first");
                    json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
                    PushMsgTask.getInstance().putWxMsg(access_token, 1, member.getOpenid(), member.getName(), json);
                }
            }
@ -1293,20 +1294,20 @@ public class FamilyContractService extends BaseService {
            new Thread(new SignUploadTask(sf.getCode())).start();
            JSONObject participants = new JSONObject();
            participants.put(sf.getPatient(),0);
            if(StringUtils.equals(sf.getDoctor(),sf.getDoctorHealth())){//全科和建管同一个人
                participants.put(sf.getDoctor(),0);
            }else{//全科和建管不同一个人
                participants.put(sf.getDoctorHealth(),0);
                participants.put(sf.getDoctor(),1);
            participants.put(sf.getPatient(), 0);
            if (StringUtils.equals(sf.getDoctor(), sf.getDoctorHealth())) {//全科和建管同一个人
                participants.put(sf.getDoctor(), 0);
            } else {//全科和建管不同一个人
                participants.put(sf.getDoctorHealth(), 0);
                participants.put(sf.getDoctor(), 1);
            }
            Patient patient = patientDao.findByCode(sf.getPatient());
            //创建医生会话讨论组
            JSONObject sessionObj  =  ImUtill.createSession(participants,ImUtill.SESSION_TYPE_MUC,patient.getName(),patient.getCode()+"_"+sf.getTeamCode()+"_"+2);
            if(sessionObj.getInt("status")==-1){
                throw  new RuntimeException(sessionObj.getString("message"));
            JSONObject sessionObj = ImUtill.createSession(participants, ImUtill.SESSION_TYPE_MUC, patient.getName(), patient.getCode() + "_" + sf.getTeamCode() + "_" + 2);
            if (sessionObj.getInt("status") == -1) {
                throw new RuntimeException(sessionObj.getString("message"));
            }
            ImUtill.sendImMsg(doc.getCode(),doc.getName(),patient.getCode()+"_"+sf.getTeamCode()+"_"+2,"0","家庭医生签约成功!","1");
            ImUtill.sendImMsg(doc.getCode(), doc.getName(), patient.getCode() + "_" + sf.getTeamCode() + "_" + 2, "0", "家庭医生签约成功!", "1");
        }
        result.put("status", 1);
        BusinessLogs.info(BusinessLogs.BusinessType.sign, caller, sf.getPatient(), new JSONObject(sf));
@ -1364,17 +1365,17 @@ public class FamilyContractService extends BaseService {
            json.put("orgName", sf.getHospitalName());
            json.put("remark", sf.getName() + ",您好!您的签约医生已同意您的解约申请,解约已生效。");
            if(StringUtils.isNotBlank(sf.getOpenid())){
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                PushMsgTask.getInstance().putWxMsg(access_token, 5, sf.getOpenid(), sf.getName(), json);
            }else{
                JSONObject j =  weiXinOpenIdUtils.getFamilyOpenId(patient);
                Patient member = (Patient)j.get("member");
                if(StringUtils.isNotBlank(member.getOpenid())){
                    String first = (String)json.get("first");
            } else {
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient);
                Patient member = (Patient) j.get("member");
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    String first = (String) json.get("first");
                    json.remove("first");
                    Patient p = patientDao.findByCode(patient);
                    json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
                    PushMsgTask.getInstance().putWxMsg(access_token, 5, member.getOpenid(), member.getName(), json);
                }
            }
@ -1393,17 +1394,17 @@ public class FamilyContractService extends BaseService {
            json.put("orgName", sf.getHospitalName());
            json.put("remark", sf.getName() + ",您好!您的签约医生拒绝您的解约申请,解约失败。");
            if(StringUtils.isNotBlank(sf.getOpenid())){
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                PushMsgTask.getInstance().putWxMsg(access_token, 5, sf.getOpenid(), sf.getName(), json);
            }else{
                JSONObject j =  weiXinOpenIdUtils.getFamilyOpenId(patient);
                Patient member = (Patient)j.get("member");
                if(StringUtils.isNotBlank(member.getOpenid())){
                    String first = (String)json.get("first");
            } else {
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(patient);
                Patient member = (Patient) j.get("member");
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    String first = (String) json.get("first");
                    json.remove("first");
                    Patient p = patientDao.findByCode(patient);
                    json.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
                    PushMsgTask.getInstance().putWxMsg(access_token, 5, member.getOpenid(), member.getName(), json);
                }
            }
@ -1853,14 +1854,14 @@ public class FamilyContractService extends BaseService {
                    result.put("msg", "与当前健管师有未结束的咨询");
                    return result;
                }
                try{
                    if(signFamily.getDoctorHealth().equals(signFamily.getDoctor())){
                        ImUtill.deleteMucUser(healthDoctor,"",patient+"_"+signFamily.getTeamCode()+"_2");
                    }else{
                        ImUtill.deleteMucUser(healthDoctor,signFamily.getDoctorHealth(),patient+"_"+signFamily.getTeamCode()+"_2");
                try {
                    if (signFamily.getDoctorHealth().equals(signFamily.getDoctor())) {
                        ImUtill.deleteMucUser(healthDoctor, "", patient + "_" + signFamily.getTeamCode() + "_2");
                    } else {
                        ImUtill.deleteMucUser(healthDoctor, signFamily.getDoctorHealth(), patient + "_" + signFamily.getTeamCode() + "_2");
                    }
                }catch (Exception e){
                } catch (Exception e) {
                    result.put("status", -1);
                    result.put("msg", e.getMessage());
                    return result;
@ -1903,9 +1904,9 @@ public class FamilyContractService extends BaseService {
                    data.put("remark", docHealth.getName() + "医生与" + signFamily.getDoctorName() + "医生一道,为您提供优质健康服务");
                }
                wxMessages.add(data);
                try{
                    ImUtill.deleteMucUser(docHealth.getCode(),"",patient+"_"+signFamily.getTeamCode()+"_2");
                }catch (Exception e){
                try {
                    ImUtill.deleteMucUser(docHealth.getCode(), "", patient + "_" + signFamily.getTeamCode() + "_2");
                } catch (Exception e) {
                    result.put("status", -1);
                    result.put("msg", e.getMessage());
                    return result;
@ -1949,9 +1950,9 @@ public class FamilyContractService extends BaseService {
            String oldDoctorName = signFamily.getDoctorName();
            if (StringUtils.isNotEmpty(signFamily.getDoctor())) {
                DoctorTeamMember teamMember = doctorTeamDoctor.findMemberByTeamAndQkCode(signFamily.getTeamCode(), signFamily.getDoctor());
                 try{
                    ImUtill.deleteMucUser(doctor,signFamily.getDoctor(),patient+"_"+signFamily.getTeamCode()+"_2");
                }catch (Exception e){
                try {
                    ImUtill.deleteMucUser(doctor, signFamily.getDoctor(), patient + "_" + signFamily.getTeamCode() + "_2");
                } catch (Exception e) {
                    result.put("status", -1);
                    result.put("msg", e.getMessage());
                    return result;
@ -2014,19 +2015,19 @@ public class FamilyContractService extends BaseService {
        for (JSONObject msg : wxMessages) {
            if(StringUtils.isNotBlank(p.getOpenid())){
            if (StringUtils.isNotBlank(p.getOpenid())) {
                PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, p.getOpenid(), p.getName(), msg);
            }else{
            } else {
                //如果自己没有绑定,则发给家人
                JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                Patient member = (Patient)j.get("member");
                if(StringUtils.isNotBlank(member.getOpenid())){
                    String first = (String)msg.get("first");
                Patient member = (Patient) j.get("member");
                if (StringUtils.isNotBlank(member.getOpenid())) {
                    String first = (String) msg.get("first");
                    msg.remove("first");
                    try{
                        msg.put("first",weiXinOpenIdUtils.getTitleMes(p,j.getInt("relation"),member.getName()));
                    }catch (Exception e){
                    try {
                        msg.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), member.getName()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    PushMsgTask.getInstance().putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), msg);
@ -2050,7 +2051,7 @@ public class FamilyContractService extends BaseService {
        return result;
    }
    public JSONObject findByParamsWithDoctor(String doctorCode, String teamCode, String params,int level) throws Exception {
    public JSONObject findByParamsWithDoctor(String doctorCode, String teamCode, String params, int level) throws Exception {
        JSONObject returnMap = new JSONObject();
        String addressSql = "select a.signcode,a.name,a.address,a.code,a.hasopenid,a.idcard,a.photo from( SELECT " +
                "  sf.CODE signcode, " +
@ -2068,11 +2069,11 @@ public class FamilyContractService extends BaseService {
                " AND sf. STATUS > 0 " +
                // " and sf.doctor = ? " +
                " and sf.admin_team_code = ? " +
                " AND ( "+(level==2?"sf.doctor =?":"sf.doctor_health =? ")+") ) a where 1=1";
                " AND ( " + (level == 2 ? "sf.doctor =?" : "sf.doctor_health =? ") + ") ) a where 1=1";
        if (!org.springframework.util.StringUtils.isEmpty(params)) {
            addressSql += " AND a.address like '%" + params + "%'";
        }
        List<Map<String, Object>> datas = jdbcTemplate.queryForList(addressSql, teamCode,doctorCode);
        List<Map<String, Object>> datas = jdbcTemplate.queryForList(addressSql, teamCode, doctorCode);
        if (datas != null && datas.size() > 0) {
            JSONArray jsonArray = new JSONArray();
            for (Map<String, Object> map : datas) {
@ -2105,12 +2106,12 @@ public class FamilyContractService extends BaseService {
                " AND sf. STATUS > 0 " +
                //" and sf.doctor = ? " +
                " and sf.admin_team_code = ? " +
                " AND ( "+(level==2?"sf.doctor =?":"sf.doctor_health =? ")+") ) a where 1=1";
                " AND ( " + (level == 2 ? "sf.doctor =?" : "sf.doctor_health =? ") + ") ) a where 1=1";
        if (!org.springframework.util.StringUtils.isEmpty(params)) {
            patientNameSql += " AND a.name like '%" + params + "%'";
        }
        datas = jdbcTemplate.queryForList(patientNameSql, teamCode,doctorCode);
        datas = jdbcTemplate.queryForList(patientNameSql, teamCode, doctorCode);
        if (datas != null && datas.size() > 0) {
            JSONArray jsonArray = new JSONArray();
            for (Map<String, Object> map : datas) {
@ -2460,12 +2461,13 @@ public class FamilyContractService extends BaseService {
    /**
     * 根据会话信息拉取对应的人员信息
     *
     * @param sessionId
     * @return
     */
    public JSONObject getTeamDoctors(String sessionId,String doctor){
    public JSONObject getTeamDoctors(String sessionId, String doctor) {
        String infos[] = sessionId.split("_");
        String patient  = infos[0];
        String patient = infos[0];
        JSONObject result = new JSONObject();
        Map<String, JSONObject> docMap = new HashMap<>();
        SignFamily ssSign = signFamilyDao.findSignByPatient(patient, 1);
@ -2532,7 +2534,7 @@ public class FamilyContractService extends BaseService {
    public JSONObject getPatientSignDoctorsByTeam(String sessionId) {
        String infos[] =sessionId.split("_");
        String infos[] = sessionId.split("_");
        JSONObject result = new JSONObject();
        Map<String, JSONObject> docMap = new HashMap<>();
        SignFamily ssSign = signFamilyDao.findSignByPatient(infos[0], 1);
@ -2631,6 +2633,79 @@ public class FamilyContractService extends BaseService {
        return returnMap;
    }
    //根据姓名、地址、身份证搜索已分配健管师的居民
    public List getPatientByLable(String doctorCode, String filter, String level, Long team,int page,int pagesize) throws Exception {
        List list = new ArrayList();
        //判断当前用户是健康管理师还是全科
        List<Map<String, Object>> datas = null;
        if (level.equals("3")) {
            //健康管理师
            String sql = "SELECT DISTINCT " +
                    "  p.photo photo, " +
                    "  p.name name, " +
                    "  p.code code, " +
                    "  p.sex sex," +
                    "  p.address address," +
                    "  p.idcard idcard " +
                    " FROM " +
                    " wlyy_sign_family sf " +
                    " JOIN wlyy_patient p ON sf.patient = p.CODE " +
                    " left JOIN wlyy_sign_patient_label_info sp ON sf.patient = sp.patient AND sp.`status` = 1 " +
                    " WHERE " +
                    " sf.type = 2 " +
                    " AND sf. STATUS > 0 " +
                    " and sf.doctor_health = ? " +
                    " and sf.admin_team_code = ? " +
                    " AND (p.name like ? or p.address like ? or p.idcard like ? ) " +
                    " ORDER BY  p.name DESC,p.address DESC, p.idcard DESC " +
                    " limit "+(page-1)+","+pagesize;
            //查找居民
            datas = jdbcTemplate.queryForList(sql, doctorCode, team,"%"+filter+"%","%"+filter+"%","%"+filter+"%");
        } else if (level.equals("2")) {
            //全科
            String sql = "SELECT  DISTINCT " +
                    "  p.photo photo, " +
                    "  p.name name, " +
                    "  p.code code, " +
                    "  p.sex sex," +
                    "  p.address address," +
                    "  p.idcard idcard " +
                    " FROM " +
                    " wlyy_sign_family sf " +
                    " JOIN wlyy_patient p ON sf.patient = p.CODE " +
                    " left JOIN wlyy_sign_patient_label_info sp ON sf.patient = sp.patient AND sp.`status` = 1 " +
                    " WHERE " +
                    " sf.type = 2 " +
                    " AND sf. STATUS > 0 " +
                    " and  sf.doctor = ?  " +
                    " and sf.admin_team_code = ? " +
                    " AND (p.name like ? or p.address like ? or p.idcard like ? ) " +
                    " ORDER BY  p.name DESC,p.address DESC, p.idcard DESC " +
                    " limit "+(page-1)+","+pagesize;
            //查找居民
            datas = jdbcTemplate.queryForList(sql, doctorCode, team,"%"+filter+"%","%"+filter+"%","%"+filter+"%");
        } else {
            throw new Exception("参数错误!");
        }
        if (datas != null && datas.size() > 0) {
            for (Map<String, Object> map : datas) {
                Map ma = new HashMap();
                ma.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard")==null?"":map.get("idcard").toString()));
                ma.put("photo",map.get("photo")==null?"":map.get("photo").toString());
                ma.put("name",map.get("name")==null?"":map.get("name").toString());
                ma.put("code",map.get("code")==null?"":map.get("code").toString());
                ma.put("sex",map.get("sex")==null?"":map.get("sex").toString());
                ma.put("address",map.get("address")==null?"":map.get("address").toString());
                ma.put("idcard",map.get("idcard")==null?"":map.get("idcard").toString());
                list.add(ma);
            }
        }
        return list;
    }
    public JSONObject getPatientByLable(String doctorCode, String labelType, String level, Long team) throws Exception {
        JSONObject returnMap = new JSONObject();
        //判断当前用户是健康管理师还是全科

+ 14 - 4
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java

@ -95,9 +95,10 @@ public class StatisticsService extends BaseService {
     * @param endDate 截止日期
     * @param area    区域或机构代码
     * @param level   级别
     * @param level2_type   level2_type的类型
     * @return
     */
    public long getTotalAmount(String endDate, String area, int level, String index) {
    public long getTotalAmount(String endDate, String area, int level, String index,String level2_type) {
        int todayAmount = 0;
        // 查询语句
@ -123,6 +124,10 @@ public class StatisticsService extends BaseService {
            sql += " and qkdoctor_code = ?";
        }
        if(StringUtils.isNoneEmpty(level2_type)){
            sql+=" and level2_type = '"+level2_type+"'";
        }
        Map<String, Object> result = jdbcTemplate.queryForMap(sql, new Object[]{level, endDate, area});
        // 截止日期包含当天,则从redis查询当天统计数据
@ -219,7 +224,7 @@ public class StatisticsService extends BaseService {
     * @param level   级别
     * @return
     */
    public JSONArray getLowLevelTotalDetail(String endDate, String area, int level, String index, int sort, String lowLevel) throws Exception {
    public JSONArray getLowLevelTotalDetail(String endDate, String area, int level, String index, int sort, String lowLevel,String level2_type) throws Exception {
        String areaField = "";
        String lowLevelField = "";
        String lowLevelName = "";
@ -271,8 +276,13 @@ public class StatisticsService extends BaseService {
                "     quato_code = '" + index + "' " +
                "   and level1_type = ? and del = '1'" +
                "   and quota_date <= ? " +
                "   and " + areaField + " = ? " +
                " group by " + lowLevelField + "," + lowLevelName;
                "   and " + areaField + " = ? " ;
        if(org.apache.commons.lang3.StringUtils.isNoneEmpty(level2_type)){
            sql+=" and level2_type = '"+level2_type+"'";
        }
        sql+=   " group by " + lowLevelField + "," + lowLevelName;
        if (sort == 1) {
            sql += " order by amount desc";

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/team/AdminTeamService.java

@ -339,7 +339,7 @@ public class AdminTeamService extends BaseService {
        SignFamily ssSign = signFamilyDao.findSignByPatient(patient, 1);
        SignFamily jtSign = signFamilyDao.findSignByPatient(patient, 2);
        if (ssSign != null && (doctor.equals(ssSign.getDoctor())
        if (ssSign != null&&ssSign.getAdminTeamId()!=null && (doctor.equals(ssSign.getDoctor())
                || doctor.equals(ssSign.getDoctorHealth()))) {
            AdminTeam team = getTeam(ssSign.getAdminTeamId());
            result.put(new JSONObject(team));

+ 81 - 98
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java

@ -90,9 +90,11 @@ public class ManagerQuestionnaireService extends BaseService {
    @Autowired
    WeiXinOpenIdUtils weiXinOpenIdUtils;
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    public String createSurvey(String doctor, JSONObject jsonStr, String accessToken) throws Exception {
        System.out.println("=============>" + jsonStr);
        System.out.println("createSurvey ======》" + jsonStr);
//        问卷信息
        String surveyCode = getCode();
        String surveyName = jsonStr.getString("surveyName");
@ -114,12 +116,7 @@ public class ManagerQuestionnaireService extends BaseService {
        JSONArray disease = surveyTarget.getJSONArray("disease");
        JSONArray service = surveyTarget.getJSONArray("service");
        JSONArray healthCondition = surveyTarget.getJSONArray("healthCondition");
        /*String str = "SELECT DISTINCT t.patient  " +
                "FROM `wlyy_sign_patient_label_info` t,wlyy_patient p,`wlyy_sign_family` f  " +
                "WHERE t.`patient` =  p.`code`  AND f.`patient`=t.`patient` AND f.`status` IN (1,2,3) AND p.`openid` IS NOT NULL AND p.`openid`!='' ";*/
        //      保存到维度详情表(不限不保存)  维度表(1性别 2疾病类型 3服务类型 4健康状况)
        if (sex != 0) {
//            str += "AND(p.sex=" + sex + ")";
            String dimensionCode = surveyDimensionDao.findByName("性别");
            String dimensionDetailCode = getCode();
            SurveyDimensionDetail surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, sex == 1 ? "男" : "女", sex, "性别", 1, surveyCode);
@ -128,15 +125,11 @@ public class ManagerQuestionnaireService extends BaseService {
            SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
            surveyFilterDao.save(surveyFilter);
        }
//        String ser = "";
//        String servi = "";
        for (Object serv : service) {
            if ("0".equals(serv.toString())) {
//                ser += ",";
                break;
            } else {
//                ser += serv.toString() + ",";
                //                ===================================
//                       ===================================
                String dimensionCode = surveyDimensionDao.findByName("服务类型");
                String dimensionDetailCode = getCode();
                SurveyDimensionDetail surveyDimensionDetail = null;
@ -159,18 +152,10 @@ public class ManagerQuestionnaireService extends BaseService {
                surveyFilterDao.save(surveyFilter);
            }
        }
        /*ser = ser.substring(0, ser.length() - 1);
        if (ser.length() != 0) {
            servi = "(t.`label_type`=1 AND t.`label`IN(" + ser + "))";
        }*/
//        String heal = "";
//        String healt = "";
        for (Object health : healthCondition) {
            if ("0".equals(health.toString())) {
//                heal += ",";
                break;
            } else {
//                heal += health.toString() + ",";
                String dimensionCode = surveyDimensionDao.findByName("健康状况");
                String dimensionDetailCode = getCode();
                String surveyFilterCode = getCode();
@ -197,19 +182,11 @@ public class ManagerQuestionnaireService extends BaseService {
            }
        }
       /* heal = heal.substring(0, heal.length() - 1);
        if (heal.length() != 0) {
            healt = "(t.`label_type`=2 AND t.`label`IN(" + heal + "))";
        }*/
//        String dise = "";
//        String diseas = "";
        for (Object disea : disease) {
            if ("0".equals(disea.toString())) {
//                dise += ",";
                break;
            } else {
//                dise += disea.toString() + ",";
//                ================================================================
                String dimensionCode = surveyDimensionDao.findByName("疾病类型");
                String dimensionDetailCode = getCode();
                SurveyDimensionDetail surveyDimensionDetail = null;
@ -228,73 +205,37 @@ public class ManagerQuestionnaireService extends BaseService {
                surveyFilterDao.save(surveyFilter);
            }
        }
        /*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;
        }*/
       /* System.out.println("*****************str***********************" + str);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        sdf.format(new Date());
        String jsonData = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
        JSONObject json = new JSONObject(jsonData);
        json.put("survey_id", surveyCode);*/
//        List<Map<String, Object>> patients = jdbcTemplate.queryForList(str);
//        Map<String, Object> map = jdbcTemplate.queryForMap(str);
//        List<String> codes = jdbcTemplate.queryForList(str, String.class);
        List<String> codes = getCount(surveyTarget.toString());
        int amount = codes.size();
        for (String code : codes) {
//            String code = patient.get("patient").toString();
            SurveyUser user = new SurveyUser(surveyCode, code, 0, 1, new Date(), new Date());
            surveyUserDao.save(user);
//            发送居民模板 send=1发送
           /* if ("1".equals(send)) {
                String name = patient.get("name").toString();
                String openId = patient.get("openid").toString();
//            String openId = "o7NFZw1QM4YR1O19mLjwfX1Hh11A";
                json.put("keyword2", sdf.format(new Date()));
                json.put("toUser", code);
                json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                System.out.println("*************************" + json + "******************");
                System.out.println("********name*********************" + name + "openId" + openId);
                PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, openId, name, json);
            }*/
        }
        //            发送居民模板 send=1发送
//        ====================================================
        if ("1".equals(send)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
            JSONObject json = new JSONObject(str);
            codes.stream().forEach(c -> {
                Patient p = patientDao.findByCode(c);
 /*           for (String code : codes) {
//            codes.stream().forEach(c -> {
//                Patient p = patientDao.findByCode(c);
                Patient p = patientDao.findByCode(code);
                String name = p.getName();
                String openId = p.getOpenid();
                json.put("keyword2", sdf.format(new Date()));
                json.put("toUser", c);
//                json.put("toUser", c);
                json.put("toUser", code);
                json.put("survey_id", surveyCode);
                json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                logger.error("patient =======>" + code);
                logger.error("name =======>" + name);
                logger.error("openId =======>" + openId);
                //判断是否判定openId,有没有发则查找家人发送
                //判断是否有openId,有发送没有则查找家人发送
                if (StringUtils.isNotBlank(p.getOpenid())) {
                    // 添加到发送队列
                    logger.error("json =======>" + json);
                    PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
                } else {
                    JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getOpenid());
@ -307,10 +248,47 @@ public class ManagerQuestionnaireService extends BaseService {
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        logger.error("没有opIn  json =======>" + json);
                        PushMsgTask.getInstance().putWxMsg(accessToken, 11, member.getOpenid(), member.getName(), json);
                    }
                }
            });
//            });
            }*/
            new Thread() {
                public void run() {
                    for (String c : codes) {
                        Patient p = patientDao.findByCode(c);
                        String name = p.getName();
                        String openId = p.getOpenid();
                        json.put("keyword2", sdf.format(new Date()));
                        json.put("toUser", c);
                        json.put("survey_id", surveyCode);
                        json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                        //判断是否判定openId,有没有发则查找家人发送
                        if (StringUtils.isNotBlank(p.getOpenid())) {
                            // 添加到发送队列
                            logger.error("json =======>" + json);
//                            PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
                            PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, openId, name, json);
                        } else {
                            JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getOpenid());
                            Patient member = (Patient) j.get("member");
                            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) {
                                    e.printStackTrace();
                                }
                                logger.error("没有opIn  json =======>" + json);
//                                PushMsgTask.getInstance().putWxMsg(accessToken, 11, member.getOpenid(), member.getName(), json);
                                PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, member.getOpenid(), member.getName(), json);
                            }
                        }
                    }
                }
            }.start();
        }
//       =====================================================
//     获取标签数组
@ -363,7 +341,6 @@ public class ManagerQuestionnaireService extends BaseService {
                    surveyQuestionnaire.setQuestionCodeNext(qstNextQuestion);
                    surveyQuestionnaireDao.save(surveyQuestionnaire);
                    System.out.println("=====================================");
                    //                        =======================选项保存=========================
                    //                选择题
                    JSONArray options = new JSONArray(tempQestion.get("options").toString());
@ -402,7 +379,6 @@ public class ManagerQuestionnaireService extends BaseService {
                        SurveyStatistics statistics = new SurveyStatistics(statisticsCode, surveyCode, questionnaireCode, questionTitle, optionCode, 0, optcontent, haveComment, type, sort, optionSort);
                        surveyStatisticsDao.save(statistics);
                    }
//                        ===============================================================
                    break;
                case 1:
//            多选特有属性
@ -1215,7 +1191,6 @@ public class ManagerQuestionnaireService extends BaseService {
        jsonObject.put("comment", tempComment);
        jsonObject.put("label", labels);
        jsonObject.put("questions", questions);
        System.out.println("==========jsonObject============" + jsonObject);
        return jsonObject;
    }
@ -1299,6 +1274,7 @@ public class ManagerQuestionnaireService extends BaseService {
        String title = survey.getTitle();
        String templateComment = survey.getSurveyComment();
//        查询问卷标题重复情况
//       int number = surveyTemplatesDao.distinctByTitle(title);
        int number = 0;
        if (StringUtils.isEmpty(modifyTitle)) {
            number = surveyTemplatesDao.distinctByTitle(title);
@ -1306,7 +1282,7 @@ public class ManagerQuestionnaireService extends BaseService {
            number = surveyTemplatesDao.distinctByTitle(modifyTitle);
            title = modifyTitle;
        }
        if (number != 0 && StringUtils.isEmpty(modifyTitle)) {
        if (number != 1 && StringUtils.isEmpty(modifyTitle)) {
            int likeNum = surveyTemplatesDao.distinctLikeTitle(title + "%");
            return likeNum;
        }
@ -1314,20 +1290,15 @@ public class ManagerQuestionnaireService extends BaseService {
            int likeNum = surveyTemplatesDao.distinctLikeTitle(modifyTitle + "%");
            return likeNum;
        }
//        SurveyTemplates surveyTemplates = new SurveyTemplates(templateCode, title, templateComment, creater, 1, creater, updateTime);
//        更改模板信息
//        surveyTemplatesDao.save(surveyTemplates);
        surveyTemplatesDao.modifyTemplate(templateCode, title, templateComment);
        List<SurveyLabelInfo> surveyLabelInfos = surveyLabelInfoDao.findByCode(code);
        for (SurveyLabelInfo surveyLabelInfo : surveyLabelInfos) {
//        更改模板标签信息
//            SurveyLabelInfo surveyLabelInfo1 = new SurveyLabelInfo(getCode(), templateCode, 0, surveyLabelInfo.getLabel());
//            surveyLabelInfoDao.save(surveyLabelInfo1);
            surveyLabelInfoDao.modifyLabel(templateCode, surveyLabelInfo.getLabel());
        }
        List<SurveyQuestionnaire> surveyQuestionnaires = surveyQuestionnaireDao.findById(code);
        for (SurveyQuestionnaire question : surveyQuestionnaires) {
//            String qstCode = getCode();
            String qstCode = question.getCode();
            String qstTitle = question.getTitle();
            String qstComment = question.getQuestionComment();
@ -1335,26 +1306,38 @@ public class ManagerQuestionnaireService extends BaseService {
            Integer isRequired = question.getIsRequired();
            Integer minNum = question.getMinNum();
            Integer maxNum = question.getMaxNum();
//            Date createTiem = question.getCreateTime();
//            Date updateTiem = question.getUpdateTime();
            Integer sort = question.getSort();
//            Integer de = question.getDel();
            String next = question.getQuestionCodeNext();
//            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);
            //            更改问题到模板问题表(修改模板新增的问题怎么办?)
            System.out.println(templateCode + "," + qstCode + qstTitle + "," + qstComment + "," + qstType + "," + isRequired + "," + minNum + "," + maxNum + "," + sort + "," + next);
            int rows = surveyTemplateQuestionsDao.modifyQuestion(templateCode, qstCode, qstTitle, qstComment, qstType, isRequired, minNum, maxNum, sort, next);
//            新增问题直接保存
            if (rows == 0) {
                Integer de = question.getDel();
                Date createTiem = question.getCreateTime();
                Date updateTiem = question.getUpdateTime();
                SurveyTemplateQuestions surveyTemplateQuestions = new SurveyTemplateQuestions(qstCode, qstTitle, qstComment, qstType, templateCode, isRequired, minNum, maxNum, sort, next, null, de, createTiem, updateTiem);
                surveyTemplateQuestionsDao.save(surveyTemplateQuestions);
            }
            if (qstType != 2) {
                List<SurveyQuestionnaireOptions> surveyQuestionnaireOptions = surveyQuestionnaireOptionsDao.findByIdAndQstCode(code, question.getCode());
//                问卷的选项编码都是新增的,不是从模板里复用的
                for (SurveyQuestionnaireOptions option : surveyQuestionnaireOptions) {
                    SurveyTemplateOptions surveyTemplateOptions = new SurveyTemplateOptions(getCode(), option.getHaveComment(), qstCode, option.getContent(),
                            templateCode, option.getQuestionCodeNext(), null, option.getIsRequired(), option.getSort(), option.getDel());
                    //         更改到模板选项表   survey_template_options
//                    surveyTemplateOptionsDao.save(surveyTemplateOptions);
                    surveyTemplateOptionsDao.modifyOption(templateCode, qstCode, option.getCode(),
                            option.getHaveComment(), option.getContent(), option.getQuestionCodeNext(), option.getIsRequired(), option.getSort());
                    System.out.println("=============>");
                    String optCode = option.getCode();
                    Integer have = option.getHaveComment();
                    String content = option.getContent();
                    String nextCode = option.getQuestionCodeNext();
                    Integer required = option.getIsRequired();
                    Integer optsort = option.getSort();
                    int row = surveyTemplateOptionsDao.modifyOption(templateCode, qstCode, optCode, have, content, nextCode, required, optsort);
//            新增问题的选项直接保存
                    if (row == 0) {
                        Integer del = option.getDel();
                        SurveyTemplateOptions surveyTemplateOptions = new SurveyTemplateOptions(optCode, have, qstCode, content,
                                templateCode, nextCode, null, required, optsort, del);
                        surveyTemplateOptionsDao.save(surveyTemplateOptions);
                    }
                }
            }
        }

+ 4 - 64
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/PatientQuestionnaireService.java

@ -6,6 +6,8 @@ import com.yihu.wlyy.service.BaseService;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -32,6 +34,7 @@ public class PatientQuestionnaireService extends BaseService {
    private SurveyAnswersDao surveyAnswersDao;
    @Autowired
    SurveyStatisticsDao surveyStatisticsDao;
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    public JSONObject getSurveySummary(String patient, String id) throws Exception {
        JSONObject jsonObject = new JSONObject();
@ -159,72 +162,9 @@ public class PatientQuestionnaireService extends BaseService {
        jsonObject.put("sort", sorts);
//        题目数量是变量
        jsonObject.put("totalNum", total);
        logger.error("居民获取题目信息==》" + jsonObject);
        return jsonObject;
    }
//==================================原来========================================
/*public JSONObject getQuestions(String id, Integer sort, Integer pageNo, Integer total, String nextCode) throws  Exception{
    JSONObject jsonObject = new JSONObject();
    SurveyQuestionnaire question = null;
    int sorts = 0;
    if (!StringUtils.isEmpty(nextCode)) {
//            跳题
//            question = surveyQuestionnaireDao.findByIdAndSort(id, Integer.parseInt(nextCode));
        question = surveyQuestionnaireDao.findByIdAndQstId(id,nextCode);
        sorts = question.getSort();
        total = total - (sorts -(sort + 1));
    } else {
//            不跳题
        if (total == null) {
            //      该套问卷总题目数
            total = surveyQuestionnaireDao.findTotalById(id);
        }
        question = surveyQuestionnaireDao.findTotalByIdAndSort(id, sort + 1);
        sorts = question.getSort();
    }
    String qstCode = question.getCode();
    String qstTitle = question.getTitle();
    int isRequired = question.getIsRequired();
    int type = question.getQuestionType();
//        int sorts = question.getSort();
    switch (type) {
        case 0:
            List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findById(qstCode);
            for (SurveyQuestionnaireOptions option : options) {
                String content = option.getContent();
//                        可构造集合,返回选项特定值
            }
            jsonObject.put("options", options);
            break;
        case 1:
            List<SurveyQuestionnaireOptions> optionss = surveyQuestionnaireOptionsDao.findById(qstCode);
            for (SurveyQuestionnaireOptions option : optionss) {
                String content = option.getContent();
            }
            int maxNum = question.getMaxNum();
            int minNum = question.getMinNum();
            jsonObject.put("maxNum", maxNum);
            jsonObject.put("minNum", minNum);
            jsonObject.put("options", optionss);
            break;
        case 2:
            String questionCodeNext = question.getQuestionCodeNext();
            jsonObject.put("questionCodeNext", questionCodeNext);
            break;
    }
    jsonObject.put("qstCode", qstCode);
    jsonObject.put("qstTitle", qstTitle);
    jsonObject.put("isRequired", isRequired);
    jsonObject.put("type", type);
    jsonObject.put("sort", sorts);
//        题目数量是变量
    jsonObject.put("totalNum", total);
    jsonObject.put("percent", (Math.round(((float) pageNo / total) * 100)) + "%");
    return jsonObject;
}*/
//    ======================================================================================
    public void saveAnswer(String patient, JSONObject jsonData) throws Exception {
        System.out.println("********jsonData********* " + jsonData);

+ 98 - 121
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/jw/JwSmjkService.java

@ -50,7 +50,7 @@ public class JwSmjkService {
    /**
     * 获取门/急诊记录 + 住院记录
     */
    public String getResidentEventListJson(String strSSID,String type,String page,String pageSize)
    public String getResidentEventListJson(String strSSID,String type,String page,String pageSize)  throws Exception
    {
        if(SystemConf.getInstance().getEhrUsed())     //演示环境
        {
@ -58,40 +58,35 @@ public class JwSmjkService {
        }
        else {
            String re = "";
            try {
                String url = jwUrl + "/third/smjk/ResidentEventList";
            String url = jwUrl + "/third/smjk/ResidentEventList";
                List<NameValuePair> params = new ArrayList<>();
                params.add(new BasicNameValuePair("strSSID", strSSID));
                if (!StringUtils.isEmpty(type)) {
                    params.add(new BasicNameValuePair("type", type));
                }
                params.add(new BasicNameValuePair("page", page));
                params.add(new BasicNameValuePair("pageSize", pageSize));
                String response = HttpClientUtil.post(url, params, "UTF-8");
                if (!StringUtils.isEmpty(response)) {
                    JSONObject responseObject = new JSONObject(response);
                    int status = responseObject.getInt("status");
                    if (status == 200) {
                        String data = responseObject.getString("data");
                        if (!StringUtils.isEmpty(data) && data.startsWith("error")) {
                            throw new Exception(data);
                        } else {
                            JSONObject jsonData = new JSONObject(data);
                            JSONArray jsonArray = jsonData.getJSONArray("EventList");
                            re = jsonArray.toString();
                        }
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            if (!StringUtils.isEmpty(type)) {
                params.add(new BasicNameValuePair("type", type));
            }
            params.add(new BasicNameValuePair("page", page));
            params.add(new BasicNameValuePair("pageSize", pageSize));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            if (!StringUtils.isEmpty(response)) {
                JSONObject responseObject = new JSONObject(response);
                int status = responseObject.getInt("status");
                if (status == 200) {
                    String data = responseObject.getString("data");
                    if (!StringUtils.isEmpty(data) && data.startsWith("error")) {
                        throw new Exception(data);
                    } else {
                        throw new Exception(responseObject.getString("msg"));
                        JSONObject jsonData = new JSONObject(data);
                        JSONArray jsonArray = jsonData.getJSONArray("EventList");
                        re = jsonArray.toString();
                    }
                } else {
                    throw new Exception("null response.");
                    throw new Exception(responseObject.getString("msg"));
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            } else {
                throw new Exception("null response.");
            }
            if(re.contains("[{}]"))
@ -106,91 +101,80 @@ public class JwSmjkService {
    /**
     * 通过event获取档案类型列表
     */
    public String getEventCatalog(String strSSID,String strEvent)
    public String getEventCatalog(String strSSID,String strEvent)  throws Exception
    {
        if(SystemConf.getInstance().getEhrUsed())     //演示环境
        {
            return "";
        }
        else {
            try {
                String url = jwUrl + "/third/smjk/EventCatalog";
                List<NameValuePair> params = new ArrayList<>();
                params.add(new BasicNameValuePair("strSSID", strSSID));
                params.add(new BasicNameValuePair("strEvent", strEvent));
                String response = HttpClientUtil.post(url, params, "UTF-8");
                String result = "";
                if (!StringUtils.isEmpty(response)) {
                    JSONObject jsonObject = new JSONObject(response);
                    int status = jsonObject.getInt("status");
                    if (status == 200) {
                        result = jsonObject.getString("data");
                    }
                    else {
                        throw new Exception(jsonObject.getString("msg"));
            String url = jwUrl + "/third/smjk/EventCatalog";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            params.add(new BasicNameValuePair("strEvent", strEvent));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            String result = "";
            if (!StringUtils.isEmpty(response)) {
                JSONObject jsonObject = new JSONObject(response);
                int status = jsonObject.getInt("status");
                if (status == 200) {
                    result = jsonObject.getString("data");
                    if (result.startsWith("error")) {
                        throw new Exception(result);
                    }
                }
                else {
                    throw new Exception("null response.");
                    throw new Exception(jsonObject.getString("msg"));
                }
                return result;
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
                return "";
            else {
                throw new Exception("null response.");
            }
            return result;
        }
    }
    /**
     * 获取健康档案信息详情
     */
    public String getHealthData(String strSSID, String strEvent, String strCatalog, String strSerial) {
    public String getHealthData(String strSSID, String strEvent, String strCatalog, String strSerial) throws Exception {
        if(SystemConf.getInstance().getEhrUsed())     //演示环境
        {
            return ehrService.getHealthData(strSSID,strEvent,strCatalog,strSerial);
        }
        else {
            try {
                String url = jwUrl + "/third/smjk/HealthData";
                List<NameValuePair> params = new ArrayList<>();
                params.add(new BasicNameValuePair("strSSID", strSSID));
                params.add(new BasicNameValuePair("strEvent", strEvent));
                params.add(new BasicNameValuePair("strCatalog", strCatalog));
                params.add(new BasicNameValuePair("strSerial", strSerial));
                String response = HttpClientUtil.post(url, params, "UTF-8");
                String result = "";
                if (!StringUtils.isEmpty(response)) {
                    JSONObject jsonObject = new JSONObject(response);
                    int status = jsonObject.getInt("status");
                    if (status == 200) {
                        result = jsonObject.getString("data");
                        result = result.replaceAll("<\\?xml version=\"1.0\" encoding=\"utf-8\"\\?>", "");
                        if (result.startsWith("error")) {
                            throw new Exception(result);
                        }
                    }
                    else {
                        throw new Exception(jsonObject.getString("msg"));
            String url = jwUrl + "/third/smjk/HealthData";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            params.add(new BasicNameValuePair("strEvent", strEvent));
            params.add(new BasicNameValuePair("strCatalog", strCatalog));
            params.add(new BasicNameValuePair("strSerial", strSerial));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            String result = "";
            if (!StringUtils.isEmpty(response)) {
                JSONObject jsonObject = new JSONObject(response);
                int status = jsonObject.getInt("status");
                if (status == 200) {
                    result = jsonObject.getString("data");
                    result = result.replaceAll("<\\?xml version=\"1.0\" encoding=\"utf-8\"\\?>", "");
                    if (result.startsWith("error")) {
                        throw new Exception(result);
                    }
                }
                else {
                    throw new Exception("null response.");
                    throw new Exception(jsonObject.getString("msg"));
                }
                return result;
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
                return "";
            else {
                throw new Exception("null response.");
            }
            return result;
        }
    }
@ -198,54 +182,47 @@ public class JwSmjkService {
    /**
     * 获取检查检验列表
     */
    public String getExamAndLabReport(String strSSID,String page,String pageSize)
    public String getExamAndLabReport(String strSSID,String page,String pageSize) throws Exception
    {
        if(SystemConf.getInstance().getEhrUsed())     //演示环境
        {
            return "";
        }
        else {
            try {
                String url = jwUrl + "/third/smjk/ExamAndLabReport";
                List<NameValuePair> params = new ArrayList<>();
                params.add(new BasicNameValuePair("strSSID", strSSID));
                params.add(new BasicNameValuePair("page", page));
                params.add(new BasicNameValuePair("pageSize", pageSize));
                String response = HttpClientUtil.post(url, params, "UTF-8");
                String re = "";
                if (!StringUtils.isEmpty(response)) {
                    JSONObject jsonObject = new JSONObject(response);
                    int status = jsonObject.getInt("status");
                    if (status == 200) {
                        String data = jsonObject.getString("data");
                        if (!StringUtils.isEmpty(data) && data.startsWith("error")) {
                            throw new Exception(data);
                        } else {
                            JSONObject jsonData = new JSONObject(data);
                            JSONArray jsonArray = jsonData.getJSONArray("EhrList");
                            re = jsonArray.toString();
                        }
            String url = jwUrl + "/third/smjk/ExamAndLabReport";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            params.add(new BasicNameValuePair("page", page));
            params.add(new BasicNameValuePair("pageSize", pageSize));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            String re = "";
            if (!StringUtils.isEmpty(response)) {
                JSONObject jsonObject = new JSONObject(response);
                int status = jsonObject.getInt("status");
                if (status == 200) {
                    String data = jsonObject.getString("data");
                    if (!StringUtils.isEmpty(data) && data.startsWith("error")) {
                        throw new Exception(data);
                    } else {
                        throw new Exception(jsonObject.getString("msg"));
                        JSONObject jsonData = new JSONObject(data);
                        JSONArray jsonArray = jsonData.getJSONArray("EhrList");
                        re = jsonArray.toString();
                    }
                } else {
                    throw new Exception("null response.");
                }
                if(re.contains("[{}]"))
                {
                    re = re.replace("[{}]","[]");
                    throw new Exception(jsonObject.getString("msg"));
                }
                return re;
            } else {
                throw new Exception("null response.");
            }
            catch (Exception ex)
            if(re.contains("[{}]"))
            {
                ex.printStackTrace();
                return "";
                re = re.replace("[{}]","[]");
            }
            return re;
        }
    }

+ 18 - 12
patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java

@ -91,6 +91,7 @@ public class PushMsgTask {
            json.put("name", name);
            json.put("data", data);
            queue.put(json);
            String str = "";
        } catch (Exception e) {
            logger.error("添加到微信消息列队列失败!", e);
            e.printStackTrace();
@ -141,6 +142,7 @@ public class PushMsgTask {
                        String access_token = json.has("access_token") ? json.getString("access_token") : "";
                        String openid = json.has("openid") ? json.getString("openid") : "";
                        String name = json.has("name") ? json.getString("name") : "";
//                        String name = data.has("name") ? json.getString("name") : "";
                        // 发送消息到微信端
                        sendWeixinMessage(access_token, type, openid, name, data);
                    } else {
@ -185,12 +187,12 @@ public class PushMsgTask {
     *             type==7时:{"first":"消息主题","name":"就诊人名","date":"预约时间","doctorName":"医生名","orgName":"预约医院","remark":"消息备注"}
     *             type==9时:{"first":"消息主题","name":"患教标题","doctorName":"医生名","date":"发送时间","remark":"消息备注"}
     *             type==10时:{"first":"消息主题","name":"患教标题","doctorName":"医生名","date":"发送时间","remark":"消息备注"}
     *
     *             <p>
     *             type==11时:{"first":"消息主题","name":"患教标题","doctorName":"医生名","date":"发送时间","remark":"消息备注"}
     * @return
     */
//    private boolean sendWeixinMessage(String access_token, int type, String openid, String name, JSONObject json) {
    private boolean sendWeixinMessage(String access_token, int type, String openid, String name, JSONObject json) {
    public boolean sendWeixinMessage(String access_token, int type, String openid, String name, JSONObject json) {
        try {
            if (StringUtils.isEmpty(openid)) {
                logger.error("send wechat message failed:openid is empty");
@ -437,9 +439,9 @@ public class PushMsgTask {
                keyword3.setValue(json.getString("keyword3"));
                m.put("keyword3", keyword3);
            } else if (type == 11) {
                temp.setUrl(url + "survey/html/survey_info.html?openid=" + openid + "&state=" + openid + "&survey_id=" + json.getString("survey_id") + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                String xinurl = url + "survey/html/survey_info.html?openid=" + openid + "&state=" + openid + "&survey_id=" + json.getString("survey_id") + "&toUser=" + json.getString("toUser") + "&toName=" + name;
//                temp.setUrl(url + "survey/html/survey_info.html?openid=" + openid + "&state=" + openid + "&survey_id=" + json.getString("survey_id") + "&toUser=" + json.getString("toUser") + "&toName=" + name);
                temp.setUrl(xinurl);
//                temp.setTemplate_id("fgYiMntj1amEkE8_GLUPmAIyssUAroJrNSHqvydt-PQ");
                temp.setTemplate_id(SystemConf.getInstance().getSystemProperties()
                        .getProperty("template_doctor_survey"));
@ -453,17 +455,19 @@ public class PushMsgTask {
                keyword2.setValue(json.getString("keyword2"));
                m.put("keyword2", keyword2);
                logger.info("type=====>openId " + openid);
            }else if(type == 12){
                System.out.println("url=======type =11 =====================>"+xinurl);
                logger.error("url=======type =11 =====================>"+xinurl);
            } else if (type == 12) {
                temp.setUrl(url + "jtgx/html/application-msg-list.html?openid=" + openid+ "&member=" + json.getString("member"));
                temp.setUrl(url + "jtgx/html/application-msg-list.html?openid=" + openid + "&member=" + json.getString("member"));
                temp.setTemplate_id(SystemConf.getInstance().getSystemProperties().getProperty("template_doctor_survey"));
                WechatTemplateData  keyword1= new WechatTemplateData();
                WechatTemplateData keyword1 = new WechatTemplateData();
                keyword1.setColor("#000000");
                keyword1.setValue(json.getString("keyword1"));
                m.put("keyword1", keyword1);
                WechatTemplateData  keyword2= new WechatTemplateData();
                WechatTemplateData keyword2 = new WechatTemplateData();
                keyword2.setColor("#000000");
                keyword2.setValue(json.getString("keyword2"));
                m.put("keyword2", keyword2);
@ -478,17 +482,17 @@ public class PushMsgTask {
//                keyword4.setValue(json.getString("keyword4"));
//                m.put("keyword4", keyword4);
            }else if(type == 13){
            } else if (type == 13) {
                temp.setUrl(url + "jtgx/html/family.html?openid=" + openid);
                temp.setTemplate_id(SystemConf.getInstance().getSystemProperties().getProperty("template_doctor_survey"));
                WechatTemplateData  keyword1= new WechatTemplateData();
                WechatTemplateData keyword1 = new WechatTemplateData();
                keyword1.setColor("#000000");
                keyword1.setValue(json.getString("keyword1"));
                m.put("keyword1", keyword1);
                WechatTemplateData  keyword2= new WechatTemplateData();
                WechatTemplateData keyword2 = new WechatTemplateData();
                keyword2.setColor("#000000");
                keyword2.setValue(json.getString("keyword2"));
                m.put("keyword2", keyword2);
@ -519,6 +523,8 @@ public class PushMsgTask {
            temp.setData(m);
            ObjectMapper mapper = new ObjectMapper();
            String strJson = mapper.writeValueAsString(temp);
            System.out.println("send message================>" + strJson);
            logger.error("send message================>" + strJson);
            return strJson;
        } catch (Exception e) {
            e.printStackTrace();

+ 13 - 19
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ImUtill.java

@ -18,20 +18,17 @@ public class ImUtill {
     * @param status
     * @param reply
     * @return
     *
     */
    public static String getConsultData(String user, Integer status, Integer reply) {
        String imAddr = im_host + "api/v2/sessions/topics/count/reply";
        JSONObject params = new JSONObject();
        params.put("user", user);
        if (status!=null) {
            params.put("status", status);
        imAddr = imAddr + "?user=" + user;
        if (status != null) {
            imAddr += ("&status=" + status);
        }
        if (reply!=null) {
            params.put("reply", reply);
        if (reply != null) {
            imAddr += ("&reply=" + reply);
        }
        String response = HttpClientUtil.postBody(imAddr, params);
        String response = HttpClientUtil.get(imAddr, "UTF-8");
        return response;
    }
@ -49,20 +46,17 @@ public class ImUtill {
     */
    public static String getConsultByStatus(String user, Integer status, Integer reply, int page, int pagesize) {
        String imAddr = im_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);
        imAddr = imAddr + "?user=" + user + "&page=" + page + "&pagesize=" + pagesize;
        if (status != null) {
            imAddr += ("&status=" + status);
        }
        if (reply!=null) {
            params.put("reply", reply);
        if (reply != null) {
            imAddr += ("&reply=" + reply);
        }
        String response = HttpClientUtil.postBody(imAddr, params);
        String response = HttpClientUtil.get(imAddr, "UTF-8");
        return response;
    }
//    ===============================
    /**
     * 发送消息给IM
     *

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

@ -1,6 +1,8 @@
package com.yihu.wlyy.web.common.im;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.util.ImUtill;
import io.swagger.annotations.Api;
@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
import com.yihu.wlyy.util.HttpUtil;
import com.yihu.wlyy.web.BaseController;
import java.text.SimpleDateFormat;
import java.util.*;
@RestController
@ -26,25 +29,41 @@ public class imController extends BaseController {
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private DoctorDao doctorDao;
    /**
     * 获取单个咨询
     * @param consult
     * @return
     */
    @RequestMapping(value = "/getTopic")
    @ResponseBody
    public String getTopic(String consult){
        try{
            return success(ImUtill.getTopic(consult).get("data").toString());
        }catch (Exception e){
            return error(-1,e.getMessage());
        }
    }
    /**
     * 获取列表
     * status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
     * 第一次列表为当前医生(很可能团队长)待回复列表 传参:doctor有后台获取 status=0,reply=0未回复
     * 后 取团队内单各医生的咨询情况 doctor、status、reply均有前端传入
     * 后 取团队内单个医生的咨询情况 doctor、status、reply均有前端传入
     *
     * @return
     */
    @RequestMapping(value = "/consult/getList", method = RequestMethod.GET)
    @ResponseBody
    public String getTeamData(
    public String getConsultByStatus(
            @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();
            }
@ -54,11 +73,31 @@ public class imController extends BaseController {
            List list = new ArrayList();
            while (it.hasNext()) {
                Map map = new HashMap();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                JSONObject ob = (JSONObject) it.next();
                String id = ob.get("id").toString();
                String avatar = ob.get("avatar").toString();
                String session_id = ob.get("session_id").toString();
                String name = ob.get("name").toString();
                map.put("name", name);
                String name = ob.get("patient_name").toString();
                String createTime = ob.get("create_time").toString();
                String description = ob.get("description").toString();
                String sex = ob.get("sex").toString();
                String startId = ob.get("start_message_id").toString();
                String endId = ob.get("end_message_id").toString();
                if (StringUtils.isNotEmpty(createTime)){
                    Date date = sdf.parse(createTime);
                    map.put("create_time",sdf.format(date));
                }
                map.put("id", id);
                map.put("session_id", session_id);
                map.put("photo", avatar);
                map.put("patientName", name);
                map.put("sex", sex);
                map.put("description", description);
                map.put("start_message_id", startId);
                map.put("end_message_id", endId);
                list.add(map);
            }
            return write(200, "查询成功", "data", list);
@ -90,11 +129,11 @@ public class imController extends BaseController {
            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("photo", doc.get("photo")==null?"":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");
                map.put("type",doc.get("level")==null?"":doc.get("level").toString());
                String totalUnReply = ImUtill.getConsultData(doctor, 0, 0);
                int unReply = Integer.parseInt(totalUnReply);
                map.put("totalUnReply", unReply);
@ -114,36 +153,12 @@ public class imController extends BaseController {
            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, "查询成功");
            return write(200, "查询成功", "data", json);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
/**/
    /**
     * 获取团队医生下居民的咨询
@ -158,11 +173,9 @@ public class imController extends BaseController {
//            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, "查询成功");
            int count = signFamilyDao.findByPatientAndDoctor(patient, doctor);
            boolean flag = (count == 0) ? false : true;
            return write(200, "查询成功", "data", flag);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
@ -170,8 +183,7 @@ public class imController extends BaseController {
    }
    public List getMemberByDoctor(String doctor) {
//        List<Doctor> doctors = doctorDao.findMemberByLeader(doctor);
        String sql = "SELECT d.photo,d.`name`,d.sex,d.`code` " +
        String sql = "SELECT d.photo,d.`name`,d.sex,d.`code`,d.level " +
                " 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 = ? ";

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

@ -1,10 +1,13 @@
package com.yihu.wlyy.web.doctor.account;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import com.yihu.wlyy.entity.consult.ConsultTeam;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabel;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.profile.DoctorComment;
@ -12,6 +15,7 @@ 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.repository.doctor.SignPatientLabelDao;
import com.yihu.wlyy.service.app.account.PatientInfoService;
import com.yihu.wlyy.service.app.consult.ConsultTeamService;
import com.yihu.wlyy.service.app.hospital.HospitalDeptService;
@ -19,6 +23,7 @@ import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.common.account.RoleService;
import com.yihu.wlyy.util.*;
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;
@ -83,6 +88,8 @@ public class DoctorController extends BaseController {
    private RoleService roleService;
    @Autowired
    private DoctorAdminTeamDao doctorAdminTeamDao;
    @Autowired
    SignPatientLabelDao labelDao;
    /**
     * 社区医院下医生列表查询接口 没分页
@ -605,7 +612,7 @@ 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");
                json.put("isLeader", leader == 0 ? "0" : "1");
                return write(200, "医生信息查询成功!", "data", json);
            } else {
                return error(-1, "医生信息查询失败!");
@ -1778,4 +1785,71 @@ public class DoctorController extends BaseController {
            return error(-1, "查询失败");
        }
    }
    /**
     * 分配及转移健管师
     *
     * @param newDoctorCode
     * @param oldDoctorCode
     * @param patients      多个患者用,隔开
     * @param group         团队标签分组名称
     * @param sendCount
     * @param teamId
     * @param typeId
     * @return
     */
    @RequestMapping(value = "/allotOrMoveHealth")
    @ResponseBody
    public String allotOrMoveHealth(
            @RequestParam String newDoctorCode,
            @RequestParam(required = false) String oldDoctorCode,
            @RequestParam(required = false) String patients,
            @RequestParam(required = false) String group,
            @RequestParam(required = false) Integer sendCount,
            @RequestParam(required = false) String teamId,
            @RequestParam(required = false) String typeId) {
        try {
//            patients不为空是由团队中搜索居民 否则是分组分配健管师
            if (StringUtils.isNotEmpty(patients)) {
                String result = updateTeamHealthDoctors(newDoctorCode, oldDoctorCode, patients, null);
                return result;
            } else {
//            按条件获取居民
                patients = "";
                if (StringUtils.isEmpty(group)||StringUtils.isEmpty(teamId)||StringUtils.isEmpty(typeId)||sendCount==null){
                    return write(-1, "参数不能为空!");
                }
                Long teamCode = Long.parseLong(teamId);
                JSONObject list = familyContractService.findNoHealthSignFamilyHealth(null, typeId, null, teamCode);
                List<SignPatientLabel> s = labelDao.findByLabelTypeAndStatusAndTeamCode(typeId, 1, teamCode);
                for (SignPatientLabel label :s) {
//                    String labelName = label.getLabelCode();
                    String labelName = label.getLabelName();
                    if (labelName.equals(group)){
                        JSONArray jsonArray = list.getJSONArray(labelName);
                        for (int i=0;i<sendCount;i++){
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            String  patient = jsonObject.get("code").toString();
//                转移时需要剔除处于咨询状态的居民
                            if (StringUtils.isNotEmpty(oldDoctorCode)){
                                ConsultTeam consultTeam = consultTeamService.getConsultByPatientAndDoctor(patient, oldDoctorCode);
                                if (consultTeam == null) {
//                                   不是咨询状态
                                    patients+=(patient+",");
                                }
                            }else {
                                patients+=(patient+",");
                            }
                        }
                    }
                }
                patients =  patients.substring(0,patients.length()-1);
                String result = updateTeamHealthDoctors(newDoctorCode, oldDoctorCode, patients, null);
                return result;
            }
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败");
        }
    }
}

+ 20 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultController.java

@ -721,6 +721,26 @@ public class DoctorConsultController extends WeixinBaseController {
        }
    }
    /**
     * 查询与某个医生是否存在未结束的咨询
     *
     * @param consult 咨询code
     * @return
     */
    @RequestMapping(value = "/consultTeam", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String consult(@RequestParam(required = false) String consult) {
        try {
            ConsultTeam consultTeam = consultTeamService.findByCode(consult);
            return write(200, "查询成功", "data", consultTeam);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
    /**
     * 三师咨询转接接口
     *

+ 48 - 13
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/SignPatientLabelInfoController.java

@ -29,27 +29,62 @@ public class SignPatientLabelInfoController extends BaseController {
    /**
     * 根据姓名,地址,身份证号搜索团队内居民
     *
     * @param str
     * @param filter   筛选关键字
     * @param teamCode 团队编码
     * @param page
     * @param pagesize
     * @return
     */
    @RequestMapping(value = "getPatientByParams", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("由姓名|地址|身份证号搜索签约居民")
    public String getPatientByParams(@RequestParam String str,
                                     @RequestParam String teamCode) {
    public String getPatientByParams(@RequestParam String filter,
                                     @RequestParam String teamCode,
                                     @RequestParam int page,
                                     @RequestParam int pagesize) {
        try {
            if (StringUtils.isEmpty(str)) {
            if (StringUtils.isEmpty(filter)) {
                return error(-1, "搜索条件不能为空!");
            }
            if (StringUtils.isEmpty(teamCode)) {
                return error(-1, "团队不能为空!");
            }
            JSONObject temp = labelInfoService.search(str, getUID());
            long team = Long.parseLong(teamCode);
            JSONArray temp = labelInfoService.getPatientByParams(getUID(), filter, null, null, team, null, null, page, pagesize);
            return write(200, "查询成功!", "data", temp);
        } catch (Exception e) {
            error(e);
//            return error(-1, "查询失败!");
            return invalidUserException(e,-1, "查询失败!");
            return invalidUserException(e, -1, "查询失败!");
        }
    }
    /**
     * 根据姓名,地址,身份证号搜索团队内未分配健管的居民
     *
     * @param filter   筛选关键字
     * @param teamCode 团队编码
     * @return
     */
    @RequestMapping(value = "getPatientUnSign", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("由姓名|地址|身份证号搜索团队内未分配健管的居民")
    public String getPatientUnSign(@RequestParam String filter,
                                   @RequestParam String teamCode,
                                   @RequestParam int page,
                                   @RequestParam int pagesize) {
        try {
            if (StringUtils.isEmpty(filter)) {
                return error(-1, "搜索条件不能为空!");
            }
            if (StringUtils.isEmpty(teamCode)) {
                return error(-1, "团队不能为空!");
            }
            long team = Long.parseLong(teamCode);
            List list = labelInfoService.findNoHealthSignFamilyHealth(filter, team,page,pagesize);
            return write(200, "查询成功!", "data", list);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
@ -394,12 +429,12 @@ public class SignPatientLabelInfoController extends BaseController {
     */
    @RequestMapping(value = "/patient_search_exitdoc")
    public String searchPatientByNameOrLabelExitDoc(@RequestParam(required = true) String filter,
                                             @RequestParam(required = false) String labelCode,
                                             @RequestParam(required = false) String labelType,
                                             @RequestParam(required = true) Long teamCode,
                                             @RequestParam(required = false) String exLabelCode,
                                             @RequestParam(required = false) String exLabelType,
                                             @RequestParam(required = true) int page, @RequestParam(required = true) int pagesize) {
                                                    @RequestParam(required = false) String labelCode,
                                                    @RequestParam(required = false) String labelType,
                                                    @RequestParam(required = true) Long teamCode,
                                                    @RequestParam(required = false) String exLabelCode,
                                                    @RequestParam(required = false) String exLabelType,
                                                    @RequestParam(required = true) int page, @RequestParam(required = true) int pagesize) {
        try {
            if (StringUtils.isEmpty(filter)) {
                return error(-1, "搜索字段不能为空");

+ 146 - 10
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorFamilyContractController.java

@ -2,15 +2,14 @@ package com.yihu.wlyy.web.doctor.sign;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.TimeUnit;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabel;
import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.logs.BusinessLogs;
import com.yihu.wlyy.repository.doctor.SignPatientLabelDao;
import com.yihu.wlyy.service.app.account.PatientInfoService;
import com.yihu.wlyy.service.app.family.FamilyMemberService;
import com.yihu.wlyy.service.app.message.MessageService;
@ -69,7 +68,77 @@ public class DoctorFamilyContractController extends WeixinBaseController {
    AdminTeamService teamService;
    @Autowired
    FamilyMemberService familyMemberService;
    @Autowired
    SignPatientLabelDao labelDao;
    /**
     * 根据姓名、地址、身份证搜索已分配的居民
     *
     * @param filter
     * @param teamCode
     * @param doctor 健管师编码
     * @param page
     * @param pagesize
     * @return
     */
    @RequestMapping(value = "getPatientByParams")
    @ResponseBody
    @ApiOperation("由姓名|地址|身份证号搜索团队内已分配健管的居民")
    public String getPatientByParams(@RequestParam String filter,
                                     @RequestParam String teamCode,
                                     @RequestParam String doctor,
                                     @RequestParam String level,
                                     @RequestParam int page,
                                     @RequestParam int pagesize) {
        try {
            if (StringUtils.isEmpty(filter)) {
                return error(-1, "搜索条件不能为空!");
            }
            if (StringUtils.isEmpty(teamCode)) {
                return error(-1, "团队不能为空!");
            }
            long team = Long.parseLong(teamCode);
//            level 医生身份
            List list = familyContractService.getPatientByLable(doctor, filter, level, team, page, pagesize);
            return write(200, "查询成功!", "data", list);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
    /**
     * 分组查询已分配健管的居民的数量
     *
     * @param labelType
     * @param teamCode
     * @return
     */
    @RequestMapping(value = "getPatientByParamsNum")
    @ResponseBody
    public String getPatientByParamsNum(
            @RequestParam String labelType,
            @RequestParam String level,
            @RequestParam Long teamCode) {
        try {
            List listNum = new ArrayList();
            JSONObject list = familyContractService.getPatientByLable(getUID(), labelType, level, teamCode);
            List<SignPatientLabel> s = labelDao.findByLabelTypeAndStatusAndTeamCode(labelType, 1, teamCode);
            for (SignPatientLabel label : s) {
                Map map = new HashMap();
                String labelName = label.getLabelName();
                JSONArray jsonArray = list.getJSONArray(label.getLabelName());
                int length = jsonArray.length();
                map.put("label", labelName);
                map.put("number", length);
                listNum.add(map);
            }
            return write(200, "查询成功!", "data", listNum);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败");
        }
    }
    /**
     * 查看当前医生签约的居民
@ -102,10 +171,10 @@ public class DoctorFamilyContractController extends WeixinBaseController {
        try {
            List<Patient> patients = patientService.findByMobile(mobile);
            return write(200, "获取数据成功!", "data", patients);
        }catch (Exception e) {
                error(e);
                return error(-1, "获取数据失败!");
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "获取数据失败!");
        }
    }
    private void addList(JSONObject returnJO, List<Patient> pts, JSONArray array, String key) {
@ -146,6 +215,40 @@ public class DoctorFamilyContractController extends WeixinBaseController {
        }
    }
    /**
     * 根据标签查看当前医生签约的居民  3 健康管理师  2是全科
     */
    @RequestMapping(value = "/getPatientLables")
    @ResponseBody
    public String getPatientLables(String labelType, String level, String oldDoctorCode, Long teamCode) {
        try {
            List listNum = new ArrayList();
            JSONObject list = familyContractService.getPatientByLable(oldDoctorCode, labelType, level, teamCode);
            List<SignPatientLabel> s = labelDao.findByLabelTypeAndStatusAndTeamCode(labelType, 1, teamCode);
            for (SignPatientLabel label : s) {
                Map map = new HashMap();
                String labelName = label.getLabelName();
                JSONArray jsonArray = list.getJSONArray(label.getLabelName());
                List codes = new ArrayList();
                for (int i = 0 ;i<jsonArray.length();i++){
                    JSONObject json = jsonArray.getJSONObject(i);
                    Map info = new HashMap();
                    String code = json.getString("code");
                    String name = json.getString("name");
                    info.put("code",code);
                    info.put("name",name);
                    codes.add(info);
                }
                map.put("label", labelName);
                map.put("codes", codes);
                listNum.add(map);
            }
            return write(200, "查询成功", "data", listNum);
        } catch (Exception e) {
            return error(-1, "查询失败");
        }
    }
    /**
     * 医生签约患者列表查询接口
     *
@ -851,6 +954,38 @@ public class DoctorFamilyContractController extends WeixinBaseController {
        }
    }
    /**
     * 获取没有健康管理师的患者数量
     *
     * @param patientName 患者名称
     * @return
     */
    @RequestMapping(value = "/findNoHealthSignFamilyHealthNum")
    @ResponseBody
    public String findNoHealthSignFamilyHealthNum(
            String labelType,
            @RequestParam(required = false) String patientName,
            Long teamCode) {
        try {
            List listNum = new ArrayList();
            JSONObject list = familyContractService.findNoHealthSignFamilyHealth(getUID(), labelType, patientName, teamCode);
            List<SignPatientLabel> s = labelDao.findByLabelTypeAndStatusAndTeamCode(labelType, 1, teamCode);
            for (SignPatientLabel label : s) {
                Map map = new HashMap();
                String labelName = label.getLabelName();
                JSONArray jsonArray = list.getJSONArray(label.getLabelName());
                int length = jsonArray.length();
                map.put("label", labelName);
                map.put("number", length);
                listNum.add(map);
            }
            return write(200, "查询成功!", "data", listNum);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败");
        }
    }
    /**
     * 获取没有健康管理师的患者列表
     *
@ -901,9 +1036,9 @@ public class DoctorFamilyContractController extends WeixinBaseController {
    @ResponseBody
    public String findByParamsWithDoctor(
            String teamCode,
            String params,String doctor,int level) {
            String params, String doctor, int level) {
        try {
            JSONObject list = familyContractService.findByParamsWithDoctor(doctor, teamCode, params,level);
            JSONObject list = familyContractService.findByParamsWithDoctor(doctor, teamCode, params, level);
            return write(200, "签约数据加载成功!", "data", list);
        } catch (Exception e) {
            return error(-1, "查询失败");
@ -1078,6 +1213,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
    /**
     * 查询患者责任医生、团队医生
     *
     * @return
     */
    @RequestMapping(value = "/consult_doctors", method = {RequestMethod.GET, RequestMethod.POST})

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

@ -50,6 +50,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
    private SurveyUserDao surveyUserDao;
    @Autowired
    WeiXinOpenIdUtils weiXinOpenIdUtils;
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    /**
     * 获取问卷列表
@ -108,7 +109,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
            @RequestParam String id) {
        try {
            JSONObject jsonObject = managerQuestionnaireService.getQuestionnaireDetail(id);
            System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+jsonObject);
            logger.error("jsonObject=====>" + jsonObject);
            return write(200, "查询成功", "data", jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
@ -206,7 +207,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
        try {
//        解析整套问卷json字符串并保存
            JSONObject jsonStr = new JSONObject(jsonData.toString());
            System.out.println("==============================>"+jsonStr);
            System.out.println("==============================>" + jsonStr);
//            获取医生信息(仅限市级管理员)
            String doctor = getUID();
            String accessToken = getAccessToken();
@ -218,25 +219,6 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
        }
    }
    /**
     * 模板列表(按时间降序)和由模板标签获取模板概述getTemplateByLabel合并无标签值为默认列表
     *
     * @return
     *//*
    @RequestMapping(value = "getTemplateList", method = RequestMethod.GET)
    @ApiOperation(value = "模板列表")
    @ResponseBody
    public String getTemplateList(@RequestParam int pageNo,
                                  @RequestParam int pageSize) {
        try {
            List templates = managerQuestionnaireService.getTemplateList(pageNo, pageSize);
            return write(200, "查询成功!", "data", templates);
        } catch (Exception e) {
            e.printStackTrace();
            return write(-1, "查询失败!");
        }
    }*/
    /**
     * 获取模板标签
     *
@ -247,7 +229,6 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
    @ResponseBody
    public String getTemplateLabel() {
        try {
//            JSONObject jsonObject = managerQuestionnaireService.getTemplateLabel();
            List list = managerQuestionnaireService.getTemplateLabel();
            return write(200, "查询成功!", "data", list);
        } catch (Exception e) {
@ -304,6 +285,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
            @RequestParam String code) {
        try {
            JSONObject jsonObject = managerQuestionnaireService.getTemplateDetail(code);
            System.out.println("createSurvey's template===============>" + jsonObject);
            return write(200, "查询成功!", "data", jsonObject);
        } catch (Exception e) {
            error(e);
@ -378,7 +360,7 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
    /**
     * 新建问卷保存为模板
     * 引用模板新建问卷保存变更到模板
     * 引用模板新建问卷保存变更到模板(可以增加删除问题)
     *
     * @param code
     * @return
@ -397,17 +379,17 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
            int num = 0;
            if (StringUtils.isEmpty(templateCode)) {
//                保存为新模板(重复之后才会有title传进来)
                if (StringUtils.isEmpty(title)){
                if (StringUtils.isEmpty(title)) {
                    num = managerQuestionnaireService.savaSurveyAsTemplate(code, null);
                }else {
                } else {
                    num = managerQuestionnaireService.savaSurveyAsTemplate(code, title);
                }
            } else {
//                修改原模板(重复之后才会有title传进来)
                if (StringUtils.isEmpty(title)){
                if (StringUtils.isEmpty(title)) {
                    num = managerQuestionnaireService.modifyTemplate(code, templateCode, null);
                }else {
                } else {
                    num = managerQuestionnaireService.modifyTemplate(code, templateCode, title);
                }
@ -440,32 +422,13 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
            @ApiParam(value = "问卷编码")
            @RequestParam String code) {
        try {
            /*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//            sdf.format(new Date());
            String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
            String accessToken = getAccessToken();
            System.out.println("accessToken=====>" + accessToken);
            JSONObject json = new JSONObject(str);
            List<String> codes = surveyUserDao.findBySurveyCodeAndStatus(code);
            json.put("survey_id", code);
            for (String cod : codes) {
                Patient p = patientDao.findByCode(cod);
                String name = p.getName();
                String openId = p.getOpenid();
                System.out.println("controller=====>cod " + cod + " name " + name + " openId " + openId);
                json.put("keyword2", sdf.format(new Date()));
                json.put("toUser", cod);
                json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                pushMsgTask.sendWeixinMessage(accessToken, 11, openId, name, json);
            }*/
            List<String> codes = surveyUserDao.findBySurveyCodeAndStatus(code);
            String accessToken = getAccessToken();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
            JSONObject json = new JSONObject(str);
            codes.stream().forEach(c -> {
           /* codes.stream().forEach(c -> {
                Patient p = patientDao.findByCode(c);
                String name = p.getName();
                String openId = p.getOpenid();
@ -473,27 +436,67 @@ public class ManagerQuestionnaireController extends WeixinBaseController {
                json.put("toUser", c);
                json.put("survey_id", code);
                json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                logger.error("patient =======>" + code);
                logger.error("name =======>" + name);
                logger.error("openId =======>" + openId);
                //判断是否判定openId,有没有发则查找家人发送
                if(StringUtils.isNotBlank(p.getOpenid())){
                //判断是否有openId,有发送没有则查找家人发送
                if (StringUtils.isNotBlank(p.getOpenid())) {
                    // 添加到发送队列
                    logger.error("json =======>" + json);
                    PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
                }else{
                    JSONObject j  = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
                } 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(getAccessToken(), 11, member.getOpenid(), member.getName(), json);
                        logger.error("没有opIn  json =======>" + json);
                        PushMsgTask.getInstance().putWxMsg(accessToken, 11, member.getOpenid(), member.getName(), json);
                    }
                }
            });*/
            new Thread() {
                public void run() {
                    for (String c : codes) {
                        Patient p = patientDao.findByCode(c);
                        String name = p.getName();
                        String openId = p.getOpenid();
                        json.put("keyword2", sdf.format(new Date()));
                        json.put("toUser", c);
                        json.put("survey_id", code);
                        json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
                        //判断是否判定openId,有没有发则查找家人发送
                        if (StringUtils.isNotBlank(p.getOpenid())) {
                            // 添加到发送队列
                            logger.error("json =======>" + json);
//                            PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
                            PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, openId, name, json);
                        } else {
                            JSONObject j = weiXinOpenIdUtils.getFamilyOpenId(p.getOpenid());
                            Patient member = (Patient) j.get("member");
                            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) {
                                    e.printStackTrace();
                                }
                                logger.error("没有opIn  json =======>" + json);
//                                PushMsgTask.getInstance().putWxMsg(accessToken, 11, member.getOpenid(), member.getName(), json);
                                PushMsgTask.getInstance().sendWeixinMessage(accessToken, 11, member.getOpenid(), member.getName(), json);
                            }
                        }
                    }
                }
            });
            }.start();
            return write(200, "发送成功!");
        } catch (Exception e) {

+ 19 - 13
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

@ -119,10 +119,11 @@ public class StatisticsController extends BaseController {
    /**
     * 指标截止日期累积量
     *
     * @param endDate
     * @param area
     * @param level
     * @param index
     * @param endDate 结束时间
     * @param area 父code
     * @param level 等级  1 团队,2 机构,3 区,4 市
     * @param index 指标代码
     * @param level2_type  指标代码 例如性别 1 男 2 女  不传就返回男和女的总和
     * @return
     */
    @RequestMapping("/total")
@ -130,13 +131,14 @@ public class StatisticsController extends BaseController {
    public String getIndexTotal(@RequestParam(required = true) String endDate,
                                @RequestParam(required = true) String area,
                                @RequestParam(required = true) int level,
                                @RequestParam(required = true) String index) {
                                @RequestParam(required = true) String index,
                                @RequestParam(required = false) String level2_type) {
        try {
            String[] indexes = index.split(",");
            JSONObject result = new JSONObject();
            for (String idx : indexes) {
                result.put("index_" + idx, statisticsService.getTotalAmount(endDate, area, level, idx));
                result.put("index_" + idx, statisticsService.getTotalAmount(endDate, area, level, idx,level2_type));
            }
            return write(200, "查询成功", "data", result);
@ -182,10 +184,13 @@ public class StatisticsController extends BaseController {
    /**
     * 指标截止日期增量
     *
     * @param endDate
     * @param area
     * @param level
     * @param index
     * @param endDate 结束时间
     * @param area 父code
     * @param level 等级  1 团队,2 机构,3 区,4 市
     * @param index 指标代码
     * @param sort 排序 1倒叙 2是 正序
     * @param lowLevel
     * @param level2_type  指标代码 例如性别 1 男 2 女  不传就返回男和女的总和
     * @return
     */
    @RequestMapping("/lowlevel_total")
@ -195,13 +200,14 @@ public class StatisticsController extends BaseController {
                                        @RequestParam(required = true) int level,
                                        @RequestParam(required = true) String index,
                                        @RequestParam(required = true) int sort,
                                        @RequestParam(required = false) String lowLevel) {
                                        @RequestParam(required = false) String lowLevel,
                                        @RequestParam(required = false) String level2_type) {
        try {
            String[] indexes = index.split(",");
            JSONObject result = new JSONObject();
            for (String idx : indexes) {
                result.put("index_" + idx, statisticsService.getLowLevelTotalDetail(endDate, area, level, idx, sort, lowLevel));
                result.put("index_" + idx, statisticsService.getLowLevelTotalDetail(endDate, area, level, idx, sort, lowLevel,level2_type));
            }
            return write(200, "查询成功", "data", result);
@ -234,7 +240,7 @@ public class StatisticsController extends BaseController {
            JSONArray returnJa = new JSONArray();
            List<JSONArray> jsonArrays = new ArrayList<>();
            JSONArray jsonArray1 = statisticsService.getLowLevelTotalDetail(endDate, area, level, indexes[0], sort, lowLevel);
            JSONArray jsonArray1 = statisticsService.getLowLevelTotalDetail(endDate, area, level, indexes[0], sort, lowLevel,null);
            jsonArrays.add(jsonArray1);
            JSONArray jsonArray2 = statisticsService.getLowLevelIncrementDetail(endDate, endDate, area, level, indexes[1], sort, lowLevel);

+ 1 - 1
patient-co-wlyy/src/main/resources/system.properties

@ -80,7 +80,7 @@ chat_server=http://weixin.xmtyw.cn/res/chat/
sign_check_upload=http://172.19.103.87:8011/wlyy_service
# IM配置
im_list_get=http://172.19.103.29:3008
im_list_get=http://172.19.103.29:3008/
#im_list_get=http://192.168.131.102:3008/
im_group_server=http://172.19.103.29:3000/api/v1/chats/gm
msg_push_server=http://172.19.103.29:3000/api/v1/chats/sm