Bladeren bron

Merge remote-tracking branch 'origin/dev/triage20201011' into debug

zhaops 4 jaren geleden
bovenliggende
commit
9f13d2a2b9

+ 7 - 0
triage-service/pom.xml

@@ -108,6 +108,13 @@
             <optional>true</optional>
         </dependency>
 
+        <!-- easypoi -->
+        <dependency>
+            <groupId>cn.afterturn</groupId>
+            <artifactId>easypoi-spring-boot-starter</artifactId>
+            <version>4.2.0</version>
+        </dependency>
+
         <dependency>
             <groupId>net.logstash.logback</groupId>
             <artifactId>logstash-logback-encoder</artifactId>

+ 37 - 0
triage-service/src/main/java/com/diagbot/dto/MRTestDTO.java

@@ -0,0 +1,37 @@
+package com.diagbot.dto;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2020/9/11 13:49
+ */
+@Getter
+@Setter
+public class MRTestDTO {
+    @Excel(name = "病历id", width = 10, orderNum = "1", needMerge = true)
+    private String id;
+    @Excel(name = "性别", width = 10, orderNum = "2", needMerge = true, replace = { "男_1", "女_2" })
+    private String sex;
+    @Excel(name = "年龄", width = 10, orderNum = "3", needMerge = true)
+    private Integer age;
+    private String mkmc;
+    @Excel(name = "主诉", width = 50, orderNum = "4", needMerge = true)
+    private String mknr;
+    @Excel(name = "症状", width = 100, orderNum = "5", needMerge = true)
+    private String symptomNames;
+    //@ExcelCollection(name = "诊断-科室", orderNum = "6")
+    //private List<MRTestDiseaseDTO> diseaseDetails;
+
+    @Excel(name = "诊断名称", width = 50, orderNum = "7")
+    private String diseaseName;
+    @Excel(name = "内部科室名称", width = 30, orderNum = "8")
+    private String innerDeptName;
+    @Excel(name = "外部科室名称", width = 30, orderNum = "9")
+    private String outDeptName;
+    @Excel(name = "外部小科室名称", width = 30, orderNum = "10")
+    private String outSubDeptName;
+}

+ 23 - 0
triage-service/src/main/java/com/diagbot/dto/MRTestDiseaseDTO.java

@@ -0,0 +1,23 @@
+package com.diagbot.dto;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2020/9/11 13:50
+ */
+@Getter
+@Setter
+public class MRTestDiseaseDTO {
+    @Excel(name = "诊断名称", width = 50, orderNum = "1")
+    private String diseaseName;
+    @Excel(name = "内部科室名称", width = 30, orderNum = "2")
+    private String innerDeptName;
+    @Excel(name = "外部科室名称", width = 30, orderNum = "3")
+    private String outDeptName;
+    @Excel(name = "外部小科室名称", width = 30, orderNum = "4")
+    private String outSubDeptName;
+}

+ 158 - 0
triage-service/src/main/java/com/diagbot/facade/MRTestFacade.java

