|
@ -0,0 +1,182 @@
|
|
|
|
package com.yihu.wlyy.service.synergy;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.yihu.wlyy.entity.survey.SurveyQuestionResult;
|
|
|
|
import com.yihu.wlyy.entity.survey.SurveyTemplateQuestions;
|
|
|
|
import com.yihu.wlyy.entity.synergy.ManageSynergyWorkorderDO;
|
|
|
|
import com.yihu.wlyy.entity.synergy.ManageSynergyWorkorderServicerDO;
|
|
|
|
import com.yihu.wlyy.repository.survey.SurveyQuestionResultDao;
|
|
|
|
import com.yihu.wlyy.repository.survey.SurveyTemplateQuestionsDao;
|
|
|
|
import com.yihu.wlyy.repository.synergy.ManageSynergyWorkOrderDao;
|
|
|
|
import com.yihu.wlyy.repository.synergy.ManageSynergyWorkorderServicerDao;
|
|
|
|
import com.yihu.wlyy.util.HttpClientUtil;
|
|
|
|
import com.yihu.wlyy.util.query.BaseJpaService;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by humingfen on 2018/09/27.
|
|
|
|
*/
|
|
|
|
@Service
|
|
|
|
public class QuestionnaireManageService extends BaseJpaService {
|
|
|
|
|
|
|
|
@Value("${wlyy.url}")
|
|
|
|
private String wlyyUrl;
|
|
|
|
@Autowired
|
|
|
|
private HttpClientUtil httpClientUtil;
|
|
|
|
@Autowired
|
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
@Autowired
|
|
|
|
private ManageSynergyWorkOrderDao workOrderDao;
|
|
|
|
@Autowired
|
|
|
|
private ManageSynergyWorkorderServicerDao workorderServicerDao;
|
|
|
|
@Autowired
|
|
|
|
private SurveyTemplateQuestionsDao templateQuestionDao;
|
|
|
|
@Autowired
|
|
|
|
private SurveyQuestionResultDao questionResultDao;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 创建协同服务
|
|
|
|
* @param workorderDO
|
|
|
|
* @param workorderServicerDOS
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean createWorkOrder(ManageSynergyWorkorderDO workorderDO, List<ManageSynergyWorkorderServicerDO> workorderServicerDOS) {
|
|
|
|
String servicer = null;
|
|
|
|
int size = workorderServicerDOS.size();
|
|
|
|
int len = 0;
|
|
|
|
if(size > 5){
|
|
|
|
len = 5;
|
|
|
|
}else {
|
|
|
|
len = size;
|
|
|
|
}
|
|
|
|
//获取服务对象最多五个人
|
|
|
|
for(int i = 0; i < len; i++){
|
|
|
|
servicer += workorderServicerDOS.get(i).getServicePatientName() + ",";
|
|
|
|
}
|
|
|
|
servicer = servicer.substring(0, servicer.length()-1);
|
|
|
|
//保存协同服务工单
|
|
|
|
workorderDO.setCode(getCode());
|
|
|
|
workorderDO.setStatus(1);
|
|
|
|
workorderDO.setCreateTime(new Date());
|
|
|
|
workorderDO.setDel(1);
|
|
|
|
workorderDO.setServicerCount(size);
|
|
|
|
workorderDO.setServicerKey(servicer);
|
|
|
|
workOrderDao.save(workorderDO);
|
|
|
|
|
|
|
|
//保存协同服务工单的服务对象
|
|
|
|
for(ManageSynergyWorkorderServicerDO servicerDO : workorderServicerDOS){
|
|
|
|
servicerDO.setCode(getCode());
|
|
|
|
servicerDO.setWorkorderType(workorderDO.getType());
|
|
|
|
servicerDO.setWorkorderCode(workorderDO.getCode());
|
|
|
|
servicerDO.setStatus(1);
|
|
|
|
servicerDO.setCreateTime(new Date());
|
|
|
|
workorderServicerDao.save(servicerDO);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 保存问卷结果
|
|
|
|
* @param patientCode
|
|
|
|
* @param labelType
|
|
|
|
* @param customerCode
|
|
|
|
* @param isAgain
|
|
|
|
* @param source
|
|
|
|
* @param jsonData
|
|
|
|
* @param serviceCode
|
|
|
|
*/
|
|
|
|
public String saveResultAndAnswer(String patientCode, Integer labelType, String customerCode, int isAgain, int source, String jsonData, String serviceCode) {
|
|
|
|
String url = wlyyUrl + "doctor/questionnaire/saveResultAndAnswer";
|
|
|
|
String response = "";
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
params.put("labelType", labelType);
|
|
|
|
params.put("patientCode", patientCode);
|
|
|
|
params.put("jsonData", jsonData);
|
|
|
|
params.put("customerCode", customerCode);
|
|
|
|
params.put("source", source);
|
|
|
|
try {
|
|
|
|
response = httpClientUtil.post(url, params);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
JSONObject object = JSONObject.parseObject(response);
|
|
|
|
String questionResultCode = object.getString("data");
|
|
|
|
if(StringUtils.isNotBlank(questionResultCode)) {
|
|
|
|
workorderServicerDao.updateRelationCodeByCode(serviceCode, questionResultCode);
|
|
|
|
}
|
|
|
|
return questionResultCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查看调查问卷统计结果
|
|
|
|
* @param templateCode
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public JSONObject getAnswers(String templateCode) {
|
|
|
|
String url = wlyyUrl + "doctor/questionnaire/getAnswers";
|
|
|
|
String response = "";
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
params.put("templateId", templateCode);
|
|
|
|
try {
|
|
|
|
response = httpClientUtil.post(url, params);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return JSONObject.parseObject(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据问卷结果code查看居民填写问卷详情
|
|
|
|
* @param code
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public JSONObject getReuslt(String code){
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
//查找问卷结果信息
|
|
|
|
SurveyQuestionResult questionResult = questionResultDao.findByCode(code);
|
|
|
|
String patient = questionResult.getPatientCode();
|
|
|
|
String templateCode = questionResult.getTemplateCode();
|
|
|
|
//获取模板问题
|
|
|
|
List<SurveyTemplateQuestions> questionList = templateQuestionDao.findByTemplateCode(templateCode);
|
|
|
|
//查找选项和答案
|
|
|
|
Map<String, Object> answerMap = new HashMap<>();
|
|
|
|
String sql = "SELECT soa.*, 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, patient, templateCode});
|
|
|
|
for (SurveyTemplateQuestions templateQuestion : questionList) {
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
map.put("question", templateQuestion);
|
|
|
|
String qusCode = templateQuestion.getCode();
|
|
|
|
for (Map<String, Object> option : optionAnswersList) {
|
|
|
|
if (option.get("question_code").equals(qusCode)) {
|
|
|
|
map.put("option", option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
answerMap.put(templateQuestion.getSort() + "", map);
|
|
|
|
}
|
|
|
|
json.put("answer", answerMap);
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
|
|
|
public JSONObject getQuestionnaireDetail(String surveyCode) {
|
|
|
|
String url = wlyyUrl + "doctor/questionnaire/getQuestionnaireDetail";
|
|
|
|
String response = "";
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
params.put("id", surveyCode);
|
|
|
|
try {
|
|
|
|
response = httpClientUtil.post(url, params);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return JSONObject.parseObject(response);
|
|
|
|
}
|
|
|
|
}
|