Jelajahi Sumber

feat: 数据分析

xdd 1 Minggu lalu
induk
melakukan
8be9d8d066

+ 15 - 1
fs-admin/src/main/java/com/fs/medical/PhysicalExamReportController.java

@@ -4,6 +4,7 @@ import com.fs.common.annotation.RepeatSubmit;
 import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.R;
 import com.fs.medical.domain.PhysicalExamReport;
+import com.fs.medical.param.PhysicalExamReportCompareDto;
 import com.fs.medical.param.PhysicalExamReportQueryDto;
 import com.fs.medical.service.PhysicalExamReportService;
 import com.github.pagehelper.PageHelper;
@@ -48,7 +49,20 @@ public class PhysicalExamReportController extends BaseController {
             return R.error("查询失败");
         }
     }
-
+    /**
+     * 对比报告
+     */
+    @ApiOperation("对比报告")
+    @PostMapping("/compareReport")
+    public R compareReport(@RequestBody PhysicalExamReportCompareDto reportCompareDto){
+        try {
+            Object result = physicalExamReportService.compareReport(reportCompareDto);
+            return R.ok().put("data", result);
+        } catch (Exception e) {
+            logger.error("体检报告对比失败", e);
+            return R.error("对比失败");
+        }
+    }
     /**
      * 分页查询体检报告列表(带筛选)
      */

+ 16 - 0
fs-service/src/main/java/com/fs/medical/param/PhysicalExamReportCompareDto.java

@@ -0,0 +1,16 @@
+package com.fs.medical.param;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class PhysicalExamReportCompareDto implements Serializable {
+    private Long report1;
+    private Long report2;
+
+    /**
+     * 0 身体信息 1指标检查
+     */
+    private Integer type;
+}

+ 9 - 0
fs-service/src/main/java/com/fs/medical/service/PhysicalExamReportService.java

@@ -1,9 +1,11 @@
 package com.fs.medical.service;
 
 import com.fs.medical.domain.PhysicalExamReport;
+import com.fs.medical.param.PhysicalExamReportCompareDto;
 import com.fs.medical.param.PhysicalExamReportQueryDto;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 体检报告服务接口
@@ -44,4 +46,11 @@ public interface PhysicalExamReportService {
      * 分页查询体检报告列表
      */
     List<PhysicalExamReport> selectPageList(PhysicalExamReportQueryDto queryDto);
+
+    /**
+     * 对比两份体检报告
+     * @param reportCompareDto 体检报告对比DTO
+     * @return 对比结果
+     */
+    Map<String, Object> compareReport(PhysicalExamReportCompareDto reportCompareDto);
 }

+ 168 - 11
fs-service/src/main/java/com/fs/medical/service/impl/PhysicalExamReportServiceImpl.java

@@ -7,17 +7,20 @@ import com.fs.common.utils.date.DateUtil;
 import com.fs.his.domain.FsAttachment;
 import com.fs.his.service.IFsAttachmentService;
 import com.fs.medical.domain.PhysicalExamReport;
+import com.fs.medical.domain.ReportIndicatorResult;
 import com.fs.medical.mapper.PhysicalExamReportMapper;
+import com.fs.medical.param.PhysicalExamReportCompareDto;
 import com.fs.medical.param.PhysicalExamReportQueryDto;
 import com.fs.medical.service.PhysicalExamReportService;
