|
@@ -0,0 +1,282 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.diagbot.dto.ExportDiagnoseDTO;
|
|
|
+import com.diagbot.dto.ExportDiagnoseNameDTO;
|
|
|
+import com.diagbot.entity.KlDiagnoseDetail;
|
|
|
+import com.diagbot.enums.DiagnoseLexiconTypeEnum;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.service.impl.KlDiagnoseDetailServiceImpl;
|
|
|
+import com.diagbot.util.*;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 诊断依据明细表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author zhoutg
|
|
|
+ * @since 2021-06-10
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class KlDiagnoseDetailFacade extends KlDiagnoseDetailServiceImpl {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ KlDiagnoseDetailFacade klDiagnoseDetailFacade;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出诊断依据【初版】
|
|
|
+ */
|
|
|
+ public void exportDiagnose(HttpServletResponse response) {
|
|
|
+ // 获取全部数据、分组
|
|
|
+ List<KlDiagnoseDetail> klDiagnoseDetailList = klDiagnoseDetailFacade.list(new QueryWrapper<KlDiagnoseDetail>()
|
|
|
+// .eq("dis_name", "急性化脓性扁桃体炎")
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()));
|
|
|
+ Map<String, List<KlDiagnoseDetail>> diagnoseDetailMap = EntityUtil.makeEntityListMap(klDiagnoseDetailList, "disName");
|
|
|
+ Map<String, List<ExportDiagnoseDTO>> diagnoseDetails = processDiagnoseDetail(diagnoseDetailMap);
|
|
|
+ List<ExportDiagnoseDTO> res = new ArrayList<>();
|
|
|
+ for (String disName : diagnoseDetails.keySet()) {
|
|
|
+ ExportDiagnoseDTO exportDiagnoseDTO = new ExportDiagnoseDTO();
|
|
|
+ exportDiagnoseDTO.setType("【" + disName + "】"); // 疾病
|
|
|
+ res.add(exportDiagnoseDTO);
|
|
|
+ res.addAll(diagnoseDetails.get(disName));
|
|
|
+ }
|
|
|
+ // 导出数据
|
|
|
+ List<Map<String, Object>> exportDto = new LinkedList<>();
|
|
|
+
|
|
|
+ // Map<String, List<ExportDiagnoseDTO>> diagnoseDetailsNew = new LinkedHashMap<>();
|
|
|
+ // diagnoseDetailsNew.put("测试", res);
|
|
|
+ // List<ExportDiagnoseNameDTO> exportDiagnoseNameDTOList = getCatalogue(diagnoseDetailsNew); // 生成目录名称
|
|
|
+ // Map<String, String> styleMap = new LinkedHashMap<>();
|
|
|
+ // styleMap.put(ExcelUtils.HYPERLINK, "com.diagbot.entity.ExcelDataHandler");
|
|
|
+ // styleMap.put(ExcelUtils.DATA_HEIGHT, "6");
|
|
|
+ // exportDto.add(ExcelUtils.createOneSheet("目录", null, ExportDiagnoseNameDTO.class, exportDiagnoseNameDTOList, styleMap));
|
|
|
+
|
|
|
+ Map<String, String> styleMap1 = new LinkedHashMap<>();
|
|
|
+ styleMap1.put(ExcelUtils.DATA_HEIGHT, "6");
|
|
|
+ exportDto.add(ExcelUtils.createOneSheet("诊断依据", null, ExportDiagnoseDTO.class, res, styleMap1));
|
|
|
+ // int i = 0;
|
|
|
+ // for (String key : diagnoseDetailsNew.keySet()) {
|
|
|
+ // if (i++ > 50) {
|
|
|
+ // // break;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // }
|
|
|
+ ExcelUtils.exportExcel(exportDto, "diagnose.xlsx", response);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, List<ExportDiagnoseDTO>> processDiagnoseDetail(Map<String, List<KlDiagnoseDetail>> diagnoseDetailMap) {
|
|
|
+ Map<String, List<ExportDiagnoseDTO>> data = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<KlDiagnoseDetail>> kd : diagnoseDetailMap.entrySet()) {
|
|
|
+ String sheetName = kd.getKey();
|
|
|
+ List<KlDiagnoseDetail> datats = kd.getValue();
|
|
|
+ Map<Integer, List<String>> typeCodeNewListMap = new HashMap<>();// 1 --> [1.0,1.1]
|
|
|
+ Map<Integer, List<String>> exportDiagnoseDTOS = removeKlDiagnoseDetail(datats, typeCodeNewListMap);
|
|
|
+ List<ExportDiagnoseDTO> exportDiagnoseDTO= packageData(exportDiagnoseDTOS, datats, typeCodeNewListMap);
|
|
|
+ data.put(sheetName,exportDiagnoseDTO);
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param exportDiagnoseDTOS 各种类型的关联词
|
|
|
+ * @param datats 诊断依据
|
|
|
+ * @param typeCodeNewListMap 各种类型的codes
|
|
|
+ */
|
|
|
+ public List<ExportDiagnoseDTO> packageData(Map<Integer, List<String>> exportDiagnoseDTOS,List<KlDiagnoseDetail> datats,Map<Integer, List<String>> typeCodeNewListMap){
|
|
|
+ List<ExportDiagnoseDTO> eds = Lists.newArrayList();
|
|
|
+ List<Integer> types = Lists.newArrayList(91, 92, 93);
|
|
|
+
|
|
|
+ Map<Integer, List<KlDiagnoseDetail>> typeDiagnoseDetails = EntityUtil.makeEntityListMap(datats, "type");
|
|
|
+ for (Map.Entry<Integer, List<String>> edd : exportDiagnoseDTOS.entrySet()) {
|
|
|
+ Integer type = edd.getKey();
|
|
|
+ List<KlDiagnoseDetail> klDiagnoseDetails = typeDiagnoseDetails.get(type);
|
|
|
+ List<String> relations = edd.getValue();
|
|
|
+ List<String> codes = typeCodeNewListMap.get(type);
|
|
|
+ String maxCode = codes.get(codes.size() - 1);
|
|
|
+ String[] maxCodeArray = maxCode.split("\\.");
|
|
|
+ Integer max = Integer.parseInt(maxCodeArray[1]);
|
|
|
+ for (String relation:relations) {
|
|
|
+ max += 1;
|
|
|
+ KlDiagnoseDetail klDiagnoseDetail = new KlDiagnoseDetail();
|
|
|
+ klDiagnoseDetail.setType(type);
|
|
|
+ klDiagnoseDetail.setCode(maxCodeArray[0]+"."+max);
|
|
|
+ klDiagnoseDetail.setStandard(relation);
|
|
|
+ klDiagnoseDetails.add(klDiagnoseDetail);
|
|
|
+ codes.add(maxCodeArray[0]+"."+max);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ Map<String,List<String>> typeCodeMap = new HashMap<>();//A --> [1.0,1.1,1.2,1.3]
|
|
|
+ Map<String,String> oldNewCodeMap = new HashMap<>();//1.0 -->A0
|
|
|
+ for (Map.Entry<Integer, List<KlDiagnoseDetail>> tdd : typeDiagnoseDetails.entrySet()) {
|
|
|
+ List<KlDiagnoseDetail> klDiagnoseDetails = tdd.getValue();
|
|
|
+ for (KlDiagnoseDetail kdl:klDiagnoseDetails) {
|
|
|
+ Integer type = kdl.getType();
|
|
|
+ String code = kdl.getCode();
|
|
|
+ String formula = kdl.getFormula();
|
|
|
+ String typeName = DiagnoseLexiconTypeEnum.getName(type);//A:症状
|
|
|
+
|
|
|
+ ExportDiagnoseDTO exportDiagnoseDTO = new ExportDiagnoseDTO();
|
|
|
+ BeanUtil.copyProperties(kdl, exportDiagnoseDTO);
|
|
|
+
|
|
|
+ if (!types.contains(type)) {
|
|
|
+ String tName = typeName.split(":")[1];//症状
|
|
|
+ String tType = typeName.split(":")[0];//A
|
|
|
+ String tCode = code.split("\\.")[1];
|
|
|
+ if(typeCodeMap.containsKey(tType)){
|
|
|
+ List<String> codes = typeCodeMap.get(tType);
|
|
|
+ List<String> collect = codes.stream().map(z -> z.split("\\.")[1]).sorted().collect(Collectors.toList());
|
|
|
+ if(collect.contains(tCode)){
|
|
|
+ String maxCode = collect.get(collect.size()-1);
|
|
|
+ tCode = String.valueOf(Integer.parseInt(maxCode)+1);
|
|
|
+ codes.add(String.valueOf(type)+"."+tCode);
|
|
|
+
|
|
|
+ }else {
|
|
|
+ codes.add(String.valueOf(type)+"."+tCode);
|
|
|
+ }
|
|
|
+ typeCodeMap.put(tType,codes);
|
|
|
+ }else {
|
|
|
+ List<String> codes = Lists.newArrayList();
|
|
|
+ codes.add(String.valueOf(type)+"."+tCode);
|
|
|
+ typeCodeMap.put(tType,codes);
|
|
|
+ }
|
|
|
+ ReflectUtil.setProperty(exportDiagnoseDTO, "type", tName);
|
|
|
+ ReflectUtil.setProperty(exportDiagnoseDTO, "orderNo", tType+String.valueOf(tCode));
|
|
|
+ oldNewCodeMap.put(code,tType+String.valueOf(tCode));
|
|
|
+ if (code.startsWith("3.") ) {
|
|
|
+ exportDiagnoseDTO.setRule(kdl.getRelation());
|
|
|
+ exportDiagnoseDTO.setRelation("");
|
|
|
+ } else {
|
|
|
+ exportDiagnoseDTO.setRule(kdl.getStandard());
|
|
|
+ }
|
|
|
+ if(code.startsWith("4.")){
|
|
|
+ exportDiagnoseDTO.setRule(kdl.getRelation());
|
|
|
+ exportDiagnoseDTO.setRelation(kdl.getStandard());
|
|
|
+ }
|
|
|
+ exportDiagnoseDTO.setEq(kdl.getMidResult());
|
|
|
+ }else {
|
|
|
+ ReflectUtil.setProperty(exportDiagnoseDTO, "type", typeName);
|
|
|
+ for (Map.Entry<String,String> typeq:oldNewCodeMap.entrySet()){
|
|
|
+ String oldCode = typeq.getKey();
|
|
|
+ String newCode = typeq.getValue();
|
|
|
+ formula = formula.replace(oldCode,newCode);
|
|
|
+ }
|
|
|
+ exportDiagnoseDTO.setRule(formula.replaceAll("/","、")
|
|
|
+ .replaceAll("\\(","[").replaceAll("\\)","]"));
|
|
|
+ }
|
|
|
+
|
|
|
+ eds.add(exportDiagnoseDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return eds;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成目录
|
|
|
+ *
|
|
|
+ * @param diagnoseDetails
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<ExportDiagnoseNameDTO> getCatalogue(Map<String, List<ExportDiagnoseDTO>> diagnoseDetails) {
|
|
|
+ List<ExportDiagnoseNameDTO> exportDiagnoseNameDTOList = Lists.newArrayList();
|
|
|
+ for (String key : diagnoseDetails.keySet()) {
|
|
|
+ ExportDiagnoseNameDTO exportDiagnoseNameDTO = new ExportDiagnoseNameDTO();
|
|
|
+ exportDiagnoseNameDTO.setName(key);
|
|
|
+ exportDiagnoseNameDTOList.add(exportDiagnoseNameDTO);
|
|
|
+ }
|
|
|
+ return exportDiagnoseNameDTOList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 移除公式编码中没有的数据
|
|
|
+ *
|
|
|
+ * @param klDiagnoseDetails
|
|
|
+ */
|
|
|
+ public Map<Integer, List<String>> removeKlDiagnoseDetail(List<KlDiagnoseDetail> klDiagnoseDetails, Map<Integer, List<String>> typeCodeNewListMap) {
|
|
|
+
|
|
|
+ Map<Integer, List<String>> typeRelationNamesMap = new HashMap<>();// 1 --> [症状1,症状2]
|
|
|
+
|
|
|
+ //获取所有公式
|
|
|
+ List<String> allFormula = getAllFormula(klDiagnoseDetails);
|
|
|
+ //获取公式中的所有编码
|
|
|
+ List<String> regexData = getCodes(allFormula);
|
|
|
+
|
|
|
+ //遍历病历
|
|
|
+ List<Integer> types = Stream.of(1, 2, 5, 6, 7, 8, 9).collect(Collectors.toList());
|
|
|
+ Iterator<KlDiagnoseDetail> iterator = klDiagnoseDetails.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ KlDiagnoseDetail next = iterator.next();
|
|
|
+ String code = next.getCode();//1.0
|
|
|
+ Integer type = next.getType();//1
|
|
|
+ String relation = next.getRelation();
|
|
|
+ if (!regexData.contains(code) && StringUtil.isNotBlank(code)) {
|
|
|
+ iterator.remove();
|
|
|
+ } else {
|
|
|
+ if (StringUtil.isNotBlank(relation) && types.contains(type)) {
|
|
|
+ List<String> relationNames = Lists.newArrayList(relation.split("\\、"));
|
|
|
+ if (typeRelationNamesMap.containsKey(type)) {
|
|
|
+ List<String> contionNames = typeRelationNamesMap.get(type);
|
|
|
+ contionNames.addAll(relationNames);
|
|
|
+ typeRelationNamesMap.put(type, contionNames);
|
|
|
+ } else {
|
|
|
+ typeRelationNamesMap.put(type, relationNames);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(code)) {
|
|
|
+ if (typeCodeNewListMap.containsKey(type)) {
|
|
|
+ List<String> codes = typeCodeNewListMap.get(type);
|
|
|
+ codes.add(code);
|
|
|
+ typeCodeNewListMap.put(type, codes);
|
|
|
+ } else {
|
|
|
+ List<String> codes = Lists.newArrayList();
|
|
|
+ codes.add(code);
|
|
|
+ typeCodeNewListMap.put(type, codes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return typeRelationNamesMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取每个诊断依据的公式
|
|
|
+ *
|
|
|
+ * @param klDiagnoseDetails
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<String> getAllFormula(List<KlDiagnoseDetail> klDiagnoseDetails) {
|
|
|
+ List<String> formulas = Lists.newArrayList();
|
|
|
+ if (ListUtil.isNotEmpty(klDiagnoseDetails)) {
|
|
|
+ formulas = klDiagnoseDetails.stream().filter(x -> StringUtil.isBlank(x.getCode()) && StringUtil.isNotBlank(x.getFormula()))
|
|
|
+ .map(x -> x.getFormula()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ }
|
|
|
+ return formulas;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取公式中的所有编码
|
|
|
+ *
|
|
|
+ * @param formulas
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<String> getCodes(List<String> formulas) {
|
|
|
+ String pateern = "([1-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9])";
|
|
|
+ String content = formulas.stream().collect(Collectors.joining(","));
|
|
|
+ //获取公式中的编码
|
|
|
+ return RegexUtil.getRegexDatas(content, pateern);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|