| 
					
				 | 
			
			
				@ -9,6 +9,7 @@ import com.yihu.wlyy.entity.consult.Consult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.consult.ConsultTeam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.consult.ConsultTeamDoctor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.consult.ConsultTeamLog; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.device.PatientDevice; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.discussion.WlyyTalkGroup; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.doctor.profile.Doctor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeam; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -17,14 +18,18 @@ import com.yihu.wlyy.entity.education.HealthEduArticle; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.Patient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.PatientFamilyMember; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.SignFamily; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.prescription.Prescription; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.consult.ConsultTeamDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.consult.ConsultTeamDoctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.consult.ConsultTeamLogDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.doctor.DoctorPatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.doctor.DoctorTeamDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.doctor.DoctorTeamMemberDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.message.MessageDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.patient.PatientDeviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.patient.PatientFamilyMemberDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.patient.SignFamilyDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.prescription.PrescriptionDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.app.health.HealthEduArticleService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.app.health.PatientHealthGuidanceService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.app.talk.TalkGroupService; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -98,6 +103,12 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private TalkGroupService talkGroupService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private com.yihu.wlyy.service.common.account.DoctorService doctorService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PatientDeviceDao patientDeviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private MessageDao messageDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PrescriptionDao prescriptionDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    WeiXinAccessTokenUtils accessTokenUtils; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -957,6 +968,125 @@ public class ConsultTeamService extends ConsultService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 添加续方咨询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param jwCode 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param patient 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param agent 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctorCode 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param reason 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Integer addPrescriptionConsult(String jwCode,String patient,String agent,String doctorCode,ConsultTeam ct,String reason) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        synchronized (jwCode.intern()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Doctor doctor = doctorDao.findByCode(doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 查询患者信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Patient p = patientDao.findByCode(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //获取基位处方详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Prescription prescription = new Prescription(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setCode(getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setHospitalName(doctor.getHospitalName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setHospital(doctor.getHospital()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setAdminTeamId(ct.getAdminTeamId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setDept(doctor.getDept()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setDeptName(doctor.getDeptName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setDoctor(doctor.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setDoctorName(doctor.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setJwCode(jwCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setPatient(p.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setPatientName(p.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setReason(reason); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setType(2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String symptoms = p.getName()+"申请续方\n体征信息:"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //获取体征记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Iterable<PatientDevice> devices = patientDeviceDao.findByUser(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(devices!=null||devices.iterator().hasNext()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                int count = messageDao.findTzMessage(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                symptoms +="最近七天有"+count+"条异常记录"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                symptoms +="居民未绑定体征设备"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //获取上次续方时间:与平安的“智慧医保的审方系统”对接,判断居民上次续方时间,点击跳转上次续方记录。(此功能需与第三方系统对接,如果本次版本无法实现,则消息中不显示此条信息) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //创建咨询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject users = new JSONObject();//咨询参与者 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            users.put(patient, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            users.put(doctorCode, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(patient.equals(agent)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                agent = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setDoctor(doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setDoctorName(doctor.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置患者信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setSymptoms(symptoms); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置患者姓名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setName(p.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置患者生日 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setBirthday(p.getBirthday()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //新增性别 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setSex(p.getSex()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置患者头像 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setPhoto(p.getPhoto()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置操作日期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 医生未读数量为1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setDoctorRead(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 添加咨询记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Consult consult = addConsult(ct.getPatient(), null, ct.getSymptoms(), ct.getImages(), ct.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置关联指导 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            consult.setGuidance(ct.getGuidance()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 设置咨询标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setConsult(consult.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //推送给IM去创建议题,取得成员消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject messages = ImUtill.getCreateTopicMessage(patient, p.getName(), consult.getTitle(), consult.getSymptoms(), consult.getImages(),agent); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //续方咨询的sessionid为居民code+续方code+咨询类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject obj = ImUtill.createTopics(patient + "_" + prescription.getCode() + "_" + ct.getType(), consult.getCode(), p.getName(), users, messages, ImUtill.SESSION_TYPE_PRESCRIPTION); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (obj == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new RuntimeException("IM消息发送异常!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(obj.getInt("status")==-1){//im议题创建失败 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new RuntimeException(obj.getString("message")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ct.setStartMsgId(obj.get("start_msg_id").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            consultTeamDao.save(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            consultDao.save(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //记录咨询的医生详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ConsultTeamDoctor cd = new ConsultTeamDoctor(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            cd.setConsult(consult.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            cd.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            cd.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            cd.setTo(doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            consultTeamDoctorDao.save(cd); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //3、保存续方记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription.setConsult(ct.getConsult()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescriptionDao.save(prescription); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 保存医生咨询信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 添加咨询转发记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 添加医生咨询日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String content = addLogs(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 发送消息给IM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 |