| 
					
				 | 
			
			
				@ -1153,129 +1153,131 @@ public class ImService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							jsonObject.put("age",DateUtil.getAgeForIdcard(p.getIdcard())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							jsonObject.put("sex",p.getSex()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							jsonObject.put("name",p.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//4、创建咨询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							JSONObject users = new JSONObject();//咨询参与者 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							String consultTitle = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//协同门诊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							if("2".equals(wlyyOutpatientDO.getOutpatientType())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								users.put(wlyyOutpatientDO.getGeneralDoctor(),0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ct.setType(12); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								consultTitle = "申请协同门诊"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								JSONObject consultName = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								consultName.put("patientName",p.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								consultName.put("doctorName",doctor.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								jsonObject.put("name",consultName.toJSONString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								users.put(patient, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								consultTitle = "申请复诊"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							String content = jsonObject.toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							users.put(doctorCode, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//关联业务code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							ct.setRelationCode(outpatientCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//医生信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							ct.setDoctor(doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							ct.setDoctorName(doctor.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							// 设置患者信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							ct.setPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							ct.setSymptoms(wlyyOutpatientDO.getDescription()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							// 设置患者姓名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							ct.setEvaluate(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							// 医生未读数量为1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							ct.setDoctorRead(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//添加就诊图片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							ct.setImages(wlyyOutpatientDO.getDiseaseImg()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							// 添加咨询记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							ConsultDo consult = addConsult(ct.getPatient(), consultTitle, ct.getSymptoms(), ct.getImages(), ct.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							// 设置关联指导 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							consult.setGuidance(ct.getGuidance()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//关联业务code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							consult.setRelationCode(outpatientCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//支付状态为1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							consult.setPayStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							// 设置咨询标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							ct.setConsult(consult.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//推送给IM去创建议题,取得成员消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							JSONObject messages =  new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							JSONObject obj = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							String sessionId = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//协同门诊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							if("2".equals(wlyyOutpatientDO.getOutpatientType())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								BaseDoctorDO generalDoctor = baseDoctorDao.findById(wlyyOutpatientDO.getGeneralDoctor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								messages = imUtil.getCreateTopicMessage(generalDoctor.getId(),generalDoctor.getName(), consult.getTitle(), content, consult.getImages(), doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//5、(im创建咨询) 续方咨询的sessionid为居民code+就诊code+12(图文,视频,图文+视频) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								sessionId = patient + "_" + outpatientCode + "_" + ct.getType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								obj = imUtil.createTopics(sessionId, consult.getId(), p.getName(), users, messages, imUtil.SESSION_TYPE_COLLABORATION_HOSPITAL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								messages = imUtil.getCreateTopicMessage(patient, p.getName(), consult.getTitle(), content, consult.getImages(), doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//5、(im创建咨询) 续方咨询的sessionid为居民code+就诊code+9(图文,视频,图文+视频) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								sessionId = patient + "_" + outpatientCode + "_" + ct.getType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if(1== type){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									//图文复诊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									obj = imUtil.createTopics(sessionId, consult.getId(), p.getName(), users, messages, imUtil.SESSION_TYPE_EXAMINATION); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							ConsultDo consultDo = consultDao.findByRelationCode(outpatientCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							if (consultDo==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//4、创建咨询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								JSONObject users = new JSONObject();//咨询参与者 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								String consultTitle = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//协同门诊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if("2".equals(wlyyOutpatientDO.getOutpatientType())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									users.put(wlyyOutpatientDO.getGeneralDoctor(),0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									ct.setType(12); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									consultTitle = "申请协同门诊"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									JSONObject consultName = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									consultName.put("patientName",p.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									consultName.put("doctorName",doctor.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									jsonObject.put("name",consultName.toJSONString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									//视频复诊+图文复诊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									obj = imUtil.createTopics(sessionId, consult.getId(), p.getName(), users, messages, imUtil.SESSION_TYPE_EXAMINATION_VIDEO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									users.put(patient, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									consultTitle = "申请复诊"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								String content = jsonObject.toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							if (obj == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								throw new RuntimeException("IM消息发送异常!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							if (obj.getInteger("status") == -1) {//im议题创建失败 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								throw new RuntimeException(obj.getString("message")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							ct.setStartMsgId(obj.get("start_msg_id").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							consultTeamDao.save(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							consultDao.save(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//设置咨询code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								users.put(doctorCode, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//关联业务code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ct.setRelationCode(outpatientCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//医生信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ct.setDoctor(doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ct.setDoctorName(doctor.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								// 设置患者信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ct.setPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ct.setSymptoms(wlyyOutpatientDO.getDescription()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								// 设置患者姓名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ct.setEvaluate(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								// 医生未读数量为1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ct.setDoctorRead(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//添加就诊图片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ct.setImages(wlyyOutpatientDO.getDiseaseImg()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								// 添加咨询记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ConsultDo consult = addConsult(ct.getPatient(), consultTitle, ct.getSymptoms(), ct.getImages(), ct.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								// 设置关联指导 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								consult.setGuidance(ct.getGuidance()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//关联业务code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								consult.setRelationCode(outpatientCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//支付状态为1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								consult.setPayStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								// 设置咨询标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ct.setConsult(consult.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//推送给IM去创建议题,取得成员消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								JSONObject messages =  new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								JSONObject obj = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								String sessionId = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//协同门诊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if("2".equals(wlyyOutpatientDO.getOutpatientType())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									BaseDoctorDO generalDoctor = baseDoctorDao.findById(wlyyOutpatientDO.getGeneralDoctor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									messages = imUtil.getCreateTopicMessage(generalDoctor.getId(),generalDoctor.getName(), consult.getTitle(), content, consult.getImages(), doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									//5、(im创建咨询) 续方咨询的sessionid为居民code+就诊code+12(图文,视频,图文+视频) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									sessionId = patient + "_" + outpatientCode + "_" + ct.getType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									obj = imUtil.createTopics(sessionId, consult.getId(), p.getName(), users, messages, imUtil.SESSION_TYPE_COLLABORATION_HOSPITAL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									messages = imUtil.getCreateTopicMessage(patient, p.getName(), consult.getTitle(), content, consult.getImages(), doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									//5、(im创建咨询) 续方咨询的sessionid为居民code+就诊code+9(图文,视频,图文+视频) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									sessionId = patient + "_" + outpatientCode + "_" + ct.getType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									if(1== type){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
										//图文复诊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
										obj = imUtil.createTopics(sessionId, consult.getId(), p.getName(), users, messages, imUtil.SESSION_TYPE_EXAMINATION); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
										//视频复诊+图文复诊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
										obj = imUtil.createTopics(sessionId, consult.getId(), p.getName(), users, messages, imUtil.SESSION_TYPE_EXAMINATION_VIDEO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if (obj == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									throw new RuntimeException("IM消息发送异常!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if (obj.getInteger("status") == -1) {//im议题创建失败 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									throw new RuntimeException(obj.getString("message")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ct.setStartMsgId(obj.get("start_msg_id").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								consultTeamDao.save(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								consultDao.save(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//设置咨询code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//			wlyyOutpatientDO.setConsult(consult.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//			prescriptionDao.save(prescription); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//6、记录咨询的医生详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							ConsultTeamDoctorDo cd = new ConsultTeamDoctorDo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							cd.setConsult(consult.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							cd.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							cd.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							cd.setTo(doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							consultTeamDoctorDao.save(cd); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//7、发送系统消息提示团队长有未审核的消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//6、记录咨询的医生详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ConsultTeamDoctorDo cd = new ConsultTeamDoctorDo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								cd.setConsult(consult.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								cd.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								cd.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								cd.setTo(doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								consultTeamDoctorDao.save(cd); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//7、发送系统消息提示团队长有未审核的消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//			addCheckMessage(prescription, sessionId, p); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//8、 保存医生咨询信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							// 添加咨询转发记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							// 添加医生咨询日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							addLogs(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							JSONObject result = imUtil.getSingleSessionInfo(sessionId,doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//8、 保存医生咨询信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								// 添加咨询转发记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								// 添加医生咨询日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								addLogs(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							String sessionIds = patient + "_" + outpatientCode + "_" + ct.getType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							JSONObject result = imUtil.getSingleSessionInfo(sessionIds,doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							wlyyOutpatientDO.setStatus("1");//修改就诊记录为就诊中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							wlyyOutpatientDO.setConDate(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							wlyyOutpatientDO.setDoctor(doctorCode); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -1312,11 +1314,149 @@ public class ImService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//医生接诊发送导诊护士外层消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								this.sendOutpatientGuaidanceMessage(wlyyOutpatientDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * 添加复诊咨询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					public JSONObject addConsult(String outpatientCode, String patient,String doctorCode, ConsultTeamDo ct, String reason, Integer type,String wxId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//1、获取his就诊记录详情(保存续方表、药品续方信息表、续方疾病类型表) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findOne(outpatientCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						BaseDoctorDO doctor = baseDoctorDao.findById(doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//			doctorCode = doctor.getCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						// 查询患者信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						BasePatientDO p = basePatientDao.findById(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						jsonObject.put("title", p.getName() + "申请复诊"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						jsonObject.put("content",wlyyOutpatientDO.getDescription()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						jsonObject.put("age",DateUtil.getAgeForIdcard(p.getIdcard())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						jsonObject.put("sex",p.getSex()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						jsonObject.put("name",p.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//4、创建咨询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						JSONObject users = new JSONObject();//咨询参与者 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						String consultTitle = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//协同门诊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						if("2".equals(wlyyOutpatientDO.getOutpatientType())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							users.put(wlyyOutpatientDO.getGeneralDoctor(),0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							ct.setType(12); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							consultTitle = "申请协同门诊"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							JSONObject consultName = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							consultName.put("patientName",p.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							consultName.put("doctorName",doctor.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							jsonObject.put("name",consultName.toJSONString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							users.put(patient, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							consultTitle = "申请复诊"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						String content = jsonObject.toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						users.put(doctorCode, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//关联业务code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						ct.setRelationCode(outpatientCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//医生信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						ct.setDoctor(doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						ct.setDoctorName(doctor.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						// 设置患者信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						ct.setPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						ct.setSymptoms(wlyyOutpatientDO.getDescription()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						// 设置患者姓名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						ct.setEvaluate(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						// 医生未读数量为1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						ct.setDoctorRead(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//添加就诊图片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						ct.setImages(wlyyOutpatientDO.getDiseaseImg()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						// 添加咨询记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						ConsultDo consult = addConsult(ct.getPatient(), consultTitle, ct.getSymptoms(), ct.getImages(), ct.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						// 设置关联指导 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						consult.setGuidance(ct.getGuidance()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//关联业务code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						consult.setRelationCode(outpatientCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//支付状态为1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						consult.setPayStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						// 设置咨询标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						ct.setConsult(consult.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//推送给IM去创建议题,取得成员消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						JSONObject messages =  new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						JSONObject obj = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						String sessionId = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//协同门诊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						if("2".equals(wlyyOutpatientDO.getOutpatientType())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							BaseDoctorDO generalDoctor = baseDoctorDao.findById(wlyyOutpatientDO.getGeneralDoctor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							messages = imUtil.getCreateTopicMessage(generalDoctor.getId(),generalDoctor.getName(), consult.getTitle(), content, consult.getImages(), doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//5、(im创建咨询) 续方咨询的sessionid为居民code+就诊code+12(图文,视频,图文+视频) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							sessionId = patient + "_" + outpatientCode + "_" + ct.getType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							obj = imUtil.createTopics(sessionId, consult.getId(), p.getName(), users, messages, imUtil.SESSION_TYPE_COLLABORATION_HOSPITAL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							messages = imUtil.getCreateTopicMessage(patient, p.getName(), consult.getTitle(), content, consult.getImages(), doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//5、(im创建咨询) 续方咨询的sessionid为居民code+就诊code+9(图文,视频,图文+视频) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							sessionId = patient + "_" + outpatientCode + "_" + ct.getType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							if(1== type){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//图文复诊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								obj = imUtil.createTopics(sessionId, consult.getId(), p.getName(), users, messages, imUtil.SESSION_TYPE_EXAMINATION); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//视频复诊+图文复诊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								obj = imUtil.createTopics(sessionId, consult.getId(), p.getName(), users, messages, imUtil.SESSION_TYPE_EXAMINATION_VIDEO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						if (obj == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							throw new RuntimeException("IM消息发送异常!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						if (obj.getInteger("status") == -1) {//im议题创建失败 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							throw new RuntimeException(obj.getString("message")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						ct.setStartMsgId(obj.get("start_msg_id").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						consultTeamDao.save(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						consultDao.save(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//设置咨询code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//			wlyyOutpatientDO.setConsult(consult.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//			prescriptionDao.save(prescription); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//6、记录咨询的医生详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						ConsultTeamDoctorDo cd = new ConsultTeamDoctorDo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						cd.setConsult(consult.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						cd.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						cd.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						cd.setTo(doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						consultTeamDoctorDao.save(cd); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//7、发送系统消息提示团队长有未审核的消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//			addCheckMessage(prescription, sessionId, p); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//8、 保存医生咨询信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						// 添加咨询转发记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						// 添加医生咨询日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						addLogs(ct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						JSONObject result = imUtil.getSingleSessionInfo(sessionId,doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * 医生接诊发送导诊护士外层消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @param wlyyOutpatientDO 
			 |