@@ -0,0 +1,158 @@
+package com.diagbot.facade;
+
+import com.diagbot.biz.push.entity.FeatureRateV2;
+import com.diagbot.biz.push.entity.ResponseDataWithExplainV2;
+import com.diagbot.client.AiptServiceClient;
+import com.diagbot.client.TranServiceClient;
+import com.diagbot.dto.DiseaseDeptDTO;
+import com.diagbot.dto.MRTestDTO;
+import com.diagbot.dto.MRTestDiseaseDTO;
+import com.diagbot.dto.PushDTO;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
+import com.diagbot.util.BeanUtil;
+import com.diagbot.util.EntityUtil;
+import com.diagbot.util.ExcelUtils;
+import com.diagbot.util.ListUtil;
+import com.diagbot.util.RespDTOUtil;
+import com.diagbot.util.StringUtil;
+import com.diagbot.vo.AIVO;
+import com.diagbot.vo.DiseaseDeptVO;
+import com.diagbot.vo.MRTestVO;
+import com.google.common.collect.Lists;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2020/9/11 13:38
+ */
+@Component
+public class MRTestFacade {
+    @Autowired
+    private AIV2Facade aiv2Facade;
+    @Autowired
+    private AiptServiceClient aiptServiceClient;
+    @Autowired
+    private AssembleFacade assembleFacade;
+    @Autowired
+    private TranServiceClient tranServiceClient;
+
+    /**
+     * 数据导入
+     *
+     * @param file
+     */
+    public void exportMRTestResult(HttpServletResponse response, MultipartFile file) {
+        List<MRTestDTO> records = Lists.newLinkedList();
+        Map<String, List<DiseaseDeptDTO>> diseaseDeptMap = getDieseseDetpMap("邵逸夫医院");
+
+        List<MRTestVO> mrTestVOList = ExcelUtils.importExcel(file, 0, 1, MRTestVO.class);
+        if (ListUtil.isNotEmpty(mrTestVOList)) {
+            for (MRTestVO mrTestVO : mrTestVOList) {
+                AIVO aivo = new AIVO();
+                aivo.setHospitalCode("邵逸夫医院");
+                aivo.setAge(mrTestVO.getAge());
+                aivo.setSex(Integer.valueOf(mrTestVO.getSex()));
+                aivo.setSymptom(mrTestVO.getMknr());
+                PushDTO symptomPushDTO = aiv2Facade.pushSymptomForSYFV2(aivo, "1");
+
+                MRTestDTO mrTestDTO = new MRTestDTO();
+                BeanUtil.copyProperties(mrTestVO, mrTestDTO);
+                if (ListUtil.isNotEmpty(symptomPushDTO.getSymptom())) {
+                    String symptomNames = symptomPushDTO.getSymptom()
+                            .stream()
+                            .filter(i -> StringUtil.isNotBlank(i.getName()))
+                            .map(i -> i.getName())
+                            .collect(Collectors.joining("、"));
+                    mrTestDTO.setSymptomNames(symptomNames);
+                }
+                List<MRTestDiseaseDTO> diseaseDetails = pushDiseaseDept(aivo, "7", diseaseDeptMap);
+                if (ListUtil.isNotEmpty(diseaseDetails)) {
+                    mrTestDTO.setDiseaseName(diseaseDetails
+                            .stream()
+                            .filter(i -> StringUtil.isNotBlank(i.getDiseaseName()))
+                            .map(i -> i.getDiseaseName())
+                            .collect(Collectors.joining("、")));
+                    mrTestDTO.setInnerDeptName(diseaseDetails
+                            .stream()
+                            .filter(i -> StringUtil.isNotBlank(i.getInnerDeptName()))
+                            .map(i -> i.getInnerDeptName())
+                            .collect(Collectors.joining("、")));
+                    mrTestDTO.setOutDeptName(diseaseDetails
+                            .stream()
+                            .filter(i -> StringUtil.isNotBlank(i.getOutDeptName()))
+                            .map(i -> i.getOutDeptName())
+                            .collect(Collectors.joining("、")));
+                    mrTestDTO.setOutSubDeptName(diseaseDetails
+                            .stream()
+                            .filter(i -> StringUtil.isNotBlank(i.getOutSubDeptName()))
+                            .map(i -> i.getOutSubDeptName())
+                            .collect(Collectors.joining("、")));
+
+                }
+                records.add(mrTestDTO);
+            }
+        }
+        String fileName = "病历测试结果.xls";
+        ExcelUtils.exportExcel(records, null, "sheet1", MRTestDTO.class, fileName, response, 12.8f);
+    }
+
+    /**
+     * 邵逸夫诊断推理
+     *
+     * @param aivo
+     * @param type
+     * @return
+     */
+    public List<MRTestDiseaseDTO> pushDiseaseDept(AIVO aivo, String type, Map<String, List<DiseaseDeptDTO>> disDeptMap) {
+        List<MRTestDiseaseDTO> retList = Lists.newLinkedList();
+        if (StringUtil.isBlank(aivo.getHospitalCode())) {
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "请输入医院编码");
+        }
+        RespDTO<ResponseDataWithExplainV2> res
+                = aiptServiceClient.pushWithExplainV2(assembleFacade.assembleData(aivo, type));
+        RespDTOUtil.respNGDealCover(res, "中间层没有结果返回");
+        List<FeatureRateV2> dis = res.data.getDis();
+        if (ListUtil.isNotEmpty(dis)) {
+            for (FeatureRateV2 featureRate : dis) {
+                if (ListUtil.isNotEmpty(disDeptMap.get(featureRate.getFeatureName()))) {
+                    for (DiseaseDeptDTO diseaseDeptDTO : disDeptMap.get(featureRate.getFeatureName())) {
+                        MRTestDiseaseDTO mrTestDiseaseDTO = new MRTestDiseaseDTO();
+                        mrTestDiseaseDTO.setDiseaseName(featureRate.getFeatureName());
+                        mrTestDiseaseDTO.setInnerDeptName(featureRate.getExtraProperty());
+                        mrTestDiseaseDTO.setOutDeptName(diseaseDeptDTO.getDeptName());
+                        mrTestDiseaseDTO.setOutSubDeptName(diseaseDeptDTO.getSubDeptName());
+                        retList.add(mrTestDiseaseDTO);
+                    }
+                }
+            }
+
+        }
+        if (retList.size() > 2) {
+            retList = retList.subList(0, 2);
+        }
+        return retList;
+    }
+
+    public Map<String, List<DiseaseDeptDTO>> getDieseseDetpMap(String hospitalCode) {
+        //关联邵逸夫医院映射
+        DiseaseDeptVO diseaseDeptVO = new DiseaseDeptVO();
+        diseaseDeptVO.setHospitalCode(hospitalCode);
+        RespDTO<List<DiseaseDeptDTO>> diseaseDeptDTORes
+                = tranServiceClient.getDiseaseDeptByConceptNames(diseaseDeptVO);
+        RespDTOUtil.respNGDealCover(diseaseDeptDTORes, "诊断科室映射关系未维护");
+        List<DiseaseDeptDTO> diseaseDeptDTOList = diseaseDeptDTORes.data;
+        Map<String, List<DiseaseDeptDTO>> diseaseDeptMap
+                = EntityUtil.makeEntityListMap(diseaseDeptDTOList, "conceptDisName");
+        return diseaseDeptMap;
+    }
+}

