Browse Source

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

humingfen 7 năm trước cách đây
mục cha
commit
7b9d5bb684

+ 233 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/doctor/survey/SurveyScreenResult.java

@ -0,0 +1,233 @@
package com.yihu.wlyy.entity.doctor.survey;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
 * Created by zhangdan on 2018/7/2.
 */
@Entity
@Table(name = "wlyy_survey_screen_result")
public class SurveyScreenResult extends IdEntity implements Serializable{
    //模板编码
    private String templateCode;
    //模板标题
    private  String templateTitle;
    //疾病类型(根据模板表的疾病类型定义)
    private int disease;
    //医生code
    private String doctor;
    //居民code
    private String patientCode;
    //居民openid
    private String openId;
    //居民名字
    private String patientName;
    //筛查结果分值
    private int screenResultScore;
    //筛查结果
    private String screenResult;
    //是否预约(0未预约 1已预约)
    private int order;
    //是否跟踪(0未跟踪 1已跟踪)
    private int following;
    //是否完成(0未完成 1已完成)
    private int over;
    //预约记录code
    private String reservationCode;
    //创建时间
    private Date czrq;
    //是否可以再次评估(0不可以 1可以)
    private int isAgain;
    //再次筛查的上一份记录code
    private String parentCode;
    //首份记录code
    private String originCode;
    //建议code,多个逗号隔开
    private String adviceCode;
    //其他建议
    private String otherAdvice;
    public SurveyScreenResult() {
    }
    @Column(name = "template_code")
    public String getTemplateCode() {
        return templateCode;
    }
    public void setTemplateCode(String templateCode) {
        this.templateCode = templateCode;
    }
    @Column(name = "template_title")
    public String getTemplateTitle() {
        return templateTitle;
    }
    public void setTemplateTitle(String templateTitle) {
        this.templateTitle = templateTitle;
    }
    @Column(name = "disease")
    public int getDisease() {
        return disease;
    }
    public void setDisease(int disease) {
        this.disease = disease;
    }
    @Column(name = "doctor")
    public String getDoctor() {
        return doctor;
    }
    public void setDoctor(String doctor) {
        this.doctor = doctor;
    }
    @Column(name = "patient_code")
    public String getPatientCode() {
        return patientCode;
    }
    public void setPatientCode(String patientCode) {
        this.patientCode = patientCode;
    }
    @Column(name = "open_id")
    public String getOpenId() {
        return openId;
    }
    public void setOpenId(String openId) {
        this.openId = openId;
    }
    @Column(name = "patient_name")
    public String getPatientName() {
        return patientName;
    }
    public void setPatientName(String patientName) {
        this.patientName = patientName;
    }
    @Column(name = "screen_result_score")
    public int getScreenResultScore() {
        return screenResultScore;
    }
    public void setScreenResultScore(int screenResultScore) {
        this.screenResultScore = screenResultScore;
    }
    @Column(name = "screen_result")
    public String getScreenResult() {
        return screenResult;
    }
    public void setScreenResult(String screenResult) {
        this.screenResult = screenResult;
    }
    @Column(name = "order")
    public int getOrder() {
        return order;
    }
    public void setOrder(int order) {
        this.order = order;
    }
    @Column(name = "following")
    public int getFollowing() {
        return following;
    }
    public void setFollowing(int following) {
        this.following = following;
    }
    @Column(name = "over")
    public int getOver() {
        return over;
    }
    public void setOver(int over) {
        this.over = over;
    }
    @Column(name = "reservation_code")
    public String getReservationCode() {
        return reservationCode;
    }
    public void setReservationCode(String reservationCode) {
        this.reservationCode = reservationCode;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    @Column(name = "czrq")
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
    @Column(name = "is_again")
    public int getIsAgain() {
        return isAgain;
    }
    public void setIsAgain(int isAgain) {
        this.isAgain = isAgain;
    }
    @Column(name = "parent_code")
    public String getParentCode() {
        return parentCode;
    }
    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }
    @Column(name = "origin_code")
    public String getOriginCode() {
        return originCode;
    }
    public void setOriginCode(String originCode) {
        this.originCode = originCode;
    }
    @Column(name = "advice_code")
    public String getAdviceCode() {
        return adviceCode;
    }
    public void setAdviceCode(String adviceCode) {
        this.adviceCode = adviceCode;
    }
    @Column(name = "other_advice")
    public String getOtherAdvice() {
        return otherAdvice;
    }
    public void setOtherAdvice(String otherAdvice) {
        this.otherAdvice = otherAdvice;
    }
}

