| 
					
				 | 
			
			
				@ -620,7 +620,7 @@ public class SpecialistService{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " d.hospital_name AS hospital_name, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " d.`level` " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " FROM " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " wlyy_specialist_patient_relation r " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " wlyy_specialist.wlyy_specialist_patient_relation r " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " JOIN "+basedb+".wlyy_doctor d ON r.doctor = d.`code` " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " WHERE  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " r.patient ='"+patient+"' " + 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -631,7 +631,7 @@ public class SpecialistService{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " AND r.`status`>=0 " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " AND r.sign_status >0 ) r join "+basedb+".wlyy_patient p on r.patient = p.code order by p.czrq DESC "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<PatientSignInfoVO> patientSignInfoVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientSignInfoVO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        PatientSignInfoVO patientSignInfoVO = (null == patientSignInfoVOs && patientSignInfoVOs.size() > 0 )? null : patientSignInfoVOs.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        PatientSignInfoVO patientSignInfoVO = (null != patientSignInfoVOs && patientSignInfoVOs.size() > 0 )? patientSignInfoVOs.get(0):null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return MixEnvelop.getSuccess(SpecialistMapping.api_success, patientSignInfoVO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -847,9 +847,15 @@ public class SpecialistService{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 病人的家签信息、专科开通信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctorCode 医生code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param patientCode 病人id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param signStatus 签约状态,待审核:0;未签约:-1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject doctorForSpecialistInfo(String doctorCode, String patientCode)  throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject doctorForSpecialistInfo(String signStatus,String doctorCode, String patientCode)  throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SpecialistPatientRelationDO specialistPatientRelationDO = new SpecialistPatientRelationDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //待审核 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("0".equals(signStatus)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            specialistPatientRelationDO = specialistPatientRelationDao.findByDoctorAndPatient(doctorCode, patientCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //1、获取居民基础信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        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 "; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -910,6 +916,111 @@ public class SpecialistService{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return jsonObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 病人的家签信息、专科开通信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctorCode 医生code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param patientCode 病人id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param signStatus 签约状态,待审核:0;未签约:-1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject doctorForSpecialistInfoNew(String signStatus,String doctorCode, String patientCode)  throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SpecialistPatientRelationDO specialistPatientRelationDO = new SpecialistPatientRelationDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //待审核 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("0".equals(signStatus)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            specialistPatientRelationDO = selectByDoctorAndPatient(doctorCode, patientCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //1、获取居民基础信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        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、获取医生信息(所属医院、科室、姓名) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String doctorSql = "SELECT wd.hospital_name as hospitalName,wd.dept_name as deptName,wd.name as name FROM " + basedb + ".wlyy_doctor wd WHERE wd.code='" + doctorCode + "'";; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if("0".equals(signStatus)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            doctorSql="SELECT wd.hospital_name as hospitalName,wd.dept_name as deptName,wd.name as name FROM " + basedb + ".wlyy_doctor wd WHERE wd.code='" + specialistPatientRelationDO.getDoctor() + "'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        jsonObject.put("doctorInfo", jdbcTemplate.queryForMap(doctorSql)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //3、获取该医生所属团队及团队成员信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String teamSql = "SELECT at.name teamName, tm.team_id , tm.doctor_code, wd.NAME as doctorName  FROM " + basedb + ".wlyy_doctor wd LEFT JOIN  " + basedb + ".wlyy_admin_team_member tm ON wd. CODE = tm.doctor_code, " + basedb + ".wlyy_admin_team at " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "WHERE tm.team_id IN ( SELECT watm.team_id teamId FROM  " + basedb + ".wlyy_admin_team_member watm WHERE watm.doctor_code ='" + doctorCode + "'" + " AND watm.available = '1' ) AND tm.available='1' AND `at`.id=tm.team_id"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> teamList = jdbcTemplate.queryForList(teamSql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<Integer, List<Map<String, Object>>> m = teamList.stream().collect(Collectors.groupingBy(tem -> ((Integer) tem.get("team_id")).intValue(), Collectors.toList())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> mapList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (Integer i : m.keySet()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String, Object> objectMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if ("0".equals(signStatus) && i.equals(specialistPatientRelationDO.getTeamCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                objectMap.put("checkFlag", true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                objectMap.put("checkFlag", false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<String> speciaSignDiseaseList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if("0".equals(signStatus) ){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String speciaSignSql = "SELECT wpds.disease FROM wlyy.wlyy_patient_disease_server wpds WHERE wpds.patient='" + patientCode + "'" + " AND wpds.del='1' and wpds.specialist_relation_code='" + specialistPatientRelationDO.getId() + "'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                speciaSignDiseaseList = jdbcTemplate.queryForList(speciaSignSql,String.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Set<String> speciaSignSet =new HashSet<>(speciaSignDiseaseList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //已签约的疾病状态改成1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            stringList.stream().forEach(item->{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                int status=0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(stringSet.contains( item.get("disease_code"))){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //已签约过的疾病 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    status=1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(null!=speciaSignSet&& speciaSignSet.contains(item.get("disease_code"))){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //本次专病签约的疾病 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    status=2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                item.put("status",status) ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            objectMap.put("teamDisease", stringList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            mapList.add(objectMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        jsonObject.put("teamAndDoctors", mapList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //康复情况标签 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //居民的康复情况 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String patientLabelSql = "SELECT wspl.label from  wlyy.wlyy_sign_patient_label_info wspl WHERE wspl.patient='"+patientCode+"' and  wspl.label_type='8' AND status='1'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<String> patientLabelList = jdbcTemplate.queryForList(patientLabelSql,String.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Set<String> patientLabelSet =new HashSet<>(patientLabelList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        signPatientLabelList.stream().forEach(item->{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            item.put("status",patientLabelSet.contains(item.get("label_code").toString())?1:0) ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        jsonObject.put("signPatientLabels", signPatientLabelList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return jsonObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 专科医生发起签约 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param specialistPatientRelationDO 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -1029,4 +1140,21 @@ public class SpecialistService{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return MixEnvelop.getSuccessListWithPage(SpecialistMapping.api_success,resultList,page,pageSize,countMap.size()>0?Long.valueOf(countMap.get(0).get("num")+""):0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 根据医生和居民code查询居民与该医生所在团队的待审核专科签约信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param patient 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public SpecialistPatientRelationDO selectByDoctorAndPatient(String doctor,String patient){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "select * from wlyy_specialist.wlyy_specialist_patient_relation r where r.doctor in ( " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " SELECT m.doctor_code  FROM wlyy.wlyy_admin_team_member m " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " WHERE  m.team_id IN ( SELECT dt.id  FROM  wlyy.wlyy_admin_team dt LEFT JOIN wlyy.wlyy_admin_team_member watm ON dt.id = watm.team_id   WHERE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " dt.available = '1' AND watm.available = '1'  AND watm.doctor_code = '"+doctor+"') AND m.available = '1'  ) and r.patient = '"+patient+"' and r.sign_status=0"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<SpecialistPatientRelationDO> relationDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SpecialistPatientRelationDO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SpecialistPatientRelationDO specialistPatientRelationDO=null!=relationDOS&&relationDOS.size()>0?relationDOS.get(0):new SpecialistPatientRelationDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return specialistPatientRelationDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |