|
@ -4,15 +4,22 @@ 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.survey.ManagerQuestionnaireService;
|
|
|
import com.yihu.wlyy.task.PushMsgTask;
|
|
|
import com.yihu.wlyy.util.IdCardUtil;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@ -22,6 +29,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@ -47,11 +55,49 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
@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;
|
|
|
@Autowired
|
|
|
private SurveyQuestionnaireOptionsDao surveyQuestionnaireOptionsDao;
|
|
|
@Autowired
|
|
|
private SurveyQuestionnaireDao surveyQuestionnaireDao;
|
|
|
@Autowired
|
|
|
private SurveyTemplateOptionsDao surveyTemplateOptionsDao;
|
|
|
@Autowired
|
|
|
private SurveyAnswersDao surveyAnswersDao;
|
|
|
@Autowired
|
|
|
private SystemDictDao systemDictDao;
|
|
|
@Autowired
|
|
|
private SurveyDimensionDao surveyDimensionDao;
|
|
|
@Autowired
|
|
|
private SurveyDimensionDetailDao surveyDimensionDetailDao;
|
|
|
@Autowired
|
|
|
private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
|
|
|
@Autowired
|
|
|
WeiXinOpenIdUtils weiXinOpenIdUtils;
|
|
|
@Autowired
|
|
|
private PushMsgTask pushMsgTask;
|
|
|
@Autowired
|
|
|
private WechatTemplateConfigDao templateConfigDao;
|
|
|
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
@ -84,7 +130,7 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("1",dealType)){
|
|
|
//已预约
|
|
|
sql += " AND ssr.order = 1";
|
|
|
sql += " AND ssr.is_order = 1";
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("2",dealType)){
|
|
|
//已跟踪
|
|
@ -92,14 +138,15 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("3",dealType)){
|
|
|
//已接诊
|
|
|
sql += " AND ssr.order = 2";
|
|
|
sql += " AND ssr.is_order = 2";
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("4",dealType)){
|
|
|
//待处理
|
|
|
sql +=" AND ssr.`order` = 0 AND ssr.following= 0";
|
|
|
sql +=" AND ssr.is_order = 0 AND ssr.following= 0";
|
|
|
}
|
|
|
List<Map<String,Object>> maps = jdbcTemplate.queryForList(sql);
|
|
|
sql += " limit "+start+","+pageSize;
|
|
|
|
|
|
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());
|
|
@ -115,9 +162,14 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
* @param labelType
|
|
|
* @return
|
|
|
*/
|
|
|
public List<SurveyTemplates> getScreenList(int pageNo,int pageSize,int labelType){
|
|
|
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+" limit "+start+","+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+"%'";
|
|
|
}
|
|
|
sql += " order by st.create_time desc limit "+start+","+pageSize;
|
|
|
List<SurveyTemplates> surveyTemplatesList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(SurveyTemplates.class));
|
|
|
return surveyTemplatesList;
|
|
|
}
|
|
@ -129,7 +181,7 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
* @param source
|
|
|
* @param jsonData
|
|
|
*/
|
|
|
public String saveScreenResult(String patientCode,String doctor,int isAgain,int source, JSONObject jsonData){
|
|
|
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);
|
|
@ -138,6 +190,7 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
//解析json保存各种答案--获取一维数组
|
|
|
JSONArray questions = jsonData.getJSONArray("questions");
|
|
|
int totalScore = 0;
|
|
|
|
|
|
for (int i = 0; i < questions.length(); i++) {
|
|
|
//获取每一道题的信息
|
|
|
JSONObject question = new JSONObject(questions.get(i).toString());
|
|
@ -148,7 +201,20 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
JSONArray options = question.getJSONArray("options");
|
|
|
for (int j = 0; j < options.length(); j++) {
|
|
|
JSONObject option = new JSONObject(options.get(j).toString());
|
|
|
int score = Integer.parseInt(option.getString("score"));
|
|
|
/*String code = getCode();
|
|
|
String optionCode = option.get("optionCode").toString();
|
|
|
String comment = null;
|
|
|
int haveComment = 0;
|
|
|
if (option.has("comment")) {
|
|
|
comment = option.get("comment").toString();
|
|
|
haveComment = 1;
|
|
|
}
|
|
|
//保存到选择题答案表
|
|
|
SurveyOptionAnswers optionAnswer = new SurveyOptionAnswers(code, patientCode, surveyCode, qstCode, optionCode, comment, type, createTime,patient.getOpenid());
|
|
|
surveyOptionAnswersDao.save(optionAnswer);
|
|
|
//选择题修改统计表数量
|
|
|
surveyStatisticsDao.modifyAmount(surveyCode, qstCode, optionCode);*/
|
|
|
int score = option.getInt("score");
|
|
|
totalScore += score;
|
|
|
}
|
|
|
}
|
|
@ -157,7 +223,7 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
//查询该筛查的结果设置
|
|
|
SurveyTemplateResult surveyTemplateResult = surveyTemplateResultDao.getByTemplateCodeAndLowScoreAndHighScore(surveyCode,totalScore);
|
|
|
//更新上一条数据为不可再次评估
|
|
|
List<SurveyScreenResult> surveyScreenResultList = surveyScreenResultDao.findNewOneByTemplateCode(surveyCode);
|
|
|
List<SurveyScreenResult> surveyScreenResultList = surveyScreenResultDao.findNewOneByTemplateCode(surveyCode,patientCode);
|
|
|
String lastCode = "";
|
|
|
String originCode = "";
|
|
|
if (surveyScreenResultList!=null && surveyScreenResultList.size()>0){
|
|
@ -184,7 +250,7 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
//来自医生发放和自我评估不一样来源
|
|
|
if (source==1){
|
|
|
surveyScreenResult.setDoctor(doctor);
|
|
|
}else {
|
|
|
}/*else {
|
|
|
SignFamily signFamily = signFamilyDao.findByPatient(patientCode);
|
|
|
if (signFamily!=null && StringUtils.isNotEmpty(signFamily.getDoctor())){
|
|
|
surveyScreenResult.setDoctor(signFamily.getDoctor());
|
|
@ -193,17 +259,18 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
surveyScreenResult.setDoctor(signFamily.getDoctorHealth());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}*/
|
|
|
surveyScreenResult.setPatientCode(patientCode);
|
|
|
if (patient!=null){
|
|
|
surveyScreenResult.setPatientName(patient.getName());
|
|
|
surveyScreenResult.setOpenId(patient.getOpenid());
|
|
|
}
|
|
|
surveyScreenResult.setOrder(0);
|
|
|
surveyScreenResult.setIsOrder(0);
|
|
|
surveyScreenResult.setFollowing(0);
|
|
|
surveyScreenResult.setOver(1);
|
|
|
surveyScreenResult.setCzrq(new Date());
|
|
|
surveyScreenResult.setIsAgain(1);
|
|
|
surveyScreenResult.setIsEducate(0);
|
|
|
surveyScreenResult.setScreenResultScore(totalScore);
|
|
|
if (surveyTemplateResult!=null){
|
|
|
surveyScreenResult.setScreenResultCode(surveyTemplateResult.getCode());
|
|
@ -211,8 +278,8 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
surveyScreenResult.setScreenResult(surveyTemplateResult.getResult());
|
|
|
}
|
|
|
surveyScreenResultDao.save(surveyScreenResult);
|
|
|
managerQuestionnaireService.saveAnswer(patientCode,code,jsonData);
|
|
|
return code;
|
|
|
|
|
|
}
|
|
|
|
|
|
public JSONObject getScreenResultDetail(String code)throws Exception{
|
|
@ -225,16 +292,17 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
json.put("message","没有改筛查结果!");
|
|
|
return json;
|
|
|
}
|
|
|
/*String idcard = String.valueOf(infoMap.get("idcard"));
|
|
|
infoMap.put("sex",IdCardUtil.getSexForIdcard(idcard));
|
|
|
infoMap.put("age",IdCardUtil.getAgeForIdcard(idcard));*/
|
|
|
String idcard = String.valueOf(infoMap.get("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 doctorCode = String.valueOf(infoMap.get("doctor"));
|
|
|
String patientCode = String.valueOf(infoMap.get("patient_code"));
|
|
|
/* Doctor doctor = doctorDao.findByCode(doctorCode);
|
|
|
Doctor doctor = doctorDao.findByCode(doctorCode);
|
|
|
if (doctor!=null){
|
|
|
infoMap.put("level",doctor.getLevel());
|
|
|
infoMap.put("doctorName",doctor.getName());
|
|
|
}*/
|
|
|
}
|
|
|
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);
|
|
@ -244,7 +312,8 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
|
|
|
//题目和答案
|
|
|
List<SurveyTemplateQuestions> questionList = surveyTemplateQuestionsDao.findById(templateCode);
|
|
|
String sql = "SELECT soa.*,sto.score 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=?";
|
|
|
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<>();
|
|
@ -255,13 +324,14 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
map.put("option",option);
|
|
|
}
|
|
|
}
|
|
|
json.put(surveyTemplateQuestions.getSort()+"",map);
|
|
|
answerMap.put(surveyTemplateQuestions.getSort()+"",map);
|
|
|
}
|
|
|
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);
|
|
|
int following = Integer.parseInt(String.valueOf(infoMap.get("following")));
|
|
|
int order = Integer.parseInt(String.valueOf(infoMap.get("order")));
|
|
|
int order = Integer.parseInt(String.valueOf(infoMap.get("is_order")));
|
|
|
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+"'";
|
|
@ -279,7 +349,8 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
surveyAdviceList.add(surveyAdviceDao.getByCode(adviceCode));
|
|
|
}
|
|
|
}
|
|
|
resultMap.put("advice",surveyAdviceList);
|
|
|
resultMap.put("doctorAdvice",surveyAdviceList);
|
|
|
resultMap.put("doctorOtherAdvice",infoMap.get("other_advice"));
|
|
|
}
|
|
|
json.put("result",resultMap);
|
|
|
return json;
|
|
@ -311,25 +382,28 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
|
|
|
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);
|
|
|
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()).size();
|
|
|
int count = surveyScreenResultDao.getByPatientCodeAndTemplateCode(patientCode,surveyTemplates.getCode(),2).size();
|
|
|
sMap.put("myRecordCount",count);
|
|
|
mapList.add(sMap);
|
|
|
}
|
|
|
map.put("screenList",mapList);
|
|
|
String sql = "SELECT a.* FROM (SELECT * FROM wlyy_survey_screen_result WHERE patient_code='"+patientCode+"' ORDER BY czrq DESC) a GROUP BY a.template_code";
|
|
|
List<SurveyScreenResult> surveyScreenResultList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(SurveyScreenResult.class));
|
|
|
map.put("result",surveyScreenResultList);
|
|
|
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));
|
|
|
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 st.`code`='"+templateCode+"' AND ssr.patient_code='"+patientCode+"' limit ?,?";
|
|
|
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});
|
|
|
}
|
|
|
|
|
@ -359,7 +433,7 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
if (surveyScreenResult.getFollowing()==1){
|
|
|
followCount++;
|
|
|
}
|
|
|
if (surveyScreenResult.getOrder()==1){
|
|
|
if (surveyScreenResult.getIsOrder()==1){
|
|
|
orderCount++;
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(surveyScreenResult.getParentCode())){
|
|
@ -384,8 +458,570 @@ public class SurveyScreenResultService extends BaseService {
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
public int getAmountByDoctor(String json,String doctorCode) {
|
|
|
return getCountByDoctor(json,doctorCode).size();
|
|
|
}
|
|
|
|
|
|
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+"')";
|
|
|
|
|
|
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 ";
|
|
|
} else {
|
|
|
str += " AND f.STATUS>0 AND p.`openid`IS NOT NULL AND p.`openid`!='')ff WHERE ff.CODE=s.sign_code ";
|
|
|
}
|
|
|
JSONArray service = jsonObject.getJSONArray("service");
|
|
|
String ser = "";
|
|
|
service:
|
|
|
for (Object serv : service) {
|
|
|
String type = serv.toString();
|
|
|
switch (type) {
|
|
|
case "0":
|
|
|
break service;
|
|
|
default:
|
|
|
ser += " s.server_type= " + type;
|
|
|
break;
|
|
|
}
|
|
|
ser += " OR ";
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(ser)) {
|
|
|
str += " AND ( " + ser.substring(0, ser.lastIndexOf("OR")) + " ) ";
|
|
|
}
|
|
|
str += " )tt WHERE lb.`status` = 1 AND lb.patient=tt.patient ";
|
|
|
|
|
|
JSONArray healthCondition = jsonObject.getJSONArray("healthCondition");
|
|
|
String healSql = "";
|
|
|
String heal = "";
|
|
|
health:
|
|
|
for (Object health : healthCondition) {
|
|
|
String type = health.toString();
|
|
|
switch (type) {
|
|
|
case "0":
|
|
|
break health;
|
|
|
default:
|
|
|
heal += " lb.label= " + type;
|
|
|
break;
|
|
|
}
|
|
|
heal += " OR ";
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(heal)) {
|
|
|
healSql = " (lb.label_type =2 AND ( " + heal.substring(0, heal.lastIndexOf("OR")) + " ) )";
|
|
|
}
|
|
|
|
|
|
JSONArray disease = jsonObject.getJSONArray("disease");
|
|
|
String disSql = "";
|
|
|
String dis = "";
|
|
|
disea:
|
|
|
for (Object disea : disease) {
|
|
|
String type = disea.toString();
|
|
|
switch (type) {
|
|
|
case "0":
|
|
|
break disea;
|
|
|
default:
|
|
|
dis += " lb.label= " + type;
|
|
|
break;
|
|
|
}
|
|
|
dis += " OR ";
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(dis)) {
|
|
|
disSql= " (lb.label_type =3 AND ( " + dis.substring(0, dis.lastIndexOf("OR")) + " ) )";
|
|
|
}
|
|
|
|
|
|
public void getSpecialDoctorScreenList(String doctor,int type,int pageNo,int pageSize){
|
|
|
if (StringUtils.isEmpty(heal) && StringUtils.isEmpty(dis)) {
|
|
|
sql = str;
|
|
|
} else if (StringUtils.isEmpty(heal) && StringUtils.isNotEmpty(dis)) {
|
|
|
sql = str + " AND " +disSql;
|
|
|
} else if (StringUtils.isNotEmpty(heal) && StringUtils.isEmpty(dis)) {
|
|
|
sql = str + " AND " +healSql;
|
|
|
} else if (StringUtils.isNotEmpty(heal) && StringUtils.isNotEmpty(dis)) {
|
|
|
sql = str + " AND ( " + disSql +" OR " +healSql +" ) ";
|
|
|
}
|
|
|
|
|
|
System.out.println("=====query sql =======>>>>" + sql);
|
|
|
List<String> patients = jdbcTemplate.queryForList(sql, String.class);
|
|
|
return patients;
|
|
|
}
|
|
|
|
|
|
|
|
|
public String createSurvey(String doctor, JSONObject jsonStr, String accessToken) throws Exception {
|
|
|
// 问卷信息
|
|
|
String surveyCode = getCode();
|
|
|
String surveyName = jsonStr.getString("surveyName");
|
|
|
String surveyComment = jsonStr.getString("comment");
|
|
|
String templateCode = null;
|
|
|
String send = jsonStr.get("send").toString();
|
|
|
String templateLabel = jsonStr.getString("label");
|
|
|
int status = 1;
|
|
|
// 自主创建
|
|
|
int useType = 1;
|
|
|
if (!StringUtils.isEmpty(jsonStr.getString("templateCode"))) {
|
|
|
// 模板创建
|
|
|
useType = 0;
|
|
|
templateCode = jsonStr.getString("templateCode");
|
|
|
}
|
|
|
// 获取调查对象
|
|
|
JSONObject surveyTarget = jsonStr.getJSONObject("surveyTarget");
|
|
|
// 0不限 1男 2女
|
|
|
// int sex = Integer.parseInt(surveyTarget.get("sex").toString());
|
|
|
JSONArray sex = surveyTarget.getJSONArray("sex");
|
|
|
JSONArray disease = surveyTarget.getJSONArray("disease");
|
|
|
JSONArray service = surveyTarget.getJSONArray("service");
|
|
|
JSONArray healthCondition = surveyTarget.getJSONArray("healthCondition");
|
|
|
|
|
|
int sexList = 0;
|
|
|
for (Object se : sex) {
|
|
|
JSONObject sexJson = new JSONObject(se.toString());
|
|
|
int label = sexJson.getInt("label");
|
|
|
sexList = label;
|
|
|
if (label != 0) {
|
|
|
String dimensionCode = surveyDimensionDao.findByName("性别");
|
|
|
String dimensionDetailCode = getCode();
|
|
|
// SurveyDimensionDetail surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, sex == 1 ? "男" : "女", sex, "性别", 1, surveyCode);
|
|
|
// modify by wjj 2017.7.24 居民标签更改
|
|
|
SurveyDimensionDetail surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, sexJson.getString("labelName"), label, "性别", 1, surveyCode);
|
|
|
surveyDimensionDetailDao.save(surveyDimensionDetail);
|
|
|
// 保存到筛选表
|
|
|
SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
|
|
|
surveyFilterDao.save(surveyFilter);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List servList = new ArrayList();
|
|
|
for (Object serv : service) {
|
|
|
JSONObject servJson = new JSONObject(serv.toString());
|
|
|
int label = servJson.getInt("label");
|
|
|
servList.add(label);
|
|
|
if (label == 0) {
|
|
|
break;
|
|
|
} else {
|
|
|
// ===================================
|
|
|
String dimensionCode = surveyDimensionDao.findByName("服务类型");
|
|
|
String dimensionDetailCode = getCode();
|
|
|
SurveyDimensionDetail surveyDimensionDetail = null;
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, servJson.getString("labelName"), label, "服务类型", 3, surveyCode);
|
|
|
/* switch (Integer.parseInt(serv.toString())) {
|
|
|
// 1.普通人群 2.慢病人群 3.65岁以上人群
|
|
|
case 1:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "普通人群", 1, "服务类型", 3, surveyCode);
|
|
|
break;
|
|
|
case 2:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "慢病人群", 2, "服务类型", 3, surveyCode);
|
|
|
break;
|
|
|
case 3:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "65岁以上人群", 3, "服务类型", 3, surveyCode);
|
|
|
break;
|
|
|
}
|
|
|
*/
|
|
|
surveyDimensionDetailDao.save(surveyDimensionDetail);
|
|
|
|
|
|
SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
|
|
|
surveyFilterDao.save(surveyFilter);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List healthList = new ArrayList();
|
|
|
for (Object health : healthCondition) {
|
|
|
JSONObject healthJson = new JSONObject(health.toString());
|
|
|
int label = healthJson.getInt("label");
|
|
|
healthList.add(label);
|
|
|
if (label == 0) {
|
|
|
break;
|
|
|
} else {
|
|
|
String dimensionCode = surveyDimensionDao.findByName("健康状况");
|
|
|
String dimensionDetailCode = getCode();
|
|
|
String surveyFilterCode = getCode();
|
|
|
SurveyDimensionDetail surveyDimensionDetail = null;
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, healthJson.getString("labelName"), label, "健康状况", 4, surveyCode);
|
|
|
|
|
|
/*switch (Integer.parseInt(health.toString())) {
|
|
|
// 1.健康人群 2.患病人群 3.高危人群 4.恢复期人群
|
|
|
case 1:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "健康人群", 1, "健康状况", 4, surveyCode);
|
|
|
break;
|
|
|
case 2:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "患病人群", 2, "健康状况", 4, surveyCode);
|
|
|
break;
|
|
|
case 3:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "高危人群", 3, "健康状况", 4, surveyCode);
|
|
|
break;
|
|
|
case 4:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "恢复期人群", 4, "健康状况", 4, surveyCode);
|
|
|
break;
|
|
|
}*/
|
|
|
surveyDimensionDetailDao.save(surveyDimensionDetail);
|
|
|
|
|
|
SurveyFilter surveyFilter = new SurveyFilter(surveyFilterCode, surveyCode, dimensionDetailCode);
|
|
|
surveyFilterDao.save(surveyFilter);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List diseaList = new ArrayList();
|
|
|
for (Object disea : disease) {
|
|
|
JSONObject diseaJson = new JSONObject(disea.toString());
|
|
|
int label = diseaJson.getInt("label");
|
|
|
diseaList.add(label);
|
|
|
if (label == 0) {
|
|
|
// dise += ",";
|
|
|
break;
|
|
|
} else {
|
|
|
String dimensionCode = surveyDimensionDao.findByName("疾病类型");
|
|
|
String dimensionDetailCode = getCode();
|
|
|
SurveyDimensionDetail surveyDimensionDetail = null;
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, diseaJson.getString("labelName"), label, "疾病类型", 2, surveyCode);
|
|
|
|
|
|
/*switch (Integer.parseInt(disea.toString())) {
|
|
|
// 1.高血压 2糖尿病 3.高血压+糖尿病
|
|
|
case 1:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "高血压", 1, "疾病类型", 2, surveyCode);
|
|
|
break;
|
|
|
case 2:
|
|
|
surveyDimensionDetail = new SurveyDimensionDetail(dimensionDetailCode, dimensionCode, "糖尿病", 2, "疾病类型", 2, surveyCode);
|
|
|
break;
|
|
|
}*/
|
|
|
surveyDimensionDetailDao.save(surveyDimensionDetail);
|
|
|
|
|
|
SurveyFilter surveyFilter = new SurveyFilter(getCode(), surveyCode, dimensionDetailCode);
|
|
|
surveyFilterDao.save(surveyFilter);
|
|
|
}
|
|
|
}
|
|
|
// List<String> codes = getCount(surveyTarget.toString());
|
|
|
JSONObject countJson = new JSONObject();
|
|
|
countJson.put("sex", sexList);
|
|
|
countJson.put("disease", diseaList);
|
|
|
countJson.put("healthCondition", healthList);
|
|
|
countJson.put("service", servList);
|
|
|
List<String> codes = getCountByDoctor(countJson.toString(),doctor);
|
|
|
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)) {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
// String str = "{\"remark\":\"我们将按调查最终结果,优化健康服务。\",\"keyword1\":\"调查问卷\"}";
|
|
|
// JSONObject json = new JSONObject(str);
|
|
|
JSONObject json = new JSONObject();
|
|
|
/* 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", code);
|
|
|
json.put("survey_id", surveyCode);
|
|
|
json.put("first", name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。");
|
|
|
logger.error("patient =======>" + code);
|
|
|
logger.error("name =======>" + name);
|
|
|
logger.error("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());
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
// });
|
|
|
}*/
|
|
|
WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_doctor_survey","scwj");
|
|
|
String remark = templateConfig.getRemark();
|
|
|
String keyword1 = templateConfig.getKeyword1();
|
|
|
String wxTemplateCode = templateCode;
|
|
|
new Thread() {
|
|
|
public void run() {
|
|
|
for (String c : codes) {
|
|
|
Patient p = null;
|
|
|
String name = null;
|
|
|
String openId = null;
|
|
|
String first = null;
|
|
|
try {
|
|
|
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("toUser", c);
|
|
|
json.put("url","jkpg/html/start-survey.html?survey="+wxTemplateCode+"_"+doctor);
|
|
|
// String first = name + ",您好!为了给您提供更好的家庭医生健康服务,现有一份问卷需要您填写。";
|
|
|
first = templateConfig.getFirst();
|
|
|
first = first.replace("key1",(name==null?"":name));
|
|
|
json.put("first", first);
|
|
|
json.put("remark", remark);
|
|
|
} catch (JSONException e) {
|
|
|
continue;
|
|
|
}
|
|
|
//判断是否判定openId,有没有发则查找家人发送
|
|
|
if (StringUtils.isNotBlank(p.getOpenid())) {
|
|
|
// 添加到发送队列
|
|
|
logger.error("json =======>" + json);
|
|
|
// PushMsgTask.getInstance().putWxMsg(accessToken, 11, openId, name, json);
|
|
|
pushMsgTask.sendWeixinMessage(accessToken, 11, openId, name, json);
|
|
|
}else {
|
|
|
//发送代理人
|
|
|
JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(), p.getOpenid());
|
|
|
if (jsonArray != null && jsonArray.length() > 0) {
|
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
|
JSONObject j = jsonArray.getJSONObject(i);
|
|
|
Patient member = (Patient) j.get("member");
|
|
|
if (StringUtils.isNotBlank(member.getOpenid())) {
|
|
|
json.remove("toUser");
|
|
|
json.put("toUser", member.getCode());
|
|
|
json.put("url","jkpg/html/start-survey.html?survey="+wxTemplateCode+"_"+doctor);
|
|
|
json.remove("first");
|
|
|
try {
|
|
|
json.put("keyword1", keyword1);
|
|
|
json.put("first", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) + first);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
pushMsgTask.sendWeixinMessage(weiXinAccessTokenUtils.getAccessToken(), 11, member.getOpenid(), p.getName(), json);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}.start();
|
|
|
}
|
|
|
// =====================================================
|
|
|
// 获取标签数组
|
|
|
SurveyLabelInfo surveyLabelInfo = new SurveyLabelInfo();
|
|
|
surveyLabelInfo.setCode(getCode());
|
|
|
surveyLabelInfo.setRelationCode(surveyCode);
|
|
|
surveyLabelInfo.setUseType(useType);
|
|
|
surveyLabelInfo.setLabel(Integer.parseInt(templateLabel));
|
|
|
SurveyLabelInfo ss = surveyLabelInfoDao.save(surveyLabelInfo);
|
|
|
/* JSONArray lables = jsonStr.getJSONArray("label");
|
|
|
// 标签保存到wlyy_survey_label_info
|
|
|
for (Object label : lables) {
|
|
|
SurveyLabelInfo surveyLabelInfo = new SurveyLabelInfo();
|
|
|
surveyLabelInfo.setCode(getCode());
|
|
|
surveyLabelInfo.setRelationCode(surveyCode);
|
|
|
surveyLabelInfo.setUseType(useType);
|
|
|
surveyLabelInfo.setLabel(Integer.parseInt(label.toString()));
|
|
|
SurveyLabelInfo ss = surveyLabelInfoDao.save(surveyLabelInfo);
|
|
|
}*/
|
|
|
// 获取问题数组
|
|
|
JSONArray questions = jsonStr.getJSONArray("questions");
|
|
|
for (Object question : questions) {
|
|
|
JSONObject tempQestion = new JSONObject(question.toString());
|
|
|
// 不分题型都有的属性
|
|
|
String questionnaireCode = tempQestion.get("qstCode").toString();
|
|
|
String title = tempQestion.get("title").toString();
|
|
|
String comment = tempQestion.get("comment").toString();
|
|
|
int type = Integer.parseInt(tempQestion.get("type").toString());
|
|
|
int isRequired = Integer.parseInt(tempQestion.get("isRequired").toString());
|
|
|
int sort = Integer.parseInt(tempQestion.get("sort").toString());
|
|
|
int del = 1;
|
|
|
String qstNextQuestion = null;
|
|
|
// 前提一定要有nextQuestion字段传入,没有为""
|
|
|
if (!StringUtils.isEmpty(tempQestion.get("nextQuestion").toString())) {
|
|
|
// optionNextQuestion = tempOption.get("nextQuestion").toString();
|
|
|
qstNextQuestion = surveyTemplateQuestionsDao.findBySort(templateCode, tempQestion.get("nextQuestion"));
|
|
|
qstNextQuestion = (qstNextQuestion == null ? "0" : qstNextQuestion);
|
|
|
}
|
|
|
switch (type) {
|
|
|
case 0:
|
|
|
// 单选
|
|
|
SurveyQuestionnaire surveyQuestionnaire = new SurveyQuestionnaire();
|
|
|
surveyQuestionnaire.setCode(questionnaireCode);
|
|
|
surveyQuestionnaire.setTitle(title);
|
|
|
surveyQuestionnaire.setQuestionComment(comment);
|
|
|
surveyQuestionnaire.setQuestionType(type);
|
|
|
surveyQuestionnaire.setSurveyCode(surveyCode);
|
|
|
surveyQuestionnaire.setIsRequired(isRequired);
|
|
|
surveyQuestionnaire.setDel(del);
|
|
|
surveyQuestionnaire.setSort(sort);
|
|
|
surveyQuestionnaire.setCreateTime(new Date());
|
|
|
surveyQuestionnaire.setUpdateTime(new Date());
|
|
|
// 单选没有最大最小选项数及题目逻辑跳转
|
|
|
surveyQuestionnaire.setMinNum(null);
|
|
|
surveyQuestionnaire.setMaxNum(null);
|
|
|
surveyQuestionnaire.setQuestionCodeNext(qstNextQuestion);
|
|
|
|
|
|
surveyQuestionnaireDao.save(surveyQuestionnaire);
|
|
|
// =======================选项保存=========================
|
|
|
// 选择题
|
|
|
JSONArray options = new JSONArray(tempQestion.get("options").toString());
|
|
|
for (Object option : options) {
|
|
|
// String optionCode = getCode();
|
|
|
JSONObject tempOption = new JSONObject(option.toString());
|
|
|
String optionCode = tempOption.get("optCode").toString();
|
|
|
int haveComment = Integer.parseInt(tempOption.get("haveComment").toString());
|
|
|
String optionComment = tempOption.get("content").toString();
|
|
|
int required = Integer.parseInt(tempOption.get("isRequired").toString());
|
|
|
int optionSort = Integer.parseInt(tempOption.get("sort").toString());
|
|
|
int optionDel = 1;
|
|
|
String optionNextQuestion = null;
|
|
|
if (!StringUtils.isEmpty(tempOption.get("nextQuestion").toString())) {
|
|
|
// optionNextQuestion = tempOption.get("nextQuestion").toString();
|
|
|
optionNextQuestion = surveyTemplateQuestionsDao.findBySort(templateCode, tempOption.get("nextQuestion"));
|
|
|
optionNextQuestion = (optionNextQuestion == null ? "0" : optionNextQuestion);
|
|
|
}
|
|
|
// 自主创建,插入表
|
|
|
SurveyQuestionnaireOptions surveyQuestionnaireOptions = new SurveyQuestionnaireOptions(optionCode, haveComment, questionnaireCode, optionComment,
|
|
|
surveyCode, optionNextQuestion, required, optionSort, optionDel);
|
|
|
/* surveyQuestionnaireOptions.setCode(optionCode);
|
|
|
surveyQuestionnaireOptions.setHaveComment(haveComment);
|
|
|
surveyQuestionnaireOptions.setQuestionnaireCode(questionnaireCode);
|
|
|
surveyQuestionnaireOptions.setContent(optionComment);
|
|
|
surveyQuestionnaireOptions.setSurveyCode(surveyCode);
|
|
|
surveyQuestionnaireOptions.setQuestionCodeNext(optionNextQuestion);
|
|
|
surveyQuestionnaireOptions.setIsRequired(required);
|
|
|
surveyQuestionnaireOptions.setSort(optionSort);
|
|
|
surveyQuestionnaireOptions.setDel(optionDel);*/
|
|
|
surveyQuestionnaireOptionsDao.save(surveyQuestionnaireOptions);
|
|
|
|
|
|
// 单选题保存到统计表
|
|
|
String statisticsCode = getCode();
|
|
|
String questionTitle = surveyQuestionnaireDao.findByIdAndQstId(surveyCode, questionnaireCode).getTitle();
|
|
|
String optcontent = surveyQuestionnaireOptionsDao.findByRelationCode(surveyCode, questionnaireCode, optionCode).getContent();
|
|
|
SurveyStatistics statistics = new SurveyStatistics(statisticsCode, surveyCode, questionnaireCode, questionTitle, optionCode, 0, optcontent, haveComment, type, sort, optionSort);
|
|
|
surveyStatisticsDao.save(statistics);
|
|
|
}
|
|
|
break;
|
|
|
case 1:
|
|
|
// 多选特有属性
|
|
|
Integer maxOptions = null;
|
|
|
Integer minOptions = null;
|
|
|
if (!StringUtils.isEmpty(tempQestion.get("minOptions").toString())) {
|
|
|
minOptions = Integer.parseInt(tempQestion.get("minOptions").toString());
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(tempQestion.get("maxOptions").toString())) {
|
|
|
maxOptions = Integer.parseInt(tempQestion.get("maxOptions").toString());
|
|
|
}
|
|
|
SurveyQuestionnaire surveyQuestionnaire1 = new SurveyQuestionnaire();
|
|
|
surveyQuestionnaire1.setCode(questionnaireCode);
|
|
|
surveyQuestionnaire1.setTitle(title);
|
|
|
surveyQuestionnaire1.setQuestionComment(comment);
|
|
|
surveyQuestionnaire1.setQuestionType(type);
|
|
|
surveyQuestionnaire1.setSurveyCode(surveyCode);
|
|
|
surveyQuestionnaire1.setIsRequired(isRequired);
|
|
|
surveyQuestionnaire1.setMinNum(minOptions);
|
|
|
surveyQuestionnaire1.setMaxNum(maxOptions);
|
|
|
surveyQuestionnaire1.setSort(sort);
|
|
|
surveyQuestionnaire1.setQuestionCodeNext(qstNextQuestion);
|
|
|
surveyQuestionnaire1.setDel(del);
|
|
|
surveyQuestionnaire1.setCreateTime(new Date());
|
|
|
surveyQuestionnaire1.setUpdateTime(new Date());
|
|
|
|
|
|
surveyQuestionnaireDao.save(surveyQuestionnaire1);
|
|
|
|
|
|
// =======================选项保存=========================
|
|
|
// 选择题
|
|
|
JSONArray options1 = new JSONArray(tempQestion.get("options").toString());
|
|
|
for (Object option : options1) {
|
|
|
// String optionCode = getCode();
|
|
|
JSONObject tempOption = new JSONObject(option.toString());
|
|
|
String optionCode = tempOption.get("optCode").toString();
|
|
|
int haveComment = Integer.parseInt(tempOption.get("haveComment").toString());
|
|
|
String optionComment = tempOption.get("content").toString();
|
|
|
int required = Integer.parseInt(tempOption.get("isRequired").toString());
|
|
|
int optionSort = Integer.parseInt(tempOption.get("sort").toString());
|
|
|
int optionDel = 1;
|
|
|
String optionNextQuestion = null;
|
|
|
if (!StringUtils.isEmpty(tempOption.get("nextQuestion").toString())) {
|
|
|
// optionNextQuestion = tempOption.get("nextQuestion").toString();
|
|
|
optionNextQuestion = surveyTemplateQuestionsDao.findBySort(templateCode, tempOption.get("nextQuestion"));
|
|
|
optionNextQuestion = (optionNextQuestion == null ? "0" : optionNextQuestion);
|
|
|
}
|
|
|
|
|
|
// 自主创建,插入表
|
|
|
SurveyQuestionnaireOptions surveyQuestionnaireOptions = new SurveyQuestionnaireOptions();
|
|
|
surveyQuestionnaireOptions.setCode(optionCode);
|
|
|
surveyQuestionnaireOptions.setHaveComment(haveComment);
|
|
|
surveyQuestionnaireOptions.setQuestionnaireCode(questionnaireCode);
|
|
|
surveyQuestionnaireOptions.setContent(optionComment);
|
|
|
surveyQuestionnaireOptions.setSurveyCode(surveyCode);
|
|
|
surveyQuestionnaireOptions.setQuestionCodeNext(optionNextQuestion);
|
|
|
surveyQuestionnaireOptions.setIsRequired(required);
|
|
|
surveyQuestionnaireOptions.setSort(optionSort);
|
|
|
surveyQuestionnaireOptions.setDel(optionDel);
|
|
|
|
|
|
surveyQuestionnaireOptionsDao.save(surveyQuestionnaireOptions);
|
|
|
|
|
|
// 多选题保存到统计表
|
|
|
String statisticsCode = getCode();
|
|
|
String questionTitle = surveyQuestionnaireDao.findByIdAndQstId(surveyCode, questionnaireCode).getTitle();
|
|
|
String optcontent = surveyQuestionnaireOptionsDao.findByRelationCode(surveyCode, questionnaireCode, optionCode).getContent();
|
|
|
SurveyStatistics statistics = new SurveyStatistics(statisticsCode, surveyCode, questionnaireCode, questionTitle, optionCode, 0, optcontent, haveComment, type, sort, optionSort);
|
|
|
surveyStatisticsDao.save(statistics);
|
|
|
}
|
|
|
// ===============================================================
|
|
|
break;
|
|
|
case 2:
|
|
|
// 问答特有属性
|
|
|
/*String nextQuestion = null;
|
|
|
if (StringUtils.isEmpty(tempQestion.get("nextQuestion").toString())) {
|
|
|
nextQuestion = tempQestion.get("nextQuestion").toString();
|
|
|
}else {
|
|
|
nextQuestion = surveyTemplateQuestionsDao.findBySort(templateCode,tempQestion.get("nextQuestion"));
|
|
|
}*/
|
|
|
SurveyQuestionnaire surveyQuestionnaire2 = new SurveyQuestionnaire();
|
|
|
surveyQuestionnaire2.setCode(questionnaireCode);
|
|
|
surveyQuestionnaire2.setTitle(title);
|
|
|
surveyQuestionnaire2.setQuestionComment(comment);
|
|
|
surveyQuestionnaire2.setQuestionType(type);
|
|
|
surveyQuestionnaire2.setSurveyCode(surveyCode);
|
|
|
surveyQuestionnaire2.setIsRequired(isRequired);
|
|
|
// 单选没有最大最小选项数
|
|
|
surveyQuestionnaire2.setMinNum(null);
|
|
|
surveyQuestionnaire2.setMaxNum(null);
|
|
|
surveyQuestionnaire2.setSort(sort);
|
|
|
surveyQuestionnaire2.setQuestionCodeNext(qstNextQuestion);
|
|
|
surveyQuestionnaire2.setDel(del);
|
|
|
surveyQuestionnaire2.setUpdateTime(new Date());
|
|
|
surveyQuestionnaire2.setCreateTime(new Date());
|
|
|
|
|
|
surveyQuestionnaireDao.save(surveyQuestionnaire2);
|
|
|
|
|
|
// 问答题保存到统计表(只负责更改数量不负责创建)
|
|
|
String statisticsCode = getCode();
|
|
|
String questionTitle = surveyQuestionnaireDao.findByIdAndQstId(surveyCode, questionnaireCode).getTitle();
|
|
|
SurveyStatistics statistics = new SurveyStatistics(statisticsCode, surveyCode, questionnaireCode, questionTitle, null, 0, null, null, type, sort, null);
|
|
|
surveyStatisticsDao.save(statistics);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
// 保存到问卷
|
|
|
Survey survey = new Survey();
|
|
|
survey.setCode(surveyCode);
|
|
|
survey.setTitle(surveyName);
|
|
|
survey.setSurveyComment(surveyComment);
|
|
|
survey.setCreater(doctor);
|
|
|
survey.setTemplateCode(templateCode);
|
|
|
survey.setStatus(status);
|
|
|
survey.setAmount(amount);
|
|
|
survey.setCreateTime(new Date());
|
|
|
survey.setUpdateTime(new Date());
|
|
|
surveyDao.save(survey);
|
|
|
return surveyCode;
|
|
|
}
|
|
|
}
|