|  | @ -3,8 +3,10 @@ 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.repository.doctor.*;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.patient.PatientDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.patient.SignFamilyDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.BaseService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.survey.ManagerQuestionnaireService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.IdCardUtil;
 | 
	
	
		
			
				|  | @ -48,6 +50,8 @@ public class SurveyScreenResultService extends BaseService {
 | 
	
		
			
				|  |  |     private DoctorDao doctorDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SurveyAdviceDao surveyAdviceDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SignFamilyDao signFamilyDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private Logger logger = LoggerFactory.getLogger(this.getClass());
 | 
	
	
		
			
				|  | @ -67,8 +71,8 @@ public class SurveyScreenResultService extends BaseService {
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     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+"'";
 | 
	
		
			
				|  |  |         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;
 | 
	
		
			
				|  |  |         }
 | 
	
	
		
			
				|  | @ -80,7 +84,7 @@ public class SurveyScreenResultService extends BaseService {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("1",dealType)){
 | 
	
		
			
				|  |  |             //已预约
 | 
	
		
			
				|  |  |             sql += " AND ssr.`order` = 1";
 | 
	
		
			
				|  |  |             sql += " AND ssr.order = 1";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("2",dealType)){
 | 
	
		
			
				|  |  |             //已跟踪
 | 
	
	
		
			
				|  | @ -88,11 +92,17 @@ public class SurveyScreenResultService extends BaseService {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("3",dealType)){
 | 
	
		
			
				|  |  |             //已接诊
 | 
	
		
			
				|  |  |             sql += " AND ssr.reservtion_code is not null";
 | 
	
		
			
				|  |  |             sql += " AND ssr.order = 2";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(dealType) && StringUtils.equals("4",dealType)){
 | 
	
		
			
				|  |  |             //待处理
 | 
	
		
			
				|  |  |             sql +=" AND ssr.`order` = 0 AND ssr.following= 0";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         Map<String,Object> map = jdbcTemplate.queryForMap(countSql);
 | 
	
		
			
				|  |  |         List<Map<String,Object>> maps = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         sql += " 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;
 | 
	
		
			
				|  |  |     }
 | 
	
	
		
			
				|  | @ -138,7 +148,6 @@ 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());
 | 
	
		
			
				|  |  |                         String code = getCode();
 | 
	
		
			
				|  |  |                         int score = Integer.parseInt(option.getString("score"));
 | 
	
		
			
				|  |  |                         totalScore += score;
 | 
	
		
			
				|  |  |                     }
 | 
	
	
		
			
				|  | @ -161,7 +170,7 @@ public class SurveyScreenResultService extends BaseService {
 | 
	
		
			
				|  |  |         surveyScreenResult.setSource(source);
 | 
	
		
			
				|  |  |         //是来自再次评估
 | 
	
		
			
				|  |  |         if (isAgain==1){
 | 
	
		
			
				|  |  |             surveyScreenResult.setPatientName(lastCode);
 | 
	
		
			
				|  |  |             surveyScreenResult.setParentCode(lastCode);
 | 
	
		
			
				|  |  |             surveyScreenResult.setOriginCode(originCode);
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             //来自第一次筛查评分
 | 
	
	
		
			
				|  | @ -172,8 +181,20 @@ public class SurveyScreenResultService extends BaseService {
 | 
	
		
			
				|  |  |             surveyScreenResult.setTemplateTitle(surveyTemplates.getTitle());
 | 
	
		
			
				|  |  |             surveyScreenResult.setDisease(surveyTemplates.getDiseaseType());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         surveyScreenResult.setDoctor(doctor);
 | 
	
		
			
				|  |  |         surveyScreenResult.setParentCode(patientCode);
 | 
	
		
			
				|  |  |         //来自医生发放和自我评估不一样来源
 | 
	
		
			
				|  |  |         if (source==1){
 | 
	
		
			
				|  |  |             surveyScreenResult.setDoctor(doctor);
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             SignFamily signFamily = signFamilyDao.findByPatient(patientCode);
 | 
	
		
			
				|  |  |             if (signFamily!=null && StringUtils.isNotEmpty(signFamily.getDoctor())){
 | 
	
		
			
				|  |  |                 surveyScreenResult.setDoctor(signFamily.getDoctor());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (signFamily!=null && StringUtils.isNotEmpty(signFamily.getDoctorHealth())){
 | 
	
		
			
				|  |  |                 surveyScreenResult.setDoctor(signFamily.getDoctorHealth());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         surveyScreenResult.setPatientCode(patientCode);
 | 
	
		
			
				|  |  |         if (patient!=null){
 | 
	
		
			
				|  |  |             surveyScreenResult.setPatientName(patient.getName());
 | 
	
		
			
				|  |  |             surveyScreenResult.setOpenId(patient.getOpenid());
 | 
	
	
		
			
				|  | @ -204,26 +225,27 @@ public class SurveyScreenResultService extends BaseService {
 | 
	
		
			
				|  |  |             json.put("message","没有改筛查结果!");
 | 
	
		
			
				|  |  |             return json;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String idcard = String.valueOf(infoMap.get("idcard"));
 | 
	
		
			
				|  |  |         /*String idcard = String.valueOf(infoMap.get("idcard"));
 | 
	
		
			
				|  |  |         infoMap.put("sex",IdCardUtil.getSexForIdcard(idcard));
 | 
	
		
			
				|  |  |         infoMap.put("age",IdCardUtil.getAgeForIdcard(idcard));
 | 
	
		
			
				|  |  |         infoMap.put("age",IdCardUtil.getAgeForIdcard(idcard));*/
 | 
	
		
			
				|  |  |         String templateCode = String.valueOf(infoMap.get("template_code"));
 | 
	
		
			
				|  |  |         String doctorCode = String.valueOf(infoMap.get("doctor"));
 | 
	
		
			
				|  |  |         String surveyScreenResultCode = String.valueOf(infoMap.get("code"));
 | 
	
		
			
				|  |  |         //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("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";
 | 
	
		
			
				|  |  |         Map<String,Object> healthMap = jdbcTemplate.queryForMap(healthSql);
 | 
	
		
			
				|  |  |         json.put("health",healthMap);
 | 
	
		
			
				|  |  |         /*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){
 | 
	
		
			
				|  |  |             json.put("health",healthMapList.get(0));
 | 
	
		
			
				|  |  |         }*/
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //题目和答案
 | 
	
		
			
				|  |  |         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=?";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> optionAnswersList = jdbcTemplate.queryForList(sql,new Object[]{surveyScreenResultCode,patientCode,templateCode});
 | 
	
		
			
				|  |  |         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);
 | 
	
	
		
			
				|  | @ -236,13 +258,17 @@ public class SurveyScreenResultService extends BaseService {
 | 
	
		
			
				|  |  |             json.put(surveyTemplateQuestions.getSort()+"",map);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //结果
 | 
	
		
			
				|  |  |         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=?";
 | 
	
		
			
				|  |  |         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")));
 | 
	
		
			
				|  |  |         if (order==1){
 | 
	
		
			
				|  |  |         if (order>0){
 | 
	
		
			
				|  |  |             //已转诊
 | 
	
		
			
				|  |  |             //@TODO
 | 
	
		
			
				|  |  |             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){
 | 
	
		
			
				|  |  |             String adviceCodes = String.valueOf(infoMap.get("advice_code"));
 | 
	
	
		
			
				|  | @ -260,8 +286,9 @@ public class SurveyScreenResultService extends BaseService {
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<SurveyTemplateAdvice> getTemplateAdviceList(String templateCode){
 | 
	
		
			
				|  |  |         return surveyTemplateAdviceDao.getByTemplateCode(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{
 | 
	
	
		
			
				|  | @ -294,7 +321,7 @@ public class SurveyScreenResultService extends BaseService {
 | 
	
		
			
				|  |  |             mapList.add(sMap);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         map.put("screenList",mapList);
 | 
	
		
			
				|  |  |         String sql = "SELECT a.* FROM (SELECT * FROM wlyy_survey_screen_result ORDER BY czrq DESC) a WHERE a.patient_code='"+patientCode+"' GROUP BY a.template_code";
 | 
	
		
			
				|  |  |         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;
 | 
	
	
		
			
				|  | @ -357,4 +384,8 @@ public class SurveyScreenResultService extends BaseService {
 | 
	
		
			
				|  |  |         return  resultMap;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void getSpecialDoctorScreenList(String doctor,int type,int pageNo,int pageSize){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |