|
@@ -0,0 +1,80 @@
|
|
|
+package com.lantone.qc.kernel.util;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.lantone.qc.kernel.client.SimilarityServiceClient;
|
|
|
+import com.lantone.qc.pub.model.vo.SimilarityVo;
|
|
|
+import com.lantone.qc.pub.util.StringUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @author: rengb
|
|
|
+ * @time: 2020/8/24 10:06
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class SimilarityUtil {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SimilarityServiceClient similarityServiceClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据相似度,获取药品标准词
|
|
|
+ *
|
|
|
+ * @param drugWord
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getDrugStandardWord(String drugWord) {
|
|
|
+ String ret = null;
|
|
|
+ try {
|
|
|
+ JSONArray standardWords = similarityRequest("drug", drugWord, 1);
|
|
|
+ if (standardWords != null && standardWords.size() == 1) {
|
|
|
+ JSONObject standardWord = standardWords.getJSONObject(0);
|
|
|
+ if (standardWord.getDoubleValue("rate") > 0.8) {
|
|
|
+ ret = standardWord.getString("standard_word");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送相似度请求
|
|
|
+ *
|
|
|
+ * @param word_type 由服务方定的词的类型,取值:疾病—disease、症状—symptom、手术和操作—operation、药品—drug、实验室检查-lis、辅助检查-pacs、体征-vital
|
|
|
+ * @param word 原始词
|
|
|
+ * @param number 最多返回个数,如果不是有效的值,默认返回1个,最多返回10个
|
|
|
+ * @return 返回具体数据集合
|
|
|
+ */
|
|
|
+ public JSONArray similarityRequest(String word_type, String word, int number) {
|
|
|
+ if (StringUtil.isBlank(word_type) || StringUtil.isBlank(word) || number == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ JSONArray ret = null;
|
|
|
+ try {
|
|
|
+ JSONArray similarContent = new JSONArray();
|
|
|
+ JSONObject detailContent = new JSONObject();
|
|
|
+ detailContent.put("word_type", word_type);
|
|
|
+ detailContent.put("word", word);
|
|
|
+ detailContent.put("number", number);
|
|
|
+ similarContent.add(detailContent);
|
|
|
+ SimilarityVo similarityVo = new SimilarityVo();
|
|
|
+ similarityVo.setData(similarContent);
|
|
|
+ String similarJson = similarityServiceClient.getAnnotation(similarityVo);
|
|
|
+ JSONObject similarJsonObject = JSON.parseObject(similarJson);
|
|
|
+ if (similarJsonObject.getBooleanValue("status")) {
|
|
|
+ ret = similarJsonObject.getJSONArray("standard_words");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|