Browse Source

住院流失患者-bug修复

admin 3 weeks ago
parent
commit
127cddeb52

+ 8 - 3
healthy-data/healthy-doctor-data/src/main/java/com/xxh/cloud/healthy/data/framework/modules/biz/mapper/DwdPatientDataBizMapper.java

@@ -583,9 +583,14 @@ public interface DwdPatientDataBizMapper {
     List<PatientVisitRecordClientBO> queryVisitLossList(@Param(Constants.WRAPPER) Wrapper<PatientVisitRecordClientBO> wrapper);
     
     // 住院流失
-    @Select(" SELECT a.* " + 
-            " FROM dwd_inpatient_reserve_info a " + 
-            " LEFT JOIN dwd_inpatient_record_info b ON a.patient_id = b.patient_id " + 
+//    @Select(" SELECT a.* " +
+//            " FROM dwd_inpatient_reserve_info a " +
+//            " LEFT JOIN dwd_inpatient_record_info b ON a.patient_id = b.patient_id " +
+//            " ${ew.customSqlSegment} ")
+    @Select(" SELECT a.* " +
+            " FROM dwd_inpatient_reserve_info a " +
+            " LEFT JOIN dwd_inpatient_record_info b on a.patient_id = b.patient_id " +
+            " and (b.id is null or (b.id is not null and b.inpatient_date>=a.apply_date)) " +
             " ${ew.customSqlSegment} ")
     List<PatientInpatientReserveClientBO> queryInpatientLossList(@Param(Constants.WRAPPER) Wrapper<PatientInpatientReserveClientBO> wrapper);
     

+ 22 - 2
healthy-data/healthy-doctor-data/src/main/java/com/xxh/cloud/healthy/data/framework/modules/biz/service/impl/DoctorDwdPatientDataBizServiceImpl.java

@@ -1473,10 +1473,30 @@ public class DoctorDwdPatientDataBizServiceImpl implements DoctorDwdPatientDataB
     @Override
     public List<PatientInpatientReserveClientBO> queryInpatientLossList(Date startDate, Date endDate, Integer inHospitalLostDay) {
         // 查询范围内最新的数据
+//        List<PatientInpatientReserveClientBO> list = dwdPatientDataBizMapper.queryInpatientLossList(new QueryWrapper<PatientInpatientReserveClientBO>()
+//                .isNull("b.id")
+//                .ge("a.apply_date", DateUtil.date(startDate).toDateStr())
+//                .lt("a.apply_date", DateUtil.date(endDate).toDateStr())
+//                .ge("b.inpatient_date", DateUtil.date(startDate).toDateStr())
+//                .ge("b.inpatient_date", DateUtil.date(DateUtil.offsetDay(startDate, inHospitalLostDay)).toDateStr())
+//        );
         List<PatientInpatientReserveClientBO> list = dwdPatientDataBizMapper.queryInpatientLossList(new QueryWrapper<PatientInpatientReserveClientBO>()
-                .isNull("b.id")
+                        .and(wrapper -> wrapper
+                                .or(w -> w // 对应 OR 的第一个条件
+                                        .isNull("b.id")
+                                        .ge("a.apply_date", DateUtil.date(startDate).toDateStr())
+                                        .lt("a.apply_date", DateUtil.date(endDate).toDateStr())
+                                )
+                                .or(w -> w // 对应 OR 的第二个条件
+                                        .isNotNull("b.id")
+                                        .ge("a.apply_date", DateUtil.date(startDate).toDateStr())
+                                        .lt("a.apply_date", DateUtil.date(endDate).toDateStr())
+                                        .ge("b.inpatient_date", DateUtil.date(DateUtil.offsetDay(startDate, inHospitalLostDay)).toDateStr())
+                                )
+                        )
+                /*.isNull("b.id")
                 .ge("a.apply_date", DateUtil.date(startDate).toDateStr())
-                .lt("a.apply_date", DateUtil.date(endDate).toDateStr())
+                .lt("a.apply_date", DateUtil.date(endDate).toDateStr())*/
 //                .ge("b.inpatient_date", DateUtil.date(startDate).toDateStr())
 //                .ge("b.inpatient_date", DateUtil.date(DateUtil.offsetDay(startDate, inHospitalLostDay)).toDateStr())
         );

+ 39 - 18
healthy-data/healthy-doctor-data/src/main/java/com/xxh/cloud/healthy/data/framework/modules/task/service/impl/PatientLossDataStatisticServiceImpl.java

@@ -17,6 +17,8 @@ import cn.hutool.core.date.DateUtil;
 import lombok.extern.slf4j.Slf4j;
 
 import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -51,19 +53,19 @@ public class PatientLossDataStatisticServiceImpl implements PatientLossDataStati
         if (null == endDate || endDate.after(now)) {
             endDate = now;
         }
-        
+
         while (!startDate.after(endDate)) {
             // 查询挂号流失信息
-            List<DoctorDwdRegisterRecordVO> registerRecordVOs = doctorDwdPatientDataBizService.queryRegisterLossList(DateUtil.offsetDay(startDate, -registerLossDay), DateUtil.offsetDay(startDate, -registerLossDay+1));
+            List<DoctorDwdRegisterRecordVO> registerRecordVOs = doctorDwdPatientDataBizService.queryRegisterLossList(DateUtil.offsetDay(startDate, -registerLossDay), DateUtil.offsetDay(startDate, -registerLossDay + 1));
             // 保存流失数据
             if (CollUtil.isNotEmpty(registerRecordVOs)) {
                 // 校验当天同部门已就诊
                 Map<String, List<DoctorDwdRegisterRecordVO>> regVisMap = new HashMap<>();
                 Set<String> patientIds = new HashSet<>();
-                registerRecordVOs.forEach(vo-> patientIds.add(vo.getPatientId()));
-                List<DoctorDwdRegisterRecordVO> regVisList = doctorDwdPatientDataBizService.queryRegisterVisitList(patientIds, DateUtil.offsetDay(startDate, -registerLossDay), DateUtil.offsetDay(startDate, -registerLossDay+1));
+                registerRecordVOs.forEach(vo -> patientIds.add(vo.getPatientId()));
+                List<DoctorDwdRegisterRecordVO> regVisList = doctorDwdPatientDataBizService.queryRegisterVisitList(patientIds, DateUtil.offsetDay(startDate, -registerLossDay), DateUtil.offsetDay(startDate, -registerLossDay + 1));
                 if (CollUtil.isNotEmpty(regVisList)) {
-                    regVisList.forEach(vo->{
+                    regVisList.forEach(vo -> {
                         String mapKey = StrUtil.format("{}_{}", vo.getPatientId(), vo.getDepartmentCodeStandard());
                         if (regVisMap.containsKey(mapKey)) {
                             List<DoctorDwdRegisterRecordVO> mapList = regVisMap.get(mapKey);
@@ -98,7 +100,7 @@ public class PatientLossDataStatisticServiceImpl implements PatientLossDataStati
                     patientLossDataBizService.saveBatch(saveList);
                 }
             }
-            
+
             startDate = DateUtil.offsetDay(startDate, 1);
         }
     }
@@ -112,15 +114,15 @@ public class PatientLossDataStatisticServiceImpl implements PatientLossDataStati
         if (null == endDate || endDate.after(now)) {
             endDate = now;
         }
-        
+
         while (!startDate.after(endDate)) {
             // 查询就诊流失信息
-            List<PatientVisitRecordClientBO> visitRecordVOs = doctorDwdPatientDataBizService.queryVisitLossList(DateUtil.offsetDay(startDate, -visitLossDay), DateUtil.offsetDay(startDate, -visitLossDay+1));
+            List<PatientVisitRecordClientBO> visitRecordVOs = doctorDwdPatientDataBizService.queryVisitLossList(DateUtil.offsetDay(startDate, -visitLossDay), DateUtil.offsetDay(startDate, -visitLossDay + 1));
 
             // 保存流失数据
             if (CollUtil.isNotEmpty(visitRecordVOs)) {
                 List<PatientLossAddDTO> saveList = new ArrayList<>();
-                
+
                 visitRecordVOs.forEach(i -> {
                     PatientLossAddDTO loss = new PatientLossAddDTO();
                     loss.setDeptId(i.getDepartmentCodeStandard());
@@ -129,10 +131,10 @@ public class PatientLossDataStatisticServiceImpl implements PatientLossDataStati
                     loss.setType(PatientLossConstant.LossType.Visit.getCode());
                     loss.setDataSourceId(i.getId());
                     loss.setDataSourceDate(i.getVisitDate());
-                    
+
                     saveList.add(loss);
                 });
-                
+
                 if (CollUtil.isNotEmpty(saveList)) {
                     patientLossDataBizService.saveBatch(saveList);
                 }
@@ -152,15 +154,18 @@ public class PatientLossDataStatisticServiceImpl implements PatientLossDataStati
         if (null == endDate || endDate.after(now)) {
             endDate = now;
         }
-        
+
         while (!startDate.after(endDate)) {
+            DateTime dateTime = DateUtil.offsetDay(startDate, -inHospitalLostDay);
+            DateTime dateTime1 = DateUtil.offsetDay(startDate, -inHospitalLostDay + 1);
             // 查询住院流失信息
-            List<PatientInpatientReserveClientBO> inpatientRecordVOs = doctorDwdPatientDataBizService.queryInpatientLossList(DateUtil.offsetDay(startDate, -inHospitalLostDay), DateUtil.offsetDay(startDate, -inHospitalLostDay+1), inHospitalLostDay);
-            
+            List<PatientInpatientReserveClientBO> inpatientRecordVOs = doctorDwdPatientDataBizService.queryInpatientLossList(dateTime, dateTime1, inHospitalLostDay);
+
+
             // 保存流失数据
             if (CollUtil.isNotEmpty(inpatientRecordVOs)) {
                 List<PatientLossAddDTO> saveList = new ArrayList<>();
-                
+
                 inpatientRecordVOs.forEach(i -> {
                     PatientLossAddDTO loss = new PatientLossAddDTO();
                     loss.setDeptId(i.getAdmitDepartmentCodeStandard());
@@ -169,12 +174,13 @@ public class PatientLossDataStatisticServiceImpl implements PatientLossDataStati
                     loss.setType(PatientLossConstant.LossType.Inpatient.getCode());
                     loss.setDataSourceId(i.getId());
                     loss.setDataSourceDate(i.getApplyDate());
-                    
+
                     saveList.add(loss);
                 });
-                
+
                 if (CollUtil.isNotEmpty(saveList)) {
-                    patientLossDataBizService.saveBatch(saveList);
+                    List<PatientLossAddDTO> patientLossAddDTOS = duplicateRemoval(saveList);
+                    patientLossDataBizService.saveBatch(patientLossAddDTOS);
                 }
             }
 
@@ -182,4 +188,19 @@ public class PatientLossDataStatisticServiceImpl implements PatientLossDataStati
         }
     }
 
+    /**
+     * 去重
+     *
+     * @param saveList
+     */
+    private List<PatientLossAddDTO> duplicateRemoval(List<PatientLossAddDTO> saveList) {
+        List<PatientLossAddDTO> collect = saveList.stream().collect(Collectors.toMap(PatientLossAddDTO::getPatientId,
+                        Function.identity(),
+                        (existing, replacement) -> existing,
+                        LinkedHashMap::new)).values()
+                .stream()
+                .collect(Collectors.toList());
+        return collect;
+    }
+
 }

+ 6 - 0
healthy-service/healthy-serve-label-framework/src/main/java/com/xxh/cloud/healthy/serve/label/framework/modules/biz/service/impl/PatientLabelQueryServiceImpl.java

@@ -174,6 +174,9 @@ public class PatientLabelQueryServiceImpl implements PatientLabelQueryService {
         // if (StrUtil.isBlank(params.getLabelId()) || StrUtil.isBlank(params.getDoctorId())) {
         //     return new PageData<>(null, 0);
         // }
+        //如果标签id为空则直接返回空
+        //如果标签id不为空,但是医生id为空也不行
+        //必须同时写标签id和医生id
         if ((StrUtil.isBlank(params.getLabelId()) && CollectionUtil.isEmpty(params.getLabelIds())) || StrUtil.isBlank(params.getDoctorId())) {
             return new PageData<>(null, 0);
         }
@@ -201,8 +204,11 @@ public class PatientLabelQueryServiceImpl implements PatientLabelQueryService {
             return new PageData<>(null, 0);
         }
 
+        //患者id
         List<String> patientIds = new ArrayList<>();
+        //标签id
         List<String> labelIds = new ArrayList<>();
+        //id
         Set<String> patientLabelIds = new HashSet<>();
         page.getRecords().forEach(i -> {
             patientIds.add(i.getPatientId());