+ 182 - 0
triage-service/src/main/java/com/diagbot/util/ExcelUtils.java

@@ -0,0 +1,182 @@
+package com.diagbot.util;
+
+
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.ExcelImportUtil;
+import cn.afterturn.easypoi.excel.entity.ExportParams;
+import cn.afterturn.easypoi.excel.entity.ImportParams;
+import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
+import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
+import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+/**
+ * @Description: excel 导入导出工具类
+ * @author: gaodm
+ * @time: 2020/6/2 19:18
+ */
+public class ExcelUtils {
+    public static void exportExcel(List<?> list, String title, String sheetName, Class<?> pojoClass, String fileName,
+                                   boolean isCreateHeader, HttpServletResponse response) {
+        ExportParams exportParams = new ExportParams(title, sheetName);
+        exportParams.setCreateHeadRows(isCreateHeader);
+        defaultExport(list, pojoClass, fileName, response, exportParams);
+    }
+
+    public static void exportExcelDynamicCol(List<ExcelExportEntity> entityList, Collection<?> dataSet, String title, String sheetName, String fileName,
+                                    HttpServletResponse response) {
+        ExportParams exportParams = new ExportParams(title, sheetName);
+        dynamicColExport(entityList, dataSet, fileName, response, exportParams);
+    }
+
+    public static void exportExcel(List<?> list, String title, String sheetName, Class<?> pojoClass, String fileName,
+                                   HttpServletResponse response, float height) {
+        Boolean havTitle = false;
+        if (StringUtil.isNotBlank(title)) {
+            havTitle = true;
+        }
+        userExport2(list, pojoClass, fileName, response, new ExportParams(title, sheetName), height, havTitle);
+    }
+
+    public static void exportExcel(List<?> list, String title, String sheetName, Class<?> pojoClass, String fileName,
+                                   HttpServletResponse response) {
+        defaultExport(list, pojoClass, fileName, response, new ExportParams(title, sheetName));
+    }
+
+    public static void exportExcel(List<Map<String, Object>> list, String fileName, HttpServletResponse response) {
+        defaultExport(list, fileName, response);
+    }
+
+    private static void defaultExport(List<?> list, Class<?> pojoClass, String fileName, HttpServletResponse response,
+                                      ExportParams exportParams) {
+        Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, list);
+        if (workbook != null) {
+            ;
+        }
+        downLoadExcel(fileName, response, workbook);
+    }
+
+    private static void dynamicColExport(List<ExcelExportEntity> entityList, Collection<?> dataSet, String fileName, HttpServletResponse response,
+                                         ExportParams exportParams) {
+        Workbook workbook = ExcelExportUtil.exportExcel(exportParams,entityList,dataSet);
+        if (workbook != null) {
+            ;
+        }
+        downLoadExcel(fileName, response, workbook);
+    }
+
+    private static void userExport(List<?> list, Class<?> pojoClass, String fileName, HttpServletResponse response,
+                                   ExportParams exportParams) {
+        Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, list);
+        if (workbook != null) {
+            Sheet sheet = workbook.getSheetAt(0);
+            //列宽设置
+            sheet.setColumnWidth(8, 256 * 20);
+            sheet.setColumnWidth(9, 256 * 50);
+            int rowNum = sheet.getLastRowNum();
+            Row row = sheet.getRow(0);
+            for (int i = 1; i <= rowNum; i++) {
+                row = sheet.getRow(i);
+                row.setHeightInPoints(12.8f);
+            }
+        }
+        downLoadExcel(fileName, response, workbook);
+    }
+
+    private static void userExport2(List<?> list, Class<?> pojoClass, String fileName, HttpServletResponse response,
+                                    ExportParams exportParams, float height, Boolean havTitle) {
+        Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, list);
+        if (workbook != null) {
+            Sheet sheet = workbook.getSheetAt(0);
+            int rowNum = sheet.getLastRowNum();
+            Row row = sheet.getRow(0);
+            int startRowNum = 1;
+            if (havTitle) {
+                startRowNum = 2;
+            }
+            for (int i = startRowNum; i <= rowNum; i++) {
+                row = sheet.getRow(i);
+                row.setHeightInPoints(height);
+            }
+        }
+        downLoadExcel(fileName, response, workbook);
+    }
+
+    private static void downLoadExcel(String fileName, HttpServletResponse response, Workbook workbook) {
+        try {
+            response.setCharacterEncoding("UTF-8");
+            response.setHeader("content-Type", "application/vnd.ms-excel");
+            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
+            workbook.write(response.getOutputStream());
+        } catch (IOException e) {
+            // throw new NormalException(e.getMessage());
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "导出Excel异常");
+        }
+    }
+
+    private static void defaultExport(List<Map<String, Object>> list, String fileName, HttpServletResponse response) {
+        Workbook workbook = ExcelExportUtil.exportExcel(list, ExcelType.HSSF);
+        if (workbook != null) {
+            ;
+        }
+        downLoadExcel(fileName, response, workbook);
+    }
+
+    public static <T> List<T> importExcel(String filePath, Integer titleRows, Integer headerRows, Class<T> pojoClass) {
+        if (StringUtils.isBlank(filePath)) {
+            return null;
+        }
+        ImportParams params = new ImportParams();
+        params.setTitleRows(titleRows);
+        params.setHeadRows(headerRows);
+        List<T> list = null;
+        try {
+            list = ExcelImportUtil.importExcel(new File(filePath), pojoClass, params);
+        } catch (NoSuchElementException e) {
+            // throw new NormalException("模板不能为空");
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "模板不能为空");
+        } catch (Exception e) {
+            e.printStackTrace();
+            // throw new NormalException(e.getMessage());
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "导入Excel异常");
+        }
+        return list;
+    }
+
+    public static <T> List<T> importExcel(MultipartFile file, Integer titleRows, Integer headerRows,
+                                          Class<T> pojoClass) {
+        if (file == null) {
+            return null;
+        }
+        ImportParams params = new ImportParams();
+        params.setTitleRows(titleRows);
+        params.setHeadRows(headerRows);
+        List<T> list = null;
+        try {
+            list = ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params);
+        } catch (NoSuchElementException e) {
+            // throw new NormalException("excel文件不能为空");
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "excel文件不能为空");
+        } catch (Exception e) {
+            // throw new NormalException(e.getMessage());
+            System.out.println(e.getMessage());
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "导入Excel异常");
+        }
+        return list;
+    }
+
+}