+import com.fs.medical.service.ReportIndicatorResultService;
 import com.fs.store.service.cache.IFsUserCacheService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.time.LocalDateTime;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 /**
  * 体检报告服务实现类
@@ -35,6 +38,9 @@ public class PhysicalExamReportServiceImpl implements PhysicalExamReportService
 
     @Autowired
     private ICompanyUserCacheService companyUserCacheService;
+    
+    @Autowired
+    private ReportIndicatorResultService reportIndicatorResultService;
 
     @Override
     public PhysicalExamReport getById(Long reportId) {
@@ -54,10 +60,10 @@ public class PhysicalExamReportServiceImpl implements PhysicalExamReportService
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean save(PhysicalExamReport report) {
-        if (report.getCreateTime() == null){
+        if (report.getCreateTime() == null) {
             report.setCreateTime(LocalDateTime.now());
         }
-        boolean flag = physicalExamReportMapper.insert(report)>0;
+        boolean flag = physicalExamReportMapper.insert(report) > 0;
         if (flag) {
             createFile(report);
         }
@@ -66,11 +72,12 @@ public class PhysicalExamReportServiceImpl implements PhysicalExamReportService
 
     /**
      * 存储到我的附件
+     *
      * @param report
      */
     private void createFile(PhysicalExamReport report) {
         Long userId = report.getUserId();
-        if (userId == null){
+        if (userId == null) {
             return;
         }
         //更新文件夹
@@ -79,7 +86,7 @@ public class PhysicalExamReportServiceImpl implements PhysicalExamReportService
         String fileName = "体检报告";
         //查看文件夹是否存在
         FsAttachment folder = attachmentService.selectFsAttachmentByFolderName(folderName);
-        if (folder == null){
+        if (folder == null) {
             //新建文件
             folder = new FsAttachment();
             folder.setParentId(0L);
@@ -119,20 +126,170 @@ public class PhysicalExamReportServiceImpl implements PhysicalExamReportService
     public List<PhysicalExamReport> selectPageList(PhysicalExamReportQueryDto queryDto) {
         List<PhysicalExamReport> physicalExamReports = physicalExamReportMapper.selectPageList(queryDto);
         for (PhysicalExamReport physicalExamReport : physicalExamReports) {
-            if(ObjectUtils.isNotNull(physicalExamReport.getUserId())) {
+            if (ObjectUtils.isNotNull(physicalExamReport.getUserId())) {
                 String userNameById = fsUserCacheService.selectUserNameById(physicalExamReport.getUserId());
-                if(StringUtils.isNotBlank(userNameById)) {
+                if (StringUtils.isNotBlank(userNameById)) {
                     physicalExamReport.setUserName(userNameById);
                 }
             }
-            if(ObjectUtils.isNotNull(physicalExamReport.getCompanyUserId())) {
+            if (ObjectUtils.isNotNull(physicalExamReport.getCompanyUserId())) {
                 String userNameById = companyUserCacheService.selectCompanyUserNameUserById(physicalExamReport.getCompanyUserId());
-                if(StringUtils.isNotBlank(userNameById)) {
+                if (StringUtils.isNotBlank(userNameById)) {
                     physicalExamReport.setCompanyUserName(userNameById);
                 }
             }
         }
         return physicalExamReports;
     }
-}
 
+    @Override
+    public Map<String, Object> compareReport(PhysicalExamReportCompareDto reportCompareDto) {
+        Map<String, Object> result = new HashMap<>();
+
+        // 检查参数
+        if (reportCompareDto == null || reportCompareDto.getReport1() == null || reportCompareDto.getReport2() == null) {
+            result.put("success", false);
+            result.put("message", "参数不能为空");
+            return result;
+        }
+
+        // 获取两份报告
+        PhysicalExamReport report1 = physicalExamReportMapper.getById(reportCompareDto.getReport1());
+        PhysicalExamReport report2 = physicalExamReportMapper.getById(reportCompareDto.getReport2());
+
+        if (report1 == null || report2 == null) {
+            result.put("success", false);
+            result.put("message", "报告不存在");
+            return result;
+        }
+
+        // 设置基本信息
+        result.put("report1", report1);
+        result.put("report2", report2);
+        result.put("success", true);
+
+        // 根据类型进行对比
+        Integer type = reportCompareDto.getType();
+        if (type != null && type == 0) {
+            // 身体信息对比
+            Map<String, Object> bodyInfoComparison = compareBodyInfo(report1, report2);
+            result.put("comparison", bodyInfoComparison);
+        } else if (type != null && type == 1) {
+            // 指标检查对比
+            List<Map<String, Object>> indicatorComparison = compareIndicators(reportCompareDto.getReport1(), reportCompareDto.getReport2());
+            result.put("comparison", indicatorComparison);
+        }
+
+        return result;
+    }
+
+    /**
+     * 对比两份报告的身体信息
+     *
+     * @param report1 第一份报告
+     * @param report2 第二份报告
+     * @return 对比结果
+     */
+    private Map<String, Object> compareBodyInfo(PhysicalExamReport report1, PhysicalExamReport report2) {
+        Map<String, Object> comparison = new HashMap<>();
+
+        // 计算身高差异
+        if (report1.getHeight() != null && report2.getHeight() != null) {
+            BigDecimal heightDiff = report2.getHeight().subtract(report1.getHeight());
+            comparison.put("heightDiff", heightDiff);
+            comparison.put("heightChange", heightDiff.compareTo(BigDecimal.ZERO) > 0 ? "1" : "0");
+        }
+
+        // 计算体重差异
+        if (report1.getWeight() != null && report2.getWeight() != null) {
+            BigDecimal weightDiff = report2.getWeight().subtract(report1.getWeight());
+            comparison.put("weightDiff", weightDiff);
+            comparison.put("weightChange", weightDiff.compareTo(BigDecimal.ZERO) > 0 ? "1" : "0");
+        }
+
+        // 计算BMI差异
+        if (report1.getBmi() != null && report2.getBmi() != null) {
+            BigDecimal bmiDiff = report2.getBmi().subtract(report1.getBmi());
+            comparison.put("bmiDiff", bmiDiff);
+            comparison.put("bmiChange", bmiDiff.compareTo(BigDecimal.ZERO) > 0 ? "1" : "0");
+        }
+
+        // 计算腰围差异
+        if (report1.getWaistCircumference() != null && report2.getWaistCircumference() != null) {
+            BigDecimal waistDiff = report2.getWaistCircumference().subtract(report1.getWaistCircumference());
+            comparison.put("waistDiff", waistDiff);
+            comparison.put("waistChange", waistDiff.compareTo(BigDecimal.ZERO) > 0 ? "1" : "0");
+        }
+
+        // 计算胸围差异
+        if (report1.getChestCircumference() != null && report2.getChestCircumference() != null) {
+            BigDecimal chestDiff = report2.getChestCircumference().subtract(report1.getChestCircumference());
+            comparison.put("chestDiff", chestDiff);
+            comparison.put("chestChange", chestDiff.compareTo(BigDecimal.ZERO) > 0 ? "1" : "0");
+        }
+
+        return comparison;
+    }
+    
+    /**
+     * 对比两份报告的指标检查结果
+     *
+     * @param reportId1 第一份报告 ID
+     * @param reportId2 第二份报告 ID
+     * @return 对比结果列表
+     */
+    private List<Map<String, Object>> compareIndicators(Long reportId1, Long reportId2) {
+        List<Map<String, Object>> results = new ArrayList<>();
+        
+        // 获取两份报告的所有指标结果
+        List<ReportIndicatorResult> indicators1 = reportIndicatorResultService.listByReportId(reportId1);
+        List<ReportIndicatorResult> indicators2 = reportIndicatorResultService.listByReportId(reportId2);
+        
+        // 将第二份报告的指标按 indicatorId 进行索引,方便快速查找
+        Map<Long, ReportIndicatorResult> indicatorMap2 = new HashMap<>();
+        for (ReportIndicatorResult indicator : indicators2) {
+            if (indicator.getIndicatorId() != null) {
+                indicatorMap2.put(indicator.getIndicatorId(), indicator);
+            }
+        }
+        
+        // 处理每个指标的对比
+        for (ReportIndicatorResult indicator1 : indicators1) {
+            if (indicator1.getIndicatorId() == null) {
+                continue;
+            }
+            
+            // 查找第二份报告中对应的指标结果
+            ReportIndicatorResult indicator2 = indicatorMap2.get(indicator1.getIndicatorId());
+            
+            // 如果两份报告都有该指标,进行对比
+            if (indicator2 != null) {
+                Map<String, Object> comparison = new HashMap<>();
+                
+                // 指标名称和基本信息
+                comparison.put("indicatorId", indicator1.getIndicatorId());
+                comparison.put("indicatorName", indicator1.getIndicatorName());
+                comparison.put("unitName", indicator1.getUnitName());
+                comparison.put("refRange", indicator1.getRefRange());
+                
+                // 数值比较
+                comparison.put("value1", indicator1.getTestValue());
+                comparison.put("value2", indicator2.getTestValue());
+                
+                // 判断变化方向
+                String change = "0"; // 默认为"减少"
+                if (indicator1.getTestValue() != null && indicator2.getTestValue() != null) {
+                    int compareResult = indicator2.getTestValue().compareTo(indicator1.getTestValue());
+                    if (compareResult > 0) {
+                        change = "1"; // 增加
+                    }
+                }
+                comparison.put("change", change);
+                
+                results.add(comparison);
+            }
+        }
+        
+        return results;
+    }
+}