| 
					
				 | 
			
			
				@ -0,0 +1,109 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.care.service.contacts; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.device.PatientDeviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.family.PatientFamilyMemberDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.service.device.PatientDeviceService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.service.family.PatientFamilyMemberService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.patient.BasePatientDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.patient.BasePatientFamilyMemberDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.DevicePatientDevice; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.patient.dao.BasePatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.JdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created with IntelliJ IDEA. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @Author: yeshijie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @Date: 2021/5/7 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @Description: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class ContactsService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PatientFamilyMemberDao memberDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PatientDeviceDao patientDeviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PatientDeviceService patientDeviceService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BasePatientDao basePatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PatientFamilyMemberService patientFamilyMemberService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private JdbcTemplate jdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取居民的联系人 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param patient 居民 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONArray getPatientContacts(String patient, Integer isContacts) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray resultArray = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "select *,t1.id fid " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " from " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    base_patient_family_member t1, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    base_patient t2 " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " where " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    t2.id in (select family_member from base_patient_family_member where patient = ? ) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    and t1.patient = ? " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "    and t1.family_member = t2.id "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(isContacts == 1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += " and t1.is_contacts = "+ isContacts; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{patient, patient}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (result != null && result.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Map<String, Object> map : result) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject obj = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                obj.put("id", map.get("id")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                obj.put("fid", map.get("fid")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                obj.put("name", map.get("name")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                obj.put("isContacts", map.get("is_contacts")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                obj.put("sex", map.get("sex")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                obj.put("birthday", map.get("birthday")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                obj.put("idcard", StringUtils.isEmpty(String.valueOf(map.get("idcard"))) ? "" : map.get("idcard").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                obj.put("photo", map.get("photo")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                obj.put("mobile", map.get("mobile")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                obj.put("address", StringUtils.isEmpty(String.valueOf(map.get("address"))) ? "" : map.get("address")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                obj.put("familyRelation", map.get("family_relation")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                obj.put("familyRelationName", PatientFamilyMemberService.relations.get(map.get("family_relation"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                resultArray.add(obj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return resultArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void setContacts(String fid,String patient){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BasePatientFamilyMemberDO familyMemberDO = memberDao.findOne(fid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BasePatientDO patientDO = basePatientDao.findById(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设置爱牵挂智能设备sos号码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<DevicePatientDevice> patientDeviceList = patientDeviceDao.findByPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for(DevicePatientDevice patientDevice : patientDeviceList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if("4".equals(patientDevice.getCategoryCode())||"7".equals(patientDevice.getCategoryCode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientDeviceService.updAqgDeviceSosInfo(patientDevice.getDeviceSn(),"1", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            PatientFamilyMemberService.relations.get(familyMemberDO.getFamilyRelation()),patientDO.getMobile(),"1",null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        memberDao.updateContactsByPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        familyMemberDO.setIsContacts(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        memberDao.save(familyMemberDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |