| | |
| | | package com.smartor.service.impl; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.Period; |
| | | import java.time.ZoneId; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | |
| | | import com.smartor.domain.*; |
| | | import com.smartor.mapper.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.smartor.service.IPatMedOuthospService; |
| | |
| | | @Override |
| | | public List<PatMedOuthosp> selectPatMedOuthospList(PatMedOuthosp patMedOuthosp) { |
| | | List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.selectPatMedOuthospList(patMedOuthosp); |
| | | for (PatMedOuthosp patMedOuthosp1 : patMedOuthosps) { |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp1.getPatid()); |
| | | if (patArchive.getBirthdate() != null) { |
| | | Map<String, String> map = calculateAge(patArchive.getBirthdate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), LocalDate.now()); |
| | | patArchive.setAge(ObjectUtils.isNotEmpty(map.get("age")) ? Long.valueOf(map.get("age")) : null); |
| | | patArchive.setAgeUnit(map.get("ageUnit")); |
| | | patArchive.setAge2(ObjectUtils.isNotEmpty(map.get("age2")) ? Long.valueOf(map.get("age2")) : null); |
| | | patArchive.setAgeUnit2(map.get("ageUnit2")); |
| | | patMedOuthosp1.setAge(patArchive.getAge() + patArchive.getAgeUnit() + patArchive.getAge2() + patArchive.getAgeUnit2()); |
| | | patMedOuthosp1.setTelcode(patArchive.getTelcode()); |
| | | patMedOuthosp1.setIdcardno(patArchive.getIdcardno()); |
| | | } |
| | | } |
| | | return patMedOuthosps; |
| | | } |
| | | |
| | | public Map<String, String> calculateAge(LocalDate birthdate, LocalDate today) { |
| | | if (birthdate == null || today.isBefore(birthdate)) { |
| | | return null; |
| | | } |
| | | Map<String, String> ageMap = new HashMap<>(); |
| | | |
| | | Period period = Period.between(birthdate, today); |
| | | long totalDays = ChronoUnit.DAYS.between(birthdate, today); |
| | | long totalMonths = ChronoUnit.MONTHS.between(birthdate, today); |
| | | |
| | | int years = period.getYears(); |
| | | int months = period.getMonths(); |
| | | int days = period.getDays(); |
| | | |
| | | String ageUnit; |
| | | Integer age; |
| | | String ageUnit2 = null; |
| | | Integer age2 = null; |
| | | |
| | | if (totalDays < 30) { |
| | | // 小于 1 个月,按天计算 |
| | | ageUnit = "天"; |
| | | age = (int) totalDays; |
| | | ageMap.put("age", age != null ? age.toString() : null); |
| | | ageMap.put("ageUnit", ageUnit); |
| | | ageMap.put("age2", null); |
| | | ageMap.put("ageUnit2", null); |
| | | } else if (totalMonths < 12) { |
| | | // 小于 一年,按月 + 天计算 |
| | | ageUnit = "月"; |
| | | age = (int) totalMonths; |
| | | ageUnit2 = "天"; |
| | | age2 = days; |
| | | ageMap.put("age", age != null ? age.toString() : null); |
| | | ageMap.put("ageUnit", ageUnit); |
| | | ageMap.put("age2", age2 != null ? age2.toString() : null); |
| | | ageMap.put("ageUnit2", ageUnit2); |
| | | } else { |
| | | // 大于等于 一年,按年 + 月计算 |
| | | ageUnit = "岁"; |
| | | age = years; |
| | | ageUnit2 = "月"; |
| | | age2 = months; |
| | | ageMap.put("age", age != null ? age.toString() : null); |
| | | ageMap.put("ageUnit", ageUnit); |
| | | ageMap.put("age2", age2 != null ? age2.toString() : null); |
| | | ageMap.put("ageUnit2", ageUnit2); |
| | | } |
| | | |
| | | return ageMap; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | @Override |
| | | public PatMedRes selectPatMedOuthospCount(PatMedReq patMedReq) { |
| | | // 获取当前登陆人的部门权限 |
| | | if (CollectionUtils.isEmpty(patMedReq.getDeptcodeList())) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | List<SysDept> sysDepts = sysUserDeptMapper.selectDeptListByUserId(userId); |
| | | List<String> deptCode = new ArrayList<>(); |
| | | for (SysDept sysDept : sysDepts) { |
| | | deptCode.add(sysDept.getDeptId().toString()); |
| | | } |
| | | patMedReq.setDeptcodeList(deptCode); |
| | | } |
| | | // // 获取当前登陆人的部门权限 |
| | | // if (CollectionUtils.isEmpty(patMedReq.getDeptcodeList())) { |
| | | // Long userId = SecurityUtils.getUserId(); |
| | | // List<SysDept> sysDepts = sysUserDeptMapper.selectDeptListByUserId(userId); |
| | | // List<String> deptCode = new ArrayList<>(); |
| | | // for (SysDept sysDept : sysDepts) { |
| | | // deptCode.add(sysDept.getDeptId().toString()); |
| | | // } |
| | | // patMedReq.setDeptcodeList(deptCode); |
| | | // } |
| | | return patMedOuthospMapper.selectPatMedOuthospCount(patMedReq); |
| | | } |
| | | |
| | |
| | | patMedOuthosp.setDiagcheckFlag("0"); |
| | | List<PatMedOuthosp> patMedOuthosps = selectPatMedOuthospList(patMedOuthosp); |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 根据患者的疾病,获取该疾病的长期任务 |
| | | ServiceTaskdiag serviceTaskdiag = new ServiceTaskdiag(); |
| | | serviceTaskdiag.setLongtask(1L); |
| | | serviceTaskdiag.setIcd10code(patMedOuthosp1.getIcd10code()); |
| | | List<ServiceTaskdiag> serviceTaskdiags = serviceTaskdiagMapper.selectServiceTaskdiagList(serviceTaskdiag); |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp1.getPatid()); |
| | | //如果部门模板为空(将deptIsNull设置为true) |
| | | if (org.apache.commons.collections4.CollectionUtils.isEmpty(serviceTaskdiags) || serviceTaskdiags.size() == 0) { |
| | | patMedOuthosp1.setDiagcheckFlag("2"); |
| | |
| | | serviceSubtask1.setSendstate(4L); |
| | | serviceSubtask1.setRemark("疾病患者再入院"); |
| | | serviceSubtask1.setResult("error"); |
| | | serviceSubtask1.setFinishtime(new Date()); |
| | | // serviceSubtask1.setFinishtime(new Date()); |
| | | serviceSubtask1.setUpdateBy(serviceTask.getUpdateBy()); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask1); |
| | | //重新新增子任务 |
| | |
| | | serviceSubtask.setRemark("手机号为空"); |
| | | serviceSubtask.setSendstate(4L); |
| | | serviceSubtask.setResult("error"); |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | // serviceSubtask.setFinishtime(new Date()); |
| | | } |
| | | serviceSubtask.setCreateBy(serviceTask.getCreateBy()); |
| | | serviceSubtask.setCreateTime(new Date()); |
| | |
| | | serviceSubtask.setRemark("手机号为空"); |
| | | serviceSubtask.setSendstate(4L); |
| | | serviceSubtask.setResult("error"); |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | // serviceSubtask.setFinishtime(new Date()); |
| | | |
| | | } |
| | | serviceSubtask.setCreateBy(serviceTask.getCreateBy()); |
| | |
| | | serviceSubtask.setPatid(patArchive.getId()); |
| | | serviceSubtask.setSendname(patArchive.getName()); |
| | | serviceSubtask.setSfzh(patArchive.getIdcardno()); |
| | | serviceSubtask.setLeavediagname(patMedOuthosp.getDiagname()); |
| | | serviceSubtask.setLeaveicd10code(patMedOuthosp.getIcd10code()); |
| | | serviceSubtask.setSfzh(patArchive.getIdcardno()); |
| | | serviceSubtask.setPhone(patArchive.getTelcode()); |
| | | if (StringUtils.isBlank(patArchive.getTelcode())) serviceSubtask.setPhone(patArchive.getRelativetelcode()); |
| | | serviceSubtask.setSex(patArchive.getSex()); |
| | |
| | | serviceSubtask.setUpdateTime(new Date()); |
| | | serviceSubtask.setUpdateBy(serviceTask.getUpdateBy()); |
| | | serviceSubtask.setUpdateTime(new Date()); |
| | | serviceSubtask.setVisitDeptCode(patMedOuthosp.getDeptcode()); |
| | | serviceSubtask.setVisitDeptName(patMedOuthosp.getDeptname()); |
| | | serviceSubtask.setUpdateTime(new Date()); |
| | | //设置发送时间 |
| | | if (serviceTask.getSendDay() == null) serviceTask.setSendDay(1L); |
| | | Date newDate = addDays(patMedOuthosp.getAdmitdate(), serviceTask.getSendDay().intValue()); |
| | | if (patMedOuthosp.getFudate() != null) { |
| | | //如果门诊表有指定随访时间,那就用指定的 |
| | | newDate = patMedOuthosp.getFudate(); |
| | | } |
| | | serviceSubtask.setLongSendTime(newDate); |
| | | serviceSubtask.setVisitTime(newDate); |
| | | //患者发送时间 |
| | | if (StringUtils.isNotEmpty(patArchive.getNotrequiredFlag()) && patArchive.getNotrequiredFlag().equals("1")) { |
| | | String remark = patArchive.getNotrequiredreason(); |
| | | serviceSubtask.setRemark(remark); |
| | | serviceSubtask.setResult("error"); |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | // serviceSubtask.setFinishtime(new Date()); |
| | | //不执行 |
| | | serviceSubtask.setSendstate(4L); |
| | | } |