liusheng
5 天以前 6659135780e718758417efde4c8c351c69e3755b
smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java
@@ -17,6 +17,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.smartor.service.IPatMedOuthospService;
import org.springframework.util.CollectionUtils;
@@ -46,6 +47,9 @@
    private ServiceTaskdiagMapper serviceTaskdiagMapper;
    @Autowired
    private ServiceTaskdeptMapper serviceTaskdeptMapper;
    @Autowired
    private PatArchiveMapper patArchiveMapper;
@@ -67,6 +71,7 @@
     * @return 患者门诊记录
     */
    @Override
    @Cacheable(value = "selectPatMedOuthospList", key = "T(org.springframework.util.DigestUtils).md5DigestAsHex(#patMedOuthosp.toString().getBytes())", unless = "#result == null or #result.isEmpty()")
    public List<PatMedOuthosp> selectPatMedOuthospList(PatMedOuthosp patMedOuthosp) {
        List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.selectPatMedOuthospList(patMedOuthosp);
        for (PatMedOuthosp patMedOuthosp1 : patMedOuthosps) {
@@ -81,6 +86,16 @@
                patMedOuthosp1.setTelcode(patArchive.getTelcode());
                patMedOuthosp1.setIdcardno(patArchive.getIdcardno());
            }
            ServiceSubtaskVO serviceSubtaskVO = new ServiceSubtaskVO();
            serviceSubtaskVO.setPatid(patMedOuthosp1.getPatid());
            List<Long> sendstates = new ArrayList<>();
            sendstates.add(1L);
            sendstates.add(2L);
            sendstates.add(3L);
            serviceSubtaskVO.setSendstates(sendstates);
            serviceSubtaskVO.setServiceType("3");
            List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskBySendstate(serviceSubtaskVO);
            if (!CollectionUtils.isEmpty(serviceSubtaskList)) patMedOuthosp1.setServerState("1");
        }
        return patMedOuthosps;
    }
@@ -221,21 +236,19 @@
        for (PatMedOuthosp patMedOuthosp1 : patMedOuthosps) {
            PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp1.getPatid());
            //该患者有可能提前来复诊了,那他后面的本科室的通知就可以不用再发短信了
            ServiceSubtaskVO serviceSubtaskVO = new ServiceSubtaskVO();
            if (StringUtils.isNotEmpty(patMedOuthosp1.getDeptcode())) {
                serviceSubtaskVO.setDeptcode(patMedOuthosp1.getDeptcode());
                serviceSubtaskVO.setSfzh(patArchive.getIdcardno());
                serviceSubtaskVO.setType("3");
                serviceSubtaskVO.setSendstate(2L);
                serviceSubtaskVO.setPreachform("4");
                List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO);
                if (!CollectionUtils.isEmpty(serviceSubtaskList)) {
                    for (ServiceSubtask serviceSubtask : serviceSubtaskList) {
                        serviceSubtask.setSendstate(6L);
                        serviceSubtask.setRemark("已回来复诊,无需再进行短信通知");
                        serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
                    }
            //根据患者科室,获取该疾病的长期任务
            ServiceTaskdept serviceTaskdept = new ServiceTaskdept();
            serviceTaskdept.setLongtask(1L);
            serviceTaskdept.setDeptCode(patMedOuthosp1.getDeptcode());
            serviceTaskdept.setServiceType("3");
            List<ServiceTaskdept> serviceTaskdeptList = serviceTaskdeptMapper.selectServiceTaskdeptList(serviceTaskdept);
            if (org.apache.commons.collections4.CollectionUtils.isEmpty(serviceTaskdeptList) || serviceTaskdeptList.size() == 0) {
                patMedOuthosp1.setDeptcheckFlag("2");
                patMedOuthosp1.setRemark("通过部门,没有找到门诊随访任务ID");
                patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp1);
            } else {
                for (ServiceTaskdept serviceTaskdept1 : serviceTaskdeptList) {
                    writeInSubTask(serviceTaskdept1.getTaskId(), true, patMedOuthosp1, patArchive, 1);
                }
            }
@@ -247,11 +260,11 @@
            //如果部门模板为空(将deptIsNull设置为true)
            if (org.apache.commons.collections4.CollectionUtils.isEmpty(serviceTaskdiags) || serviceTaskdiags.size() == 0) {
                patMedOuthosp1.setDiagcheckFlag("2");
                patMedOuthosp1.setRemark("通过icd10,没有找到随访任务ID");
                patMedOuthosp1.setRemark("通过icd10,没有找到门诊随访任务ID");
                patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp1);
            } else {
                for (ServiceTaskdiag serviceTaskdept1 : serviceTaskdiags) {
                    writeInSubTask(serviceTaskdept1.getTaskId(), true, patMedOuthosp1, patArchive);
                    writeInSubTask(serviceTaskdept1.getTaskId(), true, patMedOuthosp1, patArchive, 2);
                }
            }
