| | |
| | | package com.smartor.service.impl; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneOffset; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.DtoConversionUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.mapper.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import com.smartor.mapper.PatMedInhospMapper; |
| | | import com.smartor.domain.PatMedInhosp; |
| | | import com.smartor.service.IPatMedInhospService; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * 患者住院记录Service业务层处理 |
| | |
| | | * @author smartor |
| | | * @date 2023-03-04 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class PatMedInhospServiceImpl implements IPatMedInhospService |
| | | { |
| | | public class PatMedInhospServiceImpl implements IPatMedInhospService { |
| | | @Autowired |
| | | private PatMedInhospMapper patMedInhospMapper; |
| | | |
| | | @Autowired |
| | | private PatArchiveMapper patArchiveMapper; |
| | | |
| | | @Autowired |
| | | private IvrLibaTemplateMapper ivrLibaTemplateMapper; |
| | | |
| | | @Autowired |
| | | private IvrTaskTemplateMapper ivrTaskTemplateMapper; |
| | | |
| | | @Autowired |
| | | private ServiceTaskMapper serviceTaskMapper; |
| | | |
| | | @Autowired |
| | | private ServiceSubtaskMapper serviceSubtaskMapper; |
| | | |
| | | //记录长期任务基础信息 |
| | | List<IvrLibaTemplate> libaTemplates = new ArrayList<>(); |
| | | List<IvrTaskTemplate> ivrTaskTemplates = new ArrayList<>(); |
| | | List<ServiceTask> serviceTaskList = new ArrayList<>(); |
| | | |
| | | /** |
| | | * 查询患者住院记录 |
| | |
| | | * @return 患者住院记录 |
| | | */ |
| | | @Override |
| | | public PatMedInhosp selectPatMedInhospByInhospid(Long inhospid) |
| | | { |
| | | public PatMedInhosp selectPatMedInhospByInhospid(Long inhospid) { |
| | | return patMedInhospMapper.selectPatMedInhospByInhospid(inhospid); |
| | | } |
| | | |
| | |
| | | * @return 患者住院记录 |
| | | */ |
| | | @Override |
| | | public List<PatMedInhosp> selectPatMedInhospList(PatMedInhosp patMedInhosp) |
| | | { |
| | | public List<PatMedInhosp> selectPatMedInhospList(PatMedInhosp patMedInhosp) { |
| | | return patMedInhospMapper.selectPatMedInhospList(patMedInhosp); |
| | | } |
| | | |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertPatMedInhosp(PatMedInhosp patMedInhosp) |
| | | { |
| | | public int insertPatMedInhosp(PatMedInhosp patMedInhosp) { |
| | | patMedInhosp.setCreateTime(DateUtils.getNowDate()); |
| | | patMedInhosp.setUpdateTime(DateUtils.getNowDate()); |
| | | return patMedInhospMapper.insertPatMedInhosp(patMedInhosp); |
| | | } |
| | | |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updatePatMedInhosp(PatMedInhosp patMedInhosp) |
| | | { |
| | | public int updatePatMedInhosp(PatMedInhosp patMedInhosp) { |
| | | patMedInhosp.setUpdateTime(DateUtils.getNowDate()); |
| | | return patMedInhospMapper.updatePatMedInhosp(patMedInhosp); |
| | | } |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deletePatMedInhospByInhospids(Long[] inhospids) |
| | | { |
| | | public int deletePatMedInhospByInhospids(Long[] inhospids) { |
| | | return patMedInhospMapper.deletePatMedInhospByInhospids(inhospids); |
| | | } |
| | | |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deletePatMedInhospByInhospid(Long inhospid) |
| | | { |
| | | public int deletePatMedInhospByInhospid(Long inhospid) { |
| | | return patMedInhospMapper.deletePatMedInhospByInhospid(inhospid); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public int dealOupHospInfo() { |
| | | //获取长期模板 |
| | | IvrLibaTemplate ivrTemp = new IvrLibaTemplate(); |
| | | ivrTemp.setDelFlag("0"); |
| | | ivrTemp.setLongTemp(1); |
| | | List<IvrLibaTemplate> ivrLibaTemplates = ivrLibaTemplateMapper.selectIvrLibaTemplateList(ivrTemp); |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | PatMedInhosp patMedInhosp = new PatMedInhosp(); |
| | | //获取未处理的数据 |
| | | patMedInhosp.setCheckFlag("0"); |
| | | patMedInhosp.setInhospstate("1"); |
| | | List<PatMedInhosp> patMedInhosps = patMedInhospMapper.selectPatMedInhospList(patMedInhosp); |
| | | for (PatMedInhosp patMedInhosp1 : patMedInhosps) { |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return 1; |
| | | } |
| | | } |