From fe47ff909096722ba8e9172c3e1f0f7910b16909 Mon Sep 17 00:00:00 2001
From: sinake <sinake1@qq.com>
Date: 星期二, 21 十月 2025 14:49:18 +0800
Subject: [PATCH] 结束出院日期格式
---
smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java | 320 ++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 300 insertions(+), 20 deletions(-)
diff --git a/smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java
index 537374f..c793f11 100644
--- a/smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java
@@ -1,21 +1,23 @@
package com.smartor.service.impl;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
+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.ruoyi.common.core.domain.entity.SysUserDept;
import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.DtoConversionUtils;
import com.ruoyi.common.utils.SecurityUtils;
-import com.smartor.domain.PatMedReq;
-import com.smartor.domain.PatMedRes;
-import com.smartor.mapper.SysUserDeptMapper;
+import com.ruoyi.common.utils.StringUtils;
+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.mapper.PatMedOuthospMapper;
-import com.smartor.domain.PatMedOuthosp;
import com.smartor.service.IPatMedOuthospService;
import org.springframework.util.CollectionUtils;
@@ -25,6 +27,7 @@
* @author smartor
* @date 2023-03-04
*/
+@Slf4j
@Service
public class PatMedOuthospServiceImpl implements IPatMedOuthospService {
@Autowired
@@ -32,6 +35,18 @@
@Autowired
private SysUserDeptMapper sysUserDeptMapper;
+
+ @Autowired
+ private ServiceSubtaskMapper serviceSubtaskMapper;
+
+ @Autowired
+ private ServiceTaskMapper serviceTaskMapper;
+
+ @Autowired
+ private ServiceTaskdiagMapper serviceTaskdiagMapper;
+
+ @Autowired
+ private PatArchiveMapper patArchiveMapper;
/**
@@ -53,7 +68,73 @@
*/
@Override
public List<PatMedOuthosp> selectPatMedOuthospList(PatMedOuthosp patMedOuthosp) {
- return patMedOuthospMapper.selectPatMedOuthospList(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;
}
/**
@@ -105,16 +186,16 @@
@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);
}
@@ -126,4 +207,203 @@
}
return patMedOuthosps.get(0);
}
+
+ /**
+ * 闂ㄨ瘖鐥呬汉淇℃伅澶勭悊
+ *
+ * @return
+ */
+ @Override
+ public Integer dealOutpatientInfo() {
+ PatMedOuthosp patMedOuthosp = new PatMedOuthosp();
+ 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);
+ }
+ }
+ }
+
+ // 鏍规嵁鎮h�呯殑鐤剧梾锛岃幏鍙栬鐤剧梾鐨勯暱鏈熶换鍔�
+ ServiceTaskdiag serviceTaskdiag = new ServiceTaskdiag();
+ serviceTaskdiag.setLongtask(1L);
+ serviceTaskdiag.setIcd10code(patMedOuthosp1.getIcd10code());
+ List<ServiceTaskdiag> serviceTaskdiags = serviceTaskdiagMapper.selectServiceTaskdiagList(serviceTaskdiag);
+ //濡傛灉閮ㄩ棬妯℃澘涓虹┖锛堝皢deptIsNull璁剧疆涓簍rue锛�
+ if (org.apache.commons.collections4.CollectionUtils.isEmpty(serviceTaskdiags) || serviceTaskdiags.size() == 0) {
+ patMedOuthosp1.setDiagcheckFlag("2");
+ patMedOuthosp1.setRemark("閫氳繃icd10,娌℃湁鎵惧埌闅忚浠诲姟ID");
+ patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp1);
+ } else {
+ for (ServiceTaskdiag serviceTaskdept1 : serviceTaskdiags) {
+ writeInSubTask(serviceTaskdept1.getTaskId(), true, patMedOuthosp1, patArchive);
+ }
+ }
+
+ }
+ return 1;
+ }
+
+ private void writeInSubTask(Long taskid, Boolean check, PatMedOuthosp patMedOuthosp, PatArchive patArchive) {
+
+ 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);
+ patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp);
+ return;
+ }
+ ServiceTask serviceTask = serviceTasks.get(0);
+ //灏佽serviceSubtask
+ ServiceSubtask serviceSubtask = boxedServiceSubtask(serviceTask, patMedOuthosp, patArchive);
+ Integer i = 0;
+ //鍏堝垽鏂竴涓嬶紝鏄惁闇�瑕佹牎楠�
+ if (check) {
+ //鍦ㄦ柊澧炰箣鍓嶏紝鍏堥�氳繃鎮h�匢D锛宻endstate=2鏌ヨ涓�涓嬶紝鍦ㄦ墍鏈夐暱鏈熶换鍔′腑锛屾槸涓嶆槸杩樻湁璇ユ偅鑰呭緟鎵ц鐨勪换鍔★紝鏈夌殑璇�,姣旇緝涔嬪墠鐨別ndtime鏄惁灏忎簬褰撳墠鐨別ndtaime,濡傛灉涔嬪墠鐨勫皬浜庣幇鍦ㄧ殑锛屽垯鐩存帴灏嗕箣鍓嶇殑鍋滄帀锛堝師鍥犲啀鍏ラ櫌锛�
+ ServiceSubtaskVO subtask = new ServiceSubtaskVO();
+ subtask.setPatid(patArchive.getId());
+ subtask.setSendstate(2L);
+ subtask.setTaskid(taskid);
+ List<ServiceSubtask> selectServiceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(subtask);
+ log.error("璇ユ偅鑰呭緟鎵ц鐨勪换鍔�:{}", selectServiceSubtaskList);
+ if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(selectServiceSubtaskList) && selectServiceSubtaskList.size() > 0) {
+ for (ServiceSubtask serviceSubtask1 : selectServiceSubtaskList) {
+ if (Objects.isNull(serviceSubtask1.getLongSendTime())) {
+ //涓嶆槸闀挎湡浠诲姟锛屼笉澶勭悊
+ continue;
+ }
+
+ //灏嗕箣鍓嶇殑鍋滄帀
+ serviceSubtask1.setSendstate(4L);
+ serviceSubtask1.setRemark("鐤剧梾鎮h�呭啀鍏ラ櫌");
+ serviceSubtask1.setResult("error");
+// serviceSubtask1.setFinishtime(new Date());
+ serviceSubtask1.setUpdateBy(serviceTask.getUpdateBy());
+ serviceSubtaskMapper.updateServiceSubtask(serviceSubtask1);
+ //閲嶆柊鏂板瀛愪换鍔�
+ i = serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
+
+ }
+ } else {
+ if (StringUtils.isEmpty(serviceSubtask.getPhone())) {
+ serviceSubtask.setRemark("鎵嬫満鍙蜂负绌�");
+ serviceSubtask.setSendstate(4L);
+ serviceSubtask.setResult("error");
+// serviceSubtask.setFinishtime(new Date());
+ }
+ serviceSubtask.setCreateBy(serviceTask.getCreateBy());
+ serviceSubtask.setCreateTime(new Date());
+ i = serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
+ }
+ } else {
+ if (StringUtils.isEmpty(serviceSubtask.getPhone())) {
+ serviceSubtask.setRemark("鎵嬫満鍙蜂负绌�");
+ serviceSubtask.setSendstate(4L);
+ serviceSubtask.setResult("error");
+// serviceSubtask.setFinishtime(new Date());
+
+ }
+ serviceSubtask.setCreateBy(serviceTask.getCreateBy());
+ serviceSubtask.setCreateTime(new Date());
+ i = serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
+ }
+ if (i == 1) {
+ //灏哻heck_flag鏀规垚1锛堝凡澶勭悊锛�
+ PatMedOuthosp patMedOuthosp1 = new PatMedOuthosp();
+ patMedOuthosp1.setId(patMedOuthosp.getId());
+ patMedOuthosp1.setDiagcheckFlag("1");
+ patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp1);
+ } else {
+ //鐢熸垚瀛愪换鍔″け璐ワ紝
+ log.error("鐢熸垚瀛愪换鍔″け璐erviceSubtask涓猴細{}", serviceSubtask);
+ PatMedOuthosp pmo = new PatMedOuthosp();
+ pmo.setId(patMedOuthosp.getId());
+ pmo.setDiagcheckFlag("2");
+ pmo.setRemark("鐢熸垚瀛愪换鍔″け璐�");
+ patMedOuthospMapper.updatePatMedOuthosp(pmo);
+ }
+ }
+
+ //灏佽serviceSubtask
+ private ServiceSubtask boxedServiceSubtask(ServiceTask serviceTask, PatMedOuthosp patMedOuthosp, PatArchive patArchive) {
+ ServiceSubtask serviceSubtask = DtoConversionUtils.sourceToTarget(serviceTask, ServiceSubtask.class);
+ serviceSubtask.setTaskid(serviceTask.getTaskid());
+ if (StringUtils.isNotEmpty(serviceTask.getLibtemplateid()))
+ serviceSubtask.setLibtemplateid(Long.valueOf(serviceTask.getLibtemplateid()));
+ serviceSubtask.setDrcode(patMedOuthosp.getDrcode());
+ serviceSubtask.setDrname(patMedOuthosp.getDrname());
+ serviceSubtask.setDeptcode(patMedOuthosp.getDeptcode());
+ serviceSubtask.setDeptname(patMedOuthosp.getDeptname());
+ serviceSubtask.setTemplateid(serviceTask.getTemplateid());
+ serviceSubtask.setTemplatename(serviceTask.getTemplatename());
+ 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.setAge(patArchive.getAge());
+ serviceSubtask.setSendstate(2L);
+ serviceSubtask.setServiceType(serviceTask.getServiceType());
+ serviceSubtask.setPreachform(serviceTask.getPreachform());
+ serviceSubtask.setHospType("1");
+ serviceSubtask.setCreateTime(new Date());
+ 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);
+ //鎮h�呭彂閫佹椂闂�
+ if (StringUtils.isNotEmpty(patArchive.getNotrequiredFlag()) && patArchive.getNotrequiredFlag().equals("1")) {
+ String remark = patArchive.getNotrequiredreason();
+ serviceSubtask.setRemark(remark);
+ serviceSubtask.setResult("error");
+// serviceSubtask.setFinishtime(new Date());
+ //涓嶆墽琛�
+ serviceSubtask.setSendstate(4L);
+ }
+ return serviceSubtask;
+ }
+
+ 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();
+ }
}
--
Gitblit v1.9.3