+ 13 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/SurveyScreenResultDao.java

@ -0,0 +1,13 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.survey.SurveyScreenResult;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by zhangdan on 2018/7/2.
 */
public interface SurveyScreenResultDao extends PagingAndSortingRepository<SurveyScreenResult, Long> {
}

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

@ -0,0 +1,273 @@
package com.yihu.wlyy.service.app.survey;
import com.yihu.wlyy.entity.doctor.survey.*;
import com.yihu.wlyy.repository.doctor.*;
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.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
 * Created by zhangdan on 2018/7/2.
 */
@Service
@Transactional
public class SurveyScreenResultService extends BaseService {
    @Autowired
    private SurveyQuestionnaireDao surveyQuestionnaireDao;
    @Autowired
    private SurveyQuestionnaireOptionsDao surveyQuestionnaireOptionsDao;
    @Autowired
    private SurveyDao surveyDao;
    @Autowired
    private SurveyUserDao surveyUserDao;
    @Autowired
    private SurveyOptionAnswersDao surveyOptionAnswersDao;
    @Autowired
    private SurveyAnswersDao surveyAnswersDao;
    @Autowired
    SurveyStatisticsDao surveyStatisticsDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private SurveyTemplatesDao surveyTemplatesDao;
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    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.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(diseaseType)){
            sql += " AND ssr.disease="+diseaseType;
        }
        if (StringUtils.isNotEmpty(patientName)){
            sql += " AND ssr.patient_name like '%"+patientName+"%'";
        }
        if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("1",dealType)){
            //已预约
            sql += " AND ssr.`order` = 1";
        }
        if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("2",dealType)){
            //已跟踪
            sql += " AND ssr.following= 1";
        }
        if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("3",dealType)){
            //已接诊
            sql += " AND ssr.reservtion_code is not null";
        }
        Map<String,Object> map = jdbcTemplate.queryForMap(countSql);
        sql += " limit "+start+","+pageSize;
        List<SurveyScreenResult> surveyScreenResultList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(SurveyScreenResult.class));
        map.put("data",surveyScreenResultList);
        return map;
    }
    public List<SurveyTemplates> getScreenList(int pageNo,int pageSize,int labelType){
        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+" limit "+start+","+pageSize;
        List<SurveyTemplates> surveyTemplatesList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(SurveyTemplates.class));
        return surveyTemplatesList;
    }
    public JSONObject getSurveySummary(String patient, String id) throws Exception {
        JSONObject jsonObject = new JSONObject();
        Survey survey = surveyDao.findById(id);
        int complete = surveyUserDao.findByPatient(patient, id);
        String title = survey.getTitle();
        String comment = survey.getSurveyComment();
        int status = survey.getStatus();
        jsonObject.put("title", title);
        jsonObject.put("comment", comment);
        jsonObject.put("status", status);
        jsonObject.put("complete", complete == 0 ? 0 : 1);
        return jsonObject;
    }
    /**
     * @param id   问卷id
     * @param sort 当前问题的sort(初始为1)
     */
    public JSONObject getQuestions(String id, Integer sort) throws Exception {
        JSONObject jsonObject = new JSONObject();
        SurveyQuestionnaire question = null;
        //      该套问卷总题目数
        int total = surveyQuestionnaireDao.findTotalById(id);
        question = surveyQuestionnaireDao.findTotalByIdAndSort(id, sort);
        int sorts = question.getSort();
        String qstCode = question.getCode();
        String qstTitle = question.getTitle();
        int isRequired = question.getIsRequired();
        if (question.getQuestionCodeNext() != null) {
            String next = question.getQuestionCodeNext();
            SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
            System.out.println("");
            jsonObject.put("nextQuestion", sq == null ? 0 : sq.getSort());
        }
        if (!StringUtils.isEmpty(question.getQuestionComment())) {
            jsonObject.put("comment", question.getQuestionComment());
        }
        int type = question.getQuestionType();
        switch (type) {
            case 0:
                List<SurveyQuestionnaireOptions> options = surveyQuestionnaireOptionsDao.findByIdAndQstCode(id, qstCode);
                List list = new ArrayList();
                for (SurveyQuestionnaireOptions option : options) {
//                        可构造集合,返回选项特定值
                    Map<String, Object> map = new HashMap<>();
                    String content = option.getContent();
                    int optSort = option.getSort();
                    int required = option.getIsRequired();
                    String surCod = option.getSurveyCode();
                    int del = option.getDel();
                    int havaComment = option.getHaveComment();
                    String code = option.getCode();
                    String questionCode = option.getQuestionnaireCode();
                    long optid = option.getId();
                    map.put("content", content);
                    map.put("isRequired", required);
                    map.put("code", code);
                    map.put("del", del);
                    map.put("sort", optSort);
                    map.put("surveyCode", surCod);
                    map.put("havaComment", havaComment);
                    map.put("questionnaireCode", questionCode);
                    map.put("id", optid);
                    if (option.getQuestionCodeNext() != null) {
                        String next = option.getQuestionCodeNext();
                        SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
                        map.put("nextQuestion", sq == null ? 0 : sq.getSort());
                    }
                    list.add(map);
                }
                jsonObject.put("options", list);
                break;
            case 1:
                List<SurveyQuestionnaireOptions> optionss = surveyQuestionnaireOptionsDao.findByIdAndQstCode(id, qstCode);
                List lis = new ArrayList();
                for (SurveyQuestionnaireOptions option : optionss) {
//                        可构造集合,返回选项特定值
                    Map<String, Object> map = new HashMap<>();
                    String content = option.getContent();
                    int optSort = option.getSort();
                    int required = option.getIsRequired();
                    String surCod = option.getSurveyCode();
                    int del = option.getDel();
                    int havaComment = option.getHaveComment();
                    String code = option.getCode();
                    String questionCode = option.getQuestionnaireCode();
                    long optid = option.getId();
                    map.put("content", content);
                    map.put("isRequired", required);
                    map.put("code", code);
                    map.put("del", del);
                    map.put("sort", optSort);
                    map.put("surveyCode", surCod);
                    map.put("havaComment", havaComment);
                    map.put("questionnaireCode", questionCode);
                    map.put("id", optid);
                    if (option.getQuestionCodeNext() != null) {
                        String next = option.getQuestionCodeNext();
                        SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
                        map.put("nextQuestion", sq == null ? 0 : sq.getSort());
                    }
                    lis.add(map);
                }
                jsonObject.put("options", lis);
                Integer maxNum = question.getMaxNum();
                Integer minNum = question.getMinNum();
                jsonObject.put("maxNum", maxNum);
                jsonObject.put("minNum", minNum);
//                jsonObject.put("options", optionss);
                break;
           /* case 2:
                if (question.getQuestionCodeNext() != null) {
                    String next = question.getQuestionCodeNext();
                    SurveyQuestionnaire sq = surveyQuestionnaireDao.findByIdAndQstId(id, next);
                    jsonObject.put("nextQuestion", sq.getSort());
                }
                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);
        logger.error("居民获取题目信息==》" + jsonObject);
        return jsonObject;
    }
    public void saveAnswer(String patient, JSONObject jsonData) throws Exception {
        System.out.println("********jsonData********* " + jsonData);
        //解析json保存各种答案
        String surveyCode = jsonData.get("surveyCode").toString();
        Date createTime = new Date();
//        获取一维数组
        JSONArray questions = jsonData.getJSONArray("questions");
        for (int i = 0; i < questions.length(); i++) {
//            获取每一道题的信息
            JSONObject question = new JSONObject(questions.get(i).toString());
            String qstCode = question.get("qstCode").toString();
            int qstsort = Integer.parseInt(question.get("sort").toString());
            int type = Integer.parseInt(question.get("type").toString());
            if (type != 2) {
                if (question.has("options")) {
//               获取每道题的所有选项
                    JSONArray options = question.getJSONArray("options");
                    for (int j = 0; j < options.length(); j++) {
                        JSONObject option = new JSONObject(options.get(j).toString());
                        String code = getCode();
                        String optionCode = option.get("optionCode").toString();
                        int optsort = Integer.parseInt(option.get("sort").toString());
                        String comment = null;
                        int haveComment = 0;
                        if (option.has("comment")) {
                            comment = option.get("comment").toString();
                            haveComment = 1;
                        }
//                 保存到选择题答案表
                        SurveyOptionAnswers optionAnswer = new SurveyOptionAnswers(code, patient, surveyCode, qstCode, optionCode, comment, type, createTime);
                        surveyOptionAnswersDao.save(optionAnswer);
//                选择题修改统计表数量
                        surveyStatisticsDao.modifyAmount(surveyCode, qstCode, optionCode);
                    }
                }
            } else {
                String content = question.get("content").toString();
                if (!StringUtils.isEmpty(content)) {
//                    保存到问答题答案表
                    String code = getCode();
                    SurveyAnswers surveyAnswer = new SurveyAnswers(code, surveyCode, patient, qstCode, content, createTime);
                    surveyAnswersDao.save(surveyAnswer);
//                问答题保存到统计表(只负责更改数量不负责创建)
                    surveyStatisticsDao.modifyAmount(surveyCode, qstCode);
                }
            }
        }
//        更改调查对象表答题状态为已答
        surveyUserDao.modifyStatus(surveyCode, patient);
    }
}

+ 84 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/survey/DoctorQuestionnaireController.java

@ -0,0 +1,84 @@
package com.yihu.wlyy.web.doctor.survey;
import com.yihu.wlyy.repository.questionnaire.QuestionnaireUsersDao;
import com.yihu.wlyy.service.questionnaire.QuestionnaireService;
import com.yihu.wlyy.service.survey.PatientQuestionnaireService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * Created by zhangdan on 2018/7/3.
 */
@Controller
@RequestMapping(value = "/doctor/questionnaire")
@Api(description = "医生端端问卷调查")
public class DoctorQuestionnaireController extends BaseController {
    @Autowired
    private PatientQuestionnaireService patientQuestionnaireService;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private QuestionnaireService questionnaireService;
    @Autowired
    private QuestionnaireUsersDao questionnaireUsersDao;
    @RequestMapping(value = "getSurveySummary", method = RequestMethod.GET)
    @ApiOperation(value = "居民端获取问卷概述")
    @ResponseBody
    public String getSurveySummary(
            @ApiParam(value = "问卷编码")
            @RequestParam String id) {
        try {
            String patient = getRepUID();
//            String patient = getUID();
            JSONObject jsonObject = patientQuestionnaireService.getSurveySummary(patient, id);
            return write(200, "查询成功!", "data", jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            return write(-1, "查询失败!");
        }
    }
    @RequestMapping(value = "getQuestions", method = RequestMethod.GET)
    @ApiOperation(value = "按升序获取问卷的问题")
    @ResponseBody
    public String getQuestions(@ApiParam(value = "问卷编码")@RequestParam String templateCode,
            @ApiParam(value = "当前问题的sort(初始为1)")@RequestParam Integer sort) {
        try {
            JSONObject jsonObject = patientQuestionnaireService.getQuestions(templateCode, sort);
            return write(200, "查询成功!", "data", jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            return write(-1, "查询失败!");
        }
    }
    @RequestMapping(value = "saveAnswer", method = RequestMethod.POST)
    @ApiOperation(value = "保存用户答案")
    @ResponseBody
    public String saveAnswer( @RequestParam String jsonData,
                              @ApiParam(value = "居民code")@RequestParam(value = "patientCode")String patientCode,
                              @ApiParam(value = "问卷标签")@RequestParam(value = "labelType")int labelType) {
        try {
            JSONObject json = new JSONObject(jsonData);
            patientQuestionnaireService.saveAnswer(patientCode, json);
            //@TODO 如果是筛查还要保存结果
            return write(200, "保存成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return write(-1, "保存失败!");
        }
    }
}

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 563 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/survey/SurveyScreenResultController.java