|  | @ -1,10 +1,11 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.dao.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.specialist.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.MixEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.dao.PatientHospitalRecordDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.dao.SpecialistPatientRelationDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.specialist.SpecialistPatientRelationDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.specialist.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.MixEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.ObjEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.specialist.SpecialistMapping;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.IdCardUtil;
 | 
	
	
		
			
				|  | @ -12,12 +13,12 @@ import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import org.apache.commons.lang.StringUtils;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | import org.springframework.data.redis.core.StringRedisTemplate;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.BeanPropertyRowMapper;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import javax.servlet.http.HttpServletRequest;
 | 
	
		
			
				|  |  | import java.text.ParseException;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | import java.util.stream.Collectors;
 | 
	
	
		
			
				|  | @ -43,6 +44,8 @@ public class SpecialistService{
 | 
	
		
			
				|  |  |     private JdbcTemplate jdbcTemplate;
 | 
	
		
			
				|  |  |     @Value("${basedb.name}")
 | 
	
		
			
				|  |  |     private String basedb;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private StringRedisTemplate redisTemplate;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public MixEnvelop<Boolean, Boolean> createSpecialistsPatientRelation(SpecialistPatientRelationDO specialistPatientRelationDO){
 | 
	
		
			
				|  |  |         specialistPatientRelationDao.save(specialistPatientRelationDO);
 | 
	
	
		
			
				|  | @ -200,8 +203,8 @@ public class SpecialistService{
 | 
	
		
			
				|  |  |                 " lb.labelType, " +
 | 
	
		
			
				|  |  |                 " lb.label, " +
 | 
	
		
			
				|  |  |                 " p.photo, " +
 | 
	
		
			
				|  |  |                 " h.label_name as health, " +
 | 
	
		
			
				|  |  |                 " h.label AS healthcode ," +
 | 
	
		
			
				|  |  |                 " lb.labelName as health, " +
 | 
	
		
			
				|  |  |                 " lb.label AS healthcode ," +
 | 
	
		
			
				|  |  |                 " s.health_assistant AS healthAssistant," +
 | 
	
		
			
				|  |  |                 " s.health_assistant_name AS healthAssistantName" +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
	
		
			
				|  | @ -220,20 +223,9 @@ public class SpecialistService{
 | 
	
		
			
				|  |  |                 " ) lb " +
 | 
	
		
			
				|  |  |                 " JOIN "+basedb+".wlyy_patient p ON p. CODE = lb.patient " +
 | 
	
		
			
				|  |  |                 " JOIN wlyy_specialist_patient_relation s ON s.patient = lb.patient " +
 | 
	
		
			
				|  |  |                 " LEFT JOIN ( " +
 | 
	
		
			
				|  |  |                 " SELECT " +
 | 
	
		
			
				|  |  |                 "  t.label, " +
 | 
	
		
			
				|  |  |                 "  t.label_name, " +
 | 
	
		
			
				|  |  |                 "  t.patient " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 "  "+basedb+".wlyy_sign_patient_label_info t " +
 | 
	
		
			
				|  |  |                 " WHERE " +
 | 
	
		
			
				|  |  |                 "  t.label_type = '8' " +
 | 
	
		
			
				|  |  |                 " AND t.`status` = '1' " +
 | 
	
		
			
				|  |  |                 " ) h ON h.patient = lb.patient " +
 | 
	
		
			
				|  |  |                 " WHERE s.doctor ='"+doctor+"' AND s.status >=0  AND s.sign_status >0"+
 | 
	
		
			
				|  |  |                 " WHERE ( s.doctor ='"+doctor+"' OR s.health_doctor='"+doctor+"' OR s.health_assistant='"+doctor+ "') AND s.status >=0  AND s.sign_status >0"+
 | 
	
		
			
				|  |  |                 " LIMIT "+(page-1)*size+","+size;
 | 
	
		
			
				|  |  |         
 | 
	
		
			
				|  |  |         System.out.print("日志:"+sql);
 | 
	
		
			
				|  |  |         if("7".equals(labelType)){
 | 
	
		
			
				|  |  |             sql = "SELECT " +
 | 
	
		
			
				|  |  |                     "c.CODE," +
 | 
	
	
		
			
				|  | @ -250,8 +242,8 @@ public class SpecialistService{
 | 
	
		
			
				|  |  |                     "JOIN "+basedb+".wlyy_patient_disease_server b ON a.id=b.specialist_relation_code AND b.disease=" +labelCode+" and b.del=1 "+
 | 
	
		
			
				|  |  |                     "JOIN "+basedb+".wlyy_patient c ON a.patient=c.CODE " +
 | 
	
		
			
				|  |  |                     "LEFT JOIN "+basedb+".wlyy_sign_patient_label_info d ON a.patient=d.patient AND d.label_type=8 AND d.`status`=1" +
 | 
	
		
			
				|  |  |                     " WHERE a.sign_status> 0 AND a.`status`>=0 AND a.doctor='"+doctor+"'"+
 | 
	
		
			
				|  |  |                     " LIMIT "+(page-1)*size+","+size;
 | 
	
		
			
				|  |  |                     " WHERE a.sign_status> 0 AND a.`status`>=0 AND a.doctor='"+doctor+"' OR a.health_assistant= '"+doctor+
 | 
	
		
			
				|  |  |                     "' LIMIT "+(page-1)*size+","+size;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -260,26 +252,27 @@ public class SpecialistService{
 | 
	
		
			
				|  |  |         return MixEnvelop.getSuccess(SpecialistMapping.api_success,PatientLabelVOs);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public MixEnvelop<Long, Long> getLabelpatientCount(String doctor, String label, String labelType){
 | 
	
		
			
				|  |  |     public MixEnvelop<Long, Long> getLabelpatientCount(String doctor, String labelType, String label){
 | 
	
		
			
				|  |  |         String sql = "SELECT " +
 | 
	
		
			
				|  |  |                 " COUNT(1) as total " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " ( " +
 | 
	
		
			
				|  |  |                 "  SELECT " +
 | 
	
		
			
				|  |  |                 "   i.label_type AS labelType, " +
 | 
	
		
			
				|  |  |                 "   i.label, " +
 | 
	
		
			
				|  |  |                 "   i.label_name AS labelName, " +
 | 
	
		
			
				|  |  |                 "   i.patient " +
 | 
	
		
			
				|  |  |                 "  FROM " +
 | 
	
		
			
				|  |  | //                " ( " +
 | 
	
		
			
				|  |  | //                "  SELECT " +
 | 
	
		
			
				|  |  | //                "   i.label_type AS labelType, " +
 | 
	
		
			
				|  |  | //                "   i.label, " +
 | 
	
		
			
				|  |  | //                "   i.label_name AS labelName, " +
 | 
	
		
			
				|  |  | //                "   i.patient " +
 | 
	
		
			
				|  |  | //                "  FROM " +
 | 
	
		
			
				|  |  |                 "   "+basedb+".wlyy_sign_patient_label_info i " +
 | 
	
		
			
				|  |  |                 "  WHERE " +
 | 
	
		
			
				|  |  |                 "   i.label = '"+label+"' "+
 | 
	
		
			
				|  |  |                 "  AND i.label_type = '"+labelType+"' " +
 | 
	
		
			
				|  |  |                 "  AND i.`status` = '1' " +
 | 
	
		
			
				|  |  |                 " ) lb " +
 | 
	
		
			
				|  |  |                 " JOIN wlyy_specialist_patient_relation s ON s.patient = lb.patient " +
 | 
	
		
			
				|  |  |                 " WHERE " +
 | 
	
		
			
				|  |  |                 " s.doctor = '"+doctor+"' AND s.status >=0  AND s.sign_status >0";
 | 
	
		
			
				|  |  |                 " AND i.patient in ( " +
 | 
	
		
			
				|  |  |                 " select patient from  wlyy_specialist_patient_relation  WHERE " +
 | 
	
		
			
				|  |  |                 "( doctor = '"+doctor+"' OR health_doctor = '"+doctor+"' OR health_assistant='"+doctor+ "' ) AND STATUS >= 0 AND sign_status > 0 )";
 | 
	
		
			
				|  |  | //                +" ) lb ";
 | 
	
		
			
				|  |  |         System.out.print("日志:"+sql);
 | 
	
		
			
				|  |  |         List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         Long count = 0L;
 | 
	
		
			
				|  |  |         if(rstotal!=null&&rstotal.size()>0){
 | 
	
	
		
			
				|  | @ -504,6 +497,9 @@ public class SpecialistService{
 | 
	
		
			
				|  |  |             relation.setHealthAssistantName(health_assistant_name);
 | 
	
		
			
				|  |  |             relation.setSignDate(new Date());
 | 
	
		
			
				|  |  |             specialistPatientRelationDao.save(relation);
 | 
	
		
			
				|  |  |             //签约成功之后,将签约关系保存在redis中
 | 
	
		
			
				|  |  |             String key = "specialist_patient_relation:" + relation.getPatient() +"_"+ ":text";
 | 
	
		
			
				|  |  |             redisTemplate.opsForValue().set(key,"true");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return MixEnvelop.getSuccess(SpecialistMapping.api_success,relation);
 | 
	
		
			
				|  |  |     }
 | 
	
	
		
			
				|  | @ -576,6 +572,7 @@ public class SpecialistService{
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public MixEnvelop findPatientSignSpecialist(String patient){
 | 
	
		
			
				|  |  |         String sql = "SELECT " +
 | 
	
		
			
				|  |  |                 " r.id AS relationCode, " +
 | 
	
		
			
				|  |  |                 " r.patient, " +
 | 
	
		
			
				|  |  |                 " r.team_code AS teamCode," +
 | 
	
		
			
				|  |  |                 " r.patient_name AS patientName, " +
 | 
	
	
		
			
				|  | @ -774,23 +771,32 @@ public class SpecialistService{
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 专科-模糊搜索注册居民
 | 
	
		
			
				|  |  |      * 专科-模糊搜索注册居民(未与该医生所在团队医生签约的居民)
 | 
	
		
			
				|  |  |      * @param doctorCode
 | 
	
		
			
				|  |  |      * @param keywords
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public MixEnvelop searchPatientInSpecialist(String doctorCode,String keywords,Integer page,Integer pageSize) throws Exception{
 | 
	
		
			
				|  |  |         String sql1 = " select count(1) as num ";
 | 
	
		
			
				|  |  |         String sql2 = " select p.name as name,p.idcard,p.code,p.photo,CASE WHEN wsf.status ='-4' THEN '已到期' WHEN wsf.status ='0' THEN '待签约' WHEN wsf.status ='1' THEN '已签约' WHEN wsf.status ='2' THEN '已签约' WHEN wsf.status ='3' THEN '已签约' ELSE '待签约' END  status  ";
 | 
	
		
			
				|  |  |         String sql2 = " select p.name as name,p.idcard,p.code,p.photo ";
 | 
	
		
			
				|  |  |         String whereSql ="";
 | 
	
		
			
				|  |  |         if(!StringUtils.isEmpty(keywords)){
 | 
	
		
			
				|  |  |             whereSql+=" and (p.name like '%"+keywords+"%' or p.idcard like '%"+keywords+"%' or p.mobile like '%"+keywords+"%') ";
 | 
	
		
			
				|  |  | //            whereSql+=" and (p.name like '%"+keywords+"%' or p.idcard like '%"+keywords+"%' or p.mobile like '%"+keywords+"%') ";
 | 
	
		
			
				|  |  |             whereSql+=" and  p.mobile ='"+keywords+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String centerSql =" from "+basedb+".wlyy_patient p LEFT JOIN  "+basedb+".wlyy_sign_family wsf ON p.code=wsf.patient AND wsf.type='1'" +
 | 
	
		
			
				|  |  |                 " WHERE p.code not in (SELECT r.patient FROM  wlyy_specialist.wlyy_specialist_patient_relation r WHERE r.sign_status = '1' and doctor='"+doctorCode+"')"+" AND p.openid IS NOT NULL "+
 | 
	
		
			
				|  |  |         String centerSql =" from "+basedb+".wlyy_patient p  " +
 | 
	
		
			
				|  |  |                 " WHERE p.code not in (SELECT r.patient FROM  wlyy_specialist.wlyy_specialist_patient_relation r WHERE r.sign_status = '1' " +
 | 
	
		
			
				|  |  |                 " AND doctor in (SELECT m.doctor_code FROM  "+basedb+".wlyy_admin_team_member m where m.team_id in " +
 | 
	
		
			
				|  |  |                 " (SELECT dt.id FROM  "+basedb+".wlyy_admin_team dt LEFT JOIN  "+basedb+".wlyy_admin_team_member watm ON dt.id=watm.team_id " +
 | 
	
		
			
				|  |  |                 " WHERE dt.available='1' AND watm.available='1' AND watm.doctor_code='"+doctorCode+"') AND  m.available='1'))"
 | 
	
		
			
				|  |  |                 +" AND p.openid IS NOT NULL "+
 | 
	
		
			
				|  |  |                whereSql;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String countCenterSql =" from "+basedb+".wlyy_patient p " +
 | 
	
		
			
				|  |  |                 " WHERE p.code not in (SELECT r.patient FROM  wlyy_specialist.wlyy_specialist_patient_relation r WHERE r.sign_status = '1' and doctor='"+doctorCode+"')"+" AND p.openid IS NOT NULL "+
 | 
	
		
			
				|  |  |                 " WHERE p.code not in (SELECT r.patient FROM  wlyy_specialist.wlyy_specialist_patient_relation r WHERE r.sign_status = '1'" +
 | 
	
		
			
				|  |  |                 " AND doctor in (SELECT m.doctor_code FROM  "+basedb+".wlyy_admin_team_member m where m.team_id in " +
 | 
	
		
			
				|  |  |                 " (SELECT dt.id FROM  "+basedb+".wlyy_admin_team dt LEFT JOIN  "+basedb+".wlyy_admin_team_member watm ON dt.id=watm.team_id " +
 | 
	
		
			
				|  |  |                 " WHERE dt.available='1' AND watm.available='1' AND watm.doctor_code='"+doctorCode+"') AND  m.available='1'))"
 | 
	
		
			
				|  |  |                 +" AND p.openid IS NOT NULL "+
 | 
	
		
			
				|  |  |                 whereSql;
 | 
	
		
			
				|  |  |         String sqlCount=sql1+countCenterSql;
 | 
	
		
			
				|  |  |         String sql=sql2+centerSql+" LIMIT "+(page-1)*pageSize+","+pageSize;
 | 
	
	
		
			
				|  | @ -802,13 +808,16 @@ public class SpecialistService{
 | 
	
		
			
				|  |  |         String sex = null;
 | 
	
		
			
				|  |  |         String sexName="";
 | 
	
		
			
				|  |  |         for(Map<String,Object> one:map){
 | 
	
		
			
				|  |  |             StringBuffer statusSql =new StringBuffer( " select CASE WHEN wsf.status ='-4' THEN '已到期' WHEN wsf.status ='0' THEN '待签约' WHEN wsf.status ='1' THEN '已签约' WHEN wsf.status ='2' THEN '已签约' WHEN wsf.status ='3' THEN '已签约' ELSE '待签约' END  status  ");
 | 
	
		
			
				|  |  |             statusSql.append("FROM wlyy.wlyy_sign_family wsf, (SELECT patient,Max(apply_date) applyDate FROM wlyy.wlyy_sign_family WHERE type = '2' AND patient='"+one.get("code")+"' GROUP BY patient) temp WHERE wsf.patient=temp.patient AND wsf.apply_date=temp.applyDate");
 | 
	
		
			
				|  |  |             List<Map<String,Object>> strMap= jdbcTemplate.queryForList(statusSql.toString());
 | 
	
		
			
				|  |  |             m = new HashMap();
 | 
	
		
			
				|  |  |             age = IdCardUtil.getAgeForIdcard(one.get("idcard")+"");
 | 
	
		
			
				|  |  |             sex = IdCardUtil.getSexForIdcard_new(one.get("idcard")+"");
 | 
	
		
			
				|  |  |             m.put("name",one.get("name"));
 | 
	
		
			
				|  |  |             m.put("age",age);
 | 
	
		
			
				|  |  |             m.put("sex",sex);
 | 
	
		
			
				|  |  |             m.put("status",one.get("status"));
 | 
	
		
			
				|  |  |             m.put("status", !(null != strMap && strMap.size() > 0) ? "待签约" : strMap.get(0).get("status"));
 | 
	
		
			
				|  |  |             if("1".equals(sex)){
 | 
	
		
			
				|  |  |                 sexName="男";
 | 
	
		
			
				|  |  |             }else if("2".equals(sex)){
 | 
	
	
		
			
				|  | @ -834,14 +843,24 @@ public class SpecialistService{
 | 
	
		
			
				|  |  |     public JSONObject doctorForSpecialistInfo(String doctorCode, String patientCode)  throws Exception{
 | 
	
		
			
				|  |  |         JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  |         //1、获取居民基础信息
 | 
	
		
			
				|  |  |         String preSql = "SELECT p.name as name,CASE p.sex WHEN 1 THEN '男' WHEN 2 THEN '女' ELSE '未知' END as sex,IFNULL(year( from_days( datediff( now(), p.birthday))),'未知') as age," +
 | 
	
		
			
				|  |  |                 " p.photo as photo,p.idcard as idcard,p.mobile as mobile,p.medicare_number as medicareNumber,p.ssc as ssc," +
 | 
	
		
			
				|  |  |                 " CASE  WHEN wsf.doctor_name is null THEN '无' ELSE wsf.doctor_name END as doctorName,CASE  WHEN wsf.hospital_name is NULL THEN '无' ELSE wsf.hospital_name END as hospitalName,CASE  WHEN wsf.mobile is NULL THEN '无' ELSE wsf.mobile END as doctorMobole ";
 | 
	
		
			
				|  |  |         String preSql = "SELECT p.name as name, p.photo as photo,p.idcard as idcard,p.mobile as mobile,p.medicare_number as medicareNumber,p.ssc as ssc," +
 | 
	
		
			
				|  |  |                 " CASE  WHEN wd.name is null THEN '无' ELSE wd.name END as doctorName,CASE  WHEN wd.hospital_name is NULL THEN '无' ELSE wd.hospital_name END as hospitalName,CASE  WHEN wd.mobile is NULL THEN '无' ELSE wd.mobile END as doctorMobole ";
 | 
	
		
			
				|  |  |         String patientSql = " from " + basedb + ".wlyy_patient p LEFT JOIN " + basedb + ".wlyy_sign_family wsf " +
 | 
	
		
			
				|  |  |                 " ON p.code=wsf.patient AND wsf.type='2' AND wsf.status='1' " +
 | 
	
		
			
				|  |  |                 " LEFT JOIN " + basedb + ".wlyy_doctor wd ON wsf.doctor =wd.code WHERE p.code='" + patientCode + "'";
 | 
	
		
			
				|  |  |         //一个居民 生效的家签信息只会有一条
 | 
	
		
			
				|  |  |         Map<String, Object> map = jdbcTemplate.queryForMap(preSql + patientSql);
 | 
	
		
			
				|  |  |         map.put("age",IdCardUtil.getAgeForIdcard(map.get("idcard")+""));
 | 
	
		
			
				|  |  |         String sexCode=IdCardUtil.getSexForIdcard_new(map.get("idcard")+"");
 | 
	
		
			
				|  |  |         String sexName="";
 | 
	
		
			
				|  |  |         if("1".equals(sexCode)){
 | 
	
		
			
				|  |  |             sexName="男";
 | 
	
		
			
				|  |  |         }else if("2".equals(sexCode)){
 | 
	
		
			
				|  |  |             sexName="女";
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             sexName="未知";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         map.put("sex",sexName);
 | 
	
		
			
				|  |  |         jsonObject.put("patientInfo", map);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //2、获取医生信息(所属医院、科室、姓名)
 | 
	
	
		
			
				|  | @ -859,17 +878,26 @@ public class SpecialistService{
 | 
	
		
			
				|  |  |             objectMap.put("teamId", i);
 | 
	
		
			
				|  |  |             objectMap.put("teamName", m.get(i).get(0).get("teamName"));
 | 
	
		
			
				|  |  |             objectMap.put("teamDoctors", m.get(i));
 | 
	
		
			
				|  |  |             //获取专科团队疾病标签
 | 
	
		
			
				|  |  |            String disSql = "SELECT wtdr.disease_code, wtdr.disease_name from  wlyy.wlyy_team_disease_relation wtdr WHERE wtdr.team_code ='" + i + "'" +"  AND wtdr.del='1'";
 | 
	
		
			
				|  |  |             //new BeanPropertyRowMapper(
 | 
	
		
			
				|  |  |             List<Map<String, Object>>  stringList = jdbcTemplate.queryForList(disSql);
 | 
	
		
			
				|  |  |             String areaSql = "SELECT wpds.disease FROM wlyy.wlyy_patient_disease_server wpds WHERE wpds.patient='" + patientCode + "'" + " AND wpds.del='1'";
 | 
	
		
			
				|  |  |             List<String> signDiseaseList = jdbcTemplate.queryForList(areaSql,String.class);
 | 
	
		
			
				|  |  |             Set<String> stringSet =new HashSet<>(signDiseaseList);
 | 
	
		
			
				|  |  | //            stringSet.addAll(new HashSet<>(signDiseaseList));
 | 
	
		
			
				|  |  |             //已签约的疾病状态改成1
 | 
	
		
			
				|  |  |             stringList.stream().forEach(item->{
 | 
	
		
			
				|  |  |                 item.put("status",stringSet.contains( item.get("disease_code"))?1:0) ;
 | 
	
		
			
				|  |  |             });
 | 
	
		
			
				|  |  |             objectMap.put("teamDisease", stringList);
 | 
	
		
			
				|  |  |             mapList.add(objectMap);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         jsonObject.put("teamAndDoctors", mapList);
 | 
	
		
			
				|  |  |         //获取专科团队疾病标签
 | 
	
		
			
				|  |  |         teamSql = "SELECT wtdr.disease_name from  wlyy.wlyy_team_disease_relation wtdr WHERE wtdr.team_code IN ( SELECT watm.team_id teamId FROM  " + basedb + ".wlyy_admin_team_member watm WHERE watm.doctor_code ='" + doctorCode + "'" + " AND watm.available = '1' ) AND wtdr.del='1'";
 | 
	
		
			
				|  |  |         //new BeanPropertyRowMapper(
 | 
	
		
			
				|  |  |         List<String> stringList = jdbcTemplate.queryForList(teamSql, String.class);
 | 
	
		
			
				|  |  |         jsonObject.put("teamDisease", stringList.stream().collect(Collectors.joining(" ")));
 | 
	
		
			
				|  |  |         //疾病标签
 | 
	
		
			
				|  |  |         teamSql = "SELECT wspl.label_code,wspl.label_name from  wlyy.wlyy_sign_patient_label wspl WHERE wspl.label_type='8' AND status='1'";
 | 
	
		
			
				|  |  |         List<Map<String, Object>> signPatientLabelList = jdbcTemplate.queryForList(teamSql);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //康复情况标签
 | 
	
		
			
				|  |  |         String labelSql = "SELECT wspl.label_code,wspl.label_name from  wlyy.wlyy_sign_patient_label wspl WHERE wspl.label_type='8' AND status='1'";
 | 
	
		
			
				|  |  |         List<Map<String, Object>> signPatientLabelList = jdbcTemplate.queryForList(labelSql);
 | 
	
		
			
				|  |  |         jsonObject.put("signPatientLabels", signPatientLabelList);
 | 
	
		
			
				|  |  |         return jsonObject;
 | 
	
		
			
				|  |  |     }
 | 
	
	
		
			
				|  | @ -883,13 +911,45 @@ public class SpecialistService{
 | 
	
		
			
				|  |  |     public ObjEnvelop<SpecialistPatientRelationDO> createPatientInSpeciaRelation(SpecialistPatientRelationDO specialistPatientRelationDO) throws Exception {
 | 
	
		
			
				|  |  |         specialistPatientRelationDO.setSignStatus("1");
 | 
	
		
			
				|  |  |         specialistPatientRelationDO.setSignDate(new Date());
 | 
	
		
			
				|  |  |         specialistPatientRelationDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         specialistPatientRelationDO.setCreateUser(specialistPatientRelationDO.getDoctor());
 | 
	
		
			
				|  |  |         specialistPatientRelationDO.setCreateUserName(specialistPatientRelationDO.getDoctorName());
 | 
	
		
			
				|  |  |         specialistPatientRelationDO.setStatus("1");//计管师分配状态
 | 
	
		
			
				|  |  |         specialistPatientRelationDO.setSignYear(String.valueOf(DateUtil.getNowYear()));
 | 
	
		
			
				|  |  |         specialistPatientRelationDO.setSignDate(new Date());
 | 
	
		
			
				|  |  |         specialistPatientRelationDO = specialistPatientRelationDao.save(specialistPatientRelationDO);
 | 
	
		
			
				|  |  |         //签约成功之后,将签约关系保存在redis中
 | 
	
		
			
				|  |  |         String key = "specialist_patient_relation:" + specialistPatientRelationDO.getPatient() +"_"+ ":text";
 | 
	
		
			
				|  |  |         redisTemplate.opsForValue().set(key,"true");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return ObjEnvelop.getSuccess("success", specialistPatientRelationDO);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public Integer updateRedisFindPatientTeamList(){
 | 
	
		
			
				|  |  |         List<SpecialistPatientRelationDO> specialistPatientRelationDOList=specialistPatientRelationDao.findAllBySignStatus("1");
 | 
	
		
			
				|  |  |         List<SpecialistPatientRelationDO> unique = specialistPatientRelationDOList.stream().collect(
 | 
	
		
			
				|  |  |                 Collectors.collectingAndThen(
 | 
	
		
			
				|  |  |                         Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SpecialistPatientRelationDO::getPatient))), ArrayList::new)
 | 
	
		
			
				|  |  |         );
 | 
	
		
			
				|  |  |         unique.stream().forEach(item->{
 | 
	
		
			
				|  |  |             //签约成功之后,将签约关系保存在redis中
 | 
	
		
			
				|  |  |             String key = "specialist_patient_relation:" + item.getPatient() +"_"+ ":text";
 | 
	
		
			
				|  |  |             redisTemplate.opsForValue().set(key,"true");
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  |         return null==unique?0:unique.size();
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 根据共管医生和居民code查询专科签约信息
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @param doctor
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<SpecialistPatientRelationDO> selectByAssistant(String patient,String doctor){
 | 
	
		
			
				|  |  |         String sql = "select * from wlyy_specialist_patient_relation r where r.health_assistant = '"+doctor+"' and r.patient = '"+patient+"' ";
 | 
	
		
			
				|  |  |         List<SpecialistPatientRelationDO> relationDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SpecialistPatientRelationDO.class));
 | 
	
		
			
				|  |  |         return relationDOS;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |