| 
					
				 | 
			
			
				@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.course.NurseryLogDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.course.PatientCourseRecordDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.course.PatientDietRecordDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.common.DictDietDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.course.NurseryLogDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.course.PatientCourseRecordDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.course.PatientDietRecordDO; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -41,6 +42,16 @@ public class NurseryLogService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private JdbcTemplate jdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 查找饮食字典 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<DictDietDO> findDictDiet(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "select * from dict_diet "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<DictDietDO> list = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(DictDietDO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return list; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 根据托育日志id查找 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param id 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -50,17 +61,37 @@ public class NurseryLogService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if("diet".equals(type)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<PatientDietRecordDO> dietRecordDOs = patientDietRecordDao.findByNurseryLogId(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(dietRecordDOs.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return ObjEnvelop.getSuccess("",dietRecordDOs.get(0)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return ObjEnvelop.getSuccess("查找成功",dietRecordDOs.get(0)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if("course".equals(type)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<PatientCourseRecordDO> courseRecordDOs = patientCourseRecordDao.findByNurseryLogId(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(courseRecordDOs.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return ObjEnvelop.getSuccess("",courseRecordDOs.get(0)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return ObjEnvelop.getSuccess("查找成功",courseRecordDOs.get(0)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return ObjEnvelop.getError("未找到记录"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 查找饮食记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public ObjEnvelop findDietRecord(String id){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        PatientDietRecordDO dietRecordDO = patientDietRecordDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return ObjEnvelop.getSuccess("查找成功",dietRecordDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 查找课程记录记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public ObjEnvelop findCourseRecord(String id){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        PatientCourseRecordDO courseRecordDO = patientCourseRecordDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return ObjEnvelop.getSuccess("查找成功",courseRecordDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取课程记录详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param id 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -113,6 +144,8 @@ public class NurseryLogService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        recordDO.setContent(content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        recordDO.setEnclosure(enclosure); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        recordDO.setNurseryLogId(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        NurseryLogDO nurseryLogDO = nurseryLogDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        recordDO.setRecordDate(nurseryLogDO.getRecordDate()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        patientCourseRecordDao.save(recordDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return recordDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -130,6 +163,8 @@ public class NurseryLogService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        recordDO.setEatType(eatType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        recordDO.setIntake(intake); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        recordDO.setAdditionalNotes(additionalNotes); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        NurseryLogDO nurseryLogDO = nurseryLogDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        recordDO.setRecordDate(nurseryLogDO.getRecordDate()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        patientDietRecordDao.save(recordDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return recordDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -282,4 +317,58 @@ public class NurseryLogService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return mapFollow; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     *获取托育日志按月日历形式 - 居民端 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param patient 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param startTime 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param endTime 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Map<String,Object> findNurseryLogByPatient(String patient, String startTime, String endTime)throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String filter = " where patient = '"+patient+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(!StringUtil.isEmpty(startTime)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            filter+=" and record_date >='"+startTime+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(!StringUtil.isEmpty(endTime)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            filter+=" and record_date <='"+endTime+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "select * from (SELECT nursery_log_id nurseryLogId,record_date recordDate,patient,'diet' type  from base_patient_diet_record " +filter+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " union all " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " SELECT nursery_log_id nurseryLogId,record_date recordDate,patient,'course' type from base_patient_course_record "+filter +" ) a"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql+=" order by recordDate desc"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String,Object>> nurseryLogDOs = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //按时间分组 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String,Object> date = sortNurseryByDate(nurseryLogDOs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Map<String,Object> sortNurseryByDate(List<Map<String,Object>> nurseryLogDOs){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //按时间分组 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String,Object> date = new HashedMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(nurseryLogDOs!=null&&nurseryLogDOs.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Iterator it = nurseryLogDOs.iterator(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            while (it.hasNext()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Map<String,Object> nurseryLogDO = (Map<String,Object>)it.next(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //1.获取日期分组 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Map<String,Object> dateNurserys = (Map<String,Object>)date.get(String.valueOf(nurseryLogDO.get("recordDate"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //判断随访时间是否已经创建分组 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(dateNurserys!=null&&dateNurserys.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //同一天时间已经有分组则加入list 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    List<Map<String,Object>> list = (List<Map<String,Object>>)dateNurserys.get("nurserys"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    list.add(nurseryLogDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //同一天的时间没有该分组则创建这天的随访计划List 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Map<String,Object> newdateNursery = new HashedMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    List<Map<String,Object>> dateNurseryLogs = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    dateNurseryLogs.add(nurseryLogDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    newdateNursery.put("nurserys",dateNurseryLogs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    date.put(String.valueOf(nurseryLogDO.get("recordDate")),newdateNursery); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |