Переглянути джерело

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

liuwenbin 7 роки тому
батько
коміт
5ccc49dbbf

+ 10 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/entity/synergy/ManageSynergyWorkorderDO.java

@ -27,6 +27,7 @@ public class ManageSynergyWorkorderDO extends IdEntity {
    private Integer del;//逻辑删除(0、有效,1、删除)
    private String content;//服务内容
    private String relationCode;//根据type关联业务code
    private String relationCodeName;//关联业务名称
    private String returnedRemark;//退回操作备注说明
    private String dealResultRemark;//处理结果
    private String dealResultAccessory;//处理结果附件
@ -150,6 +151,15 @@ public class ManageSynergyWorkorderDO extends IdEntity {
        this.relationCode = relationCode;
    }
    @Column(name = "relation_code_name")
    public String getRelationCodeName() {
        return relationCodeName;
    }
    public void setRelationCodeName(String relationCodeName) {
        this.relationCodeName = relationCodeName;
    }
    @Column(name = "returned_remark")
    public String getReturnedRemark() {
        return returnedRemark;

+ 209 - 178
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/survey/SurveyScreenResultService.java

@ -3,18 +3,17 @@ package com.yihu.wlyy.service.app.survey;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.survey.*;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.dict.SystemDictDao;
import com.yihu.wlyy.repository.doctor.*;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.survey.ManagerQuestionnaireService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.IdCardUtil;
import com.yihu.wlyy.util.http.HttpResponse;
import com.yihu.wlyy.util.http.HttpUtils;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import org.apache.commons.collections.map.HashedMap;
@ -25,6 +24,7 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@ -39,6 +39,9 @@ import java.util.*;
@Service
@Transactional
public class SurveyScreenResultService extends BaseService {
    @Value("${customerService.url}")
    private String customerUrl;
    @Autowired
    SurveyStatisticsDao surveyStatisticsDao;
    @Autowired
@ -52,28 +55,18 @@ public class SurveyScreenResultService extends BaseService {
    @Autowired
    private SurveyTemplateResultDao surveyTemplateResultDao;
    @Autowired
    private SurveyTemplateAdviceDao surveyTemplateAdviceDao;
    @Autowired
    private SurveyTemplateQuestionsDao surveyTemplateQuestionsDao;
    @Autowired
    private SurveyOptionAnswersDao surveyOptionAnswersDao;
    @Autowired
    private DoctorDao doctorDao;
    @Autowired
    private SurveyAdviceDao surveyAdviceDao;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private ManagerQuestionnaireService managerQuestionnaireService;
    @Autowired
    private SurveyDao surveyDao;
    @Autowired
    private SurveyQuestionsDao surveyQuestionsDao;
    @Autowired
    private SurveyLabelInfoDao surveyLabelInfoDao;
    @Autowired
    private SurveyQuestionsOptionsDao surveyQuestionsOptionsDao;
    @Autowired
    private SurveyUserDao surveyUserDao;
    @Autowired
    private SurveyFilterDao surveyFilterDao;
@ -82,12 +75,6 @@ public class SurveyScreenResultService extends BaseService {
    @Autowired
    private SurveyQuestionnaireDao surveyQuestionnaireDao;
    @Autowired
    private SurveyTemplateOptionsDao surveyTemplateOptionsDao;
    @Autowired
    private SurveyAnswersDao surveyAnswersDao;
    @Autowired
    private SystemDictDao systemDictDao;
    @Autowired
    private SurveyDimensionDao surveyDimensionDao;
    @Autowired
    private SurveyDimensionDetailDao surveyDimensionDetailDao;
@ -99,6 +86,8 @@ public class SurveyScreenResultService extends BaseService {
    private PushMsgTask pushMsgTask;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    @Autowired
    private DoctorService doctorService;
    private Logger logger = LoggerFactory.getLogger(this.getClass());
@ -106,6 +95,7 @@ public class SurveyScreenResultService extends BaseService {
    /**
     * 筛查记录结果列表
     *
     * @param pageNo
     * @param pageSize
     * @param doctor
@ -116,78 +106,80 @@ public class SurveyScreenResultService extends BaseService {
     * @return
     * @throws Exception
     */
    public Map<String,Object> getResultList(int pageNo, int pageSize,String doctor,String diseaseType,String dealType,String isDanger,String patientName) throws Exception {
        int start = (pageNo-1)*pageSize;
        String sql = "SELECT ssr.* FROM wlyy_survey_screen_result ssr WHERE 1=1 AND ssr.over = 1 and ssr.source=1 and ssr.doctor='"+doctor+"'";
    public Map<String, Object> getResultList(int pageNo, int pageSize, String doctor, String diseaseType, String dealType, String isDanger, String patientName) throws Exception {
        int start = (pageNo - 1) * pageSize;
        String sql = "SELECT ssr.* FROM wlyy_survey_screen_result ssr WHERE 1=1 AND ssr.over = 1 and ssr.source=1 and ssr.doctor='" + doctor + "'";
        //String countSql = "SELECT count(*) num FROM wlyy_survey_screen_result ssr WHERE 1=1 AND ssr.over = 1 and ssr.doctor='"+doctor+"'";
        if (StringUtils.isNotEmpty(isDanger)){
            sql += " AND ssr.is_danger= "+isDanger;
        if (StringUtils.isNotEmpty(isDanger)) {
            sql += " AND ssr.is_danger= " + isDanger;
        }
        if (StringUtils.isNotEmpty(diseaseType)){
            sql += " AND ssr.disease="+diseaseType;
        if (StringUtils.isNotEmpty(diseaseType)) {
            sql += " AND ssr.disease=" + diseaseType;
        }
        if (StringUtils.isNotEmpty(patientName)){
            sql += " AND ssr.patient_name like '%"+patientName+"%'";
        if (StringUtils.isNotEmpty(patientName)) {
            sql += " AND ssr.patient_name like '%" + patientName + "%'";
        }
        if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("1",dealType)){
        if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("1", dealType)) {
            //已预约
            sql += " AND ssr.is_order = 1";
        }
        if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("2",dealType)){
        if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("2", dealType)) {
            //已跟踪
            sql += " AND ssr.following= 1";
        }
        if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("3",dealType)){
        if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("3", dealType)) {
            //已接诊
            sql += " AND ssr.is_order = 2";
        }
        if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("4",dealType)){
        if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("4", dealType)) {
            //待处理
            sql +=" AND ssr.is_order = 0 AND ssr.following= 0";
            sql += " AND ssr.is_order = 0 AND ssr.following= 0";
        }
        List<Map<String,Object>> maps = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
        sql += " order by ssr.czrq desc limit "+start+","+pageSize;
        List<SurveyScreenResult> surveyScreenResultList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(SurveyScreenResult.class));
        Map<String,Object> map = new HashedMap();
        map.put("num",maps.size());
        map.put("data",surveyScreenResultList);
        sql += " order by ssr.czrq desc limit " + start + "," + pageSize;
        List<SurveyScreenResult> surveyScreenResultList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(SurveyScreenResult.class));
        Map<String, Object> map = new HashedMap();
        map.put("num", maps.size());
        map.put("data", surveyScreenResultList);
        return map;
    }
    /**
     * 筛查模板列表
     *
     * @param pageNo
     * @param pageSize
     * @param labelType
     * @return
     */
    public List<SurveyTemplates> getScreenList(int pageNo,int pageSize,int labelType,String title){
        int start = (pageNo-1)*pageSize;
    public List<SurveyTemplates> getScreenList(int pageNo, int pageSize, int labelType, String title) {
        int start = (pageNo - 1) * pageSize;
        String sql = "SELECT st.* FROM wlyy_survey_templates st LEFT JOIN wlyy_survey_label_info sli ON st.`code`= sli.relation_code" +
                " WHERE st.del = 1 and sli.label="+labelType+"";
        if (StringUtils.isNotEmpty(title)){
            sql += " and st.title like '%"+title+"%'";
                " WHERE st.del = 1 and sli.label=" + labelType + "";
        if (StringUtils.isNotEmpty(title)) {
            sql += " and st.title like '%" + title + "%'";
        }
        sql += " order by st.create_time desc limit "+start+","+pageSize;
        List<SurveyTemplates> surveyTemplatesList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(SurveyTemplates.class));
        sql += " order by st.create_time desc limit " + start + "," + pageSize;
        List<SurveyTemplates> surveyTemplatesList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(SurveyTemplates.class));
        return surveyTemplatesList;
    }
    /**
     * 保存筛查结果
     *
     * @param patientCode
     * @param doctor
     * @param source
     * @param jsonData
     */
    public String saveScreenResultAndAnswer(String patientCode,String doctor,int isAgain,int source, JSONObject jsonData)throws Exception{
    public String saveScreenResultAndAnswer(String patientCode, String doctor, int isAgain, int source, JSONObject jsonData) throws Exception {
        System.out.println("********保存筛查结果--jsonData********* " + jsonData);
        String surveyCode = jsonData.get("surveyCode").toString();
        SurveyTemplates surveyTemplates = surveyTemplatesDao.findById(surveyCode);
        Patient patient = patientDao.findByCode(patientCode);
        SurveyScreenResult surveyScreenResult =  new SurveyScreenResult();
        SurveyScreenResult surveyScreenResult = new SurveyScreenResult();
        //解析json保存各种答案--获取一维数组
        JSONArray questions = jsonData.getJSONArray("questions");
        int totalScore = 0;
@ -222,12 +214,12 @@ public class SurveyScreenResultService extends BaseService {
            }
        }
        //查询该筛查的结果设置
        SurveyTemplateResult surveyTemplateResult = surveyTemplateResultDao.getByTemplateCodeAndLowScoreAndHighScore(surveyCode,totalScore);
        SurveyTemplateResult surveyTemplateResult = surveyTemplateResultDao.getByTemplateCodeAndLowScoreAndHighScore(surveyCode, totalScore);
        //更新上一条数据为不可再次评估
        List<SurveyScreenResult> surveyScreenResultList = surveyScreenResultDao.findNewOneByTemplateCode(surveyCode,patientCode);
        List<SurveyScreenResult> surveyScreenResultList = surveyScreenResultDao.findNewOneByTemplateCode(surveyCode, patientCode);
        String lastCode = "";
        String originCode = "";
        if (surveyScreenResultList!=null && surveyScreenResultList.size()>0){
        if (surveyScreenResultList != null && surveyScreenResultList.size() > 0) {
            lastCode = surveyScreenResultList.get(0).getCode();
            originCode = surveyScreenResultList.get(0).getOriginCode();
            surveyScreenResultDao.updateNoAgain(lastCode);
@ -236,20 +228,20 @@ public class SurveyScreenResultService extends BaseService {
        surveyScreenResult.setCode(code);
        surveyScreenResult.setSource(source);
        //是来自再次评估
        if (isAgain==1){
        if (isAgain == 1) {
            surveyScreenResult.setParentCode(lastCode);
            surveyScreenResult.setOriginCode(originCode);
        }else {
        } else {
            //来自第一次筛查评分
            surveyScreenResult.setOriginCode(code);
        }
        if (surveyTemplates!=null){
        if (surveyTemplates != null) {
            surveyScreenResult.setTemplateCode(surveyTemplates.getCode());
            surveyScreenResult.setTemplateTitle(surveyTemplates.getTitle());
            surveyScreenResult.setDisease(surveyTemplates.getDiseaseType());
        }
        //来自医生发放和自我评估不一样来源
        if (source==1){
        if (source == 1) {
            surveyScreenResult.setDoctor(doctor);
        }/*else {
            SignFamily signFamily = signFamilyDao.findByPatient(patientCode);
@ -262,7 +254,7 @@ public class SurveyScreenResultService extends BaseService {
        }*/
        surveyScreenResult.setPatientCode(patientCode);
        if (patient!=null){
        if (patient != null) {
            surveyScreenResult.setPatientName(patient.getName());
            surveyScreenResult.setOpenId(patient.getOpenid());
        }
@ -273,38 +265,38 @@ public class SurveyScreenResultService extends BaseService {
        surveyScreenResult.setIsAgain(1);
        surveyScreenResult.setIsEducate(0);
        surveyScreenResult.setScreenResultScore(totalScore);
        if (surveyTemplateResult!=null){
        if (surveyTemplateResult != null) {
            surveyScreenResult.setScreenResultCode(surveyTemplateResult.getCode());
            surveyScreenResult.setIsDanger(surveyTemplateResult.getWarning());
            surveyScreenResult.setScreenResult(surveyTemplateResult.getResult());
        }
        surveyScreenResultDao.save(surveyScreenResult);
        managerQuestionnaireService.saveAnswer(patientCode,code,jsonData);
        managerQuestionnaireService.saveAnswer(patientCode, code, jsonData);
        return code;
    }
    public JSONObject getScreenResultDetail(String code)throws Exception{
    public JSONObject getScreenResultDetail(String code) throws Exception {
        JSONObject json = new JSONObject();
        //登记信息
        String infoSql = "SELECT ssr.*,p.idcard FROM wlyy_survey_screen_result ssr LEFT JOIN wlyy_patient p ON ssr.patient_code=p.code where ssr.code ='"+code+"'";
        Map<String,Object> infoMap = jdbcTemplate.queryForMap(infoSql);
        if (infoMap==null || infoMap.size()==0){
            json.put(code,-1);
            json.put("message","没有改筛查结果!");
        String infoSql = "SELECT ssr.*,p.idcard FROM wlyy_survey_screen_result ssr LEFT JOIN wlyy_patient p ON ssr.patient_code=p.code where ssr.code ='" + code + "'";
        Map<String, Object> infoMap = jdbcTemplate.queryForMap(infoSql);
        if (infoMap == null || infoMap.size() == 0) {
            json.put(code, -1);
            json.put("message", "没有改筛查结果!");
            return json;
        }
        String idcard = String.valueOf(infoMap.get("idcard"));
        infoMap.put("sex",IdCardUtil.getSexForIdcard_new(idcard));
        infoMap.put("age",IdCardUtil.getAgeForIdcard(idcard));
        infoMap.put("sex", IdCardUtil.getSexForIdcard_new(idcard));
        infoMap.put("age", IdCardUtil.getAgeForIdcard(idcard));
        String templateCode = String.valueOf(infoMap.get("template_code"));
        String doctorCode = String.valueOf(infoMap.get("doctor"));
        String patientCode = String.valueOf(infoMap.get("patient_code"));
        Doctor doctor = doctorDao.findByCode(doctorCode);
        if (doctor!=null){
            infoMap.put("level",doctor.getLevel());
            infoMap.put("doctorName",doctor.getName());
        if (doctor != null) {
            infoMap.put("level", doctor.getLevel());
            infoMap.put("doctorName", doctor.getName());
        }
        json.put("info",infoMap);
        json.put("info", infoMap);
        /*String healthSql ="SELECT value1,value2 FROM device.wlyy_patient_health_index WHERE user='"+patientCode+"' AND type=3 ORDER BY record_date DESC LIMIT 1";
        List<Map<String,Object>> healthMapList = jdbcTemplate.queryForList(healthSql);
        if (healthMapList!=null && healthMapList.size()>0){
@ -313,170 +305,171 @@ public class SurveyScreenResultService extends BaseService {
        //题目和答案
        List<SurveyTemplateQuestions> questionList = surveyTemplateQuestionsDao.findById(templateCode);
        Map<String,Object> answerMap = new HashMap<>();
        Map<String, Object> answerMap = new HashMap<>();
        String sql = "SELECT soa.*,sto.score,sto.content FROM wlyy_survey_option_answers soa LEFT JOIN wlyy_survey_template_options sto ON soa.options_code= sto.code WHERE soa.screen_result_code=? AND soa.patient=? AND soa.survey_code=?";
        List<Map<String,Object>> optionAnswersList = jdbcTemplate.queryForList(sql,new Object[]{code,patientCode,templateCode});
        for (SurveyTemplateQuestions surveyTemplateQuestions : questionList){
            Map<String,Object> map = new HashMap<>();
            map.put("question",surveyTemplateQuestions);
        List<Map<String, Object>> optionAnswersList = jdbcTemplate.queryForList(sql, new Object[]{code, patientCode, templateCode});
        for (SurveyTemplateQuestions surveyTemplateQuestions : questionList) {
            Map<String, Object> map = new HashMap<>();
            map.put("question", surveyTemplateQuestions);
            String qusCode = surveyTemplateQuestions.getCode();
            for (Map<String,Object> option : optionAnswersList){
                if (option.get("question_code").equals(qusCode)){
                    map.put("option",option);
            for (Map<String, Object> option : optionAnswersList) {
                if (option.get("question_code").equals(qusCode)) {
                    map.put("option", option);
                }
            }
            answerMap.put(surveyTemplateQuestions.getSort()+"",map);
            answerMap.put(surveyTemplateQuestions.getSort() + "", map);
        }
        json.put("answer",answerMap);
        json.put("answer", answerMap);
        //结果
        String reultSql ="SELECT ssr.screen_result_score,ssr.screen_result,str.advice FROM wlyy_survey_screen_result ssr LEFT JOIN wlyy_survey_template_result str ON ssr.screen_result_code = str.code WHERE ssr.code='"+code+"'";
        Map<String,Object> resultMap = jdbcTemplate.queryForMap(reultSql);
        String reultSql = "SELECT ssr.screen_result_score,ssr.screen_result,str.advice FROM wlyy_survey_screen_result ssr LEFT JOIN wlyy_survey_template_result str ON ssr.screen_result_code = str.code WHERE ssr.code='" + code + "'";
        Map<String, Object> resultMap = jdbcTemplate.queryForMap(reultSql);
        int following = Integer.parseInt(String.valueOf(infoMap.get("following")));
        int order = Integer.parseInt(String.valueOf(infoMap.get("is_order")));
        if (order>0){
        if (order > 0) {
            //已转诊
            String doctorSql ="SELECT pr.doctor_name FROM wlyy_survey_screen_result ssr LEFT JOIN wlyy_patient_reservation pr ON ssr.reservation_code= pr.`code` where ssr.`code`='"+code+"'";
            List<String> list= jdbcTemplate.queryForList(doctorSql,String.class);
            if (list!=null && list.size()>0){
                json.put("specialDoctorName",list.get(0));
            String doctorSql = "SELECT pr.doctor_name FROM wlyy_survey_screen_result ssr LEFT JOIN wlyy_patient_reservation pr ON ssr.reservation_code= pr.`code` where ssr.`code`='" + code + "'";
            List<String> list = jdbcTemplate.queryForList(doctorSql, String.class);
            if (list != null && list.size() > 0) {
                json.put("specialDoctorName", list.get(0));
            }
        }else if (following==1){
        } else if (following == 1) {
            String adviceCodes = String.valueOf(infoMap.get("advice_code"));
            List<SurveyAdvice> surveyAdviceList = new ArrayList<>();
            if (StringUtils.isNotEmpty(adviceCodes)){
            if (StringUtils.isNotEmpty(adviceCodes)) {
                String[] advicesStr = adviceCodes.split(",");
                for (String adviceCode : advicesStr){
                for (String adviceCode : advicesStr) {
                    surveyAdviceList.add(surveyAdviceDao.getByCode(adviceCode));
                }
            }
            resultMap.put("doctorAdvice",surveyAdviceList);
            resultMap.put("doctorOtherAdvice",infoMap.get("other_advice"));
            resultMap.put("doctorAdvice", surveyAdviceList);
            resultMap.put("doctorOtherAdvice", infoMap.get("other_advice"));
        }
        json.put("result",resultMap);
        json.put("result", resultMap);
        return json;
    }
    public List<Map<String,Object>> getTemplateAdviceList(String templateCode){
        String sql ="SELECT st.template_code,sa.code adviceCode,sa.advice FROM wlyy_survey_template_advice st LEFT JOIN wlyy_survey_advice sa ON st.advice_code=sa.`code` WHERE st.template_code='"+templateCode+"'";
    public List<Map<String, Object>> getTemplateAdviceList(String templateCode) {
        String sql = "SELECT st.template_code,sa.code adviceCode,sa.advice FROM wlyy_survey_template_advice st LEFT JOIN wlyy_survey_advice sa ON st.advice_code=sa.`code` WHERE st.template_code='" + templateCode + "'";
        return jdbcTemplate.queryForList(sql);
    }
    public void updateAfterFollowing(String code,String adviceCodes,String otherAdvice)throws Exception{
        String sql ="UPDATE wlyy_survey_screen_result SET following=1,advice_code=?";
        if (StringUtils.isNotEmpty(otherAdvice)){
    public void updateAfterFollowing(String code, String adviceCodes, String otherAdvice) throws Exception {
        String sql = "UPDATE wlyy_survey_screen_result SET following=1,advice_code=?";
        if (StringUtils.isNotEmpty(otherAdvice)) {
            sql += " ,other_advice=?";
        }
        sql +=" where code=?";
        if (StringUtils.isNotEmpty(otherAdvice)){
            jdbcTemplate.update(sql,new Object[]{adviceCodes,otherAdvice,code});
        }else {
            jdbcTemplate.update(sql,new Object[]{adviceCodes,code});
        sql += " where code=?";
        if (StringUtils.isNotEmpty(otherAdvice)) {
            jdbcTemplate.update(sql, new Object[]{adviceCodes, otherAdvice, code});
        } else {
            jdbcTemplate.update(sql, new Object[]{adviceCodes, code});
        }
    }
    public void updateColume(String colume,Object value,String code){
        String sql ="UPDATE wlyy_survey_screen_result SET "+colume+"=? where code=?";
        jdbcTemplate.update(sql,new Object[]{value,code});
    public void updateColume(String colume, Object value, String code) {
        String sql = "UPDATE wlyy_survey_screen_result SET " + colume + "=? where code=?";
        jdbcTemplate.update(sql, new Object[]{value, code});
    }
    public Map<String,Object> patientGetList(int pageNo,int pageSize,int labelType,String patientCode){
        Map<String,Object> map = new HashedMap();
        List<SurveyTemplates> templates = getScreenList(pageNo,pageSize,labelType,null);
        List<Map<String,Object>> mapList = new ArrayList<>();
        for (SurveyTemplates surveyTemplates : templates){
            Map<String,Object> sMap = new HashedMap();
            sMap.put("surveyTemplate",surveyTemplates);
            int count =  surveyScreenResultDao.getByPatientCodeAndTemplateCode(patientCode,surveyTemplates.getCode(),2).size();
            sMap.put("myRecordCount",count);
    public Map<String, Object> patientGetList(int pageNo, int pageSize, int labelType, String patientCode) {
        Map<String, Object> map = new HashedMap();
        List<SurveyTemplates> templates = getScreenList(pageNo, pageSize, labelType, null);
        List<Map<String, Object>> mapList = new ArrayList<>();
        for (SurveyTemplates surveyTemplates : templates) {
            Map<String, Object> sMap = new HashedMap();
            sMap.put("surveyTemplate", surveyTemplates);
            int count = surveyScreenResultDao.getByPatientCodeAndTemplateCode(patientCode, surveyTemplates.getCode(), 2).size();
            sMap.put("myRecordCount", count);
            mapList.add(sMap);
        }
        map.put("screenList",mapList);
        map.put("screenList", mapList);
        return map;
    }
    public List<SurveyScreenResult> patientGetResult(String patientCode){
        Map<String,Object> map = new HashedMap();
        String sql = "SELECT a.* FROM (SELECT * FROM wlyy_survey_screen_result WHERE source=2 and patient_code='"+patientCode+"' ORDER BY czrq DESC) a  GROUP BY a.template_code";
        List<SurveyScreenResult> surveyScreenResultList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(SurveyScreenResult.class));
    public List<SurveyScreenResult> patientGetResult(String patientCode) {
        Map<String, Object> map = new HashedMap();
        String sql = "SELECT a.* FROM (SELECT * FROM wlyy_survey_screen_result WHERE source=2 and patient_code='" + patientCode + "' ORDER BY czrq DESC) a  GROUP BY a.template_code";
        List<SurveyScreenResult> surveyScreenResultList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(SurveyScreenResult.class));
        return surveyScreenResultList;
    }
    public List<Map<String,Object>> getResultByTemplateCode(int pageNo,int pageSize,String templateCode,String patientCode){
        int start = (pageNo-1)*pageSize;
        String sql ="SELECT st.*,ssr.code screenCode,ssr.screen_result,ssr.screen_result_score,ssr.czrq as screenCzrq,ssr.is_again FROM wlyy_survey_templates st LEFT JOIN wlyy_survey_screen_result ssr ON st.code = ssr.template_code WHERE ssr.source=2 and st.`code`='"+templateCode+"' AND ssr.patient_code='"+patientCode+"' order by ssr.czrq limit ?,?";
        return jdbcTemplate.queryForList(sql,new Object[]{start,pageSize});
    public List<Map<String, Object>> getResultByTemplateCode(int pageNo, int pageSize, String templateCode, String patientCode) {
        int start = (pageNo - 1) * pageSize;
        String sql = "SELECT st.*,ssr.code screenCode,ssr.screen_result,ssr.screen_result_score,ssr.czrq as screenCzrq,ssr.is_again FROM wlyy_survey_templates st LEFT JOIN wlyy_survey_screen_result ssr ON st.code = ssr.template_code WHERE ssr.source=2 and st.`code`='" + templateCode + "' AND ssr.patient_code='" + patientCode + "' order by ssr.czrq limit ?,?";
        return jdbcTemplate.queryForList(sql, new Object[]{start, pageSize});
    }
    public Map<String,Object> screenStatics(String doctor){
        Map<String,Object> resultMap = new HashedMap();
        String userSql = "SELECT DISTINCT(template_code) FROM wlyy_survey_screen_result WHERE doctor = '"+doctor+"' and source=1";
        List<String> userList = jdbcTemplate.queryForList(userSql,String.class);
    public Map<String, Object> screenStatics(String doctor) {
        Map<String, Object> resultMap = new HashedMap();
        String userSql = "SELECT DISTINCT(template_code) FROM wlyy_survey_screen_result WHERE doctor = '" + doctor + "' and source=1";
        List<String> userList = jdbcTemplate.queryForList(userSql, String.class);
        //使用筛查表数量
        resultMap.put("useTemplateCount",userList.size());
        String sql = "SELECT * FROM wlyy_survey_screen_result WHERE doctor='"+doctor+"' and source=1";
        List<SurveyScreenResult> surveyScreenResultList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(SurveyScreenResult.class));
        resultMap.put("useTemplateCount", userList.size());
        String sql = "SELECT * FROM wlyy_survey_screen_result WHERE doctor='" + doctor + "' and source=1";
        List<SurveyScreenResult> surveyScreenResultList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(SurveyScreenResult.class));
        //下发问卷数量
        resultMap.put("grantCount",surveyScreenResultList.size());
        resultMap.put("grantCount", surveyScreenResultList.size());
        int overCount = 0;
        int warnCount = 0;
        int followCount = 0;
        int orderCount = 0 ;
        int orderCount = 0;
        int againCount = 0;
        int eduCount = 0;
        for (SurveyScreenResult surveyScreenResult : surveyScreenResultList){
            if (surveyScreenResult.getOver()==1){
        for (SurveyScreenResult surveyScreenResult : surveyScreenResultList) {
            if (surveyScreenResult.getOver() == 1) {
                overCount++;
            }
            if (surveyScreenResult.getIsDanger()==1){
            if (surveyScreenResult.getIsDanger() == 1) {
                warnCount++;
            }
            if (surveyScreenResult.getFollowing()==1){
            if (surveyScreenResult.getFollowing() == 1) {
                followCount++;
            }
            if (surveyScreenResult.getIsOrder()>0){
            if (surveyScreenResult.getIsOrder() > 0) {
                orderCount++;
            }
            if (StringUtils.isNotEmpty(surveyScreenResult.getParentCode())){
            if (StringUtils.isNotEmpty(surveyScreenResult.getParentCode())) {
                againCount++;
            }
            if (surveyScreenResult.getIsEducate()==1){
            if (surveyScreenResult.getIsEducate() == 1) {
                eduCount++;
            }
        }
        //筛查记录
        resultMap.put("overCount",overCount);
        resultMap.put("overCount", overCount);
        //疑似高危
        resultMap.put("dangetCount",warnCount);
        resultMap.put("dangetCount", warnCount);
        //健康跟踪
        resultMap.put("followCount",followCount);
        resultMap.put("followCount", followCount);
        //已跟踪
        resultMap.put("orderCount",orderCount);
        resultMap.put("orderCount", orderCount);
        //再次评估
        resultMap.put("againCount",againCount);
        resultMap.put("againCount", againCount);
        //健康教育
        resultMap.put("eduCount",eduCount);
        return  resultMap;
        resultMap.put("eduCount", eduCount);
        return resultMap;
    }
    public int getAmountByDoctor(String json,String doctorCode) {
        return getCountByDoctor(json,doctorCode).size();
    public int getAmountByDoctor(String json, String doctorCode) {
        return getCountByDoctor(json, doctorCode).size();
    }
    public List<String> getCountByDoctor(String json,String doctorCode) {
    public List<String> getCountByDoctor(String json, String doctorCode) {
//        1.服务 2.健康 3疾病
        JSONObject jsonObject = new JSONObject(json);
        String sql = "";
        String sex = jsonObject.get("sex").toString();
        String str = "SELECT DISTINCT lb.patient FROM wlyy_sign_patient_label_info lb,(SELECT DISTINCT ff.patient FROM wlyy_sign_family_server s, " +
                " (SELECT f.`code`,f.patient FROM wlyy_sign_family f,wlyy_patient p WHERE p.CODE=f.patient and (f.doctor='"+doctorCode+"' OR  f.doctor_health='"+doctorCode+"')";
                " (SELECT f.`code`,f.patient FROM wlyy_sign_family f,wlyy_patient p WHERE p.CODE=f.patient and (f.doctor='" + doctorCode + "' OR  f.doctor_health='" + doctorCode + "')";
        if (!"0".equals(sex)) {
            str += " AND p.sex=  " + sex +
                    " AND f.STATUS>0 AND p.`openid` IS NOT NULL AND p.`openid`!='')ff WHERE ff.CODE=s.sign_code ";
                    " AND f.STATUS>0 AND f.expenses_status = 1 AND p.`openid` IS NOT NULL AND p.`openid`!='')ff WHERE ff.CODE=s.sign_code ";
        } else {
            str += " AND f.STATUS>0 AND p.`openid`IS NOT NULL AND p.`openid`!='')ff WHERE ff.CODE=s.sign_code ";
            str += " AND f.STATUS>0 AND f.expenses_status = 1 AND p.`openid`IS NOT NULL AND p.`openid`!='')ff WHERE ff.CODE=s.sign_code ";
        }
        JSONArray service = jsonObject.getJSONArray("service");
        String ser = "";
@ -532,17 +525,17 @@ public class SurveyScreenResultService extends BaseService {
            dis += " OR ";
        }
        if (StringUtils.isNotEmpty(dis)) {
            disSql= " (lb.label_type =3 AND ( " + dis.substring(0, dis.lastIndexOf("OR")) + " )  )";
            disSql = " (lb.label_type =3 AND ( " + dis.substring(0, dis.lastIndexOf("OR")) + " )  )";
        }
        if (StringUtils.isEmpty(heal) && StringUtils.isEmpty(dis)) {
            sql = str;
        } else if (StringUtils.isEmpty(heal) && StringUtils.isNotEmpty(dis)) {
            sql = str + " AND " +disSql;
            sql = str + " AND " + disSql;
        } else if (StringUtils.isNotEmpty(heal) && StringUtils.isEmpty(dis)) {
            sql = str + " AND " +healSql;
            sql = str + " AND " + healSql;
        } else if (StringUtils.isNotEmpty(heal) && StringUtils.isNotEmpty(dis)) {
            sql = str + " AND ( " + disSql +" OR " +healSql +" ) ";
            sql = str + " AND ( " + disSql + " OR " + healSql + " ) ";
        }
        System.out.println("=====query sql =======>>>>" + sql);
@ -699,7 +692,7 @@ public class SurveyScreenResultService extends BaseService {
        countJson.put("disease", diseaList);
        countJson.put("healthCondition", healthList);
        countJson.put("service", servList);
        List<String> codes = getCountByDoctor(countJson.toString(),doctor);
        List<String> codes = getCountByDoctor(countJson.toString(), doctor);
        int amount = codes.size();
        for (String code : codes) {
//            String code = patient.get("patient").toString();
@ -749,7 +742,7 @@ public class SurveyScreenResultService extends BaseService {
                }
//            });
            }*/
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","scwj");
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey", "scwj");
            String remark = templateConfig.getRemark();
            String keyword1 = templateConfig.getKeyword1();
            String wxTemplateCode = templateCode;
@ -760,20 +753,20 @@ public class SurveyScreenResultService extends BaseService {
                        String name = null;
                        String openId = null;
                        String first = null;
                        String screenCode =null;
                        String screenCode = null;
                        try {
                            screenCode = saveAfterBatchScreen(c,openId,name,doctor,wxTemplateCode);
                            screenCode = saveAfterBatchScreen(c, openId, name, doctor, wxTemplateCode);
                            p = patientDao.findByCode(c);
                            name = p.getName();
                            openId = p.getOpenid();
                            json.put("keyword1", keyword1);
                            json.put("keyword2", sdf.format(new Date()));
                            json.put("survey", wxTemplateCode+"_"+doctor);
                            json.put("survey", wxTemplateCode + "_" + doctor);
                            json.put("toUser", c);
                            json.put("url","jkpg/html/wx-template-message.html?survey="+wxTemplateCode+"&doctor="+doctor+"&toUser="+c+"&toName="+name+"&screenCode="+screenCode);
                            json.put("url", "jkpg/html/wx-template-message.html?survey=" + wxTemplateCode + "&doctor=" + doctor + "&toUser=" + c + "&toName=" + name + "&screenCode=" + screenCode);
//                          String first = name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。";
                            first = templateConfig.getFirst();
                            first = first.replace("key1",(name==null?"":name));
                            first = first.replace("key1", (name == null ? "" : name));
                            json.put("first", first);
                            json.put("remark", remark);
                        } catch (JSONException e) {
@ -785,7 +778,7 @@ public class SurveyScreenResultService extends BaseService {
                            logger.error("json =======>" + json);
//                            PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
                            pushMsgTask.sendWeixinMessage(accessToken, 11, openId, name, json);
                        }else {
                        } else {
                            //发送代理人
                            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
                            if (jsonArray != null && jsonArray.length() > 0) {
@ -795,7 +788,7 @@ public class SurveyScreenResultService extends BaseService {
                                    if (StringUtils.isNotBlank(member.getOpenid())) {
                                        json.remove("toUser");
                                        json.put("toUser", member.getCode());
                                        json.put("url","jkpg/html/wx-template-message.html?survey="+wxTemplateCode+"&doctor="+doctor+"&toUser="+member.getCode()+"&toName="+member.getName()+"&screenCode="+screenCode);
                                        json.put("url", "jkpg/html/wx-template-message.html?survey=" + wxTemplateCode + "&doctor=" + doctor + "&toUser=" + member.getCode() + "&toName=" + member.getName() + "&screenCode=" + screenCode);
                                        json.remove("first");
                                        try {
                                            json.put("keyword1", keyword1);
@ -1028,23 +1021,23 @@ public class SurveyScreenResultService extends BaseService {
        return surveyCode;
    }
    public String saveAfterBatchScreen(String patientCode,String openId,String patientName,String doctorCode,String surveyCode){
        SurveyScreenResult surveyScreenResult =  new SurveyScreenResult();
    public String saveAfterBatchScreen(String patientCode, String openId, String patientName, String doctorCode, String surveyCode) {
        SurveyScreenResult surveyScreenResult = new SurveyScreenResult();
        SurveyTemplates surveyTemplates = surveyTemplatesDao.findById(surveyCode);
        Patient patient = patientDao.findByCode(patientCode);
        String code = getCode();
        surveyScreenResult.setCode(code);
        if (surveyTemplates!=null){
        if (surveyTemplates != null) {
            surveyScreenResult.setTemplateCode(surveyTemplates.getCode());
            surveyScreenResult.setTemplateTitle(surveyTemplates.getTitle());
            surveyScreenResult.setDisease(surveyTemplates.getDiseaseType());
        }
        surveyScreenResult.setDoctor(doctorCode);
        surveyScreenResult.setPatientCode(patientCode);
        if (patient!=null){
        if (patient != null) {
            surveyScreenResult.setPatientName(patient.getName());
            surveyScreenResult.setOpenId(patient.getOpenid());
        }else {
        } else {
            surveyScreenResult.setOpenId(openId);
            surveyScreenResult.setPatientName(patientName);
        }
@ -1063,10 +1056,10 @@ public class SurveyScreenResultService extends BaseService {
    }
    public String updateScreenAndSaveAnswer(String patientCode,String screenCode, JSONObject jsonData)throws Exception{
    public String updateScreenAndSaveAnswer(String patientCode, String screenCode, JSONObject jsonData) throws Exception {
        System.out.println("********保存筛查结果--jsonData********* " + jsonData);
        String surveyCode = jsonData.get("surveyCode").toString();
        SurveyScreenResult surveyScreenResult =  surveyScreenResultDao.getSurveyScreenResultByCode(screenCode);
        SurveyScreenResult surveyScreenResult = surveyScreenResultDao.getSurveyScreenResultByCode(screenCode);
        //解析json保存各种答案--获取一维数组
        JSONArray questions = jsonData.getJSONArray("questions");
        int totalScore = 0;
@ -1088,7 +1081,7 @@ public class SurveyScreenResultService extends BaseService {
            }
        }
        //查询该筛查的结果设置
        SurveyTemplateResult surveyTemplateResult = surveyTemplateResultDao.getByTemplateCodeAndLowScoreAndHighScore(surveyCode,totalScore);
        SurveyTemplateResult surveyTemplateResult = surveyTemplateResultDao.getByTemplateCodeAndLowScoreAndHighScore(surveyCode, totalScore);
       /* surveyScreenResult.setOver(1);
        surveyScreenResult.setCzrq(new Date());
        surveyScreenResult.setScreenResultScore(totalScore);
@ -1097,11 +1090,49 @@ public class SurveyScreenResultService extends BaseService {
            surveyScreenResult.setIsDanger(surveyTemplateResult.getWarning());
            surveyScreenResult.setScreenResult(surveyTemplateResult.getResult());
        }*/
       String sql ="UPDATE wlyy_survey_screen_result SET over=1,czrq=?,screen_result_code=?,screen_result=?,screen_result_score=?,is_danger=? WHERE code=?";
       jdbcTemplate.update(sql,new Object[]{new Date(),surveyTemplateResult.getCode(),surveyTemplateResult.getResult(),totalScore,surveyTemplateResult.getWarning(),screenCode});
        String sql = "UPDATE wlyy_survey_screen_result SET over=1,czrq=?,screen_result_code=?,screen_result=?,screen_result_score=?,is_danger=? WHERE code=?";
        jdbcTemplate.update(sql, new Object[]{new Date(), surveyTemplateResult.getCode(), surveyTemplateResult.getResult(), totalScore, surveyTemplateResult.getWarning(), screenCode});
        //surveyScreenResultDao.updateScreenAndSaveAnswer(new Date(),totalScore,surveyTemplateResult.getCode(),surveyTemplateResult.getResult(),surveyTemplateResult.getWarning(),screenCode);
        managerQuestionnaireService.saveAnswer(patientCode,surveyScreenResult.getCode(),jsonData);
        managerQuestionnaireService.saveAnswer(patientCode, surveyScreenResult.getCode(), jsonData);
        return screenCode;
    }
    //获取筛查居民信息
    public List<Map<String, Object>> initPatient(String doctor, String labelType, String serverType, Long teamCode) {
        String sql = "SELECT DISTINCT p.`code` as service_patient_code, p.`name` as service_patient_name, t1.ssc,t1.idcard,t1.mobile,t1.hospital,t1.hospital_name,h.town,h.town_name " +
                "FROM  wlyy_sign_family t1  LEFT JOIN wlyy_patient p on p. CODE = t1.patient   " +
                "LEFT JOIN wlyy_sign_patient_label_info t2 on t2.patient = t1.patient and t2.label_type = " + labelType + " and t2.status=1 " +
                "RIGHT JOIN wlyy_sign_family_server s on s.sign_code = t1.code and s.server_type in (" + serverType + ") " +
                "LEFT JOIN dm_hospital h on t1.hospital = h.`code` " +
                "WHERE ( t1.doctor = ? OR t1.doctor_health = ?) AND t1. STATUS > 0  and t1.expenses_status = 1 AND t1.admin_team_code = ? " +
                "AND p.openid IS NOT NULL AND p.openid <>'' ";
        Object[] args = new Object[]{doctor, doctor, teamCode};
        List<Map<String, Object>> patientInfo = jdbcTemplate.queryForList(sql, args);
        return patientInfo;
    }
    /**
     * 调用集美客服派发问卷协同服务接口
     *
     * @param jsonData
     * @param patientInfo
     * @param doctor
     * @return
     * @throws Exception
     */
    public String createWorkOrder(String jsonData, List<Map<String, Object>> patientInfo, String doctor) throws Exception {
        JSONObject object = new JSONObject(jsonData);
        Doctor d = doctorService.findDoctorByCode(doctor);
        object.put("createUser", d.getCode());
        object.put("createUserName", d.getName());
        object.put("createUserType", 1);
        Map<String, Object> param = new HashedMap();
        param.put("patientInfo", patientInfo.toString());
        param.put("jsonData", object.toString());
        HttpResponse response = null;
        response = HttpUtils.doPost(customerUrl + "wlyy-manage/createWorkOrder", param);
        JSONObject rs = new JSONObject(response.getContent());
        return rs.getString("message");
    }
}

+ 0 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java

@ -10,7 +10,6 @@ import com.yihu.wlyy.repository.doctor.*;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.survey.SurveyScreenResultService;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.http.HttpResponse;
@ -96,8 +95,6 @@ public class ManagerQuestionnaireService extends BaseService {
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    @Autowired
    private SurveyScreenResultService surveyScreenResultService;
    @Autowired
    private DoctorService doctorService;
    private Logger logger = LoggerFactory.getLogger(this.getClass());

+ 14 - 7
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/survey/DoctorSurveyScreenResultController.java

@ -22,6 +22,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
/**
 * 医生端-疾病筛查
 * Created by zhangdan on 2018/7/2.
@ -226,19 +229,23 @@ public class DoctorSurveyScreenResultController extends WeixinBaseController {
        }
    }
    /*@RequestMapping(value = "/createWorkOrder",method = RequestMethod.POST)
    @RequestMapping(value = "/createWorkOrder",method = RequestMethod.POST)
    @ApiOperation(value = "创建协同服务")
    public String getAllQuestions(@ApiParam(name = "jsonData",value = "协同服务json字符串")
                                  @RequestParam(value = "jsonData",required = true)String jsonData,
                                  @ApiParam(value = "筛选条件",defaultValue = "{\"sex\":1,\"disease\":[2,5,6],\"healthCondition\":[0],\"service\":[1,3]}")
                                  @RequestParam(value = "conditionJson",required = true) String conditionJson){
                                  @ApiParam(name = "labelType", value = "疾病类型", defaultValue = "3")
                                  @RequestParam(value = "labelType", required = true) String labelType,
                                  @ApiParam(name = "serverType",value = "多个条件以逗号分割")
                                  @RequestParam(value = "serverType", required = true) String serverType,
                                  @ApiParam(name = "teamCode",value = "行政团队id")
                                  @RequestParam(value = "teamCode", required = true) Long teamCode){
        try {
            surveyScreenResultService.findPatientInfo(conditionJson);
            JSONObject jsonObject = managerQuestionnaireService.getAllQuestions(surveyTemplateCode);
            return write(200, "查询成功!", "data", jsonObject);
            List<Map<String, Object>> patientInfo = surveyScreenResultService.initPatient(getUID(), labelType, serverType, teamCode);
            return write(200, "查询成功!", "data", surveyScreenResultService.createWorkOrder(jsonData, patientInfo, getUID()));
        } catch (Exception e) {
            e.printStackTrace();
            return write(-1, "查询失败!");
        }
    }*/
    }
}