Browse Source

1.修改药品相似度接口方法
2.添加批量调药品相似度接口
3.药品相似度结果做redis缓存
4.添加规则:医嘱与病程记录抗生素剂量不一致

huj 5 years ago
parent
commit
a18ab06cab

+ 7 - 1
dbanaly/src/main/resources/application-local.yml

@@ -49,5 +49,11 @@ CRF:
 Similarity:
 Similarity:
   url: http://192.168.2.234:3456/api/mr_info_ex/similarity
   url: http://192.168.2.234:3456/api/mr_info_ex/similarity
 
 
+NewSimilarity:
+  url: http://192.168.3.150:23232/api/similarity
+
+NewBatchSimilarity:
+  url: http://192.168.3.150:23232/api/similarity_batch
+
 ChiefPresentSimilarity:
 ChiefPresentSimilarity:
-  url: http://192.168.2.234:3456/api/mr_info_ex/chief_present_similarity
+  url: http://192.168.2.234:3456/api/mr_info_ex/similarity

+ 3 - 3
kernel/src/main/java/com/lantone/qc/kernel/catalogue/behospitalized/BEH0019.java

@@ -35,10 +35,10 @@ public class BEH0019 extends QCCatalogue {
             Clinical clinical = clinicals.get(0);
             Clinical clinical = clinicals.get(0);
             String clinicalName = clinical.getName();
             String clinicalName = clinical.getName();
             if (StringUtil.isNotBlank(clinicalName)) {
             if (StringUtil.isNotBlank(clinicalName)) {
-                long start = System.currentTimeMillis();
+//                long start = System.currentTimeMillis();
                 Clinic clinic = clinicFacade.clinicCache(clinicalName);
                 Clinic clinic = clinicFacade.clinicCache(clinicalName);
-                long end = System.currentTimeMillis();
-                System.out.println("取kl_clinic缓存时间:" + (end-start));
+//                long end = System.currentTimeMillis();
+//                System.out.println("取kl_clinic缓存时间:" + (end-start));
                 if (clinic != null && clinic.getHasDegree() == 1) {
                 if (clinic != null && clinic.getHasDegree() == 1) {
                     Degree degree = clinical.getDegree();
                     Degree degree = clinical.getDegree();
                     if (degree == null) {
                     if (degree == null) {

+ 212 - 0
kernel/src/main/java/com/lantone/qc/kernel/catalogue/threelevelward/THR03076.java

@@ -0,0 +1,212 @@
+package com.lantone.qc.kernel.catalogue.threelevelward;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.lantone.qc.kernel.catalogue.QCCatalogue;
+import com.lantone.qc.kernel.util.CatalogueUtil;
+import com.lantone.qc.kernel.util.SimilarityUtil;
+import com.lantone.qc.pub.model.InputInfo;
+import com.lantone.qc.pub.model.OutputInfo;
+import com.lantone.qc.pub.model.doc.DoctorAdviceDoc;
+import com.lantone.qc.pub.model.doc.ThreeLevelWardDoc;
+import com.lantone.qc.pub.model.entity.Drug;
+import com.lantone.qc.pub.model.label.ThreeLevelWardLabel;
+import com.lantone.qc.pub.util.DateUtil;
+import com.lantone.qc.pub.util.StringUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * @author HUJING
+ * @create 2020-08-26 10:51
+ * @desc 医嘱与病程记录抗生素剂量不一致
+ **/
+@Component
+public class THR03076 extends QCCatalogue {
+    @Autowired
+    SimilarityUtil similarityUtil;
+
+    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
+        status.set("0");
+        List<DoctorAdviceDoc> doctorAdviceDocs = inputInfo.getDoctorAdviceDocs();
+        List<ThreeLevelWardDoc> threeLevelWardDocs = inputInfo.getThreeLevelWardDocs();
+        if (doctorAdviceDocs.size() == 0 || threeLevelWardDocs.size() == 0) {
+            return;
+        }
+        List<Map<String, String>> docAdvStruct = doctorAdviceDocs
+                .stream()
+                .filter(Objects::nonNull)
+                .map(DoctorAdviceDoc::getStructureMap)
+                .filter(x -> StringUtil.isNotBlank(x.get("药品类型")) && x.get("药品类型").contains("抗生素") && StringUtil.isNotBlank(x.get("医嘱单次剂量")))
+                .collect(Collectors.toList());
+
+        //抗生素及开医嘱时间 <抗生素名,<抗生素用量,[抗生素使用时间...]>>
+        Map<String, Map<Double, List<String>>> antibioticInfo = Maps.newLinkedHashMap();
+        String drugName = null, value = null, startDateStr = null;
+        for (Map<String, String> structMap : docAdvStruct) {
+            drugName = structMap.get("医嘱项目名称");
+            value = structMap.get("医嘱单次剂量");
+            startDateStr = structMap.get("医嘱开始时间");
+            drugName = removeBracket(drugName);
+            String drugStandardWord = similarityUtil.getDrugStandardWord(drugName);
+            if (StringUtil.isNotBlank(drugStandardWord)) {
+                drugName = drugStandardWord;
+            }
+            collectAntibioticInfo(antibioticInfo, drugName, value, startDateStr);
+        }
+
+        //抗生素及开医嘱时间 <抗生素名,<抗生素用量,[抗生素使用时间...]>>
+        Map<String, Map<Double, List<String>>> antibioticWardInfo = Maps.newLinkedHashMap();
+        List<ThreeLevelWardDoc> allDoctorWradDocs = threeLevelWardDocs.get(0).getAllDoctorWradDocs();
+        for (ThreeLevelWardDoc doc : allDoctorWradDocs) {
+            if (doc.getThreeLevelWardLabel().size() == 0) {
+                continue;
+            }
+            ThreeLevelWardLabel label = doc.getThreeLevelWardLabel().get(0);
+            List<Drug> drugs = label.getDrugs();
+            for (Drug drug : drugs) {
+                String wardDrug = drug.getName();
+                wardDrug = removeBracket(wardDrug);
+                String drugStandardWord = similarityUtil.getDrugStandardWord(wardDrug);
+                if (StringUtil.isNotBlank(drugStandardWord)) {
+                    wardDrug = drugStandardWord;
+                }
+                if (drug.getConsumption() != null) {
+                    String consumption = drug.getConsumption().getName();
+                    collectAntibioticInfo(antibioticWardInfo, wardDrug, consumption, doc.getStructureMap().get("查房日期"));
+                }
+            }
+        }
+
+        /**
+         * 1.医嘱中开了抗生素,查房记录中没有该抗生素,则医嘱中该抗生素出现过的所有时间都会提示出来
+         * 2.医嘱中开了抗生素,查房记录中有该抗生素:
+         *      2.1 医嘱中该抗生素某使用量(如50),查房记录中没有该使用量(如只有100),则医嘱中该抗生素使用量出现过的所有时间都会提示出来
+         *      2.2 医嘱中该抗生素某使用量(如50),查房记录中也有该使用量,对比这两个时间,若医嘱时间两天内的查房记录没有该使用量,则该医嘱时间会提示出来
+         */
+        StringBuffer sb = new StringBuffer();
+        String drugKey = null;
+        for (Map.Entry<String, Map<Double, List<String>>> ai : antibioticInfo.entrySet()) {
+            drugKey = ai.getKey();
+            if (!antibioticWardInfo.containsKey(drugKey)) {
+                for (Map.Entry<Double, List<String>> ad : ai.getValue().entrySet()) {
+                    for (String date : ad.getValue()) {
+                        infoAppend(sb, drugKey, ad.getKey(), date);
+                    }
+                }
+            } else {
+                Map<Double, List<String>> adValueDate = ai.getValue();
+                Map<Double, List<String>> wardValueDate = antibioticWardInfo.get(drugKey);
+                for (Map.Entry<Double, List<String>> adMap : adValueDate.entrySet()) {
+                    Double adUsage = adMap.getKey();
+                    List<String> adDateList = adMap.getValue();
+                    if (wardValueDate.containsKey(adUsage)) {
+                        int num = 0;
+                        List<String> wardDateList = wardValueDate.get(adUsage);
+                        for (String adDate : adDateList) {
+                            for (String wardDate : wardDateList) {
+                                if (!CatalogueUtil.compareTime(StringUtil.parseDateTime(adDate), StringUtil.parseDateTime(wardDate), 48 * 60L)) {
+                                    //如果医嘱中该药使用量的医嘱时间,两天内的查房记录中也有该用量,则找到,num+1
+                                    num++;
+                                }
+                            }
+                            if (num == 0) {
+                                infoAppend(sb, drugKey, adUsage, adDate);
+                            }
+                        }
+                    } else {
+                        //遗嘱中该抗生素使用量在查房记录中没出现过,全部提示出来药品名+时间
+                        for (String adDate : adDateList) {
+                            infoAppend(sb, drugKey, adUsage, adDate);
+                        }
+                    }
+                }
+            }
+        }
+
+        if (sb.toString().length() > 0) {
+            status.set("-1");
+            info.set(sb.toString().substring(0, sb.toString().length() - 1));
+        }
+    }
+
+    /**
+     * 拼接提示信息
+     *
+     * @param sb
+     * @param drugKey
+     * @param date
+     */
+    private void infoAppend(StringBuffer sb, String drugKey, double value, String date) {
+        sb.append(drugKey).append("->").append(value)
+                .append("(").append(DateUtil.formatDate(StringUtil.parseDateTime(date))).append(")").append(",");
+    }
+
+    /**
+     * 收集抗生素各种信息
+     *
+     * @param antibioticInfo 抗生素使用量及所有时间
+     * @param drugName       抗生素名称
+     * @param value          抗生素用量
+     * @param startDateStr   抗生素使用时间(医嘱开始时间或查房时间)
+     */
+    private void collectAntibioticInfo(Map<String, Map<Double, List<String>>> antibioticInfo, String drugName, String value, String startDateStr) {
+        Map<Double, List<String>> antibioticValueList = null;
+        double v = -1;
+        try {
+            v = Double.parseDouble(getNumber(value));
+        } catch (Exception e) {
+            System.out.println("THR03076:       " + drugName + ":" + value + "解析异常");
+        }
+        if (v < 0) {
+            return;
+        }
+        if (!antibioticInfo.containsKey(drugName)) {
+            //存该抗生素使用第1个值
+            antibioticValueList = Maps.newLinkedHashMap();
+            antibioticValueList.put(v, Lists.newArrayList(startDateStr));
+            antibioticInfo.put(drugName, antibioticValueList);
+        } else {
+            antibioticValueList = antibioticInfo.get(drugName);
+            //存该抗生素使用量第n个时间
+            if (antibioticValueList.containsKey(v)) {
+                antibioticValueList.get(v).add(startDateStr);
+            } else {
+                //存该抗生素使用量第1个时间
+                antibioticValueList.put(v, Lists.newArrayList(startDateStr));
+            }
+        }
+    }
+
+    public static String getNumber(String content) {
+        String group = "";
+        String compile = "([1-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9]|\\.\\d*[1-9]|0)";
+        Pattern p = Pattern.compile(compile);
+        Matcher matcher = p.matcher(content);
+        if (matcher.find()) {
+            group = matcher.group(0);
+        }
+        return group;
+    }
+
+    /**
+     * 如果文本包含中括号([海正]美罗培南针),取括号之后的文字
+     *
+     * @param str
+     * @return
+     */
+    private String removeBracket(String str) {
+        if (str.contains("]") && str.indexOf("]") != str.length() - 1) {
+            return str.substring(str.indexOf("]") + 1);
+        }
+        return str;
+    }
+
+}

+ 23 - 0
kernel/src/main/java/com/lantone/qc/kernel/client/NewSimilarityBatchServiceClient.java

@@ -0,0 +1,23 @@
+package com.lantone.qc.kernel.client;
+
+
+import com.alibaba.fastjson.JSONArray;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+
+/**
+ * @Description: 调用新文本相似度服务
+ * @author: 胡敬
+ * @time: 2020/08/26 13:43
+ */
+@FeignClient(value = "Similarity-new-batch-service", url="${NewBatchSimilarity.url}")
+public interface NewSimilarityBatchServiceClient {
+
+    @PostMapping(value = "")
+    String getAnnotation(@RequestBody JSONArray similarityVo);
+}
+
+
+

+ 23 - 0
kernel/src/main/java/com/lantone/qc/kernel/client/NewSimilarityServiceClient.java

@@ -0,0 +1,23 @@
+package com.lantone.qc.kernel.client;
+
+
+import com.alibaba.fastjson.JSONObject;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+
+/**
+ * @Description: 调用文本相似度服务
+ * @author: 胡敬
+ * @time: 2020/08/26 13:43
+ */
+@FeignClient(value = "Similarity-new-service", url="${NewSimilarity.url}")
+public interface NewSimilarityServiceClient {
+
+    @PostMapping(value = "")
+    String getAnnotation(@RequestBody JSONObject similarityVo);
+}
+
+
+

+ 79 - 8
kernel/src/main/java/com/lantone/qc/kernel/util/SimilarityUtil.java

@@ -3,13 +3,18 @@ package com.lantone.qc.kernel.util;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
-import com.lantone.qc.kernel.client.SimilarityServiceClient;
-import com.lantone.qc.pub.model.vo.SimilarityVo;
+import com.google.common.collect.Maps;
+import com.lantone.qc.kernel.client.NewSimilarityBatchServiceClient;
+import com.lantone.qc.kernel.client.NewSimilarityServiceClient;
 import com.lantone.qc.pub.util.StringUtil;
 import com.lantone.qc.pub.util.StringUtil;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 
 
+import java.util.List;
+import java.util.Map;
+
 /**
 /**
  * @Description:
  * @Description:
  * @author: rengb
  * @author: rengb
@@ -20,7 +25,10 @@ import org.springframework.stereotype.Component;
 public class SimilarityUtil {
 public class SimilarityUtil {
 
 
     @Autowired
     @Autowired
-    private SimilarityServiceClient similarityServiceClient;
+    private NewSimilarityServiceClient newSimilarityServiceClient;
+
+    @Autowired
+    private NewSimilarityBatchServiceClient newSimilarityBatchServiceClient;
 
 
     /**
     /**
      * 根据相似度,获取药品标准词
      * 根据相似度,获取药品标准词
@@ -28,6 +36,7 @@ public class SimilarityUtil {
      * @param drugWord
      * @param drugWord
      * @return
      * @return
      */
      */
+    @Cacheable(value = "drugCache", key = "#drugWord", unless = "#result == null")
     public String getDrugStandardWord(String drugWord) {
     public String getDrugStandardWord(String drugWord) {
         String ret = null;
         String ret = null;
         try {
         try {
@@ -58,15 +67,11 @@ public class SimilarityUtil {
         }
         }
         JSONArray ret = null;
         JSONArray ret = null;
         try {
         try {
-            JSONArray similarContent = new JSONArray();
             JSONObject detailContent = new JSONObject();
             JSONObject detailContent = new JSONObject();
             detailContent.put("word_type", word_type);
             detailContent.put("word_type", word_type);
             detailContent.put("word", word);
             detailContent.put("word", word);
             detailContent.put("number", number);
             detailContent.put("number", number);
-            similarContent.add(detailContent);
-            SimilarityVo similarityVo = new SimilarityVo();
-            similarityVo.setData(similarContent);
-            String similarJson = similarityServiceClient.getAnnotation(similarityVo);
+            String similarJson = newSimilarityServiceClient.getAnnotation(detailContent);
             JSONObject similarJsonObject = JSON.parseObject(similarJson);
             JSONObject similarJsonObject = JSON.parseObject(similarJson);
             if (similarJsonObject.getBooleanValue("status")) {
             if (similarJsonObject.getBooleanValue("status")) {
                 ret = similarJsonObject.getJSONArray("standard_words");
                 ret = similarJsonObject.getJSONArray("standard_words");
@@ -77,4 +82,70 @@ public class SimilarityUtil {
         return ret;
         return ret;
     }
     }
 
 
+    /**
+     * 根据相似度,获取药品标准词
+     *
+     * @param input
+     * @param wordType
+     * @return
+     */
+    public Map<String, String> getDrugStandardWordBatch(List<String> input, String wordType) {
+        Map<String, String> wordMap = Maps.newHashMap();
+        JSONArray inputData = new JSONArray();
+        JSONObject micro = null;
+        JSONObject similarJsonObject = null;
+        JSONArray ret = null;
+        try {
+            for (String word : input) {
+                micro = new JSONObject();
+                micro.put("word_type", wordType);
+                micro.put("word", word);
+                micro.put("number", 1);
+                inputData.add(micro);
+            }
+            if (inputData.size() > 0) {
+                JSONObject data = similarityBatchRequest(inputData);
+                JSONObject wordTypeJson = data.getJSONObject(wordType);
+                for (String word : input) {
+                    similarJsonObject = wordTypeJson.getJSONObject(word);
+                    if (similarJsonObject != null && similarJsonObject.getBooleanValue("status")) {
+                        ret = similarJsonObject.getJSONArray("standard_words");
+                        if (ret != null && ret.size() == 1) {
+                            JSONObject standardWord = ret.getJSONObject(0);
+                            if (standardWord.getDoubleValue("rate") > 0.8) {
+                                String result = standardWord.getString("standard_word");
+                                wordMap.put(word, result);
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+        return wordMap;
+    }
+
+    /**
+     * 发送相似度批量请求
+     *
+     * @param jsonArray 全部需要查询的标准词封装后的集合
+     * @return 返回具体数据集合
+     */
+    public JSONObject similarityBatchRequest(JSONArray jsonArray) {
+        if (jsonArray.size() == 0) {
+            return null;
+        }
+        JSONObject ret = null;
+        try {
+            String similarJson = newSimilarityBatchServiceClient.getAnnotation(jsonArray);
+            JSONObject similarJsonObject = JSON.parseObject(similarJson);
+            if (similarJsonObject.getBooleanValue("status")) {
+                ret = similarJsonObject.getJSONObject("data");
+            }
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+        return ret;
+    }
 }
 }