|
@@ -1,21 +1,42 @@
|
|
|
package com.diagbot.model.ai.process;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.diagbot.model.ai.model.EntityEnum;
|
|
|
import com.diagbot.model.entity.Lis;
|
|
|
import com.diagbot.model.entity.LisValue;
|
|
|
import com.diagbot.model.entity.PD;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
public class EntityProcessLis extends EntityProcess {
|
|
|
public List<Lis> extractEntity(JSONObject outputs) {
|
|
|
List<Lis> lises = new ArrayList<>();
|
|
|
Lis lis = null;
|
|
|
List<Map<String, String>> lisEntityList = processJson(outputs, EntityEnum.LABORATORY.toString());
|
|
|
+ lisEntityList = lisEntityList.stream().filter(x -> x.containsKey(EntityEnum.LABORATORY_VALUE.toString())).collect(Collectors.toList());
|
|
|
+ Map<String, List<String>> detail_name = processLisoutputs(outputs);
|
|
|
+ if(ListUtil.isNotEmpty(lisEntityList)){
|
|
|
+ for (Map<String, String> c:lisEntityList) {
|
|
|
+ String detailName = c.get(EntityEnum.LABORATORY.toString());
|
|
|
+ String value = c.get(EntityEnum.LABORATORY_VALUE.toString());
|
|
|
+ for(Map.Entry<String, List<String>> f:detail_name.entrySet()){
|
|
|
+ String name = f.getKey();
|
|
|
+ List<String> details = f.getValue();
|
|
|
+ if(details.contains(detailName)){
|
|
|
+ c.put(EntityEnum.LABORATORY_ITEM.toString(),name);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lisEntityList = lisEntityList.stream().filter(x -> x.containsKey(EntityEnum.LABORATORY_ITEM.toString())).collect(Collectors.toList());
|
|
|
for (Map<String, String> lisEntityMap : lisEntityList) {
|
|
|
if (StringUtils.isEmpty(lisEntityMap.get(EntityEnum.LABORATORY.toString()))) {
|
|
|
continue;
|
|
@@ -24,6 +45,11 @@ public class EntityProcessLis extends EntityProcess {
|
|
|
for (String key : lisEntityMap.keySet()) {
|
|
|
String entity = StringUtils.isEmpty(lisEntityMap.get(key)) ? "" : lisEntityMap.get(key);
|
|
|
switch (EntityEnum.parseOfValue(key)) {
|
|
|
+ case LABORATORY_ITEM:
|
|
|
+ LisValue big = new LisValue();
|
|
|
+ big.setName(entity);
|
|
|
+ lis.setBigItem(big);
|
|
|
+ break;
|
|
|
case LABORATORY:
|
|
|
lis.setName(entity);
|
|
|
break;
|
|
@@ -35,7 +61,7 @@ public class EntityProcessLis extends EntityProcess {
|
|
|
String value = entity;
|
|
|
String[] val_unit = new String[2];
|
|
|
if (value.trim().length() > 0) {
|
|
|
- val_unit = extract_digit(value);
|
|
|
+ val_unit = extract_digit_new(value);
|
|
|
}
|
|
|
pd.setValue(val_unit[0]);
|
|
|
pd.setUnit(val_unit[1]);
|
|
@@ -47,4 +73,72 @@ public class EntityProcessLis extends EntityProcess {
|
|
|
}
|
|
|
return lises;
|
|
|
}
|
|
|
+
|
|
|
+ private Map<String,List<String>> processLisoutputs(JSONObject outputs){
|
|
|
+ JSONObject annotation = outputs.getJSONObject("annotation");
|
|
|
+ JSONArray entitys = annotation.getJSONArray("T");
|
|
|
+ JSONArray relations = annotation.getJSONArray("R");
|
|
|
+ //把name为实验室检查的id和value拿出来
|
|
|
+ Map<Integer,String> id_value = new HashMap<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < entitys.size(); i++) {
|
|
|
+ if (StringUtils.isEmpty(entitys.get(i).toString())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject entity = entitys.getJSONObject(i);
|
|
|
+ String name = entity.getString("name");
|
|
|
+ int id = entity.getIntValue("id");
|
|
|
+ String value = entity.getString("value");
|
|
|
+ if(EntityEnum.LABORATORY.toString().equals(name)){
|
|
|
+ id_value.put(id,value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //遍历关系,把name为LABORATORY_BIG的from和to拿出来
|
|
|
+ Map<Integer,List<Integer>> from_to = new HashMap<>();
|
|
|
+ for (int i = 0; i < relations.size(); i++) {
|
|
|
+ if (StringUtils.isEmpty(relations.get(i).toString())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject relationsJSONObject = relations.getJSONObject(i);
|
|
|
+ if(EntityEnum.LABORATORY_BIG.toString().equals(relationsJSONObject.getString("name"))){
|
|
|
+ int from = relationsJSONObject.getIntValue("from");
|
|
|
+ int to = relationsJSONObject.getIntValue("to");
|
|
|
+ if(from_to.containsKey(from)){
|
|
|
+ List<Integer> toList = from_to.get(from);
|
|
|
+ toList.add(to);
|
|
|
+ from_to.put(from,toList);
|
|
|
+ }else {
|
|
|
+ List<Integer> toList = new ArrayList<>();
|
|
|
+ toList.add(to);
|
|
|
+ from_to.put(from,toList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //组装化验的大小项
|
|
|
+ Map<String,List<String>> detail_name = new HashMap<>();
|
|
|
+ if(from_to.size()>0 && id_value.size()>0){
|
|
|
+ for(Map.Entry<Integer,List<Integer>> ft:from_to.entrySet()){
|
|
|
+ Integer big = ft.getKey();
|
|
|
+ List<Integer> details = ft.getValue();
|
|
|
+ for (Integer id:details) {
|
|
|
+ if(id_value.containsKey(big)&& id_value.containsKey(id)){
|
|
|
+// detail_name.put(id_value.get(ft.getValue()),id_value.get(ft.getKey()));
|
|
|
+ if(detail_name.containsKey(id_value.get(big))){
|
|
|
+ List<String> detailList = detail_name.get(id_value.get(big));
|
|
|
+ if(!detailList.contains(id_value.get(id))){
|
|
|
+ detailList.add(id_value.get(id));
|
|
|
+ }
|
|
|
+ detail_name.put(id_value.get(big),detailList);
|
|
|
+ }else {
|
|
|
+ List<String> detailList = new ArrayList<>();
|
|
|
+ detailList.add(id_value.get(id));
|
|
|
+ detail_name.put(id_value.get(big),detailList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return detail_name;
|
|
|
+ }
|
|
|
}
|