+ 24 - 0
triage-service/src/main/java/com/diagbot/vo/MRTestVO.java

@@ -0,0 +1,24 @@
+package com.diagbot.vo;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2020/9/11 13:40
+ */
+@Getter
+@Setter
+public class MRTestVO {
+    @Excel(name = "病历id", width = 10, orderNum = "1")
+    private String id;
+    @Excel(name = "性别", width = 10, orderNum = "2", replace = { "男_1", "女_2" })
+    private String sex;
+    @Excel(name = "年龄", width = 10, orderNum = "3")
+    private Integer age;
+    private String mkmc;
+    @Excel(name = "主诉", width = 50, orderNum = "4")
+    private String mknr;
+}

+ 34 - 0
triage-service/src/main/java/com/diagbot/web/MRTestController.java

@@ -0,0 +1,34 @@
+package com.diagbot.web;
+
+import com.diagbot.facade.MRTestFacade;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2020/9/11 14:38
+ */
+@RestController
+@RequestMapping("/mrtest")
+@Api(value = "MRTest", tags = { "病历测试" })
+@SuppressWarnings("unchecked")
+public class MRTestController {
+    @Autowired
+    private MRTestFacade mrTestFacade;
+
+    @ApiOperation(value = "病历测试[by:zhaops]",
+            notes = "")
+    @PostMapping("/exportMRTestResult")
+    public void exportMRTestResult(HttpServletResponse response,  @RequestParam("file") MultipartFile file) {
+        mrTestFacade.exportMRTestResult(response, file);
+    }
+}