| | |
| | | import java.util.*; |
| | | |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.DtoConversionUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | |
| | | import com.smartor.mapper.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private PatArchiveMapper patArchiveMapper; |
| | | |
| | | @Autowired |
| | | private IvrLibaTemplateMapper ivrLibaTemplateMapper; |
| | | private TemplateDeptMapper templateDeptMapper; |
| | | |
| | | @Autowired |
| | | private IvrTaskTemplateMapper ivrTaskTemplateMapper; |
| | | |
| | | @Autowired |
| | | private Icd10AssociationMapper icd10AssociationMapper; |
| | | |
| | | @Autowired |
| | | private SvyTaskTemplateMapper svyTaskTemplateMapper; |
| | | |
| | | @Autowired |
| | | private ServiceTaskMapper serviceTaskMapper; |
| | |
| | | @Override |
| | | public List<PatMedInhosp> selectPatMedInhospList(PatMedInhosp patMedInhosp) { |
| | | return patMedInhospMapper.selectPatMedInhospList(patMedInhosp); |
| | | } |
| | | |
| | | /** |
| | | * 查询当前登陆人自己(病区、部门)的患者住院记录列表 |
| | | * |
| | | * @param patMedInhospVO |
| | | * @return |
| | | */ |
| | | public List<PatMedInhosp> selectPatMedInhospListByCondition(PatMedInhospVO patMedInhospVO) { |
| | | return patMedInhospMapper.selectPatMedInhospListByCondition(patMedInhospVO); |
| | | } |
| | | |
| | | |
| | |
| | | return patMedInhospMapper.deletePatMedInhospByInhospid(inhospid); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | /** |
| | | * 删除患者住院记录信息 |
| | | * |
| | | * @param inhospno 患者住院编码 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int dealOupHospInfo() { |
| | | //获取长期模板 |
| | | IvrLibaTemplate ivrTemp = new IvrLibaTemplate(); |
| | | ivrTemp.setDelFlag("0"); |
| | | ivrTemp.setLongTemp(1); |
| | | List<IvrLibaTemplate> ivrLibaTemplates = ivrLibaTemplateMapper.selectIvrLibaTemplateList(ivrTemp); |
| | | public int deletePatMedInhospByInhospno(String inhospno) { |
| | | return patMedInhospMapper.deletePatMedInhospByInhospno(inhospno); |
| | | } |
| | | |
| | | if (CollectionUtils.isNotEmpty(ivrLibaTemplates)) { |
| | | for (IvrLibaTemplate ivrLibaTemplate : ivrLibaTemplates) { |
| | | //获取到任务模板信息 |
| | | IvrTaskTemplate ivrTaskTemplate = new IvrTaskTemplate(); |
| | | ivrTaskTemplate.setLibtemplateid(ivrLibaTemplate.getId().toString()); |
| | | List<IvrTaskTemplate> ivrTaskTemplates = ivrTaskTemplateMapper.selectIvrTaskTemplateList(ivrTaskTemplate); |
| | | if (CollectionUtils.isNotEmpty(ivrTaskTemplates)) { |
| | | IvrTaskTemplate ivrTaskTemplate1 = ivrTaskTemplates.get(0); |
| | | //通过任务模板ID获取任务 |
| | | ServiceTask ServiceTask = new ServiceTask(); |
| | | ServiceTask.setTemplateid(ivrTaskTemplate1.getId()); |
| | | List<ServiceTask> serviceTasks = serviceTaskMapper.selectServiceTaskList(ServiceTask); |
| | | if (CollectionUtils.isNotEmpty(serviceTasks)) { |
| | | serviceTaskList.add(serviceTasks.get(0)); |
| | | } |
| | | ivrTaskTemplates.add(ivrTaskTemplate1); |
| | | } |
| | | libaTemplates.add(ivrLibaTemplate); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int dealOutHospInfo() { |
| | | PatMedInhosp patMedInhosp = new PatMedInhosp(); |
| | | //获取未处理的数据 |
| | | patMedInhosp.setCheckFlag("0"); |
| | | patMedInhosp.setInhospstate("1"); |
| | | List<PatMedInhosp> patMedInhosps = patMedInhospMapper.selectPatMedInhospList(patMedInhosp); |
| | | |
| | | for (PatMedInhosp patMedInhosp1 : patMedInhosps) { |
| | | //根据患者所在科室,获取该科室的长期任务模板 |
| | | Long taskid = null; |
| | | //通过deptCode获取关联的长期任务模板 |
| | | TemplateDept templateDept = new TemplateDept(); |
| | | templateDept.setDeptCode(patMedInhosp1.getLeaveldeptcode()); |
| | | templateDept.setLongTemp(1); |
| | | templateDept.setType(11L); |
| | | List<TemplateDept> templateDepts = templateDeptMapper.selectTemplateDeptList(templateDept); |
| | | //根据获取的长期任务模板ID,获取任务模板详情 |
| | | List<SvyTaskTemplate> svyTaskTemplates = new ArrayList<>(); |
| | | if (CollectionUtils.isNotEmpty(templateDepts)) { |
| | | for (TemplateDept templateDept1 : templateDepts) { |
| | | SvyTaskTemplate svyTaskTemplate = svyTaskTemplateMapper.selectSvyTaskTemplateBySvyid(templateDept1.getTempid()); |
| | | if (ObjectUtils.isNotEmpty(svyTaskTemplate)) svyTaskTemplates.add(svyTaskTemplate); |
| | | } |
| | | } |
| | | //如果部门模板为空(暂定,将出入院表的check_flag设置为2 ,long_task_reason 记录原因) |
| | | if (CollectionUtils.isEmpty(svyTaskTemplates) || svyTaskTemplates.size() == 0) { |
| | | patMedInhosp1.setCheckFlag("2"); |
| | | patMedInhosp1.setLongTaskReason("该患者所在科室,未配置任务模板"); |
| | | patMedInhospMapper.updatePatMedInhosp(patMedInhosp1); |
| | | continue; |
| | | } |
| | | |
| | | //获取患者信息 |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedInhosp1.getPatid()); |
| | | //通过icd10code去获取相应的ivr_liba_template_id |
| | | if (StringUtils.isNotEmpty(patMedInhosp1.getIcd10code())) { |
| | | for (IvrLibaTemplate ivrLibaTemplate : libaTemplates) { |
| | | String icdCode = patMedInhosp1.getIcd10code().split(",")[0]; |
| | | if (ivrLibaTemplate.getIcd10code().equals(icdCode)) { |
| | | //通过模板ID获取任务模板 |
| | | for (IvrTaskTemplate ivrTaskTemplate : ivrTaskTemplates) { |
| | | if (ivrTaskTemplate.getLibtemplateid().equals(ivrLibaTemplate.getId().toString())) { |
| | | for (ServiceTask serviceTask : serviceTaskList) { |
| | | if (serviceTask.getTemplateid() == ivrTaskTemplate.getId()) { |
| | | //将该患者,插入到子任务表中 |
| | | ServiceSubtask serviceSubtask = DtoConversionUtils.sourceToTarget(serviceTask, ServiceSubtask.class); |
| | | serviceSubtask.setId(null); |
| | | serviceSubtask.setTaskid(serviceTask.getTaskid()); |
| | | serviceSubtask.setLibtemplateid(ivrLibaTemplate.getId()); |
| | | serviceSubtask.setTemplateid(ivrTaskTemplate.getId()); |
| | | serviceSubtask.setTemplatename(ivrLibaTemplate.getTemplateName()); |
| | | serviceSubtask.setPatid(patMedInhosp1.getPatid()); |
| | | serviceSubtask.setSendname(patMedInhosp1.getPatname()); |
| | | serviceSubtask.setPhone(patArchive.getTelcode()); |
| | | serviceSubtask.setSex(patArchive.getSex()); |
| | | serviceSubtask.setAge(patArchive.getAge()); |
| | | serviceSubtask.setSendstate(2L); |
| | | serviceSubtask.setServiceform(serviceTask.getPreachform()); |
| | | serviceSubtask.setHospType("2"); |
| | | //患者发送时间 |
| | | LocalDate currentDate = LocalDate.now(); |
| | | LocalDate newDate = currentDate.plusDays(ivrTaskTemplate.getSendDay()); |
| | | serviceSubtask.setLongSendTime(Date.from(newDate.atStartOfDay(ZoneOffset.ofHours(8)).toInstant())); |
| | | serviceSubtaskMapper.insertServiceSubtask(serviceSubtask); |
| | | //将check_flag改成1(已处理) |
| | | PatMedInhosp patMedInhosp2 = new PatMedInhosp(); |
| | | patMedInhosp2.setInhospid(patMedInhosp1.getInhospid()); |
| | | patMedInhosp2.setCheckFlag("1"); |
| | | patMedInhospMapper.updatePatMedInhosp(patMedInhosp2); |
| | | } |
| | | //给个remark(用来做是否要给发送时间标识) |
| | | String remark = null; |
| | | //定义一个模板变量,用与临时保存一下找出来的模板 |
| | | SvyTaskTemplate stt = null; |
| | | if (CollectionUtils.isNotEmpty(svyTaskTemplates) && svyTaskTemplates.size() == 1) { |
| | | stt = svyTaskTemplates.get(0); |
| | | taskid = svyTaskTemplates.get(0).getTaskid(); |
| | | |
| | | } else if (CollectionUtils.isNotEmpty(svyTaskTemplates) && svyTaskTemplates.size() > 1) { |
| | | //通过患者的疾病去找模板 |
| | | if (StringUtils.isNotEmpty(patMedInhosp1.getIcd10code())) { |
| | | aa: |
| | | for (SvyTaskTemplate svyTaskTemplate1 : svyTaskTemplates) { |
| | | //通过基础模板ID获取关联的疾病code |
| | | Icd10Association icd10Association = new Icd10Association(); |
| | | icd10Association.setType(5L); |
| | | icd10Association.setOutid(svyTaskTemplate1.getTemplateid()); |
| | | List<Icd10Association> icd10Associations = icd10AssociationMapper.selectIcd10AssociationList(icd10Association); |
| | | if (CollectionUtils.isEmpty(icd10Associations)) { |
| | | //如能模板的疾病为空,则是本科室的通用默认模板 |
| | | stt = svyTaskTemplate1; |
| | | taskid = stt.getTaskid(); |
| | | continue; |
| | | } else { |
| | | //如能模板的疾病不为空,则是用匹配到疾病的模板(如果匹配出来多个模板,只用第一个) |
| | | for (Icd10Association icd10Association1 : icd10Associations) { |
| | | if (patMedInhosp1.getIcd10code().equals(icd10Association1.getIcd10code())) { |
| | | stt = svyTaskTemplate1; |
| | | taskid = stt.getTaskid(); |
| | | break aa; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //如果循环完,stt还是为空,则该科室没有默认模板 |
| | | if (Objects.isNull(stt)) { |
| | | //在出入院表记录一下该患者状态(该科室没有模板,所以无法在子任务里生成任务,所以任务是失败是的,chect_flag=2) |
| | | patMedInhosp1.setCheckFlag("2"); |
| | | patMedInhosp1.setLongTaskReason("无法匹配到该科室模板,该科室也无默认模板"); |
| | | patMedInhospMapper.updatePatMedInhosp(patMedInhosp1); |
| | | continue; |
| | | } |
| | | } else { |
| | | //为空的话,直接用科室的通用模板的任务ID,该患者直接往子任务表里插入,但不要执行,需要人工干(将不能执行的原因备注好) |
| | | for (SvyTaskTemplate svyTaskTemplate1 : svyTaskTemplates) { |
| | | //通过基础模板ID获取关联的疾病code |
| | | Icd10Association icd10Association = new Icd10Association(); |
| | | icd10Association.setType(5L); |
| | | icd10Association.setOutid(svyTaskTemplate1.getTemplateid()); |
| | | //找出该科室的通用模板 |
| | | List<Icd10Association> icd10Associations = icd10AssociationMapper.selectIcd10AssociationList(icd10Association); |
| | | if (CollectionUtils.isEmpty(icd10Associations)) { |
| | | stt = svyTaskTemplate1; |
| | | //不配置发送时间 |
| | | remark = "患者入院疾病为空"; |
| | | //在出入院表记录一下该患者状态(该科室是有疾病为空的模板,所以可以在子任务里生成任务,所以任务是成功的,chect_flag=1) |
| | | patMedInhosp1.setCheckFlag("1"); |
| | | patMedInhosp1.setLongTaskReason("患者入院疾病为空,已找到科室模板"); |
| | | patMedInhospMapper.updatePatMedInhosp(patMedInhosp1); |
| | | continue; |
| | | } |
| | | } |
| | | if (Objects.isNull(stt)) { |
| | | //在出入院表记录一下该患者状态(该科室没有模板,所以无法在子任务里生成任务,所以任务是失败是的,chect_flag=2) |
| | | patMedInhosp1.setCheckFlag("2"); |
| | | patMedInhosp1.setLongTaskReason("患者入院疾病为空,未找到科室模板"); |
| | | patMedInhospMapper.updatePatMedInhosp(patMedInhosp1); |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | |
| | | ServiceTask serviceTask = serviceTaskMapper.selectServiceTaskByTaskid(taskid); |
| | | ServiceSubtask serviceSubtask = DtoConversionUtils.sourceToTarget(serviceTask, ServiceSubtask.class); |
| | | serviceSubtask.setTaskid(serviceTask.getTaskid()); |
| | | serviceSubtask.setLibtemplateid(stt.getTemplateid()); |
| | | serviceSubtask.setNurseId(patMedInhosp1.getNurseId()); |
| | | serviceSubtask.setNurseName(patMedInhosp1.getNurseName()); |
| | | serviceSubtask.setDrcode(patMedInhosp1.getDrcode()); |
| | | serviceSubtask.setDrname(patMedInhosp1.getDrname()); |
| | | serviceSubtask.setDeptname(patMedInhosp1.getLeaveldeptname()); |
| | | serviceSubtask.setTemplateid(stt.getId()); |
| | | serviceSubtask.setTemplatename(stt.getSvyname()); |
| | | serviceSubtask.setPatid(patArchive.getId()); |
| | | serviceSubtask.setSendname(patArchive.getName()); |
| | | serviceSubtask.setSfzh(patArchive.getIdcardno()); |
| | | serviceSubtask.setPhone(patArchive.getTelcode()); |
| | | serviceSubtask.setSex(patArchive.getSex()); |
| | | serviceSubtask.setAge(patArchive.getAge()); |
| | | serviceSubtask.setSendstate(2L); |
| | | serviceSubtask.setStarttime(patMedInhosp1.getStarttime()); |
| | | serviceSubtask.setEndtime(patMedInhosp1.getEndtime()); |
| | | serviceSubtask.setServiceType("2"); |
| | | serviceSubtask.setServiceform(serviceTask.getPreachform()); |
| | | serviceSubtask.setHospType("2"); |
| | | serviceSubtask.setCreateTime(new Date()); |
| | | serviceSubtask.setUpdateTime(new Date()); |
| | | serviceSubtask.setCreateBy(patMedInhosp1.getNurseName()); |
| | | serviceSubtask.setLeavehospitaldistrictcode(patMedInhosp1.getLeavehospitaldistrictcode()); |
| | | serviceSubtask.setLeavehospitaldistrictname(patMedInhosp1.getLeavehospitaldistrictname()); |
| | | //设置发送时间 |
| | | Date newDate = addDays(patMedInhosp1.getEndtime(), stt.getSendDay()); |
| | | serviceSubtask.setLongSendTime(newDate); |
| | | //患者发送时间 |
| | | if (StringUtils.isNotEmpty(patArchive.getNotrequiredFlag()) && patArchive.getNotrequiredFlag().equals("1")) { |
| | | remark = patArchive.getNotrequiredreason(); |
| | | serviceSubtask.setRemark(remark); |
| | | serviceSubtask.setResult("error"); |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | //不执行 |
| | | serviceSubtask.setSendstate(4L); |
| | | } |
| | | |
| | | //在新增之前,先通过患者ID,sendstate=2查询一下,在所有长期任务中,是不是还有该患者待执行的任务,有的话,比较之前的endtime是否小于当前的endtaime,如果之前的小于现在的,则直接将之前的停掉(原因再入院) |
| | | ServiceSubtaskVO subtask = new ServiceSubtaskVO(); |
| | | subtask.setPatid(patArchive.getId()); |
| | | subtask.setSendstate(2L); |
| | | List<ServiceSubtask> selectServiceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(subtask); |
| | | log.error("该患者待执行的任务:{}", selectServiceSubtaskList); |
| | | if (CollectionUtils.isNotEmpty(selectServiceSubtaskList) && selectServiceSubtaskList.size() > 0) { |
| | | for (ServiceSubtask serviceSubtask1 : selectServiceSubtaskList) { |
| | | if (Objects.isNull(serviceSubtask1.getLongSendTime())) { |
| | | //不是长期任务,不处理 |
| | | continue; |
| | | } |
| | | if (serviceSubtask1.getEndtime().before(serviceSubtask.getEndtime())) { |
| | | //如果当前循环的子任务的出院时间在“准备新增的子任务”的出院时间之前,则将循环的子任务停掉 |
| | | serviceSubtask1.setSendstate(4L); |
| | | serviceSubtask1.setRemark("患者再入院"); |
| | | serviceSubtask1.setResult("error"); |
| | | serviceSubtask1.setFinishtime(new Date()); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask1); |
| | | } else { |
| | | //相反,则将当有的数据停掉 |
| | | serviceSubtask.setResult("error"); |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | serviceSubtask.setSendstate(4L); |
| | | serviceSubtask.setRemark("患者再入院"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | serviceSubtaskMapper.insertServiceSubtask(serviceSubtask); |
| | | //将check_flag改成1(已处理) |
| | | PatMedInhosp patMedInhosp2 = new PatMedInhosp(); |
| | | patMedInhosp2.setInhospid(patMedInhosp1.getInhospid()); |
| | | patMedInhosp2.setCheckFlag("1"); |
| | | patMedInhospMapper.updatePatMedInhosp(patMedInhosp2); |
| | | } |
| | | |
| | | //获取未处理在院的数据(如果刚刚出院的患者数据的出院时间,在下面查询出的入院时间之前,那之前的出院患者的数据,也得停掉,因为又入院了) |
| | | patMedInhosp.setCheckFlag("0"); |
| | | patMedInhosp.setInhospstate("0"); |
| | | List<PatMedInhosp> patMedInhospList = patMedInhospMapper.selectPatMedInhospList(patMedInhosp); |
| | | if (CollectionUtils.isNotEmpty(patMedInhospList) && patMedInhospList.size() > 0) { |
| | | for (PatMedInhosp patMedInhosp1 : patMedInhospList) { |
| | | //获取当前入院患者的待执行的出院子任务随访信息 |
| | | ServiceSubtaskVO subtask = new ServiceSubtaskVO(); |
| | | subtask.setPatid(patMedInhosp1.getPatid()); |
| | | subtask.setSendstate(2L); |
| | | List<ServiceSubtask> selectServiceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(subtask); |
| | | log.error("入院的患者待执行的任务:{}", selectServiceSubtaskList); |
| | | if (CollectionUtils.isNotEmpty(selectServiceSubtaskList) && selectServiceSubtaskList.size() > 0) { |
| | | for (ServiceSubtask serviceSubtask1 : selectServiceSubtaskList) { |
| | | if (Objects.isNull(serviceSubtask1.getLongSendTime())) { |
| | | //不是长期任务,不处理 |
| | | continue; |
| | | } |
| | | if (serviceSubtask1.getEndtime().before(patMedInhosp1.getStarttime())) { |
| | | //如果当前循环的子任务的出院时间在“准备新增的子任务”的出院时间之前,则将循环的子任务停掉 |
| | | serviceSubtask1.setSendstate(4L); |
| | | serviceSubtask1.setRemark("患者再入院"); |
| | | serviceSubtask1.setResult("error"); |
| | | serviceSubtask1.setFinishtime(new Date()); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask1); |
| | | } |
| | | } |
| | | } |
| | | //将患入的入院数据设置为已处理 |
| | | patMedInhosp1.setCheckFlag("1"); |
| | | patMedInhospMapper.updatePatMedInhosp(patMedInhosp1); |
| | | } |
| | | } |
| | | |
| | | return 1; |
| | | } |
| | | |
| | |
| | | return patMedInhospMapper.getDeptRanking(patMedReq); |
| | | } |
| | | |
| | | private Date addDays(Date date, Integer days) { |
| | | if (days == null) { |
| | | days = 1; |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(date); |
| | | calendar.add(Calendar.DAY_OF_MONTH, days); |
| | | return calendar.getTime(); |
| | | } |
| | | |
| | | } |