| 
					
				 | 
			
			
				@ -3,13 +3,16 @@ package com.yihu.wlyy.service.service.prescription; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.common.SystemConfig; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.common.model.Result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.common.util.AmoutUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.common.util.CommonUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.common.util.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.dao.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.dao.consult.ConsultTeamDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.dao.prescription.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.entity.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.entity.consult.ConsultTeam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.entity.prescription.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.entity.prescription.VO.PrescriptionExpressageVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.service.ZysoftBaseService; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -64,11 +67,12 @@ public class PrescriptionService extends ZysoftBaseService{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PrescriptionReviewedDao prescriptionReviewedDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private MessageDao messageDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${im.data_base_name}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String im; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${redisChannel.prescription}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String channelTopic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    private String channelTopic = "redisPrescription"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private ConsultTeamDao consultTeamDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private AmoutUtils amoutUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -165,6 +169,9 @@ public class PrescriptionService extends ZysoftBaseService{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        prescriptionInfo.setIsRefrigerate(isRefrigerate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        //用药频率 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        prescriptionInfo.setDrugRateName(getZyCommonDictName(info.getString("drugRate"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        infoList.add(prescriptionInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -192,12 +199,12 @@ public class PrescriptionService extends ZysoftBaseService{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    messageDao.save(message); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    // redis 的发布 {tilte:redisAddPrescription   state: 1 ,//1:成功,2.失败 mes:'开方成功' prescription : "0001" //续方CODE  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    JSONObject redisMessage = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    redisMessage.put("title","adjustPrescription"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    redisMessage.put("state",1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    redisMessage.put("prescription",prescription.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    redisMessage.put("mes","调整处方完成"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    redisTemplate.convertAndSend(channelTopic,redisMessage.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    JSONObject redisMessage = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    redisMessage.put("title","adjustPrescription"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    redisMessage.put("state",1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    redisMessage.put("prescription",prescription.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    redisMessage.put("mes","调整处方完成"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    redisTemplate.opsForList().leftPush(channelTopic,redisMessage.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //调整失败 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescription.setStatus(4); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -222,6 +229,18 @@ public class PrescriptionService extends ZysoftBaseService{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return addZyPushLog(jsonObject,"prescriptionAdjustCompleted","接收线下处方调整完成消息",error,"POST",status,"1",errMsg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String getZyCommonDictName(String code){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String sql  ="SELECT t.name FROM zy_common_dict t WHERE t.code=? AND t.dict_name='IV_RECIPE_FREQUENCY_DICT'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<Map<String,Object>> list = jdbcTemplate.queryForList(sql,new Object[]{code}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(list!=null&&list.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return (String)(list.get(0).get("name")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 接收预结算完成消息 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -369,9 +388,88 @@ public class PrescriptionService extends ZysoftBaseService{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return addZyPushLog(jsonObject,"pharmacistPrescriptionCompletion","接收药师审方完成及结果消息",error,"POST",status,"1",errMsg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 提供在线问诊消息调阅 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param jsonObject 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String getReadNewsOnline(String jsonObject){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String url = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String error = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String status = "1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String errMsg = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject json = JSONObject.parseObject(jsonObject); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String orderNo = json.getString("ORDER_NO");//挂号编号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String recipeNo = json.getString("RECIPE_NO");//处方编号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Prescription prescription = prescriptionDao.findByVisitNoAndRecipeNo(orderNo,recipeNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(prescription==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                url = "-1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                url = SystemConfig.sysPropertiesSets.get("readNewsOnline_url")+"?consult="+prescription.getConsult(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }catch (JSONException ex){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ex.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            error = ex.getMessage(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            errMsg = ex.getMessage(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            status = "0"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            error = e.getMessage(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            status = "0"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //添加日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        addZyPushLog(jsonObject,"getReadNewsOnline","提供在线问诊消息调阅",error,"POST",status,"1",errMsg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return url; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /********************************************智业推送数据处理 end**************************************************/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /*********************************************获取im消息 start**************************************************/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取续方消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject getLoglist(String consult,Integer page,Integer pagesize){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject re = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //获取咨询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ConsultTeam consultTeam = consultTeamDao.findByConsult(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String sessionId = consultTeam.getPatient()+"_"+consult+"_8"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //获取消息记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Integer start = (page - 1 < 0 ? 0 : page - 1) * pagesize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Integer end = start + pagesize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            StringBuffer sql = new StringBuffer("select * from "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql.append(im).append(".muc_messages "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql.append(" where session_id = ? "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql.append(" order by timestamp desc "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql.append(" limit ").append(start).append(",").append(end); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<Map<String,Object>> list = jdbcTemplate.queryForList(sql.toString(),sessionId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            re.put("list",list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //获取参与人的信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            StringBuffer parts = new StringBuffer("SELECT u.code id, u.name, u.sex, u.birthday birthdate, u.photo avatar, p.participant_role role, false is_patient,p.last_fetch_time,u.level FROM "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            parts.append(im).append(".sessions s, ").append(im).append(".participants p, wlyy_doctor u "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            parts.append("WHERE s.id = ? AND s.id = p.session_id AND p.participant_id = u.code union "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            parts.append("SELECT u.code id, u.name, u.sex, u.birthday birthdate, u.photo avatar, p.participant_role role, true is_patient,p.last_fetch_time,0 as level FROM "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            parts.append(im).append(".sessions s, ").append(im).append(".participants p, wlyy_patient u "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            parts.append("WHERE s.id = ? AND s.id = p.session_id AND p.participant_id = u.code "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<Map<String,Object>> partsList = jdbcTemplate.queryForList(parts.toString(),sessionId,sessionId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            re.put("users",partsList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.info("获取续方消息失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return re; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /*********************************************获取im消息 end******************************************************/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /*********************************************请求智业接口数据 start**************************************************/ 
			 |