@@ -259,16 +272,24 @@
        return 1;
    }
    private void writeInSubTask(Long taskid, Boolean check, PatMedOuthosp patMedOuthosp, PatArchive patArchive) {
    /**
     * @param taskid
     * @param check
     * @param patMedOuthosp
     * @param patArchive
     * @param type          1 科室 2 疾病
     */
    private void writeInSubTask(Long taskid, Boolean check, PatMedOuthosp patMedOuthosp, PatArchive patArchive, Integer type) {
        ServiceTask st = new ServiceTask();
        st.setTaskid(taskid);
        st.setSendState(2L);
        List<ServiceTask> serviceTasks = serviceTaskMapper.selectServiceTaskList(st);
        if (org.apache.commons.collections4.CollectionUtils.isEmpty(serviceTasks)) {
            log.error("该患者疾病随访长期任务不存在,任务ID为:{}", taskid);
            patMedOuthosp.setDiagcheckFlag("2");
            patMedOuthosp.setRemark("该患者疾病随访长期任务不存在,任务ID为:" + taskid);
            log.info("该患者疾病随访长期任务不存在,任务ID为:{}", taskid);
            if (type == 1) patMedOuthosp.setDiagcheckFlag("2");
            if (type == 2) patMedOuthosp.setDeptcheckFlag("2");
            patMedOuthosp.setRemark("该患者门诊随访长期任务不存在,任务ID为:" + taskid);
            patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp);
            return;
        }
@@ -284,7 +305,7 @@
            subtask.setSendstate(2L);
            subtask.setTaskid(taskid);
            List<ServiceSubtask> selectServiceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(subtask);
            log.error("该患者待执行的任务:{}", CollectionUtils.isEmpty(selectServiceSubtaskList) ? null : selectServiceSubtaskList.size());
            log.info("该患者待执行的任务:{}", CollectionUtils.isEmpty(selectServiceSubtaskList) ? null : selectServiceSubtaskList.size());
            if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(selectServiceSubtaskList) && selectServiceSubtaskList.size() > 0) {
                for (ServiceSubtask serviceSubtask1 : selectServiceSubtaskList) {
                    if (Objects.isNull(serviceSubtask1.getLongSendTime())) {
@@ -293,15 +314,14 @@
                    }
                    //将之前的停掉
                    serviceSubtask1.setSendstate(4L);
                    serviceSubtask1.setRemark("疾病患者再入院");
                    serviceSubtask1.setResult("error");
//                    serviceSubtask1.setFinishtime(new Date());
                    serviceSubtask1.setSendstate(6L);
                    serviceSubtask1.setRemark("患者已经回院复诊");
                    serviceSubtask1.setResult("success");
                    serviceSubtask1.setFinishtime(new Date());
                    serviceSubtask1.setUpdateBy(serviceTask.getUpdateBy());
                    serviceSubtaskMapper.updateServiceSubtask(serviceSubtask1);
                    //重新新增子任务
                    i = serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
                }
            } else {
                if (StringUtils.isEmpty(serviceSubtask.getPhone())) {
@@ -330,14 +350,16 @@
            //将check_flag改成1(已处理)
            PatMedOuthosp patMedOuthosp1 = new PatMedOuthosp();
            patMedOuthosp1.setId(patMedOuthosp.getId());
            patMedOuthosp1.setDiagcheckFlag("1");
            if (type == 1) patMedOuthosp1.setDiagcheckFlag("2");
            if (type == 2) patMedOuthosp1.setDeptcheckFlag("2");
            patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp1);
        } else {
            //生成子任务失败,
            log.error("生成子任务失败serviceSubtask的taskid为:{},patid为:{}", serviceSubtask.getTaskid(), serviceSubtask.getPatid());
            log.info("生成子任务失败serviceSubtask的taskid为:{},patid为:{}", serviceSubtask.getTaskid(), serviceSubtask.getPatid());
            PatMedOuthosp pmo = new PatMedOuthosp();
            pmo.setId(patMedOuthosp.getId());
            pmo.setDiagcheckFlag("2");
            if (type == 1) pmo.setDiagcheckFlag("2");
            if (type == 2) pmo.setDeptcheckFlag("2");
            pmo.setRemark("生成子任务失败");
            patMedOuthospMapper.updatePatMedOuthosp(pmo);
        }
@@ -352,6 +374,8 @@
        serviceSubtask.setDrcode(patMedOuthosp.getDrcode());
        serviceSubtask.setDrname(patMedOuthosp.getDrname());
        serviceSubtask.setDeptcode(patMedOuthosp.getDeptcode());
        serviceSubtask.setInhospid(patMedOuthosp.getId());
        serviceSubtask.setHospno(patMedOuthosp.getOuthospno());
        serviceSubtask.setDeptname(patMedOuthosp.getDeptname());
        serviceSubtask.setTemplateid(serviceTask.getTemplateid());
        serviceSubtask.setTemplatename(serviceTask.getTemplatename());