| 
					
				 | 
			
			
				@ -3,11 +3,24 @@ package com.yihu.wlyy.service.app.prescription; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.followup.Followup; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.followup.FollowupDrugs; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.prescription.Prescription; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.prescription.PrescriptionFollowupContent; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.prescription.PrescriptionInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.followup.FollowUpDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.followup.FollowupDrugsDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.prescription.PrescriptionDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.prescription.PrescriptionFollowupContentDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.prescription.PrescriptionInfoDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.BaseService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.app.followup.FollowUpService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.app.health.PatientHealthIndexService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.util.ImUtill; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.JdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -26,6 +39,22 @@ public class PrescriptionFollowupContentService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					private PrescriptionFollowupContentDao prescriptionFollowupContentDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					private PrescriptionInfoDao prescriptionInfoDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					private FollowupDrugsDao followupDrugsDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					private PrescriptionDao prescriptionDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					private PatientHealthIndexService healthIndexService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					private FollowUpService followUpService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					private FollowUpDao followUpDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					private ImUtill ImUtill; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					@Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					JdbcTemplate jdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * 根据续方CODE,文件类型获取数据 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -55,9 +84,10 @@ public class PrescriptionFollowupContentService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * 保存随访调查分类数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @param prescriptioncode 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @param followupProjectData 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @param sendIM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					public void saveInfo(String prescriptioncode, String followupProjectData,String patientCode) throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					public void saveInfo(String prescriptioncode, String followupProjectData,String patientCode,boolean sendIM) throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						JSONArray objects = JSON.parseArray(followupProjectData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						if(objects!= null & objects.size() >0){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -67,7 +97,7 @@ public class PrescriptionFollowupContentService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								String followupProject = jsonObject.getString("followupProject"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								String projectValueStr = jsonObject.getString("projectData"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if(StringUtils.isNotBlank(projectValueStr)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									HashMap<String,String> projectValueMap = (HashMap)JSON.parse(projectValueStr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									Map<String,String> projectValueMap = (Map)JSON.parse(projectValueStr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									if(!projectValueMap.isEmpty()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
										projectValueMap.forEach( (key,value)->{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
											PrescriptionFollowupContent prescriptionFollowupContent = new PrescriptionFollowupContent(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -84,6 +114,19 @@ public class PrescriptionFollowupContentService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if(!savedatas.isEmpty()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									prescriptionFollowupContentDao.deleteByPrescriptioncodeAndFollowupProject(prescriptioncode,followupProject); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									prescriptionFollowupContentDao.save(savedatas); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									if(sendIM){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
										org.json.JSONObject content = new org.json.JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
										content.put("title", "【本消息为系统提醒】:"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
										if("1".equals(followupProject)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
											content.put("text", "居民已填写《身份异常症状问卷》"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
										}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
											content.put("text", "居民已填写《体征及生活方式调查问卷》"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
										} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
										content.put("sysMsg","填写完成并提交后,医生将可以查看您的问卷内容"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
										Prescription p = prescriptionDao.findByCode(prescriptioncode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
										ImUtill.sendTopicIM(p.getDoctor(), p.getDoctorName(), p.getConsult(), "17", content.toString(), null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -136,7 +179,7 @@ public class PrescriptionFollowupContentService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							JSONObject jsonObject1 = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							jsonObject1.put("type","1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							jsonObject1.put("name","身份异常症状问卷"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							jsonObject1.put("statue","已填写"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							jsonObject1.put("statue","1");//1已填写,2未填写 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							jsonObject1.put("createtime",prescriptionFollowupContent1.getCreateTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							result.add(jsonObject1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						} 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -145,11 +188,336 @@ public class PrescriptionFollowupContentService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							JSONObject jsonObject2 = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							jsonObject2.put("type","2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							jsonObject2.put("name","体征及生活方式调查问卷"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							jsonObject2.put("statue","已填写"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							jsonObject2.put("statue","1");//1已填写,2未填写 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							jsonObject2.put("createtime",prescriptionFollowupContent1.getCreateTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							result.add(jsonObject2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * 续方药品导入随访记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @param prescriptioncode 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @param followup_id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					public void importPrescriptionDrugsToFollowup(String prescriptioncode, String followup_id) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						Long followupId = Long.valueOf(followup_id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						Followup followup =followUpDao.findOne(followupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						if(followup == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							throw new Exception("未找到随访记录!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//删除原有用药记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						followupDrugsDao.deleteByFollowupId(Long.valueOf(followupId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						List<PrescriptionInfo> list = prescriptionInfoDao.findByPrescriptionCode(prescriptioncode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						if(list!=null && list.size()>0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							List<FollowupDrugs> newList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							for(PrescriptionInfo prescriptionInfo:list) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								FollowupDrugs drug = new FollowupDrugs(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								drug.setFollowupId(followupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if(prescriptionInfo.getDrugName().contains("胰岛素") &&prescriptionInfo.getSubjectClass().contains("010")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									drug.setDrugsGroup("insulin"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									drug.setDrugsGroup("normal"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								drug.setDrugsCode(prescriptionInfo.getDrugCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								drug.setDrugsName(prescriptionInfo.getDrugName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								drug.setDose(prescriptionInfo.getPhysicDose()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								drug.setUnit(prescriptionInfo.getDrugNumUnit()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								drug.setFrequency(prescriptionInfo.getDrugRate()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								drug.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								newList.add(drug); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							followupDrugsDao.save(newList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * 续方患者的血糖导入随访记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @param prescriptioncode 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @param followup_id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					public void importPatientBloodSugarToFollowup(String prescriptioncode, String followup_id,boolean sendIM) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						Long followupId = Long.valueOf(followup_id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						Followup followup =followUpDao.findOne(followupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						if(followup == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							throw new Exception("未找到随访记录!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						Prescription prescription = prescriptionDao.findByCode(prescriptioncode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						String patientCode = prescription.getParentCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						String stardate = DateUtil.getNextMonth(new Date(),-30)+" 00:00:00"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						String enddate = DateUtil.getStringDateShort()+" 23:59:59"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						List<Object> list = healthIndexService.findIndexByPatient2(patientCode, 1, stardate, enddate, 0, 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						String followupProjectData = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						org.json.JSONObject contentDoctor = new org.json.JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						org.json.JSONObject contentPatient = new org.json.JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						String imBloodSugarValue = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						String imBloodSugarDate = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						if(!list.isEmpty()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							for (Object o: list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								JSONObject obj = (JSONObject)o; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								imBloodSugarDate = obj.getString("recordDate"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//餐前 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if(StringUtils.isNotBlank(obj.getString("value1"))){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									followupProjectData = "{'BS_FPG':'"+obj.getString("value1")+"'}"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									imBloodSugarValue = obj.getString("value1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if(StringUtils.isNotBlank(obj.getString("value3"))){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									followupProjectData = "{'BS_FPG':'"+obj.getString("value3")+"'}"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									imBloodSugarValue = obj.getString("value3"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if(StringUtils.isNotBlank(obj.getString("value5"))){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									followupProjectData = "{'BS_FPG':'"+obj.getString("value5")+"'}"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									imBloodSugarValue = obj.getString("value5"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//餐后 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if(StringUtils.isNotBlank(obj.getString("value2"))){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									followupProjectData = "{'NO_BS_FPG':'"+obj.getString("value2")+"'}"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									imBloodSugarValue = obj.getString("value2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if(StringUtils.isNotBlank(obj.getString("value4"))){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									followupProjectData = "{'NO_BS_FPG':'"+obj.getString("value4")+"'}"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									imBloodSugarValue = obj.getString("value4"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if(StringUtils.isNotBlank(obj.getString("value6"))){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									followupProjectData = "{'NO_BS_FPG':'"+obj.getString("value6")+"'}"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									imBloodSugarValue = obj.getString("value6"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//随机血糖 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if(StringUtils.isNotBlank(obj.getString("value7"))){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									followupProjectData = "{'RANDOM_BLOOD_SUGAR':'"+obj.getString("value7")+"'}"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									imBloodSugarValue = obj.getString("value7"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							followUpService.esSaveFollowupProjectData(followup_id, "3", followupProjectData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//是否需要发送IM消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							if(sendIM){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//医生发送的消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentDoctor.put("text", "请提供您最近一次的血糖检测数值及检测时间"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentDoctor.put("needupload",false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								int total = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								String sql = "select sum(category_code) amount deviceType FROM wlyy_patient_device WHERE user="+prescription.getPatient(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								List<Map<String,Object>> result =  jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if (result != null && result.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									total = (result.get(0).get("amount") != null ? Integer.parseInt(result.get(0).get("amount").toString()) : 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if(total != 1 || total != 3){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									contentDoctor.put("deviceMsg","您未绑定血糖智能设备,请手动上传体征数据,绑定设备后系统将会自动将您的体征数据上报给医生"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//医生发送Im消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ImUtill.sendTopicIM(prescription.getDoctor(), prescription.getDoctorName(), prescription.getConsult(), "16", contentDoctor.toString(), null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//患者发送的消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentPatient.put("title", "【本消息为系统提醒】:"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentPatient.put("tzMsg", "体征记录:血糖"+imBloodSugarValue); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentPatient.put("tzTime", "检测时间:"+imBloodSugarDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentPatient.put("tzAlert","温馨提示:本条体征为居民上传的健康体征数据,您可以自动填入本次随访记录"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//患者发送Im消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ImUtill.sendTopicIM(prescription.getPatient(), prescription.getPatientName(), prescription.getConsult(), "16", contentPatient.toString(), null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//是否需要发送IM消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							if(sendIM){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//医生发送的消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentDoctor.put("text", "居民近30天未上传血糖体征数据,已通知居民上传数据,请耐心等待"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentDoctor.put("needupload",true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								throw new Exception("未找到30天内的血糖记录!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * 续方患者的血压导入随访记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @param prescriptioncode 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @param followup_id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @param sendIM 是否发送IM消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					public void importPatientBloodPressureToFollowup(String prescriptioncode, String followup_id,boolean sendIM) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						Long followupId = Long.valueOf(followup_id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						Followup followup =followUpDao.findOne(followupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						if(followup == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							throw new Exception("未找到随访记录!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						Prescription prescription = prescriptionDao.findByCode(prescriptioncode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						String patientCode = prescription.getParentCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						String stardate = DateUtil.getNextMonth(new Date(),-30)+" 00:00:00"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						String enddate = DateUtil.getStringDateShort()+" 23:59:59"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						org.json.JSONArray jsonArray = healthIndexService.findIndexByPatient(patientCode, 2, stardate, enddate, 0, 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						String followupProjectData = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						org.json.JSONObject contentDoctor = new org.json.JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						org.json.JSONObject contentPatient = new org.json.JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						if(jsonArray.length() > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							org.json.JSONObject jsonObject = jsonArray.getJSONObject(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							followupProjectData = "{'BP_D':'"+jsonObject.getString("value1")+"'BP_U':'"+jsonObject.getString("value2")+"'}"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							followUpService.esSaveFollowupProjectData(followup_id, "2", followupProjectData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//是否需要发送IM消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							if(sendIM){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//医生发送的消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentDoctor.put("text", "请提供您最近一次的血压检测数值及检测时间"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentDoctor.put("needUpload",false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								int total = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								String sql = "select sum(category_code) amount deviceType FROM wlyy_patient_device WHERE user="+prescription.getPatient(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								List<Map<String,Object>> result =  jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if (result != null && result.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									total = (result.get(0).get("amount") != null ? Integer.parseInt(result.get(0).get("amount").toString()) : 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								if(total != 2 || total != 3){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									contentDoctor.put("deviceMsg","您未绑定血压智能设备,请手动上传体征数据,绑定设备后系统将会自动将您的体征数据上报给医生"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//医生发送Im消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ImUtill.sendTopicIM(prescription.getDoctor(), prescription.getDoctorName(), prescription.getConsult(), "16", contentDoctor.toString(), null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//患者发送的消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentPatient.put("title", "【本消息为系统提醒】:"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentPatient.put("tzMsg", "体征记录:血压"+jsonObject.getString("value1")+"/"+jsonObject.getString("value2")+" mmHg"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentPatient.put("tzTime", "检测时间:"+jsonObject.getString("date")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentPatient.put("tzAlert","温馨提示:本条体征为居民上传的健康体征数据,您可以自动填入本次随访记录"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//患者发送Im消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								ImUtill.sendTopicIM(prescription.getPatient(), prescription.getPatientName(), prescription.getConsult(), "16", contentPatient.toString(), null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//是否需要发送IM消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							if(sendIM){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								//医生发送的消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentDoctor.put("text", "居民近30天未上传血压体征数据,已通知居民上传数据,请耐心等待"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								contentDoctor.put("needupload",true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								throw new Exception("未找到30天内的血压记录!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * 续方问卷导入随访记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @param prescriptioncode 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @param followup_id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 * @param type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					public void importfollowupcontent(String prescriptioncode, String followup_id, String type) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						Long followupId = Long.valueOf(followup_id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						Followup followup =followUpDao.findOne(followupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						if(followup == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							throw new Exception("未找到随访记录!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						Prescription prescription = prescriptionDao.findByCode(prescriptioncode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						String patientCode = prescription.getParentCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						if("1".equals(type)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						//1身份异常症状问卷 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							List<PrescriptionFollowupContent>  list = prescriptionFollowupContentDao.findByPrescriptionCodeAndFollowupProject(prescriptioncode,type); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							Map<String, String> datamap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							if(!list.isEmpty()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								for (PrescriptionFollowupContent prescriptionFollowupContent: list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									datamap.put(prescriptionFollowupContent.getFollowupKey(),prescriptionFollowupContent.getFollowupValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							followUpService.esSaveFollowupProjectData(followup_id, type, JSON.toJSONString(datamap)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						}else if("2".equals(type)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//2体征 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							Map<String, String> datamap2 = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							List<PrescriptionFollowupContent>  list2 = prescriptionFollowupContentDao.findByPrescriptionCodeAndFollowupProject(prescriptioncode,"2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							if(!list2.isEmpty()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								for (PrescriptionFollowupContent prescriptionFollowupContent: list2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									datamap2.put(prescriptionFollowupContent.getFollowupKey(),prescriptionFollowupContent.getFollowupValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							//近30天血压 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							String stardate = DateUtil.getNextMonth(new Date(),-30)+" 00:00:00"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							String enddate = DateUtil.getStringDateShort()+" 23:59:59"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							org.json.JSONArray jsonArray = healthIndexService.findIndexByPatient(patientCode, 2, stardate, enddate, 0, 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							if(jsonArray.length() > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								org.json.JSONObject jsonObject = jsonArray.getJSONObject(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								datamap2.put("BP_D",jsonObject.getString("value1")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								datamap2.put("BP_U",jsonObject.getString("value2")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							followUpService.esSaveFollowupProjectData(followup_id, "2", JSON.toJSONString(datamap2)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							Map<String, String> datamap3 = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							List<PrescriptionFollowupContent>  list3 = prescriptionFollowupContentDao.findByPrescriptionCodeAndFollowupProject(prescriptioncode,"4"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							if(!list3.isEmpty()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								for (PrescriptionFollowupContent prescriptionFollowupContent: list2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
									datamap3.put(prescriptionFollowupContent.getFollowupKey(),prescriptionFollowupContent.getFollowupValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
								} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
							followUpService.esSaveFollowupProjectData(followup_id, "4", JSON.toJSONString(datamap3)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						 
			 | 
		
	
		
			
				 | 
				 | 
			
			
						}else{} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |