Browse Source

医学规则测试

zhaops 4 năm trước cách đây
mục cha
commit
c73c5c3e5c

+ 14 - 0
cdssman-service/src/main/java/com/diagbot/entity/ResultBill.java

@@ -152,6 +152,11 @@ public class ResultBill implements Serializable {
      */
     private String message;
 
+    /**
+     * 模拟入参
+     */
+    private String inputParams;
+
     public Long getId() {
         return id;
     }
@@ -360,6 +365,14 @@ public class ResultBill implements Serializable {
         this.message = message;
     }
 
+    public String getInputParams() {
+        return inputParams;
+    }
+
+    public void setInputParams(String inputParams) {
+        this.inputParams = inputParams;
+    }
+
     @Override
     public String toString() {
         return "ResultBill{" +
@@ -389,6 +402,7 @@ public class ResultBill implements Serializable {
                 ", expectedOutput=" + expectedOutput +
                 ", success=" + success +
                 ", message=" + message +
+                ", inputParams" + inputParams +
                 "}";
     }
 }

+ 2 - 0
cdssman-service/src/main/java/com/diagbot/entity/node/BillItem.java

@@ -34,4 +34,6 @@ public class BillItem {
     private String conditionUnit;
     private Integer conditionRange;
     private Integer conditionStatus;
+
+    private String remark;
 }

+ 53 - 0
cdssman-service/src/main/java/com/diagbot/facade/DrugTypeFacade.java

@@ -0,0 +1,53 @@
+package com.diagbot.facade;
+
+import com.diagbot.repository.BaseNodeRepository;
+import com.google.common.collect.Lists;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2021/1/12 16:18
+ */
+@Component
+public class DrugTypeFacade {
+    @Autowired
+    private BaseNodeRepository baseNodeRepository;
+
+    public Map<String, List<String>> getDrugTypeMap() {
+        List<String> medClass = Lists.newArrayList();
+        Map<String, List<String>> medClassMap = new HashMap<>();
+
+        List<String> medHuaXueClass = baseNodeRepository.getMedHuaXueClass();
+        List<String> medJiePouClass = baseNodeRepository.getMedJiePouClass();
+        List<String> medYaoLiClass = baseNodeRepository.getMedYaoLiClass();
+        List<String> medZhiLiaoClass = baseNodeRepository.getMedZhiLiaoClass();
+
+        medClass.addAll(medHuaXueClass);
+        medClass.addAll(medJiePouClass);
+        medClass.addAll(medYaoLiClass);
+        medClass.addAll(medZhiLiaoClass);
+
+        for (String medcls : medClass) {
+            String[] spres = medcls.split("::");
+            String med_type = spres[1];
+            String med_name = spres[0];
+
+            if (medClassMap.get(med_type) == null) {
+                medClassMap.put(med_type, new ArrayList<>());
+            }
+            if (medClassMap.get(med_type).indexOf(med_name) == -1) {
+                medClassMap.get(med_type).add(med_name);
+            }
+        }
+
+        return medClassMap;
+    }
+
+}

+ 279 - 136
cdssman-service/src/main/java/com/diagbot/facade/RuleConvertFacade.java

@@ -13,6 +13,7 @@ import com.diagbot.util.BeanUtil;
 import com.diagbot.util.EntityUtil;
 import com.diagbot.util.ListUtil;
 import com.diagbot.util.MsgUtil;
+import com.diagbot.util.StringUtil;
 import com.google.common.collect.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -45,10 +46,15 @@ public class RuleConvertFacade {
 
     @Autowired
     private MedicineRepository medicineRepository;
+    @Autowired
+    private DrugTypeFacade drugTypeFacade;
 
     public List<ResultBill> billRuleConvert(List<BillItem> billItems, Long hospitalId) {
         List<ResultBill> retList = Lists.newLinkedList();
         List<ResultBill> resultBillList = Lists.newLinkedList();
+        List<ResultBill> retMedNameList=Lists.newArrayList();
+        List<ResultBill> retBillList = Lists.newArrayList();
+        List<ResultBill> retConflictList = Lists.newArrayList();
 
         if (ListUtil.isEmpty(billItems)) {
             return resultBillList;
@@ -62,6 +68,9 @@ public class RuleConvertFacade {
             medNameRegNameMap.put(entry.getKey(), entry.getValue().stream().map(i -> i.getMedName()).collect(Collectors.toList()));
         });
 
+        //药物过敏原药品分类转药品
+        Map<String, List<String>> medClassMap = drugTypeFacade.getDrugTypeMap();
+
         Map<String, Map<String, Map<String, List<Long>>>> lisConfigMap = lisConfigFacade.getUniqueConfigMap(hospitalId, null, null);
         Map<String, Map<String, List<Long>>> pacsConfigMap = pacsConfigFacade.getUniqueConfigMap(hospitalId, null, null);
         Map<String, Map<String, Map<String, List<Long>>>> drugConfigMap = drugConfigFacade.getUniqueConfigMap(hospitalId, null, null);
@@ -70,150 +79,206 @@ public class RuleConvertFacade {
         Map<String, Map<String, List<Long>>> transfusionConfigMap = transfusionConfigFacade.getUniqueConfigMap(hospitalId, null, null);
 
 
-        int count=1;
         for (BillItem billItem : billItems) {
-            System.out.println(count++ +",id:"+billItem.getConceptId()+"name:"+billItem.getConceptName()+",type:"+billItem.getConceptLabel());
-            List<MappingShortEntity> billMappingList = Lists.newArrayList();
-            List<MappingShortEntity> conflictMappingList = Lists.newArrayList();
+            //基础属性复制
+            ResultBill resultBill = new ResultBill();
+            resultBill.setBillType(1);
+            resultBill.setBillItemType(billItem.getConceptLabel());
+            resultBill.setBillItemName(billItem.getConceptName());
+            resultBill.setConflictItemType(billItem.getConditionLabel());
+            resultBill.setConflictItemName(billItem.getConditionName());
+            if (billItem.getConditionMaxValue() != null) {
+                resultBill.setMaxValue(BigDecimal.valueOf(billItem.getConditionMaxValue()));
+            }
+            if (billItem.getConditionMinValue() != null) {
+                resultBill.setMinValue(BigDecimal.valueOf(billItem.getConditionMinValue()));
+            }
+            resultBill.setConflictItemRange(billItem.getConditionRange());
+            resultBill.setUnit(billItem.getConditionUnit());
 
-            if (billItem.getConceptLabel().equals(GraphLabelEnum.LisSet.getName())) {
-                Map<String, Map<String, List<Long>>> subMap = lisConfigMap.get(billItem.getConceptName());
+            if (resultBill.getConflictItemType().equals(GraphLabelEnum.MedAllergen.getName())) {
+                List<String> medNameList = medClassMap.get(billItem.getConditionName());
+                if (ListUtil.isNotEmpty(medNameList)) {
+                    for (String medName : medNameList) {
+                        ResultBill resultBill1Ext = new ResultBill();
+                        BeanUtil.copyProperties(resultBill, resultBill1Ext);
+                        resultBill1Ext.setReferenceValue(resultBill1Ext.getConflictItemName());
+                        resultBill1Ext.setConflictItemName(medName);
+                        resultBillList.add(resultBill1Ext);
+                    }
+                } else {
+                    resultBillList.add(resultBill);
+                }
+            } else {
+                resultBillList.add(resultBill);
+            }
+        }
+
+        //药品注册名转通用名
+        for (ResultBill resultBill : resultBillList) {
+            if (resultBill.getBillItemType().equals(GraphLabelEnum.MedRegName.getName())) {
+                List<String> medNameList = medNameRegNameMap.get(resultBill.getBillItemName());
+                if (ListUtil.isNotEmpty(medNameList)) {
+                    for (String medName : medNameList) {
+                        ResultBill resultBill1Ext = new ResultBill();
+                        BeanUtil.copyProperties(resultBill, resultBill1Ext);
+                        resultBill1Ext.setReferenceValue(resultBill1Ext.getBillItemName());
+                        resultBill1Ext.setBillItemName(medName);
+                        retMedNameList.add(resultBill1Ext);
+                    }
+                } else {
+                    resultBill.setSuccess(0);
+                    resultBill.setMessage("药品注册名称找不到对应药品通用名称;");
+                    retMedNameList.add(resultBill);
+                }
+            } else {
+                retMedNameList.add(resultBill);
+            }
+        }
+
+        //数据映射-开单项转换
+        for (ResultBill resultBill : retMedNameList) {
+            List<MappingShortEntity> billMappingList = Lists.newArrayList();
+            if (resultBill.getBillItemType().equals(GraphLabelEnum.LisSet.getName())) {
+                Map<String, Map<String, List<Long>>> subMap = lisConfigMap.get(resultBill.getBillItemName());
                 if (subMap != null) {
                     subMap.entrySet().forEach(subEntry -> {
                         if (subEntry.getValue() != null && subEntry.getValue().size() > 0) {
                             subEntry.getValue().entrySet().forEach(detailEntry -> {
-                                billMappingList.add(setMappingShortEntity(billItem.getConceptName(), subEntry.getKey(), detailEntry.getKey()));
+                                billMappingList.add(setMappingShortEntity(resultBill.getBillItemName(), subEntry.getKey(), detailEntry.getKey()));
                             });
                         } else {
-                            billMappingList.add(setMappingShortEntity(billItem.getConceptName(), subEntry.getKey(), ""));
+                            billMappingList.add(setMappingShortEntity(resultBill.getBillItemName(), subEntry.getKey(), ""));
                         }
                     });
                 }
-            } else if (billItem.getConceptLabel().equals(GraphLabelEnum.PacsName.getName())
-                    || billItem.getConceptLabel().equals(GraphLabelEnum.PacsSubName.getName())) {
-                Map<String, List<Long>> subMap = pacsConfigMap.get(billItem.getConceptName());
+            } else if (resultBill.getBillItemType().equals(GraphLabelEnum.PacsName.getName())
+                    || resultBill.getBillItemType().equals(GraphLabelEnum.PacsSubName.getName())) {
+                Map<String, List<Long>> subMap = pacsConfigMap.get(resultBill.getBillItemName());
                 if (subMap != null) {
                     subMap.entrySet().forEach(subEntry -> {
-                        billMappingList.add(setMappingShortEntity(billItem.getConceptName(), subEntry.getKey(), ""));
+                        billMappingList.add(setMappingShortEntity(resultBill.getBillItemName(), subEntry.getKey(), ""));
                     });
                 }
-            } else if (billItem.getConceptLabel().equals(GraphLabelEnum.YiBaoOperationName.getName())) {
-                Map<String, List<Long>> subMap = operationConfigMap.get(billItem.getConceptName());
+            } else if (resultBill.getBillItemType().equals(GraphLabelEnum.YiBaoOperationName.getName())) {
+                Map<String, List<Long>> subMap = operationConfigMap.get(resultBill.getBillItemName());
                 if (subMap != null) {
                     subMap.entrySet().forEach(subEntry -> {
-                        billMappingList.add(setMappingShortEntity(billItem.getConceptName(), subEntry.getKey(), ""));
+                        billMappingList.add(setMappingShortEntity(resultBill.getBillItemName(), subEntry.getKey(), ""));
                     });
                 }
-            } else if (billItem.getConceptLabel().equals(GraphLabelEnum.MedRegName.getName())) {
-                if (medNameRegNameMap.containsKey(billItem.getConceptName())) {
-                    List<String> medNames = medNameRegNameMap.get(billItem.getConceptName());
-                    for (String medName : medNames) {
-                        Map<String, Map<String, List<Long>>> subMap = drugConfigMap.get(medName);
-                        if (subMap != null) {
-                            subMap.entrySet().forEach(subEntry -> {
-                                billMappingList.add(setMappingShortEntity(billItem.getConceptName(), subEntry.getKey(), ""));
-                            });
-                        }
+            } else if (resultBill.getBillItemType().equals(GraphLabelEnum.MedRegName.getName())) {
+                if (medNameRegNameMap.containsKey(resultBill.getBillItemName())) {
+                    Map<String, Map<String, List<Long>>> subMap = drugConfigMap.get(resultBill.getBillItemName());
+                    if (subMap != null) {
+                        subMap.entrySet().forEach(subEntry -> {
+                            billMappingList.add(setMappingShortEntity(resultBill.getBillItemName(), subEntry.getKey(), ""));
+                        });
                     }
                 }
             }
 
-            if (billItem.getConditionLabel().equals(GraphLabelEnum.Lis.getName())) {
-                Map<String, Map<String, List<Long>>> subMap = lisConfigMap.get(billItem.getConditionName());
+            if (ListUtil.isEmpty(billMappingList)) {
+                resultBill.setSuccess(0);
+                resultBill.setMessage(StringUtil.isNotBlank(resultBill.getMessage())
+                        ? resultBill.getMessage()
+                        : ""
+                        + "开单项缺少医院端映射;");
+                retBillList.add(resultBill);
+            } else {
+                billMappingList.forEach(billMappingItem -> {
+                    ResultBill addResultBill = new ResultBill();
+                    BeanUtil.copyProperties(resultBill, addResultBill);
+                    addResultBill.setBillItemHisName(billMappingItem.getHisName());
+                    addResultBill.setBillItemHisDetailName(billMappingItem.getHisDetailName());
+                    retBillList.add(addResultBill);
+                });
+            }
+        }
+
+        //数据映射-禁忌项转换
+        for (ResultBill resultBill : retBillList) {
+            List<MappingShortEntity> conflictMappingList = Lists.newArrayList();
+            if (resultBill.getConflictItemType().equals(GraphLabelEnum.Lis.getName())) {
+                Map<String, Map<String, List<Long>>> subMap = lisConfigMap.get(resultBill.getConflictItemName());
                 if (subMap != null) {
                     subMap.entrySet().forEach(subEntry -> {
                         if (subEntry.getValue() != null && subEntry.getValue().size() > 0) {
                             subEntry.getValue().entrySet().forEach(detailEntry -> {
-                                conflictMappingList.add(setMappingShortEntity(billItem.getConditionName(), subEntry.getKey(), detailEntry.getKey()));
+                                conflictMappingList.add(setMappingShortEntity(resultBill.getConflictItemName(), subEntry.getKey(), detailEntry.getKey()));
                             });
                         } else {
-                            conflictMappingList.add(setMappingShortEntity(billItem.getConditionName(), subEntry.getKey(), ""));
+                            conflictMappingList.add(setMappingShortEntity(resultBill.getConflictItemName(), subEntry.getKey(), ""));
                         }
                     });
                 }
-            } else if (billItem.getConditionLabel().equals(GraphLabelEnum.BillConflictItem.getName())) {
-                Map<String, List<Long>> subMap = pacsConfigMap.get(billItem.getConditionName());
+            } else if (resultBill.getConflictItemType().equals(GraphLabelEnum.BillConflictItem.getName())) {
+                Map<String, List<Long>> subMap = pacsConfigMap.get(resultBill.getConflictItemName());
                 if (subMap != null) {
                     subMap.entrySet().forEach(subEntry -> {
-                        conflictMappingList.add(setMappingShortEntity(billItem.getConditionName(), subEntry.getKey(), ""));
+                        conflictMappingList.add(setMappingShortEntity(resultBill.getConflictItemName(), subEntry.getKey(), ""));
                     });
                 }
-            } else if (billItem.getConditionLabel().equals(GraphLabelEnum.Disease.getName())) {
-                Map<String, List<Long>> subMap = diseaseConfigMap.get(billItem.getConditionName());
+            } else if (resultBill.getConflictItemType().equals(GraphLabelEnum.Disease.getName())) {
+                Map<String, List<Long>> subMap = diseaseConfigMap.get(resultBill.getConflictItemName());
                 if (subMap != null) {
                     subMap.entrySet().forEach(subEntry -> {
-                        conflictMappingList.add(setMappingShortEntity(billItem.getConditionName(), subEntry.getKey(), ""));
+                        conflictMappingList.add(setMappingShortEntity(resultBill.getConflictItemName(), subEntry.getKey(), ""));
                     });
                 }
-            } else if (billItem.getConditionLabel().equals(GraphLabelEnum.OralMedicine.getName())
-                    || billItem.getConditionLabel().equals(GraphLabelEnum.MedAllergen.getName())) {
-                Map<String, Map<String, List<Long>>> subMap = drugConfigMap.get(billItem.getConditionName());
+            } else if (resultBill.getConflictItemType().equals(GraphLabelEnum.OralMedicine.getName())) {
+                Map<String, Map<String, List<Long>>> subMap = drugConfigMap.get(resultBill.getConflictItemName());
                 if (subMap != null) {
                     subMap.entrySet().forEach(subEntry -> {
-                        conflictMappingList.add(setMappingShortEntity(billItem.getConditionName(), subEntry.getKey(), ""));
+                        conflictMappingList.add(setMappingShortEntity(resultBill.getConflictItemName(), subEntry.getKey(), ""));
+                    });
+                }
+            } else if (resultBill.getConflictItemType().equals(GraphLabelEnum.MedAllergen.getName())) {
+                List<String> medNameList = medClassMap.get(resultBill.getConflictItemName());
+                if (ListUtil.isNotEmpty(medNameList)) {
+                    medNameList.forEach(medName -> {
+                        Map<String, Map<String, List<Long>>> subMap = drugConfigMap.get(medName);
+                        if (subMap != null) {
+                            subMap.entrySet().forEach(subEntry -> {
+                                conflictMappingList.add(setMappingShortEntity(resultBill.getConflictItemName(), subEntry.getKey(), ""));
+                            });
+                        }
                     });
                 }
             }
 
-            //基础属性复制
-            ResultBill resultBill = new ResultBill();
-            resultBill.setBillType(1);
-            resultBill.setBillItemType(billItem.getConceptLabel());
-            resultBill.setBillItemName(billItem.getConceptName());
-            resultBill.setConflictItemType(billItem.getConditionLabel());
-            resultBill.setConflictItemName(billItem.getConditionName());
-            if (billItem.getConditionMaxValue() != null) {
-                resultBill.setMaxValue(BigDecimal.valueOf(billItem.getConditionMaxValue()));
-            }
-            if (billItem.getConditionMinValue() != null) {
-                resultBill.setMinValue(BigDecimal.valueOf(billItem.getConditionMinValue()));
-            }
-            resultBill.setConflictItemRange(billItem.getConditionRange());
-            resultBill.setUnit(billItem.getConditionUnit());
-            if (ListUtil.isEmpty(billMappingList)) {
-                if (ListUtil.isEmpty(conflictMappingList)) {
-                    ResultBill addResultBill = new ResultBill();
-                    BeanUtil.copyProperties(resultBill, addResultBill);
-                    resultBillList.add(addResultBill);
-                } else {
-                    conflictMappingList.forEach(conflictItem -> {
-                        ResultBill addResultBill = new ResultBill();
-                        BeanUtil.copyProperties(resultBill, addResultBill);
-                        addResultBill.setConflictItemHisName(conflictItem.getHisName());
-                        addResultBill.setConflictItemHisDetailName(conflictItem.getHisDetailName());
-                        resultBillList.add(addResultBill);
-                    });
+
+            if (ListUtil.isEmpty(conflictMappingList)) {
+                if (resultBill.getConflictItemType().equals(GraphLabelEnum.MedAllergen.getName())
+                        || resultBill.getConflictItemType().equals(GraphLabelEnum.OralMedicine.getName())
+                        || resultBill.getConflictItemType().equals(GraphLabelEnum.Lis.getName())
+                        || resultBill.getConflictItemType().equals(GraphLabelEnum.BillConflictItem.getName())
+                        || resultBill.getConflictItemType().equals(GraphLabelEnum.Disease.getName())) {
+                    resultBill.setSuccess(0);
+                    resultBill.setMessage(StringUtil.isNotBlank(resultBill.getMessage())
+                            ? resultBill.getMessage()
+                            : "" +
+                            "禁忌项缺少医院端映射;");
                 }
+                retConflictList.add(resultBill);
             } else {
-                if (ListUtil.isEmpty(conflictMappingList)) {
-                    billMappingList.forEach(billMappingItem -> {
-                        ResultBill addResultBill = new ResultBill();
-                        BeanUtil.copyProperties(resultBill, addResultBill);
-                        addResultBill.setBillItemHisName(billMappingItem.getHisName());
-                        addResultBill.setBillItemHisDetailName(billMappingItem.getHisDetailName());
-                        resultBillList.add(addResultBill);
-                    });
-                } else {
-                    billMappingList.forEach(billMappingItem -> {
-                        ResultBill addResultBill = new ResultBill();
-                        BeanUtil.copyProperties(resultBill, addResultBill);
-                        addResultBill.setBillItemHisName(billMappingItem.getHisName());
-                        addResultBill.setBillItemHisDetailName(billMappingItem.getHisDetailName());
-                        conflictMappingList.forEach(conflictItem -> {
-                            ResultBill addExtResultBill = new ResultBill();
-                            BeanUtil.copyProperties(addResultBill, addExtResultBill);
-                            addExtResultBill.setConflictItemHisName(conflictItem.getHisName());
-                            addExtResultBill.setConflictItemHisDetailName(conflictItem.getHisDetailName());
-                            resultBillList.add(addExtResultBill);
-                        });
-                    });
-                }
+                conflictMappingList.forEach(conflictItem -> {
+                    ResultBill addResultBill = new ResultBill();
+                    BeanUtil.copyProperties(resultBill, addResultBill);
+                    addResultBill.setConflictItemHisName(conflictItem.getHisName());
+                    addResultBill.setConflictItemHisDetailName(conflictItem.getHisDetailName());
+                    retConflictList.add(addResultBill);
+                });
             }
         }
 
+
         //模拟输入值
-        for (ResultBill result : resultBillList) {
-            String orderType = getOrderType(result.getBillItemType());
+        for (ResultBill result : retConflictList) {
+            if (result.getSuccess() != null && result.getSuccess().equals(0)) {
+                retList.add(result);
+                continue;
+            }
             if (result.getMaxValue() != null || result.getMinValue() != null) {
                 if (result.getConflictItemRange() == null) {
                     result.setConflictItemRange(0);
@@ -223,11 +288,7 @@ public class RuleConvertFacade {
                         ResultBill minResult = new ResultBill();
                         BeanUtil.copyProperties(result, minResult);
                         minResult.setInputValue(random(null, result.getMinValue()).toString());
-                        BillMsg billMsg = MsgUtil.getCommonBillMsg(minResult.getBillItemHisName(),
-                                minResult.getBillItemName(),
-                                minResult.getInputValue(),
-                                "禁忌" + minResult.getConflictItemType(),
-                                orderType);
+                        BillMsg billMsg = getBillMsg(minResult);
                         minResult.setExpectedOutput(billMsg.getMsg());
                         retList.add(minResult);
                     }
@@ -235,31 +296,18 @@ public class RuleConvertFacade {
                         ResultBill maxResult = new ResultBill();
                         BeanUtil.copyProperties(result, maxResult);
                         maxResult.setInputValue(random(result.getMaxValue(), null).toString());
-                        BillMsg billMsg = MsgUtil.getCommonBillMsg(maxResult.getBillItemHisName(),
-                                maxResult.getBillItemName(),
-                                maxResult.getInputValue(),
-                                "禁忌" + maxResult.getConflictItemType(),
-                                orderType);
+                        BillMsg billMsg = getBillMsg(maxResult);
                         maxResult.setExpectedOutput(billMsg.getMsg());
                         retList.add(maxResult);
                     }
                 } else {
                     result.setInputValue(random(result.getMinValue(), result.getMaxValue()).toString());
-                    BillMsg billMsg = MsgUtil.getCommonBillMsg(result.getBillItemHisName(),
-                            result.getBillItemName(),
-                            result.getInputValue(),
-                            "禁忌" + result.getConflictItemType(),
-                            orderType);
+                    BillMsg billMsg = getBillMsg(result);
                     result.setExpectedOutput(billMsg.getMsg());
                     retList.add(result);
                 }
             } else {
-                //result.setInputValue(result.getConflictItemName());
-                BillMsg billMsg = MsgUtil.getCommonBillMsg(result.getBillItemHisName(),
-                        result.getBillItemName(),
-                        result.getConflictItemName(),
-                        "禁忌" + result.getConflictItemType(),
-                        orderType);
+                BillMsg billMsg = getBillMsg(result);
                 result.setExpectedOutput(billMsg.getMsg());
                 retList.add(result);
             }
@@ -275,6 +323,85 @@ public class RuleConvertFacade {
         return item;
     }
 
+    /**
+     * 模拟提示信息
+     *
+     * @param resultBill
+     * @return
+     */
+    public BillMsg getBillMsg(ResultBill resultBill) {
+        BillMsg billMsg = new BillMsg();
+        String orderType = getOrderType(resultBill.getBillItemType());
+        if (resultBill.getConflictItemType().equals(GraphLabelEnum.BillConflictItem.getName())) {
+            //互斥项
+            billMsg = MsgUtil.getBillExclusionMsg(resultBill.getBillItemHisName(),
+                    resultBill.getConflictItemHisName(),
+                    resultBill.getConflictItemHisName(),
+                    "禁忌" + resultBill.getConflictItemType());
+        } else if (resultBill.getConflictItemType().equals(GraphLabelEnum.ConflictDevice.getName())) {
+            //禁忌医疗器械及物品提示信息
+            billMsg = MsgUtil.getBillMedEquMsg(resultBill.getBillItemHisName(),
+                    resultBill.getBillItemName(),
+                    resultBill.getConflictItemName(),
+                    "禁忌" + resultBill.getConflictItemType(),
+                    orderType);
+        } else if (resultBill.getConflictItemType().equals(GraphLabelEnum.YiBaoOperationName.getName())) {
+            //禁忌手术
+            billMsg = MsgUtil.getCommonSurgeryMsg(resultBill.getBillItemHisName(),
+                    resultBill.getBillItemName(),
+                    resultBill.getConflictItemHisName(),
+                    "禁忌" + resultBill.getConflictItemType(),
+                    orderType);
+        } else if (resultBill.getConflictItemType().equals(GraphLabelEnum.OralMedicine.getName())) {
+            //禁忌服用药品
+            billMsg = MsgUtil.getCommonBillMsg(resultBill.getBillItemHisName(),
+                    resultBill.getBillItemName(),
+                    "可能正在用药" + resultBill.getConflictItemHisName(),
+                    "禁忌" + resultBill.getConflictItemType(),
+                    orderType);
+        } else if (resultBill.getConflictItemType().equals(GraphLabelEnum.MedAllergen.getName())
+                || resultBill.getConflictItemType().equals(GraphLabelEnum.Allergen.getName())) {
+            //禁忌药物过敏原/食物过敏原/过敏原
+            billMsg = MsgUtil.getCommonBillMsg(resultBill.getBillItemHisName(),
+                    resultBill.getBillItemName(),
+                    StringUtil.isNotBlank(resultBill.getConflictItemHisName())
+                            ? resultBill.getConflictItemHisName()
+                            : resultBill.getConflictItemName()
+                            + "过敏",
+                    "禁忌" + resultBill.getConflictItemType(),
+                    orderType);
+        }else if (resultBill.getConflictItemType().equals(GraphLabelEnum.Group.getName())) {
+            //禁忌禁忌人群
+            billMsg = MsgUtil.getCommonBillMsg(resultBill.getBillItemHisName(),
+                    resultBill.getBillItemName(),
+                    resultBill.getConflictItemName(),
+                    "禁忌" + resultBill.getConflictItemType(),
+                    orderType);
+        } else {
+            //通用
+            String content = "";
+            if (StringUtil.isNotBlank(resultBill.getConflictItemHisName())) {
+                content = resultBill.getConflictItemHisName();
+            }
+            if (StringUtil.isNotBlank(resultBill.getConflictItemHisDetailName())
+                    && !resultBill.getConflictItemHisName().equals(resultBill.getConflictItemHisDetailName())) {
+                content += resultBill.getConflictItemHisDetailName();
+            }
+            if (StringUtil.isBlank(content)) {
+                content += resultBill.getConflictItemName();
+            }
+            if (StringUtil.isNotBlank(resultBill.getInputValue())) {
+                content += trimZero(resultBill.getInputValue());
+            }
+            billMsg = MsgUtil.getCommonBillMsg(resultBill.getBillItemHisName(),
+                    resultBill.getBillItemName(),
+                    content,
+                    "禁忌" + resultBill.getConflictItemType(),
+                    orderType);
+        }
+        return billMsg;
+    }
+
     /**
      * 生成随机数
      *
@@ -295,41 +422,57 @@ public class RuleConvertFacade {
 
     /**
      * 开单类型转换
+     *
      * @param type
      * @return
      */
-    public String getOrderType(String type){
-        String orderType="";
-        if(type.equals(GraphLabelEnum.LisSet.getName())){
-            orderType=TypeEnum.lis.getName();
+    public String getOrderType(String type) {
+        String orderType = "";
+        if (type.equals(GraphLabelEnum.LisSet.getName())) {
+            orderType = TypeEnum.lis.getName();
         }
-        if(type.equals(GraphLabelEnum.PacsName)
-                ||type.equals(GraphLabelEnum.PacsSubName)){
-            orderType=TypeEnum.pacs.getName();
+        if (type.equals(GraphLabelEnum.PacsName)
+                || type.equals(GraphLabelEnum.PacsSubName)) {
+            orderType = TypeEnum.pacs.getName();
         }
-        if(type.equals(GraphLabelEnum.YiBaoDiseaseName.getName())){
-            orderType=TypeEnum.disease.getName();
+        if (type.equals(GraphLabelEnum.YiBaoDiseaseName.getName())) {
+            orderType = TypeEnum.disease.getName();
         }
-        if(type.equals(GraphLabelEnum.MedRegName.getName())
-                ||type.equals(GraphLabelEnum.Medicine.getName())){
-            orderType=TypeEnum.drug.getName();
+        if (type.equals(GraphLabelEnum.MedRegName.getName())
+                || type.equals(GraphLabelEnum.Medicine.getName())) {
+            orderType = TypeEnum.drug.getName();
         }
-        if(type.equals(GraphLabelEnum.ClinicalFinding.getName())){
-            orderType=TypeEnum.clinical.getName();
+        if (type.equals(GraphLabelEnum.ClinicalFinding.getName())) {
+            orderType = TypeEnum.clinical.getName();
         }
-        if(type.equals(GraphLabelEnum.YiBaoOperationName.getName())){
-            orderType=TypeEnum.operation.getName();
+        if (type.equals(GraphLabelEnum.YiBaoOperationName.getName())) {
+            orderType = TypeEnum.operation.getName();
         }
-        if(type.equals(GraphLabelEnum.Vital.getName())){
-            orderType=TypeEnum.vital.getName();
+        if (type.equals(GraphLabelEnum.Vital.getName())) {
+            orderType = TypeEnum.vital.getName();
         }
-        if(type.equals(GraphLabelEnum.TransfusionRemind.getName())
-                ||type.equals(GraphLabelEnum.TransfusionSuggest.getName())){
-            orderType=TypeEnum.transfusion.getName();
+        if (type.equals(GraphLabelEnum.TransfusionRemind.getName())
+                || type.equals(GraphLabelEnum.TransfusionSuggest.getName())) {
+            orderType = TypeEnum.transfusion.getName();
         }
-        if(type.equals(GraphLabelEnum.Age.getName())){
-            orderType=TypeEnum.age.getName();
+        if (type.equals(GraphLabelEnum.Age.getName())) {
+            orderType = TypeEnum.age.getName();
         }
         return orderType;
     }
+
+    /**
+     * 去除小数点末位的0,如果都是0同时去除小数点
+     *
+     * @param s
+     * @return
+     */
+    public String trimZero(String s) {
+        if (s.indexOf(".") > 0) {
+            //正则表达
+            s = s.replaceAll("0+?$", "");//去掉后面无用的零
+            s = s.replaceAll("[.]$", "");//如小数点后面全是零则去掉小数点
+        }
+        return s;
+    }
 }

+ 33 - 12
cdssman-service/src/main/java/com/diagbot/facade/RuleTestFacade.java

@@ -25,7 +25,9 @@ import com.diagbot.repository.PacsCriticalRepository;
 import com.diagbot.repository.TransfusionRemindRepository;
 import com.diagbot.service.ResultBillService;
 import com.diagbot.service.ResultInfoService;
+import com.diagbot.util.BeanUtil;
 import com.diagbot.util.ExcelUtils;
+import com.diagbot.util.FastJsonUtils;
 import com.diagbot.util.ListUtil;
 import com.diagbot.util.RespDTOUtil;
 import com.diagbot.vo.HospitalIdVO;
@@ -33,8 +35,6 @@ import com.diagbot.vo.IndicationPushVO;
 import com.diagbot.vo.RuleTestVO;
 import com.google.common.collect.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Component;
 
 import javax.servlet.http.HttpServletResponse;
@@ -120,9 +120,19 @@ public class RuleTestFacade {
             return;
         }
 
+        List<ResultBill> saveList = Lists.newArrayList();
+
         for (ResultBill resultBill : resultList) {
+            if (resultBill.getSuccess() != null
+                    && resultBill.getSuccess().equals(0)) {
+                saveList.add(resultBill);
+                continue;
+            }
             IndicationPushVO indicationPushVO = searchDataFacade.creatBillVO(resultBill);
             indicationPushVO.setHospitalId(hospitalId);
+
+            resultBill.setInputParams(FastJsonUtils.getBeanToJson(indicationPushVO));
+
             RespDTO<IndicationDTO> respDTO = cdssCoreClient.indication(indicationPushVO);
             if (RespDTOUtil.respIsOK(respDTO)) {
                 IndicationDTO data = respDTO.data;
@@ -130,24 +140,32 @@ public class RuleTestFacade {
                 if (ListUtil.isEmpty(billMsgList)) {
                     resultBill.setSuccess(0);
                     resultBill.setMessage("未提示开单项");
+                    saveList.add(resultBill);
                 } else {
                     /*private String referenceValue;*/
-                    resultBill.setOutput(billMsgList.get(0).getMsg());
-                    if (resultBill.getOutput().equals(resultBill.getExpectedOutput())) {
-                        resultBill.setSuccess(1);
-                    } else {
-                        resultBill.setSuccess(0);
+                    for (BillMsg billMsg : billMsgList) {
+                        ResultBill saveResultBill = new ResultBill();
+                        BeanUtil.copyProperties(resultBill, saveResultBill);
+                        saveResultBill.setOutput(billMsg.getMsg());
+                        if (saveResultBill.getOutput().equals(saveResultBill.getExpectedOutput())) {
+                            saveResultBill.setSuccess(1);
+                        } else {
+                            saveResultBill.setSuccess(0);
+                            saveResultBill.setMessage("提示内容与预期不符");
+                        }
+                        saveList.add(saveResultBill);
                     }
                 }
             } else {
                 resultBill.setSuccess(0);
                 resultBill.setMessage("远程调用推理接口失败");
+                saveList.add(resultBill);
             }
         }
 
-        Integer totleNum = resultList.size();
-        Integer successNum = resultList.stream().filter(i -> i.getSuccess().equals(1)).collect(Collectors.toList()).size();
-        Integer failedNum = resultList.stream().filter(i -> i.getSuccess().equals(0)).collect(Collectors.toList()).size();
+        Integer totleNum = saveList.size();
+        Integer successNum = saveList.stream().filter(i -> i.getSuccess().equals(1)).collect(Collectors.toList()).size();
+        Integer failedNum = saveList.stream().filter(i -> i.getSuccess().equals(0)).collect(Collectors.toList()).size();
 
 
         //保存测试结果
@@ -173,11 +191,14 @@ public class RuleTestFacade {
         resultBillQueryWrapper.eq("result_id", resultInfo.getId());
         resultBillService.remove(resultBillQueryWrapper);
 
-        for (ResultBill resultBill : resultList) {
+        for (ResultBill resultBill : saveList) {
+            resultBill.setBillType(1);
+            resultBill.setGmtCreate(now);
+            resultBill.setGmtModified(now);
             resultBill.setResultId(resultInfo.getId());
         }
 
-        resultBillService.saveOrUpdateBatch(resultList);
+        resultBillService.saveOrUpdateBatch(saveList);
     }
 
     /**

+ 10 - 3
cdssman-service/src/main/java/com/diagbot/facade/SearchDataFacade.java

@@ -22,7 +22,7 @@ public class SearchDataFacade {
         IndicationPushVO indicationPushVO = new IndicationPushVO();
         indicationPushVO.setAge("20");
         indicationPushVO.setSex(3);
-        indicationPushVO.setRuleType("1");
+        indicationPushVO.setRuleType("2");
 
         //开单项
         if (resultBill.getBillItemType().equals(GraphLabelEnum.LisSet.getName())) {
@@ -66,12 +66,16 @@ public class SearchDataFacade {
             //禁忌年龄特殊处理
             if (resultBill.getConflictItemName().equals("年龄")) {
                 indicationPushVO.setAge(resultBill.getInputValue());
+            } else if (resultBill.getConflictItemName().equals("体温")) {
+                indicationPushVO.setVital(resultBill.getConflictItemName() + resultBill.getInputValue() + "℃,");
             } else {
                 indicationPushVO.setVital(resultBill.getConflictItemName() + resultBill.getInputValue() + ",");
             }
         } else if (resultBill.getConflictItemType().equals(GraphLabelEnum.ClinicalFinding.getName())) {
             indicationPushVO.setSymptom(indicationPushVO.getSymptom() +
-                    resultBill.getInputValue() + ",");
+                    resultBill.getConflictItemName() +
+                    (resultBill.getInputValue() != null ? resultBill.getInputValue() : "") +
+                    ",");
         } else if (resultBill.getConflictItemType().equals(GraphLabelEnum.OralMedicine.getName())) {
             indicationPushVO.setSymptom(indicationPushVO.getSymptom() +
                     "一直服用" +
@@ -119,7 +123,10 @@ public class SearchDataFacade {
             indicationPushVO.getDiag().add(diag);
         } else if (resultBill.getConflictItemType().equals(GraphLabelEnum.Group.getName())) {
             indicationPushVO.setSymptom(indicationPushVO.getSymptom() +
-                    resultBill.getConflictItemName() + resultBill.getInputValue() + resultBill.getUnit() + ",");
+                    resultBill.getConflictItemName() +
+                    (resultBill.getInputValue() != null ? resultBill.getInputValue() : "") +
+                    (StringUtil.isNotBlank(resultBill.getUnit()) ? resultBill.getUnit() : "") +
+                    ",");
         } else if (resultBill.getConflictItemType().equals(GraphLabelEnum.ConflictDevice.getName())) {
             indicationPushVO.setPasts(indicationPushVO.getPasts() +
                     "有" + resultBill.getConflictItemName() + ",");

+ 17 - 0
cdssman-service/src/main/java/com/diagbot/repository/BaseNodeRepository.java

@@ -2,8 +2,25 @@ package com.diagbot.repository;
 
 
 import com.diagbot.entity.node.base.BaseNode;
+import org.springframework.data.neo4j.annotation.Query;
 import org.springframework.data.neo4j.repository.Neo4jRepository;
 
+import java.util.List;
+
 public interface BaseNodeRepository extends Neo4jRepository<BaseNode, Long> {
+    @Query("MATCH (c:药品化学物质类别)<-[r:药品相关药品化学物质类别]-(y:药品代码通用名)-[r1:药品相关药品通用名称]->(m:药品通用名称) " +
+            " RETURN DISTINCT(m.name)+'::'+c.name")
+    List<String> getMedHuaXueClass();
+
+    @Query("MATCH (c:药品治疗学类别)<-[r:药品相关药品治疗学类别]-(y:药品代码通用名)-[r1:药品相关药品通用名称]->(m:药品通用名称) " +
+            " RETURN DISTINCT(m.name)+'::'+c.name")
+    List<String> getMedZhiLiaoClass();
+
+    @Query("MATCH (c:药品药理学类别)<-[r:药品相关药品药理学类别]-(y:药品代码通用名)-[r1:药品相关药品通用名称]->(m:药品通用名称) " +
+            " RETURN DISTINCT(m.name)+'::'+c.name")
+    List<String> getMedYaoLiClass();
 
+    @Query("MATCH (c:药品解剖学类别)<-[r:药品相关药品解剖学类别]-(y:药品代码通用名)-[r1:药品相关药品通用名称]->(m:药品通用名称) " +
+            " RETURN DISTINCT(m.name)+'::'+c.name")
+    List<String> getMedJiePouClass();
 }

+ 0 - 1
cdssman-service/src/main/java/com/diagbot/repository/BillManRepository.java

@@ -113,7 +113,6 @@ public interface BillManRepository extends Neo4jRepository<BillItemDetail,Long>
             "n.范围 as conditionRange\n")
     List<BillItem> getAllRules();
 
-
     @Query("match (m)-[r]->(n) " +
             "where type(r) contains '禁忌' " +
             "and labels(m)[0] = $conceptLabel " +

+ 0 - 20
cdssman-service/src/main/java/com/diagbot/util/MsgUtil.java

@@ -48,26 +48,6 @@ public class MsgUtil {
         return billMsg;
     }
 
-    // /**
-    //  * 开单合理性通用提示信息
-    //  *
-    //  * @param orderName 原开单项
-    //  * @param orderStandName 标准开单项
-    //  * @param content 匹配内容
-    //  * @param type 类型
-    //  * @return
-    //  */
-    // public static BillMsg getCommonBillMsg(String orderName, String orderStandName, String content, String type) {
-    //     BillMsg billMsg = new BillMsg();
-    //     String msg = String.format("该患者%s,不宜开%s", content, orderName);
-    //     billMsg.setMsg(msg);
-    //     billMsg.setOrderName(orderName);
-    //     billMsg.setOrderStandName(orderStandName);
-    //     billMsg.setContent(content);
-    //     billMsg.setType(type);
-    //     return billMsg;
-    // }
-
     /**
      * 开单合理性通用提示信息
      *

+ 1 - 0
cdssman-service/src/main/resources/mapper/ResultBillMapper.xml

@@ -30,6 +30,7 @@
         <result column="expected_output" property="expectedOutput" />
         <result column="success" property="success" />
         <result column="message" property="message" />
+        <result column="input_params" property="inputParams" />
     </resultMap>
 
 </mapper>