| 
					
				 | 
			
			
				@ -0,0 +1,143 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.hospital.module.common.service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.doctor.dao.BaseDoctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.doctor.BaseDoctorDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.label.WlyyPatientLabelDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.label.WlyyPatientLabelLogDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.label.WlyyPatientLabelDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.label.WlyyPatientLabelLogDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.web.PageEnvelop; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.entity.ServiceException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.BeanPropertyRowMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.JdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by yeshijie on 2024/3/4. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class LabelService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private WlyyPatientLabelDao patientLabelDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private WlyyPatientLabelLogDao logDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseDoctorDao doctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private JdbcTemplate jdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<WlyyPatientLabelDO> findByPatient(String patient){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return patientLabelDao.findByPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //查询专病的康复管理未执行完成数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public int existDisease(String patient,String disease){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT COUNT(id) from wlyy_patient_rehabilitation_plan " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " WHERE patient='"+patient+"' and disease ='"+disease+"' and `status` in (1,3)"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return jdbcTemplate.queryForObject(sql,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //添加专病标签 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void addDiseaseLable(String patient,String disease,String diseaseName){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(patientLabelDao.findByPatient(patient,disease,"3").size()==0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                WlyyPatientLabelDO label = new WlyyPatientLabelDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                label.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                label.setIsSystem(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                label.setPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                label.setLabelCode(disease); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                label.setLabelName(diseaseName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                label.setLabelType("3"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                patientLabelDao.save(label); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //查询标签新增日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public PageEnvelop patientLabelLogPage(String patient, String doctor, String labelType, int page, int size){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "select * "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String countSql = "select count(*) "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String filter = " from wlyy_patient_label_log where 1=1 "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String orderBy = " order by create_time desc limit "+(page-1)*size+","+size; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(patient)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            filter += " and patient = '"+patient+"' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(doctor)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            filter += " and doctor = '"+doctor+"' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(labelType)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            filter += " and label_type = '"+labelType+"' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<WlyyPatientLabelLogDO> logDOS = jdbcTemplate.query(sql+filter+orderBy,new BeanPropertyRowMapper<>(WlyyPatientLabelLogDO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Long count = jdbcTemplate.queryForObject(countSql+filter,Long.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return PageEnvelop.getSuccessListWithPage("查询成功",logDOS,page,size,count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //保存居民标签 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void savePatientLabel(List<WlyyPatientLabelDO> labelDOS, String patient,String doctor) throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<WlyyPatientLabelDO> patientLabelDOS = patientLabelDao.findByPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String,String> map = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (WlyyPatientLabelDO label:patientLabelDOS){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String labelCode = label.getLabelCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String labelType = label.getLabelType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put(labelType+"_"+labelCode,label.getLabelName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        patientLabelDao.deleteByPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<WlyyPatientLabelLogDO> labelLogDOS = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Date now = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BaseDoctorDO doctorDO = doctorDao.findByIdAndDel(doctor); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(labelDOS!=null&&labelDOS.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (WlyyPatientLabelDO label:labelDOS){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                label.setPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                label.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                label.setIsSystem(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String key = label.getLabelType()+"_"+label.getLabelCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(!map.containsKey(key)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    WlyyPatientLabelLogDO logDO = new WlyyPatientLabelLogDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logDO.setCreateTime(now); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logDO.setPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logDO.setDoctor(doctor); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logDO.setDoctorName(doctorDO.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logDO.setLabelCode(label.getLabelCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logDO.setLabelName(label.getLabelName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logDO.setLabelType(label.getLabelType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logDO.setJobTitle(doctorDO.getJobTitleName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    labelLogDOS.add(logDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            patientLabelDao.saveAll(labelDOS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(labelLogDOS.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logDao.saveAll(labelLogDOS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //添加自定义标签字典 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public WlyyHospitalSysDictDO addLabelDict(String labelName) throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isBlank(labelName)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new ServiceException("请填写分组名称"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        labelName = labelName.trim(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<WlyyHospitalSysDictDO> dictDOList = wlyyHospitalSysDictDao.findByDictNameAndDictCode("patient_lable_custom",labelName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(dictDOList.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new ServiceException("该分组已存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        WlyyHospitalSysDictDO dictDO = new WlyyHospitalSysDictDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        dictDO.setDictValue(labelName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        dictDO.setDictCode(labelName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        dictDO.setDictName("patient_lable_custom"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        dictDO = wlyyHospitalSysDictDao.save(dictDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return dictDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |