| 
					
				 | 
			
			
				@ -0,0 +1,212 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.care.service.visit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.fasterxml.jackson.databind.JavaType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.fasterxml.jackson.databind.ObjectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.visit.BaseVisitDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.doctor.dao.BaseDoctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.doctor.BaseDoctorDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.patient.BasePatientDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.visit.BaseVisitDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.patient.dao.BasePatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.common.IdCardUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.transaction.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by yeshijie on 2021/11/11. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class BaseVisitService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseVisitDao baseVisitDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private ObjectMapper objectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BasePatientDao patientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseDoctorDao doctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取走访列表-日历 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<Map<String, Object>> getListByDoctor(String doctorCode, String startTime, String endTime) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> re = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String, Map<String, Object>> temp = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<BaseVisitDO> list = baseVisitDao.findByDoctor(doctorCode, DateUtil.strToDate(startTime), DateUtil.strToDate(endTime)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (list != null && list.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (BaseVisitDO visitDO : list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String date = DateUtil.dateToStrShort(visitDO.getVisitPlanDate()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Map<String, String> map = getVisitDetail(visitDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (temp.containsKey(date)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Map<String, Object> vo = temp.get(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    vo.put("num", Integer.parseInt(vo.get("num").toString()) + 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    ((List<Map<String, String>>) vo.get("list")).add(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    temp.put(date, vo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Map<String, Object> vo = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    List<Map<String, String>> list1 = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    vo.put("date", date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    vo.put("num", 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    list1.add(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    vo.put("list", list1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    temp.put(date, vo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Map<String, Object> map : temp.values()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                re.add(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return re; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 转译走访信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private Map<String, String> getVisitDetail(BaseVisitDO visitDO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String, String> re = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("id", visitDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("visitDate", DateUtil.dateToStrLong(visitDO.getVisitDate())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("visitPlanDate", DateUtil.dateToStrLong(visitDO.getVisitPlanDate())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("type", visitDO.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("status", visitDO.getStatus()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("doctor", visitDO.getDoctor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("doctorName", visitDO.getDoctorName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("patient", visitDO.getPatient()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("patientName", visitDO.getPatientName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return re; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 删除 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String delVisti(String id){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BaseVisitDO visitDO = baseVisitDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(visitDO == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return "走访已删除,请勿重复操作"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if("1".equals(visitDO.getStatus())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return "走访已完成不能删除"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 修改走访计划时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String updVisit(String id,String visitPlanDate){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BaseVisitDO visitDO = baseVisitDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if("1".equals(visitDO.getStatus())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return "走访已完成不能修改"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Date planDate = DateUtil.strToDate(visitPlanDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(DateUtil.compareDateTime(planDate,new Date())<0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return "计划走访日期不能早于当前日期"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        visitDO.setVisitPlanDate(planDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        visitDO.setStatus("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        baseVisitDao.save(visitDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 完成走访 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String completeVisit(String id,String visitContent,String visitImg){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BaseVisitDO visitDO = baseVisitDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if("1".equals(visitDO.getStatus())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return "走访已完成,请勿重复操作"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        visitDO.setVisitDate(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        visitDO.setStatus("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        visitDO.setVisitContent(visitContent); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        visitDO.setVisitImg(visitImg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        baseVisitDao.save(visitDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取走访详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Map<String, String> findVisitDetail(String id){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String, String> re = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BaseVisitDO visitDO = baseVisitDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("id", visitDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("visitDate", DateUtil.dateToStrLong(visitDO.getVisitDate())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("visitPlanDate", DateUtil.dateToStrLong(visitDO.getVisitPlanDate())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("type", visitDO.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("status", visitDO.getStatus()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("doctor", visitDO.getDoctor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("doctorName", visitDO.getDoctorName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("patient", visitDO.getPatient()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("patientName", visitDO.getPatientName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("visitImg",visitDO.getVisitImg()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("visitContent",visitDO.getVisitContent()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BasePatientDO patient = patientDao.findById(visitDO.getPatient()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (patient != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            re.put("idcard", patient.getIdcard()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String mobile = patient.getMobile(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            re.put("mobile", mobile); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            re.put("sex", String.valueOf(patient.getSex())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            re.put("birthday", DateUtil.dateToStrLong(patient.getBirthday())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            re.put("photo", patient.getPhoto()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            re.put("age", IdCardUtil.getAgeByIdcardOrBirthday(patient.getIdcard(),patient.getBirthday())+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return re; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 新增随访计划(批量) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void addVistiPlan(String doctorCode, String patientCode, String data) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //批量随访计划 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, Map.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, String>> list = objectMapper.readValue(data, javaType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (list != null && list.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //获取患者信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            BasePatientDO patient = patientDao.findById(patientCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (patient == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new Exception("获取不到用户信息!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            BaseDoctorDO doctor = doctorDao.findById(doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (doctor == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new Exception("获取不到医生信息!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<BaseVisitDO> visitPlans = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Map<String, String> map : list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                BaseVisitDO visitDO = new BaseVisitDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                visitDO.setType("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                visitDO.setStatus("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Date date = DateUtil.strToDate(map.get("date")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                visitDO.setVisitPlanDate(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                visitDO.setDoctor(doctorCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                visitDO.setDoctorName(doctor.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                visitDO.setPatient(patientCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                visitDO.setPatientName(patient.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                visitPlans.add(visitDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            baseVisitDao.save(visitPlans); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |